www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8521] New: Internal error: e2ir.c 720 when a function uses a template which relies on that function and -release and -inline are used

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8521

           Summary: Internal error: e2ir.c 720 when a function uses a
                    template which relies on that function and -release
                    and -inline are used
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: jmdavisProg gmx.com



PDT ---

strideBack, and decode work with arbitrary ranges of code units, which is
needed for the D lexer for Phobos that I'm working on.

This is the reduced code:

import std.traits;

void main()
{
    auto tmp = "hello";
    size_t i = 0;
    decode(tmp, i);
}

template isRange(R)
{
    enum bool isRange = is(typeof(
    {
        R r = void;
        auto w = r.front;
    }));
}

 property dchar front(A)(A a)
{
    size_t i = 0;
    return decode(a, i);
}

dchar decode(S)(auto ref S str, ref size_t index)
{
    return decodeImpl(str, index);
}

private dchar decodeImpl(S)(auto ref S str, ref size_t index)
{
    enum canIndex = isRange!S;

    assert(0);
}


It compiles just fine normally, but when you compile with -release and -inline
together, it fails to compile, giving this error:

decodeImpl(S)
Internal error: e2ir.c 720

I think that the problem stems from the fact that isRange depends on decode,
which in turn depends on isRange, and something about the inlining process
screws it up. Moving the line with isRange from decodeImpl into decode makes
the problem going away as does removing front from inside of isRange. And using
decode inside of isRange makes it go away as well. So, it seems that the number
of levels of indirection has to be at at least a certain level before the
failure occurs.


don't compile with both -release and -inline, so clearly the code can work, but
something about -release and -inline screws it up.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 08 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8521


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|blocker                     |major



PDT ---
Okay. I was finally able to find a workaround by moving the test inside of
decodeImpl to outside of it, which is leaking its implementation details and
forcing a bool with the result of the test to be passed to an overload of
decodeImpl which doesn't need the test at all, but it does make it so that the
code works, and it doesn't affect the public API at all. So, I'm changing this
bug to major rather than blocker.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 08 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8521




Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/ad177d0cf124d5984e983d30fc481ca2b0f5d7ce


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8521


Rainer Schuetze <r.sagitario gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario gmx.de



PDT ---
I just hit this bug aswell, but your work-around does not seem to help. With
current head from github:

module test;
import std.utf;

dchar foo(string s)
{
    size_t pos;
    return decode(s, pos);
}


I get ICE with -inline:

m:\s\d\rainers\windows\bin\dmd -c test.d
m:\s\d\rainers\windows\bin\dmd -c -inline test.d
Statement::doInline() goto __returnLabel; Assertion failure: '0' on line 470 in file 'inline.c' abnormal program termination
m:\s\d\rainers\windows\bin\dmd -c -inline -release test.d
decodeImpl(bool canIndex,S) if (is(S : const(char[])) || isInputRange!(S) && is(Unqual!(ElementEncod ingType!(S)) == char)) Internal error: e2ir.c 720 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8521




PDT ---
Well, it helps in that the situation is improved enough that dmd's tests passed
(which wasn't the case before), but clearly, it doesn't fully get around the
problem. Bleh.

I guess that I'll have to take another whack at the workaround. It would be
_really_ nice if someone could fix this bug though.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8521




PDT ---
It seems that dmd is unable to generate code for the expression

    return str[index] < codeUnitLimit!S ? str[index++] : decodeImpl!true(str,
index);

This workaround compiled for me:

    if(str[index] < codeUnitLimit!S)
        return str[index++];
    return decodeImpl!true(str, index);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8521




Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/038e30c737370d7d0489be2e0e889f0f8f071fad


Apparently, using the ternary operator makes it worse, so I switched it
to use if instead. The semantics are identical.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 22 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8521


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
            Version|unspecified                 |D2
         Resolution|                            |WORKSFORME



18:10:31 PDT ---
These examples compile successfully with 2.064 head.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 03 2013