summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-01-17 22:18:26 -0800
committerOri Bernstein <ori@eigenstate.org>2018-01-17 22:18:26 -0800
commit490e90d2122d80bce4e5f710e046b90fc9cc31ca (patch)
treefe90f739ae700c7f68bdf2f1fdaec2df2dd3d21f
parent8e1bb5d4fc204ce149ceb545aef7b783d73641bc (diff)
downloadmc-490e90d2122d80bce4e5f710e046b90fc9cc31ca.tar.gz
Hack in seqaux.
It's not perfect, and the right solution would be to keep a trait->aux mapping, but for now it works good enough.
-rw-r--r--mbld/libs.myr2
-rw-r--r--parse/export.c1
-rw-r--r--parse/infer.c35
-rw-r--r--parse/parse.h7
-rw-r--r--parse/specialize.c35
-rw-r--r--parse/use.c10
6 files changed, 44 insertions, 46 deletions
diff --git a/mbld/libs.myr b/mbld/libs.myr
index 9652c15..49e2fc6 100644
--- a/mbld/libs.myr
+++ b/mbld/libs.myr
@@ -22,7 +22,7 @@ pkg bld =
incs : byte[:][:] -> void)
;;
-const Abiversion = 15
+const Abiversion = 16
const builtlib = {b, mt, dep, dyndep
var ldep, l, u
diff --git a/parse/export.c b/parse/export.c
index 2d6e075..136f0de 100644
--- a/parse/export.c
+++ b/parse/export.c
@@ -74,6 +74,7 @@ tagtype(Stab *st, Type *t, int ingeneric, int hidelocal)
if (!t || t->vis != Visintern)
return;
t->vis = Vishidden;
+ tagtype(st, t->seqaux, ingeneric, hidelocal);
for (i = 0; i < t->nsub; i++)
tagtype(st, t->sub[i], ingeneric, hidelocal);
for (i = 0; i < t->nspec; i++) {
diff --git a/parse/infer.c b/parse/infer.c
index 16122c6..bfac296 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -69,7 +69,6 @@ static size_t nspecializations;
static Stab **specializationscope;
static size_t nspecializationscope;
static Traitmap *traitmap;
-static Htab *seqbase;
static void
ctxstrcall(char *buf, size_t sz, Node *n)
@@ -472,16 +471,16 @@ tyfreshen(Tysubst *subst, Type *orig)
pushenv(orig->env);
if (!subst) {
subst = mksubst();
- ty = tyspecialize(orig, subst, delayed, seqbase);
+ ty = tyspecialize(orig, subst, delayed);
substfree(subst);
} else {
- ty = tyspecialize(orig, subst, delayed, seqbase);
+ ty = tyspecialize(orig, subst, delayed);
}
ty->spec = orig->spec;
ty->nspec = orig->nspec;
base = basetype(ty);
if (base)
- htput(seqbase, ty, base);
+ ty->seqaux = base;
popenv(orig->env);
return ty;
}
@@ -543,7 +542,7 @@ tyresolve(Type *t)
t->trneed = mkbs();
bsput(t->trneed, tr->uid);
if (nameeq(t->spec[i]->trait[j], traittab[Tciter]->name))
- htput(seqbase, t, t->spec[i]->aux);
+ t->seqaux = t->spec[i]->aux;
}
}
@@ -1027,7 +1026,7 @@ tyrank(Type *t)
{
if (t->type == Tyvar) {
/* has associated iterator type */
- if (hthas(seqbase, t))
+ if (t->seqaux)
return 1;
else
return 0;
@@ -1118,10 +1117,10 @@ basetype(Type *a)
{
Type *t;
- t = htget(seqbase, a);
+ t = a->seqaux;
while (!t && a->type == Tyname) {
a = a->sub[0];
- t = htget(seqbase, a);
+ t = a->seqaux;
}
if (!t && (a->type == Tyslice || a->type == Tyarray || a->type == Typtr))
t = a->sub[0];
@@ -1732,7 +1731,7 @@ inferexpr(Node **np, Type *ret, int *sawret)
infersub(n, ret, sawret, &isconst);
b = mktyvar(n->loc);
t = mktyvar(n->loc);
- htput(seqbase, t, b);
+ t->seqaux = b;
unify(n, type(args[0]), t);
constrain(n, type(args[0]), traittab[Tcidx]);
constrain(n, type(args[1]), traittab[Tcint]);
@@ -1742,7 +1741,7 @@ inferexpr(Node **np, Type *ret, int *sawret)
infersub(n, ret, sawret, &isconst);
b = mktyvar(n->loc);
t = mktyvar(n->loc);
- htput(seqbase, t, b);
+ t->seqaux = b;
unify(n, type(args[0]), t);
constrain(n, type(args[1]), traittab[Tcint]);
constrain(n, type(args[1]), traittab[Tcnum]);
@@ -1956,7 +1955,7 @@ specializeimpl(Node *n)
substput(subst, tr->param, n->impl.type);
for (j = 0; j < tr->naux; j++)
substput(subst, tr->aux[j], n->impl.aux[j]);
- ty = tyspecialize(type(proto), subst, delayed, NULL);
+ ty = tyspecialize(type(proto), subst, delayed);
substfree(subst);
popenv(proto->decl.env);
@@ -2125,7 +2124,7 @@ infernode(Node **np, Type *ret, int *sawret)
if (b)
unify(n, e, b);
else
- htput(seqbase, t, e);
+ t->seqaux = e;
delayedcheck(n, curstab());
break;
case Nmatchstmt:
@@ -2190,7 +2189,7 @@ tyfix(Node *ctx, Type *orig, int noerr)
env = t->env;
if (env)
pushenv(env);
- base = htget(seqbase, orig);
+ base = orig->seqaux;
if (orig->type == Tyvar && hthas(delayed, orig)) {
d = htget(delayed, orig);
if (t->type == Tyvar) {
@@ -2235,7 +2234,7 @@ tyfix(Node *ctx, Type *orig, int noerr)
if (t->type == Tyvar && !noerr)
fatal(ctx, "underconstrained type %s near %s", tyfmt(buf, 1024, t), ctxstr(ctx));
if (base)
- htput(seqbase, t, tyfix(ctx, base, noerr));
+ t->seqaux = tyfix(ctx, base, noerr);
if (env)
popenv(env);
return t;
@@ -2380,7 +2379,7 @@ fixiter(Node *n, Type *ty, Type *base)
Node *impl;
ty = tysearch(ty);
- b = htget(seqbase, ty);
+ b = ty->seqaux;
if (!b)
return;
bestrank = -1;
@@ -2898,7 +2897,6 @@ initimpl(void)
Type *ty;
pushstab(file->file.globls);
- seqbase = mkht(tyhash, tyeq);
traitmap = zalloc(sizeof(Traitmap));
builtintraits();
for (i = 0; i < nimpltab; i++) {
@@ -2908,9 +2906,8 @@ initimpl(void)
pushenv(impl->impl.env);
ty = tf(impl->impl.type);
addtraittab(traitmap, tr, ty);
- if (tr->uid == Tciter) {
- htput(seqbase, tf(impl->impl.type), tf(impl->impl.aux[0]));
- }
+ if (tr->uid == Tciter)
+ ty->seqaux = tf(impl->impl.aux[0]);
popenv(impl->impl.env);
}
popstab();
diff --git a/parse/parse.h b/parse/parse.h
index 06b0b11..1bf0029 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -1,4 +1,4 @@
-#define Abiversion 15
+#define Abiversion 16
typedef struct Srcloc Srcloc;
typedef struct Tysubst Tysubst;
@@ -135,8 +135,7 @@ struct Type {
Traitspec **spec;
size_t nspec;
- //Node **traits; /* trait list */
- //size_t ntraits; /* trait list size */
+ Type *seqaux;
Type **gparam; /* Tygeneric: type parameters that match the type args */
size_t ngparam; /* Tygeneric: count of type parameters */
@@ -544,7 +543,7 @@ void substfree(Tysubst *subst);
void substput(Tysubst *subst, Type *from, Type *to);
Type *substget(Tysubst *subst, Type *from);
Node *specializedcl(Node *n, Type *param, Type *to, Node **name);
-Type *tyspecialize(Type *t, Tysubst *tymap, Htab *delayed, Htab *tybase);
+Type *tyspecialize(Type *t, Tysubst *tymap, Htab *delayed);
Node *genericname(Node *n, Type *param, Type *t);
void geninit(void);
diff --git a/parse/specialize.c b/parse/specialize.c
index 9088250..006662d 100644
--- a/parse/specialize.c
+++ b/parse/specialize.c
@@ -82,9 +82,9 @@ substfree(Tysubst *subst)
* replaced with type variables that we can unify
* against */
Type *
-tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
+tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed)
{
- Type *t, *ret, *tmp, *var, *base;
+ Type *t, *ret, *tmp, *var;
Traitspec *ts;
size_t i, narg;
Type **arg;
@@ -104,16 +104,11 @@ tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
ts = zalloc(sizeof(Traitspec));
ts->trait = t->spec[i]->trait;
ts->ntrait = t->spec[i]->ntrait;
- ts->param = tyspecialize(t->spec[i]->param, tsmap, delayed, trbase);
+ ts->param = tyspecialize(t->spec[i]->param, tsmap, delayed);
if (t->spec[i]->aux)
- ts->aux = tyspecialize(t->spec[i]->aux, tsmap, delayed, trbase);
+ ts->aux = tyspecialize(t->spec[i]->aux, tsmap, delayed);
lappend(&ret->spec, &ret->nspec, ts);
}
- tmp = htget(trbase, t);
- if (tmp) {
- tmp = tyspecialize(tmp, tsmap, delayed, trbase);
- htput(trbase, ret, tmp);
- }
break;
case Tygeneric:
var = mktyvar(t->loc);
@@ -124,8 +119,8 @@ tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
substput(tsmap, t->gparam[i], orig->arg[i]);
}
for (i = 0; i < t->ngparam; i++)
- lappend(&arg, &narg, tyspecialize(t->gparam[i], tsmap, delayed, trbase));
- ret = mktyname(t->loc, t->name, tyspecialize(t->sub[0], tsmap, delayed, trbase));
+ lappend(&arg, &narg, tyspecialize(t->gparam[i], tsmap, delayed));
+ ret = mktyname(t->loc, t->name, tyspecialize(t->sub[0], tsmap, delayed));
if (orig->type == Tyunres)
substpop(tsmap);
ret->arg = arg;
@@ -138,14 +133,10 @@ tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
var = mktyvar(t->loc);
substput(tsmap, t, var);
for (i = 0; i < t->narg; i++)
- lappend(&arg, &narg, tyspecialize(t->arg[i], tsmap, delayed, trbase));
- ret = mktyname(t->loc, t->name, tyspecialize(t->sub[0], tsmap, delayed, trbase));
+ lappend(&arg, &narg, tyspecialize(t->arg[i], tsmap, delayed));
+ ret = mktyname(t->loc, t->name, tyspecialize(t->sub[0], tsmap, delayed));
ret->arg = arg;
ret->narg = narg;
- if (trbase && hthas(trbase, orig) && !hthas(trbase, ret)) {
- base = htget(trbase, orig);
- htput(trbase, ret, tyspecialize(base, tsmap, delayed, trbase));
- }
tytab[var->tid] = ret;
break;
case Tystruct:
@@ -162,7 +153,7 @@ tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
for (i = 0; i < t->nmemb; i++) {
tmp = NULL;
if (ret->udecls[i]->etype)
- tmp = tyspecialize(t->udecls[i]->etype, tsmap, delayed, trbase);
+ tmp = tyspecialize(t->udecls[i]->etype, tsmap, delayed);
ret->udecls[i] = mkucon(t->loc, t->udecls[i]->name, ret, tmp);
ret->udecls[i]->utype = ret;
ret->udecls[i]->id = i;
@@ -173,7 +164,7 @@ tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
ret = t;
if (delayed && hthas(delayed, t)) {
tmp = htget(delayed, t);
- htput(delayed, ret, tyspecialize(tmp, tsmap, delayed, trbase));
+ htput(delayed, ret, tyspecialize(tmp, tsmap, delayed));
}
break;
default:
@@ -181,12 +172,14 @@ tyspecialize(Type *orig, Tysubst *tsmap, Htab *delayed, Htab *trbase)
ret = tydup(t);
substput(tsmap, t, ret);
for (i = 0; i < t->nsub; i++)
- ret->sub[i] = tyspecialize(t->sub[i], tsmap, delayed, trbase);
+ ret->sub[i] = tyspecialize(t->sub[i], tsmap, delayed);
} else {
ret = t;
}
break;
}
+ if (t->seqaux)
+ ret->seqaux = tyspecialize(t->seqaux, tsmap, delayed);
return ret;
}
@@ -197,7 +190,7 @@ static Type *
tysubst(Type *t, Tysubst *tsmap)
{
if (hasparams(t))
- return tyspecialize(t, tsmap, NULL, NULL);
+ return tyspecialize(t, tsmap, NULL);
else
return t;
}
diff --git a/parse/use.c b/parse/use.c
index cf9ba90..605b3be 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -236,6 +236,7 @@ typickle(FILE *fd, Type *ty)
if (ty->spec[i]->aux)
wrtype(fd, ty->spec[i]->aux);
}
+ wrtype(fd, ty->seqaux);
wrint(fd, ty->nsub);
switch (ty->type) {
case Tyunres:
@@ -312,6 +313,10 @@ traitpickle(FILE *fd, Trait *tr)
static void
wrtype(FILE *fd, Type *ty)
{
+ if (!ty) {
+ wrint(fd, 0);
+ return;
+ }
if (ty->tid >= Builtinmask)
die("Type id %d for %s too big", ty->tid, tystr(ty));
if (ty->vis == Visbuiltin)
@@ -326,7 +331,9 @@ rdtype(FILE *fd, Type **dest)
uintptr_t tid;
tid = rdint(fd);
- if (tid & Builtinmask) {
+ if (tid == 0) {
+ return;
+ } else if (tid & Builtinmask) {
*dest = mktype(Zloc, tid & ~Builtinmask);
} else {
typefix = xrealloc(typefix, (ntypefix + 1) * sizeof(typefix[0]));
@@ -382,6 +389,7 @@ tyunpickle(FILE *fd)
if (rdbool(fd))
rdtype(fd, &ty->spec[i]->aux);
}
+ rdtype(fd, &ty->seqaux);
ty->nsub = rdint(fd);
if (ty->nsub > 0)
ty->sub = zalloc(ty->nsub * sizeof(Type *));