www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8847] New: voldemort + inout confuses "is"

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

           Summary: voldemort + inout confuses "is"
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com


--- Comment #0 from monarchdodra gmail.com 2012-10-18 02:13:05 PDT ---
I discovered this inside phobos. First reduced test case:

//----
import std.stdio;
import std.range;
import std.conv;

void main()
{
    auto a = iota(1, 2);
    auto b = a[];
    alias typeof(a) A;
    alias typeof(b) B;
    writeln("Typeof A: ", A.stringof);
    writeln("Typeof B: ", B.stringof);
    assert(is(A == B), text(A.stringof, " is different from " , B.stringof));
}
//----
Typeof A: Result
Typeof B: Result
core.exception.AssertError main.d(13): Result is different from Result
//----

Which is very strange. I found the root condition that recreates this: It is
having a voldemort function that is qualified with inout:

//----
import std.stdio;
import std.conv;

auto S()
{
    static struct Result
    {
      inout(Result) get() inout {return this;}
    }
    return Result();
}

void main()
{
    auto a = S();
    auto b = a.get();
    alias typeof(a) A;
    alias typeof(b) B;
    writeln("Typeof A: ", A.stringof);
    writeln("Typeof B: ", B.stringof);
    assert(is(A == B), text(A.stringof, " is different from " , B.stringof));
}
//----
Typeof A: Result
Typeof B: Result
core.exception.AssertError main.d(21): Result is different from Result
//----

I'm marking this as major, because it is currently showing up in Phobos:
I wrote a fix for emplace, to bypass opAssign (which it should *not* be
calling), and it turns out there is an emplace that fails to build a
zip.opSlice because of this:

Pull: https://github.com/D-Programming-Language/phobos/pull/837
D2: http://d.puremagic.com/test-results/pull-history.ghtml?repoid=3&pullid=837

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



--- Comment #1 from monarchdodra gmail.com 2012-10-18 02:19:29 PDT ---
(In reply to comment #0)
 Which is very strange. I found the root condition that recreates this: It is
 having a voldemort function that is qualified with inout:
 
 //----
 import std.stdio;
 import std.conv;
 
 auto S()
 {
     static struct Result
     {
       inout(Result) get() inout {return this;}
     }
     return Result();
 }
 
 void main()
 {
     auto a = S();
     auto b = a.get();
     alias typeof(a) A;
     alias typeof(b) B;
     writeln("Typeof A: ", A.stringof);
     writeln("Typeof B: ", B.stringof);
     assert(is(A == B), text(A.stringof, " is different from " , B.stringof));
 }
 //----
 Typeof A: Result
 Typeof B: Result
 core.exception.AssertError main.d(21): Result is different from Result
 //----

Yeah, I forgot to mention, if you remove the "inout" attribute, or if you make Result a global struct, the problem disappears, so it *really* only ever appears when inout and voldemort are combined. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8847


klickverbot <code klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code klickverbot.at


--- Comment #2 from klickverbot <code klickverbot.at> 2012-10-18 02:29:59 PDT
---
This is probably the same issue I hit when merging the 2.060 frontend into LDC
a while ago. The issue is that the same type can end up with two different
mangled names, which causes two different TypeInfo instances to be emitted.

The test case from
https://github.com/ldc-developers/ldc/blob/master/gen/tocall.cpp#L677:

---
auto iota() {
    static struct Result {
        this(int) {}
        inout(Result) test() inout { return cast(inout)Result(0); }
    }
    return Result.init;
}
void main() { auto r = iota(); }
---

I'm not sure what the correct fix is here – Walter? Kenji?

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



--- Comment #3 from monarchdodra gmail.com 2012-10-28 04:01:55 PDT ---
(In reply to comment #2)
 This is probably the same issue I hit when merging the 2.060 frontend into LDC
 a while ago. The issue is that the same type can end up with two different
 mangled names, which causes two different TypeInfo instances to be emitted.
 
 [SNIP]
 
 I'm not sure what the correct fix is here – Walter? Kenji?

Any news? Do you have any idea about the *cost* of fixing this? If there is a fix possible, then I'll wait for it (No problem waiting whatsoever). But if not, then I'll go for bypass, just want to know which direction I should take this... Thanks. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 28 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8847



--- Comment #4 from monarchdodra gmail.com 2012-11-30 02:35:04 PST ---
(In reply to comment #3)
 
 Any news?

I wanted to add that https://github.com/D-Programming-Language/phobos/pull/982 Is also subject to this issue. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 30 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8847


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com
           Severity|major                       |blocker


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



--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2012-11-30 23:46:35 PST ---
This is a serious problem about the name mangling rule for Voldemort Type.

At least there is two rules.
1. Mangled name of a function symbol contains the mangled name of its return
type.
2. A nested declaration's mangled name contains its enclosing mangled name.
---
module test;
pragma(msg, "1f: ", foo.mangleof);
// _D4test3fooFZAi
// --> _D [ 4test 3foo / [ FZ / Ai ] ]   ...#1(Ai == int[])
int[] foo() {
  struct S { int value; }
  pragma(msg, "1i: ", S.mangleof);
  // S4test3fooFZAi1S
  // --> S [ 4test 3foo / [ FZ / Ai ] ] 1S   ...#2
  return null;
}
---

But, Voldemort Types cannot be mangled based on the rules.
Because, a nested struct requires enclosing function's mangling,
but the function requires return type's mangling. It's circular dependency.

In current, that is *accidentally* working.
---
auto bar() {
  struct S { int value; }
  pragma(msg, "2i: ", S.mangleof);
  // S4test3bar1S
  // --> S [ 4test 3bar / [ / ] ] 1S
  // ...incorrect
  return S(1);
}
pragma(msg, "2f: ", bar.mangleof);
// _D4test3barFZS4test3bar1S
// --> _D [ 4test 3bar / [ FZ / S4test3bar1S ] ]
// ...incorrect
---

And, inout type deduction on function call shoots the rule inconsistency.
---
auto baz(inout int = 0) {
  struct S { int value; }
  pragma(msg, "3i: ", S.mangleof);   // S inside bar
  // S4test3baz1S
  // --> S [ 4test 3baz / [ / ] ] 1S   ...(A)
  return inout(S)(1);
}
pragma(msg, "3f: ", baz.mangleof);
// _D4test3bazFNgiZNgS4test3baz1S
// --> _D [ 4test 3baz / [ FNgiZ / Ng S4test3baz1S ] ]

pragma(msg, "3o: ", typeof(baz(0)).mangleof);   // S outside bar
// S4test3bazFNgiZNgS4test3baz1S1S
// --> S [ 4test 3baz / [ FNgiZNg / S4test3baz1S ] ] 1S   ...(B)
---

Compare:
A. --> S [ 4test 3baz / [         /              ] ] 1S
B. --> S [ 4test 3baz / [ FNgiZNg / S4test3baz1S ] ] 1S

Mismatching between A and B is the root cause of this issue.

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



--- Comment #6 from github-bugzilla puremagic.com 2012-12-17 21:38:47 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/6022082b29f670095fb082102420c7b331cb7d14
Further strengthen hasSlicing.

The extra requirements are not currently enabled because of bug# 8847,
but they're now there, and they're listed as their in the documentation
so that no one will think that they're not supposed to apply.

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


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #7 from Kenji Hara <k.hara.pg gmail.com> 2012-12-17 22:54:17 PST ---
https://github.com/D-Programming-Language/dmd/pull/1381

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



--- Comment #8 from github-bugzilla puremagic.com 2013-02-03 09:40:26 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/1116d6bab4aefad92ff94205a25b82cc51d06237
fix Issue 8847 - voldemort + inout confuses "is"

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 03 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8847


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |FIXED


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