Skip to content

Commit a0fae92

Browse files
committed
[Runtime] Diagnose multiple retroactive conformances for X: P.
Thread a module name into the protocol conformance lookup function (e.g., the function implementing swift_conformsToProtocol), and compare that against the module context of retroactive conformances. When we don’t care where we find the resulting conformance (e.g., the module name is NULL), and more than one retroactive conformance found, produce a warning like this: ***Swift runtime warning: multiple conformances for 'RetroactiveCommon.CommonStruct: CommonP1' found in modules 'RetroactiveA' and 'RetroactiveB'. Arbitrarily selecting conformance from module 'RetroactiveA' This code will also be used to select specific conformances.
1 parent 8906b06 commit a0fae92

File tree

7 files changed

+292
-33
lines changed

7 files changed

+292
-33
lines changed

include/swift/ABI/Metadata.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,11 +2292,17 @@ struct TargetProtocolConformanceDescriptor final
22922292
return TypeRef.getTypeContextDescriptor(getTypeKind());
22932293
}
22942294

2295+
/// Whether this is a retroactive conformance.
2296+
bool isRetroactive() const {
2297+
return Flags.isRetroactive();
2298+
}
2299+
22952300
/// Retrieve the context of a retroactive conformance.
2296-
const TargetContextDescriptor<Runtime> *getRetroactiveContext() const {
2301+
ConstTargetPointer<Runtime, TargetContextDescriptor<Runtime>>
2302+
getRetroactiveContext() const {
22972303
if (!Flags.isRetroactive()) return nullptr;
22982304

2299-
return this->template getTrailingObjects<RelativeContextPointer<Runtime>>();
2305+
return *this->template getTrailingObjects<RelativeContextPointer<Runtime>>();
23002306
}
23012307

23022308
/// Whether this conformance is non-unique because it has been synthesized

stdlib/public/runtime/Private.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ class TypeInfo {
452452
ProtocolDescriptorRef protocol,
453453
const WitnessTable **conformance);
454454

455+
/// Determine whether the given type conforms to the given Swift protocol.
456+
const WitnessTable *
457+
_conformsToSwiftProtocol(const Metadata * const type,
458+
const ProtocolDescriptor *protocol,
459+
const char *module);
460+
455461
/// Given a type that we know conforms to the given protocol, find the
456462
/// superclass that introduced the conformance.
457463
const Metadata *findConformingSuperclass(const Metadata *type,

0 commit comments

Comments
 (0)