Skip to content

Commit d9ca3be

Browse files
authored
Many Things Don't Need a TypeChecker Part 2 (#27946)
Many Things Don't Need a TypeChecker Part 2
2 parents a5d3dda + 34ce9bd commit d9ca3be

9 files changed

+374
-369
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ TypeChecker::applyFunctionBuilderBodyTransform(FuncDecl *FD,
484484
BraceStmt *body,
485485
Type builderType) {
486486
// Try to build a single result expression.
487-
BuilderClosureVisitor visitor(Context, nullptr,
487+
auto &ctx = FD->getASTContext();
488+
BuilderClosureVisitor visitor(ctx, nullptr,
488489
/*wantExpr=*/true, builderType);
489490
Expr *returnExpr = visitor.visit(body);
490491
if (!returnExpr)
@@ -496,9 +497,8 @@ TypeChecker::applyFunctionBuilderBodyTransform(FuncDecl *FD,
496497
return nullptr;
497498

498499
auto loc = returnExpr->getStartLoc();
499-
auto returnStmt =
500-
new (Context) ReturnStmt(loc, returnExpr, /*implicit*/ true);
501-
return BraceStmt::create(Context, body->getLBraceLoc(), { returnStmt },
500+
auto returnStmt = new (ctx) ReturnStmt(loc, returnExpr, /*implicit*/ true);
501+
return BraceStmt::create(ctx, body->getLBraceLoc(), { returnStmt },
502502
body->getRBraceLoc());
503503
}
504504

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7045,7 +7045,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, ConcreteDeclRef callee,
70457045
apply->setIsSuper(isSuper);
70467046

70477047
cs.setExprTypes(apply);
7048-
Expr *result = tc.substituteInputSugarTypeForResult(apply);
7048+
Expr *result = TypeChecker::substituteInputSugarTypeForResult(apply);
70497049
cs.cacheExprTypes(result);
70507050

70517051
// If we have a covariant result type, perform the conversion now.

lib/Sema/MiscDiagnostics.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,11 +2918,11 @@ void swift::performAbstractFuncDeclDiagnostics(TypeChecker &TC,
29182918
}
29192919

29202920
// Perform MiscDiagnostics on Switch Statements.
2921-
static void checkSwitch(TypeChecker &TC, const SwitchStmt *stmt) {
2921+
static void checkSwitch(ASTContext &ctx, const SwitchStmt *stmt) {
29222922
// We want to warn about "case .Foo, .Bar where 1 != 100:" since the where
29232923
// clause only applies to the second case, and this is surprising.
29242924
for (auto cs : stmt->getCases()) {
2925-
TC.checkUnsupportedProtocolType(cs);
2925+
TypeChecker::checkUnsupportedProtocolType(ctx, cs);
29262926

29272927
// The case statement can have multiple case items, each can have a where.
29282928
// If we find a "where", and there is a preceding item without a where, and
@@ -2949,25 +2949,25 @@ static void checkSwitch(TypeChecker &TC, const SwitchStmt *stmt) {
29492949
if (prevLoc.isInvalid() || thisLoc.isInvalid())
29502950
continue;
29512951

2952-
auto &SM = TC.Context.SourceMgr;
2952+
auto &SM = ctx.SourceMgr;
29532953
auto prevLineCol = SM.getLineAndColumn(prevLoc);
29542954
if (SM.getLineNumber(thisLoc) != prevLineCol.first)
29552955
continue;
2956-
2957-
TC.diagnose(items[i].getWhereLoc(), diag::where_on_one_item)
2956+
2957+
ctx.Diags.diagnose(items[i].getWhereLoc(), diag::where_on_one_item)
29582958
.highlight(items[i].getPattern()->getSourceRange())
29592959
.highlight(where->getSourceRange());
29602960

29612961
// Whitespace it out to the same column as the previous item.
29622962
std::string whitespace(prevLineCol.second-1, ' ');
2963-
TC.diagnose(thisLoc, diag::add_where_newline)
2963+
ctx.Diags.diagnose(thisLoc, diag::add_where_newline)
29642964
.fixItInsert(thisLoc, "\n"+whitespace);
29652965

29662966
auto whereRange = SourceRange(items[i].getWhereLoc(),
29672967
where->getEndLoc());
29682968
auto charRange = Lexer::getCharSourceRangeFromSourceRange(SM, whereRange);
29692969
auto whereText = SM.extractText(charRange);
2970-
TC.diagnose(prevLoc, diag::duplicate_where)
2970+
ctx.Diags.diagnose(prevLoc, diag::duplicate_where)
29712971
.fixItInsertAfter(items[i-1].getEndLoc(), " " + whereText.str())
29722972
.highlight(items[i-1].getSourceRange());
29732973
}
@@ -3999,10 +3999,10 @@ void swift::performSyntacticExprDiagnostics(TypeChecker &TC, const Expr *E,
39993999
}
40004000

40014001
void swift::performStmtDiagnostics(TypeChecker &TC, const Stmt *S) {
4002-
TC.checkUnsupportedProtocolType(const_cast<Stmt *>(S));
4002+
TypeChecker::checkUnsupportedProtocolType(TC.Context, const_cast<Stmt *>(S));
40034003

40044004
if (auto switchStmt = dyn_cast<SwitchStmt>(S))
4005-
checkSwitch(TC, switchStmt);
4005+
checkSwitch(TC.Context, switchStmt);
40064006

40074007
checkStmtConditionTrailingClosure(TC, S);
40084008

0 commit comments

Comments
 (0)