Skip to content

Conversation

@vtjnash
Copy link
Member

@vtjnash vtjnash commented May 12, 2023

This prepares us to delete the separate hygiene pass, and make it part of lowering resolve-scopes. This affects a few macros which expect to run macroexpand then mangle the result more, and the result of those macros is not already wrapped in esc(). The damage seems relatively minor however, and generally a good improvement.

@vtjnash vtjnash added macros @macros minor change Marginal behavior change acceptable for a minor release labels May 12, 2023
@vtjnash vtjnash requested a review from JeffBezanson May 12, 2023 16:35
@vtjnash
Copy link
Member Author

vtjnash commented May 16, 2023

@nanosoldier runtests()

@nanosoldier
Copy link
Collaborator

Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.

@vtjnash
Copy link
Member Author

vtjnash commented May 18, 2023

Some findings so far (to be updated):

@vtjnash vtjnash marked this pull request as draft May 19, 2023 23:33
This prepares us to delete the separate hygiene pass, and make it part
of lowering resolve-scopes. This affects a few macros which expect to
run macroexpand then mangle the result more, and the result of those
macros is not already wrapped in `esc()`. The damage seems relatively
minor however, and generally a good improvement.
vtjnash added a commit that referenced this pull request Aug 29, 2025
Setting `legacyscope=false` is intended to make it much easier to debug
and test macro expansion, since it no longer runs a buggy symbol
mangling pass automatically. Adding the mutating version
(`macroexpand!`) is mainly a handy way to opt in to the new
legacyscope=true, without needing to spell that out.

More background: the macroexpand.scm pass design is buggy, so we'd like
to stop using in the future. Currently changing the default causes
visible breakage to a lot of buggy packages tests, so for now just
provide the option to skip the legacy scope resolution. This is a
continuation of #49793 and a
prerequisite for eventually replacing the flisp code with JuliaLowering
(once we can deprecate this parameter).

Implement in-place macro expansion with `macroexpand!` (no corresponding
`@macroexpand!`) that avoids copying AST nodes when the original
expression is no longer needed anyways. But more importantly, add a
`legacyscope::Bool` keyword argument to the functions that allows opting
out of the legacy scope mangling.

Changes:
- Consolidate `jl_macroexpand` C functions with added parameters for
`recursive`, `inplace`, and the (legacy) `expand_scope` control.
- Add `macroexpand!` Julia function with `legacyscope=false` default.
- Update `macroexpand` to have `legacyscope` (default `true`) for
backward compatibility, until v2 or earlier.

Added to backporting so that new code can start to be written with
`legacyscope=false`. Not entirely a new feature, since this is just
adding the ability to disable an old (long deprecated) feature.

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

Labels

macros @macros minor change Marginal behavior change acceptable for a minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants