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

Reply via email to