Skip to content

Conversation

@mlechu
Copy link
Member

@mlechu mlechu commented Nov 18, 2025

Evaluating a macro's name should be done in the same world we pass into lowering and use for expansion. Fix this for all reasonable macro names.

The lowering iterator (currently very cold code only used for module/toplevel expressions that JuliaLowering "controls") also needs to update the expansion world between steps.

@mlechu mlechu requested a review from c42f November 18, 2025 22:25
@mlechu mlechu added the compiler:lowering Syntax lowering (compiler front end, 2nd stage) label Nov 18, 2025
@mlechu mlechu force-pushed the jl-iterator-world-age branch from 46674f4 to 84f90da Compare November 18, 2025 23:31
Comment on lines +74 to +78
ctx1 = let c = iter.ctx
MacroExpansionContext(
c.graph, c.bindings, c.scope_layers, c.scope_layer_stack,
c.expr_compat_mode, world)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be worth a separate helper / constructor

One common pattern is:

MacroExpansionContext(ctx::MacroExpansionContext; graph = ctx.graph, bindings = ctx.bindings, scope_layers = ctx.scope_layers, scope_layer_stack = ctx.scope_layer_stack, expr_compat_mode = ctx.expr_compat_mode, world = ctx.world) = MacroExpansionContext(graph, bindings, scope_layers, scope_layer_stack, expr_compat_mode, world)

ctx1 = MacroExpansionContext(iter.ctx; world = world)

Copy link
Member Author

@mlechu mlechu Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably just create a brand-new macro context for each step. I don't see why we need a big graph with everything in it, and it might mess with the ctx.scope_layers[1]-is-always-the-base-layer assumption from your fix in #60174

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:lowering Syntax lowering (compiler front end, 2nd stage)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants