@@ -10,7 +10,17 @@ trait PartialEvaluator extends SimplifierWithPC { self =>
1010 import symbols ._
1111 import exprOps ._
1212
13+ protected def strictlyPositive (tpe : Type , e : Expr ): Expr = (tpe match {
14+ case IntegerType () => GreaterThan (e, IntegerLiteral (0 ))
15+ case BVType (signed, size) => GreaterThan (e, BVLiteral (signed, 0 , size))
16+ case TupleType (tps) => and((1 to tps.length).map(i => strictlyPositive(tps(i- 1 ), TupleSelect (e,i))): _* )
17+ case _ => sys.error(s " Type $tpe is not supported for measures " )
18+ }).setPos(e)
19+
1320 override protected def simplify (e : Expr , path : Env ): (Expr , Boolean ) = e match {
21+ // case Annotated(e, Seq(Unchecked)) =>
22+ // simplify(e, path)
23+
1424 case fi @ FunctionInvocation (id, tps, args) =>
1525 val tfd = fi.tfd
1626 val (rargs, pargs) = args.map(simplify(_, path)).unzip
@@ -20,6 +30,23 @@ trait PartialEvaluator extends SimplifierWithPC { self =>
2030 case _ => false
2131 } (expr)
2232
33+ def validMeasure : Boolean = {
34+ println(" measure: " + measureOf(tfd.fullBody))
35+ measureOf(tfd.fullBody) match {
36+ case Some (measure) =>
37+ val nextMeasure = exprOps.replaceFromSymbols(tfd.params.zip(args).toMap, measure)
38+ println(" next: " + nextMeasure)
39+ val query = strictlyPositive(nextMeasure.getType, nextMeasure)
40+ println(" query: " + query)
41+ val result = path.implies(query)
42+
43+ println(" result: " + result)
44+ result
45+
46+ case None => false
47+ }
48+ }
49+
2350 def isProductiveUnfolding (inlined : Expr ): Boolean = {
2451 def isKnown (expr : Expr ): Boolean = expr match {
2552 case BooleanLiteral (_) => true
@@ -74,7 +101,7 @@ trait PartialEvaluator extends SimplifierWithPC { self =>
74101
75102 inlined
76103 .filterNot(containsChoose)
77- .filter(isProductiveUnfolding)
104+ .filter(expr => validMeasure || isProductiveUnfolding(expr) )
78105 .map(unfold)
79106 .getOrElse((
80107 FunctionInvocation (id, tps, rargs).copiedFrom(fi),
0 commit comments