Skip to content

Commit 22b08da

Browse files
committed
[Sema] Remove replaceInvalidRefsWithErrors param
Doesn't seem like anything is relying on setting this to `false` anymore, remove it.
1 parent 7c01181 commit 22b08da

14 files changed

+38
-79
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5402,19 +5402,11 @@ class ConstraintSystem {
54025402
public:
54035403
/// Pre-check the target, validating any types that occur in it
54045404
/// and folding sequence expressions.
5405-
///
5406-
/// \param replaceInvalidRefsWithErrors Indicates whether it's allowed
5407-
/// to replace any discovered invalid member references with `ErrorExpr`.
5408-
static bool preCheckTarget(SyntacticElementTarget &target,
5409-
bool replaceInvalidRefsWithErrors);
5405+
static bool preCheckTarget(SyntacticElementTarget &target);
54105406

54115407
/// Pre-check the expression, validating any types that occur in the
54125408
/// expression and folding sequence expressions.
5413-
///
5414-
/// \param replaceInvalidRefsWithErrors Indicates whether it's allowed
5415-
/// to replace any discovered invalid member references with `ErrorExpr`.
5416-
static bool preCheckExpression(Expr *&expr, DeclContext *dc,
5417-
bool replaceInvalidRefsWithErrors);
5409+
static bool preCheckExpression(Expr *&expr, DeclContext *dc);
54185410

54195411
/// Solve the system of constraints generated from provided target.
54205412
///

include/swift/Sema/IDETypeChecking.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ namespace swift {
158158

159159
/// Thunk around \c TypeChecker::resolveDeclRefExpr to make it available to
160160
/// \c swift::ide
161-
Expr *resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *Context,
162-
bool replaceInvalidRefsWithErrors);
161+
Expr *resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *Context);
163162

164163
LookupResult
165164
lookupSemanticMember(DeclContext *DC, Type ty, DeclName name);

lib/IDE/IDETypeChecking.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,9 +1022,8 @@ swift::getShorthandShadows(CaptureListExpr *CaptureList, DeclContext *DC) {
10221022
}
10231023

10241024
if (auto UDRE = dyn_cast<UnresolvedDeclRefExpr>(Init)) {
1025-
if (DC) {
1026-
Init = resolveDeclRefExpr(UDRE, DC, /*replaceInvalidRefsWithErrors=*/false);
1027-
}
1025+
if (DC)
1026+
Init = resolveDeclRefExpr(UDRE, DC);
10281027
}
10291028

10301029
auto *ReferencedVar = Init->getReferencedDecl().getDecl();
@@ -1045,9 +1044,8 @@ swift::getShorthandShadows(LabeledConditionalStmt *CondStmt, DeclContext *DC) {
10451044

10461045
Expr *Init = Cond.getInitializer();
10471046
if (auto UDRE = dyn_cast<UnresolvedDeclRefExpr>(Init)) {
1048-
if (DC) {
1049-
Init = resolveDeclRefExpr(UDRE, DC, /*replaceInvalidRefsWithErrors=*/false);
1050-
}
1047+
if (DC)
1048+
Init = resolveDeclRefExpr(UDRE, DC);
10511049
}
10521050

10531051
auto ReferencedVar = Init->getReferencedDecl().getDecl();

lib/IDE/PostfixCompletion.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ getOperatorCompletionTypes(DeclContext *DC, Type LHSType, OperatorDecl *Op) {
292292
UnresolvedDeclRefExpr UDRE(DeclNameRef(Op->getName()),
293293
getDeclRefKindOfOperator(Op), DeclNameLoc(Loc));
294294
DiagnosticTransaction IgnoreDiags(DC->getASTContext().Diags);
295-
Expr *OpExpr =
296-
resolveDeclRefExpr(&UDRE, DC, /*replaceInvalidRefsWithErrors=*/true);
295+
Expr *OpExpr = resolveDeclRefExpr(&UDRE, DC);
297296
IgnoreDiags.abort();
298297
if (isa<ErrorExpr>(OpExpr)) {
299298
// If we couldn't resolve the operator (e.g. because there is only an
@@ -318,7 +317,7 @@ getOperatorCompletionTypes(DeclContext *DC, Type LHSType, OperatorDecl *Op) {
318317
llvm_unreachable("unexpected operator kind");
319318
}
320319

321-
CS.preCheckExpression(OpCallExpr, DC, /*replaceInvalidRefsWithErrors=*/true);
320+
CS.preCheckExpression(OpCallExpr, DC);
322321
OpCallExpr = CS.generateConstraints(OpCallExpr, DC);
323322

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

lib/Sema/BuilderTransform.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,8 +1316,7 @@ class PreCheckResultBuilderApplication : public ASTWalker {
13161316
// Suppress any diagnostics which could be produced by this expression.
13171317
DiagnosticTransaction transaction(diagEngine);
13181318

1319-
HasError |= ConstraintSystem::preCheckExpression(
1320-
E, DC, /*replaceInvalidRefsWithErrors=*/true);
1319+
HasError |= ConstraintSystem::preCheckExpression(E, DC);
13211320

13221321
HasError |= transaction.hasErrors();
13231322

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10761,7 +10761,7 @@ static bool inferEnumMemberThroughTildeEqualsOperator(
1076110761

1076210762
DiagnosticTransaction diagnostics(ctx.Diags);
1076310763
{
10764-
if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true)) {
10764+
if (cs.preCheckTarget(target)) {
1076510765
// Skip diagnostics if they are disabled, otherwise it would result in
1076610766
// duplicate diagnostics, since this operation is going to be repeated
1076710767
// in diagnostic mode.

lib/Sema/CSSyntacticElement.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ class SyntacticElementConstraintGenerator
557557
void visitExprPattern(ExprPattern *EP) {
558558
auto target = SyntacticElementTarget::forExprPattern(EP);
559559

560-
if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true)) {
560+
if (cs.preCheckTarget(target)) {
561561
hadError = true;
562562
return;
563563
}
@@ -771,8 +771,7 @@ class SyntacticElementConstraintGenerator
771771
init, patternType, patternBinding, index,
772772
/*bindPatternVarsOneWay=*/false);
773773

774-
if (ConstraintSystem::preCheckTarget(
775-
target, /*replaceInvalidRefsWithErrors=*/true))
774+
if (ConstraintSystem::preCheckTarget(target))
776775
return std::nullopt;
777776

778777
return target;

lib/Sema/PreCheckExpr.cpp

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,7 @@ static BinaryExpr *getCompositionExpr(Expr *expr) {
406406
/// returning the resultant expression. Context is the DeclContext used
407407
/// for the lookup.
408408
Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
409-
DeclContext *DC,
410-
bool replaceInvalidRefsWithErrors) {
409+
DeclContext *DC) {
411410
// Process UnresolvedDeclRefExpr by doing an unqualified lookup.
412411
DeclNameRef Name = UDRE->getName();
413412
SourceLoc Loc = UDRE->getLoc();
@@ -431,10 +430,10 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
431430
LookupName = DeclNameRef(lookupName);
432431
}
433432

433+
auto &Context = DC->getASTContext();
434+
434435
auto errorResult = [&]() -> Expr * {
435-
if (replaceInvalidRefsWithErrors)
436-
return new (DC->getASTContext()) ErrorExpr(UDRE->getSourceRange());
437-
return UDRE;
436+
return new (Context) ErrorExpr(UDRE->getSourceRange());
438437
};
439438

440439
// Perform standard value name lookup.
@@ -449,8 +448,6 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
449448
bool AllDeclRefs = true;
450449
SmallVector<ValueDecl*, 4> ResultValues;
451450

452-
auto &Context = DC->getASTContext();
453-
454451
// First, look for a local binding in scope.
455452
if (Loc.isValid() && !Name.isOperator()) {
456453
ASTScope::lookupLocalDecls(DC->getParentSourceFile(),
@@ -487,8 +484,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
487484
Context.Diags.diagnose(Loc, diag::use_local_before_declaration, Name);
488485
Context.Diags.diagnose(innerDecl, diag::decl_declared_here,
489486
localDeclAfterUse);
490-
Expr *error = new (Context) ErrorExpr(UDRE->getSourceRange());
491-
return error;
487+
return errorResult();
492488
}
493489

494490
Lookup.shiftDownResults();
@@ -705,7 +701,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
705701
UDRE->getRefKind() == DeclRefKind::BinaryOperator
706702
? 0
707703
: UDRE->getRefKind() == DeclRefKind::PrefixOperator ? 1 : 2);
708-
return new (Context) ErrorExpr(UDRE->getSourceRange());
704+
return errorResult();
709705
}
710706

711707
// For operators, sort the results so that non-generic operations come
@@ -844,7 +840,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
844840
auto *Decl = Result.getValueDecl();
845841
Context.Diags.diagnose(Decl, diag::decl_declared_here, Decl);
846842
}
847-
return new (Context) ErrorExpr(UDRE->getSourceRange());
843+
return errorResult();
848844
}
849845

850846
/// If an expression references 'self.init' or 'super.init' in an
@@ -1036,10 +1032,6 @@ namespace {
10361032

10371033
Expr *ParentExpr;
10381034

1039-
/// Indicates whether pre-check is allowed to insert
1040-
/// implicit `ErrorExpr` in place of invalid references.
1041-
bool UseErrorExprs;
1042-
10431035
/// A stack of expressions being walked, used to determine where to
10441036
/// insert RebindSelfInConstructorExpr nodes.
10451037
llvm::SmallVector<Expr *, 8> ExprStack;
@@ -1107,10 +1099,8 @@ namespace {
11071099
void markAcceptableDiscardExprs(Expr *E);
11081100

11091101
public:
1110-
PreCheckExpression(DeclContext *dc, Expr *parent,
1111-
bool replaceInvalidRefsWithErrors)
1112-
: Ctx(dc->getASTContext()), DC(dc), ParentExpr(parent),
1113-
UseErrorExprs(replaceInvalidRefsWithErrors) {}
1102+
PreCheckExpression(DeclContext *dc, Expr *parent)
1103+
: Ctx(dc->getASTContext()), DC(dc), ParentExpr(parent) {}
11141104

11151105
ASTContext &getASTContext() const { return Ctx; }
11161106

@@ -1232,8 +1222,7 @@ namespace {
12321222
new (Ctx) ErrorExpr(unresolved->getSourceRange()));
12331223
}
12341224

1235-
auto *refExpr =
1236-
TypeChecker::resolveDeclRefExpr(unresolved, DC, UseErrorExprs);
1225+
auto *refExpr = TypeChecker::resolveDeclRefExpr(unresolved, DC);
12371226

12381227
// Check whether this is standalone `self` in init accessor, which
12391228
// is invalid.
@@ -2461,14 +2450,13 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
24612450
: nullptr;
24622451
}
24632452

2464-
bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target,
2465-
bool replaceInvalidRefsWithErrors) {
2453+
bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target) {
24662454
auto *DC = target.getDeclContext();
24672455

24682456
bool hadErrors = false;
24692457

24702458
if (auto *expr = target.getAsExpr()) {
2471-
hadErrors |= preCheckExpression(expr, DC, replaceInvalidRefsWithErrors);
2459+
hadErrors |= preCheckExpression(expr, DC);
24722460
// Even if the pre-check fails, expression still has to be re-set.
24732461
target.setExpr(expr);
24742462
}
@@ -2479,12 +2467,10 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target,
24792467
auto *sequenceExpr = stmt->getParsedSequence();
24802468
auto *whereExpr = stmt->getWhere();
24812469

2482-
hadErrors |= preCheckExpression(sequenceExpr, DC,
2483-
/*replaceInvalidRefsWithErrors=*/true);
2470+
hadErrors |= preCheckExpression(sequenceExpr, DC);
24842471

24852472
if (whereExpr) {
2486-
hadErrors |= preCheckExpression(whereExpr, DC,
2487-
/*replaceInvalidRefsWithErrors=*/true);
2473+
hadErrors |= preCheckExpression(whereExpr, DC);
24882474
}
24892475

24902476
// Update sequence and where expressions to pre-checked versions.
@@ -2501,12 +2487,11 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target,
25012487

25022488
/// Pre-check the expression, validating any types that occur in the
25032489
/// expression and folding sequence expressions.
2504-
bool ConstraintSystem::preCheckExpression(Expr *&expr, DeclContext *dc,
2505-
bool replaceInvalidRefsWithErrors) {
2490+
bool ConstraintSystem::preCheckExpression(Expr *&expr, DeclContext *dc) {
25062491
auto &ctx = dc->getASTContext();
25072492
FrontendStatsTracer StatsTracer(ctx.Stats, "precheck-expr", expr);
25082493

2509-
PreCheckExpression preCheck(dc, expr, replaceInvalidRefsWithErrors);
2494+
PreCheckExpression preCheck(dc, expr);
25102495

25112496
// Perform the pre-check.
25122497
if (auto result = expr->walk(preCheck)) {

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,7 @@ bool TypeChecker::typeCheckForCodeCompletion(
221221
if (needsPrecheck) {
222222
// First, pre-check the expression, validating any types that occur in the
223223
// expression and folding sequence expressions.
224-
auto failedPreCheck =
225-
ConstraintSystem::preCheckTarget(target,
226-
/*replaceInvalidRefsWithErrors=*/true);
227-
224+
auto failedPreCheck = ConstraintSystem::preCheckTarget(target);
228225
if (failedPreCheck)
229226
return false;
230227
}
@@ -303,9 +300,7 @@ static std::optional<Type>
303300
getTypeOfCompletionContextExpr(DeclContext *DC, CompletionTypeCheckKind kind,
304301
Expr *&parsedExpr,
305302
ConcreteDeclRef &referencedDecl) {
306-
if (constraints::ConstraintSystem::preCheckExpression(
307-
parsedExpr, DC,
308-
/*replaceInvalidRefsWithErrors=*/true))
303+
if (constraints::ConstraintSystem::preCheckExpression(parsedExpr, DC))
309304
return std::nullopt;
310305

311306
switch (kind) {

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,8 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target,
478478

479479
// First, pre-check the target, validating any types that occur in the
480480
// expression and folding sequence expressions.
481-
if (ConstraintSystem::preCheckTarget(
482-
target, /*replaceInvalidRefsWithErrors=*/true)) {
481+
if (ConstraintSystem::preCheckTarget(target))
483482
return errorResult();
484-
}
485483

486484
// Check whether given target has a code completion token which requires
487485
// special handling. Returns true if handled, in which case we've already

lib/Sema/TypeCheckPattern.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,7 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
531531

532532

533533
// Perform unqualified name lookup to find out what the UDRE is.
534-
return getSubExprPattern(TypeChecker::resolveDeclRefExpr(
535-
ude, DC, /*replaceInvalidRefsWithErrors=*/true));
534+
return getSubExprPattern(TypeChecker::resolveDeclRefExpr(ude, DC));
536535
}
537536

538537
// Call syntax forms a pattern if:

lib/Sema/TypeChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,9 @@ bool swift::typeCheckForCodeCompletion(
571571
callback);
572572
}
573573

574-
Expr *swift::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *Context,
575-
bool replaceInvalidRefsWithErrors) {
576-
return TypeChecker::resolveDeclRefExpr(UDRE, Context, replaceInvalidRefsWithErrors);
574+
Expr *swift::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
575+
DeclContext *Context) {
576+
return TypeChecker::resolveDeclRefExpr(UDRE, Context);
577577
}
578578

579579
void TypeChecker::checkForForbiddenPrefix(ASTContext &C, DeclBaseName Name) {

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,7 @@ Type getOptionalType(SourceLoc loc, Type elementType);
293293
/// Bind an UnresolvedDeclRefExpr by performing name lookup and
294294
/// returning the resultant expression. Context is the DeclContext used
295295
/// for the lookup.
296-
///
297-
/// \param replaceInvalidRefsWithErrors Indicates whether it's allowed
298-
/// to replace any discovered invalid member references with `ErrorExpr`.
299-
Expr *resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *Context,
300-
bool replaceInvalidRefsWithErrors);
296+
Expr *resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *Context);
301297

302298
/// Check for invalid existential types in the given declaration.
303299
void checkExistentialTypes(Decl *decl);

unittests/Sema/KeypathFunctionConversionTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ TEST_F(SemaTest, TestKeypathFunctionConversionPrefersNarrowConversion) {
106106

107107
Expr *target = callExpr;
108108
ConstraintSystem cs(DC, ConstraintSystemOptions());
109-
ASSERT_FALSE(cs.preCheckExpression(target, DC, false));
109+
ASSERT_FALSE(cs.preCheckExpression(target, DC));
110110
auto *expr = cs.generateConstraints(callExpr, DC);
111111
ASSERT_TRUE(expr);
112112

0 commit comments

Comments
 (0)