Skip to content

Many Things Don't Need a TypeChecker Part 2 #27946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/Sema/BuilderTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ TypeChecker::applyFunctionBuilderBodyTransform(FuncDecl *FD,
BraceStmt *body,
Type builderType) {
// Try to build a single result expression.
BuilderClosureVisitor visitor(Context, nullptr,
auto &ctx = FD->getASTContext();
BuilderClosureVisitor visitor(ctx, nullptr,
/*wantExpr=*/true, builderType);
Expr *returnExpr = visitor.visit(body);
if (!returnExpr)
Expand All @@ -496,9 +497,8 @@ TypeChecker::applyFunctionBuilderBodyTransform(FuncDecl *FD,
return nullptr;

auto loc = returnExpr->getStartLoc();
auto returnStmt =
new (Context) ReturnStmt(loc, returnExpr, /*implicit*/ true);
return BraceStmt::create(Context, body->getLBraceLoc(), { returnStmt },
auto returnStmt = new (ctx) ReturnStmt(loc, returnExpr, /*implicit*/ true);
return BraceStmt::create(ctx, body->getLBraceLoc(), { returnStmt },
body->getRBraceLoc());
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7045,7 +7045,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, ConcreteDeclRef callee,
apply->setIsSuper(isSuper);

cs.setExprTypes(apply);
Expr *result = tc.substituteInputSugarTypeForResult(apply);
Expr *result = TypeChecker::substituteInputSugarTypeForResult(apply);
cs.cacheExprTypes(result);

// If we have a covariant result type, perform the conversion now.
Expand Down
18 changes: 9 additions & 9 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2918,11 +2918,11 @@ void swift::performAbstractFuncDeclDiagnostics(TypeChecker &TC,
}

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

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

auto &SM = TC.Context.SourceMgr;
auto &SM = ctx.SourceMgr;
auto prevLineCol = SM.getLineAndColumn(prevLoc);
if (SM.getLineNumber(thisLoc) != prevLineCol.first)
continue;
TC.diagnose(items[i].getWhereLoc(), diag::where_on_one_item)

ctx.Diags.diagnose(items[i].getWhereLoc(), diag::where_on_one_item)
.highlight(items[i].getPattern()->getSourceRange())
.highlight(where->getSourceRange());

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

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

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

if (auto switchStmt = dyn_cast<SwitchStmt>(S))
checkSwitch(TC, switchStmt);
checkSwitch(TC.Context, switchStmt);

checkStmtConditionTrailingClosure(TC, S);

Expand Down
Loading