Skip to content

Commit 88ee618

Browse files
committed
Move Vending Top-Level Autoclosure discriminators into ASTContext
This bit has historically survived typechecking and parsing across source files. Stick it where we stick the other global state. This also means we don't have to thread TopLevelContext around anymore when invoking high-level typechecking entrypoints.
1 parent 0a3a130 commit 88ee618

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

include/swift/AST/ASTContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ class ASTContext final {
277277
/// The # of times we have performed typo correction.
278278
unsigned NumTypoCorrections = 0;
279279

280+
/// The next auto-closure discriminator. This needs to be preserved
281+
/// across invocations of both the parser and the type-checker.
282+
unsigned NextAutoClosureDiscriminator = 0;
283+
280284
private:
281285
/// The current generation number, which reflects the number of
282286
/// times that external modules have been loaded.

include/swift/Parse/LocalContext.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ class LocalContext {
6161
};
6262

6363
/// Information associated with parsing the top-level context.
64-
class TopLevelContext : public LocalContext {
65-
public:
66-
/// The next auto-closure discriminator. This needs to be preserved
67-
/// across invocations of both the parser and the type-checker.
68-
unsigned NextAutoClosureDiscriminator = 0;
69-
};
64+
class TopLevelContext : public LocalContext {};
7065

7166
} // end namespace swift
7267

lib/Sema/PCMacro.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ void swift::performPCMacro(SourceFile &SF, TopLevelContext &TLC) {
692692
if (NewBody != Body) {
693693
TLCD->setBody(NewBody);
694694
TypeChecker::checkTopLevelErrorHandling(TLCD);
695-
TypeChecker::contextualizeTopLevelCode(TLC, TLCD);
695+
TypeChecker::contextualizeTopLevelCode(TLCD);
696696
}
697697
return false;
698698
}

lib/Sema/TypeCheckStmt.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,14 @@ bool TypeChecker::contextualizeInitializer(Initializer *DC, Expr *E) {
231231
return CC.hasAutoClosures();
232232
}
233233

234-
void TypeChecker::contextualizeTopLevelCode(TopLevelContext &TLC,
235-
TopLevelCodeDecl *TLCD) {
236-
unsigned nextDiscriminator = TLC.NextAutoClosureDiscriminator;
234+
void TypeChecker::contextualizeTopLevelCode(TopLevelCodeDecl *TLCD) {
235+
auto &Context = TLCD->DeclContext::getASTContext();
236+
unsigned nextDiscriminator = Context.NextAutoClosureDiscriminator;
237237
ContextualizeClosures CC(TLCD, nextDiscriminator);
238238
TLCD->getBody()->walk(CC);
239-
assert(nextDiscriminator == TLC.NextAutoClosureDiscriminator &&
239+
assert(nextDiscriminator == Context.NextAutoClosureDiscriminator &&
240240
"reentrant/concurrent invocation of contextualizeTopLevelCode?");
241-
TLC.NextAutoClosureDiscriminator = CC.NextDiscriminator;
241+
Context.NextAutoClosureDiscriminator = CC.NextDiscriminator;
242242
}
243243

244244
/// Emits an error with a fixit for the case of unnecessary cast over a

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ void swift::performTypeChecking(SourceFile &SF, TopLevelContext &TLC,
366366
if (auto *TLCD = dyn_cast<TopLevelCodeDecl>(D)) {
367367
// Immediately perform global name-binding etc.
368368
TypeChecker::typeCheckTopLevelCodeDecl(TLCD);
369-
TypeChecker::contextualizeTopLevelCode(TLC, TLCD);
369+
TypeChecker::contextualizeTopLevelCode(TLCD);
370370
} else {
371371
TypeChecker::typeCheckDecl(D);
372372
}

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,7 @@ class TypeChecker final {
11591159
///
11601160
/// \returns true if any closures were found
11611161
static bool contextualizeInitializer(Initializer *DC, Expr *init);
1162-
static void contextualizeTopLevelCode(TopLevelContext &TLC,
1163-
TopLevelCodeDecl *TLCD);
1162+
static void contextualizeTopLevelCode(TopLevelCodeDecl *TLCD);
11641163

11651164
/// Return the type-of-reference of the given value.
11661165
///

0 commit comments

Comments
 (0)