-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[5.9][Macros] Use source locations to determine whether to suppress macro expansions. #66578
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
hborla
merged 14 commits into
swiftlang:release/5.9
from
hborla:5.9-suppress-expansion-in-macro-argument
Jun 13, 2023
Merged
[5.9][Macros] Use source locations to determine whether to suppress macro expansions. #66578
hborla
merged 14 commits into
swiftlang:release/5.9
from
hborla:5.9-suppress-expansion-in-macro-argument
Jun 13, 2023
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
hborla
commented
Jun 12, 2023
- Explanation: A detailed explanation is in the description of [Macros] Use source locations to determine whether to suppress macro expansions. #66532. The short version is that this change fixes a source of bogus type checker errors that were caused by incorrectly identifying code as being part of a macro argument and excluding macro-generated names from name lookup as a result.
- Issue: rdar://109214279
- Risk: There's a moderate risk of new circular reference errors when applying macros, because the old approach was not sound and it would incorrectly suppress macro expansions for code that needs to expand macros. However, code that would produce circular reference errors is actually circular and needs to be changed. The current behavior will depend on the ordering of macro expansions, which is very bad, and this fix will eliminate that.
- Testing: Added new tests to the suite.
- Reviewer: @DougGregor
- Main branch PR: [Macros] Use source locations to determine whether to suppress macro expansions. #66532
…omAttributeScope so that it can represent the scope for any custom attribute and its arguments. This commit is NFC, but CustomAttributeScope is now applicable to attached macros. (cherry picked from commit abcdc6c)
(cherry picked from commit 2c0c596)
…s inside a macro argument. (cherry picked from commit cd79cf9)
(cherry picked from commit 2943064)
…APIs. This source location will be used to determine whether to add a name lookup option to exclude macro expansions when the name lookup request is constructed. Currently, the source location argument is unused. (cherry picked from commit cd752cc)
expansions. Evaluator::hasActiveResolveMacroRequest is now unused. (cherry picked from commit 61c99cc)
(cherry picked from commit db23cf5)
checker while type checking a freestanding macro argument in the same scope. (cherry picked from commit f9f63e3)
…arbitrary names at global scope. Freestanding and peer macros applied at top-level scope cannot introduce arbitrary names. Introducing arbitrary names means that any lookup into this scope must expand the macro. This is a problem, because resolving the macro can invoke type checking other declarations, e.g. anything that the macro arguments depend on. If _anything_ the macro depends on performs name unqualified name lookup, e.g. type resolution, we'll get circularity errors. It's better to prevent this by banning these macros at global scope if any of the macro candidates introduce arbitrary names. (cherry picked from commit 9824954)
… of a macro argument. (cherry picked from commit 0b91f63)
…lookup. (cherry picked from commit 706411d)
…ass. IDE inspection can delay parsing of particular declarations, so expanding ASTScopes during the first pass will miss those declarations. Clear any expanded scopes to force re-expansion during the second pass. (cherry picked from commit 51e1a39)
…ookup namespace. This moves the `isInMacroArgument` predicate and `lookupMacros` into `namelookup`. ASTScope still encapsulates the scope tree and contains the operation to lookup the enclosing macro scope, which then invokes a callback to determine whether a potential macro scope is indeed a macro, because answering this question requires name lookup. (cherry picked from commit 393b4ce)
(cherry picked from commit 2cc1204)
@swift-ci please test |
DougGregor
approved these changes
Jun 13, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.