Skip to content

[5.9][Macros] Fix visiting nested conformance macro declarations in SIL and IRGen. #65237

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
merged 1 commit into from
Apr 18, 2023

Conversation

hborla
Copy link
Member

@hborla hborla commented Apr 17, 2023

  • Explanation: When expanding a conformance macro, the generated extension decls are added to the TopLevelDecls vector of the synthesized file unit to expose them to sf->getSynthesizedFile()->getTopLevelDecls(). There are two problems with this:
  1. These decls are also visited via visitAuxiliaryDecls() for the purpose of type checking. This causes problems in code generation because the extensions are visited separately, and because SIL and IRGen assume nested auxiliary decls are members.

  2. SILGen only emits top-level decls directly from the source file rather than its synthesized file. Auxiliary decls are visited here, but this doesn't work for nested conformance macros because the attached-to decl is not at the top-level, so macro-generated conformances for nested types never emit their descriptor.

    To fix this in the short term, visit top-level decls in the synthesized file that are generated by conformance macros, and skip auxiliary extension decls when emitting type members. This fix is narrowly scoped to only impact macros, but in the future this warrants a more structural fix to better handle top-level decls in the synthesized file.

…d IRGen.

When expanding a conformance macro, the generated extension decls are added to
the TopLevelDecls vector of the synthesized file unit to expose them to
sf->getSynthesizedFile()->getTopLevelDecls(). There are two problems with this:

  1. These decls are also visited via visitAuxiliaryDecls() for the purpose of
     type checking. This causes problems in code generation because the extensions
     are visited separately, and because SIL and IRGen assume nested auxiliary decls
     are members.
  2. SILGen only emits top-level decls directly from the source file rather than its
     synthesized file. Auxiliary decls are visited here, but this doesn't work for
     nested conformance macros because the attached-to decl is not at the top-level,
     so macro-generated conformances for nested types never emit their descriptor.

To fix this in the short term, visit top-level decls in the synthesized file that are
generated by conformance macros, and skip auxiliary extension decls when emitting type
members. This fix is narrowly scoped to only impact macros, but in the future this
warrants a more structural fix to better handle top-level decls in the synthesized file.

(cherry picked from commit ae32673)
@hborla hborla requested a review from a team as a code owner April 17, 2023 23:14
@hborla
Copy link
Member Author

hborla commented Apr 17, 2023

@swift-ci please test

@hborla hborla merged commit c9969a1 into swiftlang:release/5.9 Apr 18, 2023
@hborla hborla deleted the 5.9-nested-conformance-macros branch April 18, 2023 04:55
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants