-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Expr/SyntaxTree parity: trivial conversions
#60373
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
base: master
Are you sure you want to change the base?
Conversation
Merged!
At what point do we replace |
PR 4 in the list replaces it completely from the perspective of macro authors. Internal to lowering, we can make individual changes to |
1f327e5 to
64ec26d
Compare
JuliaLowering/test/compat.jl
Outdated
| end | ||
|
|
||
| # ignore_lnn=false is good for checking, but too noisy to use much | ||
| function expr_equal_forgiving(e1, e2; ignore_lnn=true) |
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.
| function expr_equal_forgiving(e1, e2; ignore_lnn=true) | |
| function expr_equal_forgiving(e1, e2; ignore_linenums=true) |
in keeping with Base.remove_linenums!
| need_lnns = head in (:block, :toplevel) | ||
| out = Expr(head) | ||
| for c in children(st) | ||
| need_lnns && push!(out.args, source_location(LineNumberNode, c)) |
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.
Maybe a dumb suggestion, but should this do some kind of delta detection to avoid polluting the IR?
(i.e. only a emit a LineNumberNode when the lineinfo changes from stmt-to-stmt)
I'm not sure our debuginfo encoding in Expr is well-defined enough to do that losslessly, but perhaps it's good enough?
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.
That sounds reasonable, but would be a separate change we could implement here and in both parsers. It isn't so clear to me who is consuming the linenodes and whether they will break.
| elseif e isa Symbol | ||
| setattr!(makeleaf(graph, src, K"Identifier"), :name_val, String(e)) | ||
| elseif e isa QuoteNode | ||
| cid, _ = _expr_to_est(graph, e.value, src) |
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.
Does this handle QuoteNode of non-self-quoting values correctly?
QuoteNode(LineNumberNode(...)), QuoteNode(Expr(...)), QuoteNode(Symbol(...)), 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.
It should, but I should add separate tests for those.
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.
Hmm it looks like the LineNumberNode will pollute the debuginfo at least, but also converting the internal value at all does not seem correct to me...
It would require that lowering de-convert it when lowering something like return $(QuoteNode(Expr(...))), but that is also wrong to do, since you don't know whether I actually put a EST (or other SyntaxTree) in there to begin with.
JuliaLowering/test/compat.jl
Outdated
| zip(e1.args, e2.args)) | ||
| end | ||
|
|
||
| local roundtrip = e->JuliaLowering.est_to_expr(JuliaLowering.expr_to_est(e)) |
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.
Very nice test!
I'd prefer to keep CST and RawGreenNode close together, and aim for CST to eventually be the new AST once we release new-style macros. In the meantime it's an implementation detail which we can keep refining as we see fit. My very strong preference is that we don't get stuck with the |
As discussed on slack with @c42f and @topolarity, I gave conversions an honest try, but couldn't see the end of the tunnel in terms of correctness. The equivalence between SyntaxNode and Expr is only defined on surface syntax or fully-macro-expanded syntax, and not the steps in between, or if errors occur. We have a plan for syntax evolution now, too, so there compelling reasons not to lump changes to AST layout into JuliaLowering's macro expansion.
Let
ESTbe the "new" Expr-like SyntaxTree I'm working on andCSTbe the current SyntaxNode-like version. PRs planned:SyntaxGraph/SyntaxTreefrom JuliaLowering to JuliaSyntax #60370EST<->Exprconversion, tested by parsing code in bulk and round-trippingRawGreenNode->EST(identical logic to existingRawGreenNode->Expr, and testable with this PR'sExpr->EST)EST->CST*: This would just be a simplification of our existingExpr->CST, and prevents us from needing to make huge changes in desugaring (which understandsCST*). Macro expansion will becomeEST->ESTrather thanCST->CST*.