Skip to content

Commit 7bad9aa

Browse files
committed
Drop the TypeChecker out of ConstraintSystem
1 parent e7ef8ab commit 7bad9aa

14 files changed

+53
-58
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ ConstraintSystem::TypeMatchResult ConstraintSystem::applyFunctionBuilder(
516516

517517
// Pre-check the closure body: pre-check any expressions in it and look
518518
// for return statements.
519-
switch (TC.preCheckFunctionBuilderClosureBody(closure)) {
519+
switch (getTypeChecker().preCheckFunctionBuilderClosureBody(closure)) {
520520
case FunctionBuilderClosurePreCheck::Okay:
521521
// If the pre-check was okay, apply the function-builder transform.
522522
break;
@@ -582,7 +582,7 @@ ConstraintSystem::TypeMatchResult ConstraintSystem::applyFunctionBuilder(
582582
// that CSGen might have.
583583
//
584584
// TODO: just build the AST the way we want it in the first place.
585-
if (TC.preCheckExpression(singleExpr, closure))
585+
if (getTypeChecker().preCheckExpression(singleExpr, closure))
586586
return getTypeMatchFailure(locator);
587587

588588
singleExpr = generateConstraints(singleExpr, closure);

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4494,8 +4494,8 @@ namespace {
44944494
cs.cacheType(outerClosure);
44954495

44964496
// The inner closure at least will definitely have a capture.
4497-
cs.TC.ClosuresWithUncomputedCaptures.push_back(outerClosure);
4498-
cs.TC.ClosuresWithUncomputedCaptures.push_back(closure);
4497+
cs.getTypeChecker().ClosuresWithUncomputedCaptures.push_back(outerClosure);
4498+
cs.getTypeChecker().ClosuresWithUncomputedCaptures.push_back(closure);
44994499

45004500
// let outerApply = "\( outerClosure )( \(E) )"
45014501
auto outerApply = CallExpr::createImplicit(ctx, outerClosure, {E}, {});
@@ -5408,7 +5408,7 @@ Expr *ExprRewriter::coerceCallArguments(Expr *arg, AnyFunctionType *funcType,
54085408
arg, closureType->getResult(),
54095409
locator.withPathElement(ConstraintLocator::AutoclosureResult));
54105410

5411-
convertedArg = cs.TC.buildAutoClosureExpr(dc, arg, closureType);
5411+
convertedArg = cs.getTypeChecker().buildAutoClosureExpr(dc, arg, closureType);
54125412
cs.cacheExprTypes(convertedArg);
54135413
} else {
54145414
convertedArg = coerceToType(

lib/Sema/CSDiag.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,8 @@ Expr *FailureDiagnosis::typeCheckChildIndependently(
10171017
// expression (which may lead to infinite recursion). If the client is
10181018
// telling us that it knows what it is doing, then believe it.
10191019
if (!options.contains(TCC_ForceRecheck)) {
1020-
if (CS.TC.isExprBeingDiagnosed(subExpr)) {
1021-
auto *savedExpr = CS.TC.getExprBeingDiagnosed(subExpr);
1020+
if (CS.getTypeChecker().isExprBeingDiagnosed(subExpr)) {
1021+
auto *savedExpr = CS.getTypeChecker().getExprBeingDiagnosed(subExpr);
10221022
if (subExpr == savedExpr)
10231023
return subExpr;
10241024

@@ -1028,7 +1028,7 @@ Expr *FailureDiagnosis::typeCheckChildIndependently(
10281028
}
10291029

10301030
// Mark current expression as about to be diagnosed.
1031-
CS.TC.addExprForDiagnosis(subExpr, subExpr);
1031+
CS.getTypeChecker().addExprForDiagnosis(subExpr, subExpr);
10321032

10331033
// Validate contextual type before trying to use it.
10341034
std::tie(convertType, convertTypePurpose) =
@@ -1118,7 +1118,7 @@ Expr *FailureDiagnosis::typeCheckChildIndependently(
11181118
}
11191119

11201120
if (preCheckedExpr != subExpr)
1121-
CS.TC.addExprForDiagnosis(preCheckedExpr, subExpr);
1121+
CS.getTypeChecker().addExprForDiagnosis(preCheckedExpr, subExpr);
11221122

11231123
return subExpr;
11241124
}
@@ -4068,7 +4068,7 @@ diagnoseAmbiguousMultiStatementClosure(ClosureExpr *closure) {
40684068
if (hasUnresolvedParams)
40694069
continue;
40704070

4071-
CS.TC.preCheckExpression(resultExpr, CS.DC);
4071+
CS.getTypeChecker().preCheckExpression(resultExpr, CS.DC);
40724072

40734073
// Obtain type of the result expression without applying solutions,
40744074
// because otherwise this might result in leaking of type variables,

lib/Sema/CSDiagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class FailureDiagnostic {
121121
InFlightDiagnostic emitDiagnostic(ArgTypes &&... Args) const;
122122

123123
protected:
124-
TypeChecker &getTypeChecker() const { return CS.TC; }
124+
TypeChecker &getTypeChecker() const { return CS.getTypeChecker(); }
125125

126126
DeclContext *getDC() const { return CS.DC; }
127127

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3799,9 +3799,8 @@ bool swift::areGenericRequirementsSatisfied(
37993799
const DeclContext *DC, GenericSignature sig,
38003800
SubstitutionMap Substitutions, bool isExtension) {
38013801

3802-
auto *TC = DC->getASTContext().getLegacyGlobalTypeChecker();
38033802
ConstraintSystemOptions Options;
3804-
ConstraintSystem CS(*TC, const_cast<DeclContext *>(DC), Options);
3803+
ConstraintSystem CS(const_cast<DeclContext *>(DC), Options);
38053804
auto Loc = CS.getConstraintLocator(nullptr);
38063805

38073806
// For every requirement, add a constraint.
@@ -3865,7 +3864,7 @@ swift::resolveValueMember(DeclContext &DC, Type BaseTy, DeclName Name) {
38653864
// If the current ast context has no type checker, create one for it.
38663865
auto *TC = DC.getASTContext().getLegacyGlobalTypeChecker();
38673866
assert(TC && "Must have type checker to make global query!");
3868-
ConstraintSystem CS(*TC, &DC, None);
3867+
ConstraintSystem CS(&DC, None);
38693868

38703869
// Look up all members of BaseTy with the given Name.
38713870
MemberLookupResult LookupResult = CS.performMemberLookup(

lib/Sema/CSRanking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static bool isProtocolExtensionAsSpecializedAs(TypeChecker &tc,
340340

341341
// Form a constraint system where we've opened up all of the requirements of
342342
// the second protocol extension.
343-
ConstraintSystem cs(tc, dc1, None);
343+
ConstraintSystem cs(dc1, None);
344344
OpenedTypeMap replacements;
345345
cs.openGeneric(dc2, sig2, ConstraintLocatorBuilder(nullptr), replacements);
346346

@@ -507,7 +507,7 @@ llvm::Expected<bool> CompareDeclSpecializationRequest::evaluate(
507507
};
508508

509509
// Construct a constraint system to compare the two declarations.
510-
ConstraintSystem cs(*tc, dc, ConstraintSystemOptions());
510+
ConstraintSystem cs(dc, ConstraintSystemOptions());
511511
bool knownNonSubtype = false;
512512

513513
auto *locator = cs.getConstraintLocator(nullptr);

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4584,7 +4584,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
45844584
// separately.
45854585
switch (kind) {
45864586
case ConstraintKind::SelfObjectOfProtocol: {
4587-
auto conformance = TC.containsProtocol(
4587+
auto conformance = TypeChecker::containsProtocol(
45884588
type, protocol, DC,
45894589
(ConformanceCheckFlags::InExpression |
45904590
ConformanceCheckFlags::SkipConditionalRequirements));

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ bool ConstraintSystem::Candidate::solve(
573573
};
574574

575575
// Allocate new constraint system for sub-expression.
576-
ConstraintSystem cs(BaseCS.getTypeChecker(), DC, None, E);
576+
ConstraintSystem cs(DC, None, E);
577577
cs.baseCS = &BaseCS;
578578

579579
// Set up expression type checker timer for the candidate.

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ using namespace constraints;
3535
#define DEBUG_TYPE "ConstraintSystem"
3636

3737
ExpressionTimer::ExpressionTimer(Expr *E, ConstraintSystem &CS)
38-
: E(E), WarnLimit(CS.TC.getWarnLongExpressionTypeChecking()),
38+
: E(E), WarnLimit(CS.getTypeChecker().getWarnLongExpressionTypeChecking()),
3939
Context(CS.getASTContext()),
4040
StartTime(llvm::TimeRecord::getCurrentTime()),
41-
PrintDebugTiming(CS.TC.getDebugTimeExpressions()), PrintWarning(true) {
41+
PrintDebugTiming(CS.getTypeChecker().getDebugTimeExpressions()),
42+
PrintWarning(true) {
4243
if (auto *baseCS = CS.baseCS) {
4344
// If we already have a timer in the base constraint
4445
// system, let's seed its start time to the child.
@@ -71,11 +72,11 @@ ExpressionTimer::~ExpressionTimer() {
7172
.highlight(E->getSourceRange());
7273
}
7374

74-
ConstraintSystem::ConstraintSystem(TypeChecker &tc, DeclContext *dc,
75+
ConstraintSystem::ConstraintSystem(DeclContext *dc,
7576
ConstraintSystemOptions options,
7677
Expr *expr)
77-
: TC(tc), DC(dc), Options(options),
78-
Arena(tc.Context, Allocator),
78+
: Context(dc->getASTContext()), DC(dc), Options(options),
79+
Arena(dc->getASTContext(), Allocator),
7980
CG(*new ConstraintGraph(*this))
8081
{
8182
if (expr)
@@ -1707,7 +1708,7 @@ static bool shouldCheckForPartialApplication(ConstraintSystem &cs,
17071708

17081709
// FIXME(diagnostics): This check should be removed together with
17091710
// expression based diagnostics.
1710-
if (cs.TC.isExprBeingDiagnosed(anchor))
1711+
if (cs.getTypeChecker().isExprBeingDiagnosed(anchor))
17111712
return false;
17121713

17131714
// If this is a reference to instance method marked as 'mutating'

lib/Sema/ConstraintSystem.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,9 @@ struct DynamicCallableMethods {
983983
/// solution of which assigns concrete types to each of the type variables.
984984
/// Constraint systems are typically generated given an (untyped) expression.
985985
class ConstraintSystem {
986+
ASTContext &Context;
987+
986988
public:
987-
TypeChecker &TC;
988989
DeclContext *DC;
989990
ConstraintSystemOptions Options;
990991
Optional<ExpressionTimer> Timer;
@@ -1654,19 +1655,21 @@ class ConstraintSystem {
16541655
~SolverScope();
16551656
};
16561657

1657-
ConstraintSystem(TypeChecker &tc, DeclContext *dc,
1658+
ConstraintSystem(DeclContext *dc,
16581659
ConstraintSystemOptions options,
16591660
Expr *expr = nullptr);
16601661
~ConstraintSystem();
16611662

16621663
/// Retrieve the type checker associated with this constraint system.
1663-
TypeChecker &getTypeChecker() const { return TC; }
1664+
TypeChecker &getTypeChecker() const {
1665+
return *Context.getLegacyGlobalTypeChecker();
1666+
}
16641667

16651668
/// Retrieve the constraint graph associated with this constraint system.
16661669
ConstraintGraph &getConstraintGraph() const { return CG; }
16671670

16681671
/// Retrieve the AST context.
1669-
ASTContext &getASTContext() const { return TC.Context; }
1672+
ASTContext &getASTContext() const { return Context; }
16701673

16711674
/// Determine whether this constraint system has any free type
16721675
/// variables.
@@ -3714,7 +3717,8 @@ class ConstraintSystem {
37143717
return isExpressionAlreadyTooComplex= true;
37153718
}
37163719

3717-
auto timeoutThresholdInMillis = TC.getExpressionTimeoutThresholdInSeconds();
3720+
const auto timeoutThresholdInMillis =
3721+
getTypeChecker().getExpressionTimeoutThresholdInSeconds();
37183722
if (Timer && Timer->isExpired(timeoutThresholdInMillis)) {
37193723
// Disable warnings about expressions that go over the warning
37203724
// threshold since we're arbitrarily ending evaluation and

0 commit comments

Comments
 (0)