Value Range Propigation Spec

Shammah Chancellor via Digitalmars-d digitalmars-d at puremagic.com
Thu Oct 23 08:29:29 PDT 2014


On 2014-10-22 20:32:35 +0000, Walter Bright said:

> On 10/22/2014 2:31 AM, Shammah Chancellor wrote:
>> A couple of us working on SDC are trying to get ValueRange propigation
>> implemented.   I was wonder if someone could offer some insight as to how VRP
>> works in DMD.   If for example, trying to get the value range of a global, what
>> is the expected behavior?
>> 
>> It seems as though VRP is a language feature, and not a compiler feature --
>> since this allows some code to compile and not others.   Is there a
>> specification for how it should work somewhere?  If not, it's hard to implement
>> other compilers that will not generate errors in the same circumstances as DMD.
>> 
> 
> VRP is definitely a language feature, not a compiler feature. The 
> specification is straightforward - a narrowing conversion can be 
> implicitly performed if it can be proved that it would not lose 
> information.
> 
> How it works, though, is kinda tricky, and the only guide to it is the 
> compiler source code.


Walter,

Several of us working on it were a little surprised that DMD does not 
compile this:

void main() {
	long l = 42;
	int i = l;
}

Is this expected to compile?  Planned?     My post was based on my 
thought that this *did* compile and we were wondering rules for when 
the range would be reset.   If `l` were __gshared for example, the 
range wouldn't be deterministic.

Surely there should be some rules document?  What we've implemented, is 
that the value range is calculated at float80 precision, and it's min 
and max can fit in the ultimate type for a cast, then it's good to go.  
We only look at the actual expression being implicitly cast.


Thanks,
-Shammah



More information about the Digitalmars-d mailing list