www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4941] New: TypeTuple slice boundaries are not CTFE'd

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

           Summary: TypeTuple slice boundaries are not CTFE'd
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: patch, rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: rsinfu gmail.com


--- Comment #0 from Shin Fujishiro <rsinfu gmail.com> 2010-09-25 21:25:29 PDT
---
Type tuples can't be sliced with boundaries that involve CTFE-able function
call(s). The following valid code doesn't compile (both D1 & D2):
--------------------
template T(_...) { alias _ T; }
size_t mid(size_t n) { return n/2; }

alias T!(int, int, int)[0 .. mid($)] A;
// Error: Integer constant expression expected instead of mid(3u)
--------------------


Patch against dmd r687, makes it sure that TypeSlice boundaries get CTFE'd.

--- src/mtype.c
+++ src/mtype.c
   -7787,11 +7787,11    Type *TypeSlice::semantic(Loc loc, Scope *sc)
     TypeTuple *tt = (TypeTuple *)tbn;

     lwr = semanticLength(sc, tbn, lwr);
-    lwr = lwr->optimize(WANTvalue);
+    lwr = lwr->optimize(WANTvalue | WANTinterpret);
     uinteger_t i1 = lwr->toUInteger();

     upr = semanticLength(sc, tbn, upr);
-    upr = upr->optimize(WANTvalue);
+    upr = upr->optimize(WANTvalue | WANTinterpret);
     uinteger_t i2 = upr->toUInteger();

     if (!(i1 <= i2 && i2 <= tt->arguments->dim))

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 25 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4941



--- Comment #1 from Shin Fujishiro <rsinfu gmail.com> 2010-09-25 22:11:04 PDT
---
Created an attachment (id=776)
Patch against dmd r687, CTFE on tuple slice boundaries

The attached patch obsoletes the patch in comment #0.  The new one applies the
same fix to other relevant parts, and fixes following additional cases:


template T(_...) { alias _ T; }
size_t mid(size_t n) { return n/2; }

alias T!(int, int)[0 .. mid($)] A;      // A
alias T!(1, 2, 3)[0 .. mid($)] B;       // B

void main()
{
    T!(int, int, int) values;
    auto slice = values[0 .. mid($)];   // C
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 25 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4941


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2010-09-27
21:08:58 PDT ---
http://www.dsource.org/projects/dmd/changeset/696

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