summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-07-15 14:44:40 -0700
committerOri Bernstein <ori@eigenstate.org>2017-07-15 14:44:40 -0700
commit2fd7aa8d72729ccec6c611fb3586e9c4c7b5e067 (patch)
treebff78a7a88c260d0e20a341274fa28f38cf10ed9
parent357f87c1117edfdf77411781ebfae221a406c454 (diff)
downloadmc-2fd7aa8d72729ccec6c611fb3586e9c4c7b5e067.tar.gz
Use type hashing instead of string hasing in tyenv.
Set the stage for stricter env lookups.
-rw-r--r--parse/dump.c16
-rw-r--r--parse/infer.c35
-rw-r--r--parse/stab.c8
3 files changed, 23 insertions, 36 deletions
diff --git a/parse/dump.c b/parse/dump.c
index f84eea1..9437984 100644
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -111,16 +111,14 @@ outenv(Tyenv *e, FILE *fd, int depth)
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
diff --git a/parse/infer.c b/parse/infer.c
index 80a55ec..a919d84 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -518,30 +518,19 @@ remapping(Type *t)
{
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 */
diff --git a/parse/stab.c b/parse/stab.c
index 757dceb..dea101a 100644
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -122,7 +122,7 @@ mkenv()
e = malloc(sizeof(Tyenv));
e->super = NULL;
- e->tab = mkht(strhash, streq);
+ e->tab = mkht(tyhash, tyeq);
return e;
}
@@ -638,11 +638,11 @@ bindtype_rec(Tyenv *e, Type *t, Bitset *visited)
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 @@ isbound(Type *t)
Tyenv *e;
for (e = curenv(); e; e = e->super)
- if (htget(e->tab, t->pname))
+ if (htget(e->tab, t))
return 1;
return 0;
}