ref: 76c34b542f0b5c0cd6cc60a9cef9d53b6fc899d1
parent: b369801b6f39ddd1aed3c13e2dcb23c61fc57ae7
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Mar 2 18:20:26 EST 2016
Allow importing multiple instances of a trait. Hidden imports ftw.
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -171,6 +171,7 @@
char isproto; /* is it a prototype (for exporting purposes) */
char ishidden; /* should user code be able to use this? */
+ char isimport; /* have we defined it locally? */
};
struct Node {
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -413,8 +413,8 @@
*old = *new;
else if (new->isproto && !old->isproto)
*new = *old;
- else
- return 0;
+ else if (!new->isimport && !old->isimport)
+ return new->vis == Vishidden || old->vis == Vishidden;
return 1;
}
--- a/parse/use.c
+++ b/parse/use.c
@@ -213,8 +213,8 @@
wrbyte(fd, ty->vis);
/* tid is generated; don't write */
/* FIXME: since we only support hardcoded traits, we just write
- * out the set of them. we should write out the trait list as
- * well */
+ * out the set of them. we should write out the trait list as
+ * well */
if (!ty->traits) {
wrint(fd, 0);
} else {
@@ -415,6 +415,7 @@
tr->param = tyunpickle(fd);
tr->naux = rdint(fd);
tr->aux = zalloc(tr->naux * sizeof(Type*));
+ tr->isimport = 1;
for (i = 0; i < tr->naux; i++)
rdtype(fd, &tr->aux[i]);
n = rdint(fd);
@@ -747,11 +748,11 @@
Type *t, *u, *old;
/*
- * merge duplicate definitions.
- * This allows us to compare named types by id, instead
- * of doing a deep walk through the type. This ability is
- * depended on when we do type inference.
- */
+ * merge duplicate definitions.
+ * This allows us to compare named types by id, instead
+ * of doing a deep walk through the type. This ability is
+ * depended on when we do type inference.
+ */
for (i = 0; i < ntypefixdest; i++) {
t = htget(tidmap, itop(typefixid[i]));
if (!t)
@@ -793,11 +794,11 @@
Trait *t;
/*
- * merge duplicate definitions.
- * This allows us to compare named types by id, instead
- * of doing a deep walk through the type. This ability is
- * depended on when we do type inference.
- */
+ * merge duplicate definitions.
+ * This allows us to compare named types by id, instead
+ * of doing a deep walk through the type. This ability is
+ * depended on when we do type inference.
+ */
for (i = 0; i < ntraitfixdest; i++) {
t = htget(trmap, itop(traitfixid[i]));
if (!t)
@@ -891,8 +892,8 @@
}
pkg = rdstr(f);
/* if the package names match up, or the usefile has no declared
- * package, then we simply add to the current stab. Otherwise,
- * we add a new stab under the current one */
+ * package, then we simply add to the current stab. Otherwise,
+ * we add a new stab under the current one */
if (st->name) {
if (pkg && !strcmp(pkg, st->name)) {
s = st;
@@ -957,7 +958,8 @@
case 'R':
tr = traitunpickle(f);
tr->vis = vis;
- puttrait(s, tr->name, tr);
+ if (tr->vis != Vishidden)
+ puttrait(s, tr->name, tr);
for (i = 0; i < tr->nfuncs; i++) {
putdcl(s, tr->funcs[i]);
tr->funcs[i]->decl.impls = mkht(tyhash, tyeq);