Skip to content

Commit e8a1524

Browse files
authored
Merge pull request #16063 from slavapestov/simply-quite-lazy
Simplify finalization of 'lazy' properties
2 parents 14a4e6f + 14f9e8a commit e8a1524

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5109,6 +5109,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
51095109
Bits.AbstractFunctionDecl.HasComputedNeedsNewVTableEntry = false;
51105110
Bits.AbstractFunctionDecl.DefaultArgumentResilienceExpansion =
51115111
unsigned(ResilienceExpansion::Maximal);
5112+
Bits.AbstractFunctionDecl.Synthesized = false;
51125113

51135114
// Verify no bitfield truncation.
51145115
assert(Bits.AbstractFunctionDecl.NumParameterLists == NumParameterLists);

lib/Sema/TypeCheckDecl.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4373,6 +4373,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
43734373

43744374
TC.validateDecl(ED);
43754375
TC.DeclsToFinalize.remove(ED);
4376+
ED->setHasValidatedLayout();
43764377

43774378
{
43784379
// Check for circular inheritance of the raw type.
@@ -4406,6 +4407,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
44064407

44074408
TC.validateDecl(SD);
44084409
TC.DeclsToFinalize.remove(SD);
4410+
SD->setHasValidatedLayout();
44094411

44104412
TC.addImplicitConstructors(SD);
44114413

@@ -4531,6 +4533,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
45314533
TC.validateDecl(CD);
45324534
TC.requestSuperclassLayout(CD);
45334535
TC.DeclsToFinalize.remove(CD);
4536+
CD->setHasValidatedLayout();
45344537

45354538
{
45364539
// Check for circular inheritance.
@@ -6910,7 +6913,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
69106913
}
69116914

69126915
if (!isa<ClassDecl>(nominal))
6913-
DeclsToFinalize.insert(nominal);
6916+
requestNominalLayout(nominal);
69146917

69156918
break;
69166919
}
@@ -7732,7 +7735,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
77327735
}
77337736

77347737
// Member subscripts need some special validation logic.
7735-
if (auto nominalDecl = dc->getAsNominalTypeOrNominalTypeExtensionContext()) {
7738+
if (dc->isTypeContext()) {
77367739
// If this is a class member, mark it final if the class is final.
77377740
inferFinalAndDiagnoseIfNeeded(*this, SD, StaticSpellingKind::None);
77387741

@@ -7988,8 +7991,6 @@ static void finalizeType(TypeChecker &TC, NominalTypeDecl *nominal) {
79887991
assert(!nominal->hasClangNode());
79897992
assert(isa<SourceFile>(nominal->getModuleScopeContext()));
79907993

7991-
Optional<bool> lazyVarsAlreadyHaveImplementation;
7992-
79937994
if (auto *classDecl = dyn_cast<ClassDecl>(nominal))
79947995
TC.requestSuperclassLayout(classDecl);
79957996

@@ -8004,31 +8005,14 @@ static void finalizeType(TypeChecker &TC, NominalTypeDecl *nominal) {
80048005
TC.validateDecl(VD);
80058006

80068007
// The only thing left to do is synthesize storage for lazy variables.
8007-
// We only have to do that if it's a type from another file, though.
8008-
// In NDEBUG builds, bail out as soon as we can.
8009-
#ifdef NDEBUG
8010-
if (lazyVarsAlreadyHaveImplementation.hasValue() &&
8011-
lazyVarsAlreadyHaveImplementation.getValue())
8012-
continue;
8013-
#endif
80148008
auto *prop = dyn_cast<VarDecl>(D);
80158009
if (!prop)
80168010
continue;
80178011

80188012
if (prop->getAttrs().hasAttribute<LazyAttr>() && !prop->isStatic()
80198013
&& prop->getGetter()) {
8020-
bool hasImplementation = prop->getGetter()->hasBody();
8021-
8022-
if (lazyVarsAlreadyHaveImplementation.hasValue()) {
8023-
assert(lazyVarsAlreadyHaveImplementation.getValue() ==
8024-
hasImplementation &&
8025-
"only some lazy vars already have implementations");
8026-
} else {
8027-
lazyVarsAlreadyHaveImplementation = hasImplementation;
8028-
}
8029-
8030-
if (!hasImplementation)
8031-
TC.completeLazyVarImplementation(prop);
8014+
assert(!prop->getGetter()->hasBody());
8015+
TC.completeLazyVarImplementation(prop);
80328016
}
80338017
}
80348018

0 commit comments

Comments
 (0)