Skip to content

Rework mangling of macro expansions in local contexts to not trigger type checking #77999

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

Merged

Conversation

DougGregor
Copy link
Member

The mangling of macro expansions relies on having a type-checked AST for its enclosing context. When that enclosing context is within a local context (say, a local type), mangling would trigger type checking of that local type, which could then involve assigning local discriminators. However, if this happens before type checking of the enclosing function body, we would end up failing to assign closure discriminators to (e.g.) autoclosures within the body.

The fundamental problem here is the interaction between discriminator assignment (which can only happen after type checking) and mangling of macro expansion buffers (which can happen during that type checking). Break this cycle by providing a different approach to mangling macro expansions within local contexts as the innermost non-local context + a name-based discriminator within that local context. These manglings are not ABI and are not stable, so we can adjust them later if we come up with a scheme we like better. However, by breaking this cycle, we eliminate assertions and miscompiles that come from missing discriminators in this case.

Fixes rdar://139734958.

…type checking.

The mangling of macro expansions relies on having a type-checked AST
for its enclosing context. When that enclosing context is within a
local context (say, a local type), mangling would trigger type
checking of that local type, which could then involve assigning local
discriminators. However, if this happens before type checking of the
enclosing function body, we would end up failing to assign closure
discriminators to (e.g.) autoclosures within the body.

The fundamental problem here is the interaction between discriminator
assignment (which can only happen after type checking) and mangling of
macro expansion buffers (which can happen during that type checking).
Break this cycle by providing a different approach to mangling macro
expansions within local contexts as the innermost non-local context +
a name-based discriminator within that local context. These manglings
are not ABI and are not stable, so we can adjust them later if we come
up with a scheme we like better. However, by breaking this cycle, we
eliminate assertions and miscompiles that come from missing
discriminators in this case.

Fixes rdar://139734958.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Windows

@DougGregor DougGregor merged commit 64fb19b into swiftlang:main Dec 6, 2024
3 checks passed
@DougGregor DougGregor deleted the local-macro-expansion-mangling branch December 6, 2024 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant