D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10317 - (2.063): Recursive error within Phobos
Summary: (2.063): Recursive error within Phobos
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-09 07:21 UTC by Andrej Mitrovic
Modified: 2017-07-02 16:24 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2013-06-09 07:21:42 UTC
-----
module test;

import std.algorithm;

struct Set(E)
{
    E[] sortedElements() inout
    {
        E[] elems = payload.keys;
        sort(elems);  // Causes error
        return elems;
    }

    int[E] payload;
}

enum E { a, b }

struct S
{
    Set!E e;
}

void main()
{
    S s;
}
-----

2.062:
$ dmd test.d

2.063
$ dmd test.d
C:\DMD\dmd2\windows\bin\..\..\src\phobos\std\format.d(2009): Error: template instance std.traits.CharTypeOf!(E) recursive expansion
Comment 1 Andrej Mitrovic 2013-06-09 17:31:33 UTC
Btw, when building with MSC the error never shows up, the compiler just spins the CPU forever. I guess this is a bug of its own.
Comment 2 Andrei Alexandrescu 2013-06-09 18:18:15 UTC
Simplified: 

import std.algorithm;

enum E { a, b }

void main()
{
    auto a = new E[100];
    sort(a);
}
Comment 3 Andrei Alexandrescu 2013-06-09 19:08:51 UTC
I looked into this, here's how far I got:

On https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d#L8130, "static if (is(typeof(text(r))))" is evaluated. That's what's causing the crash. The question is what's causing the bug. I don't know; instantiating typeof(text(r)) works properly in tests.
Comment 4 Andrej Mitrovic 2013-06-09 19:12:35 UTC
(In reply to comment #3)
> I looked into this, here's how far I got:
> 
> On
> https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d#L8130,
> "static if (is(typeof(text(r))))" is evaluated. That's what's causing the
> crash. The question is what's causing the bug. I don't know; instantiating
> typeof(text(r)) works properly in tests.

What I'm wondering: when does text(r) ever not work? Is there an actual test-case for this?
Comment 5 Andrei Alexandrescu 2013-06-09 19:14:03 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > I looked into this, here's how far I got:
> > 
> > On
> > https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d#L8130,
> > "static if (is(typeof(text(r))))" is evaluated. That's what's causing the
> > crash. The question is what's causing the bug. I don't know; instantiating
> > typeof(text(r)) works properly in tests.
> 
> What I'm wondering: when does text(r) ever not work? Is there an actual
> test-case for this?

Hmm, good point. I don't know. I think at this time we have a textual representation for everything.
Comment 6 Andrej Mitrovic 2013-06-09 19:43:52 UTC
(In reply to comment #5)
> Hmm, good point. I don't know. I think at this time we have a textual
> representation for everything.

Ok, I'll whip up a quick test and a phobos pull, so we can at least avoid blocking the .2 release.
Comment 7 Andrej Mitrovic 2013-06-09 19:47:10 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > Hmm, good point. I don't know. I think at this time we have a textual
> > representation for everything.
> 
> Ok, I'll whip up a quick test and a phobos pull, so we can at least avoid
> blocking the .2 release.

https://github.com/D-Programming-Language/phobos/pull/1343
Comment 8 github-bugzilla 2013-06-10 09:41:21 UTC
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/8f5f220194c313dad1cdc36db797ecbee78844d0
Fix Issue 10317 - Remove text(range) check and avoid recursive instantiation bug.

https://github.com/D-Programming-Language/phobos/commit/28189ff131e9003d1b0ed5a148f43d65f1823c87
Merge pull request #1343 from AndrejMitrovic/Fix10317

Issue 10317 - Remove text(range) check and avoid recursive instantiation bug.
Comment 9 Andrej Mitrovic 2013-06-10 11:35:58 UTC
The library fix is in place, but we still have to figure out why 2.062 doesn't exhibit the same behavior even though it has the same library code. So I'm downgrading this to a normal bug to avoid blocking the .2 release
Comment 10 Vladimir Panteleev 2017-07-02 16:24:27 UTC
(In reply to Andrej Mitrovic from comment #9)
> The library fix is in place, but we still have to figure out why 2.062
> doesn't exhibit the same behavior even though it has the same library code.
> So I'm downgrading this to a normal bug to avoid blocking the .2 release

As no reproducible test case has materialized in the past 4 years, closing.

FWIW, this regression was initially introduced in https://github.com/dlang/dmd/pull/1760.