Skip to content

Commit c89a4a5

Browse files
committed
Sema: Remove dead code from ExprCleaner and CleanupIllFormedExpressionRAII
1 parent 3cb14a0 commit c89a4a5

File tree

4 files changed

+13
-70
lines changed

4 files changed

+13
-70
lines changed

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3556,7 +3556,7 @@ bool swift::typeCheckUnresolvedExpr(DeclContext &DC,
35563556
auto *TC = static_cast<TypeChecker*>(DC.getASTContext().getLazyResolver());
35573557
ConstraintSystem CS(*TC, &DC, Options);
35583558
Parent = Parent->walk(SanitizeExpr(CS));
3559-
CleanupIllFormedExpressionRAII cleanup(TC->Context, Parent);
3559+
CleanupIllFormedExpressionRAII cleanup(Parent);
35603560
InferUnresolvedMemberConstraintGenerator MCG(E, CS);
35613561
ConstraintWalker cw(MCG);
35623562
Parent->walk(cw);

lib/Sema/ConstraintSystem.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,9 +3398,6 @@ void eraseOpenedExistentials(constraints::ConstraintSystem &CS, Expr *&expr);
33983398
/// their type variables, and we don't want pointers into the original AST to
33993399
/// dereference these now-dangling types.
34003400
class ExprCleaner {
3401-
llvm::SmallVector<Expr*,4> Exprs;
3402-
llvm::SmallVector<TypeLoc*, 4> TypeLocs;
3403-
llvm::SmallVector<Pattern*, 4> Patterns;
34043401
llvm::SmallVector<VarDecl*, 4> Vars;
34053402
public:
34063403

@@ -3409,21 +3406,6 @@ class ExprCleaner {
34093406
ExprCleaner *TS;
34103407
ExprCleanerImpl(ExprCleaner *TS) : TS(TS) {}
34113408

3412-
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
3413-
TS->Exprs.push_back(expr);
3414-
return { true, expr };
3415-
}
3416-
3417-
bool walkToTypeLocPre(TypeLoc &TL) override {
3418-
TS->TypeLocs.push_back(&TL);
3419-
return true;
3420-
}
3421-
3422-
std::pair<bool, Pattern*> walkToPatternPre(Pattern *P) override {
3423-
TS->Patterns.push_back(P);
3424-
return { true, P };
3425-
}
3426-
34273409
bool walkToDeclPre(Decl *D) override {
34283410
if (auto VD = dyn_cast<VarDecl>(D))
34293411
TS->Vars.push_back(VD);
@@ -3444,22 +3426,6 @@ class ExprCleaner {
34443426
~ExprCleaner() {
34453427
// Check each of the expression nodes to verify that there are no type
34463428
// variables hanging out. If so, just nuke the type.
3447-
for (auto E : Exprs) {
3448-
if (E->getType() && E->getType()->hasTypeVariable())
3449-
E->setType(Type());
3450-
}
3451-
3452-
for (auto TL : TypeLocs) {
3453-
if (TL->getTypeRepr() && TL->getType() &&
3454-
TL->getType()->hasTypeVariable())
3455-
TL->setType(Type(), false);
3456-
}
3457-
3458-
for (auto P : Patterns) {
3459-
if (P->hasType() && P->getType()->hasTypeVariable())
3460-
P->setType(Type());
3461-
}
3462-
34633429
for (auto VD : Vars) {
34643430
if (VD->hasType() && VD->getType()->hasTypeVariable()) {
34653431
VD->setType(Type());

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,31 +1649,9 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
16491649

16501650
/// \brief Clean up the given ill-formed expression, removing any references
16511651
/// to type variables and setting error types on erroneous expression nodes.
1652-
void CleanupIllFormedExpressionRAII::doIt(Expr *expr, ASTContext &Context) {
1652+
void CleanupIllFormedExpressionRAII::doIt(Expr *expr) {
16531653
class CleanupIllFormedExpression : public ASTWalker {
1654-
ASTContext &context;
1655-
16561654
public:
1657-
CleanupIllFormedExpression(ASTContext &context) : context(context) { }
1658-
1659-
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
1660-
// If the type of this expression has a type variable or is invalid,
1661-
// overwrite it with ErrorType.
1662-
Type type = expr->getType();
1663-
if (type && type->hasTypeVariable())
1664-
expr->setType(ErrorType::get(context));
1665-
1666-
return { true, expr };
1667-
}
1668-
1669-
// If we find a TypeLoc (e.g. in an as? expr) with a type variable, rewrite
1670-
// it.
1671-
bool walkToTypeLocPre(TypeLoc &TL) override {
1672-
if (TL.getType() && TL.getType()->hasTypeVariable())
1673-
TL.setType(Type(), /*was validated*/false);
1674-
return true;
1675-
}
1676-
16771655
bool walkToDeclPre(Decl *D) override {
16781656
// This handles parameter decls in ClosureExprs.
16791657
if (auto VD = dyn_cast<VarDecl>(D)) {
@@ -1692,13 +1670,13 @@ void CleanupIllFormedExpressionRAII::doIt(Expr *expr, ASTContext &Context) {
16921670
};
16931671

16941672
if (expr)
1695-
expr->walk(CleanupIllFormedExpression(Context));
1673+
expr->walk(CleanupIllFormedExpression());
16961674
}
16971675

16981676

16991677
CleanupIllFormedExpressionRAII::~CleanupIllFormedExpressionRAII() {
17001678
if (expr)
1701-
CleanupIllFormedExpressionRAII::doIt(*expr, Context);
1679+
CleanupIllFormedExpressionRAII::doIt(*expr);
17021680
}
17031681

17041682
/// Pre-check the expression, validating any types that occur in the
@@ -1825,7 +1803,7 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
18251803
csOptions |= ConstraintSystemFlags::PreferForceUnwrapToOptional;
18261804
ConstraintSystem cs(*this, dc, csOptions);
18271805
cs.baseCS = baseCS;
1828-
CleanupIllFormedExpressionRAII cleanup(Context, expr);
1806+
CleanupIllFormedExpressionRAII cleanup(expr);
18291807
ExprCleaner cleanup2(expr);
18301808

18311809
// Verify that a purpose was specified if a convertType was. Note that it is
@@ -1940,7 +1918,7 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
19401918

19411919
// Construct a constraint system from this expression.
19421920
ConstraintSystem cs(*this, dc, ConstraintSystemFlags::AllowFixes);
1943-
CleanupIllFormedExpressionRAII cleanup(Context, expr);
1921+
CleanupIllFormedExpressionRAII cleanup(expr);
19441922

19451923
// Attempt to solve the constraint system.
19461924
SmallVector<Solution, 4> viable;
@@ -2035,7 +2013,7 @@ void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
20352013
// If the previous checking gives the expr error type,
20362014
// clear the result and re-check.
20372015
{
2038-
CleanupIllFormedExpressionRAII cleanup(Context, expr);
2016+
CleanupIllFormedExpressionRAII cleanup(expr);
20392017

20402018
const Type originalType = expr->getType();
20412019
if (originalType && originalType->hasError())
@@ -2058,7 +2036,7 @@ bool TypeChecker::typeCheckCompletionSequence(Expr *&expr, DeclContext *DC) {
20582036

20592037
// Construct a constraint system from this expression.
20602038
ConstraintSystem CS(*this, DC, ConstraintSystemFlags::AllowFixes);
2061-
CleanupIllFormedExpressionRAII cleanup(Context, expr);
2039+
CleanupIllFormedExpressionRAII cleanup(expr);
20622040

20632041
auto *SE = cast<SequenceExpr>(expr);
20642042
assert(SE->getNumElements() >= 3);
@@ -2135,7 +2113,7 @@ bool TypeChecker::typeCheckExpressionShallow(Expr *&expr, DeclContext *dc) {
21352113

21362114
// Construct a constraint system from this expression.
21372115
ConstraintSystem cs(*this, dc, ConstraintSystemFlags::AllowFixes);
2138-
CleanupIllFormedExpressionRAII cleanup(Context, expr);
2116+
CleanupIllFormedExpressionRAII cleanup(expr);
21392117
if (auto generatedExpr = cs.generateConstraintsShallow(expr))
21402118
expr = generatedExpr;
21412119
else
@@ -3001,7 +2979,7 @@ bool TypeChecker::convertToType(Expr *&expr, Type type, DeclContext *dc,
30012979
// TODO: need to add kind arg?
30022980
// Construct a constraint system from this expression.
30032981
ConstraintSystem cs(*this, dc, ConstraintSystemFlags::AllowFixes);
3004-
CleanupIllFormedExpressionRAII cleanup(Context, expr);
2982+
CleanupIllFormedExpressionRAII cleanup(expr);
30052983

30062984
// If there is a type that we're expected to convert to, add the conversion
30072985
// constraint.

lib/Sema/TypeChecker.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,16 +2522,15 @@ class TypeChecker final : public LazyResolver {
25222522
/// \brief RAII object that cleans up the given expression if not explicitly
25232523
/// disabled.
25242524
class CleanupIllFormedExpressionRAII {
2525-
ASTContext &Context;
25262525
Expr **expr;
25272526

25282527
public:
2529-
CleanupIllFormedExpressionRAII(ASTContext &Context, Expr *&expr)
2530-
: Context(Context), expr(&expr) { }
2528+
CleanupIllFormedExpressionRAII(Expr *&expr)
2529+
: expr(&expr) { }
25312530

25322531
~CleanupIllFormedExpressionRAII();
25332532

2534-
static void doIt(Expr *expr, ASTContext &Context);
2533+
static void doIt(Expr *expr);
25352534

25362535
/// \brief Disable the cleanup of this expression; it doesn't need it.
25372536
void disable() {

0 commit comments

Comments
 (0)