Skip to content

Commit 31c761f

Browse files
committed
IRGen: Fix some more incorrect conformance checks
1 parent eb19dda commit 31c761f

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

lib/IRGen/GenArchetype.cpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7296,17 +7296,19 @@ ResilientEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
72967296
SILType Type,
72977297
EnumDecl *theEnum,
72987298
llvm::StructType *enumTy) {
7299+
auto cp = !theEnum->canBeCopyable()
7300+
? IsNotCopyable : IsCopyable;
72997301
auto abiAccessible = IsABIAccessible_t(TC.IGM.isTypeABIAccessible(Type));
73007302
auto *bitwiseCopyableProtocol =
73017303
IGM.getSwiftModule()->getASTContext().getProtocol(
73027304
KnownProtocolKind::BitwiseCopyable);
73037305
if (bitwiseCopyableProtocol &&
7304-
IGM.getSwiftModule()->lookupConformance(
7305-
theEnum->getDeclaredInterfaceType(), bitwiseCopyableProtocol)) {
7306+
IGM.getSwiftModule()->checkConformance(Type.getASTType(),
7307+
bitwiseCopyableProtocol)) {
73067308
return BitwiseCopyableTypeInfo::create(enumTy, abiAccessible);
73077309
}
73087310
return registerEnumTypeInfo(
7309-
new ResilientEnumTypeInfo(*this, enumTy, Copyable,
7311+
new ResilientEnumTypeInfo(*this, enumTy, cp,
73107312
abiAccessible));
73117313
}
73127314

lib/IRGen/GenStruct.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,8 +1705,7 @@ const TypeInfo *TypeConverter::convertStructType(TypeBase *key, CanType type,
17051705
IGM.getSwiftModule()->getASTContext().getProtocol(
17061706
KnownProtocolKind::BitwiseCopyable);
17071707
if (bitwiseCopyableProtocol &&
1708-
IGM.getSwiftModule()->lookupConformance(D->getDeclaredInterfaceType(),
1709-
bitwiseCopyableProtocol)) {
1708+
IGM.getSwiftModule()->checkConformance(type, bitwiseCopyableProtocol)) {
17101709
return BitwiseCopyableTypeInfo::create(IGM.OpaqueTy, structAccessible);
17111710
}
17121711
return &getResilientStructTypeInfo(copyable, structAccessible);
Lines changed: 13 additions & 0 deletions
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 {}
Lines changed: 34 additions & 0 deletions
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)