ref: 279038538923c87b8aa0ac155fc48ee95f7f9b59
parent: 551d87b88e124e57e95b051539cfddbe8ea62180
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Jul 10 18:19:21 EDT 2017
Clean up conditions in trait satisfaction.
--- a/mi/dfcheck.c
+++ b/mi/dfcheck.c
@@ -29,7 +29,8 @@
return;
for (j = 0; j < r->ndefs[did]; j++) {
t = tybase(exprtype(n));
- if (t->type == Tystruct || t->type == Tyunion || t->type == Tyarray || t->type == Tytuple || t->type == Tyvoid)
+ if (t->type == Tystruct || t->type == Tyunion || t->type == Tyarray ||
+ t->type == Tytuple || t->type == Tyvoid)
continue;
if (bshas(kill, r->defs[did][j]))
continue;
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -876,18 +876,11 @@
}
}
-/* does b satisfy all the constraints of a? */
static int
-checktraits(Type *a, Type *b)
+satisfiestraits(Type *a, Type *b)
{
- /* a has no traits to satisfy */
- if (!a->traits)
+ if (!a->traits || bscount(a->traits) == 0)
return 1;
- /* b satisfies no traits; only valid if a requires none */
- if (!b->traits)
- return bscount(a->traits) == 0;
- /* if a->traits is a subset of b->traits, all of
- * a's constraints are satisfied by b. */
return bsissubset(a->traits, b->traits);
}
@@ -900,7 +893,7 @@
char traitbuf[64], abuf[64], bbuf[64];
char asrc[64], bsrc[64];
- if (!checktraits(a, b)) {
+ if (!satisfiestraits(a, b)) {
sep = "";
n = 0;
for (i = 0; bsiter(a->traits, &i); i++) {
@@ -2142,9 +2135,9 @@
}
}
if (t->type == Tyvar) {
- if (hastrait(t, traittab[Tcint]) && checktraits(t, tyint))
+ if (hastrait(t, traittab[Tcint]) && satisfiestraits(t, tyint))
t = tyint;
- if (hastrait(t, traittab[Tcfloat]) && checktraits(t, tyflt))
+ if (hastrait(t, traittab[Tcfloat]) && satisfiestraits(t, tyflt))
t = tyflt;
} else if (!t->fixed) {
t->fixed = 1;