Skip to content

Commit b291cf4

Browse files
committed
SIL: Consider Builtin.FixedArray and @_rawLayout types to be structurally addressable-for-dependencies.
A primary purpose of these features is to enable persistent references into their storage, so it's reasonable to assume this property for these types and types containing them.
1 parent d9ee3f4 commit b291cf4

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ namespace {
389389

390390
props = mergeIsTypeExpansionSensitive(isSensitive, props);
391391

392+
// Fixed array regions are implied to be addressable-for-dependencies,
393+
// since the developer probably wants to be able to form Spans etc.
394+
// over them.
395+
props.setAddressableForDependencies();
396+
392397
// If the size isn't a known literal, then the layout is also dependent,
393398
// so make it address-only. If the size is massive, also treat it as
394399
// address-only since there's little practical benefit to passing around
@@ -2540,6 +2545,7 @@ namespace {
25402545
// If the type has raw storage, it is move-only and address-only.
25412546
if (D->getAttrs().hasAttribute<RawLayoutAttr>()) {
25422547
properties.setAddressOnly();
2548+
properties.setAddressableForDependencies();
25432549
properties.setNonTrivial();
25442550
properties.setLexical(IsLexical);
25452551
return handleMoveOnlyAddressOnly(structType, properties);

test/SILOptimizer/addressable_dependencies.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// RUN: %target-swift-frontend -emit-sil -enable-experimental-feature BuiltinModule -enable-experimental-feature LifetimeDependence -enable-experimental-feature AddressableTypes %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -emit-sil -enable-experimental-feature BuiltinModule -enable-experimental-feature LifetimeDependence -enable-experimental-feature AddressableTypes -enable-experimental-feature ValueGenerics %s | %FileCheck %s
22

33
// REQUIRES: swift_feature_BuiltinModule
44
// REQUIRES: swift_feature_AddressableTypes
55
// REQUIRES: swift_feature_LifetimeDependence
6+
// REQUIRES: swift_feature_ValueGenerics
67

78
import Builtin
89

@@ -58,3 +59,22 @@ struct AllocatedNode: ~Copyable {
5859
}
5960
}
6061

62+
struct Schmector {
63+
// structurally addressable-for-dependencies by virtue of containing a
64+
// Builtin.FixedArray
65+
private var elements: Builtin.FixedArray<10, Int>
66+
67+
var storage: Spam {
68+
// CHECK-LABEL: sil {{.*}}@${{.*}}9SchmectorV7storage{{.*}}Vvg :
69+
// CHECK-SAME: (@in_guaranteed Schmector) ->
70+
@lifetime(borrow self)
71+
borrowing get {
72+
return Spam(base: UnsafePointer(Builtin.addressOfBorrow(self)), count: 10)
73+
}
74+
}
75+
}
76+
77+
struct Spam: ~Escapable {
78+
@_unsafeNonescapableResult
79+
init(base: UnsafePointer<Int>, count: Int) {}
80+
}

0 commit comments

Comments
 (0)