Skip to content

Commit 40b1fd7

Browse files
committed
[BitwiseCopyable] Verify only within module.
Don't verify lowering in modules built from swiftinterface (which may not have been built with `-enable-experimental-feature BitwiseCopyable`) Allow trivial types defined in other modules to lack conformance because those modules may not have been built with the feature enabled.
1 parent c13422d commit 40b1fd7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,6 +3038,15 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30383038

30393039
auto conformance = M.checkConformance(substType, bitwiseCopyableProtocol);
30403040

3041+
if (auto *nominal = substType.getAnyNominal()) {
3042+
auto *module = nominal->getModuleContext();
3043+
if (module && module->isBuiltFromInterface()) {
3044+
// Don't verify for types in modules built from interfaces; the feature
3045+
// may not have been enabled in them.
3046+
return;
3047+
}
3048+
}
3049+
30413050
if (lowering.isTrivial() && !conformance) {
30423051
// A trivial type can lack a conformance in a few cases:
30433052
// (1) containing or being a resilient type
@@ -3054,6 +3063,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30543063
// struct S {
30553064
// unowned(unsafe) var o: AnyObject
30563065
// }
3066+
// (5) being defined in a different module
30573067
bool hasNoNonconformingNode = visitAggregateLeaves(
30583068
origType, substType, forExpansion,
30593069
/*isLeafAggregate=*/
@@ -3072,7 +3082,11 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30723082
}
30733083

30743084
// Resilient trivial types may not conform (case (1)).
3075-
return nominal->isResilient();
3085+
if (nominal->isResilient())
3086+
return true;
3087+
3088+
// Trivial types from other modules may not conform (case (5)).
3089+
return nominal->getModuleContext() != &M;
30763090
},
30773091
/*visit=*/
30783092
[&](auto ty, auto origTy, auto *field, auto index) -> bool {
@@ -3128,7 +3142,11 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31283142
}
31293143

31303144
// Resilient trivial types may not conform (case (1)).
3131-
return !nominal->isResilient();
3145+
if (nominal->isResilient())
3146+
return false;
3147+
3148+
// Trivial types from other modules may not conform (case (5)).
3149+
return nominal->getModuleContext() == &M;
31323150
});
31333151
if (hasNoNonconformingNode) {
31343152
llvm::errs() << "Trivial type without a BitwiseCopyable conformance!?:\n"

test/IRGen/bitwise_copyable.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// RUN: -enable-experimental-feature BitwiseCopyable \
66
// RUN: -enable-builtin-module
77

8+
import Foundation
9+
810
// REQUIRES: asserts
911

1012
// Force verification of TypeLowering's isTrivial.
@@ -32,3 +34,7 @@ func nameBuiltinBridgeObject(_ b: Builtin.BridgeObject) {}
3234
func nameBuiltinUnsafeValueBuffer(_ b: Builtin.UnsafeValueBuffer) {}
3335
func nameBuiltinDefaultActorStorage(_ b: Builtin.DefaultActorStorage) {}
3436
func nameBuiltinNonDefaultDistributedActorStorage(_ b: Builtin.NonDefaultDistributedActorStorage) {}
37+
38+
struct MyObjCBool {
39+
var value: ObjCBool
40+
}

0 commit comments

Comments
 (0)