On Tue Apr 11 03:05:16 2023 +0000, Zebediah Figura wrote:
Now, regarding the reporting the previous variable's location. It begs
the question of what to do when there are more than 2 repetitions. If we do this, we probably would want to report all locations where the semantic is used, and also find a way of reporting when a semantic is used more than once in a single location that doesn't imply printing the location as many times as it is repeated (consider a very large array of structs with the semantic in a field).
I spent some time thinking about this, but I can't see a way that
wouldn't require storing all the reported locations. So, IMO, the additional complexity doesn't overweight the benefit. But if you think that it is important enough, I will do it. I don't think you need to do that. Rather, you just want to do it like a normal redefinition error: every time there's a definition which conflicts with an earlier definition, you "note" the first earlier definition that conflicts. I also don't see why you'd want to report the previous location more than once for an array?
I think I did a poor job at explaining the problem, consider this example:
```hlsl struct apple { float4 a[2] : REPEATED_OUTPUT; };
float4 main(out apple a[5], out float4 r : REPEATED_OUTPUT) : sv_target { // ... } ```
In that case we will iterate 5 times through the apple struct, and try to add the REPEATED_OUTPUT0 semantic var 5 times, and also REPEATED_OUTPUT1 5 times. For each, the first time we create the semantic var, the **second time** we have to report the error, indicating that the first time the location was the same as now, and the following 3 iterations we need to ignore the error. But we also have to report the error for the `r` parameter.
So the challenge here is knowing when we already have reported the specific error for a (semantic,index,location) trio.
It took me some time but in v3 I came up with an strategy that achieves this by including additional flags in the hlsl_semantic struct, for whether it is in an hlsl_ir_var or in a hlsl_struct_field), that keep track of the errors already reported.