Skip to content

Commit d0240cc

Browse files
committed
Sema: Simplify finalizeType() by using getStoredProperties()
Continue gutting finalizeType() by using our new request to synthesize the backing storage for lazy properties and property wrappers.
1 parent 83c90b6 commit d0240cc

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,9 +2056,6 @@ static void finishProtocolStorageImplInfo(AbstractStorageDecl *storage) {
20562056
}
20572057

20582058
static void finishLazyVariableImplInfo(VarDecl *var) {
2059-
// FIXME: Remove this once getStoredProperties() is a request
2060-
(void) var->getLazyStorageProperty();
2061-
20622059
// If there are already accessors, something is invalid; bail out.
20632060
if (!var->getImplInfo().isSimpleStored())
20642061
return;
@@ -2074,6 +2071,9 @@ static bool allPropertyWrapperValueSettersAreAccessible(VarDecl *var) {
20742071
for (unsigned i : indices(wrapperAttrs)) {
20752072
auto wrapperInfo = var->getAttachedPropertyWrapperTypeInfo(i);
20762073
auto valueVar = wrapperInfo.valueVar;
2074+
// Only nullptr with invalid code.
2075+
if (!valueVar)
2076+
return false;
20772077
if (!valueVar->isSettable(nullptr) ||
20782078
!valueVar->isSetterAccessibleFrom(innermostDC))
20792079
return false;
@@ -2083,10 +2083,6 @@ static bool allPropertyWrapperValueSettersAreAccessible(VarDecl *var) {
20832083
}
20842084

20852085
static void finishPropertyWrapperImplInfo(VarDecl *var) {
2086-
auto backingVar = var->getPropertyWrapperBackingProperty();
2087-
if (!backingVar || backingVar->isInvalid())
2088-
return;
2089-
20902086
auto parentSF = var->getDeclContext()->getParentSourceFile();
20912087
bool wrapperSetterIsUsable =
20922088
var->getSetter() ||

lib/Sema/TypeCheckDecl.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,6 +2875,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
28752875

28762876
TC.addImplicitConstructors(SD);
28772877

2878+
// Force lowering of stored properties.
2879+
(void) SD->getStoredProperties();
2880+
28782881
for (Decl *Member : SD->getMembers())
28792882
visit(Member);
28802883

@@ -3002,6 +3005,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
30023005
DescriptiveDeclKind::Class, path);
30033006
}
30043007

3008+
// Force lowering of stored properties.
3009+
(void) CD->getStoredProperties();
3010+
30053011
for (Decl *Member : CD->getMembers()) {
30063012
visit(Member);
30073013
}
@@ -4522,31 +4528,16 @@ static void finalizeType(TypeChecker &TC, NominalTypeDecl *nominal) {
45224528
CD->addImplicitDestructor();
45234529
}
45244530

4531+
// Force lowering of stored properties.
4532+
(void) nominal->getStoredProperties();
4533+
45254534
for (auto *D : nominal->getMembers()) {
45264535
auto VD = dyn_cast<ValueDecl>(D);
45274536
if (!VD)
45284537
continue;
45294538

4530-
if (!shouldValidateMemberDuringFinalization(nominal, VD))
4531-
continue;
4532-
4533-
TC.DeclsToFinalize.insert(VD);
4534-
4535-
// The only thing left to do is synthesize storage for lazy variables
4536-
// and property wrappers.
4537-
auto *prop = dyn_cast<VarDecl>(D);
4538-
if (!prop)
4539-
continue;
4540-
4541-
if (prop->getAttrs().hasAttribute<LazyAttr>() && !prop->isStatic() &&
4542-
(!prop->getGetter() || !prop->getGetter()->hasBody())) {
4543-
(void) prop->getLazyStorageProperty();
4544-
}
4545-
4546-
// Ensure that we create the backing variable for a wrapped property.
4547-
if (prop->hasAttachedPropertyWrapper()) {
4548-
(void) prop->getPropertyWrapperBackingProperty();
4549-
}
4539+
if (shouldValidateMemberDuringFinalization(nominal, VD))
4540+
TC.DeclsToFinalize.insert(VD);
45504541
}
45514542

45524543
if (auto *CD = dyn_cast<ClassDecl>(nominal)) {

0 commit comments

Comments
 (0)