Skip to content

Commit 21eaaaa

Browse files
Merge pull request #71632 from nate-chandler/bitwise-copyable/dont-infer-package
[BitwiseCopyable] Don't infer for packages types.
2 parents 3706583 + b4323c8 commit 21eaaaa

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 24 additions & 7 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
@@ -3072,13 +3072,21 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30723072
// }
30733073
// (5) being defined in a different module
30743074
// (6) being defined in a module built from interface
3075+
// (7) being or containing a variadic generic type which doesn't conform
3076+
// unconditionally but does in this case
3077+
// (8) being or containing the error type
30753078
bool hasNoNonconformingNode = visitAggregateLeaves(
30763079
origType, substType, forExpansion,
30773080
/*isLeafAggregate=*/
30783081
[&](auto ty, auto origTy, auto *field, auto index) -> bool {
3082+
// These show up in the context of non-conforming variadic generics
3083+
// which may lack a conformance (case (7)).
3084+
if (isa<SILPackType>(ty) || isa<PackExpansionType>(ty))
3085+
return true;
3086+
30793087
auto *nominal = ty.getAnyNominal();
3080-
// Non-nominal aggregates must not be responsible for non-conformance;
3081-
// walk into them.
3088+
// Only pack-related non-nominal aggregates may be responsible for
3089+
// non-conformance; walk into the rest.
30823090
if (!nominal)
30833091
return false;
30843092

@@ -3089,11 +3097,11 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
30893097
return true;
30903098
}
30913099

3092-
// Public, non-frozen trivial types may not conform (case (1)).
3100+
// Exported, non-frozen trivial types may not conform (case (1)).
30933101
if (nominal
30943102
->getFormalAccessScope(/*useDC=*/nullptr,
30953103
/*treatUsableFromInlineAsPublic=*/true)
3096-
.isPublic())
3104+
.isPublicOrPackage())
30973105
return true;
30983106

30993107
auto *module = nominal->getModuleContext();
@@ -3113,6 +3121,15 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31133121

31143122
auto isTopLevel = !field;
31153123

3124+
// The error type doesn't conform but is trivial (case (8)).
3125+
if (isa<ErrorType>(ty))
3126+
return false;
3127+
3128+
// These show up in the context of non-conforming variadic generics
3129+
// which may lack a conformance (case (7)).
3130+
if (isa<SILPackType>(ty) || isa<PackExpansionType>(ty))
3131+
return false;
3132+
31163133
// A BitwiseCopyable conformer appearing within its layout doesn't
31173134
// explain why substType doesn't itself conform.
31183135
if (M.checkConformance(ty, bitwiseCopyableProtocol))
@@ -3159,11 +3176,11 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31593176
return false;
31603177
}
31613178

3162-
// Public, non-frozen trivial types may not conform (case (1)).
3179+
// Exported, non-frozen trivial types may not conform (case (1)).
31633180
if (nominal
31643181
->getFormalAccessScope(/*useDC=*/nullptr,
31653182
/*treatUsableFromInlineAsPublic=*/true)
3166-
.isPublic())
3183+
.isPublicOrPackage())
31673184
return false;
31683185

31693186
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)