"Meta"  wrote in message news:pogogtdjyetukenny...@forum.dlang.org...

I've always wondered if VRP can be leveraged in certain situations. I can't remember exactly how it's supposed to work, but very basically, isn't it just numeric variables (and expressions?) having an associated range that they carry around with them at compile time, so something like this is possible:

long n1 = long.max;
int n2 = n1 % 3; //No cast needed due to VRP

Couldn't this be used for other things as well, such as detecting numeric overflow at compile time, or like Nordlow suggested, figuring out when it's safe to elide an array bounds check?

It can, and it already is. The problem is that n1 above is not guaranteed to _stay_ equal to long.max. Without data flow analysis the compiler doesn't know that it is never re-assigned, so the possible range is any value that fits in a long.

There are cases where it should be able to tell without data flow analysis but are currently not implemented.

Reply via email to