Skip to content

Commit 48ada41

Browse files
authored
Merge pull request #59821 from hborla/remove-reuse-prechecked-type
[ConstraintSystem] Remove `ConstraintSystemFlags::ReusePrecheckedType`.
2 parents bf9b4e3 + b0307a5 commit 48ada41

File tree

3 files changed

+14
-62
lines changed

3 files changed

+14
-62
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,10 +1538,6 @@ enum class ConstraintSystemFlags {
15381538
/// left in-tact.
15391539
AllowUnresolvedTypeVariables = 0x04,
15401540

1541-
/// If set, constraint system always reuses type of pre-typechecked
1542-
/// expression, and doesn't dig into its subexpressions.
1543-
ReusePrecheckedType = 0x08,
1544-
15451541
/// If set, verbose output is enabled for this constraint system.
15461542
///
15471543
/// Note that this flag is automatically applied to all constraint systems,
@@ -1550,16 +1546,16 @@ enum class ConstraintSystemFlags {
15501546
/// \c DebugConstraintSolverAttempt. Finally, it can also be automatically
15511547
/// enabled for a pre-configured set of expressions on line numbers by setting
15521548
/// \c DebugConstraintSolverOnLines.
1553-
DebugConstraints = 0x10,
1549+
DebugConstraints = 0x08,
15541550

15551551
/// Don't try to type check closure bodies, and leave them unchecked. This is
15561552
/// used for source tooling functionalities.
1557-
LeaveClosureBodyUnchecked = 0x20,
1553+
LeaveClosureBodyUnchecked = 0x10,
15581554

15591555
/// If set, we are solving specifically to determine the type of a
15601556
/// CodeCompletionExpr, and should continue in the presence of errors wherever
15611557
/// possible.
1562-
ForCodeCompletion = 0x40,
1558+
ForCodeCompletion = 0x20,
15631559

15641560
/// Include Clang function types when checking equality for function types.
15651561
///
@@ -1570,10 +1566,10 @@ enum class ConstraintSystemFlags {
15701566
/// should be treated as semantically different, as they may have different
15711567
/// calling conventions, say due to Clang attributes such as
15721568
/// `__attribute__((ns_consumed))`.
1573-
UseClangFunctionTypes = 0x80,
1569+
UseClangFunctionTypes = 0x40,
15741570

15751571
/// When set, ignore async/sync mismatches
1576-
IgnoreAsyncSyncMismatch = 0x100,
1572+
IgnoreAsyncSyncMismatch = 0x80,
15771573
};
15781574

15791575
/// Options that affect the constraint system as a whole.
@@ -3831,10 +3827,6 @@ class ConstraintSystem {
38313827
return Options.contains(ConstraintSystemFlags::SuppressDiagnostics);
38323828
}
38333829

3834-
bool shouldReusePrecheckedType() const {
3835-
return Options.contains(ConstraintSystemFlags::ReusePrecheckedType);
3836-
}
3837-
38383830
/// Whether we are solving to determine the possible types of a
38393831
/// \c CodeCompletionExpr.
38403832
bool isForCodeCompletion() const {

lib/Sema/CSGen.cpp

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,12 @@ namespace {
8888
class LinkedExprCollector : public ASTWalker {
8989

9090
llvm::SmallVectorImpl<Expr*> &LinkedExprs;
91-
ConstraintSystem &CS;
9291

9392
public:
94-
LinkedExprCollector(llvm::SmallVectorImpl<Expr *> &linkedExprs,
95-
ConstraintSystem &cs)
96-
: LinkedExprs(linkedExprs), CS(cs) {}
93+
LinkedExprCollector(llvm::SmallVectorImpl<Expr *> &linkedExprs)
94+
: LinkedExprs(linkedExprs) {}
9795

9896
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
99-
100-
if (CS.shouldReusePrecheckedType() &&
101-
!CS.getType(expr)->hasTypeVariable()) {
102-
return { false, expr };
103-
}
104-
10597
if (isa<ClosureExpr>(expr))
10698
return {false, expr};
10799

@@ -161,12 +153,6 @@ namespace {
161153
LTI(lti), CS(cs) {}
162154

163155
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
164-
165-
if (CS.shouldReusePrecheckedType() &&
166-
!CS.getType(expr)->hasTypeVariable()) {
167-
return { false, expr };
168-
}
169-
170156
if (isa<LiteralExpr>(expr)) {
171157
LTI.hasLiteral = true;
172158
return { false, expr };
@@ -791,11 +777,6 @@ namespace {
791777
if (CS.isArgumentIgnoredForCodeCompletion(expr)) {
792778
return {false, expr};
793779
}
794-
795-
if (CS.shouldReusePrecheckedType() &&
796-
!CS.getType(expr)->hasTypeVariable()) {
797-
return { false, expr };
798-
}
799780

800781
if (auto applyExpr = dyn_cast<ApplyExpr>(expr)) {
801782
if (isa<PrefixUnaryExpr>(applyExpr) ||
@@ -3654,15 +3635,6 @@ namespace {
36543635
return {false, expr};
36553636
}
36563637

3657-
if (CG.getConstraintSystem().shouldReusePrecheckedType()) {
3658-
if (expr->getType()) {
3659-
assert(!expr->getType()->hasTypeVariable());
3660-
assert(!expr->getType()->hasPlaceholder());
3661-
CG.getConstraintSystem().cacheType(expr);
3662-
return { false, expr };
3663-
}
3664-
}
3665-
36663638
// Note that the subexpression of a #selector expression is
36673639
// unevaluated.
36683640
if (auto sel = dyn_cast<ObjCSelectorExpr>(expr)) {
@@ -4436,7 +4408,7 @@ void ConstraintSystem::optimizeConstraints(Expr *e) {
44364408
SmallVector<Expr *, 16> linkedExprs;
44374409

44384410
// Collect any linked expressions.
4439-
LinkedExprCollector collector(linkedExprs, *this);
4411+
LinkedExprCollector collector(linkedExprs);
44404412
e->walk(collector);
44414413

44424414
// Favor types, as appropriate.

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,11 @@ namespace {
109109
/// FIXME: Remove this.
110110
class SanitizeExpr : public ASTWalker {
111111
ASTContext &C;
112-
bool ShouldReusePrecheckedType;
113112
llvm::SmallDenseMap<OpaqueValueExpr *, Expr *, 4> OpenExistentials;
114113

115114
public:
116-
SanitizeExpr(ASTContext &C,
117-
bool shouldReusePrecheckedType)
118-
: C(C), ShouldReusePrecheckedType(shouldReusePrecheckedType) { }
115+
SanitizeExpr(ASTContext &C)
116+
: C(C) { }
119117

120118
std::pair<bool, ArgumentList *>
121119
walkToArgumentListPre(ArgumentList *argList) override {
@@ -126,12 +124,6 @@ class SanitizeExpr : public ASTWalker {
126124

127125
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
128126
while (true) {
129-
130-
// If we should reuse pre-checked types, don't sanitize the expression
131-
// if it's already type-checked.
132-
if (ShouldReusePrecheckedType && expr->getType())
133-
return { false, expr };
134-
135127
// OpenExistentialExpr contains OpaqueValueExpr in its sub expression.
136128
if (auto OOE = dyn_cast<OpenExistentialExpr>(expr)) {
137129
auto archetypeVal = OOE->getOpaqueValue();
@@ -301,8 +293,7 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
301293
FreeTypeVariableBinding allowFreeTypeVariables) {
302294
auto &Context = dc->getASTContext();
303295

304-
expr = expr->walk(SanitizeExpr(Context,
305-
/*shouldReusePrecheckedType=*/false));
296+
expr = expr->walk(SanitizeExpr(Context));
306297

307298
FrontendStatsTracer StatsTracer(Context.Stats,
308299
"typecheck-expr-no-apply", expr);
@@ -400,12 +391,10 @@ getTypeOfCompletionOperatorImpl(DeclContext *DC, Expr *expr,
400391
"typecheck-completion-operator", expr);
401392
PrettyStackTraceExpr stackTrace(Context, "type-checking", expr);
402393

403-
expr = expr->walk(SanitizeExpr(Context,
404-
/*shouldReusePrecheckedType=*/true));
394+
expr = expr->walk(SanitizeExpr(Context));
405395

406396
ConstraintSystemOptions options;
407397
options |= ConstraintSystemFlags::SuppressDiagnostics;
408-
options |= ConstraintSystemFlags::ReusePrecheckedType;
409398
options |= ConstraintSystemFlags::LeaveClosureBodyUnchecked;
410399

411400
// Construct a constraint system from this expression.
@@ -577,8 +566,7 @@ bool TypeChecker::typeCheckForCodeCompletion(
577566
return false;
578567

579568
if (auto *expr = getAsExpr(node)) {
580-
node = expr->walk(SanitizeExpr(Context,
581-
/*shouldReusePrecheckedType=*/false));
569+
node = expr->walk(SanitizeExpr(Context));
582570
}
583571

584572
CompletionContextFinder contextAnalyzer(node, DC);
@@ -774,7 +762,7 @@ swift::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
774762
bool swift::typeCheckExpression(DeclContext *DC, Expr *&parsedExpr) {
775763
auto &ctx = DC->getASTContext();
776764

777-
parsedExpr = parsedExpr->walk(SanitizeExpr(ctx, /*shouldReusePrecheckedType=*/false));
765+
parsedExpr = parsedExpr->walk(SanitizeExpr(ctx));
778766

779767
DiagnosticSuppression suppression(ctx.Diags);
780768
auto resultTy = TypeChecker::typeCheckExpression(

0 commit comments

Comments
 (0)