On 5/31/14, 6:47 PM, Meta wrote:
On Saturday, 31 May 2014 at 23:30:41 UTC, Walter Bright wrote:
There isn't a suitable place. To make it work, data flow analysis
would have to be added to the front end. While doable, this is not a
simple addition. Eventually, we'll have to do it as a lot of things
become possible & better with data flow analysis, not just bounds
check elimination.

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?

For $/n VRP can't be used because it's geared toward constants, not relative to variables. So VRP could inform of something like "this number is between 0 and 5", not "this number is between 0 and a.length". -- Andrei

Reply via email to