Skip to content
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

[Compile Time Constant Extraction] Query nominal type *conformances* to get at the protocols, instead of getAllProtocols(). #74698

Merged

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented Jun 25, 2024

As it stands, for extension macros which add protocol conformances, the list of protocols specified on the macro's conformances: parameter gets added in its entirety to the list of a nominal type's protocols in ConformanceLookupTable::addMacroGeneratedProtocols. Whereas the macro itself, may only add some of the specified conformances. This means that getAllProtocols() may contain a super-set of protocols captured in getAllConformances, some of which may not actually be generated by the macro.

This change narrowly fixes ConstExtract to query actual generated conformances. Though, potentially we should make ConformanceLookupTable::addMacroGeneratedProtocols behave in a way that reflects the protocols the macro actually adds the conformances to, instead of the ones it may add conformances to.

Resolves rdar:https://130316531

… get at the protocols, instead of `getAllProtocols`.

As it stands, for extension macros which add protocol conformances, the list of protocols specified on the macro's 'conformances:' parameter gets added in its entirety to the list of a nominal type's protocols in 'ConformanceLookupTable::addMacroGeneratedProtocols'. Whereas the macro itself, may only add *some* of the specified conformances. This means that `getAllProtocols` may contain a super-set of protocols captured in `getAllConformances`, some of which may not actually be generated by the macro.

This change narrowly fixes ConstExtract to query actual generated conformances. Though, potentially we should make 'ConformanceLookupTable::addMacroGeneratedProtocols' behave in a way that reflects the protocols the macro actually adds the conformances to, instead of the ones it may add conformances to.

Resolves rdar:https://130316531
@artemcm
Copy link
Contributor Author

artemcm commented Jun 25, 2024

@hborla, @slavapestov
From https://github.com/swiftlang/swift-evolution/blob/main/proposals/0402-extension-macros.md#suppressing-redundant-conformances:

The following restrictions apply to generated conformances and names listed in @attached(extension):

  • An extension macro cannot add a conformance to a protocol that is not covered by the conformances: list in @attached(extension, conformances:).
  • An extension macro cannot add a member that is not covered by the names: list in @attached(extension, names:).
  • An extension macro cannot introduce an extension with an attached peer macro, because the peer-macro-generated names are not covered by the original @attached(extension) attribute.

It is my reading of this that there is no reason that the macro may choose to conditionally avoid adding a conformance to a protocol specified in conformances:. In which case, should addMacroGeneratedProtocols add them all unconditionally?

@artemcm
Copy link
Contributor Author

artemcm commented Jun 25, 2024

@swift-ci test

@artemcm artemcm merged commit 3e8e44d into swiftlang:main Jun 27, 2024
5 checks passed
@artemcm artemcm deleted the ConstExtractConformanceExtractionFix branch June 27, 2024 16:56
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.

None yet

2 participants