Skip to content

Commit 8621742

Browse files
committed
[BitwiseCopyable] Don't infer for packages types.
Like public and @usableFromInline types, package types too are exported. In the case of a module built with library evolution, they may cease to conform in the future. Apply the same rule regardless of that build configuration.
1 parent 4d8c842 commit 8621742

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,7 +3056,7 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30563056

30573057
if (lowering.isTrivial() && !conformance) {
30583058
// A trivial type can lack a conformance in a few cases:
3059-
// (1) containing or being a public, non-frozen type
3059+
// (1) containing or being a exported, non-frozen type
30603060
// (2) containing or being a generic type which doesn't conform
30613061
// unconditionally but in this particular instantiation is trivial
30623062
// (3) being a special type that's not worth forming a conformance for
@@ -3089,11 +3089,11 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30893089
return true;
30903090
}
30913091

3092-
// Public, non-frozen trivial types may not conform (case (1)).
3092+
// Exported, non-frozen trivial types may not conform (case (1)).
30933093
if (nominal
30943094
->getFormalAccessScope(/*useDC=*/nullptr,
30953095
/*treatUsableFromInlineAsPublic=*/true)
3096-
.isPublic())
3096+
.isPublicOrPackage())
30973097
return true;
30983098

30993099
auto *module = nominal->getModuleContext();
@@ -3159,11 +3159,11 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31593159
return false;
31603160
}
31613161

3162-
// Public, non-frozen trivial types may not conform (case (1)).
3162+
// Exported, non-frozen trivial types may not conform (case (1)).
31633163
if (nominal
31643164
->getFormalAccessScope(/*useDC=*/nullptr,
31653165
/*treatUsableFromInlineAsPublic=*/true)
3166-
.isPublic())
3166+
.isPublicOrPackage())
31673167
return false;
31683168

31693169
auto *module = nominal->getModuleContext();

lib/Sema/TypeCheckBitwise.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ getImplicitCheckForNominal(NominalTypeDecl *nominal) {
5757
if (!nominal
5858
->getFormalAccessScope(
5959
/*useDC=*/nullptr, /*treatUsableFromInlineAsPublic=*/true)
60-
.isPublic())
60+
.isPublicOrPackage())
6161
return {BitwiseCopyableCheck::Implicit};
6262

6363
if (nominal->hasClangNode() ||

test/Sema/bitwise_copyable_package_resilience.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
//--- Library.swift
2323

24-
// !public => conforms
24+
// package => exported => !inferred
2525
package struct PackageStruct {
2626
package var int: Int
2727
}
2828

29-
// Public => !conforms
29+
// public => exported => !inferred
3030
public struct PublicStruct {
3131
public var int: Int
3232
}
@@ -36,7 +36,8 @@ import Library
3636

3737
func take<T : _BitwiseCopyable>(_ t: T) {}
3838

39-
func passPackageStruct(_ s: PackageStruct) { take(s) }
39+
func passPackageStruct(_ s: PackageStruct) { take(s) } // expected-error{{type_does_not_conform_decl_owner}}
40+
// expected-note@-3{{where_requirement_failure_one_subst}}
4041

4142
func passPublicStruct(_ s: PublicStruct) { take(s) } // expected-error{{type_does_not_conform_decl_owner}}
42-
// expected-note@-5{{where_requirement_failure_one_subst}}
43+
// expected-note@-6{{where_requirement_failure_one_subst}}

0 commit comments

Comments
 (0)