From c7f7ca3d9ec1bfabb4061d73848a0a9d1568b413 Mon Sep 17 00:00:00 2001 From: James Price Date: Sat, 18 Jun 2022 14:22:15 +0000 Subject: [PATCH] tint: Simplify ++/-- handling in transform Now that we have untyped literals, we can just add `1` rather than adding either `1u` or `1i`. Bug: tint:1488 Change-Id: I59512be8fc67b1bf45088478da7c93bed37a69b8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94141 Auto-Submit: James Price Kokoro: Kokoro Commit-Queue: Ben Clayton Reviewed-by: Ben Clayton --- .../transform/expand_compound_assignment.cc | 8 +------- .../expand_compound_assignment_test.cc | 20 +++++++++---------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/tint/transform/expand_compound_assignment.cc b/src/tint/transform/expand_compound_assignment.cc index d15d790dab..e5e953cff0 100644 --- a/src/tint/transform/expand_compound_assignment.cc +++ b/src/tint/transform/expand_compound_assignment.cc @@ -174,14 +174,8 @@ void ExpandCompoundAssignment::Run(CloneContext& ctx, const DataMap&, DataMap&) state.Expand(assign, assign->lhs, ctx.Clone(assign->rhs), assign->op); } else if (auto* inc_dec = node->As()) { // For increment/decrement statements, `i++` becomes `i = i + 1`. - // TODO(jrprice): Simplify this when we have untyped literals. - auto* sem_lhs = ctx.src->Sem().Get(inc_dec->lhs); - const ast::IntLiteralExpression* one = - sem_lhs->Type()->UnwrapRef()->is_signed_integer_scalar() - ? ctx.dst->Expr(1_i)->As() - : ctx.dst->Expr(1_u)->As(); auto op = inc_dec->increment ? ast::BinaryOp::kAdd : ast::BinaryOp::kSubtract; - state.Expand(inc_dec, inc_dec->lhs, one, op); + state.Expand(inc_dec, inc_dec->lhs, ctx.dst->Expr(1_a), op); } } state.Finalize(); diff --git a/src/tint/transform/expand_compound_assignment_test.cc b/src/tint/transform/expand_compound_assignment_test.cc index 613a13535a..6b18b40378 100644 --- a/src/tint/transform/expand_compound_assignment_test.cc +++ b/src/tint/transform/expand_compound_assignment_test.cc @@ -473,7 +473,7 @@ fn main() { auto* expect = R"( fn main() { var v : i32; - v = (v + 1i); + v = (v + 1); } )"; @@ -493,7 +493,7 @@ fn main() { auto* expect = R"( fn main() { var v : u32; - v = (v + 1u); + v = (v + 1); } )"; @@ -513,7 +513,7 @@ fn main() { auto* expect = R"( fn main() { var v : i32; - v = (v - 1i); + v = (v - 1); } )"; @@ -533,7 +533,7 @@ fn main() { auto* expect = R"( fn main() { var v : u32; - v = (v - 1u); + v = (v - 1); } )"; @@ -556,7 +556,7 @@ fn main() { var v : i32; let p = &(v); let tint_symbol = &(*(p)); - *(tint_symbol) = (*(tint_symbol) + 1i); + *(tint_symbol) = (*(tint_symbol) + 1); } )"; @@ -584,7 +584,7 @@ struct S { fn main() { var s : S; - s.m = (s.m + 1i); + s.m = (s.m + 1); } )"; @@ -617,7 +617,7 @@ fn idx() -> i32 { fn main() { let tint_symbol = &(a[idx()]); - *(tint_symbol) = (*(tint_symbol) + 1i); + *(tint_symbol) = (*(tint_symbol) + 1); } )"; @@ -651,7 +651,7 @@ fn idx() -> i32 { fn main() { let tint_symbol = &(v); let tint_symbol_1 = idx(); - (*(tint_symbol))[tint_symbol_1] = ((*(tint_symbol))[tint_symbol_1] + 1i); + (*(tint_symbol))[tint_symbol_1] = ((*(tint_symbol))[tint_symbol_1] + 1); } )"; @@ -671,7 +671,7 @@ fn main() { auto* expect = R"( fn main() { var v : vec4; - v.y = (v.y + 1i); + v.y = (v.y + 1); } )"; @@ -727,7 +727,7 @@ fn main() { continuing { let tint_symbol = &(a[idx1()]); let tint_symbol_1 = idx2(); - (*(tint_symbol))[tint_symbol_1] = ((*(tint_symbol))[tint_symbol_1] + 1i); + (*(tint_symbol))[tint_symbol_1] = ((*(tint_symbol))[tint_symbol_1] + 1); } } }