summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-08-20 19:52:05 -0700
committerOri Bernstein <ori@eigenstate.org>2017-08-20 19:52:05 -0700
commit73e2c5b1664a814e363364921270ae365473e622 (patch)
tree2f456d9420766a11efcd46dcba27acd121e3cb18 /parse
parent6e4bf0cdecce71d9a839c1e7f6a42409c2f9d961 (diff)
downloadmc-73e2c5b1664a814e363364921270ae365473e622.tar.gz
Fix a few bugs.
Diffstat (limited to 'parse')
-rw-r--r--parse/infer.c40
-rw-r--r--parse/use.c5
2 files changed, 30 insertions, 15 deletions
diff --git a/parse/infer.c b/parse/infer.c
index 6d15240..44fb805 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -255,8 +255,6 @@ adddispspecialization(Node *n, Stab *stab)
tr = traittab[Tcdisp];
ty = decltype(n);
- //if (!ty->traits || !bshas(ty->traits, Tcdisp))
- // return;
assert(tr->nproto == 1);
if (hthas(tr->proto[0]->decl.impls, ty))
return;
@@ -2603,17 +2601,26 @@ specialize(void)
popstab();
}
}
+
+static Traitmap *
+mktraitmap()
+{
+ Traitmap *m;
+
+ m = zalloc(sizeof(Traitmap));
+ m->traits = mkbs();
+ m->name = mkht(namehash, nameeq);
+ return m;
+}
+
static void
builtintraits(void)
{
size_t i;
/* char::(numeric,integral) */
- for (i = 0; i < Ntypes; i++) {
- traitmap->sub[i] = zalloc(sizeof(Traitmap));
- traitmap->sub[i]->traits = mkbs();
- traitmap->sub[i]->name = mkht(namehash, nameeq);
- }
+ for (i = 0; i < Ntypes; i++)
+ traitmap->sub[i] = mktraitmap();
bsput(traitmap->sub[Tychar]->traits, Tcnum);
bsput(traitmap->sub[Tychar]->traits, Tcint);
@@ -2680,18 +2687,23 @@ addtraittab(Traitmap *m, Trait *tr, Type *ty)
{
Bitset *bs;
Traitmap *mm;
+ size_t i;
- if (!m->sub[ty->type]) {
- m->sub[ty->type] = zalloc(sizeof(Traitmap));
- m->sub[ty->type]->traits = mkbs();
- m->sub[ty->type]->name = mkht(namehash, nameeq);
- }
+ if (!m->sub[ty->type])
+ m = mktraitmap();
mm = m->sub[ty->type];
switch (ty->type) {
case Tygeneric:
case Typaram:
- lappend(&mm->filter, &m->nfilter, ty);
- lappend(&mm->filtertr, &m->nfiltertr, tr);
+ for (i = 0; i < Ntypes; i++) {
+ if (i == Typaram)
+ continue;
+ if (!m->sub[i])
+ m->sub[i] = mktraitmap();
+ mm = m->sub[i];
+ lappend(&mm->filter, &mm->nfilter, ty);
+ lappend(&mm->filtertr, &mm->nfiltertr, tr);
+ }
break;
case Tyname:
if (ty->ngparam == 0) {
diff --git a/parse/use.c b/parse/use.c
index bb5d76a..09683f9 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -840,8 +840,11 @@ fixtraitmappings(Stab *st)
}
if (traitfix[i].dest)
*traitfix[i].dest = tr;
- if (traitfix[i].type)
+ if (traitfix[i].type && traitfix[i].type->type == Typaram) {
+ if (!traitfix[i].type->trneed)
+ traitfix[i].type->trneed = mkbs();
bsput(traitfix[i].type->trneed, tr->uid);
+ }
}
free(traitfix);