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

Have isExpressionFresh consider arguments when computing freshness of a function call #1505

Merged
merged 1 commit into from
Apr 12, 2024
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 @@ -701,7 +701,7 @@ trait EffectsAnalyzer extends oo.CachingPhase {
val specced = BodyWithSpecs(symbols.simplifyLets(fi.inlined))
specced.bodyOpt
.map(specced.wrapLets)
.forall(isExpressionFresh)
.forall(rec(_, bindings))

// other function invocations always return a fresh expression, by hypothesis (global assumption)
case (_: FunctionInvocation | _: ApplyLetRec | _: Application) => true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import stainless.lang._

object FreshExpr {
object FreshExpr1 {
case class C1(var c2: C2)
case class C2(var c3: C3)
case class C3(var bi: BigInt)
Expand Down
18 changes: 18 additions & 0 deletions frontends/benchmarks/imperative/valid/FreshExpr2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import stainless.lang._

object FreshExpr2 {

def iden(arr: Array[Int]) = arr

// Recursive functions must return fresh expression
def counting(i: Int): Array[Int] = {
require(0 <= i && i <= 10)
decreases(10 - i)
if (i < 10) {
counting(i + 1)
} else {
val b = Array.fill(0)(0)
iden(b) // This is a fresh expression
}
}
}