Skip to content

Commit d598515

Browse files
committed
IRGen: Fix some more incorrect conformance checks
1 parent 5d7e502 commit d598515

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

lib/IRGen/GenArchetype.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ const TypeInfo *TypeConverter::convertArchetypeType(ArchetypeType *archetype) {
414414
IGM.getSwiftModule()->getASTContext().getProtocol(
415415
KnownProtocolKind::BitwiseCopyable);
416416
// The protocol won't be present in swiftinterfaces from older SDKs.
417-
if (bitwiseCopyableProtocol && IGM.getSwiftModule()->lookupConformance(
417+
if (bitwiseCopyableProtocol && IGM.getSwiftModule()->checkConformance(
418418
archetype, bitwiseCopyableProtocol)) {
419419
return BitwiseCopyableTypeInfo::create(storageType, abiAccessible);
420420
}

lib/IRGen/GenEnum.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -7303,17 +7303,19 @@ ResilientEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
73037303
SILType Type,
73047304
EnumDecl *theEnum,
73057305
llvm::StructType *enumTy) {
7306+
auto cp = !theEnum->canBeCopyable()
7307+
? IsNotCopyable : IsCopyable;
73067308
auto abiAccessible = IsABIAccessible_t(TC.IGM.isTypeABIAccessible(Type));
73077309
auto *bitwiseCopyableProtocol =
73087310
IGM.getSwiftModule()->getASTContext().getProtocol(
73097311
KnownProtocolKind::BitwiseCopyable);
73107312
if (bitwiseCopyableProtocol &&
7311-
IGM.getSwiftModule()->lookupConformance(
7312-
theEnum->getDeclaredInterfaceType(), bitwiseCopyableProtocol)) {
7313+
IGM.getSwiftModule()->checkConformance(Type.getASTType(),
7314+
bitwiseCopyableProtocol)) {
73137315
return BitwiseCopyableTypeInfo::create(enumTy, abiAccessible);
73147316
}
73157317
return registerEnumTypeInfo(
7316-
new ResilientEnumTypeInfo(*this, enumTy, Copyable,
7318+
new ResilientEnumTypeInfo(*this, enumTy, cp,
73177319
abiAccessible));
73187320
}
73197321

lib/IRGen/GenStruct.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1706,8 +1706,7 @@ const TypeInfo *TypeConverter::convertStructType(TypeBase *key, CanType type,
17061706
IGM.getSwiftModule()->getASTContext().getProtocol(
17071707
KnownProtocolKind::BitwiseCopyable);
17081708
if (bitwiseCopyableProtocol &&
1709-
IGM.getSwiftModule()->lookupConformance(D->getDeclaredInterfaceType(),
1710-
bitwiseCopyableProtocol)) {
1709+
IGM.getSwiftModule()->checkConformance(type, bitwiseCopyableProtocol)) {
17111710
return BitwiseCopyableTypeInfo::create(IGM.OpaqueTy, structAccessible);
17121711
}
17131712
return &getResilientStructTypeInfo(copyable, structAccessible);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public struct BitwiseStruct<T> {
2+
var t: T
3+
4+
public init(t: T) { self.t = t }
5+
}
6+
7+
extension BitwiseStruct: BitwiseCopyable where T: BitwiseCopyable {}
8+
9+
public enum BitwiseEnum<T> {
10+
case t(T)
11+
}
12+
13+
extension BitwiseEnum: BitwiseCopyable where T: BitwiseCopyable {}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift-dylib(%t/%target-library-name(bitwise_copyable_other)) -enable-library-evolution %S/Inputs/bitwise_copyable_other.swift -emit-module -emit-module-path %t/bitwise_copyable_other.swiftmodule -module-name bitwise_copyable_other
4+
// RUN: %target-codesign %t/%target-library-name(bitwise_copyable_other)
5+
6+
// RUN: %target-build-swift %s -lbitwise_copyable_other -I %t -L %t -o %t/main %target-rpath(%t)
7+
// RUN: %target-codesign %t/main
8+
9+
// RUN: %target-run %t/main %t/%target-library-name(bitwise_copyable_other)
10+
11+
// REQUIRES: executable_test
12+
13+
import StdlibUnittest
14+
import bitwise_copyable_other
15+
16+
var bitwise = TestSuite("BitwiseCopyable")
17+
18+
bitwise.test("Conditional conformance with resilient struct") {
19+
func callee(_: consuming BitwiseStruct<LifetimeTracked>) {}
20+
21+
for _ in 0..<10 {
22+
callee(BitwiseStruct(t: LifetimeTracked(0)))
23+
}
24+
}
25+
26+
bitwise.test("Conditional conformance with resilient enum") {
27+
func callee(_: consuming BitwiseEnum<LifetimeTracked>) {}
28+
29+
for _ in 0..<10 {
30+
callee(BitwiseEnum.t(LifetimeTracked(0)))
31+
}
32+
}
33+
34+
runAllTests()

0 commit comments

Comments
 (0)