Skip to content

Commit a24c448

Browse files
Merge pull request #77512 from nate-chandler/rdar139448358
[FixedArray] Fix BitwiseCopyable inference.
2 parents 3793c37 + d06d5bb commit a24c448

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

lib/AST/Builtins.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,11 +3385,12 @@ bool BuiltinType::isBitwiseCopyable() const {
33853385
return false;
33863386

33873387
case BuiltinTypeKind::BuiltinFixedArray: {
3388-
// Bitwise-copyability depends on the element type.
3388+
// FixedArray<N, X> : BitwiseCopyable whenever X : BitwiseCopyable
33893389
auto bfa = cast<BuiltinFixedArrayType>(this);
33903390
auto &C = bfa->getASTContext();
3391-
return (bool)lookupConformance(bfa->getElementType(),
3392-
C.getProtocol(KnownProtocolKind::BitwiseCopyable));
3391+
return (bool)checkConformance(
3392+
bfa->getElementType(),
3393+
C.getProtocol(KnownProtocolKind::BitwiseCopyable));
33933394
}
33943395
}
33953396
}

lib/SIL/IR/TypeLowering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,7 @@ bool TypeConverter::visitAggregateLeaves(
30003000
return isa<SILPackType>(ty) ||
30013001
isa<TupleType>(ty) ||
30023002
isa<PackExpansionType>(ty) ||
3003+
isa<BuiltinFixedArrayType>(ty) ||
30033004
ty.getEnumOrBoundGenericEnum() ||
30043005
ty.getStructOrBoundGenericStruct();
30053006
};
@@ -3036,6 +3037,13 @@ bool TypeConverter::visitAggregateLeaves(
30363037
insertIntoWorklist(expansion.getPatternType(),
30373038
origTy.getPackExpansionPatternType(),
30383039
field, index);
3040+
} else if (auto array = dyn_cast<BuiltinFixedArrayType>(ty)) {
3041+
auto origBFA = origTy.getAs<BuiltinFixedArrayType>();
3042+
insertIntoWorklist(
3043+
array->getElementType(),
3044+
AbstractionPattern(origTy.getGenericSignatureOrNull(),
3045+
origBFA->getElementType()),
3046+
field, index);
30393047
} else if (auto *decl = ty.getStructOrBoundGenericStruct()) {
30403048
for (auto *structField : decl->getStoredProperties()) {
30413049
auto subMap = ty->getContextSubstitutionMap();

test/SILGen/bitwise_copyable.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
// RUN: %target-swift-frontend \
2-
// RUN: %s \
3-
// RUN: -emit-silgen \
4-
// RUN: -target %target-swift-5.1-abi-triple \
5-
// RUN: -enable-experimental-feature Sensitive \
1+
// RUN: %target-swift-frontend \
2+
// RUN: %s \
3+
// RUN: -emit-silgen \
4+
// RUN: -disable-experimental-parser-round-trip \
5+
// RUN: -target %target-swift-5.1-abi-triple \
6+
// RUN: -enable-experimental-feature Sensitive \
7+
// RUN: -enable-experimental-feature ValueGenerics \
68
// RUN: -enable-builtin-module
79

10+
// FIXME: Remove -disable-experimental-parser-round-trip when it's not required for using ValueGenerics.
11+
812
// REQUIRES: swift_feature_Sensitive
13+
// REQUIRES: swift_feature_ValueGenerics
14+
15+
// REQUIRES: asserts
916

1017
// Force verification of TypeLowering's isTrivial.
1118

@@ -68,3 +75,10 @@ struct S_Explicit_Sensitive {
6875

6976
func takeS_Explicit_Sensitive(_ s: S_Explicit_Sensitive) {
7077
}
78+
79+
import Builtin
80+
81+
func foo() {
82+
let bricks: Builtin.FixedArray<1, Conditional<Int>>
83+
let bricks2: Builtin.FixedArray<1, Conditional<String>>
84+
}

test/Sema/bitwise_copyable.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// RUN: %target-typecheck-verify-swift \
2+
// RUN: -disable-experimental-parser-round-trip \
23
// RUN: -disable-availability-checking \
34
// RUN: -enable-experimental-feature NonescapableTypes \
5+
// RUN: -enable-experimental-feature ValueGenerics \
46
// RUN: -enable-experimental-feature Sensitive \
57
// RUN: -enable-builtin-module \
68
// RUN: -debug-diagnostic-names
79

10+
// FIXME: Remove -disable-experimental-parser-round-trip when it's not required for using ValueGenerics.
11+
812
// REQUIRES: swift_feature_NonescapableTypes
13+
// REQUIRES: swift_feature_ValueGenerics
914
// REQUIRES: swift_feature_Sensitive
1015

1116
//==============================================================================
@@ -109,6 +114,17 @@ func passS_Implicit_Sensitive(_ s: S_Implicit_Sensitive) {
109114
// expected-note@-94 {{where_requirement_failure_one_subst}}
110115
}
111116

117+
import Builtin
118+
119+
func passFixedArray1N<T>(_ fa: Builtin.FixedArray<1, T>) {
120+
take1(fa) // expected-error {{type_does_not_conform_decl_owner}}
121+
// expected-note@-101 {{where_requirement_failure_one_subst}}
122+
}
123+
124+
func passFixedArray1N<T : BitwiseCopyable>(_ fa: Builtin.FixedArray<1, T>) {
125+
take1(fa)
126+
}
127+
112128
//==============================================================================
113129
//===========================DEPENDENCY-FREE TESTS=(END)======================}}
114130
//==============================================================================

0 commit comments

Comments
 (0)