summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-09-02 16:11:54 -0700
committerOri Bernstein <ori@eigenstate.org>2017-09-02 16:11:54 -0700
commit290709fdfc3fa92e84f9f2bf214c6a144f24c5ee (patch)
tree4d61591c8231c21807599b84541d0e790216b3c6 /parse
parent987d3f2938a42db4285417109fed8d4a82655676 (diff)
downloadmc-290709fdfc3fa92e84f9f2bf214c6a144f24c5ee.tar.gz
Unjank trait resolution.
Diffstat (limited to 'parse')
-rw-r--r--parse/gram.y20
-rw-r--r--parse/infer.c10
-rw-r--r--parse/parse.h3
3 files changed, 15 insertions, 18 deletions
diff --git a/parse/gram.y b/parse/gram.y
index 9dc198d..f96cea6 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -31,7 +31,6 @@ int yylex(void);
static Op binop(int toktype);
static Node *mkpseudodecl(Srcloc l, Type *t);
static void installucons(Stab *st, Type *t);
-static void addtrait(Type *t, char *str);
static void setattrs(Node *dcl, char **attrs, size_t nattrs);
static void setupinit(Node *n);
@@ -499,13 +498,13 @@ generictype
: Ttyparam {$$ = mktyparam($1->loc, $1->id);}
| Ttyparam Twith name {
$$ = mktyparam($1->loc, $1->id);
- addtrait($$, $3->name.name);
+ lappend(&$$->traits, &$$->ntraits, $3);
}
| Ttyparam Twith Toparen typaramlist Tcparen {
size_t i;
$$ = mktyparam($1->loc, $1->id);
for (i = 0; i < $4.nn; i++)
- addtrait($$, $4.nl[i]->name.name);
+ lappend(&$$->traits, &$$->ntraits, $4.nl[i]);
}
;
@@ -1077,21 +1076,6 @@ static void setupinit(Node *n)
n->decl.name->name.name = strdup(s);
}
-static void addtrait(Type *t, char *str)
-{
- size_t i;
-
- for (i = 0; i < ntraittab; i++) {
- if (!strcmp(namestr(traittab[i]->name), str)) {
- if (!t->trneed)
- t->trneed = mkbs();
- bsput(t->trneed, i);
- return;
- }
- }
- lfatal(t->loc, "Constraint %s does not exist", str);
-}
-
static Node *mkpseudodecl(Srcloc l, Type *t)
{
static int nextpseudoid;
diff --git a/parse/infer.c b/parse/infer.c
index a05dd64..0b0852a 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -480,6 +480,7 @@ static void
tyresolve(Type *t)
{
size_t i;
+ Trait *tr;
if (t->resolved)
return;
@@ -523,6 +524,15 @@ tyresolve(Type *t)
break;
}
+ for (i = 0; i < t->ntraits; i++) {
+ tr = gettrait(curstab(), t->traits[i]);
+ if (!tr)
+ lfatal(t->loc, "trait %s does not exist", ctxstr(t->traits[i]));
+ if (!t->trneed)
+ t->trneed = mkbs();
+ bsput(t->trneed, tr->uid);
+ }
+
for (i = 0; i < t->nsub; i++) {
t->sub[i] = tf(t->sub[i]);
if (t->sub[i] == t) {
diff --git a/parse/parse.h b/parse/parse.h
index afed7ef..aaba54f 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -125,6 +125,9 @@ struct Type {
Vis vis;
+ Node **traits; /* trait list */
+ size_t ntraits; /* trait list size */
+
Type **gparam; /* Tygeneric: type parameters that match the type args */
size_t ngparam; /* Tygeneric: count of type parameters */
Type **arg; /* Tyname: type arguments instantiated */