Skip to content

Commit 7b27b4b

Browse files
committed
[silgenpattern] Change SILGenPattern to use CaseStmt::hasFallthroughDest() instead of computing this itself.
rdar://47467128
1 parent 78aefb9 commit 7b27b4b

File tree

2 files changed

+3
-41
lines changed

2 files changed

+3
-41
lines changed

include/swift/AST/Stmt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ class CaseStmt final
10631063
}
10641064

10651065
size_t numTrailingObjects(OverloadToken<FallthroughStmt *>) const {
1066-
return size_t(hasFallthrough);
1066+
return hasFallthrough ? 1 : 0;
10671067
}
10681068
};
10691069

lib/SILGen/SILGenPattern.cpp

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,44 +2521,6 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
25212521
}
25222522
}
25232523

2524-
namespace {
2525-
class FallthroughFinder : public ASTWalker {
2526-
bool &Result;
2527-
public:
2528-
FallthroughFinder(bool &Result) : Result(Result) {}
2529-
2530-
// We walk through statements. If we find a fallthrough, then we got what
2531-
// we came for.
2532-
std::pair<bool, Stmt *> walkToStmtPre(Stmt *S) override {
2533-
if (isa<FallthroughStmt>(S))
2534-
Result = true;
2535-
2536-
return { true, S };
2537-
}
2538-
2539-
// Expressions, patterns and decls cannot contain fallthrough statements, so
2540-
// there is no reason to walk into them.
2541-
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
2542-
return { false, E };
2543-
}
2544-
std::pair<bool, Pattern*> walkToPatternPre(Pattern *P) override {
2545-
return { false, P };
2546-
}
2547-
2548-
bool walkToDeclPre(Decl *D) override { return false; }
2549-
bool walkToTypeLocPre(TypeLoc &TL) override { return false; }
2550-
bool walkToTypeReprPre(TypeRepr *T) override { return false; }
2551-
};
2552-
} // end anonymous namespace
2553-
2554-
2555-
static bool containsFallthrough(Stmt *S) {
2556-
bool Result = false;
2557-
S->walk(FallthroughFinder(Result));
2558-
return Result;
2559-
}
2560-
2561-
25622524
/// Context info used to emit FallthroughStmts.
25632525
/// Since fallthrough-able case blocks must not bind variables, they are always
25642526
/// emitted in the outermost scope of the switch.
@@ -2770,8 +2732,8 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
27702732
const_cast<Expr*>(labelItem.getGuardExpr()),
27712733
hasFallthrough);
27722734
}
2773-
2774-
hasFallthrough = containsFallthrough(caseBlock->getBody());
2735+
2736+
hasFallthrough = caseBlock->hasFallthroughDest();
27752737
}
27762738

27772739
// Emit alloc_stacks for address-only variables appearing in

0 commit comments

Comments
 (0)