Skip to content

Commit cceb9a3

Browse files
authored
Merge pull request swiftlang#32934 from xymus/spi-property-wrappers-storage-5.3
[5.3][Sema] SPI info on a wrapped property should propagate to the backing storage
2 parents de1bbf6 + 25f324e commit cceb9a3

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
@@ -2249,7 +2249,15 @@ SPIGroupsRequest::evaluate(Evaluator &evaluator, const Decl *decl) const {
22492249
for (auto spi : attr->getSPIGroups())
22502250
spiGroups.insert(spi);
22512251

2252-
auto &ctx = decl->getASTContext();
2252+
// Backing storage for a wrapped property gets the SPI groups from the
2253+
// original property.
2254+
if (auto varDecl = dyn_cast<VarDecl>(decl))
2255+
if (auto originalDecl = varDecl->getOriginalWrappedProperty()) {
2256+
auto originalSPIs = originalDecl->getSPIGroups();
2257+
spiGroups.insert(originalSPIs.begin(), originalSPIs.end());
2258+
}
2259+
2260+
// If there is no local SPI information, look at the context.
22532261
if (spiGroups.empty()) {
22542262

22552263
// Then in the extended nominal type.
@@ -2269,6 +2277,7 @@ SPIGroupsRequest::evaluate(Evaluator &evaluator, const Decl *decl) const {
22692277
}
22702278
}
22712279

2280+
auto &ctx = decl->getASTContext();
22722281
return ctx.AllocateCopy(spiGroups.getArrayRef());
22732282
}
22742283

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)