Skip to content

Conversation

@mlechu
Copy link
Member

@mlechu mlechu commented Nov 19, 2025

Moved from JuliaLang/JuliaLowering.jl#114 with tests added


I didn't originally implement this correctly: toplevel forms coming from macro expansions only need tweaking if we're in some scope layer other than the default one.

@mlechu mlechu requested a review from c42f November 19, 2025 00:38
@mlechu mlechu added the compiler:lowering Syntax lowering (compiler front end, 2nd stage) label Nov 19, 2025
@mlechu mlechu force-pushed the jl-moved-escapable-toplevel branch from ad93407 to 2315530 Compare November 19, 2025 15:23
Copy link
Member

@topolarity topolarity left a comment

Choose a reason for hiding this comment

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

Reasoning seems sound 👍

Change looks good to me

expand_macro(ctx, ex)
elseif k == K"toplevel" && length(ctx.scope_layer_stack) > 1
fix_toplevel_expansion(ctx, ex, current_layer(ctx).mod,
source_location(LineNumberNode, ex))
Copy link
Member

Choose a reason for hiding this comment

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

This seems to change the LineNumberNode slightly (allows file === nothing), but I guess we don't use this in lowering right now.

Does this affect anything?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, as the file === nothing -> file = :none case above is just for passing line number nodes to buggy macros (buggy assuming file is generally allowed to be anything). We could try always normalizing file to string or symbol everywhere in lowering, but that would be hard to do completely since these things can be values as well.

Copy link
Member

Choose a reason for hiding this comment

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

Is the argument used though? it seems like macro expansion just drops it right now

Copy link
Member Author

Choose a reason for hiding this comment

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

It's used in the expr-macro case

@topolarity topolarity merged commit b95df09 into JuliaLang:master Nov 19, 2025
8 checks passed
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