Skip to content

Commit

Permalink
remove named expression entry for phony assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed May 2, 2022
1 parent 57e1793 commit 859cbac
Show file tree
Hide file tree
Showing 33 changed files with 1,014 additions and 157 deletions.
2 changes: 2 additions & 0 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,8 @@ impl<'a, W: Write> Writer<'a, W> {
Some(self.namer.call(name))
} else if self.need_bake_expressions.contains(&handle) {
Some(format!("{}{}", back::BAKE_PREFIX, handle.index()))
} else if info.ref_count == 0 {
Some(self.namer.call(""))
} else {
None
};
Expand Down
2 changes: 2 additions & 0 deletions src/back/hlsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,8 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
// Otherwise, we could accidentally write variable name instead of full expression.
// Also, we use sanitized names! It defense backend from generating variable with name from reserved keywords.
Some(self.namer.call(name))
} else if info.ref_count == 0 {
Some(self.namer.call(""))
} else {
let min_ref_count = func_ctx.expressions[handle].bake_ref_count();
if min_ref_count <= info.ref_count {
Expand Down
2 changes: 2 additions & 0 deletions src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2422,6 +2422,8 @@ impl<W: Write> Writer<W> {
// Don't assume the names in `named_expressions` are unique,
// or even valid. Use the `Namer`.
Some(self.namer.call(name))
} else if info.ref_count == 0 {
Some(self.namer.call(""))
} else {
// If this expression is an index that we're going to first compare
// against a limit, and then actually use as an index, then we may
Expand Down
5 changes: 5 additions & 0 deletions src/back/wgsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,11 @@ impl<W: Write> Writer<W> {
// Otherwise, we could accidentally write variable name instead of full expression.
// Also, we use sanitized names! It defense backend from generating variable with name from reserved keywords.
Some(self.namer.call(name))
} else if info.ref_count == 0 {
write!(self.out, "{}_ = ", level)?;
self.write_expr(module, handle, func_ctx)?;
writeln!(self.out, ";")?;
continue;
} else {
let expr = &func_ctx.expressions[handle];
let min_ref_count = expr.bake_ref_count();
Expand Down
5 changes: 1 addition & 4 deletions src/front/wgsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3499,15 +3499,12 @@ impl Parser {
let _ = lexer.next();
emitter.start(context.expressions);
lexer.expect(Token::Operation('='))?;
let expr_id = self.parse_general_expression(
self.parse_general_expression(
lexer,
context.as_expression(block, &mut emitter),
)?;
lexer.expect(Token::Separator(';'))?;
block.extend(emitter.finish(context.expressions));
// TODO: the situation here could be improved but
// for now this is necessary to get the expressions emitted
context.named_expressions.insert(expr_id, "_".to_string());
None
}
"let" => {
Expand Down
2 changes: 2 additions & 0 deletions tests/out/wgsl/210-bevy-2d-shader-vert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ fn main(@location(0) Vertex_Position: vec3<f32>, @location(1) Vertex_Normal: vec
Vertex_Position_1 = Vertex_Position;
Vertex_Normal_1 = Vertex_Normal;
Vertex_Uv_1 = Vertex_Uv;
_ = (&global.ViewProj);
_ = (&global_1.Model);
main_1();
let _e21 = v_Uv;
let _e23 = gl_Position;
Expand Down
1 change: 1 addition & 0 deletions tests/out/wgsl/210-bevy-shader-vert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn main(@location(0) Vertex_Position: vec3<f32>, @location(1) Vertex_Normal: vec
Vertex_Position_1 = Vertex_Position;
Vertex_Normal_1 = Vertex_Normal;
Vertex_Uv_1 = Vertex_Uv;
_ = (&global.ViewProj);
main_1();
let _e23 = v_Position;
let _e25 = v_Normal;
Expand Down
4 changes: 4 additions & 0 deletions tests/out/wgsl/246-collatz-comp.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ fn collatz_iterations(n: u32) -> u32 {
var n_1: u32;
var i: u32 = 0u;

_ = (&global.indices);
n_1 = n;
_ = u32(0);
loop {
let _e7 = n_1;
if !((_e7 != u32(1))) {
break;
}
{
_ = n_1;
let _e14 = n_1;
if ((f32(_e14) % f32(2)) == f32(0)) {
{
Expand Down Expand Up @@ -44,6 +47,7 @@ fn main_1() {
index = _e3.x;
let _e6 = index;
let _e8 = index;
_ = global.indices[_e8];
let _e11 = index;
let _e13 = global.indices[_e11];
let _e14 = collatz_iterations(_e13);
Expand Down
1 change: 1 addition & 0 deletions tests/out/wgsl/277-casting-vert.wgsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
fn main_1() {
var a: f32 = 1.0;

_ = f32(1);
}

@vertex
Expand Down
1 change: 1 addition & 0 deletions tests/out/wgsl/280-matrix-cast-vert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ fn main_1() {
var a: mat4x4<f32> = mat4x4<f32>(vec4<f32>(1.0, 0.0, 0.0, 0.0), vec4<f32>(0.0, 1.0, 0.0, 0.0), vec4<f32>(0.0, 0.0, 1.0, 0.0), vec4<f32>(0.0, 0.0, 0.0, 1.0));

let _e1 = f32(1);
_ = mat4x4<f32>(vec4<f32>(_e1, 0.0, 0.0, 0.0), vec4<f32>(0.0, _e1, 0.0, 0.0), vec4<f32>(0.0, 0.0, _e1, 0.0), vec4<f32>(0.0, 0.0, 0.0, _e1));
}

@vertex
Expand Down
2 changes: 2 additions & 0 deletions tests/out/wgsl/800-out-of-bounds-panic-vert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ fn main_1() {
fn main(@location(0) position: vec2<f32>, @location(1) color: vec4<f32>) -> VertexOutput {
position_1 = position;
color_1 = color;
_ = (&global.view_matrix);
_ = (&global_1.world_matrix);
main_1();
let _e15 = frag_color;
let _e17 = gl_Position;
Expand Down
1 change: 1 addition & 0 deletions tests/out/wgsl/900-implicit-conversions-vert.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ fn implicit_dims_3(v_6: vec4<f32>) {
fn main_1() {
exact_1(1);
implicit(f32(1u));
_ = vec3<i32>(1);
implicit_dims_2(vec3<f32>(vec3<i32>(1)));
return;
}
Expand Down
1 change: 1 addition & 0 deletions tests/out/wgsl/901-lhs-field-select-vert.wgsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
fn main_1() {
var a: vec4<f32> = vec4<f32>(1.0, 1.0, 1.0, 1.0);

_ = vec4<f32>(1.0);
a.x = 2.0;
return;
}
Expand Down
14 changes: 7 additions & 7 deletions tests/out/wgsl/access.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ fn test_matrix_within_struct_accesses() {

let _e4 = idx;
idx = (_e4 - 1);
let unnamed = baz.m;
let unnamed_1 = baz.m[0];
_ = baz.m;
_ = baz.m[0];
let _e14 = idx;
let unnamed_2 = baz.m[_e14];
let unnamed_3 = baz.m[0][1];
_ = baz.m[_e14];
_ = baz.m[0][1];
let _e26 = idx;
let unnamed_4 = baz.m[0][_e26];
_ = baz.m[0][_e26];
let _e30 = idx;
let unnamed_5 = baz.m[_e30][1];
_ = baz.m[_e30][1];
let _e36 = idx;
let _e38 = idx;
let unnamed_6 = baz.m[_e36][_e38];
_ = baz.m[_e36][_e38];
t = Baz(mat3x2<f32>(vec2<f32>(1.0), vec2<f32>(2.0), vec2<f32>(3.0)));
let _e50 = idx;
idx = (_e50 + 1);
Expand Down
Loading

0 comments on commit 859cbac

Please sign in to comment.