Skip to content

Commit 535150c

Browse files
committed
Move preCheckExpression to ConstraintSystem
1 parent ecb7b8c commit 535150c

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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 (getTypeChecker().preCheckExpression(singleExpr, closure))
585+
if (ConstraintSystem::preCheckExpression(singleExpr, closure))
586586
return getTypeMatchFailure(locator);
587587

588588
singleExpr = generateConstraints(singleExpr, closure);
@@ -617,13 +617,12 @@ namespace {
617617

618618
/// Pre-check all the expressions in the closure body.
619619
class PreCheckFunctionBuilderClosure : public ASTWalker {
620-
TypeChecker &TC;
621620
ClosureExpr *Closure;
622621
bool HasReturnStmt = false;
623622
bool HasError = false;
624623
public:
625-
PreCheckFunctionBuilderClosure(TypeChecker &tc, ClosureExpr *closure)
626-
: TC(tc), Closure(closure) {}
624+
PreCheckFunctionBuilderClosure(ClosureExpr *closure)
625+
: Closure(closure) {}
627626

628627
FunctionBuilderClosurePreCheck run() {
629628
Stmt *oldBody = Closure->getBody();
@@ -649,7 +648,7 @@ class PreCheckFunctionBuilderClosure : public ASTWalker {
649648
// Pre-check the expression. If this fails, abort the walk immediately.
650649
// Otherwise, replace the expression with the result of pre-checking.
651650
// In either case, don't recurse into the expression.
652-
if (TC.preCheckExpression(E, /*DC*/ Closure)) {
651+
if (ConstraintSystem::preCheckExpression(E, /*DC*/ Closure)) {
653652
HasError = true;
654653
return std::make_pair(false, nullptr);
655654
}
@@ -682,7 +681,7 @@ TypeChecker::preCheckFunctionBuilderClosureBody(ClosureExpr *closure) {
682681
if (it != precheckedFunctionBuilderClosures.end())
683682
return it->second;
684683

685-
auto result = PreCheckFunctionBuilderClosure(*this, closure).run();
684+
auto result = PreCheckFunctionBuilderClosure(closure).run();
686685

687686
// Cache the result.
688687
precheckedFunctionBuilderClosures.insert(std::make_pair(closure, result));

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4068,7 +4068,7 @@ diagnoseAmbiguousMultiStatementClosure(ClosureExpr *closure) {
40684068
if (hasUnresolvedParams)
40694069
continue;
40704070

4071-
CS.getTypeChecker().preCheckExpression(resultExpr, CS.DC);
4071+
ConstraintSystem::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/ConstraintSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,6 +3588,10 @@ class ConstraintSystem {
35883588
= FreeTypeVariableBinding::Disallow);
35893589

35903590
public:
3591+
/// Pre-check the expression, validating any types that occur in the
3592+
/// expression and folding sequence expressions.
3593+
static bool preCheckExpression(Expr *&expr, DeclContext *dc);
3594+
35913595
/// Solve the system of constraints generated from provided expression.
35923596
///
35933597
/// The expression should have already been pre-checked with

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,7 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
20132013

20142014
/// Pre-check the expression, validating any types that occur in the
20152015
/// expression and folding sequence expressions.
2016-
bool TypeChecker::preCheckExpression(Expr *&expr, DeclContext *dc) {
2016+
bool ConstraintSystem::preCheckExpression(Expr *&expr, DeclContext *dc) {
20172017
PreCheckExpression preCheck(dc, expr);
20182018
// Perform the pre-check.
20192019
if (auto result = expr->walk(preCheck)) {
@@ -2177,7 +2177,7 @@ Type TypeChecker::typeCheckExpressionImpl(Expr *&expr, DeclContext *dc,
21772177

21782178
// First, pre-check the expression, validating any types that occur in the
21792179
// expression and folding sequence expressions.
2180-
if (preCheckExpression(expr, dc)) {
2180+
if (ConstraintSystem::preCheckExpression(expr, dc)) {
21812181
listener.preCheckFailed(expr);
21822182
return Type();
21832183
}

lib/Sema/TypeChecker.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//===----------------------------------------------------------------------===//
1717

1818
#include "swift/Subsystems.h"
19+
#include "ConstraintSystem.h"
1920
#include "TypeChecker.h"
2021
#include "TypeCheckObjC.h"
2122
#include "TypeCheckType.h"
@@ -623,12 +624,11 @@ void swift::typeCheckPatternBinding(PatternBindingDecl *PBD,
623624
}
624625

625626
static Optional<Type> getTypeOfCompletionContextExpr(
626-
TypeChecker &TC,
627627
DeclContext *DC,
628628
CompletionTypeCheckKind kind,
629629
Expr *&parsedExpr,
630630
ConcreteDeclRef &referencedDecl) {
631-
if (TC.preCheckExpression(parsedExpr, DC))
631+
if (constraints::ConstraintSystem::preCheckExpression(parsedExpr, DC))
632632
return None;
633633

634634
switch (kind) {
@@ -672,10 +672,10 @@ Optional<Type> swift::getTypeOfCompletionContextExpr(
672672
Expr *&parsedExpr,
673673
ConcreteDeclRef &referencedDecl) {
674674
DiagnosticSuppression suppression(Ctx.Diags);
675-
TypeChecker &TC = createTypeChecker(Ctx);
675+
(void)createTypeChecker(Ctx);
676676

677677
// Try to solve for the actual type of the expression.
678-
return ::getTypeOfCompletionContextExpr(TC, DC, kind, parsedExpr,
678+
return ::getTypeOfCompletionContextExpr(DC, kind, parsedExpr,
679679
referencedDecl);
680680
}
681681

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,10 +1075,6 @@ class TypeChecker final {
10751075
/// struct or class.
10761076
static void addImplicitConstructors(NominalTypeDecl *typeDecl);
10771077

1078-
/// Pre-check the expression, validating any types that occur in the
1079-
/// expression and folding sequence expressions.
1080-
bool preCheckExpression(Expr *&expr, DeclContext *dc);
1081-
10821078
/// Pre-check the body of the given closure, which we are about to
10831079
/// generate constraints for.
10841080
///

0 commit comments

Comments
 (0)