summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-07-10 22:19:21 -0700
committerOri Bernstein <ori@eigenstate.org>2017-07-10 22:20:08 -0700
commit279038538923c87b8aa0ac155fc48ee95f7f9b59 (patch)
tree26ecaa2c6064bf6d4032a5a0de86179c1e6d4454
parent551d87b88e124e57e95b051539cfddbe8ea62180 (diff)
downloadmc-279038538923c87b8aa0ac155fc48ee95f7f9b59.tar.gz
Clean up conditions in trait satisfaction.
-rw-r--r--mi/dfcheck.c3
-rw-r--r--parse/infer.c17
2 files changed, 7 insertions, 13 deletions
diff --git a/mi/dfcheck.c b/mi/dfcheck.c
index b43ef9c..fc9664c 100644
--- a/mi/dfcheck.c
+++ b/mi/dfcheck.c
@@ -29,7 +29,8 @@ checkundef(Node *n, Reaching *r, Bitset *reach, Bitset *kill)
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;
diff --git a/parse/infer.c b/parse/infer.c
index 597b044..3f3f181 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -876,18 +876,11 @@ constrain(Node *ctx, Type *a, Trait *c)
}
}
-/* 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 @@ verifytraits(Node *ctx, Type *a, Type *b)
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 @@ tyfix(Node *ctx, Type *orig, int noerr)
}
}
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;