Skip to content

Rewrite most gensym macros to use automatic hygiene instead #59239

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Aug 8, 2025

Manual gensym code often contains a lot of mistakes, either because the
user uses something like . or +, or because it combines code from
multiple modules (gensym is only unique within a pre-compile unit). This
replaces most uses for macro local variables with proper scope markers.
I did not rewrite _lift_one_interp_helper or replace_ref_begin_end_
however, since, while possible by adding esc to every argument that
has not used a gensym value, if any other argument did is a value, I
worried that could lead to macroexpand.scm making more new mistakes so I
left if for a separate PR. Better yet, we could make a unhygienic-scope
and unescape pair for marking the inverse/dual of the usual operations
(marking a symbol as unescaped within a region of unhygienic (escaped)
code to make these various uses easier to implement.

But also do rewrite replace_ref_begin_end_ to respect argument order
and evaluation count (similar to its julia-syntax.scm counterpart) and
scoping (not adding let unpredictably).

Allows using meta.jl much earlier in the build (instead of importing
these from show.jl).
@vtjnash vtjnash changed the title Rewrite most gensym macros to use automatic hygiene instead [NFCI] Rewrite most gensym macros to use automatic hygiene instead Aug 8, 2025
@vtjnash vtjnash added compiler:lowering Syntax lowering (compiler front end, 2nd stage) macros @macros labels Aug 8, 2025
Manual `gensym` code often contains a lot of mistakes, either because the
user uses something like `.` or `+`, or because it combines code from
multiple modules (gensym is only unique within a pre-compile unit). This
replaces most uses for macro local variables with proper scope markers.
I did not rewrite `_lift_one_interp_helper` or `replace_ref_begin_end_`
however, since, while possible by adding `esc` to every argument that
has not used a gensym value, if any other argument did is a value, I
worried that could lead to macroexpand.scm making more new mistakes so I
left if for a separate PR. Better yet, we could make a unhygienic-scope
and unescape pair for marking the inverse/dual of the usual operations
(marking a symbol as unescaped within a region of unhygienic (escaped)
code to make these various uses easier to implement.

But rewrite `replace_ref_begin_end_` to respect argument order and
evaluation count (similar to its julia-syntax.scm counterpart) and
scoping (not adding `let` unpredictably).
@vtjnash vtjnash force-pushed the jn/gensym-deprecated branch from 4cf81b5 to c244cf7 Compare August 8, 2025 21:19
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) macros @macros
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant