Skip to content

Commit 9dd63a4

Browse files
committed
AST: Use resilient access pattern for stored properties of resilient types visible via -enable-testing
Fixes <rdar://problem/45919829>.
1 parent e7dd1c1 commit 9dd63a4

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

lib/AST/Decl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,18 +1781,18 @@ bool AbstractStorageDecl::isFormallyResilient() const {
17811781
if (getAttrs().hasAttribute<FixedLayoutAttr>())
17821782
return false;
17831783

1784-
// Private and (unversioned) internal variables always have a
1785-
// fixed layout.
1786-
if (!getFormalAccessScope(/*useDC=*/nullptr,
1787-
/*treatUsableFromInlineAsPublic=*/true).isPublic())
1788-
return false;
1789-
17901784
// If we're an instance property of a nominal type, query the type.
17911785
auto *dc = getDeclContext();
17921786
if (!isStatic())
17931787
if (auto *nominalDecl = dc->getSelfNominalTypeDecl())
17941788
return nominalDecl->isResilient();
17951789

1790+
// Non-public global and static variables always have a
1791+
// fixed layout.
1792+
if (!getFormalAccessScope(/*useDC=*/nullptr,
1793+
/*treatUsableFromInlineAsPublic=*/true).isPublic())
1794+
return false;
1795+
17961796
return true;
17971797
}
17981798

test/Inputs/resilient_struct.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,7 @@ public struct ResilientWeakRef {
9191
public struct ResilientRef {
9292
public var r: Referent
9393
}
94+
95+
public struct ResilientWithInternalField {
96+
var x: Int
97+
}

test/SILGen/struct_resilience.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
// RUN: %empty-directory(%t)
3-
// RUN: %target-swift-frontend -module-name struct_resilience -emit-module -enable-resilience -emit-module-path=%t/resilient_struct.swiftmodule -enable-sil-ownership -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
4-
// RUN: %target-swift-emit-silgen -module-name struct_resilience -I %t -enable-sil-ownership -enable-resilience %s | %FileCheck %s
3+
// RUN: %target-swift-frontend -emit-module -enable-resilience -emit-module-path=%t/resilient_struct.swiftmodule -enable-sil-ownership %S/../Inputs/resilient_struct.swift
4+
// RUN: %target-swift-emit-silgen -I %t -enable-sil-ownership -enable-resilience %s | %FileCheck %s
55

66
import resilient_struct
77

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
// RUN: %empty-directory(%t)
3+
// RUN: %target-swift-frontend -emit-module -enable-resilience -enable-testing -emit-module-path=%t/resilient_struct.swiftmodule -enable-sil-ownership %S/../Inputs/resilient_struct.swift
4+
// RUN: %target-swift-emit-silgen -I %t -enable-sil-ownership %s | %FileCheck %s
5+
6+
@testable import resilient_struct
7+
8+
// CHECK-LABEL: sil @$s26struct_resilience_testable37takesResilientStructWithInternalFieldySi010resilient_A00eghI0VF : $@convention(thin) (@in_guaranteed ResilientWithInternalField) -> Int
9+
// CHECK: [[COPY:%.*]] = alloc_stack $ResilientWithInternalField
10+
// CHECK: copy_addr %0 to [initialization] [[COPY]] : $*ResilientWithInternalField
11+
// CHECK: [[FN:%.*]] = function_ref @$s16resilient_struct26ResilientWithInternalFieldV1xSivg : $@convention(method) (@in_guaranteed ResilientWithInternalField) -> Int
12+
// CHECK: [[RESULT:%.*]] = apply [[FN]]([[COPY]])
13+
// CHECK: destroy_addr [[COPY]]
14+
// CHECK: dealloc_stack [[COPY]]
15+
// CHECK: return [[RESULT]]
16+
17+
public func takesResilientStructWithInternalField(_ s: ResilientWithInternalField) -> Int {
18+
return s.x
19+
}

0 commit comments

Comments
 (0)