From 792f8d176029fea3b0e4df797561ecb91b04a1bd Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Fri, 8 Nov 2024 10:41:03 -0800 Subject: [PATCH 1/2] [FixedArray] Fix BitwiseCopyable inference. `FixedArray : BitwiseCopyable` iff `T : BitwiwseCopyable`; determining this requires using `checkConformance`, not `lookupConformance`. --- lib/AST/Builtins.cpp | 7 ++++--- test/Sema/bitwise_copyable.swift | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/AST/Builtins.cpp b/lib/AST/Builtins.cpp index 268cb4ac823fe..7327b20a05173 100644 --- a/lib/AST/Builtins.cpp +++ b/lib/AST/Builtins.cpp @@ -3385,11 +3385,12 @@ bool BuiltinType::isBitwiseCopyable() const { return false; case BuiltinTypeKind::BuiltinFixedArray: { - // Bitwise-copyability depends on the element type. + // FixedArray : BitwiseCopyable whenever X : BitwiseCopyable auto bfa = cast(this); auto &C = bfa->getASTContext(); - return (bool)lookupConformance(bfa->getElementType(), - C.getProtocol(KnownProtocolKind::BitwiseCopyable)); + return (bool)checkConformance( + bfa->getElementType(), + C.getProtocol(KnownProtocolKind::BitwiseCopyable)); } } } diff --git a/test/Sema/bitwise_copyable.swift b/test/Sema/bitwise_copyable.swift index 8fdd0bd53aebc..dfb8961e2eef3 100644 --- a/test/Sema/bitwise_copyable.swift +++ b/test/Sema/bitwise_copyable.swift @@ -1,11 +1,16 @@ // RUN: %target-typecheck-verify-swift \ +// RUN: -disable-experimental-parser-round-trip \ // RUN: -disable-availability-checking \ // RUN: -enable-experimental-feature NonescapableTypes \ +// RUN: -enable-experimental-feature ValueGenerics \ // RUN: -enable-experimental-feature Sensitive \ // RUN: -enable-builtin-module \ // RUN: -debug-diagnostic-names +// FIXME: Remove -disable-experimental-parser-round-trip when it's not required for using ValueGenerics. + // REQUIRES: swift_feature_NonescapableTypes +// REQUIRES: swift_feature_ValueGenerics // REQUIRES: swift_feature_Sensitive //============================================================================== @@ -109,6 +114,17 @@ func passS_Implicit_Sensitive(_ s: S_Implicit_Sensitive) { // expected-note@-94 {{where_requirement_failure_one_subst}} } +import Builtin + +func passFixedArray1N(_ fa: Builtin.FixedArray<1, T>) { + take1(fa) // expected-error {{type_does_not_conform_decl_owner}} + // expected-note@-101 {{where_requirement_failure_one_subst}} +} + +func passFixedArray1N(_ fa: Builtin.FixedArray<1, T>) { + take1(fa) +} + //============================================================================== //===========================DEPENDENCY-FREE TESTS=(END)======================}} //============================================================================== From d06d5bb6fe2ee9ab72355c72c4329606c6d7e15a Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Fri, 8 Nov 2024 10:58:16 -0800 Subject: [PATCH 2/2] [FixedArray] Fix TypeLowering verification. A new aggregate type has been added and must be walked into. rdar://139448358 --- lib/SIL/IR/TypeLowering.cpp | 8 ++++++++ test/SILGen/bitwise_copyable.swift | 24 +++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/SIL/IR/TypeLowering.cpp b/lib/SIL/IR/TypeLowering.cpp index 72d68a8c1a9ef..53d15836642f7 100644 --- a/lib/SIL/IR/TypeLowering.cpp +++ b/lib/SIL/IR/TypeLowering.cpp @@ -3000,6 +3000,7 @@ bool TypeConverter::visitAggregateLeaves( return isa(ty) || isa(ty) || isa(ty) || + isa(ty) || ty.getEnumOrBoundGenericEnum() || ty.getStructOrBoundGenericStruct(); }; @@ -3036,6 +3037,13 @@ bool TypeConverter::visitAggregateLeaves( insertIntoWorklist(expansion.getPatternType(), origTy.getPackExpansionPatternType(), field, index); + } else if (auto array = dyn_cast(ty)) { + auto origBFA = origTy.getAs(); + insertIntoWorklist( + array->getElementType(), + AbstractionPattern(origTy.getGenericSignatureOrNull(), + origBFA->getElementType()), + field, index); } else if (auto *decl = ty.getStructOrBoundGenericStruct()) { for (auto *structField : decl->getStoredProperties()) { auto subMap = ty->getContextSubstitutionMap(); diff --git a/test/SILGen/bitwise_copyable.swift b/test/SILGen/bitwise_copyable.swift index 7cecf34d79c7b..cdc4546189cdd 100644 --- a/test/SILGen/bitwise_copyable.swift +++ b/test/SILGen/bitwise_copyable.swift @@ -1,11 +1,18 @@ -// RUN: %target-swift-frontend \ -// RUN: %s \ -// RUN: -emit-silgen \ -// RUN: -target %target-swift-5.1-abi-triple \ -// RUN: -enable-experimental-feature Sensitive \ +// RUN: %target-swift-frontend \ +// RUN: %s \ +// RUN: -emit-silgen \ +// RUN: -disable-experimental-parser-round-trip \ +// RUN: -target %target-swift-5.1-abi-triple \ +// RUN: -enable-experimental-feature Sensitive \ +// RUN: -enable-experimental-feature ValueGenerics \ // RUN: -enable-builtin-module +// FIXME: Remove -disable-experimental-parser-round-trip when it's not required for using ValueGenerics. + // REQUIRES: swift_feature_Sensitive +// REQUIRES: swift_feature_ValueGenerics + +// REQUIRES: asserts // Force verification of TypeLowering's isTrivial. @@ -68,3 +75,10 @@ struct S_Explicit_Sensitive { func takeS_Explicit_Sensitive(_ s: S_Explicit_Sensitive) { } + +import Builtin + +func foo() { + let bricks: Builtin.FixedArray<1, Conditional> + let bricks2: Builtin.FixedArray<1, Conditional> +}