shithub: mc

Download patch

ref: c5649fe3ddc066335f816d59a4f31b9c26b1c230
parent: 284e7bb9bee1f03a7792347dd0da3a0c5dd2fbb4
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Jan 28 16:30:58 EST 2016

Clean up type inference a bit.

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -829,13 +829,13 @@
 	for (i = 0; i < u->nmemb; i++) {
 		found = 0;
 		for (j = 0; j < v->nmemb; j++) {
-			if (strcmp(namestr(u->udecls[i]->name), namestr(v->udecls[i]->name)) != 0)
+			if (strcmp(namestr(u->udecls[i]->name), namestr(v->udecls[j]->name)) != 0)
 				continue;
 			found = 1;
-			if (u->udecls[i]->etype == NULL && v->udecls[i]->etype == NULL)
+			if (u->udecls[i]->etype == NULL && v->udecls[j]->etype == NULL)
 				continue;
-			else if (u->udecls[i]->etype && v->udecls[i]->etype)
-				unify(st, ctx, u->udecls[i]->etype, v->udecls[i]->etype);
+			else if (u->udecls[i]->etype && v->udecls[j]->etype)
+				unify(st, ctx, u->udecls[i]->etype, v->udecls[j]->etype);
 			else
 				fatal(ctx, "can't unify %s and %s near %s\n", tystr(u), tystr(v),
 						ctxstr(st, ctx));
@@ -850,6 +850,7 @@
 {
 	size_t i, j;
 	int found;
+	char *ud, *vd;
 
 	if (u->nmemb != v->nmemb)
 		fatal(ctx, "can't unify %s and %s near %s\n", tystr(u), tystr(v), ctxstr(st, ctx));
@@ -857,12 +858,15 @@
 	for (i = 0; i < u->nmemb; i++) {
 		found = 0;
 		for (j = 0; j < v->nmemb; j++) {
-			if (strcmp(namestr(u->sdecls[i]->decl.name),
-						namestr(v->sdecls[i]->decl.name)) != 0)
-				continue;
-			found = 1;
-			unify(st, ctx, type(st, u->sdecls[i]), type(st, v->sdecls[i]));
+			ud = namestr(u->sdecls[i]->decl.name);
+			vd = namestr(v->sdecls[j]->decl.name);
+			if (strcmp(ud, vd) == 0) {
+				found = 1;
+				//printf("unifying member %s and %s\n", tystr(type(st, u->sdecls[i])), tystr(type(st, v->sdecls[j])));
+				unify(st, ctx, type(st, u->sdecls[i]), type(st, v->sdecls[j]));
+			}
 		}
+		/* we had at least one missing member */
 		if (!found)
 			fatal(ctx, "can't unify %s and %s near %s\n", tystr(u), tystr(v),
 					ctxstr(st, ctx));
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -57,7 +57,7 @@
 		ret->issynth = 1;
 		ret->arg = arg;
 		ret->narg = narg;
-		*var = *ret;
+		tytab[var->tid] = ret;
 		break;
 	case Tyname:
 		if (!hasparams(t))
--- a/parse/type.c
+++ b/parse/type.c
@@ -515,6 +515,7 @@
 	char *end;
 	char *sep;
 
+	t = tysearch(t);
 	sep = "";
 	p = buf;
 	end = p + len;
@@ -747,6 +748,7 @@
 	size_t i;
 	char *p, *end;
 
+	ty = tysearch(ty);
 	p = buf;
 	end = buf + sz;
 	switch (ty->type) {