Bug 12394 – Regression: std.regex unittests take agonizingly long to run - like hours on OSX
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2014-03-17T18:45:00Z
Last change time
2014-04-22T06:39:55Z
Assigned to
nobody
Creator
bugzilla
Comments
Comment #0 by bugzilla — 2014-03-17T18:45:52Z
The diff with one that runs in a reasonable length of time is:
----------------------------
3931,3934c3931,3934
< CtContext lookaround()
< {
< CtContext ct;
< ct.total_matches = total_matches;
---
> CtContext lookaround(uint s, uint e)
> {
> CtContext ct;
> ct.total_matches = e - s;
4052c4052
< CtContext context = lookaround(); //split off new context
---
> CtContext context = lookaround(ir[1].raw, ir[2].raw); //split off new context
4187a4188
> auto altCode = testCode.length ? ctSub("else goto case $$;", fixup) : "";
4200,4206c4201,4206
< else
< goto case $$;
< case $$://restore state and go inside loop
< $$
< goto case $$;`, curInfLoop, addr+2, curInfLoop,
< testCode, saveCode(addr+1),
< addr+2, fixup, addr+1, restoreCode(), fixup);
---
> $$
> case $$://restore state and go inside loop
> $$
> goto case $$;`, curInfLoop, addr+2,
> curInfLoop, testCode, saveCode(addr+1),
> addr+2, altCode, addr+1, restoreCode(), fixup);
5209,5216c5209,5215
< matcher.re.ngroup = re.ir[t.pc+2].raw - re.ir[t.pc+1].raw;
< matcher.backrefed = backrefed.empty ? t.matches : backrefed;
< //backMatch
< bool nomatch = (matcher.matchOneShot(t.matches, IRL!(IR.LookbehindStart))
< == MatchResult.Match) ^ positive;
< freelist = matcher.freelist;
< subCounters[t.pc] = matcher.genCounter;
< if(nomatch)
---
> matcher.re.ngroup = me - ms;
> matcher.backrefed = backrefed.empty ? t.matches : backrefed;
> //backMatch
> auto mRes = matcher.matchOneShot(t.matches.ptr[ms .. me], IRL!(IR.LookbehindStart));
> freelist = matcher.freelist;
> subCounters[t.pc] = matcher.genCounter;
> if((mRes == MatchResult.Match) ^ positive)
5240,5241c5239
< bool nomatch = (matcher.matchOneShot(t.matches, IRL!(IR.LookaheadStart))
< == MatchResult.Match) ^ positive;
---
> auto mRes = matcher.matchOneShot(t.matches.ptr[ms .. me], IRL!(IR.LookaheadStart));
5246c5244
< if(nomatch)
---
> if((mRes == MatchResult.Match) ^ positive)
5261,5263c5259
< t.pc = re.ir[t.pc].indexOfPair(t.pc);
< uint ms = re.ir[t.pc+1].raw, me = re.ir[t.pc+2].raw;
< finish(t, matches.ptr[ms..me]);
---
> finish(t, matches.ptr[0 .. re.ngroup]);
5653c5649
< assert(c.pre == "@"); // Part of input preceeding match
---
> assert(c.pre == "@"); // Part of input preceding match
7459a7456,7472
> // bugzilla 12076
> unittest
> {
> auto RE = ctRegex!(r"(?<!x\w+)\s(\w+)");
> string s = "one two";
> auto m = match(s, RE);
> }
>
> // bugzilla 12105
> unittest
> {
> auto r = ctRegex!`.*?(?!a)`;
> assert("aaab".matchFirst(r).hit == "aaa");
> auto r2 = ctRegex!`.*(?!a)`;
> assert("aaab".matchFirst(r2).hit == "aaab");
> }
>
------------------------------------------------------
It happens on my OSX machine, possibly because it doesn't have that much memory and is swapping itself to death. But unittests need to run in a reasonable amount of time or people won't run them at all.
Comment #1 by dmitry.olsh — 2014-03-18T01:39:26Z
I bet CTFE puts pressure on RAM and that Mac machine doesn't have that much.
Looking at fresh unittests below, try changing:
// bugzilla 12076
...
auto RE = ctRegex!(r"(?<!x\w+)\s(\w+)");
To
auto RE = ctRegex!(r"(?<!x[a-z]+)\s([a-z]+)");