-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Compiled lambdas now close only on non-ghost variables (#2854)
- Loading branch information
1 parent
c93508f
commit c449f53
Showing
6 changed files
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// RUN: %dafny -compile:4 -compileTarget:cs "%s" > "%t" | ||
// RUN: %dafny -noVerify -compile:4 -compileTarget:js "%s" >> "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
method InSeq<T>(ts: seq<T>) returns (f: T --> bool) | ||
ensures forall t <- ts :: f.requires(t) | ||
{ | ||
ghost var pre := t => t in ts; | ||
f := t requires pre(t) => true; | ||
} | ||
|
||
method InSeq2<T>(ghost ts: seq<T>) returns (f: T --> bool) | ||
ensures forall t <- ts :: f.requires(t) | ||
{ | ||
f := t requires (ghost var b := t in ts; b) => true; | ||
} | ||
|
||
method Main() { | ||
var f := InSeq([1, 2]); | ||
print "2 in seq? ", f(2),"\n"; | ||
var g := InSeq2([1, 2]); | ||
print "2 in seq? ", g(2),"\n"; | ||
print "All right"; | ||
} |
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 @@ | ||
|
||
Dafny program verifier finished with 3 verified, 0 errors | ||
2 in seq? true | ||
2 in seq? true | ||
All right | ||
Dafny program verifier did not attempt verification | ||
2 in seq? true | ||
2 in seq? true | ||
All right |
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,19 @@ | ||
// RUN: %dafny -compile:3 -compileTarget:cs "%s" > "%t" | ||
// RUN: %dafny -noVerify -compile:4 -compileTarget:js "%s" >> "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
// Returns a function that computes the sum of n consecutive integers starting at pos | ||
function method Sum( | ||
ghost remaining: nat, | ||
n: nat | ||
): (p: nat -> nat) | ||
decreases remaining | ||
requires remaining == n | ||
{ | ||
(pos: nat) => | ||
var x: nat := if n == 0 then 0 else Sum(remaining - 1, n - 1)(pos+1) + pos; | ||
x | ||
} | ||
method Main() { | ||
print Sum(5, 5)(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,5 @@ | ||
|
||
Dafny program verifier finished with 2 verified, 0 errors | ||
60 | ||
Dafny program verifier did not attempt verification | ||
60 |