www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7810] New: ctRegex!`a|b` asserts at regex.d:1150

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

           Summary: ctRegex!`a|b` asserts at regex.d:1150
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: simendsjo gmail.com


--- Comment #0 from simendsjo <simendsjo gmail.com> 2012-04-02 06:12:47 PDT ---
Using dmd 2.059 trunk

import std.regex;
//enum re = ctRegex!`(^[a-z]+)|([A-Z0-9][a-z0-9]+)|([A-Z]+)|([a-z]+)`;
//enum re = ctRegex!`(a)|(b)`;
enum re = ctRegex!`a|b`;
void main() {}


/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(1150): Error:
assert(this.ir[cast(ulong)orStart].code() == cast(IR)129u) failed
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(876):        called
from here: this.parseRegex()
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6428):       
called from here: parser.this(pattern,flags)
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6412):       
called from here: regexImpl(pattern,flags)
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6437):       
called from here: regex("a|b",[])
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(1150): Error:
assert(this.ir[cast(ulong)orStart].code() == cast(IR)129u) failed
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(876):        called
from here: this.parseRegex()
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6428):       
called from here: parser.this(pattern,flags)
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6412):       
called from here: regexImpl(pattern,flags)
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6439):       
called from here: regex("a|b",[])
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6439):       
called from here: ctGenRegExCode(regex("a|b",[]))
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(1150): Error:
assert(this.ir[cast(ulong)orStart].code() == cast(IR)129u) failed
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(876):        called
from here: this.parseRegex()
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6428):       
called from here: parser.this(pattern,flags)
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6412):       
called from here: regexImpl(pattern,flags)
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6446):       
called from here: regex("a|b",[])
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6446):       
called from here:
StaticRegex(null,Regex(null,null,null,0u,0u,0u,0u,0u,null,null,ShiftOr(null,0u,0u))).this(regex("a|b",[]),&
func)
/home/simendsjo/code/dmd-trunk/build/src/phobos/std/regex.d(6463): Error:
template instance std.regex.ctRegexImpl!("a|b",[]) error instantiating
re.d(4):        instantiated from here: ctRegex!("a|b")
re.d(4): Error: template instance std.regex.ctRegex!("a|b") error instantiating

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



--- Comment #1 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-04-17
01:55:53 PDT ---
Created an attachment (id=1094)
Stripped down regex parser

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


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh gmail.com
          Component|Phobos                      |DMD


--- Comment #2 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-04-17
01:57:52 PDT ---
It's a bug in CTFE not in Phobos. R-T version runs the same code and doesn't
hit the assert. See reduced test case.

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


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |beatgammit gmail.com


--- Comment #3 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-04-19
09:36:11 PDT ---
*** Issue 7567 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: -------
Apr 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7810


Brad Anderson <eco gnuk.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eco gnuk.net


--- Comment #4 from Brad Anderson <eco gnuk.net> 2012-05-17 19:40:52 PDT ---
Doesn't appear to require ctRegex to trigger.  This produces the same assertion
failure.

import std.regex;

auto r = regex(r"(a|c");

void main() { }

This worked in 2.058 but not 2.059.

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



--- Comment #5 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-05-17
23:01:09 PDT ---
(In reply to comment #4)
 Doesn't appear to require ctRegex to trigger.  This produces the same assertion
 failure.
 
 import std.regex;
 
 auto r = regex(r"(a|c");
 
 void main() { }
 
 This worked in 2.058 but not 2.059.

not the same. And yes, global variable == CTFE parser. + r"(a|c" unbalanced paren, so it should eventually throw exception but it asserts before it have the chance to do that. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 17 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7810


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|ctRegex!`a|b` asserts at    |[CTFE] Typesafe variadic
                   |regex.d:1150                |function with array of
                   |                            |structs


--- Comment #6 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-09-26
11:47:45 PDT ---
I've finally pinned down this bugger. 
The problem is in typesafe variadic function if the parameter type is a struct.

See simple test below:
//encoded IR instruction
struct Bytecode
{
    uint raw;
}

int fn1(T)(T[] items...)
{
    assert(items[0] == 20);
    return 42;
}

int fn2(T)(T[] items...)
{
    assert(items[0] == Bytecode(20));
    return 42;
}

//this passes...
static assert(fn1(20, 30) == 42); 

//this dies inside of fn2
static assert(fn2(Bytecode(20), Bytecode(30)) == 42); 

void main()
{//both of these pass at R-T
    assert(fn1(20, 30) == 42); 
    assert(fn2(Bytecode(20), Bytecode(30)) == 42);
}

Output:

sr_micro.d(15): Error: assert(items[0u] == Bytecode(20u)) failed
sr_micro.d(23):        called from here: fn2((Bytecode[2u] __arrayArg6 = void;
 , __arrayArg6[0u] = Bytecode(20u) , __arrayArg6[1u] = Bytecode(30u) ,
cast(Bytecode[])__arrayArg6))
sr_micro.d(23):        while evaluating: static assert(fn2((Bytecode[2u]
__arrayArg6 = void;
 , __arrayArg6[0u] = Bytecode(20u) , __arrayArg6[1u] = Bytecode(30u) ,
cast(Bytecode[])__arrayArg6)) == 42)

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



--- Comment #7 from Don <clugdbug yahoo.com.au> 2012-09-28 00:01:52 PDT ---
Problem happens when an array is initialized to void in global scope (outside
of CTFE) and then modified in CTFE. Haven't fixed this yet.

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



--- Comment #8 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-09-28
03:08:46 PDT ---
(In reply to comment #7)
 Problem happens when an array is initialized to void in global scope (outside
 of CTFE) and then modified in CTFE. Haven't fixed this yet.

Thanks for looking into it. It took soo long to reduce but at least now I have an idea of a workaround. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 28 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7810



--- Comment #9 from Don <clugdbug yahoo.com.au> 2012-10-01 06:17:47 PDT ---
Further reduced shows it's a problem with void initialized static arrays. I
have a fix.

int bug7810() {

    int[1][3] x = void;
    x[0] = [2];
    x[1] = [7];
    assert(x[0][0] == 2);
    return 1;
}
static assert(bug7810());

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



--- Comment #10 from Don <clugdbug yahoo.com.au> 2012-10-01 07:16:00 PDT ---
https://github.com/D-Programming-Language/dmd/pull/1155

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



--- Comment #11 from github-bugzilla puremagic.com 2012-10-16 04:22:39 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7d133964da2a5c0c794b82d42f3f3c9cbfdcf078
Fix issue 7810 [CTFE] Typesafe variadic function with array of structs

It's actually a problem with void-initialized static arrays.
This was the root cause of a compile-time regexp bug.

https://github.com/D-Programming-Language/dmd/commit/eaa03fefeb1a698f586d5f5a09068f3433bf4b29
Merge pull request #1155 from donc/ctfe7810array_voidinit

Fix issue 7810 [CTFE] Typesafe variadic function with array of structs

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


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com


--- Comment #12 from yebblies <yebblies gmail.com> 2012-10-16 22:23:50 EST ---
Fixed for D2

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


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #13 from Walter Bright <bugzilla digitalmars.com> 2012-10-16
17:45:35 PDT ---
Fixed for D1.

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


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |val markovic.io


--- Comment #14 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-11-30
12:49:43 PST ---
*** Issue 8725 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: -------
Nov 30 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7810


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |iteronvexor gmail.com


--- Comment #15 from Don <clugdbug yahoo.com.au> 2012-12-12 04:54:33 PST ---
*** Issue 8805 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: -------
Dec 12 2012