[Issue 13228] Value range analysis for the length of slices

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Nov 11 13:22:41 PST 2014


https://issues.dlang.org/show_bug.cgi?id=13228

Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com

--- Comment #3 from Steven Schveighoffer <schveiguy at yahoo.com> ---
(In reply to bearophile_hugs from comment #0)
> I suggest to introduce in D a value range analysis and propagation for the
> length of slices, it should allow code like (currently refused):
> 
> 
> void foo(int[100]) {}
> ubyte x = 100;
> void main() {
>     const int[] a = new int[x];
>     foo(a);
> }
> 
> 
> That currently gives:
> 
> test.d(5,8): Error: function test.foo (int[100] _param_0) is not callable
> using argument types (const(int[]))

static this()
{
  x = 99;
}

oops...

> 
> 
> That is comparable to code like this (that is accepted by dmd 2.066beta5):
> 
> void foo(ubyte) {}
> ubyte x = 100;
> void main() {
>     const int a = x;
>     foo(a);
> }

This is not the same, because a's value isn't known at compile time, just its
range.

This ER is asking for flow analysis, which I think is not on the table. Be
mindful of what the compiler can know at compile time. Value range analysis for
expressions dies at the end of an expression.

--


More information about the Digitalmars-d-bugs mailing list