www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10012] New: [2.063 beta] pure constructors taking POD structs should be allowed for shared/immutable construction

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

           Summary: [2.063 beta] pure constructors taking POD structs
                    should be allowed for shared/immutable construction
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: sludwig outerproduct.org


--- Comment #0 from Sönke Ludwig <sludwig outerproduct.org> 2013-04-30 02:04:08
PDT ---
The following snippet errors out:

---
struct S { }
class Test2 { this(S) pure {} }

void main()
{
    auto test2 = new shared Test2(S());
    auto test3 = new immutable Test2/(S());
}
---

test_shared.d(7): Error: mutable method test_shared.Test2.this is not callable
u
sing a immutable object
test_shared.d(7): Error: incompatible types for ((new immutable(Test2)) /
(S()))
: 'immutable(Test2)' and 'S'

However, since any instance of S is an independent copy, the resulting object
is still unique and thus should be liable for immutable or shared object
construction. Also, in addition to POD types, types containing only immutable
references should be allowed.

Finally, shared references can also be allowed when constructing a shared
object, but this is a different kind of "unique" or "isolated" concept - I call
it "weakly isolated" in my library implementation [1] following the "weakly
pure" nomenclature - so this may need some bigger changes.

[1]
https://github.com/rejectedsoftware/vibe.d/blob/6c9efa2fdcef1797c84e58483410f262a2a82d67/source/vibe/core/concurrency.d#L958

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



--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2013-04-30 02:13:44 PDT ---
(In reply to comment #0)
     auto test3 = new immutable Test2 / (S());   // unnecessary '/'
auto test3 = new immutable Test2(S()); After the fix, the code would work. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10012



--- Comment #2 from Sönke Ludwig <sludwig outerproduct.org> 2013-04-30 02:24:01
PDT ---
Sorry, I was blind while preparing the test case. This is the correct one:

---
struct S { string str; }
class Test { S _s; this(S s) pure { _s = s; } }

void main()
{
    auto test2 = new shared Test(S());
    auto test3 = new immutable Test(S());
}
---

So POD indeed works right, but immutable (and shared) references are seemingly
disallowed.

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2013-05-04 00:43:03 PDT ---
(In reply to comment #2)
 Sorry, I was blind while preparing the test case. This is the correct one:
 
 ---
 struct S { string str; }
 class Test { S _s; this(S s) pure { _s = s; } }
 
 void main()
 {
     auto test2 = new shared Test(S());
     auto test3 = new immutable Test(S());
 }
 ---
 
 So POD indeed works right, but immutable (and shared) references are seemingly
 disallowed.
This is current dmd implementation limitation. In complex cases dmd cannot detect that the constructor generates unique object. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 04 2013