Skip to content

Commit fb8b060

Browse files
committed
Remove some remaining TypeCheckers
1 parent 7b9d28d commit fb8b060

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 3 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 {
@@ -1476,8 +1476,9 @@ bool TypeChecker::diagnoseSelfAssignment(const Expr *expr) {
14761476
auto srcDecl = findReferencedDecl(srcExpr);
14771477

14781478
if (dstDecl.second && dstDecl == srcDecl) {
1479-
diagnose(expr->getLoc(), dstDecl.first ? diag::self_assignment_prop
1480-
: 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)
14811482
.highlight(dstExpr->getSourceRange())
14821483
.highlight(srcExpr->getSourceRange());
14831484
return true;

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,15 +1154,17 @@ namespace {
11541154
return finish(true, expr);
11551155

11561156
if (isa<SubscriptExpr>(call->getSecond())) {
1157-
TC.diagnose(expr->getStartLoc(),
1158-
diag::cannot_pass_inout_arg_to_subscript);
1157+
getASTContext().Diags.diagnose(
1158+
expr->getStartLoc(),
1159+
diag::cannot_pass_inout_arg_to_subscript);
11591160
return finish(false, nullptr);
11601161
}
11611162
}
11621163
}
11631164
}
11641165

1165-
TC.diagnose(expr->getStartLoc(), diag::extraneous_address_of);
1166+
getASTContext().Diags.diagnose(expr->getStartLoc(),
1167+
diag::extraneous_address_of);
11661168
return finish(false, nullptr);
11671169
}
11681170

@@ -1648,7 +1650,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
16481650
if (auto *AE = dyn_cast<ArrowExpr>(E)) {
16491651
if (!AE->isFolded()) return nullptr;
16501652

1651-
auto diagnoseMissingParens = [](TypeChecker &TC, TypeRepr *tyR) {
1653+
auto diagnoseMissingParens = [](DiagnosticEngine &DE, TypeRepr *tyR) {
16521654
bool isVoid = false;
16531655
if (const auto Void = dyn_cast<SimpleIdentTypeRepr>(tyR)) {
16541656
if (Void->getIdentifier().str() == "Void") {
@@ -1657,24 +1659,25 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
16571659
}
16581660

16591661
if (isVoid) {
1660-
TC.diagnose(tyR->getStartLoc(), diag::function_type_no_parens)
1662+
DE.diagnose(tyR->getStartLoc(), diag::function_type_no_parens)
16611663
.fixItReplace(tyR->getStartLoc(), "()");
16621664
} else {
1663-
TC.diagnose(tyR->getStartLoc(), diag::function_type_no_parens)
1665+
DE.diagnose(tyR->getStartLoc(), diag::function_type_no_parens)
16641666
.highlight(tyR->getSourceRange())
16651667
.fixItInsert(tyR->getStartLoc(), "(")
16661668
.fixItInsertAfter(tyR->getEndLoc(), ")");
16671669
}
16681670
};
16691671

1672+
auto &DE = getASTContext().Diags;
16701673
auto extractInputTypeRepr = [&](Expr *E) -> TupleTypeRepr * {
16711674
if (!E)
16721675
return nullptr;
16731676
if (auto *TyE = dyn_cast<TypeExpr>(E)) {
16741677
auto ArgRepr = TyE->getTypeRepr();
16751678
if (auto *TTyRepr = dyn_cast<TupleTypeRepr>(ArgRepr))
16761679
return TTyRepr;
1677-
diagnoseMissingParens(TC, ArgRepr);
1680+
diagnoseMissingParens(DE, ArgRepr);
16781681
return TupleTypeRepr::create(getASTContext(), {ArgRepr},
16791682
ArgRepr->getSourceRange());
16801683
}
@@ -1689,7 +1692,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
16891692
auto ArgRepr = ArgsTypeExpr->getTypeRepr();
16901693
if (auto *TTyRepr = dyn_cast<TupleTypeRepr>(ArgRepr))
16911694
return TTyRepr;
1692-
diagnoseMissingParens(TC, ArgRepr);
1695+
diagnoseMissingParens(DE, ArgRepr);
16931696
return TupleTypeRepr::create(getASTContext(), {ArgRepr},
16941697
ArgRepr->getSourceRange());
16951698
}
@@ -1715,7 +1718,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
17151718

17161719
TupleTypeRepr *ArgsTypeRepr = extractInputTypeRepr(AE->getArgsExpr());
17171720
if (!ArgsTypeRepr) {
1718-
TC.diagnose(AE->getArgsExpr()->getLoc(),
1721+
DE.diagnose(AE->getArgsExpr()->getLoc(),
17191722
diag::expected_type_before_arrow);
17201723
auto ArgRange = AE->getArgsExpr()->getSourceRange();
17211724
auto ErrRepr = new (getASTContext()) ErrorTypeRepr(ArgRange);
@@ -1725,7 +1728,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
17251728

17261729
TypeRepr *ResultTypeRepr = extractTypeRepr(AE->getResultExpr());
17271730
if (!ResultTypeRepr) {
1728-
TC.diagnose(AE->getResultExpr()->getLoc(),
1731+
DE.diagnose(AE->getResultExpr()->getLoc(),
17291732
diag::expected_type_after_arrow);
17301733
ResultTypeRepr = new (getASTContext())
17311734
ErrorTypeRepr(AE->getResultExpr()->getSourceRange());
@@ -1802,6 +1805,7 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
18021805

18031806
TypeRepr *rootType = nullptr;
18041807
SmallVector<KeyPathExpr::Component, 4> components;
1808+
auto &DE = getASTContext().Diags;
18051809

18061810
// Pre-order visit of a sequence foo.bar[0]?.baz, which means that the
18071811
// components are pushed in reverse order.
@@ -1863,10 +1867,10 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
18631867
// \(<expr>) may be an attempt to write a string interpolation outside
18641868
// of a string literal; diagnose this case specially.
18651869
if (isa<ParenExpr>(expr) || isa<TupleExpr>(expr)) {
1866-
TC.diagnose(expr->getLoc(),
1870+
DE.diagnose(expr->getLoc(),
18671871
diag::expr_string_interpolation_outside_string);
18681872
} else {
1869-
TC.diagnose(expr->getLoc(),
1873+
DE.diagnose(expr->getLoc(),
18701874
diag::expr_swift_keypath_invalid_component);
18711875
}
18721876
}
@@ -1890,7 +1894,7 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
18901894
} else {
18911895
// FIXME: Probably better to catch this case earlier and force-eval as
18921896
// TypeExpr.
1893-
TC.diagnose(root->getLoc(),
1897+
DE.diagnose(root->getLoc(),
18941898
diag::expr_swift_keypath_not_starting_with_type);
18951899

18961900
// Traverse this path for recovery purposes: it may be a typo like
@@ -1905,7 +1909,7 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
19051909

19061910
// Key paths must be spelled with at least one component.
19071911
if (components.empty()) {
1908-
TC.diagnose(KPE->getLoc(), diag::expr_swift_keypath_empty);
1912+
DE.diagnose(KPE->getLoc(), diag::expr_swift_keypath_empty);
19091913
// Passes further down the pipeline expect keypaths to always have at least
19101914
// one component, so stuff an invalid component in the AST for recovery.
19111915
components.push_back(KeyPathExpr::Component());
@@ -1920,7 +1924,7 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
19201924
Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
19211925
// If constructor call is expected to produce an optional let's not attempt
19221926
// this optimization because literal initializers aren't failable.
1923-
if (!TC.getLangOpts().isSwiftVersionAtLeast(5)) {
1927+
if (!getASTContext().LangOpts.isSwiftVersionAtLeast(5)) {
19241928
if (!ExprStack.empty()) {
19251929
auto *parent = ExprStack.back();
19261930
if (isa<BindOptionalExpr>(parent) || isa<ForceValueExpr>(parent))

lib/Sema/TypeCheckPattern.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ namespace {
844844
// 1b. pat
845845
// type ~ ((T1, ..., Tn)) (n >= 2)
846846
// 2. pat ~ (P1, ..., Pm) (m >= 2)
847-
void implicitlyUntuplePatternIfApplicable(TypeChecker *TC,
847+
void implicitlyUntuplePatternIfApplicable(DiagnosticEngine &DE,
848848
Pattern *&enumElementInnerPat,
849849
Type enumPayloadType) {
850850
if (auto *tupleType = dyn_cast<TupleType>(enumPayloadType.getPointer())) {
@@ -853,20 +853,20 @@ void implicitlyUntuplePatternIfApplicable(TypeChecker *TC,
853853
auto *semantic = enumElementInnerPat->getSemanticsProvidingPattern();
854854
if (auto *tuplePattern = dyn_cast<TuplePattern>(semantic)) {
855855
if (tuplePattern->getNumElements() >= 2) {
856-
TC->diagnose(tuplePattern->getLoc(),
857-
diag::matching_tuple_pattern_with_many_assoc_values);
856+
DE.diagnose(tuplePattern->getLoc(),
857+
diag::matching_tuple_pattern_with_many_assoc_values);
858858
enumElementInnerPat = semantic;
859859
}
860860
} else {
861-
TC->diagnose(enumElementInnerPat->getLoc(),
862-
diag::matching_pattern_with_many_assoc_values);
861+
DE.diagnose(enumElementInnerPat->getLoc(),
862+
diag::matching_pattern_with_many_assoc_values);
863863
}
864864
}
865865
} else if (auto *tupleType = enumPayloadType->getAs<TupleType>()) {
866866
if (tupleType->getNumElements() >= 2
867867
&& enumElementInnerPat->getKind() == PatternKind::Tuple)
868-
TC->diagnose(enumElementInnerPat->getLoc(),
869-
diag::matching_many_patterns_with_tupled_assoc_value);
868+
DE.diagnose(enumElementInnerPat->getLoc(),
869+
diag::matching_many_patterns_with_tupled_assoc_value);
870870
}
871871
}
872872
}
@@ -1361,7 +1361,7 @@ bool TypeChecker::coercePatternToType(Pattern *&P, TypeResolution resolution,
13611361
newSubOptions.setContext(TypeResolverContext::EnumPatternPayload);
13621362
newSubOptions |= TypeResolutionFlags::FromNonInferredPattern;
13631363

1364-
::implicitlyUntuplePatternIfApplicable(this, sub, elementType);
1364+
::implicitlyUntuplePatternIfApplicable(Context.Diags, sub, elementType);
13651365

13661366
if (coercePatternToType(sub, resolution, elementType, newSubOptions))
13671367
return true;

0 commit comments

Comments
 (0)