-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove ensuring clause in ghost elimination (#1454)
- Loading branch information
1 parent
d941894
commit 92ee799
Showing
6 changed files
with
116 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
sbt-plugin/src/sbt-test/sbt-plugin/ghost/tailrec/TailRec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package test | ||
|
||
import stainless._ | ||
import stainless.annotation.{ghost => ghostAnnot, _} | ||
import stainless.lang._ | ||
import StaticChecks._ | ||
|
||
object Main { | ||
import stainless.lang.WhileDecorations | ||
|
||
def loop1(count: Long, l1: Long, l2: Long, l3: Long): Long = { | ||
require(count >= 0) | ||
decreases(count) | ||
if (count == 0) l1 | ||
else loop1(count - 1, l1, l2, l3) | ||
}.ensuring(_ == l1) | ||
|
||
def loop2(count: Long, l1: Long, l2: Long, l3: Long): Long = { | ||
require(count >= 0) | ||
decreases(count) | ||
if (count == 0) l1 | ||
else { | ||
val myRes = loop2(count - 1, l1, l2, l3) | ||
ghost { | ||
assert(myRes == l1) | ||
} | ||
myRes | ||
} | ||
}.ensuring(_ == l1) | ||
|
||
def whileLoop(upto: Long): Unit = { | ||
var i: Long = 0 | ||
(while(i < upto) { | ||
decreases(upto - i) | ||
i += 1 | ||
}).invariant(i >= 0) | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
loop1(100000, 1, 2, 3) | ||
loop2(100000, 1, 2, 3) | ||
whileLoop(10000) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
> + tailrec/run | ||
> + basic/run | ||
$ exists basic/target/scala-2.13/classes/test/Main.class | ||
$ exists basic/target/scala-3.3.0/classes/test/Main.class | ||
$ absent basic/target/sneakyGhostCalled basic/target/insideGhostCalled | ||
> + actor-tests/compile | ||
> + actor-tests/compile |