Thread overview
[Issue 15064] [CTFE] AliasSeq in multi-level alias this fails in CTFE
[Issue 15064] [CTFE] std.range.enumerate is not CTFE-able
Sep 15, 2015
Jack Stouffer
Sep 16, 2015
Kenji Hara
Sep 16, 2015
Jack Stouffer
Sep 16, 2015
Kenji Hara
Nov 21, 2016
Paolo Invernizzi
Sep 18, 2017
b2.temp@gmx.com
Sep 18, 2017
Simen Kjaeraas
Mar 21, 2020
Basile-z
September 15, 2015
https://issues.dlang.org/show_bug.cgi?id=15064

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |CTFE
           Priority|P1                          |P3

--
September 16, 2015
https://issues.dlang.org/show_bug.cgi?id=15064

--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> ---
Please add a test case, at least.

--
September 16, 2015
https://issues.dlang.org/show_bug.cgi?id=15064

--- Comment #2 from Jack Stouffer <jack@jackstouffer.com> ---
Sorry

int test()
{
    import std.range : enumerate;

    int[] a = [1];

    foreach (i, e; a.enumerate) {}

    return 0;
}

void main()
{
    enum res = test(); // fails
    int res = test(); // works fine
}

--
September 16, 2015
https://issues.dlang.org/show_bug.cgi?id=15064

--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> ---
Thanks.

--
November 21, 2016
https://issues.dlang.org/show_bug.cgi?id=15064

Paolo Invernizzi <paolo.invernizzi@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |paolo.invernizzi@gmail.com

--
September 18, 2017
https://issues.dlang.org/show_bug.cgi?id=15064

b2.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp@gmx.com

--- Comment #4 from b2.temp@gmx.com ---
Remove the field names of the Tuple used in enumerate and it works i.e change the definition

"alias ElemType = Tuple!(Enumerator, "index", ElementType!Range, "value");"

to

"alias ElemType = Tuple!(Enumerator, ElementType!Range);"

(+ fix the unittests that use the field name by using indexers as postfix)

and it works, although No idea why. This is just a clue, not a fix. Removing the field names would break code.

--
September 18, 2017
https://issues.dlang.org/show_bug.cgi?id=15064

Simen Kjaeraas <simen.kjaras@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simen.kjaras@gmail.com
          Component|phobos                      |dmd
            Summary|[CTFE] std.range.enumerate  |[CTFE] AliasSeq in
                   |is not CTFE-able            |multi-level alias this
                   |                            |fails in CTFE
           Severity|enhancement                 |normal

--- Comment #5 from Simen Kjaeraas <simen.kjaras@gmail.com> ---
Reduced test case:

import std.meta : AliasSeq;

struct Super {
    AliasSeq!(int, int) expand;
    alias expand this;
}

struct Tuple {
    Super inner;
    alias inner this;
}

struct Range {
    Tuple front;
    void popFront() {}
    bool empty = true;
}

int test1() {
    import std.algorithm : map;
    foreach (i, e; Range.init) {} // Fails
    foreach (i, e; [Tuple.init].map!(a=>a)) {} // Fails
    foreach (i, e; [Tuple.init]) {} // Works [line 23]
    return 3;
}

enum s1 = test1();

And even more reduced, I think:

struct Super2 {
    AliasSeq!int expand;
    alias expand this;
}

struct Tuple2 {
    Super2 inner;
    alias inner this;
}

int test2() {
    AliasSeq!int a = Tuple2.init; // Fails with same message
    int b = Tuple2.init[0]; // Works [line 41]

    return 3;
}

enum s2 = test2();

Since test2 gives the same error message, and the same kind of unpacking will happen in both cases, I assume that's the root problem.

So in summary: If an AliasSeq is used in alias this inside another alias this, some context goes missing in CTFE, possibly only during tuple assignment (see line 41). Strangely, it seems to work when the unpacking comes from an array instead of a range (line 23). Not sure why that is, but it seems tangential to the real problem here.

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=15064

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--
December 13
https://issues.dlang.org/show_bug.cgi?id=15064

--- Comment #6 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19043

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--