Skip to content

Commit 77393e3

Browse files
authored
Merge pull request #28118 from CodaFi/checkered-past
[NFC] Drop More TypeCheckers
2 parents 2394bab + e6dbfa3 commit 77393e3

16 files changed

+735
-782
lines changed

lib/Sema/CSApply.cpp

Lines changed: 417 additions & 493 deletions
Large diffs are not rendered by default.

lib/Sema/CSDiag.cpp

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
117117

118118
template<typename ...ArgTypes>
119119
InFlightDiagnostic diagnose(ArgTypes &&...Args) {
120-
return CS.TC.diagnose(std::forward<ArgTypes>(Args)...);
120+
return CS.getASTContext().Diags.diagnose(std::forward<ArgTypes>(Args)...);
121121
}
122122

123123
/// Attempt to diagnose a failure without taking into account the specific
@@ -1270,7 +1270,7 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
12701270

12711271
// If it failed and diagnosed something, then we're done.
12721272
if (!exprType)
1273-
return CS.TC.Diags.hadAnyError();
1273+
return CS.getASTContext().Diags.hadAnyError();
12741274

12751275
// If we don't have a type for the expression, then we cannot use it in
12761276
// conversion constraint diagnostic generation. If the types match, then it
@@ -1647,14 +1647,14 @@ static DeclName getBaseName(DeclContext *context) {
16471647
};
16481648

16491649
static void emitFixItForExplicitlyQualifiedReference(
1650-
TypeChecker &tc, UnresolvedDotExpr *UDE,
1650+
DiagnosticEngine &de, UnresolvedDotExpr *UDE,
16511651
decltype(diag::fix_unqualified_access_top_level) diag, DeclName baseName,
16521652
DescriptiveDeclKind kind) {
16531653
auto name = baseName.getBaseIdentifier();
16541654
SmallString<32> namePlusDot = name.str();
16551655
namePlusDot.push_back('.');
16561656

1657-
tc.diagnose(UDE->getLoc(), diag, namePlusDot, kind, name)
1657+
de.diagnose(UDE->getLoc(), diag, namePlusDot, kind, name)
16581658
.fixItInsert(UDE->getStartLoc(), namePlusDot);
16591659
}
16601660

@@ -1678,14 +1678,16 @@ void ConstraintSystem::diagnoseDeprecatedConditionalConformanceOuterAccess(
16781678
? choiceParentDecl->getDescriptiveKind()
16791679
: DescriptiveDeclKind::Module;
16801680

1681-
TC.diagnose(UDE->getLoc(),
1681+
auto &DE = getASTContext().Diags;
1682+
DE.diagnose(UDE->getLoc(),
16821683
diag::warn_deprecated_conditional_conformance_outer_access,
16831684
UDE->getName(), choiceKind, choiceParentKind, choiceBaseName,
16841685
innerChoice->getDescriptiveKind(),
16851686
innerParentDecl->getDescriptiveKind(), innerBaseName);
16861687

16871688
emitFixItForExplicitlyQualifiedReference(
1688-
TC, UDE, diag::fix_deprecated_conditional_conformance_outer_access,
1689+
getASTContext().Diags, UDE,
1690+
diag::fix_deprecated_conditional_conformance_outer_access,
16891691
choiceBaseName, choiceKind);
16901692
}
16911693

@@ -1705,7 +1707,7 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
17051707
if (CCI.empty() || !CCI[0].getDecl())
17061708
return false;
17071709

1708-
auto &TC = CS.TC;
1710+
auto &ctx = CS.getASTContext();
17091711
// Call expression is formed as 'foo.bar' where 'foo' might be an
17101712
// implicit "Self" reference, such use wouldn't provide good diagnostics
17111713
// for situations where instance members have equal names to functions in
@@ -1719,7 +1721,7 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
17191721
return false;
17201722

17211723
auto baseDecl = baseExpr->getDecl();
1722-
if (!baseExpr->isImplicit() || baseDecl->getFullName() != TC.Context.Id_self)
1724+
if (!baseExpr->isImplicit() || baseDecl->getFullName() != ctx.Id_self)
17231725
return false;
17241726

17251727
// Our base expression is an implicit 'self.' reference e.g.
@@ -1837,21 +1839,23 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
18371839
auto baseName = getBaseName(choice->getDeclContext());
18381840

18391841
auto origCandidate = CCI[0].getDecl();
1840-
TC.diagnose(UDE->getLoc(), diagnostic, UDE->getName(),
1841-
origCandidate->getDescriptiveKind(),
1842-
origCandidate->getFullName(), choice->getDescriptiveKind(),
1843-
choice->getFullName(), baseKind, baseName);
1842+
ctx.Diags.diagnose(UDE->getLoc(), diagnostic, UDE->getName(),
1843+
origCandidate->getDescriptiveKind(),
1844+
origCandidate->getFullName(),
1845+
choice->getDescriptiveKind(),
1846+
choice->getFullName(), baseKind, baseName);
18441847

18451848
auto topLevelDiag = diag::fix_unqualified_access_top_level;
18461849
if (baseKind == DescriptiveDeclKind::Module)
18471850
topLevelDiag = diag::fix_unqualified_access_top_level_multi;
18481851

1849-
emitFixItForExplicitlyQualifiedReference(TC, UDE, topLevelDiag, baseName,
1852+
emitFixItForExplicitlyQualifiedReference(ctx.Diags, UDE, topLevelDiag,
1853+
baseName,
18501854
choice->getDescriptiveKind());
18511855

18521856
for (auto &candidate : calleeInfo.candidates) {
18531857
if (auto decl = candidate.getDecl())
1854-
TC.diagnose(decl, diag::decl_declared_here, decl->getFullName());
1858+
ctx.Diags.diagnose(decl, diag::decl_declared_here, decl->getFullName());
18551859
}
18561860

18571861
return true;
@@ -1912,7 +1916,6 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
19121916
}
19131917

19141918
class ArgumentMatcher : public MatchCallArgumentListener {
1915-
TypeChecker &TC;
19161919
Expr *ArgExpr;
19171920
ArrayRef<AnyFunctionType::Param> &Parameters;
19181921
const ParameterListInfo &ParamInfo;
@@ -1934,7 +1937,7 @@ class ArgumentMatcher : public MatchCallArgumentListener {
19341937
const ParameterListInfo &paramInfo,
19351938
SmallVectorImpl<AnyFunctionType::Param> &args,
19361939
CalleeCandidateInfo &CCI, bool isSubscript)
1937-
: TC(CCI.CS.TC), ArgExpr(argExpr), Parameters(params),
1940+
: ArgExpr(argExpr), Parameters(params),
19381941
ParamInfo(paramInfo), Arguments(args), CandidateInfo(CCI),
19391942
IsSubscript(isSubscript) {}
19401943

@@ -1950,7 +1953,8 @@ class ArgumentMatcher : public MatchCallArgumentListener {
19501953
assert(!newNames.empty() && "No arguments were re-labeled");
19511954

19521955
// Let's diagnose labeling problem but only related to corrected ones.
1953-
if (diagnoseArgumentLabelError(TC.Context, ArgExpr, newNames, IsSubscript))
1956+
if (diagnoseArgumentLabelError(CandidateInfo.CS.getASTContext(), ArgExpr,
1957+
newNames, IsSubscript))
19541958
Diagnosed = true;
19551959

19561960
return true;
@@ -1981,7 +1985,6 @@ diagnoseSingleCandidateFailures(CalleeCandidateInfo &CCI, Expr *fnExpr,
19811985
return false;
19821986

19831987
auto candidate = CCI[0];
1984-
auto &TC = CCI.CS.TC;
19851988

19861989
if (!candidate.hasParameters())
19871990
return false;
@@ -2015,7 +2018,7 @@ diagnoseSingleCandidateFailures(CalleeCandidateInfo &CCI, Expr *fnExpr,
20152018
};
20162019
Expr *innerE = getInnerExpr(argExpr);
20172020

2018-
InFlightDiagnostic diag = TC.diagnose(
2021+
InFlightDiagnostic diag = CCI.CS.getASTContext().Diags.diagnose(
20192022
fnExpr->getLoc(),
20202023
diag::invalid_initialization_parameter_same_type, resTy);
20212024
diag.highlight((innerE ? innerE : argExpr)->getSourceRange());
@@ -2063,13 +2066,14 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
20632066
ArrayRef<Identifier> argLabels) {
20642067
if (auto *MTT = CS.getType(fnExpr)->getAs<MetatypeType>()) {
20652068
auto instTy = MTT->getInstanceType();
2069+
auto &DE = CS.getASTContext().Diags;
20662070
if (instTy->getAnyNominal()) {
20672071
// If we are invoking a constructor on a nominal type and there are
20682072
// absolutely no candidates, then they must all be private.
20692073
if (CCI.empty() || (CCI.size() == 1 && CCI.candidates[0].getDecl() &&
20702074
isa<ProtocolDecl>(CCI.candidates[0].getDecl()))) {
2071-
CS.TC.diagnose(fnExpr->getLoc(), diag::no_accessible_initializers,
2072-
instTy);
2075+
DE.diagnose(fnExpr->getLoc(), diag::no_accessible_initializers,
2076+
instTy);
20732077
return true;
20742078
}
20752079
// continue below
@@ -2078,9 +2082,9 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
20782082
// is malformed.
20792083
SourceRange initExprRange(fnExpr->getSourceRange().Start,
20802084
argExpr->getSourceRange().End);
2081-
CS.TC.diagnose(fnExpr->getLoc(), instTy->isExistentialType() ?
2082-
diag::construct_protocol_by_name :
2083-
diag::non_nominal_no_initializers, instTy)
2085+
DE.diagnose(fnExpr->getLoc(), instTy->isExistentialType() ?
2086+
diag::construct_protocol_by_name :
2087+
diag::non_nominal_no_initializers, instTy)
20842088
.highlight(initExprRange);
20852089
return true;
20862090
}
@@ -2362,8 +2366,8 @@ static bool diagnoseClosureExplicitParameterMismatch(
23622366
continue;
23632367

23642368
if (!CS.TC.isConvertibleTo(argType, paramType, CS.DC)) {
2365-
CS.TC.diagnose(loc, diag::types_not_convertible, false, paramType,
2366-
argType);
2369+
CS.getASTContext().Diags.diagnose(loc, diag::types_not_convertible,
2370+
false, paramType, argType);
23672371
return true;
23682372
}
23692373
}
@@ -2478,9 +2482,10 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
24782482
auto processor = [&](Type resultType, Type expectedResultType) -> bool {
24792483
if (resultType && expectedResultType) {
24802484
if (!resultType->isEqual(expectedResultType)) {
2481-
CS.TC.diagnose(closureExpr->getEndLoc(),
2482-
diag::cannot_convert_closure_result, resultType,
2483-
expectedResultType);
2485+
auto &DE = CS.getASTContext().Diags;
2486+
DE.diagnose(closureExpr->getEndLoc(),
2487+
diag::cannot_convert_closure_result, resultType,
2488+
expectedResultType);
24842489
return true;
24852490
}
24862491

@@ -2650,7 +2655,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
26502655
// possible.
26512656
fnExpr = typeCheckChildIndependently(callExpr->getFn());
26522657
if (!fnExpr) {
2653-
return CS.TC.Diags.hadAnyError();
2658+
return CS.getASTContext().Diags.hadAnyError();
26542659
}
26552660
}
26562661

@@ -3298,7 +3303,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
32983303
}
32993304

33003305
// Coerce parameter types here only if there are no unresolved
3301-
CS.TC.coerceParameterListToType(params, CE, fnType);
3306+
TypeChecker::coerceParameterListToType(params, CE, fnType);
33023307
expectedResultType = fnType->getResult();
33033308
}
33043309

@@ -3525,19 +3530,18 @@ bool FailureDiagnosis::visitDictionaryExpr(DictionaryExpr *E) {
35253530
/// _ColorLiteralType), suggest that the user import the appropriate module for
35263531
/// the target.
35273532
bool FailureDiagnosis::visitObjectLiteralExpr(ObjectLiteralExpr *E) {
3528-
auto &TC = CS.getTypeChecker();
3529-
35303533
// Type check the argument first.
35313534
auto protocol = TypeChecker::getLiteralProtocol(CS.getASTContext(), E);
35323535
if (!protocol)
35333536
return false;
3534-
DeclName constrName = TC.getObjectLiteralConstructorName(E);
3537+
auto constrName =
3538+
TypeChecker::getObjectLiteralConstructorName(CS.getASTContext(), E);
35353539
assert(constrName);
35363540
auto *constr = dyn_cast_or_null<ConstructorDecl>(
35373541
protocol->getSingleRequirement(constrName));
35383542
if (!constr)
35393543
return false;
3540-
auto paramType = TC.getObjectLiteralParameterType(E, constr);
3544+
auto paramType = TypeChecker::getObjectLiteralParameterType(E, constr);
35413545
if (!typeCheckChildIndependently(
35423546
E->getArg(), paramType, CTP_CallArgument))
35433547
return true;
@@ -3580,11 +3584,11 @@ bool FailureDiagnosis::visitObjectLiteralExpr(ObjectLiteralExpr *E) {
35803584

35813585
// Emit the diagnostic.
35823586
const auto plainName = E->getLiteralKindPlainName();
3583-
TC.diagnose(E->getLoc(), diag::object_literal_default_type_missing,
3584-
plainName);
3587+
Ctx.Diags.diagnose(E->getLoc(), diag::object_literal_default_type_missing,
3588+
plainName);
35853589
if (!importModule.empty()) {
3586-
TC.diagnose(E->getLoc(), diag::object_literal_resolve_import,
3587-
importModule, importDefaultTypeName, plainName);
3590+
Ctx.Diags.diagnose(E->getLoc(), diag::object_literal_resolve_import,
3591+
importModule, importDefaultTypeName, plainName);
35883592
}
35893593
return true;
35903594
}

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ template <typename... ArgTypes>
8989
InFlightDiagnostic
9090
FailureDiagnostic::emitDiagnostic(ArgTypes &&... Args) const {
9191
auto &cs = getConstraintSystem();
92-
return cs.TC.diagnose(std::forward<ArgTypes>(Args)...);
92+
return cs.getASTContext().Diags.diagnose(std::forward<ArgTypes>(Args)...);
9393
}
9494

9595
Expr *FailureDiagnostic::findParentExpr(Expr *subExpr) const {
@@ -1333,10 +1333,9 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
13331333
return false;
13341334

13351335
if (auto assignExpr = dyn_cast<AssignExpr>(diagExpr)) {
1336-
auto &TC = getTypeChecker();
13371336
// Let's check whether this is an attempt to assign
13381337
// variable or property to itself.
1339-
if (TC.diagnoseSelfAssignment(assignExpr))
1338+
if (TypeChecker::diagnoseSelfAssignment(assignExpr))
13401339
return true;
13411340

13421341
diagExpr = assignExpr->getDest();
@@ -1477,8 +1476,9 @@ bool TypeChecker::diagnoseSelfAssignment(const Expr *expr) {
14771476
auto srcDecl = findReferencedDecl(srcExpr);
14781477

14791478
if (dstDecl.second && dstDecl == srcDecl) {
1480-
diagnose(expr->getLoc(), dstDecl.first ? diag::self_assignment_prop
1481-
: diag::self_assignment_var)
1479+
auto &DE = dstDecl.second->getASTContext().Diags;
1480+
DE.diagnose(expr->getLoc(), dstDecl.first ? diag::self_assignment_prop
1481+
: diag::self_assignment_var)
14821482
.highlight(dstExpr->getSourceRange())
14831483
.highlight(srcExpr->getSourceRange());
14841484
return true;

lib/Sema/CSFix.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,11 +885,10 @@ bool IgnoreAssignmentDestinationType::diagnose(Expr *root, bool asNote) const {
885885
// `let _ = { $0 = $0 = 42 }`. Assignment chaining results in
886886
// type mismatch between result of the previous assignment and the next.
887887
{
888-
auto &TC = cs.getTypeChecker();
889888
llvm::SaveAndRestore<AssignExpr *> anchor(AE);
890889

891890
do {
892-
if (TC.diagnoseSelfAssignment(AE))
891+
if (TypeChecker::diagnoseSelfAssignment(AE))
893892
return true;
894893
} while ((AE = dyn_cast_or_null<AssignExpr>(cs.getParentExpr(AE))));
895894
}

0 commit comments

Comments
 (0)