[Macros] Allow extension macros to suppress conformances that are already

stated in the original source.

If an extension macro can introduce protocol conformances, macro expansion
will check which of those protocols already have a stated conformance in the
original source. The protocols that don't will be passed as arguments to
extension macro expansion, indicating to the macro that it should only add
conformances to those protocols.
This commit is contained in:
Holly Borla
2023-06-30 14:08:56 -07:00
parent e44c11f56f
commit 0bd898eb12
17 changed files with 305 additions and 23 deletions

View File

@@ -1961,6 +1961,17 @@ LookupConformanceInModuleRequest::evaluate(
if (!nominal || isa<ProtocolDecl>(nominal))
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
// Expand conformances added by extension macros.
//
// FIXME: This expansion should only be done if the
// extension macro can generate a conformance to the
// given protocol, but conformance macros do not specify
// that information upfront.
(void)evaluateOrDefault(
ctx.evaluator,
ExpandExtensionMacros{nominal},
{ });
// Find the (unspecialized) conformance.
SmallVector<ProtocolConformance *, 2> conformances;
if (!nominal->lookupConformance(protocol, conformances)) {