Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lib/SIL/IR/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3038,6 +3038,15 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,

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

if (auto *nominal = substType.getAnyNominal()) {
auto *module = nominal->getModuleContext();
if (module && module->isBuiltFromInterface()) {
// Don't verify for types in modules built from interfaces; the feature
// may not have been enabled in them.
return;
}
}

if (lowering.isTrivial() && !conformance) {
// A trivial type can lack a conformance in a few cases:
// (1) containing or being a resilient type
Expand All @@ -3054,6 +3063,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
// struct S {
// unowned(unsafe) var o: AnyObject
// }
// (5) being defined in a different module
bool hasNoNonconformingNode = visitAggregateLeaves(
origType, substType, forExpansion,
/*isLeafAggregate=*/
Expand All @@ -3072,7 +3082,11 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
}

// Resilient trivial types may not conform (case (1)).
return nominal->isResilient();
if (nominal->isResilient())
return true;

// Trivial types from other modules may not conform (case (5)).
return nominal->getModuleContext() != &M;
},
/*visit=*/
[&](auto ty, auto origTy, auto *field, auto index) -> bool {
Expand Down Expand Up @@ -3128,7 +3142,11 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
}

// Resilient trivial types may not conform (case (1)).
return !nominal->isResilient();
if (nominal->isResilient())
return false;

// Trivial types from other modules may not conform (case (5)).
return nominal->getModuleContext() == &M;
});
if (hasNoNonconformingNode) {
llvm::errs() << "Trivial type without a BitwiseCopyable conformance!?:\n"
Expand Down
6 changes: 6 additions & 0 deletions test/IRGen/bitwise_copyable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
// RUN: -enable-builtin-module

// REQUIRES: asserts
// REQUIRES: objc_interop

// Force verification of TypeLowering's isTrivial.

import Foundation
import Builtin

struct Box<T : _BitwiseCopyable> : _BitwiseCopyable {
Expand All @@ -32,3 +34,7 @@ func nameBuiltinBridgeObject(_ b: Builtin.BridgeObject) {}
func nameBuiltinUnsafeValueBuffer(_ b: Builtin.UnsafeValueBuffer) {}
func nameBuiltinDefaultActorStorage(_ b: Builtin.DefaultActorStorage) {}
func nameBuiltinNonDefaultDistributedActorStorage(_ b: Builtin.NonDefaultDistributedActorStorage) {}

struct MyObjCBool {
var value: ObjCBool
}