-
Notifications
You must be signed in to change notification settings - Fork 9
New Core.declare_global and Core.declare_const lowering #87
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
Corresponds to #58279 (also take unused_only)
mlechu
left a comment
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.
| # constructed followed by destructuring. In particular, any side effects due to | ||
| # evaluating the individual terms in the right hand side tuple must happen in | ||
| # order. | ||
| function tuple_to_assignments(ctx, ex) |
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.
| type | ||
| end | ||
| ] | ||
| [K"latestworld"] |
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.
Most world age increments have been moved to linearization in JuliaLowering; move this if you can
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.
Realizing I mixed up which file I was commenting on, sorry. I was worried about emitting (globaldecl ...) (latestworld) in desugaring and sending that through the woodchipper (closure conversion)
|
JuliaLowering doesn't suffer from JuliaLang/julia#59755 because of a quirk in how toplevel statements are hoisted, so this can be merged as-is. I should get around to documenting when "definition time" side effects happen, when you can observe the result of an import, etc... |
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.
This looks good, and people (including me) want JuliaLowering working on 1.13 again. Thanks for porting this!
| end | ||
| ] | ||
| [K"latestworld"] | ||
| @ast ctx src_ex [K"removable" "nothing"::K"core"] |
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.
No need for the nested @ast here :)
| mod::K"Value" name::K"Symbol" strong::K"Bool" | ||
| if type !== nothing | ||
| type | ||
| end |
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.
This if isn't required - children of type Nothing will be elided from @ast child list - we're allowed to do this without ambiguity because AST fragments must always be of type SyntaxTree.
| if ret_nothing | ||
| nothing | ||
| else | ||
| @ast ctx src_ex [K"removable" "nothing"::K"core"] |
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.
"nothing"::K"core" is always removable as is access to other core bindings which we know cannot have side effects - so it's not necessary to wrap this.
* Support `const foo() = ...` * Add support for destructuring `const` * Generate Core.declare_const; make constdecl a lowering-only kind * Generate Core.declare_global; remove globaldecl kind, desugar global Corresponds to #58279 (also take unused_only) * Refresh IR test cases * Update README * Fix toplevel_pure * Random typo fix * Use Core.declare_const instead of jl_set_const * Don't test on 1.12 in CI * Update test/decls.jl Co-authored-by: Em Chu <[email protected]> * Expand global/local function def body properly * Add a handful more IR tests for declarations * Add tests for JuliaLang/julia#59755 --------- Co-authored-by: Em Chu <[email protected]>
This commit utilizes a new branch `jetls-hacking-2` for JETLS. This branch is basically the latest c42f/JuliaLowering.jl#main - c42f/JuliaLowering.jl#87. Since the current JETLS implementation does not run inference on JL-generated code, we could simply include that commit straightforwardly.
This commit utilizes a new branch `jetls-hacking-2` for JETLS. This branch is basically the latest c42f/JuliaLowering.jl#main - c42f/JuliaLowering.jl#87. Since the current JETLS implementation does not run inference on JL-generated code, we could simply include that commit straightforwardly.
This commit utilizes a new branch `jetls-hacking-2` for JETLS. ~~This branch is basically the latest c42f/JuliaLowering.jl#main - c42f/JuliaLowering.jl#87~~. Since the current JETLS implementation does not run inference on JL-generated code, we could simply include that commit straightforwardly. `jetls-hacking-2` is now the very latest c42f/JuliaLowering.jl#main + c42f/JuliaLowering.jl#89.
This commit utilizes a new branch `jetls-hacking-2` for JETLS. ~~This branch is basically the latest c42f/JuliaLowering.jl#main - c42f/JuliaLowering.jl#87~~. Since the current JETLS implementation does not run inference on JL-generated code, we could simply include that commit straightforwardly. `jetls-hacking-2` is now the very latest c42f/JuliaLowering.jl#main + c42f/JuliaLowering.jl#89.
Co-authored-by: Claire Foster <[email protected]>
Co-authored-by: Claire Foster <[email protected]>
These are the JuliaLowering changes for JuliaLang/julia#58187 and
JuliaLang/julia#58279, as well as a handful of small changes to get us closer to
passing the Julia syntax test suite.
Fixes #28.
Change summary
const foo() = ...(whereconsthas no effect) is unfortunately present ina few packages and is now supported.
constis now supported,eg
const x, (; y, z) = 1, (; y=2, z=3)orconst x, y..., z = foo().Expr(:const, ...)form has been removed, and replaced with theCore.declare_constbuiltin.Expr(:const, x), wherexis a symbol or GlobalRef. It would be nice todeprecate and remove this eventually.
constdeclis now a lowering-only kind.Expr(:globaldecl, ...)andExpr(:global, ...)have beenremoved and replaced with
Core.declare_global. This is notable because itis an explicit side effect that is hoisted to the top level, like closure
definitions, while
globaldeclandglobalare evaluated by walking thelowered code in
jl_method_set_source.lambdakind now has atoplevel_pureattribute, analogous to thetoplevel-pureExpr head used in flisp.Expr(:global, x)withxbeing a symbol or GlobalRef is alsosupported now (like the const version, it should eventually be removed in
favour of calling
Core.declare_globaldirectly, if we make it public).unused_onlylowering-only kind previously discussed in Fix decls in value position without assignment to returnnothing#67since
globalno longer survives tolinearize_ir.Limitations and TODOs
JuliaLowering generally evaluates the entire RHS of a destructuring assignment
before doing any assignments, but this is restricted to one non-nested LHS
pattern. For example:
It would be nice to extend this to a general guarantee that if the RHS throws
or is evaluated and determined not to satisfy the LHS pattern, we don't do any
of the side effects.
We emit redundant calls to
Core.declare_global. They are benign, becausethey are guaranteed to be emitted in order of increasing strength: weak global
declaration, then strong but with no declared type, then strong with explicit
type. It would be nice to collapse these into a single call with the
strongest effect.
JuliaSyntax converts
f() = ...into afunctionnode with theSHORT_FORM_FUNCTION_FLAGflag, but doesn't do this for functions definedwith the destructuring syntax:
f(), g() = 1, 2. This "feature" allows youto define methods but gives you no way of accessing the arguments (similarly,
curly assignment in an LHS pattern doesn't let you use the type variables).
This shouldn't really be allowed, but depending on what PkgEval says we may
have to hack it in.
T{U}, f(x::String)::Vector{DataType}..., v::DataType = [Val{i} for i in 1:10] # Defines a constant `T`, a method `f(::String)` that returns a Vector of Val # datatypes, and a typed global variable `v`, all at once! : )