Skip to content

Commit b3ed4d3

Browse files
committed
[AST] Make it possible to access type wrapper storage of a var
This is important because we need to force existance of the underlying storage at the right moment.
1 parent a672db9 commit b3ed4d3

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Diff for: include/swift/AST/Decl.h

+7
Original file line numberDiff line numberDiff line change
@@ -5564,6 +5564,13 @@ class VarDecl : public AbstractStorageDecl {
55645564
/// all access to it routed through a type wrapper.
55655565
bool isAccessedViaTypeWrapper() const;
55665566

5567+
/// For type wrapped properties (see \c isAccessedViaTypeWrapper)
5568+
/// all access is routed through a type wrapper.
5569+
///
5570+
/// \returns an underlying type wrapper property which is a
5571+
/// storage endpoint for all access to this property.
5572+
VarDecl *getUnderlyingTypeWrapperStorage() const;
5573+
55675574
/// Visit all auxiliary declarations to this VarDecl.
55685575
///
55695576
/// An auxiliary declaration is a declaration synthesized by the compiler to support

Diff for: lib/Sema/TypeCheckStorage.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static bool hasStoredProperties(NominalTypeDecl *decl) {
104104

105105
static void computeLoweredStoredProperties(NominalTypeDecl *decl) {
106106
// Just walk over the members of the type, forcing backing storage
107-
// for lazy properties and property wrappers to be synthesized.
107+
// for lazy properties, property and type wrappers to be synthesized.
108108
for (auto *member : decl->getMembers()) {
109109
auto *var = dyn_cast<VarDecl>(member);
110110
if (!var || var->isStatic())
@@ -117,6 +117,10 @@ static void computeLoweredStoredProperties(NominalTypeDecl *decl) {
117117
(void) var->getPropertyWrapperAuxiliaryVariables();
118118
(void) var->getPropertyWrapperInitializerInfo();
119119
}
120+
121+
if (var->isAccessedViaTypeWrapper()) {
122+
(void)var->getUnderlyingTypeWrapperStorage();
123+
}
120124
}
121125

122126
// If this is an actor, check conformance to the Actor protocol to

Diff for: lib/Sema/TypeCheckTypeWrapper.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ bool VarDecl::isAccessedViaTypeWrapper() const {
6060
false);
6161
}
6262

63+
VarDecl *VarDecl::getUnderlyingTypeWrapperStorage() const {
64+
auto *mutableSelf = const_cast<VarDecl *>(this);
65+
return evaluateOrDefault(getASTContext().evaluator,
66+
GetTypeWrapperStorageForProperty{mutableSelf},
67+
nullptr);
68+
}
69+
6370
NominalTypeDecl *NominalTypeDecl::getTypeWrapper() const {
6471
auto *mutableSelf = const_cast<NominalTypeDecl *>(this);
6572
return evaluateOrDefault(getASTContext().evaluator,
@@ -217,8 +224,7 @@ static SubscriptExpr *subscriptTypeWrappedProperty(VarDecl *var,
217224

218225
auto *typeWrapperVar =
219226
evaluateOrDefault(ctx.evaluator, GetTypeWrapperProperty{parent}, nullptr);
220-
auto *storageVar = evaluateOrDefault(
221-
ctx.evaluator, GetTypeWrapperStorageForProperty{var}, nullptr);
227+
auto *storageVar = var->getUnderlyingTypeWrapperStorage();
222228

223229
assert(typeWrapperVar);
224230
assert(storageVar);

0 commit comments

Comments
 (0)