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

Add missing termination measures in the sequence and array encodings #758

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -362,12 +362,14 @@ class ArrayEncoding extends TypeEncoding with SharedArrayEmbedding {
Seq(vpr.Trigger(Seq(trigger))()),
vpr.Implies(boundaryCondition(vIdx.localVar, t.len)(src), idxEq)()
)()
val terminationMeasure =
jcp19 marked this conversation as resolved.
Show resolved Hide resolved
synthesized(termination.DecreasesWildcard(None))("This function is assumed to terminate")

vpr.Function(
name = s"${Names.arrayDefaultFunc}_${t.serialize}",
formalArgs = Seq.empty,
typ = vResType,
pres = Seq.empty,
pres = Seq(terminationMeasure),
posts = Vector(lenEq, arrayEq),
body = None
)()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import viper.gobra.translator.util.FunctionGenerator
import viper.gobra.translator.util.ViperUtil.synthesized
import viper.gobra.translator.util.ViperWriter.CodeWriter
import viper.gobra.util.Violation
import viper.silver.plugin.standard.termination
import viper.silver.{ast => vpr}

class SequenceEncoding extends LeafTypeEncoding {
Expand Down Expand Up @@ -245,6 +246,7 @@ class SequenceEncoding extends LeafTypeEncoding {

// preconditions
val pre1 = synthesized(vpr.LeCmp(vpr.IntLit(0)(), nDecl.localVar))("Sequence length might be negative")
val pre2 = synthesized(termination.DecreasesWildcard(None))("This function is assumed to terminate")
jcp19 marked this conversation as resolved.
Show resolved Hide resolved

// postconditions
val post1 = vpr.EqCmp(vResultLength, nDecl.localVar)()
Expand All @@ -262,7 +264,7 @@ class SequenceEncoding extends LeafTypeEncoding {
name = s"${Names.emptySequenceFunc}_${Names.serializeType(t)}",
formalArgs = Vector(nDecl),
typ = vResultType,
pres = Vector(pre1),
pres = Vector(pre1, pre2),
posts = Vector(post1, post2),
body = None
)()
Expand Down
Loading