Skip to content

Commit

Permalink
Fix issue 621 (#622)
Browse files Browse the repository at this point in the history
* Fix 621

* fix identation
  • Loading branch information
jcp19 authored Feb 10, 2023
1 parent 64122cf commit e498930
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import viper.gobra.frontend.info.base.Type
import viper.gobra.frontend.info.base.Type._
import viper.gobra.frontend.info.implementation.TypeInfoImpl
import viper.gobra.frontend.info.implementation.typing.BaseTyping
import viper.gobra.util.TypeBounds
import viper.gobra.util.Violation.violation

import scala.annotation.unused
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import viper.gobra.translator.encodings.combinators.TypeEncoding
import viper.gobra.translator.context.Context
import viper.gobra.translator.library.embeddings.EmbeddingParameter
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}

import scala.annotation.unused
Expand Down Expand Up @@ -318,7 +320,10 @@ class ArrayEncoding extends TypeEncoding with SharedArrayEmbedding {
name = s"${Names.arrayConversionFunc}_${t.serialize}",
formalArgs = Vector(variable(ctx)(x)),
typ = vResultType,
pres = Vector(pure(addressFootprint(ctx)(x, in.WildcardPerm(Source.Parser.Internal)))(ctx).res),
pres = Vector(
pure(addressFootprint(ctx)(x, in.WildcardPerm(Source.Parser.Internal)))(ctx).res,
synthesized(termination.DecreasesWildcard(None))("This function is assumed to terminate")
),
posts = Vector(post),
body = None
)()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import viper.gobra.translator.context.Context
import viper.gobra.translator.library.embeddings.EmbeddingComponent
import viper.gobra.translator.Names
import viper.gobra.translator.util.FunctionGenerator
import viper.gobra.translator.util.ViperUtil.synthesized
import viper.gobra.translator.util.ViperWriter.CodeLevel.pure
import viper.silver.plugin.standard.termination

class SharedArrayComponentImpl extends SharedArrayComponent {

Expand Down Expand Up @@ -48,7 +50,7 @@ class SharedArrayComponentImpl extends SharedArrayComponent {
name = s"${Names.arrayNilFunc}_${t.serialize}",
formalArgs = Seq.empty,
typ = vResType,
pres = Seq.empty,
pres = Seq(synthesized(termination.DecreasesWildcard(None))("This function is assumed to terminate")),
posts = Vector(vpr.EqCmp(ctx.array.len(vpr.Result(vResType)())(), vpr.IntLit(1)())(), forall),
body = None
)()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,4 @@ trait TypeEncoding extends Generator {
val (pos, info, errT) = src.vprMeta
node(pos, info, errT)(ctx)
}

/** Adds simple (source) information to a node without source information. */
protected def synthesized[T](node: (vpr.Position, vpr.Info, vpr.ErrorTrafo) => T)(comment: String): T =
node(vpr.NoPosition, vpr.SimpleInfo(Seq(comment)), vpr.NoTrafos)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.bitbucket.inkytonik.kiama.==>
import viper.gobra.ast.{internal => in}
import viper.gobra.translator.context.Context
import viper.gobra.translator.encodings.combinators.Encoding
import viper.gobra.translator.util.ViperUtil.synthesized
import viper.gobra.translator.util.ViperWriter.MemberLevel.unit
import viper.gobra.translator.util.ViperWriter.MemberWriter
import viper.silver.{ast => vpr}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import viper.gobra.translator.Names
import viper.gobra.translator.encodings.combinators.LeafTypeEncoding
import viper.gobra.translator.context.Context
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.{ast => vpr}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import viper.gobra.translator.encodings.arrays.SharedArrayEmbedding
import viper.gobra.translator.encodings.combinators.LeafTypeEncoding
import viper.gobra.translator.context.Context
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.verifier.{errors => err}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import viper.gobra.translator.Names
import viper.gobra.translator.encodings.combinators.TypeEncoding
import viper.gobra.translator.context.Context
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.{ast => vpr}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package viper.gobra.translator.library.embeddings
import viper.gobra.translator.Names
import viper.gobra.translator.context.Context
import viper.gobra.translator.library.Generator
import viper.gobra.translator.util.ViperUtil.synthesized
import viper.silver.{ast => vpr}
import viper.silver.plugin.standard.termination

Expand Down Expand Up @@ -149,7 +150,4 @@ object EmbeddingComponent {
genUnboxFuncMap += (id -> unbox)
}
}

private def synthesized[T](node: (vpr.Position, vpr.Info, vpr.ErrorTrafo) => T)(comment: String): T =
node(vpr.NoPosition, vpr.SimpleInfo(Seq(comment)), vpr.NoTrafos)
}
4 changes: 4 additions & 0 deletions src/main/scala/viper/gobra/translator/util/ViperUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ object ViperUtil {

s.reduceWithContext(Nil, addDecls, combineResults)
}

/** Adds simple (source) information to a node without source information. */
def synthesized[T](node: (Position, Info, ErrorTrafo) => T)(comment: String): T =
node(NoPosition, SimpleInfo(Seq(comment)), NoTrafos)
}
15 changes: 15 additions & 0 deletions src/test/resources/regressions/issues/000621.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

package pkg

type A struct {
x [3]int
}

ghost
requires acc(&a.x)
decreases
pure func f(a *A) int {
return let x := a.x in x[0]
}

0 comments on commit e498930

Please sign in to comment.