shithub: mc

Download patch

ref: 29bd0da380f893e1f031c36878676a460fd18402
parent: 2d534bb4fe76d68eb1ffb7805054d9acfef0e89e
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jan 29 19:16:02 EST 2016

Fix recursive types. Again.

	This code does 2 things:
		1) It compares on TID. This shouldn't matter much.
		2) It resolves the type in the substitution map. This
		   prevents us from returning the wrong type.

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -934,7 +934,7 @@
 	/* a ==> b */
 	a = tf(st, u);
 	b = tf(st, v);
-	if (a == b)
+	if (a->tid == b->tid)
 		return a;
 
 	/* we unify from lower to higher ranked types */
@@ -955,16 +955,8 @@
 	}
 
 	r = NULL;
-	/*
-	 * unify eagerly here, solving the problem of comparing two specialized types
-	 * that don't have pointer equality.
-	 *
-	 * If the types *actually* conflict, we will error out later in this function,
-	 * and the bogus unification won't matter. If the types *are* the same, though,
-	 * then this short circuits a whole bunch of infinite recursion.
-	 */
-	tytab[a->tid] = b;
 	if (a->type == Tyvar) {
+		tytab[a->tid] = b;
 		ea = basetype(st, a);
 		eb = basetype(st, b);
 		if (ea && eb)
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -90,7 +90,7 @@
 	t = tysearch(orig);
 	tmp = substget(tsmap, t);
 	if (tmp)
-		return tmp;
+		return tysearch(tmp);
 	arg = NULL;
 	narg = 0;
 	switch (t->type) {