Skip to content

Commit d341c41

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

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3760,6 +3760,11 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
37603760
/// Return a type wrapper (if any) associated with this type.
37613761
NominalTypeDecl *getTypeWrapper() const;
37623762

3763+
/// If this declaration has a type wrapper return a property that
3764+
/// is used for all type wrapper related operations (mainly for
3765+
/// applicable property access routing).
3766+
VarDecl *getTypeWrapperProperty() const;
3767+
37633768
/// Get an initializer that could be used to instantiate a
37643769
/// type wrapped type.
37653770
ConstructorDecl *getTypeWrapperInitializer() const;

lib/Sema/TypeCheckStorage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ static bool hasStoredProperties(NominalTypeDecl *decl) {
103103
}
104104

105105
static void computeLoweredStoredProperties(NominalTypeDecl *decl) {
106+
// If declaration has a type wrapper, make sure that
107+
// `$_storage` property is synthesized.
108+
if (decl->hasTypeWrapper())
109+
(void)decl->getTypeWrapperProperty();
110+
106111
// Just walk over the members of the type, forcing backing storage
107112
// for lazy properties, property and type wrappers to be synthesized.
108113
for (auto *member : decl->getMembers()) {

lib/Sema/TypeCheckTypeWrapper.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ Type GetTypeWrapperType::evaluate(Evaluator &evaluator,
135135
return type;
136136
}
137137

138+
VarDecl *NominalTypeDecl::getTypeWrapperProperty() const {
139+
auto *mutableSelf = const_cast<NominalTypeDecl *>(this);
140+
return evaluateOrDefault(getASTContext().evaluator,
141+
GetTypeWrapperProperty{mutableSelf}, nullptr);
142+
}
143+
138144
ConstructorDecl *NominalTypeDecl::getTypeWrapperInitializer() const {
139145
auto *mutableSelf = const_cast<NominalTypeDecl *>(this);
140146
return evaluateOrDefault(getASTContext().evaluator,
@@ -222,8 +228,7 @@ static SubscriptExpr *subscriptTypeWrappedProperty(VarDecl *var,
222228
if (!(parent && parent->hasTypeWrapper()))
223229
return nullptr;
224230

225-
auto *typeWrapperVar =
226-
evaluateOrDefault(ctx.evaluator, GetTypeWrapperProperty{parent}, nullptr);
231+
auto *typeWrapperVar = parent->getTypeWrapperProperty();
227232
auto *storageVar = var->getUnderlyingTypeWrapperStorage();
228233

229234
assert(typeWrapperVar);

0 commit comments

Comments
 (0)