Skip to content

[FixedArray] Fix BitwiseCopyable inference. #77512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2024
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
7 changes: 4 additions & 3 deletions lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3385,11 +3385,12 @@ bool BuiltinType::isBitwiseCopyable() const {
return false;

case BuiltinTypeKind::BuiltinFixedArray: {
// Bitwise-copyability depends on the element type.
// FixedArray<N, X> : BitwiseCopyable whenever X : BitwiseCopyable
auto bfa = cast<BuiltinFixedArrayType>(this);
auto &C = bfa->getASTContext();
return (bool)lookupConformance(bfa->getElementType(),
C.getProtocol(KnownProtocolKind::BitwiseCopyable));
return (bool)checkConformance(
bfa->getElementType(),
C.getProtocol(KnownProtocolKind::BitwiseCopyable));
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions lib/SIL/IR/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3000,6 +3000,7 @@ bool TypeConverter::visitAggregateLeaves(
return isa<SILPackType>(ty) ||
isa<TupleType>(ty) ||
isa<PackExpansionType>(ty) ||
isa<BuiltinFixedArrayType>(ty) ||
ty.getEnumOrBoundGenericEnum() ||
ty.getStructOrBoundGenericStruct();
};
Expand Down Expand Up @@ -3036,6 +3037,13 @@ bool TypeConverter::visitAggregateLeaves(
insertIntoWorklist(expansion.getPatternType(),
origTy.getPackExpansionPatternType(),
field, index);
} else if (auto array = dyn_cast<BuiltinFixedArrayType>(ty)) {
auto origBFA = origTy.getAs<BuiltinFixedArrayType>();
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();
Expand Down
24 changes: 19 additions & 5 deletions test/SILGen/bitwise_copyable.swift
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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<Int>>
let bricks2: Builtin.FixedArray<1, Conditional<String>>
}
16 changes: 16 additions & 0 deletions test/Sema/bitwise_copyable.swift
Original file line number Diff line number Diff line change
@@ -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

//==============================================================================
Expand Down Expand Up @@ -109,6 +114,17 @@ func passS_Implicit_Sensitive(_ s: S_Implicit_Sensitive) {
// expected-note@-94 {{where_requirement_failure_one_subst}}
}

import Builtin

func passFixedArray1N<T>(_ 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<T : BitwiseCopyable>(_ fa: Builtin.FixedArray<1, T>) {
take1(fa)
}

//==============================================================================
//===========================DEPENDENCY-FREE TESTS=(END)======================}}
//==============================================================================
Expand Down