-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Lowering API: Allow for switching to JuliaLowering #58207
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
Conversation
e14f301 to
890ec36
Compare
|
Should #58055 be merged first? |
890ec36 to
1aebe67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried converting this to a Core._lower call, which gave me a wide variety of test failures seemingly due to fl_lower being defined after some generated functions are. Fixed by putting the ccall back, but local tests also pass if I keep _lower and move include("flfrontend.jl") earlier in Base_compiler.jl (I don't think it matters, and JuliaLowering doesn't use our generated_body_to_codeinfo anyway).
Nope, this (and the lowering API refactor) should supersede it |
Without using JuliaLowering, this should just call `fl_lower` in flfrontend.jl
and behave as usual. This structure mirrors the parsing API.
1aebe67 to
3988537
Compare
|
@JeffBezanson @vtjnash can we get a quick review before merging? Would be good to have one more set of eyes for the "big picture" direction here |
|
I'll merge this today if there's no new feedback. |
|
Thanks @mlechu ! |
This PR along with the associated JuliaLowering PR allow us to experiment
with JuliaLowering as the core lowering implementation, mainly for JETLS
development at the moment (cc @aviatesk, @c42f).
Changes
JuliaLowering works with
JuliaLowering.SyntaxTreeinput instead of Expr. Thischange allows
SyntaxTrees out of parsing and into lowering, hopefully withoutdisturbing existing code expecting Expr. The current design wraps
x::SyntaxTreelikeExpr(:syntaxtree, x)because otherwisetoplevel_eval_flexwouldn't know whatxis, but once we're past theexperimental phase, it would only make sense for the compiler to actually know
about the types it's operating on.
New:
Core._lowerIt (a julia entrypoint),
jl_lower(C entrypoint),jl_fl_lower, andfl_lowerall mirror the existing parsing API which was added in #35243.Click for pre-PR call graph
After this change:
Like
Core._parse,Core._lowerreturns ansvecwith the first element asthe expected result, and the remaining elements can hold extra information like
the lowered SyntaxTree with provenance info (I've left the specification of
extra return values for later, when JuliaLowering is more stable and JETLS knows
what it needs, because we may opt to pack provenance into the lowered CodeInfo
object instead). Parsing only uses the svec to return an offset, but it could
actually make use of the the flexibility to return diagnostics in the future.
It's unfortunately not clear what types we can expect to go into and come out of
lowering (I got Expr, LineNumberNode, String, Symbol, and Nothing in testing.)
Remove
jl_lower_expr_modI realize this isn't being called from C, and Core._lower is a more sensible
entry point from julia. We could probably also remove some uncalled parse and
jl_load functions.
Limitations
These belong to JuliaLowering, but are listed here as known issues for anyone
who wants to try it out.
(module ...)forms don't go through JuliaLowering yet. Modules are loweredto a call to
JuliaLowering.eval_module(parentmod, modname, syntaxtree),which is currently a stub function that converts to Expr for lowering and
evaluation, which JuliaLowering can't use.
invoking normal macros defined pre-JuliaLowering will not.