Skip to content

[5.9] [Macros] Cope with local types and opaque result types in macros and expansions #67103

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

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Jul 3, 2023

  • Explanation: Fixes several issues with local types and opaque result types within macro arguments and expansions, which would manifest as link errors (missing symbols).
  • Scope: Narrow. Only changes behavior when local types and opaque result types are used in conjunction with macros.
  • Risk: Low due to narrow scope.
  • Original pull request: [Macros] Cope with local types and opaque result types in macros and expansions. #67099
  • Issue: 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 DougGregor requested a review from a team as a code owner July 3, 2023 23:11
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit b4d63bb into swiftlang:release/5.9 Jul 4, 2023
@DougGregor DougGregor deleted the macros-local-and-opaque-types-5.9 branch July 4, 2023 05:06
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