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



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




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



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



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



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




23:01:09 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.
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



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




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




03:08:46 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.
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




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




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




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


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



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



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



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



*** 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