D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4504 - D1: ICE(toir.c) nested function passed by alias to nested member function
Summary: D1: ICE(toir.c) nested function passed by alias to nested member function
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 normal
Assignee: No Owner
URL:
Keywords: ice
: 4784 (view as issue list)
Depends on:
Blocks:
 
Reported: 2010-07-25 04:44 UTC by Peter Alexander
Modified: 2013-11-24 19:42 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Peter Alexander 2010-07-25 04:44:05 UTC
Compiling the following produces the error at compile time: "Internal error: toir.c 190"

import std.algorithm;
import std.range;

void main()
{
	int foo(int i) { return i == 1 ? 1 : foo(1); }
	auto x = count(map!foo(iota(1, 2)), 1);
}

Only happens when:
- foo is recursive
- foo is a local function (doesn't happen if it is global)
- when using count (calling the function alone, or just mapping is fine)
- when compiling with (-inline)

If any one of these conditions isn't met then the code compiles as expected.

Note that while I have only noticed that std.algorithm.count causes this problem, and std.algorithm.map doesn't, I haven't tested any other algorithms.

I'm using DMD 2.047.
Comment 1 bearophile_hugs 2010-07-25 04:49:55 UTC
On Windows, dmd 2.047, I don't see the error.
Comment 2 Peter Alexander 2010-07-25 04:52:25 UTC
(In reply to comment #1)
> On Windows, dmd 2.047, I don't see the error.

Interesting. Did you compile with -inline?
Comment 3 bearophile_hugs 2010-07-25 05:40:21 UTC
I'm using just basic compilation:
dmd test.d
Comment 4 Peter Alexander 2010-07-25 05:53:59 UTC
(In reply to comment #3)
> I'm using just basic compilation:
> dmd test.d

Well you won't get the error :P

"Only happens when:
...
- when compiling with (-inline)"
Comment 5 Don 2010-11-22 02:02:04 UTC
Reduced test case, from the duplicate bug 4784.
---

struct A( alias P ) {
    static void a() {
        void aa() { P(); }
    }
}

template B( alias P ) {
    void b() { A!P a; }
}

struct C( alias P ) {
    void c() { B!P.b(); }
}

void main() {
    void bar() {}
    C!bar c;
}
Comment 6 Don 2010-11-22 02:07:10 UTC
The reduced case shows it doesn't require -inline.
Comment 7 Don 2010-11-22 02:12:16 UTC
*** Issue 4784 has been marked as a duplicate of this issue. ***
Comment 8 Brad Roberts 2011-02-06 15:40:12 UTC
Mass migration of bugs marked as x86-64 to just x86.  The platform run on isn't what's relevant, it's if the app is a 32 or 64 bit app.
Comment 9 Don 2011-10-25 02:49:48 UTC
Reduced test case applies to D1 as well:

struct B4504(alias P)
{
    static void a() {
        void aa() {
            P();
        }
    }
}

void bug4504() {
    void bar() {}
    B4504!(bar) b;
}
Comment 10 bearophile_hugs 2012-01-26 04:54:36 UTC
Same bug?


import std.algorithm: map;
void foo() {
    map!(x => x)([1]);
}
void main() {
    int opApply(int delegate(ref int) dg) {
        int result;
        foo();
        result = dg(result);
        if (result)
            return result;
        return result;
    }
}
Comment 11 bearophile_hugs 2012-01-26 04:56:11 UTC
Same bug?


import std.algorithm: map;
void foo() {
    map!(x => x)([1]);
}
struct Bar {
    int opApply(int delegate(ref int) dg) {
        int result;
        foo();
        result = dg(result);
        if (result)
            return result;
        return result;
    }
}
void main() {}


DMD 2.058head:
test.d(6): Error: function test.Bar.opApply cannot get frame pointer to map
Comment 12 Walter Bright 2012-03-12 20:40:24 UTC
With 2.059, no error occurs for the original case.

The errors in the other cases are legitimate, and are different.
Comment 13 Don 2012-05-03 04:49:17 UTC
The ICE still happens on D1.074 and D1 git head.

Reopening and marking as D1 only.
Comment 14 Kenji Hara 2013-11-24 19:42:55 UTC
D1 is not supported anymore.