Skip to content

Commit 91018f5

Browse files
mlechutopolarity
andauthored
[JuliaLowering] Use Expr structure in macro expansion (#60733)
Step 4 in the the plan at #60373. Main changes: - Delete old `expr_to_syntaxtree` (hooray) - Introduce `est_to_dst`, which does a similar conversion as the above, but can assume all macros have expanded. (I've chosen "dst" for to mean "desugarable syntax tree" instead of the "current syntax tree" naming I've been using thus far) - Update macro expansion to be a function EST->EST - Add the AST validator from JuliaLang/JuliaLowering.jl#93, which I've changed to work on Expr structure. It's included in this PR so that `est_to_dst` doesn't need to do all the same checking (since nothing can be assumed about the output of macro expansion). Most of the long write-up there still applies, and using the same assumptions in desugaring could make it much less messy in the future. - This also means we're now able to return multiple AST-related syntax errors per top-level thunk, which may be of interest to @aviatesk. I haven't implemented pretty-printing for this beyond a `for` loop, though. - We now go though the `Core.@doc`system instead of the `K"doc"`system, which should be a temporary solution before we (1) get JuliaLowering working, then (2) handle docstrings in lowering in both implementations. - Many tests have been updated with the changes in behaviour. I've deleted a few where the point of the test is no longer relevant, but otherwise tried to maintain the spirit of each test. - Changes in syntax_macros.jl to produce the new old AST. The largest change is to our version of `@ccall`. Desugaring has also been tweaked so that it can tolerate `@ccall` expanded by flisp. stdlib status: There shouldn't be any regressions, and TOML and LibGit2 now precompile. Atop #60710 --------- Co-authored-by: Cody Tapscott <topolarity@tapscott.me>
1 parent 839059f commit 91018f5

40 files changed

Lines changed: 2118 additions & 1964 deletions

JuliaLowering/src/JuliaLowering.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ using .JuliaSyntax: highlight, Kind, @KSet_str, is_leaf, children, numchildren,
2222
setattr, setattr!, syntax_graph, is_compatible_graph,
2323
check_compatible_graph, copy_node, copy_ast, provenance, sourceref,
2424
reparent, mapchildren, flattened_provenance, mkleaf, mknode, newleaf,
25-
newnode, tree_ids
25+
newnode, tree_ids, @stm, mapsyntax
2626

2727
_include("kinds.jl")
2828
_register_kinds()
2929

3030
_include("ast.jl")
3131
_include("bindings.jl")
3232
_include("utils.jl")
33+
_include("validation.jl")
3334

3435
_include("macro_expansion.jl")
3536
_include("desugaring.jl")

JuliaLowering/src/ast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function JuliaSyntax.newleaf(ctx, prov, k, @nospecialize(value))
105105
setattr!(leaf._graph, leaf._id, :var_id, value)
106106
elseif k == K"label"
107107
setattr!(leaf._graph, leaf._id, :id, value)
108-
elseif k == K"symbolic_label"
108+
elseif k == K"symboliclabel"
109109
setattr!(leaf._graph, leaf._id, :name_val, value)
110110
elseif k in KSet"TOMBSTONE SourceLocation latestworld latestworld_if_toplevel
111111
softscope"

JuliaLowering/src/binding_analysis.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,24 @@ function du_declare!(state::DefUseState, var_id)
177177
end
178178
end
179179

180-
# Returns whether e contained a symbolic_label
180+
# Returns whether e contained a symboliclabel
181181
function du_visit!(ctx, state::DefUseState, e)
182182
k = kind(e)
183183

184184
if k == K"BindingId"
185185
du_mark_used!(state, e.var_id)
186186
return false
187187

188-
elseif k == K"symbolic_label"
189-
# Must check BEFORE is_leaf since symbolic_label is a leaf node
188+
elseif k == K"symboliclabel"
189+
# Must check BEFORE is_leaf since symboliclabel is a leaf node
190190
du_kill!(state)
191191
return true
192192

193193
elseif k == K"label"
194194
du_kill!(state)
195195
return false
196196

197-
elseif k in KSet"break symbolic_goto"
197+
elseif k in KSet"break symbolicgoto"
198198
# this kill!() is not required for soundness since these are branch points
199199
# not merge points, but it's here for parity with flisp
200200
du_kill!(state)

0 commit comments

Comments
 (0)