Jump to page: 1 2
Thread overview
[Issue 14931] switch doesn't work with any pointers
Aug 18, 2015
Sobirari Muhomori
Aug 18, 2015
Sobirari Muhomori
Aug 18, 2015
Sobirari Muhomori
Aug 18, 2015
yebblies
Aug 19, 2015
yebblies
Aug 19, 2015
ZombineDev
Aug 19, 2015
yebblies
Aug 19, 2015
Walter Bright
Aug 19, 2015
yebblies
Aug 19, 2015
Sobirari Muhomori
Aug 19, 2015
ZombineDev
Aug 20, 2015
yebblies
Dec 17, 2022
Iain Buclaw
August 18, 2015
https://issues.dlang.org/show_bug.cgi?id=14931

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|switch doesn't work with    |switch doesn't work with
                   |pointers to functions. Also |any pointers
                   |casting pointers to         |
                   |functions to integers       |
                   |doesn't work during         |
                   |compilation.                |

--
August 18, 2015
https://issues.dlang.org/show_bug.cgi?id=14931

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86                         |All
                 OS|Mac OS X                    |All

--- Comment #1 from Andrei Alexandrescu <andrei@erdani.com> ---
Consider:

void fun(T)() {}
alias Ptr = void function() pure nothrow @nogc @safe;

void main(string[] argv) {
    enum a = &fun!int;
    static immutable Ptr b = &fun!double;
    static assert(a != b);

    Ptr p;
    switch (p)
    {
        case a: break;
        case b: break;
    }
}

The first three lines in main() clarify that pointers to functions can be evaluated and compared during compilation. Yet the switch statement does not work.

This applies to general pointers - switch does not work with any pointers, yet it should work because pointers are comparable and there exist constant pointers.

--
August 18, 2015
https://issues.dlang.org/show_bug.cgi?id=14931

Sobirari Muhomori <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=5862

--
August 18, 2015
https://issues.dlang.org/show_bug.cgi?id=14931

Sobirari Muhomori <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=6176

--
August 18, 2015
https://issues.dlang.org/show_bug.cgi?id=14931

Sobirari Muhomori <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://forum.dlang.org/post
                   |                            |/mqvbcl$1k2q$2@digitalmars.
                   |                            |com

--- Comment #2 from Sobirari Muhomori <dfj1esp02@sneakemail.com> ---
As I understand from the discussion, the idea is to not only compile it, but to generate a jump table for such switch statement instead of being a syntax sugar for if-else chain?

--
August 18, 2015
https://issues.dlang.org/show_bug.cgi?id=14931

--- Comment #3 from Andrei Alexandrescu <andrei@erdani.com> ---
Yah, accept it and subject it to the usual assumptions and optimizations that go for equivalent integral-based switch statements.

--
August 18, 2015
https://issues.dlang.org/show_bug.cgi?id=14931

yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com

--- Comment #4 from yebblies <yebblies@gmail.com> ---
(In reply to Andrei Alexandrescu from comment #3)
> Yah, accept it and subject it to the usual assumptions and optimizations that go for equivalent integral-based switch statements.

There is no guarantee that integral switches get turned into jump tables.

--
August 19, 2015
https://issues.dlang.org/show_bug.cgi?id=14931

--- Comment #5 from Andrei Alexandrescu <andrei@erdani.com> ---
(In reply to yebblies from comment #4)
> (In reply to Andrei Alexandrescu from comment #3)
> > Yah, accept it and subject it to the usual assumptions and optimizations that go for equivalent integral-based switch statements.
> 
> There is no guarantee that integral switches get turned into jump tables.

Understood, thanks. Just handle them the same is all.

--
August 19, 2015
https://issues.dlang.org/show_bug.cgi?id=14931

--- Comment #6 from yebblies <yebblies@gmail.com> ---
(In reply to Andrei Alexandrescu from comment #5)
> (In reply to yebblies from comment #4)
> > (In reply to Andrei Alexandrescu from comment #3)
> > > Yah, accept it and subject it to the usual assumptions and optimizations that go for equivalent integral-based switch statements.
> > 
> > There is no guarantee that integral switches get turned into jump tables.
> 
> Understood, thanks. Just handle them the same is all.

We should be able to support pointer switch, but we can't do pointer switch jump tables since the pointer's integer representation isn't known until link time.

--
August 19, 2015
https://issues.dlang.org/show_bug.cgi?id=14931

ZombineDev <petar.p.kirov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |petar.p.kirov@gmail.com

--- Comment #7 from ZombineDev <petar.p.kirov@gmail.com> ---
Is it possible to generate a jump table with placeholders and fill them at link time?

--
« First   ‹ Prev
1 2