tint/HoistToDeclBefore: Use explicit types
Hoisting a constant array with an abstract type may change its materialized type when using type inference, so use explicit typing instead. Fixed: tint:1847 Change-Id: I890826945bac7a2b7d8a0b84967f9d3c9ba439b7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120901 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
parent
60d3738102
commit
239b4298b3
|
@ -134,7 +134,7 @@ Transform::ApplyResult PromoteInitializersToLet::Apply(const Program* src,
|
|||
return expr_a->Declaration()->node_id < expr_b->Declaration()->node_id;
|
||||
});
|
||||
|
||||
// Hoist all the expression in to_hoist to a constant variable, declared just before the
|
||||
// Hoist all the expressions in to_hoist to a constant variable, declared just before the
|
||||
// statement of usage.
|
||||
HoistToDeclBefore hoist_to_decl_before(ctx);
|
||||
for (auto* expr : to_hoist) {
|
||||
|
|
|
@ -61,7 +61,7 @@ fn f() {
|
|||
var f1 = 2.0;
|
||||
var f2 = 3.0;
|
||||
var f3 = 4.0;
|
||||
let tint_symbol = array<f32, 4u>(f0, f1, f2, f3);
|
||||
let tint_symbol : array<f32, 4u> = array<f32, 4u>(f0, f1, f2, f3);
|
||||
var i = tint_symbol[2];
|
||||
}
|
||||
)";
|
||||
|
@ -110,7 +110,7 @@ struct S {
|
|||
|
||||
fn f() {
|
||||
let runtime_value = 1;
|
||||
let tint_symbol = S(runtime_value, 2.0, vec3<f32>());
|
||||
let tint_symbol : S = S(runtime_value, 2.0, vec3<f32>());
|
||||
var x = tint_symbol.b;
|
||||
}
|
||||
)";
|
||||
|
@ -137,7 +137,7 @@ struct S {
|
|||
auto* expect = R"(
|
||||
fn f() {
|
||||
let runtime_value = 1;
|
||||
let tint_symbol = S(runtime_value, 2.0, vec3<f32>());
|
||||
let tint_symbol : S = S(runtime_value, 2.0, vec3<f32>());
|
||||
var x = tint_symbol.b;
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ const TRI_VERTICES = array(vec4(0.0, 0.0, 0.0, 1.0), vec4(0.0, 1.0, 0.0, 1.0), v
|
|||
|
||||
@vertex
|
||||
fn vs_main(@builtin(vertex_index) in_vertex_index : u32) -> @builtin(position) vec4<f32> {
|
||||
let tint_symbol = TRI_VERTICES;
|
||||
let tint_symbol : array<vec4<f32>, 3u> = TRI_VERTICES;
|
||||
return tint_symbol[in_vertex_index];
|
||||
}
|
||||
)";
|
||||
|
@ -249,7 +249,7 @@ fn f() {
|
|||
const f1 = 2.0;
|
||||
const C = array<f32, 2u>(f0, f1);
|
||||
let runtime_value = 1;
|
||||
let tint_symbol = C;
|
||||
let tint_symbol : array<f32, 2u> = C;
|
||||
var i = tint_symbol[runtime_value];
|
||||
}
|
||||
)";
|
||||
|
@ -272,7 +272,7 @@ fn f() {
|
|||
auto* expect = R"(
|
||||
fn f() {
|
||||
var insert_after = 1;
|
||||
let tint_symbol = array<f32, 4u>(0.0, 1.0, 2.0, 3.0);
|
||||
let tint_symbol : array<f32, 4u> = array<f32, 4u>(0.0, 1.0, 2.0, 3.0);
|
||||
for(var i = tint_symbol[insert_after]; ; ) {
|
||||
break;
|
||||
}
|
||||
|
@ -301,7 +301,7 @@ fn f() {
|
|||
const arr = array<f32, 4u>(0.0, 1.0, 2.0, 3.0);
|
||||
let runtime_value = 1;
|
||||
var insert_after = 1;
|
||||
let tint_symbol = arr;
|
||||
let tint_symbol : array<f32, 4u> = arr;
|
||||
for(var i = tint_symbol[runtime_value]; ; ) {
|
||||
break;
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ const arr = array<f32, 4u>(0.0, 1.0, 2.0, 3.0);
|
|||
fn f() {
|
||||
let runtime_value = 1;
|
||||
var insert_after = 1;
|
||||
let tint_symbol = arr;
|
||||
let tint_symbol : array<f32, 4u> = arr;
|
||||
for(var i = tint_symbol[runtime_value]; ; ) {
|
||||
break;
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ fn get_b_runtime(s : S) -> f32 {
|
|||
|
||||
fn f() {
|
||||
var insert_after = 1;
|
||||
let tint_symbol = S(1, 2.0, vec3<f32>());
|
||||
let tint_symbol : S = S(1, 2.0, vec3<f32>());
|
||||
for(var x = get_b_runtime(tint_symbol); ; ) {
|
||||
break;
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ struct S {
|
|||
auto* expect = R"(
|
||||
fn f() {
|
||||
var insert_after = 1;
|
||||
let tint_symbol = S(1, 2.0, vec3<f32>());
|
||||
let tint_symbol : S = S(1, 2.0, vec3<f32>());
|
||||
for(var x = get_b_runtime(tint_symbol); ; ) {
|
||||
break;
|
||||
}
|
||||
|
@ -448,7 +448,7 @@ fn f() {
|
|||
fn f() {
|
||||
var f = 1.0;
|
||||
loop {
|
||||
let tint_symbol = array<f32, 1u>(f);
|
||||
let tint_symbol : array<f32, 1u> = array<f32, 1u>(f);
|
||||
if (!((f == tint_symbol[0]))) {
|
||||
break;
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ fn f() {
|
|||
{
|
||||
var i = f;
|
||||
loop {
|
||||
let tint_symbol = arr;
|
||||
let tint_symbol : array<f32, 1u> = arr;
|
||||
if (!((i == tint_symbol[runtime_value]))) {
|
||||
break;
|
||||
}
|
||||
|
@ -533,7 +533,7 @@ fn F() {
|
|||
{
|
||||
var i = f;
|
||||
loop {
|
||||
let tint_symbol = arr;
|
||||
let tint_symbol : array<f32, 1u> = arr;
|
||||
if (!((i == tint_symbol[runtime_value]))) {
|
||||
break;
|
||||
}
|
||||
|
@ -578,7 +578,7 @@ fn f() {
|
|||
}
|
||||
|
||||
continuing {
|
||||
let tint_symbol = array<f32, 1u>(1.0);
|
||||
let tint_symbol : array<f32, 1u> = array<f32, 1u>(1.0);
|
||||
f = (f + tint_symbol[runtime_value]);
|
||||
}
|
||||
}
|
||||
|
@ -616,7 +616,7 @@ fn f() {
|
|||
}
|
||||
|
||||
continuing {
|
||||
let tint_symbol = arr;
|
||||
let tint_symbol : array<f32, 1u> = arr;
|
||||
f = (f + tint_symbol[runtime_value]);
|
||||
}
|
||||
}
|
||||
|
@ -656,7 +656,7 @@ fn f() {
|
|||
}
|
||||
|
||||
continuing {
|
||||
let tint_symbol = arr;
|
||||
let tint_symbol : array<f32, 1u> = arr;
|
||||
f = (f + tint_symbol[runtime_value]);
|
||||
}
|
||||
}
|
||||
|
@ -683,11 +683,11 @@ fn f() {
|
|||
auto* expect = R"(
|
||||
fn f() {
|
||||
let runtime_value = 0;
|
||||
let tint_symbol = array<f32, 1u>(0.0);
|
||||
let tint_symbol : array<f32, 1u> = array<f32, 1u>(0.0);
|
||||
{
|
||||
var f = tint_symbol[runtime_value];
|
||||
loop {
|
||||
let tint_symbol_1 = array<f32, 1u>(1.0);
|
||||
let tint_symbol_1 : array<f32, 1u> = array<f32, 1u>(1.0);
|
||||
if (!((f < tint_symbol_1[runtime_value]))) {
|
||||
break;
|
||||
}
|
||||
|
@ -696,7 +696,7 @@ fn f() {
|
|||
}
|
||||
|
||||
continuing {
|
||||
let tint_symbol_2 = array<f32, 1u>(2.0);
|
||||
let tint_symbol_2 : array<f32, 1u> = array<f32, 1u>(2.0);
|
||||
f = (f + tint_symbol_2[runtime_value]);
|
||||
}
|
||||
}
|
||||
|
@ -728,11 +728,11 @@ fn f() {
|
|||
const arr_a = array<f32, 1u>(0.0);
|
||||
const arr_b = array<f32, 1u>(1.0);
|
||||
const arr_c = array<f32, 1u>(2.0);
|
||||
let tint_symbol = arr_a;
|
||||
let tint_symbol : array<f32, 1u> = arr_a;
|
||||
{
|
||||
var f = tint_symbol[runtime_value];
|
||||
loop {
|
||||
let tint_symbol_1 = arr_b;
|
||||
let tint_symbol_1 : array<f32, 1u> = arr_b;
|
||||
if (!((f < tint_symbol_1[runtime_value]))) {
|
||||
break;
|
||||
}
|
||||
|
@ -741,7 +741,7 @@ fn f() {
|
|||
}
|
||||
|
||||
continuing {
|
||||
let tint_symbol_2 = arr_c;
|
||||
let tint_symbol_2 : array<f32, 1u> = arr_c;
|
||||
f = (f + tint_symbol_2[runtime_value]);
|
||||
}
|
||||
}
|
||||
|
@ -772,7 +772,7 @@ fn f() {
|
|||
if (true) {
|
||||
var marker = 0;
|
||||
} else {
|
||||
let tint_symbol = array<f32, 2u>(f, f);
|
||||
let tint_symbol : array<f32, 2u> = array<f32, 2u>(f, f);
|
||||
if ((f == tint_symbol[0])) {
|
||||
var marker = 1;
|
||||
}
|
||||
|
@ -813,11 +813,11 @@ fn f() {
|
|||
} else if (true) {
|
||||
var marker = 1;
|
||||
} else {
|
||||
let tint_symbol = array<f32, 2u>(f, f);
|
||||
let tint_symbol : array<f32, 2u> = array<f32, 2u>(f, f);
|
||||
if ((f == tint_symbol[0])) {
|
||||
var marker = 2;
|
||||
} else {
|
||||
let tint_symbol_1 = array<f32, 2u>(f, f);
|
||||
let tint_symbol_1 : array<f32, 2u> = array<f32, 2u>(f, f);
|
||||
if ((f == tint_symbol_1[1])) {
|
||||
var marker = 3;
|
||||
} else if (true) {
|
||||
|
@ -867,11 +867,11 @@ fn f() {
|
|||
} else if (true) {
|
||||
var marker = 1;
|
||||
} else {
|
||||
let tint_symbol = arr;
|
||||
let tint_symbol : array<f32, 2u> = arr;
|
||||
if ((f == tint_symbol[runtime_value])) {
|
||||
var marker = 2;
|
||||
} else {
|
||||
let tint_symbol_1 = arr;
|
||||
let tint_symbol_1 : array<f32, 2u> = arr;
|
||||
if ((f == tint_symbol_1[(runtime_value + 1)])) {
|
||||
var marker = 3;
|
||||
} else if (true) {
|
||||
|
@ -925,11 +925,11 @@ fn F() {
|
|||
} else if (true) {
|
||||
var marker = 1;
|
||||
} else {
|
||||
let tint_symbol = arr;
|
||||
let tint_symbol : array<f32, 2u> = arr;
|
||||
if ((f == tint_symbol[runtime_value])) {
|
||||
var marker = 2;
|
||||
} else {
|
||||
let tint_symbol_1 = arr;
|
||||
let tint_symbol_1 : array<f32, 2u> = arr;
|
||||
if ((f == tint_symbol_1[(runtime_value + 1)])) {
|
||||
var marker = 3;
|
||||
} else if (true) {
|
||||
|
@ -968,7 +968,7 @@ fn f() {
|
|||
auto* expect = R"(
|
||||
fn f() {
|
||||
let runtime_value = 1;
|
||||
let tint_symbol = array<array<f32, 2u>, 2u>(array<f32, 2u>(1.0, 2.0), array<f32, 2u>(3.0, 4.0));
|
||||
let tint_symbol : array<array<f32, 2u>, 2u> = array<array<f32, 2u>, 2u>(array<f32, 2u>(1.0, 2.0), array<f32, 2u>(3.0, 4.0));
|
||||
var i = tint_symbol[runtime_value][(runtime_value + 1)];
|
||||
}
|
||||
)";
|
||||
|
@ -1008,7 +1008,7 @@ fn f() {
|
|||
const arr_0 = array<f32, 2u>(1.0, 2.0);
|
||||
const arr_1 = array<f32, 2u>(3.0, 4.0);
|
||||
const arr_2 = array<array<f32, 2u>, 2u>(arr_0, arr_1);
|
||||
let tint_symbol = arr_2;
|
||||
let tint_symbol : array<array<f32, 2u>, 2u> = arr_2;
|
||||
var i = tint_symbol[runtime_value][(runtime_value + 1)];
|
||||
}
|
||||
)";
|
||||
|
@ -1041,7 +1041,7 @@ const arr_2 = array<array<f32, 2u>, 2u>(arr_0, arr_1);
|
|||
|
||||
fn f() {
|
||||
let runtime_value = 1;
|
||||
let tint_symbol = arr_2;
|
||||
let tint_symbol : array<array<f32, 2u>, 2u> = arr_2;
|
||||
var i = tint_symbol[runtime_value][(runtime_value + 1)];
|
||||
}
|
||||
)";
|
||||
|
@ -1096,7 +1096,7 @@ fn get_a(s : S3) -> S2 {
|
|||
}
|
||||
|
||||
fn f() {
|
||||
let tint_symbol = S3(S2(1, S1(2), 3));
|
||||
let tint_symbol : S3 = S3(S2(1, S1(2), 3));
|
||||
var x = get_a(tint_symbol).b.a;
|
||||
}
|
||||
)";
|
||||
|
@ -1139,7 +1139,7 @@ fn get_a(s : S2) -> array<S1, 3u> {
|
|||
}
|
||||
|
||||
fn f() {
|
||||
let tint_symbol = S2(array<S1, 3u>(S1(1), S1(2), S1(3)));
|
||||
let tint_symbol : S2 = S2(array<S1, 3u>(S1(1), S1(2), S1(3)));
|
||||
var x = get_a(tint_symbol)[1].a;
|
||||
}
|
||||
)";
|
||||
|
@ -1170,7 +1170,7 @@ struct S1 {
|
|||
|
||||
auto* expect = R"(
|
||||
fn f() {
|
||||
let tint_symbol = S2(array<S1, 3u>(S1(1), S1(2), S1(3)));
|
||||
let tint_symbol : S2 = S2(array<S1, 3u>(S1(1), S1(2), S1(3)));
|
||||
var x = get_a(tint_symbol)[1].a;
|
||||
}
|
||||
|
||||
|
@ -1272,7 +1272,7 @@ fn X() {
|
|||
}
|
||||
|
||||
continuing {
|
||||
let tint_symbol = array<i32, 1u>(i);
|
||||
let tint_symbol : array<i32, 1u> = array<i32, 1u>(i);
|
||||
f = (f + tint_symbol[0]);
|
||||
}
|
||||
}
|
||||
|
@ -1284,7 +1284,7 @@ fn Y() {
|
|||
{
|
||||
var f = 0;
|
||||
loop {
|
||||
let tint_symbol_1 = array<i32, 1u>(i);
|
||||
let tint_symbol_1 : array<i32, 1u> = array<i32, 1u>(i);
|
||||
if (!((f < tint_symbol_1[0]))) {
|
||||
break;
|
||||
}
|
||||
|
@ -1301,7 +1301,7 @@ fn Y() {
|
|||
|
||||
fn Z() {
|
||||
var i = 10;
|
||||
let tint_symbol_2 = array<i32, 1u>(i);
|
||||
let tint_symbol_2 : array<i32, 1u> = array<i32, 1u>(i);
|
||||
for(var f = tint_symbol_2[0]; (f < 10); f = (f + 1)) {
|
||||
var i = 20;
|
||||
}
|
||||
|
@ -1313,5 +1313,27 @@ fn Z() {
|
|||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(PromoteInitializersToLetTest, AssignAbstractArray) {
|
||||
// Test that hoisting an array with abstract type still materializes to the correct type.
|
||||
auto* src = R"(
|
||||
fn f() {
|
||||
var arr : array<f32, 4>;
|
||||
arr = array(1, 2, 3, 4);
|
||||
}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
fn f() {
|
||||
var arr : array<f32, 4>;
|
||||
let tint_symbol : array<f32, 4u> = array(1, 2, 3, 4);
|
||||
arr = tint_symbol;
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<PromoteInitializersToLet>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::transform
|
||||
|
|
|
@ -181,6 +181,12 @@ class Transform : public Castable<Transform> {
|
|||
const DataMap& inputs,
|
||||
DataMap& outputs) const = 0;
|
||||
|
||||
/// CreateASTTypeFor constructs new ast::Type that reconstructs the semantic type `ty`.
|
||||
/// @param ctx the clone context
|
||||
/// @param ty the semantic type to reconstruct
|
||||
/// @returns an ast::Type that when resolved, will produce the semantic type `ty`.
|
||||
static ast::Type CreateASTTypeFor(CloneContext& ctx, const type::Type* ty);
|
||||
|
||||
protected:
|
||||
/// Removes the statement `stmt` from the transformed program.
|
||||
/// RemoveStatement handles edge cases, like statements in the initializer and
|
||||
|
@ -188,12 +194,6 @@ class Transform : public Castable<Transform> {
|
|||
/// @param ctx the clone context
|
||||
/// @param stmt the statement to remove when the program is cloned
|
||||
static void RemoveStatement(CloneContext& ctx, const ast::Statement* stmt);
|
||||
|
||||
/// CreateASTTypeFor constructs new ast::Type that reconstructs the semantic type `ty`.
|
||||
/// @param ctx the clone context
|
||||
/// @param ty the semantic type to reconstruct
|
||||
/// @returns an ast::Type that when resolved, will produce the semantic type `ty`.
|
||||
static ast::Type CreateASTTypeFor(CloneContext& ctx, const type::Type* ty);
|
||||
};
|
||||
|
||||
} // namespace tint::transform
|
||||
|
|
|
@ -45,7 +45,9 @@ struct HoistToDeclBefore::State {
|
|||
switch (kind) {
|
||||
case VariableKind::kLet: {
|
||||
auto builder = [this, expr, name] {
|
||||
return b.Decl(b.Let(name, ctx.CloneWithoutTransform(expr)));
|
||||
return b.Decl(b.Let(
|
||||
name, Transform::CreateASTTypeFor(ctx, ctx.src->Sem().GetVal(expr)->Type()),
|
||||
ctx.CloneWithoutTransform(expr)));
|
||||
};
|
||||
if (!InsertBeforeImpl(before_expr->Stmt(), std::move(builder))) {
|
||||
return false;
|
||||
|
@ -55,7 +57,9 @@ struct HoistToDeclBefore::State {
|
|||
|
||||
case VariableKind::kVar: {
|
||||
auto builder = [this, expr, name] {
|
||||
return b.Decl(b.Var(name, ctx.CloneWithoutTransform(expr)));
|
||||
return b.Decl(b.Var(
|
||||
name, Transform::CreateASTTypeFor(ctx, ctx.src->Sem().GetVal(expr)->Type()),
|
||||
ctx.CloneWithoutTransform(expr)));
|
||||
};
|
||||
if (!InsertBeforeImpl(before_expr->Stmt(), std::move(builder))) {
|
||||
return false;
|
||||
|
|
|
@ -51,7 +51,7 @@ TEST_F(HoistToDeclBeforeTest, VarInit) {
|
|||
|
||||
auto* expect = R"(
|
||||
fn f() {
|
||||
let tint_symbol = 1i;
|
||||
let tint_symbol : i32 = 1i;
|
||||
var a = tint_symbol;
|
||||
}
|
||||
)";
|
||||
|
@ -82,7 +82,7 @@ TEST_F(HoistToDeclBeforeTest, ForLoopInit) {
|
|||
|
||||
auto* expect = R"(
|
||||
fn f() {
|
||||
var tint_symbol = 1i;
|
||||
var tint_symbol : i32 = 1i;
|
||||
for(var a = tint_symbol; true; ) {
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ fn f() {
|
|||
}
|
||||
|
||||
continuing {
|
||||
let tint_symbol = 1i;
|
||||
let tint_symbol : i32 = 1i;
|
||||
var a = tint_symbol;
|
||||
}
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ TEST_F(HoistToDeclBeforeTest, WhileCond) {
|
|||
fn f() {
|
||||
var a : bool;
|
||||
loop {
|
||||
var tint_symbol = a;
|
||||
var tint_symbol : bool = a;
|
||||
if (!(tint_symbol)) {
|
||||
break;
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ TEST_F(HoistToDeclBeforeTest, Array1D) {
|
|||
auto* expect = R"(
|
||||
fn f() {
|
||||
var a : array<i32, 10u>;
|
||||
let tint_symbol = a[0i];
|
||||
let tint_symbol : i32 = a[0i];
|
||||
var b = tint_symbol;
|
||||
}
|
||||
)";
|
||||
|
@ -314,7 +314,7 @@ TEST_F(HoistToDeclBeforeTest, Array2D) {
|
|||
auto* expect = R"(
|
||||
fn f() {
|
||||
var a : array<array<i32, 10u>, 10i>;
|
||||
var tint_symbol = a[0i][0i];
|
||||
var tint_symbol : i32 = a[0i][0i];
|
||||
var b = tint_symbol;
|
||||
}
|
||||
)";
|
||||
|
@ -793,5 +793,65 @@ fn f() {
|
|||
EXPECT_EQ(expect, str(cloned));
|
||||
}
|
||||
|
||||
TEST_F(HoistToDeclBeforeTest, AbstractArray_ToLet) {
|
||||
// fn f() {
|
||||
// var a : array<f32, 1> = array(1);
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* expr = b.Call(b.ty("array"), b.Expr(1_a));
|
||||
auto* var = b.Decl(b.Var("a", b.ty.array(b.ty.f32(), 1_a), expr));
|
||||
b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{var});
|
||||
|
||||
Program original(std::move(b));
|
||||
ProgramBuilder cloned_b;
|
||||
CloneContext ctx(&cloned_b, &original);
|
||||
|
||||
HoistToDeclBefore hoistToDeclBefore(ctx);
|
||||
auto* sem_expr = ctx.src->Sem().Get(expr);
|
||||
hoistToDeclBefore.Add(sem_expr, expr, HoistToDeclBefore::VariableKind::kLet);
|
||||
|
||||
ctx.Clone();
|
||||
Program cloned(std::move(cloned_b));
|
||||
|
||||
auto* expect = R"(
|
||||
fn f() {
|
||||
let tint_symbol : array<f32, 1u> = array(1);
|
||||
var a : array<f32, 1> = tint_symbol;
|
||||
}
|
||||
)";
|
||||
|
||||
EXPECT_EQ(expect, str(cloned));
|
||||
}
|
||||
|
||||
TEST_F(HoistToDeclBeforeTest, AbstractArray_ToVar) {
|
||||
// fn f() {
|
||||
// var a : array<f32, 1> = array(1);
|
||||
// }
|
||||
ProgramBuilder b;
|
||||
auto* expr = b.Call(b.ty("array"), b.Expr(1_a));
|
||||
auto* var = b.Decl(b.Var("a", b.ty.array(b.ty.f32(), 1_a), expr));
|
||||
b.Func("f", utils::Empty, b.ty.void_(), utils::Vector{var});
|
||||
|
||||
Program original(std::move(b));
|
||||
ProgramBuilder cloned_b;
|
||||
CloneContext ctx(&cloned_b, &original);
|
||||
|
||||
HoistToDeclBefore hoistToDeclBefore(ctx);
|
||||
auto* sem_expr = ctx.src->Sem().Get(expr);
|
||||
hoistToDeclBefore.Add(sem_expr, expr, HoistToDeclBefore::VariableKind::kVar);
|
||||
|
||||
ctx.Clone();
|
||||
Program cloned(std::move(cloned_b));
|
||||
|
||||
auto* expect = R"(
|
||||
fn f() {
|
||||
var tint_symbol : array<f32, 1u> = array(1);
|
||||
var a : array<f32, 1> = tint_symbol;
|
||||
}
|
||||
)";
|
||||
|
||||
EXPECT_EQ(expect, str(cloned));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::transform
|
||||
|
|
|
@ -44,7 +44,7 @@ fn f() {
|
|||
fn f() {
|
||||
var i : i32;
|
||||
let p = array<i32, 4>(1, 2, 3, 4);
|
||||
var var_for_index = p;
|
||||
var var_for_index : array<i32, 4u> = p;
|
||||
let x = var_for_index[i];
|
||||
}
|
||||
)";
|
||||
|
@ -68,7 +68,7 @@ fn f() {
|
|||
fn f() {
|
||||
var i : i32;
|
||||
let p = mat2x2(1.0, 2.0, 3.0, 4.0);
|
||||
var var_for_index = p;
|
||||
var var_for_index : mat2x2<f32> = p;
|
||||
let x = var_for_index[i];
|
||||
}
|
||||
)";
|
||||
|
@ -99,8 +99,8 @@ fn f() {
|
|||
var i : i32;
|
||||
var j : i32;
|
||||
let p = array<array<i32, 2>, 2>(array<i32, 2>(1, 2), array<i32, 2>(3, 4));
|
||||
var var_for_index = p;
|
||||
var var_for_index_1 = var_for_index[i];
|
||||
var var_for_index : array<array<i32, 2u>, 2u> = p;
|
||||
var var_for_index_1 : array<i32, 2u> = var_for_index[i];
|
||||
let x = var_for_index_1[j];
|
||||
}
|
||||
)";
|
||||
|
@ -126,7 +126,7 @@ fn f() {
|
|||
fn f() {
|
||||
var i : i32;
|
||||
let p = array<array<i32, 2>, 2>(array<i32, 2>(1, 2), array<i32, 2>(3, 4));
|
||||
var var_for_index = p;
|
||||
var var_for_index : array<array<i32, 2u>, 2u> = p;
|
||||
for(let x = var_for_index[i]; ; ) {
|
||||
break;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ fn f() {
|
|||
fn f() {
|
||||
var i : i32;
|
||||
let p = mat2x2(1.0, 2.0, 3.0, 4.0);
|
||||
var var_for_index = p;
|
||||
var var_for_index : mat2x2<f32> = p;
|
||||
for(let x = var_for_index[i]; ; ) {
|
||||
break;
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ fn f() {
|
|||
var i : i32;
|
||||
let p = array<i32, 2>(1, 2);
|
||||
loop {
|
||||
var var_for_index = p;
|
||||
var var_for_index : array<i32, 2u> = p;
|
||||
if (!((var_for_index[i] < 3))) {
|
||||
break;
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ fn f() {
|
|||
var i : i32;
|
||||
let p = mat2x2(1.0, 2.0, 3.0, 4.0);
|
||||
loop {
|
||||
var var_for_index = p;
|
||||
var var_for_index : mat2x2<f32> = p;
|
||||
if (!((var_for_index[i].x < 3.0))) {
|
||||
break;
|
||||
}
|
||||
|
@ -252,12 +252,12 @@ fn f() {
|
|||
var i : i32;
|
||||
let p = mat2x2(1.0, 2.0, 3.0, 4.0);
|
||||
loop {
|
||||
var var_for_index = p;
|
||||
var var_for_index : mat2x2<f32> = p;
|
||||
if (!((var_for_index[i].x < 3.0))) {
|
||||
break;
|
||||
}
|
||||
{
|
||||
var var_for_index_1 = p;
|
||||
var var_for_index_1 : mat2x2<f32> = p;
|
||||
if ((var_for_index_1[i].x < 1.0)) {
|
||||
var marker = 1;
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ fn f() {
|
|||
if (false) {
|
||||
var marker = 0;
|
||||
} else {
|
||||
var var_for_index = p;
|
||||
var var_for_index : array<i32, 2u> = p;
|
||||
if ((var_for_index[i] < 3)) {
|
||||
var marker = 1;
|
||||
}
|
||||
|
@ -337,11 +337,11 @@ fn f() {
|
|||
} else if (true) {
|
||||
var marker = 1;
|
||||
} else {
|
||||
var var_for_index = p;
|
||||
var var_for_index : array<i32, 2u> = p;
|
||||
if ((var_for_index[i] < 3)) {
|
||||
var marker = 2;
|
||||
} else {
|
||||
var var_for_index_1 = p;
|
||||
var var_for_index_1 : array<i32, 2u> = p;
|
||||
if ((var_for_index_1[i] < 4)) {
|
||||
var marker = 3;
|
||||
} else if (true) {
|
||||
|
@ -380,7 +380,7 @@ fn f() {
|
|||
if (false) {
|
||||
var marker_if = 1;
|
||||
} else {
|
||||
var var_for_index = p;
|
||||
var var_for_index : mat2x2<f32> = p;
|
||||
if ((var_for_index[i].x < 3.0)) {
|
||||
var marker_else_if = 1;
|
||||
}
|
||||
|
@ -424,11 +424,11 @@ fn f() {
|
|||
} else if (true) {
|
||||
var marker = 1;
|
||||
} else {
|
||||
var var_for_index = p;
|
||||
var var_for_index : mat2x2<f32> = p;
|
||||
if ((var_for_index[i].x < 3.0)) {
|
||||
var marker = 2;
|
||||
} else {
|
||||
var var_for_index_1 = p;
|
||||
var var_for_index_1 : mat2x2<f32> = p;
|
||||
if ((var_for_index_1[i].y < 3.0)) {
|
||||
var marker = 3;
|
||||
} else if (true) {
|
||||
|
|
Loading…
Reference in New Issue