Skip to content

Commit 15a8316

Browse files
committed
Sema: Remove finalizeAbstractStorageDecl()
Also since we're lazier about validating accessors now, relax some checks in the ASTVerifier so that it can tolerate implicit accessors without interface types. All other declarations must still have interface types in verifyChecked(). ASTVerifier: Tolerate implicit accessors without interface types
1 parent 8b4b15b commit 15a8316

File tree

3 files changed

+52
-51
lines changed

3 files changed

+52
-51
lines changed

lib/AST/ASTVerifier.cpp

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,44 +2471,48 @@ class Verifier : public ASTWalker {
24712471
Out << "property getter has parameters\n";
24722472
abort();
24732473
}
2474-
Type getterResultType = getter->getResultInterfaceType();
2475-
getterResultType =
2476-
var->getDeclContext()->mapTypeIntoContext(getterResultType);
2477-
if (!getterResultType->isEqual(typeForAccessors)) {
2478-
Out << "property and getter have mismatched types: '";
2479-
typeForAccessors.print(Out);
2480-
Out << "' vs. '";
2481-
getterResultType.print(Out);
2482-
Out << "'\n";
2483-
abort();
2474+
if (getter->hasInterfaceType()) {
2475+
Type getterResultType = getter->getResultInterfaceType();
2476+
getterResultType =
2477+
var->getDeclContext()->mapTypeIntoContext(getterResultType);
2478+
if (!getterResultType->isEqual(typeForAccessors)) {
2479+
Out << "property and getter have mismatched types: '";
2480+
typeForAccessors.print(Out);
2481+
Out << "' vs. '";
2482+
getterResultType.print(Out);
2483+
Out << "'\n";
2484+
abort();
2485+
}
24842486
}
24852487
}
24862488
}
24872489

24882490
if (const FuncDecl *setter = var->getSetter()) {
2489-
if (!setter->getResultInterfaceType()->isVoid()) {
2490-
Out << "property setter has non-Void result type\n";
2491-
abort();
2492-
}
2493-
if (setter->getParameters()->size() == 0) {
2494-
Out << "property setter has no parameters\n";
2495-
abort();
2496-
}
2497-
if (setter->getParameters()->size() != 1) {
2498-
Out << "property setter has 2+ parameters\n";
2499-
abort();
2500-
}
2501-
const ParamDecl *param = setter->getParameters()->get(0);
2502-
Type paramType = param->getInterfaceType();
2503-
if (!var->getDeclContext()->contextHasLazyGenericEnvironment()) {
2504-
paramType = var->getDeclContext()->mapTypeIntoContext(paramType);
2505-
if (!paramType->isEqual(typeForAccessors)) {
2506-
Out << "property and setter param have mismatched types:\n";
2507-
typeForAccessors.dump(Out, 2);
2508-
Out << "vs.\n";
2509-
paramType.dump(Out, 2);
2491+
if (setter->hasInterfaceType()) {
2492+
if (!setter->getResultInterfaceType()->isVoid()) {
2493+
Out << "property setter has non-Void result type\n";
2494+
abort();
2495+
}
2496+
if (setter->getParameters()->size() == 0) {
2497+
Out << "property setter has no parameters\n";
25102498
abort();
25112499
}
2500+
if (setter->getParameters()->size() != 1) {
2501+
Out << "property setter has 2+ parameters\n";
2502+
abort();
2503+
}
2504+
const ParamDecl *param = setter->getParameters()->get(0);
2505+
Type paramType = param->getInterfaceType();
2506+
if (!var->getDeclContext()->contextHasLazyGenericEnvironment()) {
2507+
paramType = var->getDeclContext()->mapTypeIntoContext(paramType);
2508+
if (!paramType->isEqual(typeForAccessors)) {
2509+
Out << "property and setter param have mismatched types:\n";
2510+
typeForAccessors.dump(Out, 2);
2511+
Out << "vs.\n";
2512+
paramType.dump(Out, 2);
2513+
abort();
2514+
}
2515+
}
25122516
}
25132517
}
25142518

@@ -3010,6 +3014,16 @@ class Verifier : public ASTWalker {
30103014
void verifyChecked(AbstractFunctionDecl *AFD) {
30113015
PrettyStackTraceDecl debugStack("verifying AbstractFunctionDecl", AFD);
30123016

3017+
if (!AFD->hasValidSignature()) {
3018+
if (isa<AccessorDecl>(AFD) && AFD->isImplicit())
3019+
return;
3020+
3021+
Out << "All functions except implicit accessors should be "
3022+
"validated by now\n";
3023+
AFD->dump(Out);
3024+
abort();
3025+
}
3026+
30133027
// If this function is generic or is within a generic context, it should
30143028
// have an interface type.
30153029
if (AFD->isGenericContext() !=

lib/Sema/CodeSynthesis.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,10 @@ LazyStoragePropertyRequest::evaluate(Evaluator &evaluator,
17081708
NameBuf += "$__lazy_storage_$_";
17091709
NameBuf += VD->getName().str();
17101710
auto StorageName = Context.getIdentifier(NameBuf);
1711+
1712+
if (!VD->hasInterfaceType())
1713+
Context.getLazyResolver()->resolveDeclSignature(VD);
1714+
17111715
auto StorageTy = OptionalType::get(VD->getType());
17121716
auto StorageInterfaceTy = OptionalType::get(VD->getInterfaceType());
17131717

lib/Sema/TypeCheckDecl.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,22 +2166,6 @@ static void validateAbstractStorageDecl(TypeChecker &TC,
21662166
TC.DeclsToFinalize.insert(storage);
21672167
}
21682168

2169-
static void finalizeAbstractStorageDecl(TypeChecker &TC,
2170-
AbstractStorageDecl *storage) {
2171-
TC.validateDecl(storage);
2172-
2173-
// Add any mandatory accessors now.
2174-
maybeAddAccessorsToStorage(storage);
2175-
2176-
for (auto accessor : storage->getAllAccessors()) {
2177-
// Are there accessors we can safely ignore here, like maybe observers?
2178-
TC.validateDecl(accessor);
2179-
2180-
// Finalize the accessors as well.
2181-
TC.DeclsToFinalize.insert(accessor);
2182-
}
2183-
}
2184-
21852169
/// Check the requirements in the where clause of the given \c source
21862170
/// to ensure that they don't introduce additional 'Self' requirements.
21872171
static void checkProtocolSelfRequirements(ProtocolDecl *proto,
@@ -4495,20 +4479,19 @@ static void finalizeType(TypeChecker &TC, NominalTypeDecl *nominal) {
44954479

44964480
TC.DeclsToFinalize.insert(VD);
44974481

4498-
// The only thing left to do is synthesize storage for lazy variables.
4482+
// The only thing left to do is synthesize storage for lazy variables
4483+
// and property wrappers.
44994484
auto *prop = dyn_cast<VarDecl>(D);
45004485
if (!prop)
45014486
continue;
45024487

45034488
if (prop->getAttrs().hasAttribute<LazyAttr>() && !prop->isStatic() &&
45044489
(!prop->getGetter() || !prop->getGetter()->hasBody())) {
4505-
finalizeAbstractStorageDecl(TC, prop);
45064490
(void) prop->getLazyStorageProperty();
45074491
}
45084492

45094493
// Ensure that we create the backing variable for a wrapped property.
45104494
if (prop->hasAttachedPropertyWrapper()) {
4511-
finalizeAbstractStorageDecl(TC, prop);
45124495
(void) prop->getPropertyWrapperBackingProperty();
45134496
}
45144497
}
@@ -4558,7 +4541,7 @@ void TypeChecker::finalizeDecl(ValueDecl *decl) {
45584541
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
45594542
finalizeType(*this, nominal);
45604543
} else if (auto storage = dyn_cast<AbstractStorageDecl>(decl)) {
4561-
finalizeAbstractStorageDecl(*this, storage);
4544+
maybeAddAccessorsToStorage(storage);
45624545
}
45634546
}
45644547

0 commit comments

Comments
 (0)