Value Range Propigation Spec
bearophile via Digitalmars-d
digitalmars-d at puremagic.com
Thu Oct 23 08:39:54 PDT 2014
Shammah Chancellor:
> 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?
Currently this doesn't compile, and it's expected to not compile.
Currently VRP works only inside one expression (I guess to keep
low the compiler complexity). So the value range of l is lost
when it's assigned to i.
Very recently VRP was improved and now the value range of
immutable values is kept.
I don't know if there are plans to improve the VRP. I hope to see
some improvements, like:
void foo(in uint x)
in {
assert(x < 10_000);
} body {
ushort y = x;
if (x < 100) {
ubyte z = x;
}
}
Another example:
uint bar()
out(result) {
assert(result < 100);
} body {
return 99;
}
void spam(in ubyte x) {}
void main() {
spam(bar());
}
Other improvements are possible, and very useful. I have some
more enhancement requests in Bugzilla.
Bye,
bearophile
More information about the Digitalmars-d
mailing list