@@ -1166,10 +1166,15 @@ namespace {
1166
1166
class DeclChecker : public DeclVisitor <DeclChecker> {
1167
1167
public:
1168
1168
ASTContext &Ctx;
1169
+ SourceFile *SF;
1169
1170
1170
- explicit DeclChecker (ASTContext &ctx) : Ctx(ctx) {}
1171
+ explicit DeclChecker (ASTContext &ctx, SourceFile *SF ) : Ctx(ctx), SF(SF ) {}
1171
1172
1172
1173
ASTContext &getASTContext () const { return Ctx; }
1174
+ void addDelayedFunction (AbstractFunctionDecl *AFD) {
1175
+ if (!SF) return ;
1176
+ SF->DelayedFunctions .push_back (AFD);
1177
+ }
1173
1178
1174
1179
void visit (Decl *decl) {
1175
1180
if (auto *Stats = getASTContext ().Stats )
@@ -1385,7 +1390,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
1385
1390
TypeChecker::checkDeclAttributes (PBD);
1386
1391
1387
1392
bool isInSILMode = false ;
1388
- if (auto sourceFile = DC-> getParentSourceFile () )
1393
+ if (auto sourceFile = SF )
1389
1394
isInSILMode = sourceFile->Kind == SourceFileKind::SIL;
1390
1395
bool isTypeContext = DC->isTypeContext ();
1391
1396
@@ -1443,7 +1448,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
1443
1448
// protocol.
1444
1449
if (var->isStatic () && !isa<ProtocolDecl>(DC)) {
1445
1450
// ...but don't enforce this for SIL or module interface files.
1446
- switch (DC-> getParentSourceFile () ->Kind ) {
1451
+ switch (SF ->Kind ) {
1447
1452
case SourceFileKind::Interface:
1448
1453
case SourceFileKind::SIL:
1449
1454
return ;
@@ -1461,7 +1466,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
1461
1466
1462
1467
// Global variables require an initializer in normal source files.
1463
1468
if (DC->isModuleScopeContext ()) {
1464
- switch (DC-> getParentSourceFile () ->Kind ) {
1469
+ switch (SF ->Kind ) {
1465
1470
case SourceFileKind::Main:
1466
1471
case SourceFileKind::REPL:
1467
1472
case SourceFileKind::Interface:
@@ -1994,7 +1999,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
1994
1999
// Check for circular inheritance within the protocol.
1995
2000
(void )PD->hasCircularInheritedProtocols ();
1996
2001
1997
- auto *SF = PD->getParentSourceFile ();
1998
2002
if (SF) {
1999
2003
if (auto *tracker = SF->getReferencedNameTracker ()) {
2000
2004
bool isNonPrivate = (PD->getFormalAccess () > AccessLevel::FilePrivate);
@@ -2150,9 +2154,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
2150
2154
} else if (shouldSkipBodyTypechecking (FD)) {
2151
2155
FD->setBodySkipped (FD->getBodySourceRange ());
2152
2156
} else {
2153
- // FIXME: Remove TypeChecker dependency.
2154
- auto &TC = *Ctx.getLegacyGlobalTypeChecker ();
2155
- TC.definedFunctions .push_back (FD);
2157
+ addDelayedFunction (FD);
2156
2158
}
2157
2159
2158
2160
checkExplicitAvailability (FD);
@@ -2484,9 +2486,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
2484
2486
} else if (shouldSkipBodyTypechecking (CD)) {
2485
2487
CD->setBodySkipped (CD->getBodySourceRange ());
2486
2488
} else {
2487
- // FIXME: Remove TypeChecker dependency.
2488
- auto &TC = *Ctx.getLegacyGlobalTypeChecker ();
2489
- TC.definedFunctions .push_back (CD);
2489
+ addDelayedFunction (CD);
2490
2490
}
2491
2491
2492
2492
checkDefaultArguments (CD->getParameters ());
@@ -2501,14 +2501,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
2501
2501
} else if (shouldSkipBodyTypechecking (DD)) {
2502
2502
DD->setBodySkipped (DD->getBodySourceRange ());
2503
2503
} else {
2504
- // FIXME: Remove TypeChecker dependency.
2505
- auto &TC = *Ctx.getLegacyGlobalTypeChecker ();
2506
- TC.definedFunctions .push_back (DD);
2504
+ addDelayedFunction (DD);
2507
2505
}
2508
2506
}
2509
2507
};
2510
2508
} // end anonymous namespace
2511
2509
2512
2510
void TypeChecker::typeCheckDecl (Decl *D) {
2513
- DeclChecker (D->getASTContext ()).visit (D);
2511
+ auto *SF = D->getDeclContext ()->getParentSourceFile ();
2512
+ DeclChecker (D->getASTContext (), SF).visit (D);
2514
2513
}
0 commit comments