posh icon indicating copy to clipboard operation
posh copied to clipboard

Fix redundant struct literal expressions in generated code

Open leod opened this issue 1 year ago • 0 comments

Currently, the implementation of Object::expr() returns a new Rc in each call. This is necessary to allow users to construct structs as normal Rust literals.

Since we use Rcs to deduplicate expressions, this has the downside of generating redundant struct literal expressions:

    vec4 var_0 = texture(uniforms_b, vertex_output_uv);
    float var_1 = var_0.x;
    float var_2 = var_0.y;
    float var_3 = var_0.z;
    vec3 var_4 = mix(((1.055 * pow(vec3(var_1, var_2, var_3), vec3(0.41666666, 0.41666666, 0.41666666))) - 0.055), (vec3(var_1, var_2, var_3) * 12.92), lessThan(vec3(var_1, var_2, var_3), vec3(0.0031308, 0.0031308, 0.0031308)));

Here, the vec3(var_1, var_2, var_3) is redundant.

We could fix this by caching struct literal expressions in Trace somehow. Maybe.

leod avatar Apr 04 '23 16:04 leod