Skip to content

Commit 3c16ecf

Browse files
committed
[Sema] Remove preCheckExpression
There are only a couple of clients left using this, migrate them onto `preCheckTarget`.
1 parent 8879ae5 commit 3c16ecf

File tree

10 files changed

+29
-39
lines changed

10 files changed

+29
-39
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5404,10 +5404,6 @@ class ConstraintSystem {
54045404
/// and folding sequence expressions.
54055405
static bool preCheckTarget(SyntacticElementTarget &target);
54065406

5407-
/// Pre-check the expression, validating any types that occur in the
5408-
/// expression and folding sequence expressions.
5409-
static bool preCheckExpression(Expr *&expr, DeclContext *dc);
5410-
54115407
/// Solve the system of constraints generated from provided target.
54125408
///
54135409
/// \param target The target that we'll generate constraints from, which

lib/IDE/PostfixCompletion.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,14 @@ getOperatorCompletionTypes(DeclContext *DC, Type LHSType, OperatorDecl *Op) {
317317
llvm_unreachable("unexpected operator kind");
318318
}
319319

320-
CS.preCheckExpression(OpCallExpr, DC);
321-
OpCallExpr = CS.generateConstraints(OpCallExpr, DC);
320+
auto target = SyntacticElementTarget(OpCallExpr, DC, CTP_Unused, Type(),
321+
/*isDiscarded*/ true);
322+
if (CS.preCheckTarget(target))
323+
return {};
324+
if (CS.generateConstraints(target))
325+
return {};
326+
327+
OpCallExpr = target.getAsExpr();
322328

323329
CS.assignFixedType(CS.getType(&LHS)->getAs<TypeVariableType>(), LHSType);
324330

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ class VarDeclMultipleReferencesChecker : public ASTWalker {
16491649
}
16501650

16511651
// FIXME: We can see UnresolvedDeclRefExprs here because we have
1652-
// not yet run preCheckExpression() on the entire function body
1652+
// not yet run preCheckTarget() on the entire function body
16531653
// yet.
16541654
//
16551655
// We could consider pre-checking more eagerly.

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ TypeVarRefCollector::walkToExprPre(Expr *expr) {
889889
inferTypeVars(DRE->getDecl());
890890

891891
// FIXME: We can see UnresolvedDeclRefExprs here because we don't walk into
892-
// patterns when running preCheckExpression, since we don't resolve patterns
892+
// patterns when running preCheckTarget, since we don't resolve patterns
893893
// until CSGen. We ought to consider moving pattern resolution into
894894
// pre-checking, which would allow us to pre-check patterns normally.
895895
if (auto *declRef = dyn_cast<UnresolvedDeclRefExpr>(expr)) {

lib/Sema/PreCheckExpr.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,19 +2440,3 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target) {
24402440
target = *newTarget;
24412441
return false;
24422442
}
2443-
2444-
/// Pre-check the expression, validating any types that occur in the
2445-
/// expression and folding sequence expressions.
2446-
bool ConstraintSystem::preCheckExpression(Expr *&expr, DeclContext *dc) {
2447-
auto &ctx = dc->getASTContext();
2448-
FrontendStatsTracer StatsTracer(ctx.Stats, "precheck-expr", expr);
2449-
2450-
PreCheckExpression preCheck(dc);
2451-
2452-
// Perform the pre-check.
2453-
if (auto result = expr->walk(preCheck)) {
2454-
expr = result;
2455-
return false;
2456-
}
2457-
return true;
2458-
}

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,13 @@ static std::optional<Type>
300300
getTypeOfCompletionContextExpr(DeclContext *DC, CompletionTypeCheckKind kind,
301301
Expr *&parsedExpr,
302302
ConcreteDeclRef &referencedDecl) {
303-
if (constraints::ConstraintSystem::preCheckExpression(parsedExpr, DC))
303+
auto target = SyntacticElementTarget(parsedExpr, DC, CTP_Unused, Type(),
304+
/*isDiscarded*/ true);
305+
if (constraints::ConstraintSystem::preCheckTarget(target))
304306
return std::nullopt;
305307

308+
parsedExpr = target.getAsExpr();
309+
306310
switch (kind) {
307311
case CompletionTypeCheckKind::Normal:
308312
// Handle below.

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ BodyInitKindRequest::evaluate(Evaluator &evaluator,
550550
myKind = BodyInitKind::Delegating;
551551
else if (auto *declRef = dyn_cast<UnresolvedDeclRefExpr>(arg)) {
552552
// FIXME: We can see UnresolvedDeclRefExprs here because we have
553-
// not yet run preCheckExpression() on the entire function body
553+
// not yet run preCheckTarget() on the entire function body
554554
// yet.
555555
//
556556
// We could consider pre-checking more eagerly.

lib/Sema/TypeCheckExpr.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ static Expr *makeBinOp(ASTContext &Ctx, Expr *Op, Expr *LHS, Expr *RHS,
290290
if (auto *ternary = dyn_cast<TernaryExpr>(Op)) {
291291
// Resolve the ternary expression.
292292
if (!Ctx.CompletionCallback) {
293-
// In code completion we might call preCheckExpression twice - once for
293+
// In code completion we might call preCheckTarget twice - once for
294294
// the first pass and once for the second pass. This is fine since
295-
// preCheckExpression idempotent.
295+
// preCheckTarget is idempotent.
296296
assert(!ternary->isFolded() && "already folded if expr in sequence?!");
297297
}
298298
ternary->setCondExpr(LHS);
@@ -303,9 +303,9 @@ static Expr *makeBinOp(ASTContext &Ctx, Expr *Op, Expr *LHS, Expr *RHS,
303303
if (auto *assign = dyn_cast<AssignExpr>(Op)) {
304304
// Resolve the assignment expression.
305305
if (!Ctx.CompletionCallback) {
306-
// In code completion we might call preCheckExpression twice - once for
306+
// In code completion we might call preCheckTarget twice - once for
307307
// the first pass and once for the second pass. This is fine since
308-
// preCheckExpression idempotent.
308+
// preCheckTarget is idempotent.
309309
assert(!assign->isFolded() && "already folded assign expr in sequence?!");
310310
}
311311
assign->setDest(LHS);
@@ -316,9 +316,9 @@ static Expr *makeBinOp(ASTContext &Ctx, Expr *Op, Expr *LHS, Expr *RHS,
316316
if (auto *as = dyn_cast<ExplicitCastExpr>(Op)) {
317317
// Resolve the 'as' or 'is' expression.
318318
if (!Ctx.CompletionCallback) {
319-
// In code completion we might call preCheckExpression twice - once for
319+
// In code completion we might call preCheckTarget twice - once for
320320
// the first pass and once for the second pass. This is fine since
321-
// preCheckExpression idempotent.
321+
// preCheckTarget is idempotent.
322322
assert(!as->isFolded() && "already folded 'as' expr in sequence?!");
323323
}
324324
assert(RHS == as && "'as' with non-type RHS?!");
@@ -329,9 +329,9 @@ static Expr *makeBinOp(ASTContext &Ctx, Expr *Op, Expr *LHS, Expr *RHS,
329329
if (auto *arrow = dyn_cast<ArrowExpr>(Op)) {
330330
// Resolve the '->' expression.
331331
if (!Ctx.CompletionCallback) {
332-
// In code completion we might call preCheckExpression twice - once for
332+
// In code completion we might call preCheckTarget twice - once for
333333
// the first pass and once for the second pass. This is fine since
334-
// preCheckExpression idempotent.
334+
// preCheckTarget is idempotent.
335335
assert(!arrow->isFolded() && "already folded '->' expr in sequence?!");
336336
}
337337
arrow->setArgsExpr(LHS);

test/type/array.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func constructArray(_ n: Int) {
4242

4343
typealias FixIt0 = Int[] // expected-error{{array types are now written with the brackets around the element type}}{{20-20=[}}{{23-24=}}
4444

45-
// Make sure preCheckExpression() properly folds member types.
45+
// Make sure preCheckTarget() properly folds member types.
4646

4747
class Outer {
4848
class Middle {

unittests/Sema/KeypathFunctionConversionTests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ TEST_F(SemaTest, TestKeypathFunctionConversionPrefersNarrowConversion) {
104104
fDecls, DeclNameLoc(), FunctionRefKind::SingleApply, false);
105105
auto *callExpr = CallExpr::create(Context, fDRE, argList, false);
106106

107-
Expr *target = callExpr;
108107
ConstraintSystem cs(DC, ConstraintSystemOptions());
109-
ASSERT_FALSE(cs.preCheckExpression(target, DC));
110-
auto *expr = cs.generateConstraints(callExpr, DC);
111-
ASSERT_TRUE(expr);
108+
auto target = SyntacticElementTarget(callExpr, DC, CTP_Unused, Type(),
109+
/*isDiscarded*/ true);
110+
ASSERT_FALSE(cs.preCheckTarget(target));
111+
ASSERT_FALSE(cs.generateConstraints(target));
112112

113113
SmallVector<Solution, 2> solutions;
114114
cs.solve(solutions);

0 commit comments

Comments
 (0)