summaryrefslogtreecommitdiff
path: root/parse/infer.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-01-02 22:14:43 -0800
committerOri Bernstein <ori@eigenstate.org>2018-01-11 22:16:11 -0800
commit9424339d8d453f5c559edd5d23549d662d1c9d8d (patch)
treefc725c32315c782b60eae6d48a1bb9171d3040b4 /parse/infer.c
parente6967548eec255e4518b1cdff5955d4b333f103b (diff)
downloadmc-9424339d8d453f5c559edd5d23549d662d1c9d8d.tar.gz
Fix how we bind types.
Now we accept most valid programs, and reject most invalid ones.
Diffstat (limited to 'parse/infer.c')
-rw-r--r--parse/infer.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/parse/infer.c b/parse/infer.c
index 7e6d6d1..24f5f88 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -37,6 +37,7 @@ static int tryconstrain(Type *ty, Trait *tr, int update);
static Type *tyfreshen(Tysubst *subst, Type *orig);
static Type *tf(Type *t);
+static Type *basetype(Type *a);
static Type *unify(Node *ctx, Type *a, Type *b);
static Type *tyfix(Node *ctx, Type *orig, int noerr);
@@ -463,7 +464,7 @@ needfreshen(Type *t)
static Type *
tyfreshen(Tysubst *subst, Type *orig)
{
- Type *ty;
+ Type *ty, *base;
if (!needfreshen(orig))
return orig;
@@ -477,6 +478,9 @@ tyfreshen(Tysubst *subst, Type *orig)
}
ty->spec = orig->spec;
ty->nspec = orig->nspec;
+ base = basetype(ty);
+ if (base)
+ htput(seqbase, ty, base);
popenv(orig->env);
return ty;
}
@@ -2594,7 +2598,8 @@ typesub(Node *n, int noerr)
typesub(n->iterstmt.elt, noerr);
typesub(n->iterstmt.seq, noerr);
typesub(n->iterstmt.body, noerr);
- additerspecialization(n, curstab());
+ if (!ingeneric)
+ additerspecialization(n, curstab());
break;
case Nmatchstmt:
typesub(n->matchstmt.val, noerr);
@@ -2693,6 +2698,8 @@ specialize(void)
tr = traittab[Tciter];
assert(tr->nproto == 2);
ty = exprtype(n->iterstmt.seq);
+ if (ty->type == Typaram)
+ continue;
it = itertype(n->iterstmt.seq, mktype(n->loc, Tybool));
d = specializedcl(tr->proto[0], ty, it, &name);
@@ -2855,6 +2862,7 @@ initimpl(void)
Type *ty;
pushstab(file->file.globls);
+ seqbase = mkht(tyhash, tyeq);
traitmap = zalloc(sizeof(Traitmap));
builtintraits();
for (i = 0; i < nimpltab; i++) {