Skip to content

Commit da772e9

Browse files
committed
[Runtime] Make swift::swift_conformsToSwiftProtocol overridable.
This is a funnel point for looking up the protocol conformance descriptor for a given conforming type + conformance. Make it overridable in case we need to back-deploy changes or fixes. Implements rdar://problem/46281660.
1 parent f9797b4 commit da772e9

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

stdlib/public/runtime/CompatibilityOverride.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ OVERRIDE_PROTOCOLCONFORMANCE(conformsToProtocol, const WitnessTable *, , swift::
130130
const ProtocolDescriptor *protocol),
131131
(type, protocol))
132132

133+
OVERRIDE_PROTOCOLCONFORMANCE(conformsToSwiftProtocol,
134+
const ProtocolConformanceDescriptor *, , swift::,
135+
(const Metadata * const type,
136+
const ProtocolDescriptor *protocol,
137+
StringRef moduleName),
138+
(type, protocol, moduleName))
139+
133140
OVERRIDE_KEYPATH(getKeyPath, const HeapObject *, , swift::,
134141
(const void *pattern, const void *arguments),
135142
(pattern, arguments))

stdlib/public/runtime/Private.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,9 @@ class TypeInfo {
510510
/// Determine whether the given type conforms to the given Swift protocol,
511511
/// returning the appropriate protocol conformance descriptor when it does.
512512
const ProtocolConformanceDescriptor *
513-
_conformsToSwiftProtocol(const Metadata * const type,
514-
const ProtocolDescriptor *protocol,
515-
StringRef module);
513+
swift_conformsToSwiftProtocol(const Metadata * const type,
514+
const ProtocolDescriptor *protocol,
515+
StringRef module);
516516

517517
/// Retrieve an associated type witness from the given witness table.
518518
///

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,10 +532,10 @@ namespace {
532532
};
533533
}
534534

535-
const ProtocolConformanceDescriptor *
536-
swift::_conformsToSwiftProtocol(const Metadata * const type,
537-
const ProtocolDescriptor *protocol,
538-
StringRef module) {
535+
static const ProtocolConformanceDescriptor *
536+
swift_conformsToSwiftProtocolImpl(const Metadata * const type,
537+
const ProtocolDescriptor *protocol,
538+
StringRef module) {
539539
auto &C = Conformances.get();
540540

541541
// See if we have a cached conformance. The ConcurrentMap data structure
@@ -601,7 +601,8 @@ swift::_conformsToSwiftProtocol(const Metadata * const type,
601601
static const WitnessTable *
602602
swift_conformsToProtocolImpl(const Metadata * const type,
603603
const ProtocolDescriptor *protocol) {
604-
auto description = _conformsToSwiftProtocol(type, protocol, StringRef());
604+
auto description =
605+
swift_conformsToSwiftProtocol(type, protocol, StringRef());
605606
if (!description)
606607
return nullptr;
607608

unittests/runtime/CompatibilityOverride.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ TEST_F(CompatibilityOverrideTest, test_swift_conformsToProtocol) {
168168
ASSERT_EQ(Result, nullptr);
169169
}
170170

171+
TEST_F(CompatibilityOverrideTest, test_swift_conformsToSwiftProtocol) {
172+
auto Result = swift_conformsToSwiftProtocol(nullptr, nullptr, StringRef());
173+
ASSERT_EQ(Result, nullptr);
174+
}
175+
171176
TEST_F(CompatibilityOverrideTest, test_swift_getTypeByMangledNode) {
172177
Demangler demangler;
173178
auto Result = swift_getTypeByMangledNode(demangler, nullptr, nullptr,

0 commit comments

Comments
 (0)