Skip to content

Commit 97fa263

Browse files
committed
[ConstraintSystem] Remove CleanupIllFormedExpressionRAII and its uses
1 parent 2ddeef7 commit 97fa263

File tree

3 files changed

+6
-75
lines changed

3 files changed

+6
-75
lines changed

lib/Sema/CSGen.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3610,7 +3610,6 @@ bool swift::typeCheckUnresolvedExpr(DeclContext &DC,
36103610
auto *TC = static_cast<TypeChecker*>(DC.getASTContext().getLazyResolver());
36113611
ConstraintSystem CS(*TC, &DC, Options);
36123612
Parent = Parent->walk(SanitizeExpr(CS));
3613-
CleanupIllFormedExpressionRAII cleanup(Parent);
36143613
InferUnresolvedMemberConstraintGenerator MCG(E, CS);
36153614
ConstraintWalker cw(MCG);
36163615
Parent->walk(cw);

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,38 +1894,6 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
18941894
typeExpr->getTypeLoc());
18951895
}
18961896

1897-
/// \brief Clean up the given ill-formed expression, removing any references
1898-
/// to type variables and setting error types on erroneous expression nodes.
1899-
void CleanupIllFormedExpressionRAII::doIt(Expr *expr) {
1900-
class CleanupIllFormedExpression : public ASTWalker {
1901-
public:
1902-
bool walkToDeclPre(Decl *D) override {
1903-
// This handles parameter decls in ClosureExprs.
1904-
if (auto VD = dyn_cast<VarDecl>(D)) {
1905-
if (VD->hasType() && VD->getType()->hasTypeVariable()) {
1906-
VD->markInvalid();
1907-
}
1908-
}
1909-
return true;
1910-
}
1911-
1912-
// Don't walk into statements. This handles the BraceStmt in
1913-
// non-single-expr closures, so we don't walk into their body.
1914-
std::pair<bool, Stmt *> walkToStmtPre(Stmt *S) override {
1915-
return { false, S };
1916-
}
1917-
};
1918-
1919-
if (expr)
1920-
expr->walk(CleanupIllFormedExpression());
1921-
}
1922-
1923-
1924-
CleanupIllFormedExpressionRAII::~CleanupIllFormedExpressionRAII() {
1925-
if (expr)
1926-
CleanupIllFormedExpressionRAII::doIt(*expr);
1927-
}
1928-
19291897
/// Pre-check the expression, validating any types that occur in the
19301898
/// expression and folding sequence expressions.
19311899
bool TypeChecker::preCheckExpression(Expr *&expr, DeclContext *dc) {
@@ -2004,7 +1972,6 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
20041972

20051973
ConstraintSystem cs(*this, dc, csOptions);
20061974
cs.baseCS = baseCS;
2007-
CleanupIllFormedExpressionRAII cleanup(expr);
20081975

20091976
// Verify that a purpose was specified if a convertType was. Note that it is
20101977
// ok to have a purpose without a convertType (which is used for call
@@ -2071,10 +2038,8 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
20712038
return Type();
20722039
}
20732040

2074-
if (options.contains(TypeCheckExprFlags::SkipApplyingSolution)) {
2075-
cleanup.disable();
2041+
if (options.contains(TypeCheckExprFlags::SkipApplyingSolution))
20762042
return solution.simplifyType(cs.getType(expr));
2077-
}
20782043

20792044
// Apply the solution to the expression.
20802045
result = cs.applySolution(
@@ -2109,7 +2074,6 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
21092074
}
21102075

21112076
expr = result;
2112-
cleanup.disable();
21132077
return cs.getType(expr);
21142078
}
21152079

@@ -2123,7 +2087,6 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
21232087

21242088
// Construct a constraint system from this expression.
21252089
ConstraintSystem cs(*this, dc, ConstraintSystemFlags::SuppressDiagnostics);
2126-
CleanupIllFormedExpressionRAII cleanup(expr);
21272090

21282091
// Attempt to solve the constraint system.
21292092
SmallVector<Solution, 4> viable;
@@ -2212,18 +2175,12 @@ void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
22122175
// Attempt to solve the constraint system.
22132176
SmallVector<Solution, 4> viable;
22142177

2215-
// If the previous checking gives the expr error type,
2216-
// clear the result and re-check.
2217-
{
2218-
CleanupIllFormedExpressionRAII cleanup(expr);
2178+
const Type originalType = expr->getType();
2179+
if (originalType && originalType->hasError())
2180+
expr->setType(Type());
22192181

2220-
const Type originalType = expr->getType();
2221-
if (originalType && originalType->hasError())
2222-
expr->setType(Type());
2223-
2224-
cs.solve(expr, /*convertType*/ Type(), listener, viable,
2225-
allowFreeTypeVariables);
2226-
}
2182+
cs.solve(expr, /*convertType*/ Type(), listener, viable,
2183+
allowFreeTypeVariables);
22272184

22282185
for (auto &solution : viable) {
22292186
auto exprType = solution.simplifyType(cs.getType(expr));
@@ -2237,7 +2194,6 @@ bool TypeChecker::typeCheckCompletionSequence(Expr *&expr, DeclContext *DC) {
22372194

22382195
// Construct a constraint system from this expression.
22392196
ConstraintSystem CS(*this, DC, ConstraintSystemFlags::SuppressDiagnostics);
2240-
CleanupIllFormedExpressionRAII cleanup(expr);
22412197

22422198
auto *SE = cast<SequenceExpr>(expr);
22432199
assert(SE->getNumElements() >= 3);
@@ -2323,7 +2279,6 @@ bool TypeChecker::typeCheckExpressionShallow(Expr *&expr, DeclContext *dc) {
23232279

23242280
// Construct a constraint system from this expression.
23252281
ConstraintSystem cs(*this, dc, ConstraintSystemFlags::AllowFixes);
2326-
CleanupIllFormedExpressionRAII cleanup(expr);
23272282
if (auto generatedExpr = cs.generateConstraintsShallow(expr))
23282283
expr = generatedExpr;
23292284
else
@@ -2366,7 +2321,6 @@ bool TypeChecker::typeCheckExpressionShallow(Expr *&expr, DeclContext *dc) {
23662321
}
23672322

23682323
expr = result;
2369-
cleanup.disable();
23702324
return false;
23712325
}
23722326

@@ -3236,8 +3190,6 @@ bool TypeChecker::convertToType(Expr *&expr, Type type, DeclContext *dc,
32363190
// TODO: need to add kind arg?
32373191
// Construct a constraint system from this expression.
32383192
ConstraintSystem cs(*this, dc, ConstraintSystemFlags::AllowFixes);
3239-
CleanupIllFormedExpressionRAII cleanup(expr);
3240-
32413193
// If there is a type that we're expected to convert to, add the conversion
32423194
// constraint.
32433195
cs.addConstraint(ConstraintKind::Conversion, expr->getType(), type,
@@ -3285,7 +3237,6 @@ bool TypeChecker::convertToType(Expr *&expr, Type type, DeclContext *dc,
32853237
}
32863238

32873239
expr = result;
3288-
cleanup.disable();
32893240
return false;
32903241
}
32913242

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,25 +2340,6 @@ class TypeChecker final : public LazyResolver {
23402340
DeclTypeCheckingSemantics getDeclTypeCheckingSemantics(ValueDecl *decl);
23412341
};
23422342

2343-
/// \brief RAII object that cleans up the given expression if not explicitly
2344-
/// disabled.
2345-
class CleanupIllFormedExpressionRAII {
2346-
Expr **expr;
2347-
2348-
public:
2349-
CleanupIllFormedExpressionRAII(Expr *&expr)
2350-
: expr(&expr) { }
2351-
2352-
~CleanupIllFormedExpressionRAII();
2353-
2354-
static void doIt(Expr *expr);
2355-
2356-
/// \brief Disable the cleanup of this expression; it doesn't need it.
2357-
void disable() {
2358-
expr = nullptr;
2359-
}
2360-
};
2361-
23622343
/// Temporary on-stack storage and unescaping for encoded diagnostic
23632344
/// messages.
23642345
///

0 commit comments

Comments
 (0)