File tree Expand file tree Collapse file tree 8 files changed +81
-5
lines changed Expand file tree Collapse file tree 8 files changed +81
-5
lines changed Original file line number Diff line number Diff line change @@ -314,8 +314,19 @@ SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
314
314
neverPublic = true ;
315
315
}
316
316
}
317
+
318
+ auto effectiveAccess = d->getEffectiveAccess ();
319
+
320
+ // Private setter implementations for an internal storage declaration should
321
+ // be internal as well, so that a dynamically-writable
322
+ // keypath can be formed from other files.
323
+ if (auto accessor = dyn_cast<AccessorDecl>(d)) {
324
+ if (accessor->isSetter ()
325
+ && accessor->getStorage ()->getEffectiveAccess () == AccessLevel::Internal)
326
+ effectiveAccess = AccessLevel::Internal;
327
+ }
317
328
318
- switch (d-> getEffectiveAccess () ) {
329
+ switch (effectiveAccess ) {
319
330
case AccessLevel::Private:
320
331
case AccessLevel::FilePrivate:
321
332
return maybeAddExternal (SILLinkage::Private);
Original file line number Diff line number Diff line change
1
+ struct A {
2
+ private( set) var x : Int {
3
+ get { return 0 }
4
+ set { }
5
+ }
6
+
7
+ private( set) subscript( x: Int ) -> Int {
8
+ get { return x }
9
+ set { }
10
+ }
11
+ }
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ internal struct PrivateSettersForReadOnlyInternal : PublicReadOnlyOperations {
105
105
// CHECK-DAG: sil hidden{{( \[.+\])*}} @$S22accessibility_warnings33PrivateSettersForReadOnlyInternalV4sizeSivg
106
106
public private( set) var size = 0
107
107
// CHECK-DAG: sil hidden @$S22accessibility_warnings33PrivateSettersForReadOnlyInternalVyS2icig
108
- // CHECK-DAG: sil private @$S22accessibility_warnings33PrivateSettersForReadOnlyInternalVyS2icis
108
+ // CHECK-DAG: sil hidden @$S22accessibility_warnings33PrivateSettersForReadOnlyInternalVyS2icis
109
109
internal private( set) subscript ( _: Int ) -> Int { // no-warning
110
110
get { return 42 }
111
111
set { }
Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ struct Foo {
213
213
private( set) subscript( withPrivateSet x: Void ) -> Void {
214
214
// CHECK-DAG: sil hidden @$S9accessors3FooV14withPrivateSetyyt_tcig : $@convention(method) (Foo) -> () {
215
215
get { }
216
- // CHECK-DAG: sil private @$S9accessors3FooV14withPrivateSetyyt_tcis : $@convention(method) (@inout Foo) -> () {
216
+ // CHECK-DAG: sil hidden @$S9accessors3FooV14withPrivateSetyyt_tcis : $@convention(method) (@inout Foo) -> () {
217
217
set { }
218
218
}
219
219
subscript( withNestedClass x: Void ) -> Void {
@@ -229,7 +229,7 @@ struct Foo {
229
229
private( set) var variableWithPrivateSet : Void {
230
230
// CHECK-DAG: sil hidden @$S9accessors3FooV22variableWithPrivateSetytvg : $@convention(method) (Foo) -> () {
231
231
get { }
232
- // CHECK-DAG: sil private @$S9accessors3FooV22variableWithPrivateSetytvs : $@convention(method) (@inout Foo) -> () {
232
+ // CHECK-DAG: sil hidden @$S9accessors3FooV22variableWithPrivateSetytvs : $@convention(method) (@inout Foo) -> () {
233
233
set { }
234
234
}
235
235
var propertyWithNestedClass : Void {
Original file line number Diff line number Diff line change
1
+ // RUN: %target-swift-emit-silgen -module-name keypaths -primary-file %s %S/Inputs/keypaths_multi_file_b.swift | %FileCheck %s
2
+ // RUN: %target-swift-emit-silgen -module-name keypaths %s -primary-file %S/Inputs/keypaths_multi_file_b.swift | %FileCheck --check-prefix=DEFINITION %s
3
+
4
+ func foo( x: Int ) -> KeyPath < A , Int > {
5
+ switch x {
6
+ case 0 :
7
+ return \A . x
8
+ default :
9
+ return \A . [ 0 ]
10
+ }
11
+ return \A . x
12
+ }
13
+
14
+ // A.x setter
15
+ // CHECK-LABEL: sil hidden_external @$S8keypaths1AV1xSivs
16
+ // DEFINITION-LABEL: sil hidden @$S8keypaths1AV1xSivs
17
+
18
+ // A.subscript setter
19
+ // CHECK-LABEL: sil hidden_external @$S8keypaths1AVyS2icis
20
+ // DEFINITION-LABEL: sil hidden @$S8keypaths1AVyS2icis
Original file line number Diff line number Diff line change
1
+ struct A {
2
+ private( set) var x : Int {
3
+ get { return 0 }
4
+ set { }
5
+ }
6
+
7
+ private( set) subscript( x: Int ) -> Int {
8
+ get { return 0 }
9
+ set { }
10
+ }
11
+ }
12
+
13
+ func A_x_keypath( ) -> WritableKeyPath < A , Int > {
14
+ return \A . x
15
+ }
16
+
17
+ func A_subscript_0_keypath( ) -> WritableKeyPath < A , Int > {
18
+ return \A . [ 0 ]
19
+ }
Original file line number Diff line number Diff line change 1
1
// RUN: %empty-directory(%t)
2
- // RUN: %target-build-swift %s -Xfrontend -enable-sil-ownership -Xfrontend -g - o %t/a.out
2
+ // RUN: %target-build-swift %s -o %t/a.out
3
3
// RUN: %target-run %t/a.out
4
4
// REQUIRES: executable_test
5
5
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: cp %s %t/main.swift
3
+ // RUN: %target-build-swift -o %t/a.out %t/main.swift %S/Inputs/KeyPathMultiFile_b.swift
4
+ // RUN: %target-run %t/a.out
5
+
6
+ import StdlibUnittest
7
+
8
+ var keyPathMultiFile = TestSuite ( " key paths across multiple files " )
9
+
10
+ keyPathMultiFile. test ( " identity across multiple files " ) {
11
+ expectEqual ( A_x_keypath ( ) , \A . x)
12
+ expectEqual ( A_subscript_0_keypath ( ) , \A . [ 0 ] )
13
+ }
14
+
15
+ runAllTests ( )
You can’t perform that action at this time.
0 commit comments