Skip to content

[6.2] Sema: Don't expand macros when binding extensions #82132

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

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Jun 10, 2025

6.2 cherry-pick of #82129.

  • Description: Extension binding could trigger macro expansion, which could perform name lookups, which would fail if not all extensions have been bound yet. In the radar, this manifested as intermittent type checking failures that depended on source file order. Fix this by first attempting extension binding without macro expansion, and then finally doing a second pass with macro expansion to get anything that truly requires it.

  • Origination: This was always broken.

  • Risk: Low.

  • Tested: Added a test case that fails with an expression checker diagnostic previously.

  • Radar: Fixes rdar://149798059.

  • Reviewed by: @rjmccall

@slavapestov slavapestov requested a review from a team as a code owner June 10, 2025 00:30
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov force-pushed the bind-extensions-macro-6.2 branch from ece05c2 to 490fd98 Compare June 12, 2025 00:12
Macro expansion can call typeCheckExpr(), which performs qualified
lookups. So if we expand macros while binding extensions, these
qualified lookups can fail because they cannot find members of
extensions that have not been bound yet.

To fix this, try binding extensions without performing macro
expansion first. If any extensions remain at the end, we fall back
to the old behavior, and try to bind them again, this time
performing macro expansion.

Fixes rdar://149798059.
@slavapestov slavapestov force-pushed the bind-extensions-macro-6.2 branch from 490fd98 to a10cc92 Compare June 13, 2025 20:00
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov merged commit acb53d2 into swiftlang:release/6.2 Jun 14, 2025
6 of 7 checks passed
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.

2 participants