Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator for staged function should be in .source #18838

Closed
Keno opened this issue Oct 7, 2016 · 14 comments
Closed

Generator for staged function should be in .source #18838

Keno opened this issue Oct 7, 2016 · 14 comments
Assignees
Labels
compiler:codegen Generation of LLVM IR and native code
Milestone

Comments

@Keno
Copy link
Member

Keno commented Oct 7, 2016

julia> @generated function generatedfoo(T)
           :(return $T)
       end
generatedfoo (generic function with 1 method)

julia> (@which generatedfoo(1)).source
ERROR: UndefRefError: access to undefined reference

It doesn't make much sense to me to not have this here. It's what the user wrote, after all, even if you have to look at isstaged to properly interpret it.

@JeffBezanson
Copy link
Member

I agree. Also, in theory it would be nice to have an actual unspecialized implementation of a generated function in the unspecialized field.

@andyferris
Copy link
Member

I was a little excited to see .source here but I realized it's not that at all... it's Julia IR. Shouldn't "source code" mean code from the source, i.e. user-level Julia syntax?

(btw if I could insert AST/IR into new methods or get the actual toplevel source from a method, I would find that useful - e.g. we could make Traitor.jl actually useful).

@JeffBezanson
Copy link
Member

Understood --- the key feature of this field is that it's what was originally written, albeit converted to IR. We could call the field ir, but (1) that's more obscure, and (2) it's not just any IR, but the original IR (as opposed to that of a specialization). I welcome any name suggestions here.

@StefanKarpinski
Copy link
Member

StefanKarpinski commented Oct 11, 2016

.ir0, .ir_original? tbh, anyone who's using this should probably know what IR means.

@JeffBezanson
Copy link
Member

cc @vtjnash

@JeffBezanson
Copy link
Member

Not directly related to this, but there is a questionable property of the CodeInfo type I didn't notice before: there is no way to uncompress it without having its Method, but it doesn't reference its Method any more. This undermines the status of CodeInfo as an independent type, since having one by itself is basically useless.

Of course, the solution to this might involve eliminating the compressed representation. However, even then we still might want per-method constant tables, in which case you'd still need a Method.

@JeffBezanson
Copy link
Member

It's also a bit odd that a CodeInfo can tell you the type of absolutely everything inside a function, except the inferred return type of the function overall. Of course, I was the one who set that in motion by removing the Expr corresponding to the function body, but it really doesn't make sense to wrap every function's IR in an Expr. This leads to, for example, needing to return a CodeInfo=>Type pair from code_typed, which is not terribly natural. So maybe we should just move the rettype field into CodeInfo.

@vtjnash
Copy link
Member

vtjnash commented Oct 12, 2016

This undermines the status of CodeInfo as an independent type, since having one by itself is basically useless.

This is already true for other reasons, but we perhaps should still add the backlink. It would be redundant with its lookup, but so are a lot of the fields of Method.

So maybe we should just move copy the rettype field into CodeInfo.

It wouldn't be a terrible idea to duplicate it, since MethodInstance->rettype ≭ CodeInfo->rettype (in general), but I'm not sure whether that is just more confusing for other developers.

Please let's wait for #17057 first though, since that can complicate these questions quite significantly. And separating the CodeInfo fields out into their own type is one mechanism I've been using to partition the complexity better. (because it means that type inference doesn't change any fields of MethodInstance)

Also, in theory it would be nice to have an actual unspecialized implementation of a generated function in the unspecialized field.

Yes. In theory too, I think this means the ->source field should be a MethodInstance in the isstaged case. The current setup is mostly a lazy way to help cause faster errors when the user forgets to check ->isstaged before using ->source.

@StefanKarpinski
Copy link
Member

@Keno: is this really release blocking?

@Keno
Copy link
Member Author

Keno commented Dec 15, 2016

Yes, this whole data structure needs another look. Right now it may not have enough information for the debugger anymore (the second issue Jeff mentioned above).

@kshyatt kshyatt added the compiler:codegen Generation of LLVM IR and native code label Dec 18, 2016
@tkelman
Copy link
Contributor

tkelman commented Dec 29, 2016

it may not have enough information for the debugger anymore

Will fixing this be breaking? If so, this needs to be worked on ASAP

@josefsachsconning
Copy link
Contributor

From my perspective, not fixing this would be breaking, since it is necessary for Gallium to work in v0.6 (stopped working around September 14.)

@JeffBezanson
Copy link
Member

@Keno I believe the debugger should be getting a MethodInstance, which should have all the needed info. Do you happen to know of anything else the debugger needs here?

@Keno
Copy link
Member Author

Keno commented Jan 3, 2017

I'll have to revisit this. I remember when we tried porting the debugger over initially, there was something missing, but since we thought this would be refactored anyway, I don't think we went into too much detail.

@JeffBezanson JeffBezanson self-assigned this Jan 3, 2017
JeffBezanson added a commit that referenced this issue Jan 4, 2017
fix #18838, populate `source` field of generated functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

No branches or pull requests

8 participants