Jump to page: 1 2
Thread overview
[Issue 14835] Constant folding should not affect front end flow analysis
[Issue 14835] Statement is not reachable doesn't play along generic code
Oct 12, 2015
Martin Nowak
Oct 13, 2015
Mathias LANG
Oct 24, 2015
Marc Schütz
May 09, 2016
Jack Stouffer
Aug 04, 2016
Les De Ridder
Oct 12, 2016
Walter Bright
Oct 18, 2016
anonymous4
Mar 28, 2021
Walter Bright
Mar 28, 2021
Dlang Bot
Mar 29, 2021
deadalnix
Dec 17, 2022
Iain Buclaw
Sep 21
Dlang Bot
Oct 01
Dlang Bot
October 12, 2015
https://issues.dlang.org/show_bug.cgi?id=14835

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@dawg.eu

--- Comment #1 from Martin Nowak <code@dawg.eu> ---
*** Issue 15166 has been marked as a duplicate of this issue. ***

--
October 13, 2015
https://issues.dlang.org/show_bug.cgi?id=14835

Steven Schveighoffer <schveiguy@yahoo.com> changed:

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

--- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> ---
Why can't the "hack" variable be eliminated by enclosing the rest of the function in the else branch?

And what about this solution for the group comparison (copied from my post in
Issue 15166):

private bool compare(alias Group1, alias Group2)()
{
    foreach (index, element; Group!(Group1.expand, void).expand)
    {
        static if(index == Group1.expand.length)
            return true;
        else static if (!is(Group1.expand[index] == Group2.expand[index]))
            return false;
    }
}

Neither requires recursion.

--
October 13, 2015
https://issues.dlang.org/show_bug.cgi?id=14835

--- Comment #3 from Mathias LANG <pro.mathias.lang@gmail.com> ---
Note that with this implementation you get an error (missing return) in 2.068.0, but 2.069.0-b1 fixed that.

But the point is not about the actual implementation, but the effect of this warning. It makes meta code much harder to write that it's needed, and way less natural. Will you accept a language where every `if` statement has to be followed by an `else` statement ?

--
October 13, 2015
https://issues.dlang.org/show_bug.cgi?id=14835

--- Comment #4 from Steven Schveighoffer <schveiguy@yahoo.com> ---
What the compiler is doing here is giving you information that code you wrote will not get executed.

The problem is that the code in question is only one *particular* execution (or instantiation) of that code.

To your example, isEven!1 will execute the line of code that is deemed to be unreachable.

The issue here is that the compiler can't "try all possibilities" to see if it will be able to find a path to that code (halting problem).

So probably we should turn off that feature when the code has taken a branch based on a template constant or a static if. The compiler should assume the other branch could be executed for a different instantiation, and so not complain for this one.

I don't think there's a "right" way to handle this. The error in question is truly a function of optimization and folding, but the user sees things in terms of lines of code. To say a line of code may not be executed if you call it one way is an error, even though it will be executed if you call it another way, doesn't make a lot of sense. If we are going to be "helpful", we should at least be accurate.

This is coming from someone who doesn't know how the compiler is implemented, or doesn't even know how compilers are implemented. So perhaps this is too difficult a task?

BTW, I was also saying that you *could* fix the problem without dummy variables or recursion, but I agree that the compiler is being unhelpful here.

--
October 24, 2015
https://issues.dlang.org/show_bug.cgi?id=14835

thomas.bockman@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thomas.bockman@gmail.com

--- Comment #5 from thomas.bockman@gmail.com ---
This issue will block for further improvements to constant folding and value range propagation, as better folding and VRP make it noticeably worse.

I found this out by adding VRP-based constant folding for integer comparisons,
and then trying to compile Phobos and vibe.d - see:
    https://github.com/D-Programming-Language/dmd/pull/5229

--
October 24, 2015
https://issues.dlang.org/show_bug.cgi?id=14835

--- Comment #6 from thomas.bockman@gmail.com ---
Here's a minimal compilable (requires dmd argument -wi, rather than -w) example, for anyone trying to fix this:

module main;

import std.stdio;

void reachIf(bool x)()
{
    if(!x)
        return;
    writeln("reached"); // Warning: statement is not reachable
}

void main(string[] args) {
    reachIf!true();  // prints "reached"
    reachIf!false(); // triggers warning
}

--
October 24, 2015
https://issues.dlang.org/show_bug.cgi?id=14835

Marc Schütz <schuetzm@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schuetzm@gmx.net

--
May 09, 2016
https://issues.dlang.org/show_bug.cgi?id=14835

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jack@jackstouffer.com
           Severity|normal                      |major

--- Comment #7 from Jack Stouffer <jack@jackstouffer.com> ---
This has come up again: https://github.com/dlang/phobos/pull/4287

This issue is a major annoyance when writing template code and almost anyone writing optimized code with static if's will run into it eventually, so I'm raising the importance of this.

--
June 24, 2016
https://issues.dlang.org/show_bug.cgi?id=14835

Steven Schveighoffer <schveiguy@yahoo.com> changed:

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

--
August 04, 2016
https://issues.dlang.org/show_bug.cgi?id=14835

Les De Ridder <dlang@lesderid.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dlang@lesderid.net

--
« First   ‹ Prev
1 2