forked from epfl-lara/stainless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9290a38
commit 854e4f4
Showing
26 changed files
with
525 additions
and
73 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
2 changes: 1 addition & 1 deletion
2
...marks/extraction/invalid/ImpurePure.scala → ...arks/extraction/invalid/ImpurePure1.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
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,12 @@ | ||
import stainless.annotation.pure | ||
|
||
object ImpurePure2 { | ||
case class Box(var value: Int) | ||
|
||
@pure | ||
def outer(b: Box): Unit = { // A lying "pure" function! | ||
def inner: Unit = { | ||
b.value = 1234 | ||
} | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
frontends/benchmarks/extraction/invalid/InnerfunArgAliasing2.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,24 @@ | ||
import stainless._ | ||
import stainless.lang._ | ||
import stainless.annotation._ | ||
|
||
object InnerfunArgAliasing2 { | ||
|
||
case class Box(var value: Int) | ||
case class BBox(var box: Box) | ||
|
||
def outer(x: BBox, y: BBox, cond: Boolean): Unit = { | ||
val z = if (cond) y else x | ||
|
||
def inner(innoncentLooking: Box): Unit = { | ||
val oldX = x.box.value | ||
innoncentLooking.value = 1234 | ||
assert(innoncentLooking.value == 1234) | ||
// This must hold because we assume x.box and innoncentLooking are disjoint | ||
assert(x.box.value == oldX) | ||
} | ||
|
||
// Illegal aliasing due to z.box aliasing x.box for cond = false | ||
inner(z.box) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
frontends/benchmarks/extraction/invalid/InnerfunArgAliasing3.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,26 @@ | ||
import stainless._ | ||
import stainless.lang._ | ||
import stainless.annotation._ | ||
|
||
object InnerfunArgAliasing3 { | ||
|
||
case class Box(var value: Int) | ||
|
||
def outer(boxes: Array[Box], i: Int, j: Int): Unit = { | ||
require(0 <= i && i < boxes.length) | ||
require(0 <= j && j < boxes.length) | ||
|
||
val boxi = boxes(i) | ||
|
||
def inner(innoncentLooking: Box): Unit = { | ||
val oldI = boxi.value | ||
innoncentLooking.value = 1234 | ||
assert(innoncentLooking.value == 1234) | ||
// This must hold because we assume boxi and innoncentLooking are disjoint | ||
assert(boxi.value == oldI) | ||
} | ||
|
||
// Illegal aliasing due to boxi aliasing boxes(j) for i == j | ||
inner(boxes(j)) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
frontends/benchmarks/extraction/invalid/InnerfunArgAliasing4.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,27 @@ | ||
import stainless._ | ||
import stainless.lang._ | ||
import stainless.annotation._ | ||
|
||
object InnerfunArgAliasing4 { | ||
|
||
case class Box(var value: Int) | ||
|
||
def outer(boxes: Array[Box], i: Int, j: Int, z: Int): Unit = { | ||
require(0 <= i && i < boxes.length) | ||
require(0 <= j && j < boxes.length) | ||
require(0 <= z && z < boxes.length) | ||
|
||
val boxi = boxes(i) | ||
|
||
def inner(innoncentLooking: Box): Unit = { | ||
val oldI = boxi.value | ||
innoncentLooking.value = 1234 | ||
assert(innoncentLooking.value == 1234) | ||
// This must hold because we assume boxi and innoncentLooking are disjoint | ||
assert(boxi.value == oldI) | ||
} | ||
|
||
// Illegal aliasing due to boxi aliasing boxes(z) for i == z and j != z | ||
inner(boxes.updated(j, Box(123))(z)) | ||
} | ||
} |
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,13 @@ | ||
import stainless.annotation._ | ||
|
||
object i1274a { | ||
@extern | ||
def f(x: BigInt): Unit = { | ||
var t = x | ||
t += 1 | ||
// This require is not properly extracted into a spec (due to having impure constructs before) | ||
// It will disappear because bodies of @extern functions are removed | ||
// As this is in general not the behavior one expects, we should reject the program. | ||
require(t >= 10) | ||
} | ||
} |
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,16 @@ | ||
import stainless.annotation._ | ||
|
||
object i1274b { | ||
@extern | ||
def f(x: BigInt, y: BigInt): Unit = { | ||
require(x >= 10) | ||
val t = x.toString // Unsupported construct | ||
// This extern function contract still misses the following require | ||
// but we can't resume the extraction after having encountered an | ||
// unsupported feature. We must reject to program because this require | ||
// will be erased, akin to SneakySpecsInExtern1. | ||
require(x >= y) | ||
} | ||
|
||
def callF: Unit = f(10, 10) | ||
} |
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,10 @@ | ||
import stainless._ | ||
import stainless.lang._ | ||
import stainless.annotation._ | ||
|
||
object PureFnWithInnerFn { | ||
@pure | ||
def outer: Unit = { | ||
def inner: Unit = () | ||
} | ||
} |
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,14 @@ | ||
object i1268 { | ||
case class Box(var value: Int) | ||
|
||
def outer(cond: Boolean): Unit = { | ||
val box = Box(123) | ||
assert(box.value == 123) | ||
|
||
def inner: Unit = { | ||
assert(box.value == 123) // invalid (though we never actually call inner) | ||
} | ||
|
||
if (cond) box.value = 456 | ||
} | ||
} |
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,9 @@ | ||
import stainless.io._ | ||
|
||
object i1272 { | ||
|
||
def writing(fos: FileOutputStream): Unit = { | ||
// Invalid, we need fos.isOpen | ||
fos.write(1) | ||
} | ||
} |
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,12 @@ | ||
object i1268a { | ||
case class Box(var value: Int) | ||
|
||
def outer: Unit = { | ||
val box = Box(123) | ||
assert(box.value == 123) | ||
|
||
def inner: Unit = { | ||
assert(box.value == 123) | ||
} | ||
} | ||
} |
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,22 @@ | ||
import stainless.lang._ | ||
|
||
object i1268b { | ||
case class Box(var value: BigInt) { | ||
def increment: Box = { | ||
value += 1 | ||
this | ||
} | ||
} | ||
|
||
def outer(b1: Box): Unit = { | ||
val oldb1 = b1.value | ||
val b2 = freshCopy(b1).increment | ||
assert(b1.value == oldb1) | ||
assert(b2.value == b1.value + 1) | ||
|
||
def inner: Unit = { | ||
assert(b1.value == oldb1) | ||
assert(b2.value == b1.value + 1) | ||
} | ||
} | ||
} |
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,26 @@ | ||
import stainless._ | ||
import stainless.lang._ | ||
import StaticChecks._ | ||
|
||
object i1269 { | ||
case class Box(var value: Int) | ||
|
||
def outer1(b: Box): Unit = { | ||
require(b.value == 123) | ||
|
||
def inner1a: Unit = ().ensuring(_ => snapshot(b).value == 123) | ||
|
||
def inner1b(v: Int): Unit = { | ||
require(snapshot(b).value == v) | ||
assert(v == 123) | ||
} | ||
} | ||
|
||
def outer2(b: Box): Unit = { | ||
require(b.value == 123) | ||
|
||
def inner2: Unit = { | ||
b.value = 456 | ||
}.ensuring(_ => snapshot(b).value == 456) | ||
} | ||
} |
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,10 @@ | ||
object i1270 { | ||
case class Box(var value: Int) | ||
|
||
def outer(b: Box): Unit = { | ||
def inner(v: Int): Unit = { | ||
require(b.value == v) | ||
} | ||
inner(b.value) | ||
} | ||
} |
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,15 @@ | ||
import stainless.io._ | ||
|
||
object i1272 { | ||
def read(fis: FileInputStream)(implicit s: State): Unit = { | ||
require(fis.isOpen) | ||
val a1 = fis.tryReadByte() | ||
val a2 = fis.tryReadByte() | ||
} | ||
|
||
def write(fos: FileOutputStream): Unit = { | ||
require(fos.isOpen) | ||
fos.write(1) | ||
fos.write(2) | ||
} | ||
} |
Oops, something went wrong.