www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12315] New: std.array.array at compile-time too

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

           Summary: std.array.array at compile-time too
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2014-03-08 07:02:11 PST ---
import std.array: array;
struct Foo1 {
    int i;
}
struct Foo2 {
    immutable int i;
}
void main() {
    enum r1 = [Foo1(1)].array; // OK
    enum r2 = [Foo2(1)].array; // Error
}


dmd 2.066alpha gives:

...\dmd2\src\phobos\std\conv.d(3908,23): Error: memcpy cannot be interpreted at
compile time, because it has no available source code
...\dmd2\src\phobos\std\array.d(45,23):        called from here:
emplaceRef(result[i], e)
temp.d(10,24):        called from here: array([Foo2(1)])

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 08 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12315


Peter Alexander <peter.alexander.au gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |CTFE
                 CC|                            |peter.alexander.au gmail.co
                   |                            |m
          Component|Phobos                      |DMD


--- Comment #1 from Peter Alexander <peter.alexander.au gmail.com> 2014-03-09
05:00:05 PDT ---
Changing this to dmd CTFE bug. I can't think of any way to solve it in Phobos
without more compiler support.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 09 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12315



--- Comment #2 from bearophile_hugs eml.cc 2014-03-09 05:26:20 PDT ---
(In reply to comment #1)
 Changing this to dmd CTFE bug. I can't think of any way to solve it in Phobos
 without more compiler support.

This seems to work: import std.traits: ForeachType; ForeachType!R[] myArray(R)(R r) { if (__ctfe) { typeof(return) result; foreach (item; r) result ~= r; return result; } else { // ... assert(0); } } struct Foo1 { int i; } struct Foo2 { immutable int i; } void main() { enum r1 = [Foo1(1)].myArray; // OK enum r2 = [Foo2(1)].myArray; // OK } -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 09 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12315


Peter Alexander <peter.alexander.au gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|DMD                         |Phobos


--- Comment #3 from Peter Alexander <peter.alexander.au gmail.com> 2014-03-09
06:46:00 PDT ---
(In reply to comment #2)
 (In reply to comment #1)
 Changing this to dmd CTFE bug. I can't think of any way to solve it in Phobos
 without more compiler support.

This seems to work:

... why didn't I think of that :-) I'll make the pull. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 09 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12315



--- Comment #4 from bearophile_hugs eml.cc 2014-03-09 06:59:29 PDT ---
(In reply to comment #3)

 I'll make the pull.

There are also assumeSafeAppend, reserve/capacity, and so on. I don't know if they speedup the code at compile-time too. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 09 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12315



--- Comment #5 from Peter Alexander <peter.alexander.au gmail.com> 2014-03-09
07:01:52 PDT ---
https://github.com/D-Programming-Language/phobos/pull/1986

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 09 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12315



--- Comment #6 from bearophile_hugs eml.cc 2014-03-09 07:11:11 PDT ---
(In reply to comment #5)

 There are also assumeSafeAppend, reserve/capacity, and so on. I don't know if
 they speedup the code at compile-time too.

It seems code like this doesn't yet work: import std.traits: ForeachType; import std.range: hasLength; ForeachType!R[] myArray(R)(R r) { if (__ctfe) { typeof(return) result; static if (hasLength!R) result.reserve = r.length; foreach (item; r) result ~= r; return result; } else { // ... assert(0); } } struct Foo1 { int i; } struct Foo2 { immutable int i; } void main() { enum r1 = [Foo1(1)].myArray; // OK enum r2 = [Foo2(1)].myArray; // OK } -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 09 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12315



--- Comment #7 from github-bugzilla puremagic.com 2014-03-09 12:06:52 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/8d9479c3a4b1f3cb7738b27d90d92330c8d1f058
Fix Issue 12315 - `array` at compile-time with all types

Problem was that `emplaceRef` calls `memcpy` for some types, which is unsafe
and unavailable at compile time.

https://d.puremagic.com/issues/show_bug.cgi?id=12315

https://github.com/D-Programming-Language/phobos/commit/6b31fb8685b458f142db34ca21e5c9639e5cb38d
Merge pull request #1986 from Poita/bug12315

Fix Issue 12315 - `array` at compile-time with all types

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 09 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12315


Peter Alexander <peter.alexander.au gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 09 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12315


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |monarchdodra gmail.com
         Resolution|FIXED                       |


--- Comment #8 from monarchdodra gmail.com 2014-03-10 00:14:37 PDT ---
Reopening because I'm not sure it's worth filing something new, but `Appender`
will also CTFE fail on the same types.

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