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

Fix issue 796 #800

Merged
merged 6 commits into from
Nov 27, 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 @@ -105,7 +105,12 @@ trait StmtTyping extends BaseTyping { this: TypeInfoImpl =>
}
if (firstChecks.isEmpty) latterChecks else firstChecks

case n@PForStmt(_, cond, _, _, _) => isExpr(cond).out ++ comparableTypes.errors(exprType(cond), BooleanT)(n)
case n@PForStmt(_, cond, _, spec, _) =>
val isGhost = isEnclosingGhost(n)
val noTerminationMeasureMsg = "Loop occurring in ghost context does not have a termination measure"
isExpr(cond).out ++
comparableTypes.errors(exprType(cond), BooleanT)(n) ++
error(n, noTerminationMeasureMsg, isGhost && spec.terminationMeasure.isEmpty)

case PShortForRange(range, shorts, _, _, _) =>
underlyingType(exprType(range.exp)) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func ParallelSum(s []int) (res int) {
invariant forall j int :: 0 <= j && j < n ==> acc(&s[j], 1/2)
invariant forall j int :: 0 <= j && j < n ==> tokens[j] == locHasVal!<&seenSlice[j],s[j]!>
invariant forall j int :: 0 <= j && j < n ==> (j < i ? acc(&seenSlice[j], 1/2) && seenSlice[j] == s[j] : sync.InjEval(tokens[j], j))
decreases n - i
for i:=0; i < n; i++ {
unfold sync.InjEval(tokens[i], i)
unfold locHasVal!<&seenSlice[i],s[i]!>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func SearchReplace(s []int, x, y int) {
invariant forall j int :: 0 <= j &&
j < (i == len(seqs) ? len(s) : i * workRange) ==>
acc(&s[j]) && s[j] == (s0[j] == x ? y : s0[j])
decreases len(pseqs) - i
for i := 0; i != len(pseqs); i++ {
unfold sync.InjEval(pseqs[i],i)
low := i * workRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func ParallelSum(s []int) (res int) {
invariant forall j int :: 0 <= j && j < n ==> acc(&s[j], 1/2)
invariant forall j int :: 0 <= j && j < n ==> tokens[j] == locHasVal!<&seenSlice[j],s[j]!>
invariant forall j int :: 0 <= j && j < n ==> (j < i ? acc(&seenSlice[j], 1/2) && seenSlice[j] == s[j] : sync.InjEval(tokens[j], j))
decreases n - i
for i:=0; i < n; i++ {
unfold sync.InjEval(tokens[i], i)
unfold locHasVal!<&seenSlice[i],s[i]!>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func SearchReplace(s []int, x, y int) {
invariant forall j int :: 0 <= j &&
j < (i == len(seqs) ? len(s) : i * workRange) ==>
acc(&s[j]) && s[j] == (s0[j] == x ? y : s0[j])
decreases len(pseqs) - i
for i := 0; i != len(pseqs); i++ {
unfold sync.InjEval(pseqs[i],i)
low := i * workRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func ParallelSum(s []int) (res int) {
invariant forall j int :: 0 <= j && j < n ==> acc(&s[j], 1/2)
invariant forall j int :: 0 <= j && j < n ==> tokens[j] == locHasVal!<&seenSlice[j],s[j]!>
invariant forall j int :: 0 <= j && j < n ==> (j < i ? acc(&seenSlice[j], 1/2) && seenSlice[j] == s[j] : sync.InjEval(tokens[j], j))
decreases n - i
for i:=0; i < n; i++ {
unfold sync.InjEval(tokens[i], i)
unfold locHasVal!<&seenSlice[i],s[i]!>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func SearchReplace(s []int, x, y int) {
invariant forall j int :: 0 <= j &&
j < (i == len(seqs) ? len(s) : i * workRange) ==>
acc(&s[j]) && s[j] == (s0[j] == x ? y : s0[j])
decreases len(pseqs) - i
for i := 0; i != len(pseqs); i++ {
unfold sync.InjEval(pseqs[i],i)
low := i * workRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ package pkg

requires 0 < len(xs)
func foo(ghost xs seq[bool]) {
//:: ExpectedOutput(for_loop_error:seq_index_exceeds_length_error)
ghost for ;xs[42]; { }
ghost {
decreases
//:: ExpectedOutput(for_loop_error:seq_index_exceeds_length_error)
for ;xs[42]; { break }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ package pkg

requires 0 < len(xs)
func foo(ghost xs seq[bool]) {
//:: ExpectedOutput(for_loop_error:seq_index_negative_error)
ghost for ;xs[-1]; { }
ghost {
decreases
//:: ExpectedOutput(for_loop_error:seq_index_negative_error)
for ;xs[-1]; { break }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ func example7(ghost xs seq[bool]) {

requires 0 < len(xs)
func example8(ghost xs seq[bool]) {
ghost for ;xs[0]; { }
ghost {
decreases
for ;xs[0]; { break }
}
}
20 changes: 20 additions & 0 deletions src/test/resources/regressions/issues/000796.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

package issue000796

func m1() {
//:: ExpectedOutput(type_error)
ghost for {

}
}

func m2() {
ghost {
//:: ExpectedOutput(type_error)
for {

}
}
}
Loading