Skip to content

Commit 0dc0a64

Browse files
committed
wip: remove deprecated methods + comments, handle continue/break in for each
1 parent e7ec1ab commit 0dc0a64

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

include/swift/AST/Stmt.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,10 @@ class ForEachStmt : public LabeledStmt {
10081008
// Set by Sema:
10091009
ProtocolConformanceRef sequenceConformance = ProtocolConformanceRef();
10101010
Type sequenceType;
1011-
Expr *nextCall = nullptr;
10121011
BraceStmt *desugaredStmt = nullptr;
10131012
Expr *convertElementExpr = nullptr;
1013+
LabeledStmt *continueTarget = nullptr;
1014+
LabeledStmt *breakTarget = nullptr;
10141015

10151016
public:
10161017
ForEachStmt(LabeledStmtInfo LabelInfo, SourceLoc ForLoc, SourceLoc TryLoc,
@@ -1026,9 +1027,6 @@ class ForEachStmt : public LabeledStmt {
10261027
setPattern(Pat);
10271028
}
10281029

1029-
void setNextCall(Expr *next) { nextCall = next; }
1030-
Expr *getNextCall() const { return nextCall; }
1031-
10321030
void setConvertElementExpr(Expr *expr) { convertElementExpr = expr; }
10331031
Expr *getConvertElementExpr() const { return convertElementExpr; }
10341032

@@ -1087,6 +1085,12 @@ class ForEachStmt : public LabeledStmt {
10871085
BraceStmt* desugar();
10881086
BraceStmt* getDesugaredStmt() const { return desugaredStmt; }
10891087
void setDesugaredStmt(BraceStmt* newStmt) { desugaredStmt = newStmt; }
1088+
1089+
void setContinueTarget(LabeledStmt *target) { continueTarget = target; }
1090+
LabeledStmt* getContinueTarget() { return continueTarget; }
1091+
1092+
void setBreakTarget(LabeledStmt *target) { breakTarget = target; }
1093+
LabeledStmt* getBreakTarget() { return breakTarget; }
10901094
};
10911095

10921096
/// A pattern and an optional guard expression used in a 'case' statement.

lib/SILGen/SILGenStmt.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,8 @@ void StmtEmitter::visitBreakStmt(BreakStmt *S) {
14591459
void SILGenFunction::emitBreakOutOf(SILLocation loc, Stmt *target) {
14601460
// Find the target JumpDest based on the target that sema filled into the
14611461
// stmt.
1462+
if (isa<ForEachStmt>(target))
1463+
target = dyn_cast<ForEachStmt>(target)->getBreakTarget();
14621464
for (auto &elt : BreakContinueDestStack) {
14631465
if (target == elt.Target) {
14641466
Cleanups.emitBranchAndCleanups(elt.BreakDest, loc);
@@ -1471,10 +1473,14 @@ void SILGenFunction::emitBreakOutOf(SILLocation loc, Stmt *target) {
14711473
void StmtEmitter::visitContinueStmt(ContinueStmt *S) {
14721474
assert(S->getTarget() && "Sema didn't fill in continue target?");
14731475

1476+
auto* target = S->getTarget();
1477+
if (isa<ForEachStmt>(target))
1478+
target = dyn_cast<ForEachStmt>(target)->getContinueTarget();
1479+
14741480
// Find the target JumpDest based on the target that sema filled into the
14751481
// stmt.
14761482
for (auto &elt : SGF.BreakContinueDestStack) {
1477-
if (S->getTarget() == elt.Target) {
1483+
if (target == elt.Target) {
14781484
SGF.Cleanups.emitBranchAndCleanups(elt.ContinueDest, S);
14791485
return;
14801486
}

lib/Sema/CSApply.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9355,13 +9355,6 @@ applySolutionToForEachStmtPreamble(ForEachStmt *stmt,
93559355

93569356
stmt->setParsedSequence(rewrittenTarget->getAsExpr());
93579357

9358-
// FIXME: Next used to be optional but we have to deal w this differently now
9359-
// This models the gap between the type of the next call and the pattern's
9360-
// We will be typechecking next separately w the contextual type of the
9361-
// pattern we already have so this shouldnt be necessary anymore
9362-
// Convert that std::optional<Element> value to the type of the pattern.
9363-
// (deleted code here)
9364-
93659358
// Get the conformance of the sequence type to the Sequence protocol.
93669359
auto sequenceProto = TypeChecker::getProtocol(
93679360
ctx, stmt->getForLoc(),

lib/Sema/TypeCheckStmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3597,6 +3597,8 @@ static BraceStmt *desugarForEachStmt(ForEachStmt* stmt){
35973597
// FIXME: do we need to do anything extra here or elseswhere if the for each
35983598
// stmt is async?
35993599
auto* whileStmt = new (ctx) WhileStmt(stmt->getLabelInfo(), SourceLoc(), ctx.AllocateCopy(cond), whileBody, true);
3600+
stmt->setBreakTarget(whileStmt);
3601+
stmt->setContinueTarget(whileStmt);
36003602

36013603
SmallVector<ASTNode, 2> stmts;
36023604
stmts.push_back(PB);

0 commit comments

Comments
 (0)