Skip to content

Commit

Permalink
simsym: Precisely type the result of symif
Browse files Browse the repository at this point in the history
Previously, symif used a generic wrap call on its result, which works
for obvious types, but falls back to SExpr in harder cases like
tuinterpreted.  Prior to small lists, we had limited use of symif, so
this didn't cause problems, but small lists stress symif much more.

Modify symif to wrap its result in the type of its consequent (or
alternate, which must match).
  • Loading branch information
Austin Clements committed Aug 11, 2014
1 parent 4602631 commit a482c62
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion simsym.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,14 @@ def symeq(*exprs):
return symand([a == b for a, b in zip(exprs, exprs[1:])])

def symif(pred, cons, alt):
return wrap(z3.If(unwrap(pred), unwrap(cons), unwrap(alt)))
e = z3.If(unwrap(pred), unwrap(cons), unwrap(alt))
# Wrap the result in the type of the consequent, rather than a
# generic SExpr.
if isinstance(cons, Symbolic):
return type(cons)._wrap(e, None)
if isinstance(alt, Symbolic):
return type(alt)._wrap(e, None)
return wrap(e)

def distinct(*exprlist):
return wrap(z3.Distinct(*map(unwrap, exprlist)))
Expand Down Expand Up @@ -952,6 +959,7 @@ def wrap(ref):
return SArith._wrap(ref, None)
if isinstance(ref, z3.BoolRef):
return SBool._wrap(ref, None)
# XXX Could be a tuinterpreted
return SExpr._wrap(ref, None)

def wraplist(reflist):
Expand Down

0 comments on commit a482c62

Please sign in to comment.