Skip to content

Conversation

@mlechu
Copy link
Member

@mlechu mlechu commented Jan 17, 2026

(TODO write more, clean up changes)

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 Attempt to define the AST 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.@docsystem 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.

stdlib status: There shouldn't be any regressions, and TOML now compiles. LibGit2 is now blocked by a different bug.

Atop #60710

Three small changes, none worth doing out of context of the EST change:

- Remove `extension` and just use the three heads it represented (`locals`,
     `islocal`, `isglobal`) directly.  This is a reasonable idea that we could
     try again sometime with more of the kinds under `BEGIN_EXTENSION_KINDS`.
      For now, we aren't constrained in the `Kind` namespace, and it's worth
     reducing non-simplifying differences between trees.

- Use `inert_syntaxtree` instead of a meta-hint on `inert`.  This is mainly so
     it's representable in Expr, but is also visually clearer in debugging since
     it's never ambiguous what tree kind we want.  This required adding it to
     various "ignored forms" checks, but I plan to clean these up as we figure
     out the set of allowed forms in each pass.

- Tweak `hygienic_scope` to be `hygienic-scope`.  Dumb, but this is one of the
     very few expr-specific, macro-expansion-specific heads that should be
     spelled the same, since there isn't any good opportunity to convert it.
This change moves the separation of the generated and non-generated function
     body ahead of desugaring using a new `(generated_function callex gen_body
     nongen_body)` form.  Previously, desugaring would search for an
     `(if (generated) gen_ex nongen_ex)` form in the function body, then create
     a method with body `(stuff_surrounding_if_expression... $gen_ex)`.
      However, our pre-desugaring (and soon AST conversion) alter
     `stuff_surrounding_if_expression` in a way we can't correctly convert back
     to Expr.  This PR handles quoting of the generated body at the same time
     everything else is quoted.
@mlechu mlechu requested review from c42f and topolarity January 17, 2026 01:37
@mlechu mlechu force-pushed the est-4 branch 2 times, most recently from 4b5da92 to 0bb3340 Compare January 17, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant