Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing termination measures #675

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class SliceEncoding(arrayEmb : SharedArrayEmbedding) extends LeafTypeEncoding {
* ensures soffset(result) == offset
* ensures slen(result) == len
* ensures scap(result) == cap
* dereases _
* }}}
*/
private val constructGenerator : FunctionGenerator[vpr.Type] = new FunctionGenerator[vpr.Type] {
Expand All @@ -357,6 +358,7 @@ class SliceEncoding(arrayEmb : SharedArrayEmbedding) extends LeafTypeEncoding {
val pre2 = synthesized(vpr.LeCmp(vpr.IntLit(0)(), lenDecl.localVar))("Slice length might be negative")
val pre3 = synthesized(vpr.LeCmp(lenDecl.localVar, capDecl.localVar))("Slice length might exceed capacity")
val pre4 = synthesized(vpr.LeCmp(vpr.Add(offsetDecl.localVar, capDecl.localVar)(), ctx.array.len(aDecl.localVar)()))("Slice capacity might exceed the capacity of the underlying array")
val pre5 = synthesized(termination.DecreasesWildcard(None))("This function is assumed to terminate")

// postconditions
val result = vpr.Result(ctx.slice.typ(typ))()
Expand All @@ -369,7 +371,7 @@ class SliceEncoding(arrayEmb : SharedArrayEmbedding) extends LeafTypeEncoding {
s"${Names.sliceConstruct}_${Names.serializeType(typ)}",
Seq(aDecl, offsetDecl, lenDecl, capDecl),
ctx.slice.typ(typ),
Seq(pre1, pre2, pre3, pre4),
Seq(pre1, pre2, pre3, pre4, pre5),
Seq(post1, post2, post3, post4),
None
)()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package viper.gobra.translator.library.slices

import viper.gobra.translator.library.arrays.Arrays
import viper.silver.plugin.standard.termination
import viper.gobra.translator.util.ViperUtil.synthesized
import viper.silver.{ast => vpr}

class SlicesImpl(val arrays : Arrays) extends Slices {
Expand Down Expand Up @@ -274,6 +276,7 @@ class SlicesImpl(val arrays : Arrays) extends Slices {
* {{{
* function sadd(left: Int, right: Int): Int
* ensures result == left + right
* decreases
* {
* left + right
* }
Expand All @@ -284,7 +287,8 @@ class SlicesImpl(val arrays : Arrays) extends Slices {
val rDecl = vpr.LocalVarDecl("right", vpr.Int)()
val body : vpr.Exp = vpr.Add(lDecl.localVar, rDecl.localVar)()
val post : vpr.Exp = vpr.EqCmp(vpr.Result(vpr.Int)(), body)()
vpr.Function("sadd", Seq(lDecl, rDecl), vpr.Int, Seq(), Seq(post), Some(body))()
val pre : vpr.Exp = synthesized(termination.DecreasesTuple(Seq.empty, None))("Termination measure")
vpr.Function("sadd", Seq(lDecl, rDecl), vpr.Int, Seq(pre), Seq(post), Some(body))()
}

/**
Expand Down
Loading