meson-plus-plus icon indicating copy to clipboard operation
meson-plus-plus copied to clipboard

implement set_variable and unset_variable

Open dcbaker opened this issue 1 year ago • 0 comments

set_variable

We have the problem that you can use set_variable to set a variable by a variable. consider:

foreach x : ['a', 'b', 'c', 'd']
  set_variable(x, 'foo')
endforeach

It's tempting to try to do early lowering on this, where we would early on rewrite set_variable('x', 'foo') to x = 'foo', but I highly doubt that's useful. that's a case where someone can just write x = 'foo', and not get into the weeds of set_variable. Even in the case above, it's rather simple to handle this via loop unrolling. The real concern I have, is that we may not always be aware of what x is, and thus have invalid global value numbering, and perhaps even have invalid optimization of the program. This is more complicated when the value is also a variable, such as set_variable(x, y)

unset_variable

This will require better tracking of variables declared in blocks, since the biggest side effect of this is that we need to make sure that versions of variables that are undefined don't propagate across block boundaries. That probably means that we should move variable version tracking to either the cfg node or the block

dcbaker avatar Nov 13 '24 17:11 dcbaker