Thread overview
[Bug 140] Inlining certain trivial function fails
Jul 12, 2014
Johannes Pfau
Jul 12, 2014
Johannes Pfau
Jul 21, 2014
Iain Buclaw
July 12, 2014
http://bugzilla.gdcproject.org/show_bug.cgi?id=140

Johannes Pfau <johannespfau@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johannespfau@gmail.com

--- Comment #1 from Johannes Pfau <johannespfau@gmail.com> ---
Try to add @attribute("forceinline") to the failing function (you might have to copy std.algorith to some other file, name it xtd.algorithm or something), then compiling should fail with some error message and you can use dustmite to reduce the test case.

-- 
You are receiving this mail because:
You are watching all bug changes.


July 12, 2014
http://bugzilla.gdcproject.org/show_bug.cgi?id=140

art.08.09@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |art.08.09@gmail.com

--- Comment #2 from art.08.09@gmail.com ---
(In reply to Johannes Pfau from comment #1)
> Try to add @attribute("forceinline") to the failing function (you might have to copy std.algorith to some other file, name it xtd.algorithm or something), then compiling should fail with some error message and you can use dustmite to reduce the test case.

Well, that results in basically the same testcase and a stripped-down std.array with just the necessary primitives.

But after adding the always_inline attribute I at least got a little more informative diagnostic:

std/algorithm.d: In member function 'pure nothrow @property @safe bool
xstd.algorithm.__T12FilterResultS633std10functional36__T8unaryFunVAyaa8_612e6c656e677468Z8unaryFunTAAyaZ.FilterResult.empty()':
std/array.d:408: error: inlining failed in call to always_inline 'pure nothrow
@property @safe bool
xstd.array.empty!(immutable(char)[]).empty(const(immutable(char)[][]))':
mismatched arguments
std/algorithm.d:1449: error: called from here


If I call std.array.empty /directly/ then there is no problem and `empty` is properly inlined. The problem appears only when calling it via eg std.algorithm.FilterResult.empty...

-- 
You are receiving this mail because:
You are watching all bug changes.


July 12, 2014
http://bugzilla.gdcproject.org/show_bug.cgi?id=140

--- Comment #3 from Johannes Pfau <johannespfau@gmail.com> ---
Reduced:

test.d
----------------------------------------------------
import xtd.array;

int main()
{
    void[] a = [];
    return (FilterResult!(void[])(a)).empty;
}

struct FilterResult(Range)
{
    Range _input;

    @property empty() { return xtd.array.empty(_input); }
}
----------------------------------------------------

xtd/array.d
----------------------------------------------------
import gcc.attribute;

@attribute("forceinline") @property empty(T)(in T[] a)
{
    return !a.length;
}
----------------------------------------------------

gdc test.d -finline
----------------------------------------------------
test.d: In member function 'empty':
xtd/array.d:3: error: inlining failed in call to always_inline 'empty':
mismatched arguments
test.d:14: error: called from here
----------------------------------------------------


Merging array.d/test.d leads to a different error:
test.d
----------------------------------------------------
import gcc.attribute;

@attribute("forceinline") @property empty2(T)(in T[] a)
{
    return !a.length;
}


int main()
{
    void[] a = [];
    return (FilterResult!(void[])(a)).empty;
}

struct FilterResult(Range)
{
    Range _input;

    @property empty() { return empty2(_input); }
}
----------------------------------------------------

gdc test.d -finline
----------------------------------------------------
cc1d: /build/gdc/src/gcc-4.9.0/gcc/d/dfrontend/interpret.c:676: void
FuncDeclaration::ctfeCompile(): Assertion `semanticRun == PASSsemantic3done'
failed.
test.d: In member function 'empty':
test.d:18: internal compiler error: Aborted
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.
----------------------------------------------------

This error vanishes if the forceinline attribute is removed.

-- 
You are receiving this mail because:
You are watching all bug changes.


July 21, 2014
http://bugzilla.gdcproject.org/show_bug.cgi?id=140

--- Comment #4 from Iain Buclaw <ibuclaw@gdcproject.org> ---
The ICE has been fixed in: https://github.com/D-Programming-GDC/GDC/commit/db6e514f7a5fef192bd70dc2ed4aa80a7eeac1fe

-- 
You are receiving this mail because:
You are watching all bug changes.