Thread overview
[Issue 2474] New: Recursive lazy arguments are inlined incorrectly
Nov 27, 2008
d-bugmail
Nov 27, 2008
d-bugmail
Nov 27, 2008
d-bugmail
Jan 11, 2009
d-bugmail
Sep 14, 2010
Don
November 27, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2474

           Summary: Recursive lazy arguments are inlined incorrectly
           Product: D
           Version: 2.021
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: snake.scaly@gmail.com


This code:

--8<-----------
int foo(lazy int x)
{
  int bar()
  {
    return foo(bar());
  }
  return bar();
}
--8<-----------

produces the following output when compiled:

> dmd inlinebug.d -c -inline
inlinebug.d(5): delegate inlinebug.foo.bar.__dgliteral1 is a nested function and cannot be accessed from foo

Without the -inline flag this code compiles and works as expected.

The same bug is present in DMD 1.037.


-- 

November 27, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2474


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
            Version|2.021                       |1.036




------- Comment #1 from smjg@iname.com  2008-11-27 09:42 -------
>> dmd inlinebug.d -c -inline
> inlinebug.d(5): delegate inlinebug.foo.bar.__dgliteral1 is a nested function and cannot be accessed from foo

Presumably, inlining changes

    return bar();

to

    return foo(bar());

after which it tries to TRO the foo call, but gets mixed up as it relies on the nested function bar.

I'm not sure if the compiler is actually within its rights to complain about this, as it's bad code even though not technically illegal.  And if such bad code interferes with optimisation, should the compiler error or just not bother with the optimisation?

> Without the -inline flag this code compiles and works as expected.

As in throws a stack overflow?

> The same bug is present in DMD 1.037.

And 1.036 and 2.020.  AIUI if the same bug occurs in both D1 and D2, it is preferred to file it under the D1 version.


-- 

November 27, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2474





------- Comment #2 from snake.scaly@gmail.com  2008-11-27 10:51 -------
> I'm not sure if the compiler is actually within its rights to complain about this, as it's bad code even though not technically illegal...
> 
> > Without the -inline flag this code compiles and works as expected.
> 
> As in throws a stack overflow?

This is a reduced version of Knuth's "Man or Boy" test:

--8<----------------
import std.stdio;

int a(int k, lazy int x1, lazy int x2, lazy int x3, lazy int x4, lazy int x5)
{
  int b()
  {
    k--;
    return a(k, b(), x1, x2, x3, x4);
  }
  return k <= 0 ? x4 + x5 : b();
}

void main()
{
  writefln(a(10, 1, -1, -1, 1, 0));
}
--8<----------------

>dmd manorboy.d

>manorboy
-67

>dmd -inline manorboy.d
manorboy.d(8): delegate manorboy.a.b.__dgliteral1 is a nested function and
cannot be accessed from a
manorboy.d(8): delegate manorboy.a.b.__dgliteral2 is a nested function and
cannot be accessed from a
manorboy.d(8): delegate manorboy.a.b.__dgliteral3 is a nested function and
cannot be accessed from a
manorboy.d(8): delegate manorboy.a.b.__dgliteral4 is a nested function and
cannot be accessed from a
manorboy.d(8): delegate manorboy.a.b.__dgliteral5 is a nested function and
cannot be accessed from a

See also the issue 2475, it's the same.


-- 

January 11, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2474


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com




------- Comment #3 from smjg@iname.com  2009-01-11 16:47 -------
*** Bug 2475 has been marked as a duplicate of this bug. ***


-- 

September 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2474


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fawzi@gmx.ch


--- Comment #4 from Don <clugdbug@yahoo.com.au> 2010-09-13 23:55:41 PDT ---
*** Issue 3244 has been marked as a duplicate of this issue. ***

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