3 ms·
> 'Telling whether i will be accessed before being assigned' is equivalent to the halting problem. This is true. However, figuring out the most efficient progr
by TheLoneWolfling 12y ago
> 'Telling whether i will be accessed before being assigned' is equivalent to the halting problem.
This is true. However, figuring out the most efficient program that's equivalent to a given program also suffers from the halting problem, and that's literally the definition of the goal of an optimizer.
So no: in general you cannot prove if an arbitrary variable will be accessed. However, you can, and will, take a conservative approach and narrow it down as much as possible.
In other words, if you can prove that it will be accessed before being assigned, great. If you can prove that it won't be accessed before being assigned, great. If you can't prove either... Meh, you have to include a redundant store.
It's exactly the same way that optimizers work to, for example, remove redundant stores to a variable. Because it is.
Except that, if you read carefully, what I proposed wasn't quite the same thing.
I'm proposing a language where a read from an uninitialized variable must be consistent with the uninitialized variable having been set to an arbitrary value (in range) before the first read from it. So compiling the static code {int x; return x;} into {return 0;} is perfectly allowed, as is compiling it into {return 42;}.