Skip to content

Commit 930c8f2

Browse files
authored
Merge pull request swiftlang#32910 from xymus/spi-property-wrappers-storage
[Sema] SPI groups on a wrapped property propagates to the backing storage
2 parents a8b41d3 + 47e4e29 commit 930c8f2

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

lib/AST/Module.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,15 @@ SPIGroupsRequest::evaluate(Evaluator &evaluator, const Decl *decl) const {
20532053
for (auto spi : attr->getSPIGroups())
20542054
spiGroups.insert(spi);
20552055

2056-
auto &ctx = decl->getASTContext();
2056+
// Backing storage for a wrapped property gets the SPI groups from the
2057+
// original property.
2058+
if (auto varDecl = dyn_cast<VarDecl>(decl))
2059+
if (auto originalDecl = varDecl->getOriginalWrappedProperty()) {
2060+
auto originalSPIs = originalDecl->getSPIGroups();
2061+
spiGroups.insert(originalSPIs.begin(), originalSPIs.end());
2062+
}
2063+
2064+
// If there is no local SPI information, look at the context.
20572065
if (spiGroups.empty()) {
20582066

20592067
// Then in the extended nominal type.
@@ -2073,6 +2081,7 @@ SPIGroupsRequest::evaluate(Evaluator &evaluator, const Decl *decl) const {
20732081
}
20742082
}
20752083

2084+
auto &ctx = decl->getASTContext();
20762085
return ctx.AllocateCopy(spiGroups.getArrayRef());
20772086
}
20782087

test/SPI/private_swiftinterface.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,45 @@ private class PrivateClassLocal {}
8888
// CHECK-PUBLIC-NOT: extensionSPIMethod
8989
}
9090

91+
@propertyWrapper
92+
public struct Wrapper<T> {
93+
public var value: T
94+
95+
public var wrappedValue: T {
96+
get { value }
97+
set { value = newValue }
98+
}
99+
}
100+
101+
@propertyWrapper
102+
public struct WrapperWithInitialValue<T> {
103+
private var value: T
104+
105+
public var wrappedValue: T {
106+
get { value }
107+
set { value = newValue }
108+
}
109+
110+
public var projectedValue: Wrapper<T> {
111+
get { Wrapper(value: value) }
112+
set { value = newValue.value }
113+
}
114+
}
115+
116+
public class SomeClass {
117+
}
118+
119+
public struct PublicStruct {
120+
@_spi(S) @Wrapper public var spiWrappedSimple: SomeClass
121+
// CHECK-PRIVATE: @_spi(S) @{{.*}}.Wrapper public var spiWrappedSimple: {{.*}}.SomeClass
122+
// CHECK-PUBLIC-NOT: spiWrappedSimple
123+
124+
@_spi(S) @WrapperWithInitialValue public var spiWrappedDefault: SomeClass
125+
// CHECK-PRIVATE: @_spi(S) @{{.*}}.WrapperWithInitialValue @_projectedValueProperty($spiWrappedDefault) public var spiWrappedDefault: {{.*}}.SomeClass
126+
// CHECK-PRIVATE: @_spi(S) public var $spiWrappedDefault: {{.*}}.Wrapper<{{.*}}.SomeClass>
127+
// CHECK-PUBLIC-NOT: spiWrappedDefault
128+
}
129+
91130
@_spi(LocalSPI) public protocol SPIProto3 {
92131
// CHECK-PRIVATE: @_spi(LocalSPI) public protocol SPIProto3
93132
// CHECK-PUBLIC-NOT: SPIProto3

0 commit comments

Comments
 (0)