Skip to content

Commit

Permalink
More simplification for permission expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoeilers committed Aug 30, 2024
1 parent 56d5860 commit 54cecc4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/scala/viper/silver/ast/utility/Simplifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,15 @@ object Simplifier {
case PermMinus(PermMinus(single)) => single
case PermMul(fst, FullPerm()) => fst
case PermMul(FullPerm(), snd) => snd
case root@PermMul(AnyPermLiteral(a, b), AnyPermLiteral(c, d)) =>
val product = Rational(a, b) * Rational(c, d)
FractionalPerm(IntLit(product.numerator)(root.pos, root.info), IntLit(product.denominator)(root.pos, root.info))(root.pos, root.info)
case PermMul(_, np@NoPerm()) if assumeWelldefinedness => np
case PermMul(np@NoPerm(), _) if assumeWelldefinedness => np

case PermMul(wc@WildcardPerm(), _) if assumeWelldefinedness => wc
case PermMul(_, wc@WildcardPerm()) if assumeWelldefinedness => wc

case root@PermGeCmp(a, b) if assumeWelldefinedness && a == b => TrueLit()(root.pos, root.info)
case root@PermLeCmp(a, b) if assumeWelldefinedness && a == b => TrueLit()(root.pos, root.info)
case root@PermGtCmp(a, b) if assumeWelldefinedness && a == b => FalseLit()(root.pos, root.info)
Expand All @@ -125,6 +131,16 @@ object Simplifier {
BoolLit(Rational(a, b) < Rational(c, d))(root.pos, root.info)
case root@PermLeCmp(AnyPermLiteral(a, b), AnyPermLiteral(c, d)) =>
BoolLit(Rational(a, b) <= Rational(c, d))(root.pos, root.info)
case root@EqCmp(AnyPermLiteral(a, b), AnyPermLiteral(c, d)) =>
BoolLit(Rational(a, b) == Rational(c, d))(root.pos, root.info)
case root@NeCmp(AnyPermLiteral(a, b), AnyPermLiteral(c, d)) =>
BoolLit(Rational(a, b) != Rational(c, d))(root.pos, root.info)

case root@PermLeCmp(NoPerm(), WildcardPerm()) =>
TrueLit()(root.pos, root.info)
case root@NeCmp(WildcardPerm(), NoPerm()) =>
TrueLit()(root.pos, root.info)

case DebugPermMin(e0@AnyPermLiteral(a, b), e1@AnyPermLiteral(c, d)) =>
if (Rational(a, b) < Rational(c, d)) {
e0
Expand All @@ -137,6 +153,9 @@ object Simplifier {
case root@PermAdd(AnyPermLiteral(a, b), AnyPermLiteral(c, d)) =>
val sum = Rational(a, b) + Rational(c, d)
FractionalPerm(IntLit(sum.numerator)(root.pos, root.info), IntLit(sum.denominator)(root.pos, root.info))(root.pos, root.info)
case PermAdd(NoPerm(), rhs) => rhs
case PermAdd(lhs, NoPerm()) => lhs
case PermSub(lhs, NoPerm()) => lhs

case root@GeCmp(IntLit(left), IntLit(right)) =>
BoolLit(left >= right)(root.pos, root.info)
Expand Down

0 comments on commit 54cecc4

Please sign in to comment.