Skip to content

Commit cab4e9f

Browse files
committed
Eagerly TypeCheck Synthesized Decls
1 parent 2f2b8af commit cab4e9f

File tree

5 files changed

+12
-42
lines changed

5 files changed

+12
-42
lines changed

include/swift/AST/SourceFile.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ class SourceFile final : public FileUnit {
147147
/// A set of synthesized declarations that need to be type checked.
148148
llvm::SmallVector<Decl *, 8> SynthesizedDecls;
149149

150-
/// We might perform type checking on the same source file more than once,
151-
/// if its the main file or a REPL instance, so keep track of the last
152-
/// checked synthesized declaration to avoid duplicating work.
153-
unsigned LastCheckedSynthesizedDecl = 0;
154-
155150
/// A mapping from Objective-C selectors to the methods that have
156151
/// those selectors.
157152
llvm::DenseMap<ObjCSelector, llvm::TinyPtrVector<AbstractFunctionDecl *>>

lib/Sema/DerivedConformances.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void DerivedConformance::addMembersToConformanceContext(
4040
auto IDC = cast<IterableDeclContext>(ConformanceDecl);
4141
for (auto child : children) {
4242
IDC->addMember(child);
43+
TypeChecker::typeCheckDecl(child);
4344
}
4445
}
4546

@@ -281,38 +282,28 @@ DerivedConformance::createSelfDeclRef(AbstractFunctionDecl *fn) {
281282
AccessorDecl *DerivedConformance::
282283
addGetterToReadOnlyDerivedProperty(VarDecl *property,
283284
Type propertyContextType) {
284-
auto getter =
285-
declareDerivedPropertyGetter(property, propertyContextType);
286-
287-
property->setImplInfo(StorageImplInfo::getImmutableComputed());
288-
property->setAccessors(SourceLoc(), {getter}, SourceLoc());
289-
290-
return getter;
291-
}
292-
293-
AccessorDecl *
294-
DerivedConformance::declareDerivedPropertyGetter(VarDecl *property,
295-
Type propertyContextType) {
296285
auto &C = property->getASTContext();
297286
auto parentDC = property->getDeclContext();
298287
ParameterList *params = ParameterList::createEmpty(C);
299288

300289
Type propertyInterfaceType = property->getInterfaceType();
301-
302-
auto getterDecl = AccessorDecl::create(C,
290+
291+
auto getter = AccessorDecl::create(C,
303292
/*FuncLoc=*/SourceLoc(), /*AccessorKeywordLoc=*/SourceLoc(),
304293
AccessorKind::Get, property,
305294
/*StaticLoc=*/SourceLoc(), StaticSpellingKind::None,
306295
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(),
307296
/*GenericParams=*/nullptr, params,
308297
TypeLoc::withoutLoc(propertyInterfaceType), parentDC);
309-
getterDecl->setImplicit();
310-
getterDecl->setIsTransparent(false);
298+
getter->setImplicit();
299+
getter->setIsTransparent(false);
311300

312-
getterDecl->copyFormalAccessFrom(property);
301+
getter->copyFormalAccessFrom(property);
313302

303+
property->setImplInfo(StorageImplInfo::getImmutableComputed());
304+
property->setAccessors(SourceLoc(), {getter}, SourceLoc());
314305

315-
return getterDecl;
306+
return getter;
316307
}
317308

318309
std::pair<VarDecl *, PatternBindingDecl *>

lib/Sema/DerivedConformances.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,7 @@ class DerivedConformance {
197197
/// Add a getter to a derived property. The property becomes read-only.
198198
static AccessorDecl *
199199
addGetterToReadOnlyDerivedProperty(VarDecl *property,
200-
Type propertyContextType);
201-
202-
/// Declare a getter for a derived property.
203-
/// The getter will not be added to the property yet.
204-
static AccessorDecl *declareDerivedPropertyGetter(VarDecl *property,
205-
Type propertyContextType);
200+
Type propertyContextType);
206201

207202
/// Build a reference to the 'self' decl of a derived function.
208203
static DeclRefExpr *createSelfDeclRef(AbstractFunctionDecl *fn);

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3675,6 +3675,7 @@ void TypeChecker::typeCheckDecl(Decl *D) {
36753675
// Returns 'nullptr' if this is the setter's 'newValue' parameter;
36763676
// otherwise, returns the corresponding parameter of the subscript
36773677
// declaration.
3678+
36783679
static ParamDecl *getOriginalParamFromAccessor(AbstractStorageDecl *storage,
36793680
AccessorDecl *accessor,
36803681
ParamDecl *param) {

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ static void bindExtensions(SourceFile &SF) {
294294

295295
static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC) {
296296
unsigned currentFunctionIdx = 0;
297-
unsigned currentSynthesizedDecl = SF.LastCheckedSynthesizedDecl;
298297
do {
299298
// Type check the body of each of the function in turn. Note that outside
300299
// functions must be visited before nested functions for type-checking to
@@ -306,18 +305,7 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
306305

307306
TypeChecker::typeCheckAbstractFunctionBody(AFD);
308307
}
309-
310-
// Type check synthesized functions and their bodies.
311-
for (unsigned n = SF.SynthesizedDecls.size();
312-
currentSynthesizedDecl != n;
313-
++currentSynthesizedDecl) {
314-
auto decl = SF.SynthesizedDecls[currentSynthesizedDecl];
315-
TypeChecker::typeCheckDecl(decl);
316-
}
317-
318-
} while (currentFunctionIdx < TC.definedFunctions.size() ||
319-
currentSynthesizedDecl < SF.SynthesizedDecls.size());
320-
308+
} while (currentFunctionIdx < TC.definedFunctions.size());
321309

322310
// Compute captures for functions and closures we visited.
323311
for (auto *closure : TC.ClosuresWithUncomputedCaptures) {

0 commit comments

Comments
 (0)