Skip to content

Commit ff4d9af

Browse files
committed
Sema: Inherit SPI groups when synthesizing modify accessor.
Resolves rdar://108069565
1 parent 987e569 commit ff4d9af

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,17 @@ createCoroutineAccessorPrototype(AbstractStorageDecl *storage,
23242324
AvailabilityInference::applyInferredAvailableAttrs(accessor,
23252325
asAvailableAs, ctx);
23262326

2327+
// A modify coroutine should have the same SPI visibility as the setter.
2328+
if (kind == AccessorKind::Modify) {
2329+
if (FuncDecl *setter = storage->getParsedAccessor(AccessorKind::Set)) {
2330+
if (!setter->getSPIGroups().empty()) {
2331+
auto spiAttr = SPIAccessControlAttr::create(
2332+
ctx, SourceLoc(), SourceRange(), setter->getSPIGroups());
2333+
accessor->getAttrs().add(spiAttr);
2334+
}
2335+
}
2336+
}
2337+
23272338
finishImplicitAccessor(accessor, ctx);
23282339

23292340
return accessor;

test/SPI/private_swiftinterface.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ public class SomeClass {
139139
}
140140

141141
public struct PublicStruct {
142+
@_spi(S) public var spiVar: SomeClass
143+
// CHECK-PRIVATE: @_spi(S) public var spiVar: {{.*}}.SomeClass
144+
// CHECK-PUBLIC-NOT: spiVar
145+
146+
public var publicVarWithSPISet: SomeClass {
147+
get { SomeClass() }
148+
@_spi(S) set {}
149+
}
150+
// CHECK-PRIVATE: public var publicVarWithSPISet: {{.*}}.SomeClass {
151+
// CHECK-PRIVATE-NEXT: get
152+
// CHECK-PRIVATE-NEXT: @_spi(S) set
153+
// CHECK-PRIVATE-NEXT: }
154+
// CHECK-PUBLIC: public var publicVarWithSPISet: {{.*}}.SomeClass {
155+
// CHECK-PUBLIC-NEXT: get
156+
// CHECK-PUBLIC-NEXT: }
157+
142158
@_spi(S) @Wrapper public var spiWrappedSimple: SomeClass
143159
// CHECK-PRIVATE: @_spi(S) @{{.*}}.Wrapper public var spiWrappedSimple: {{.*}}.SomeClass
144160
// CHECK-PUBLIC-NOT: spiWrappedSimple

test/api-digester/ignore-spi-by-given-group-name.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,39 @@
22

33
// RUN: %target-swift-frontend -emit-module -o %t/Foo.swiftmodule -emit-abi-descriptor-path %t/abi-before.json %s -enable-library-evolution -DBASELINE -emit-tbd-path %t/abi-before.tbd
44
// RUN: %target-swift-frontend -emit-module -o %t/Foo.swiftmodule -emit-abi-descriptor-path %t/abi-after.json %s -enable-library-evolution -emit-tbd-path %t/abi-after.tbd
5-
// RUN: %api-digester -diagnose-sdk --input-paths %t/abi-before.json -input-paths %t/abi-after.json -abi -o %t/result.txt
6-
// RUN: %FileCheck %s -check-prefix CHECK_INCLUDE_SPI < %t/result.txt
5+
// RUN: %api-digester -diagnose-sdk --input-paths %t/abi-before.json -input-paths %t/abi-after.json -abi -o %t/include-result.txt
6+
// RUN: %FileCheck %s -check-prefix CHECK_INCLUDE_SPI < %t/include-result.txt
77

8-
// RUN: %api-digester -diagnose-sdk --input-paths %t/abi-before.json -input-paths %t/abi-after.json -abi -o %t/result.txt -ignore-spi-group secret
9-
// RUN: %FileCheck -check-prefix CHECK_EXCLUDE_SPI %s < %t/result.txt
8+
// RUN: %api-digester -diagnose-sdk --input-paths %t/abi-before.json -input-paths %t/abi-after.json -abi -o %t/exclude-result.txt -ignore-spi-group secret
9+
// RUN: %FileCheck -check-prefix CHECK_EXCLUDE_SPI %s < %t/exclude-result.txt
1010

1111
#if BASELINE
1212

13+
public struct Struct {
14+
public var x: Int {
15+
get { 0 }
16+
@_spi(secret) set {}
17+
}
18+
}
19+
1320
@_spi(secret)
1421
public func foo() {}
1522

1623
#else
1724

25+
public struct Struct {
26+
public var x: Int {
27+
get { 0 }
28+
}
29+
}
1830

1931
#endif
2032

33+
// CHECK_INCLUDE_SPI: Accessor Struct.x.Modify() has been removed
34+
// CHECK_EXCLUDE_SPI-NOT: Struct.x.Modify()
35+
36+
// CHECK_INCLUDE_SPI: Accessor Struct.x.Set() has been removed
37+
// CHECK_EXCLUDE_SPI-NOT: Struct.x.Set()
38+
2139
// CHECK_INCLUDE_SPI: Func foo() has been removed
2240
// CHECK_EXCLUDE_SPI-NOT: foo()

0 commit comments

Comments
 (0)