mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 10:49:14 +00:00
Remove if-break deprecation
This CL removes support or if-break and requires the use of break-if. Bug: tint:1724 Change-Id: I8311de2f0ce11b5af7fada71d258ae441f9e42f8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/111100 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
669e15e139
commit
0acbb4e047
@@ -557,16 +557,6 @@ TEST_F(ResolverBehaviorTest, StmtLoopEmpty_ContEmpty_NoExit) {
|
||||
EXPECT_EQ(r()->error(), "12:34 error: loop does not exit");
|
||||
}
|
||||
|
||||
TEST_F(ResolverBehaviorTest, StmtLoopEmpty_ContIfTrueBreak) {
|
||||
auto* stmt = Loop(Block(), Block(If(true, Block(Break()))));
|
||||
WrapInFunction(stmt);
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
auto* sem = Sem().Get(stmt);
|
||||
EXPECT_EQ(sem->Behaviors(), sem::Behavior::kNext);
|
||||
}
|
||||
|
||||
TEST_F(ResolverBehaviorTest, StmtLoopEmpty_BreakIf) {
|
||||
auto* stmt = Loop(Block(), Block(BreakIf(true)));
|
||||
WrapInFunction(stmt);
|
||||
|
||||
@@ -1029,10 +1029,10 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfTrueInContinuing) {
|
||||
// }
|
||||
// }
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 warning: use of deprecated language feature: `break` must not be used to exit "
|
||||
"from a continuing block. Use `break-if` instead.");
|
||||
"12:34 error: `break` must not be used to exit from a continuing block. "
|
||||
"Use `break-if` instead.");
|
||||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfElseInContinuing) {
|
||||
@@ -1043,10 +1043,10 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfElseInContinuing) {
|
||||
// }
|
||||
// }
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 warning: use of deprecated language feature: `break` must not be used to exit "
|
||||
"from a continuing block. Use `break-if` instead.");
|
||||
"12:34 error: `break` must not be used to exit from a continuing block. "
|
||||
"Use `break-if` instead.");
|
||||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInContinuing) {
|
||||
@@ -1056,12 +1056,8 @@ TEST_F(ResolverValidationTest, Stmt_BreakInContinuing) {
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 warning: use of deprecated language feature: `break` must not be used to exit "
|
||||
"from a continuing block. Use `break-if` instead.\n"
|
||||
"12:34 error: break statement in a continuing block must be the single "
|
||||
"statement of an if statement's true or false block, and that if "
|
||||
"statement must be the last statement of the continuing block\n"
|
||||
"12:34 note: break statement is not directly in if statement block");
|
||||
"12:34 error: `break` must not be used to exit from a continuing block. "
|
||||
"Use `break-if` instead.");
|
||||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfInIfInContinuing) {
|
||||
@@ -1075,13 +1071,8 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfInIfInContinuing) {
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 warning: use of deprecated language feature: `break` must not be used to exit "
|
||||
"from a continuing block. Use `break-if` instead.\n"
|
||||
"12:34 error: break statement in a continuing block must be the single "
|
||||
"statement of an if statement's true or false block, and that if "
|
||||
"statement must be the last statement of the continuing block\n"
|
||||
"56:78 note: if statement containing break statement is not directly in "
|
||||
"continuing block");
|
||||
"12:34 error: `break` must not be used to exit from a continuing block. "
|
||||
"Use `break-if` instead.");
|
||||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfTrueMultipleStmtsInContinuing) {
|
||||
@@ -1094,12 +1085,8 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfTrueMultipleStmtsInContinuing) {
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 warning: use of deprecated language feature: `break` must not be used to exit "
|
||||
"from a continuing block. Use `break-if` instead.\n"
|
||||
"12:34 error: break statement in a continuing block must be the single "
|
||||
"statement of an if statement's true or false block, and that if "
|
||||
"statement must be the last statement of the continuing block\n"
|
||||
"56:78 note: if statement block contains multiple statements");
|
||||
"12:34 error: `break` must not be used to exit from a continuing block. "
|
||||
"Use `break-if` instead.");
|
||||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfElseMultipleStmtsInContinuing) {
|
||||
@@ -1113,12 +1100,8 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfElseMultipleStmtsInContinuing) {
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 warning: use of deprecated language feature: `break` must not be used to exit "
|
||||
"from a continuing block. Use `break-if` instead.\n"
|
||||
"12:34 error: break statement in a continuing block must be the single "
|
||||
"statement of an if statement's true or false block, and that if "
|
||||
"statement must be the last statement of the continuing block\n"
|
||||
"56:78 note: if statement block contains multiple statements");
|
||||
"12:34 error: `break` must not be used to exit from a continuing block. "
|
||||
"Use `break-if` instead.");
|
||||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfElseIfInContinuing) {
|
||||
@@ -1131,12 +1114,8 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfElseIfInContinuing) {
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 warning: use of deprecated language feature: `break` must not be used to exit "
|
||||
"from a continuing block. Use `break-if` instead.\n"
|
||||
"12:34 error: break statement in a continuing block must be the single "
|
||||
"statement of an if statement's true or false block, and that if "
|
||||
"statement must be the last statement of the continuing block\n"
|
||||
"56:78 note: else has condition");
|
||||
"12:34 error: `break` must not be used to exit from a continuing block. "
|
||||
"Use `break-if` instead.");
|
||||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfNonEmptyElseInContinuing) {
|
||||
@@ -1150,12 +1129,8 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfNonEmptyElseInContinuing) {
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 warning: use of deprecated language feature: `break` must not be used to exit "
|
||||
"from a continuing block. Use `break-if` instead.\n"
|
||||
"12:34 error: break statement in a continuing block must be the single "
|
||||
"statement of an if statement's true or false block, and that if "
|
||||
"statement must be the last statement of the continuing block\n"
|
||||
"56:78 note: non-empty false block");
|
||||
"12:34 error: `break` must not be used to exit from a continuing block. "
|
||||
"Use `break-if` instead.");
|
||||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfElseNonEmptyTrueInContinuing) {
|
||||
@@ -1169,12 +1144,8 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfElseNonEmptyTrueInContinuing) {
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 warning: use of deprecated language feature: `break` must not be used to exit "
|
||||
"from a continuing block. Use `break-if` instead.\n"
|
||||
"12:34 error: break statement in a continuing block must be the single "
|
||||
"statement of an if statement's true or false block, and that if "
|
||||
"statement must be the last statement of the continuing block\n"
|
||||
"56:78 note: non-empty true block");
|
||||
"12:34 error: `break` must not be used to exit from a continuing block. "
|
||||
"Use `break-if` instead.");
|
||||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakInIfInContinuingNotLast) {
|
||||
@@ -1187,13 +1158,8 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfInContinuingNotLast) {
|
||||
WrapInFunction(Loop(Block(), cont));
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 warning: use of deprecated language feature: `break` must not be used to exit "
|
||||
"from a continuing block. Use `break-if` instead.\n"
|
||||
"12:34 error: break statement in a continuing block must be the single "
|
||||
"statement of an if statement's true or false block, and that if "
|
||||
"statement must be the last statement of the continuing block\n"
|
||||
"56:78 note: if statement containing break statement is not the last "
|
||||
"statement of the continuing block");
|
||||
"12:34 error: `break` must not be used to exit from a continuing block. "
|
||||
"Use `break-if` instead.");
|
||||
}
|
||||
|
||||
TEST_F(ResolverValidationTest, Stmt_BreakNotInLoopOrSwitch) {
|
||||
|
||||
@@ -1438,64 +1438,11 @@ bool Validator::BreakStatement(const sem::Statement* stmt,
|
||||
AddError("break statement must be in a loop or switch case", stmt->Declaration()->source);
|
||||
return false;
|
||||
}
|
||||
if (auto* continuing = ClosestContinuing(/*stop_at_loop*/ true, current_statement)) {
|
||||
AddWarning(
|
||||
"use of deprecated language feature: `break` must not be used to exit from "
|
||||
"a continuing block. Use `break-if` instead.",
|
||||
if (ClosestContinuing(/*stop_at_loop*/ true, current_statement) != nullptr) {
|
||||
AddError(
|
||||
"`break` must not be used to exit from a continuing block. Use `break-if` instead.",
|
||||
stmt->Declaration()->source);
|
||||
|
||||
auto fail = [&](const char* note_msg, const Source& note_src) {
|
||||
constexpr const char* kErrorMsg =
|
||||
"break statement in a continuing block must be the single statement of an if "
|
||||
"statement's true or false block, and that if statement must be the last statement "
|
||||
"of the continuing block";
|
||||
AddError(kErrorMsg, stmt->Declaration()->source);
|
||||
AddNote(note_msg, note_src);
|
||||
return false;
|
||||
};
|
||||
|
||||
if (auto* block = stmt->Parent()->As<sem::BlockStatement>()) {
|
||||
auto* block_parent = block->Parent();
|
||||
auto* if_stmt = block_parent->As<sem::IfStatement>();
|
||||
if (!if_stmt) {
|
||||
return fail("break statement is not directly in if statement block",
|
||||
stmt->Declaration()->source);
|
||||
}
|
||||
if (block->Declaration()->statements.Length() != 1) {
|
||||
return fail("if statement block contains multiple statements",
|
||||
block->Declaration()->source);
|
||||
}
|
||||
|
||||
if (if_stmt->Parent()->Is<sem::IfStatement>()) {
|
||||
return fail("else has condition", if_stmt->Declaration()->source);
|
||||
}
|
||||
|
||||
bool el_contains_break = block->Declaration() == if_stmt->Declaration()->else_statement;
|
||||
if (el_contains_break) {
|
||||
if (auto* true_block = if_stmt->Declaration()->body; !true_block->Empty()) {
|
||||
return fail("non-empty true block", true_block->source);
|
||||
}
|
||||
} else {
|
||||
auto* else_stmt = if_stmt->Declaration()->else_statement;
|
||||
if (else_stmt) {
|
||||
return fail("non-empty false block", else_stmt->source);
|
||||
}
|
||||
}
|
||||
|
||||
if (if_stmt->Parent()->Declaration() != continuing) {
|
||||
return fail(
|
||||
"if statement containing break statement is not directly in continuing block",
|
||||
if_stmt->Declaration()->source);
|
||||
}
|
||||
if (auto* cont_block = continuing->As<ast::BlockStatement>()) {
|
||||
if (if_stmt->Declaration() != cont_block->Last()) {
|
||||
return fail(
|
||||
"if statement containing break statement is not the last statement of the "
|
||||
"continuing block",
|
||||
if_stmt->Declaration()->source);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user