Skip to content

[Macros] Cope with local types and opaque result types in macros and expansions. #67099

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

Address a few related issues that affect local types and opaque result types within macros:

  • Don't add local types or opaque types encountered while parsing the arguments of a freestanding macro to the global list. When we do add them, make sure we're adding them to the outermost source file so they'll get seen later. This avoids trying to generate code for these types, because they aren't supposed to be part of the program. Note that a similar problem remains for arguments to attached macros, which will need to be addressed with a more significant refactoring.
  • When determining whether opaque types should be substituted within a resilience domain, check the outermost source files rather than the exact source file, otherwise we will end up with a mismatch in argument-passing conventions.
  • When delaying the type checking of functions that occur as part of a macro expansion, make sure we record them in the outermost Swift source file. Otherwise, we won't come back to them.

There is a common theme here of using AST state on the source file in a manner that isn't ideal, and starts to break down with macros. In these cases, we're relying on side effects from earlier phases (parsing and type checking) to inform later phases, rather than properly expressing the dependencies through requests.

Fixes rdar://110674997&110713264.

…expansions

Address a few related issues that affect local types and opaque result types within macros:
* Don't add local types or opaque types encountered while parsing the
arguments of a freestanding macro to the global list. When we do add
them, make sure we're adding them to the outermost source file so
they'll get seen later. This avoids trying to generate code for these
types, because they aren't supposed to be part of the program. Note
that a similar problem remains for arguments to attached macros, which
will need to be addressed with a more significant refactoring.
* When determining whether opaque types should be substituted within a
resilience domain, check the outermost source files rather than the exact
source file, otherwise we will end up with a mismatch in
argument-passing conventions.
* When delaying the type checking of functions that occur as part of a
macro expansion, make sure we record them in the outermost Swift source
file. Otherwise, we won't come back to them.

There is a common theme here of using AST state on the source file in
a manner that isn't ideal, and starts to break down with macros. In
these cases, we're relying on side effects from earlier phases
(parsing and type checking) to inform later phases, rather than
properly expressing the dependencies through requests.

Fixes rdar://110674997&110713264.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit 5f2beba into swiftlang:main Jul 4, 2023
@DougGregor DougGregor deleted the macros-local-and-opaque-types branch July 4, 2023 02:52
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