Skip to content

Commit cd09269

Browse files
committed
IRGen: metadata for noncopyable exist. metatype
Missed a case when determining the strategy to use for obtaining the metadata for a noncopyable existential metatype. Without this patch, trying to use a metatype like `any ~Copyable.Type` can cause a crash at runtime when setting a deployment target that predates Swift 6.0, due to that runtime not knowing how to demangle inverses. resolves rdar://134280902
1 parent bd15da6 commit cd09269

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/IRGen/GenReflection.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ getRuntimeVersionThatSupportsDemanglingType(CanType type) {
245245
}
246246
}
247247

248+
// Any composition with an inverse will need the 6.0 runtime to demangle.
249+
if (auto pct = dyn_cast<ProtocolCompositionType>(t)) {
250+
if (pct->hasInverse())
251+
return addRequirement(Swift_6_0);
252+
}
253+
248254
return false;
249255
});
250256

test/IRGen/noncopyable_metadata_requests.swift

+14
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,17 @@ func testNOTCopyableOptional() {
126126
}
127127
testNOTCopyableOptional()
128128
// CHECK: Optional.bar(2)
129+
130+
131+
// NEW: define hidden swiftcc void @"$s4main26check_existential_metatype4withyypRi_s_XPXpSg_tF"
132+
// NEW: call ptr @__swift_instantiateConcreteTypeFromMangledName(ptr @"$sypRi_s_XPXpSgMD")
133+
// NEW: }
134+
135+
// OLD: define hidden swiftcc void @"$s4main26check_existential_metatype4withyypRi_s_XPXpSg_tF"
136+
// OLD: call swiftcc %swift.metadata_response @"$sypRi_s_XPXpSgMa"
137+
// OLD: }
138+
func check_existential_metatype(with x: (any ~Copyable.Type)?) {
139+
x.map { print("passed type = \($0)") }
140+
}
141+
check_existential_metatype(with: NC.self)
142+
// CHECK: passed type = NC

0 commit comments

Comments
 (0)