Skip to content

Commit

Permalink
Premise now adds to path conditions without runtime-checking (assumed…
Browse files Browse the repository at this point in the history
…). Need to fix evalConstructor.
  • Loading branch information
robby-phd committed Sep 11, 2023
1 parent 29acc78 commit 92425f2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
6 changes: 5 additions & 1 deletion jvm/src/test/scala/org/sireum/logika/example/field-access.sc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ Deduce(
Old(baz) Baz(Foo(0), Bar(10), 100)(foo =
Baz(Foo(0), Bar(10), 100).foo(x = 1)
) by Premise,
baz Old(baz)(bar = Bar(2)) by Premise
baz Baz(
Foo(1),
Baz(Foo(0), Bar(10), 100).bar,
Baz(Foo(0), Bar(10), 100).z
)(bar = Bar(2)) by Premise
)
assert(baz.foo.x == 1 & baz.bar.y == 2 & baz.z == 100)

4 changes: 2 additions & 2 deletions jvm/src/test/scala/org/sireum/logika/example/oop.sc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ object B {
a.x = a.x + inc
a.y = a.y + a.x
Deduce(
Old(a) At(a, 0)(x = At(a, 0).x + B.inc) by Premise,
a Old(a)(y = Old(a).y + Old(a).x) by Premise
Old(a) At(a, 0)(x = At(a, 0).x + B.inc) by Premise
//FIXME evalConstructor: a ≡ At(a, 0)(x = At(a, 0).x + B.inc)(y = Old(a).y + Old(a).x) by Premise
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions jvm/src/test/scala/org/sireum/logika/example/premise.sc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def testIdString(): Unit = {
//@formatter:off
At[Z]("addY.n", 0) == 0 by Premise,
At[Z]("addY.n", 1) == 1 by Premise,
At(y, 0) + At[Z]("addY.n", 0) == At(y, 0) + 0 by Premise,
At(y, 1) == At(y, 0) + At[Z]("addY.n", 0) by Premise,
y == At(y, 0) + 0 + 1 by Premise
//@formatter:on
)
Expand All @@ -128,7 +128,7 @@ def testNameString(): Unit = {
//@formatter:off
At[Z]("addFooY.n", 0) == 0 by Premise,
At[Z]("addFooY.n", 1) == 1 by Premise,
At(Foo.y, 0) + At[Z]("addFooY.n", 0) == At(Foo.y, 0) + 0 by Premise,
At(Foo.y, 1) == At(Foo.y, 0) + 0 by Premise,
Foo.y == At(Foo.y, 0) + 0 + 1 by Premise
//@formatter:on
)
Expand Down
20 changes: 14 additions & 6 deletions shared/src/main/scala/org/sireum/logika/Logika.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,9 @@ import Util._
case res: AST.ResolvedInfo.Tuple =>
assert(receiverOpt.nonEmpty)
return evalTupleProjection(res)
case AST.ResolvedInfo.BuiltIn(AST.ResolvedInfo.BuiltIn.Kind.Apply) =>
assert(receiverOpt.nonEmpty)
return evalExp(split, smt2, cache, rtCheck, state, receiverOpt.get, reporter)
case _ =>
reporter.warn(e.posOpt, kind, s"Not currently supported: $e")
return ISZ((state(status = State.Status.Error), State.errorValue))
Expand Down Expand Up @@ -1697,12 +1700,16 @@ import Util._
case _ =>
}
val s4 = s3.addClaim(State.Claim.Let.AdtLit(sym, args.toIS[Option[State.Value]].map((vOpt: Option[State.Value]) => vOpt.get)))
val (s5, vs) = addValueInv(this, smt2, cache, T, s4, sym, attr.posOpt.get, reporter)
var s6 = s5
for (v <- vs if s6.ok) {
s6 = evalAssertH(T, smt2, cache, st"Invariant on ${(ti.name, ".")} construction".render, s6, v, attr.posOpt, reporter)
if (rtCheck) {
val (s5, vs) = addValueInv(this, smt2, cache, T, s4, sym, attr.posOpt.get, reporter)
var s6 = s5
for (v <- vs if s6.ok) {
s6 = evalAssertH(T, smt2, cache, st"Invariant on ${(ti.name, ".")} construction".render, s6, v, attr.posOpt, reporter)
}
r = r :+ ((s4(nextFresh = s6.nextFresh, status = s6.status), sym))
} else {
r = r :+ ((s4, sym))
}
r = r :+ ((s4(nextFresh = s6.nextFresh, status = s6.status), sym))
} else {
r = r :+ ((s2, State.errorValue))
}
Expand Down Expand Up @@ -1823,7 +1830,8 @@ import Util._
def evalOld(exp: AST.Exp.Old): (State, State.Value) = {
for (i <- state.claims.size - 1 to 0 by -1) {
state.claims(i) match {
case c: State.Claim.Old => return (state, c.value)
case c: State.Claim.Old =>
return (state, c.value)
case _ =>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ object AutoPlugin {
|}""".render)
}
val (stat, nextFresh, premises, conclusion) =
logika.evalRegularStepClaim(smt2, cache, state, step.claim, step.id.posOpt, reporter)
logika.evalRegularStepClaimRtCheck(smt2, cache, F, state, step.claim, step.id.posOpt, reporter)
return Plugin.Result(stat, nextFresh, premises :+ conclusion)
} else if (id == "Premise") {
AutoPlugin.detectOrIntro(logika.th, step.claim, pathConditions) match {
Expand All @@ -315,7 +315,7 @@ object AutoPlugin {
reporter.inform(pos, Logika.Reporter.Info.Kind.Verified, acceptMsg.render)
}
val (stat, nextFresh, premises, conclusion) =
logika.evalRegularStepClaim(smt2, cache, state, step.claim, step.id.posOpt, reporter)
logika.evalRegularStepClaimRtCheck(smt2, cache, F, state, step.claim, step.id.posOpt, reporter)
return Plugin.Result(stat, nextFresh, premises :+ conclusion)
case _ =>
reporter.error(posOpt, Logika.kind,
Expand Down

0 comments on commit 92425f2

Please sign in to comment.