ref: ab42f5c4f29b1860d26c40bd05bb123a3ef49a6f
parent: 1db8622646327359d06877fb85534a33cfa5ad6b
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Aug 13 12:38:10 EDT 2016
Don't generate loops in trees. We only want to append to last if we're actaully expanding the match frontier. It's a bug to add it if it's unused.
--- a/mi/match.c
+++ b/mi/match.c
@@ -297,6 +297,8 @@
for (j = 0; j < nlast; j++)
if (addwildrec(loc, ty->sub[i], last[j], next, &tail, &ntail))
ret = 1;
+ if (i == ty->nsub - 1)
+ break;
lfree(&last, &nlast);
last = tail;
nlast = ntail;
@@ -313,6 +315,8 @@
for (j = 0; j < nlast; j++)
if (addwildrec(loc, ty->sub[0], last[j], next, &tail, &ntail))
ret = 1;
+ if (i == nelt - 1)
+ break;
lfree(&last, &nlast);
last = tail;
nlast = ntail;
@@ -327,6 +331,8 @@
for (j = 0; j < nlast; j++)
if (addwildrec(loc, decltype(ty->sdecls[i]), last[j], next, &tail, &ntail))
ret = 1;
+ if (i == ty->nsub - 1)
+ break;
lfree(&last, &nlast);
last = tail;
nlast = ntail;
@@ -333,7 +339,6 @@
}
break;
case Tyunion:
- lappend(&last, &nlast, start);
for (i = 0; i < ty->nmemb; i++) {
uc = ty->udecls[i];
next = dtbytag(start, uc);
@@ -350,7 +355,7 @@
start->any = accept;
ret = 1;
}
- lappend(end, nend, start->any);
+ lappend(&last, &nlast, accept);
break;
case Tyslice:
ret = acceptall(start, accept);
@@ -357,7 +362,6 @@
lappend(&last, &nlast, accept);
break;
case Typtr:
- lappend(&last, &nlast, start);
ret = addwildrec(loc, ty->sub[0], start, accept, &last, &nlast);
break;
default: