Skip to content

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

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 17, 2023

Conversation

hborla
Copy link
Member

@hborla hborla commented Apr 17, 2023

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.

Fixes rdar://107962528.

…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.
@hborla hborla requested a review from DougGregor April 17, 2023 17:35
@hborla
Copy link
Member Author

hborla commented Apr 17, 2023

@swift-ci please smoke test

@hborla
Copy link
Member Author

hborla commented Apr 17, 2023

@swift-ci please smoke test macOS

@hborla hborla merged commit 273a400 into swiftlang:main Apr 17, 2023
@hborla hborla deleted the nested-conformance-macros branch April 17, 2023 23:01
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