summaryrefslogtreecommitdiff
path: root/parse/infer.c
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2018-04-18 08:30:41 -0400
committerS. Gilles <sgilles@math.umd.edu>2018-04-18 08:30:41 -0400
commit9aabbe574e648e0a462b211c62da5eb5875343b7 (patch)
tree9ac90949a12806359fd4b996029757c84ef6e2a6 /parse/infer.c
parent4acd9ee51a541f94e81457b1a7fb3accbd790696 (diff)
parent3d71446ecb6569add0d9eaf2e7e4a05d99bd2625 (diff)
downloadmc-9aabbe574e648e0a462b211c62da5eb5875343b7.tar.gz
Merge remote-tracking branch 'ori/master' into HEAD
Diffstat (limited to 'parse/infer.c')
-rw-r--r--parse/infer.c60
1 files changed, 35 insertions, 25 deletions
diff --git a/parse/infer.c b/parse/infer.c
index bb1ea59..58399b0 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -29,6 +29,7 @@ struct Traitmap {
size_t nfiltertr;
};
+int allowhidden;
static void infernode(Node **np, Type *ret, int *sawret);
static void inferexpr(Node **np, Type *ret, int *sawret);
@@ -69,6 +70,8 @@ static size_t nspecializations;
static Stab **specializationscope;
static size_t nspecializationscope;
static Traitmap *traitmap;
+static Bitset *tytraits[Ntypes];
+
static void
ctxstrcall(char *buf, size_t sz, Node *n)
@@ -685,7 +688,7 @@ mktylike(Srcloc l, Ty other)
t = mktyvar(l);
/* not perfect in general, but good enough for all places mktylike is used. */
- t->trneed = bsdup(traitmap->sub[other]->traits);
+ t->trneed = bsdup(tytraits[other]);
return t;
}
@@ -958,7 +961,7 @@ static void
verifytraits(Node *ctx, Type *a, Type *b)
{
char traitbuf[64], abuf[64], bbuf[64];
- char asrc[64], bsrc[64];
+ char asrc[128], bsrc[128];
Bitset *abs, *bbs;
size_t i, n;
Srcloc l;
@@ -979,10 +982,11 @@ verifytraits(Node *ctx, Type *a, Type *b)
n = 0;
*traitbuf = 0;
for (i = 0; bsiter(abs, &i); i++) {
- if (!bshas(bbs, i))
+ if (!bshas(bbs, i)) {
n += bprintf(traitbuf + n, sizeof(traitbuf) - n, "%s%s", sep,
- namestr(traittab[i]->name));
- sep = ",";
+ namestr(traittab[i]->name));
+ sep = ",";
+ }
}
tyfmt(abuf, sizeof abuf, a);
tyfmt(bbuf, sizeof bbuf, b);
@@ -1320,7 +1324,7 @@ initvar(Node *n, Node *s)
Type *t, *param;
Tysubst *subst;
- if (s->decl.ishidden)
+ if (s->decl.ishidden && !allowhidden)
fatal(n, "attempting to refer to hidden decl %s", ctxstr(n));
param = n->expr.param;
@@ -2787,41 +2791,47 @@ builtintraits(void)
/* char::(numeric,integral) */
for (i = 0; i < Ntypes; i++)
- traitmap->sub[i] = mktraitmap();
+ tytraits[i] = mkbs();
- bsput(traitmap->sub[Tychar]->traits, Tcnum);
- bsput(traitmap->sub[Tychar]->traits, Tcint);
+ bsput(tytraits[Tychar], Tcnum);
+ bsput(tytraits[Tychar], Tcint);
- bsput(traitmap->sub[Tybyte]->traits, Tcnum);
- bsput(traitmap->sub[Tybyte]->traits, Tcint);
+ bsput(tytraits[Tybyte], Tcnum);
+ bsput(tytraits[Tybyte], Tcint);
/* <integer types>::(numeric,integral) */
for (i = Tyint8; i < Tyflt32; i++) {
- bsput(traitmap->sub[i]->traits, Tcnum);
- bsput(traitmap->sub[i]->traits, Tcint);
+ bsput(tytraits[i], Tcnum);
+ bsput(tytraits[i], Tcint);
}
/* <floats>::(numeric,floating) */
- bsput(traitmap->sub[Tyflt32]->traits, Tcnum);
- bsput(traitmap->sub[Tyflt32]->traits, Tcflt);
- bsput(traitmap->sub[Tyflt64]->traits, Tcnum);
- bsput(traitmap->sub[Tyflt64]->traits, Tcflt);
+ bsput(tytraits[Tyflt32], Tcnum);
+ bsput(tytraits[Tyflt32], Tcflt);
+ bsput(tytraits[Tyflt64], Tcnum);
+ bsput(tytraits[Tyflt64], Tcflt);
/* @a*::(sliceable) */
- bsput(traitmap->sub[Typtr]->traits, Tcslice);
+ bsput(tytraits[Typtr], Tcslice);
/* @a[:]::(indexable,sliceable) */
- bsput(traitmap->sub[Tyslice]->traits, Tcidx);
- bsput(traitmap->sub[Tyslice]->traits, Tcslice);
- bsput(traitmap->sub[Tyslice]->traits, Tciter);
+ bsput(tytraits[Tyslice], Tcidx);
+ bsput(tytraits[Tyslice], Tcslice);
+ bsput(tytraits[Tyslice], Tciter);
/* @a[SZ]::(indexable,sliceable) */
- bsput(traitmap->sub[Tyarray]->traits, Tcidx);
- bsput(traitmap->sub[Tyarray]->traits, Tcslice);
- bsput(traitmap->sub[Tyarray]->traits, Tciter);
+ bsput(tytraits[Tyarray], Tcidx);
+ bsput(tytraits[Tyarray], Tcslice);
+ bsput(tytraits[Tyarray], Tciter);
/* @a::function */
- bsput(traitmap->sub[Tyfunc]->traits, Tcfunc);
+ bsput(tytraits[Tyfunc], Tcfunc);
+
+ for (i = 0; i < Ntypes; i++) {
+ traitmap->sub[i] = mktraitmap();
+ bsunion(traitmap->sub[i]->traits, tytraits[i]);
+ }
+
}
static Trait*