Skip to content

Commit d8dfbbc

Browse files
committed
performAbstractFuncDeclDiagnostics doesn't need a TypeChecker
1 parent fb55c03 commit d8dfbbc

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,8 @@ class VarDeclUsageChecker : public ASTWalker {
20372037
void operator=(const VarDeclUsageChecker &) = delete;
20382038

20392039
public:
2040-
VarDeclUsageChecker(TypeChecker &TC, AbstractFunctionDecl *AFD) : Diags(TC.Diags) {
2040+
VarDeclUsageChecker(AbstractFunctionDecl *AFD)
2041+
: Diags(AFD->getASTContext().Diags) {
20412042
// If this AFD is a setter, track the parameter and the getter for
20422043
// the containing property so if newValue isn't used but the getter is used
20432044
// an error can be reported.
@@ -2054,7 +2055,7 @@ class VarDeclUsageChecker : public ASTWalker {
20542055

20552056
VarDeclUsageChecker(DiagnosticEngine &Diags) : Diags(Diags) {}
20562057

2057-
VarDeclUsageChecker(TypeChecker &tc, VarDecl *vd) : Diags(tc.Diags) {
2058+
VarDeclUsageChecker(VarDecl *vd) : Diags(vd->getASTContext().Diags) {
20582059
// Track a specific VarDecl
20592060
VarDecls[vd] = 0;
20602061
if (auto *childVd = vd->getCorrespondingCaseBodyVariable().getPtrOrNull()) {
@@ -2283,7 +2284,7 @@ class VarDeclUsageChecker : public ASTWalker {
22832284
/// An AST walker that determines the underlying type of an opaque return decl
22842285
/// from its associated function body.
22852286
class OpaqueUnderlyingTypeChecker : public ASTWalker {
2286-
TypeChecker &TC;
2287+
ASTContext &Ctx;
22872288
AbstractFunctionDecl *Implementation;
22882289
OpaqueTypeDecl *OpaqueDecl;
22892290
BraceStmt *Body;
@@ -2292,11 +2293,10 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
22922293
bool HasInvalidReturn = false;
22932294

22942295
public:
2295-
OpaqueUnderlyingTypeChecker(TypeChecker &TC,
2296-
AbstractFunctionDecl *Implementation,
2296+
OpaqueUnderlyingTypeChecker(AbstractFunctionDecl *Implementation,
22972297
OpaqueTypeDecl *OpaqueDecl,
22982298
BraceStmt *Body)
2299-
: TC(TC),
2299+
: Ctx(Implementation->getASTContext()),
23002300
Implementation(Implementation),
23012301
OpaqueDecl(OpaqueDecl),
23022302
Body(Body)
@@ -2316,8 +2316,7 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
23162316
// If there are no candidates, then the body has no return statements, and
23172317
// we have nothing to infer the underlying type from.
23182318
if (Candidates.empty()) {
2319-
TC.diagnose(Implementation->getLoc(),
2320-
diag::opaque_type_no_underlying_type_candidates);
2319+
Implementation->diagnose(diag::opaque_type_no_underlying_type_candidates);
23212320
return;
23222321
}
23232322

@@ -2339,12 +2338,12 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
23392338
}
23402339

23412340
if (mismatch) {
2342-
TC.diagnose(Implementation->getLoc(),
2343-
diag::opaque_type_mismatched_underlying_type_candidates);
2341+
Implementation->diagnose(
2342+
diag::opaque_type_mismatched_underlying_type_candidates);
23442343
for (auto candidate : Candidates) {
2345-
TC.diagnose(candidate.first->getLoc(),
2346-
diag::opaque_type_underlying_type_candidate_here,
2347-
candidate.second);
2344+
Ctx.Diags.diagnose(candidate.first->getLoc(),
2345+
diag::opaque_type_underlying_type_candidate_here,
2346+
candidate.second);
23482347
}
23492348
return;
23502349
}
@@ -2356,9 +2355,9 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
23562355
});
23572356

23582357
if (isSelfReferencing) {
2359-
TC.diagnose(Candidates.front().first->getLoc(),
2360-
diag::opaque_type_self_referential_underlying_type,
2361-
underlyingType);
2358+
Ctx.Diags.diagnose(Candidates.front().first->getLoc(),
2359+
diag::opaque_type_self_referential_underlying_type,
2360+
underlyingType);
23622361
return;
23632362
}
23642363

@@ -2885,14 +2884,14 @@ void VarDeclUsageChecker::handleIfConfig(IfConfigDecl *ICD) {
28852884
/// Apply the warnings managed by VarDeclUsageChecker to the top level
28862885
/// code declarations that haven't been checked yet.
28872886
void swift::
2888-
performTopLevelDeclDiagnostics(TypeChecker &TC, TopLevelCodeDecl *TLCD) {
2889-
VarDeclUsageChecker checker(TC.Diags);
2887+
performTopLevelDeclDiagnostics(TopLevelCodeDecl *TLCD) {
2888+
auto &ctx = TLCD->getDeclContext()->getASTContext();
2889+
VarDeclUsageChecker checker(ctx.Diags);
28902890
TLCD->walk(checker);
28912891
}
28922892

28932893
/// Perform diagnostics for func/init/deinit declarations.
2894-
void swift::performAbstractFuncDeclDiagnostics(TypeChecker &TC,
2895-
AbstractFunctionDecl *AFD,
2894+
void swift::performAbstractFuncDeclDiagnostics(AbstractFunctionDecl *AFD,
28962895
BraceStmt *body) {
28972896
assert(body && "Need a body to check");
28982897

@@ -2902,17 +2901,17 @@ void swift::performAbstractFuncDeclDiagnostics(TypeChecker &TC,
29022901

29032902
// Check for unused variables, as well as variables that are could be
29042903
// declared as constants.
2905-
body->walk(VarDeclUsageChecker(TC, AFD));
2904+
body->walk(VarDeclUsageChecker(AFD));
29062905

29072906
// If the function has an opaque return type, check the return expressions
29082907
// to determine the underlying type.
29092908
if (auto opaqueResultTy = AFD->getOpaqueResultTypeDecl()) {
2910-
OpaqueUnderlyingTypeChecker(TC, AFD, opaqueResultTy, body).check();
2909+
OpaqueUnderlyingTypeChecker(AFD, opaqueResultTy, body).check();
29112910
} else if (auto accessor = dyn_cast<AccessorDecl>(AFD)) {
29122911
if (accessor->isGetter()) {
29132912
if (auto opaqueResultTy
29142913
= accessor->getStorage()->getOpaqueResultTypeDecl()) {
2915-
OpaqueUnderlyingTypeChecker(TC, AFD, opaqueResultTy, body).check();
2914+
OpaqueUnderlyingTypeChecker(AFD, opaqueResultTy, body).check();
29162915
}
29172916
}
29182917
}

lib/Sema/MiscDiagnostics.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@ void performSyntacticExprDiagnostics(TypeChecker &TC, const Expr *E,
4242
/// Emit diagnostics for a given statement.
4343
void performStmtDiagnostics(TypeChecker &TC, const Stmt *S);
4444

45-
void performAbstractFuncDeclDiagnostics(TypeChecker &TC,
46-
AbstractFunctionDecl *AFD,
45+
void performAbstractFuncDeclDiagnostics(AbstractFunctionDecl *AFD,
4746
BraceStmt *body);
4847

4948
/// Perform diagnostics on the top level code declaration.
50-
void performTopLevelDeclDiagnostics(TypeChecker &TC, TopLevelCodeDecl *TLCD);
49+
void performTopLevelDeclDiagnostics(TopLevelCodeDecl *TLCD);
5150

5251
/// Emit a fix-it to set the access of \p VD to \p desiredAccess.
5352
///

lib/Sema/TypeCheckStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ TypeCheckFunctionBodyUntilRequest::evaluate(Evaluator &evaluator,
21782178

21792179
// If nothing went wrong yet, perform extra checking.
21802180
if (!hadError && endTypeCheckLoc.isInvalid())
2181-
performAbstractFuncDeclDiagnostics(tc, AFD, body);
2181+
performAbstractFuncDeclDiagnostics(AFD, body);
21822182

21832183
// Wire up the function body now.
21842184
AFD->setBody(body, AbstractFunctionDecl::BodyKind::TypeChecked);
@@ -2228,5 +2228,5 @@ void TypeChecker::typeCheckTopLevelCodeDecl(TopLevelCodeDecl *TLCD) {
22282228
StmtChecker(*this, TLCD).typeCheckStmt(Body);
22292229
TLCD->setBody(Body);
22302230
checkTopLevelErrorHandling(TLCD);
2231-
performTopLevelDeclDiagnostics(*this, TLCD);
2231+
performTopLevelDeclDiagnostics(TLCD);
22322232
}

0 commit comments

Comments
 (0)