Skip to content

Commit 31ec175

Browse files
committed
SIL: Only lower nominal types marked with @_addressableForDependencies as such.
I accidentally typoed the RecursiveProperties constructor so that every type was getting treated as addressable-for-dependencies. Oops.
1 parent a25edb2 commit 31ec175

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

include/swift/SIL/TypeLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class TypeLowering {
222222
IsNotTypeExpansionSensitive,
223223
HasRawPointer_t hasRawPointer = DoesNotHaveRawPointer,
224224
IsLexical_t isLexical = IsNotLexical, HasPack_t hasPack = HasNoPack,
225-
IsAddressableForDependencies_t isAFD = IsAddressableForDependencies)
225+
IsAddressableForDependencies_t isAFD = IsNotAddressableForDependencies)
226226
: Flags((isTrivial ? 0U : NonTrivialFlag) |
227227
(isFixedABI ? 0U : NonFixedABIFlag) |
228228
(isAddressOnly ? AddressOnlyFlag : 0U) |

lib/SIL/IR/TypeLowering.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,7 @@ namespace {
25102510
}
25112511

25122512
if (D->isCxxNonTrivial()) {
2513+
properties.setAddressableForDependencies();
25132514
properties.setAddressOnly();
25142515
properties.setNonTrivial();
25152516
properties.setLexical(IsLexical);
@@ -2550,6 +2551,10 @@ namespace {
25502551
properties.setLexical(IsLexical);
25512552
return handleAddressOnly(structType, properties);
25522553
}
2554+
2555+
if (D->getAttrs().hasAttribute<AddressableForDependenciesAttr>()) {
2556+
properties.setAddressableForDependencies();
2557+
}
25532558

25542559
auto subMap = structType->getContextSubstitutionMap();
25552560

@@ -2620,6 +2625,10 @@ namespace {
26202625
if (handleResilience(enumType, D, properties))
26212626
return handleAddressOnly(enumType, properties);
26222627

2628+
if (D->getAttrs().hasAttribute<AddressableForDependenciesAttr>()) {
2629+
properties.setAddressableForDependencies();
2630+
}
2631+
26232632
// [is_or_contains_pack_unsubstituted] Visit the elements of the
26242633
// unsubstituted type to find pack types which would be substituted away.
26252634
for (auto elt : D->getAllElements()) {

test/SILOptimizer/addressable_dependencies.swift

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@
66

77
import Builtin
88

9+
struct NodeRef: ~Escapable {
10+
private var parent: UnsafePointer<Node>
11+
12+
// CHECK-LABEL: sil {{.*}}@${{.*}}7NodeRefV4node{{.*}}fC :
13+
// CHECK-SAME: (@in_guaranteed Node,
14+
@lifetime(borrow node)
15+
init(node: borrowing Node) {
16+
// CHECK: bb0(%0 : @noImplicitCopy $*Node,
17+
// CHECK: [[RAW_PTR:%.*]] = address_to_pointer {{.*}}%0
18+
// CHECK: struct $UnsafePointer<Node> ([[RAW_PTR]])
19+
self.parent = UnsafePointer(Builtin.addressOfBorrow(node))
20+
}
21+
22+
// CHECK-LABEL: sil {{.*}}@${{.*}}7NodeRefV9allocated{{.*}}fC :
23+
// CHECK-SAME: (@guaranteed AllocatedNode,
24+
@lifetime(borrow allocated)
25+
init(allocated: borrowing AllocatedNode) {
26+
self.parent = allocated.node
27+
}
28+
}
29+
930
@_addressableForDependencies
1031
struct Node {
1132
var id: String
@@ -23,16 +44,17 @@ struct Node {
2344
}
2445
}
2546

26-
struct NodeRef: ~Escapable {
27-
private var parent: UnsafePointer<Node>
47+
// not addressable for dependencies
48+
struct AllocatedNode: ~Copyable {
49+
fileprivate var node: UnsafePointer<Node>
2850

29-
// CHECK-LABEL: sil {{.*}}@${{.*}}7NodeRefV4node{{.*}}fC :
30-
// CHECK-SAME: (@in_guaranteed Node,
31-
@lifetime(borrow node)
32-
init(node: borrowing Node) {
33-
// CHECK: bb0(%0 : @noImplicitCopy $*Node,
34-
// CHECK: [[RAW_PTR:%.*]] = address_to_pointer {{.*}}%0
35-
// CHECK: struct $UnsafePointer<Node> ([[RAW_PTR]])
36-
self.parent = UnsafePointer(Builtin.addressOfBorrow(node))
51+
var ref: NodeRef {
52+
// CHECK-LABEL: sil {{.*}}@${{.*}}13AllocatedNodeV3ref{{.*}}Vvg :
53+
// CHECK-SAME: (@guaranteed AllocatedNode) ->
54+
@lifetime(borrow self)
55+
borrowing get {
56+
return NodeRef(allocated: self)
57+
}
3758
}
3859
}
60+

0 commit comments

Comments
 (0)