Unreachable warning is annoying
Steven Schveighoffer
schveiguy at yahoo.com
Thu Mar 15 23:27:33 UTC 2018
On 3/13/18 3:21 PM, Timon Gehr wrote:
> On 13.03.2018 18:43, H. S. Teoh wrote:
>> On Tue, Mar 13, 2018 at 01:32:55PM -0400, Steven Schveighoffer via
>> Digitalmars-d wrote:
>> [...]
>>> An unrolled foreach on a tuple has a notion that the flow control
>>> jumps out of the loop, and it's OK to skip further loops (even though
>>> they are technically unrolled).
>> [...]
>>
>> This is not true. Foreach on a tuple does *not* skip expanding all
>> iterations of the loop regardless of any `break`s or `continue`s. It's
>> the codegen that eliminates the resulting dead code. See:
>>
>> https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time#Case_Study:_foreach_over_a_type_list
>>
>>
>>
>> T
>>
>
> I think that's what he was saying. :)
Note, I replied with the following text, but for some reason the forum
does NOT see this post. It should be here:
https://forum.dlang.org/post/p8990d$2ona$1@digitalmars.com
And it does exist on the NNTP server.
Anyway, here's what I said:
Yes. In fact, when you use the ever-so-handy -vcg-ast switch, it shows this:
staticFind!(int, int, double)
{
pure nothrow @nogc @safe int staticFind()
{
/*unrolled*/ {
{
enum ulong id = 0LU;
alias R = int;
return 0;
}
{
enum ulong id = 1LU;
alias R = double;
return -1;
}
}
}
}
If I compile that directly, I get the unreachable warning. Obviously
there is something hidden in the actual AST that says "it's ok this
statement isn't reached, because it's really skipped by returning out of
the foreach".
If I use static foreach, it has the warning, and I'm assuming this is
because static foreach is a straight loop unrolling, whereas foreach on
a tuple has some semblance of flow control with the loop itself.
Note: I don't have any idea how this really works internally, I'm
guessing at the black box behavior
-Steve
More information about the Digitalmars-d
mailing list