shithub: mc

Download patch

ref: 2fd7aa8d72729ccec6c611fb3586e9c4c7b5e067
parent: 357f87c1117edfdf77411781ebfae221a406c454
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jul 15 10:44:40 EDT 2017

Use type hashing instead of string hasing in tyenv.

	Set the stage for stricter env lookups.

--- a/parse/dump.c
+++ b/parse/dump.c
@@ -111,16 +111,14 @@
 	Type *t;
 	char *s;
 
-	if (e->tab) {
-		k = htkeys(e->tab, &n);
-		for (i = 0; i < n; i++) {
-			t = htget(e->tab, k[i]);
-			s = tystr(t);
-			findentf(fd, depth + 1, "B %s\n", s);
-			free(s);
-		}
-		free(k);
+	k = htkeys(e->tab, &n);
+	for (i = 0; i < n; i++) {
+		t = htget(e->tab, k[i]);
+		s = tystr(t);
+		findentf(fd, depth + 1, "B %s\n", s);
+		free(s);
 	}
+	free(k);
 }
 
 void
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -518,30 +518,19 @@
 {
 	Stab *ns;
 	Type *lu;
-	Tyenv *e;
 
-	switch (t->type) {
-	case Tyunres:
-		ns = curstab();
-		if (t->name->name.ns) {
-			ns = getns(file, t->name->name.ns);
-		}
-		if (!ns)
-			fatal(t->name, "could not resolve namespace \"%s\"",
-					t->name->name.ns);
-		if (!(lu = gettype(ns, t->name)))
-			fatal(t->name, "could not resolve type %s", tystr(t));
-		return lu;
-	case Typaram:
-		for (e = curenv(); e; e = e->super) {
-			lu = htget(e->tab, t);
-			if (lu)
-				return lu;
-		}
-	default:
-		break;
-	}
-	return NULL;
+	if (t->type != Tyunres)
+		return NULL;
+
+	ns = curstab();
+	if (t->name->name.ns)
+		ns = getns(file, t->name->name.ns);
+	if (!ns)
+		fatal(t->name, "no namespace \"%s\"", t->name->name.ns);
+	lu = gettype(ns, t->name);
+	if (!lu)
+		fatal(t->name, "no type %s", tystr(t));
+	return lu;
 }
 
 /* Look up the best type to date in the unification table, returning it */
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -122,7 +122,7 @@
 
 	e = malloc(sizeof(Tyenv));
 	e->super = NULL;
-	e->tab = mkht(strhash, streq);
+	e->tab = mkht(tyhash, tyeq);
 	return e;
 }
 
@@ -638,11 +638,11 @@
 	bsput(visited, t->tid);
 	switch (t->type) {
 	case Typaram:
-		tt = htget(e->tab, t->pname);
+		tt = htget(e->tab, t);
 		if (tt && tt != t)
 			tytab[t->tid] = tt;
 		else if (!isbound(t))
-			htput(e->tab, t->pname, t);
+			htput(e->tab, t, t);
 		break;
 	case Tygeneric:
 		for (i = 0; i < t->ngparam; i++)
@@ -694,7 +694,7 @@
 
 	Tyenv *e;
 	for (e = curenv(); e; e = e->super)
-		if (htget(e->tab, t->pname))
+		if (htget(e->tab, t))
 			return 1;
 	return 0;
 }