-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement assigned(e) expression (#5501)
Implements the `assigned(e)` expression, fixing #5251.
- Loading branch information
Showing
18 changed files
with
250 additions
and
16 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
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
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
42 changes: 42 additions & 0 deletions
42
Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Assigned.dfy
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,42 @@ | ||
// RUN: %verify --relax-definite-assignment "%s" > "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
class C<G> | ||
{ | ||
var x: G | ||
const y: G | ||
|
||
constructor Con0(i: int, a: G, b: G) | ||
{ | ||
x := a; | ||
y := b; | ||
assert assigned(x); | ||
assert assigned(y); | ||
new; | ||
if i > 0 { | ||
x := y; | ||
} | ||
} | ||
|
||
constructor Con1(i: int, a: G, b: G) | ||
{ | ||
x := a; | ||
assert assigned(x); | ||
assume {:axiom} assigned(y); | ||
new; | ||
if i > 0 { | ||
x := y; | ||
} | ||
} | ||
} | ||
|
||
method M0<G>(x: int, a: G, b: G) returns (y: G) | ||
{ | ||
if x < 10 { | ||
y := a; | ||
} else if x < 20 { | ||
return b; | ||
} else { | ||
assume {:axiom} assigned(y); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
Source/IntegrationTests/TestFiles/LitTests/LitTest/dafny0/Assigned.dfy.expect
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,2 @@ | ||
| ||
Dafny program verifier finished with 3 verified, 0 errors |
89 changes: 89 additions & 0 deletions
89
...IntegrationTests/TestFiles/LitTests/LitTest/proof-obligation-desc/definite-assignment.dfy
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,89 @@ | ||
// RUN: %exits-with 4 %verify --show-proof-obligation-expressions "%s" > "%t" | ||
// RUN: %diff "%s.expect" "%t" | ||
|
||
class C<G> | ||
{ | ||
var x: G | ||
const y: G | ||
|
||
constructor Con0(i: int, a: G, b: G) | ||
{ | ||
if i > 0 { | ||
x := a; | ||
} else { | ||
y := b; | ||
} | ||
new; | ||
if i > 10 { | ||
x := y; | ||
} | ||
} | ||
} | ||
|
||
method M0<G>(i: int, a: G, b: G) returns (x: G, y: G) | ||
{ | ||
if i < 0 { | ||
x := a; | ||
} else if i < 10 { | ||
y := b; | ||
} else if i < 20 { | ||
x := a; | ||
y := x; | ||
} else if i < 30 { | ||
x := y; | ||
y := b; | ||
} | ||
} | ||
|
||
method M1<G>(i: int, a: G, b: G) returns (x: G, y: G) | ||
{ | ||
if i < 0 { | ||
return x, y; | ||
} | ||
return a, b; | ||
} | ||
|
||
method M2<G>(i: int, a: G, b: G) returns (x: G, y: G) | ||
{ | ||
if i < 0 { | ||
x := a; | ||
return x, y; | ||
} | ||
return a, b; | ||
} | ||
|
||
method M3<G>(i: int, a: G, b: G, c: G) returns (x: G, y: G, z: G) | ||
{ | ||
if i < 0 { | ||
x := y; | ||
return x, y, z; | ||
} | ||
return a, b, c; | ||
} | ||
|
||
method M4<G>(i: int, a: G, b: G) returns (x: G, y: G) | ||
{ | ||
if i < 0 { | ||
x := a; | ||
return; | ||
} | ||
return a, b; | ||
} | ||
|
||
method M5<G>(i: int, a: G, b: G, c: G) returns (x: G, y: G, z: G) | ||
{ | ||
if i < 0 { | ||
x := y; | ||
return; | ||
} | ||
return a, b, c; | ||
} | ||
|
||
method M6<G>(i: int, a: G, b: G) returns (x: G, y: G) | ||
{ | ||
if i < 0 { | ||
x, y := y, x; | ||
return; | ||
} | ||
return a, b; | ||
} |
32 changes: 32 additions & 0 deletions
32
...tionTests/TestFiles/LitTests/LitTest/proof-obligation-desc/definite-assignment.dfy.expect
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,32 @@ | ||
definite-assignment.dfy(16,4): Error: field 'x', which is subject to definite-assignment rules, might be uninitialized at this point in the constructor body | ||
Asserted expression: assigned(x) | ||
definite-assignment.dfy(16,4): Error: field 'y', which is subject to definite-assignment rules, might be uninitialized at this point in the constructor body | ||
Asserted expression: assigned(y) | ||
definite-assignment.dfy(33,9): Error: variable 'y', which is subject to definite-assignment rules, might be uninitialized here | ||
Asserted expression: assigned(y) | ||
definite-assignment.dfy(36,0): Error: out-parameter 'x', which is subject to definite-assignment rules, might be uninitialized at this return point | ||
Asserted expression: assigned(x) | ||
definite-assignment.dfy(36,0): Error: out-parameter 'y', which is subject to definite-assignment rules, might be uninitialized at this return point | ||
Asserted expression: assigned(y) | ||
definite-assignment.dfy(41,11): Error: variable 'x', which is subject to definite-assignment rules, might be uninitialized here | ||
Asserted expression: assigned(x) | ||
definite-assignment.dfy(41,14): Error: variable 'y', which is subject to definite-assignment rules, might be uninitialized here | ||
Asserted expression: assigned(y) | ||
definite-assignment.dfy(50,14): Error: variable 'y', which is subject to definite-assignment rules, might be uninitialized here | ||
Asserted expression: assigned(y) | ||
definite-assignment.dfy(58,9): Error: variable 'y', which is subject to definite-assignment rules, might be uninitialized here | ||
Asserted expression: assigned(y) | ||
definite-assignment.dfy(59,17): Error: variable 'z', which is subject to definite-assignment rules, might be uninitialized here | ||
Asserted expression: assigned(z) | ||
definite-assignment.dfy(68,4): Error: out-parameter 'y', which is subject to definite-assignment rules, might be uninitialized at this return point | ||
Asserted expression: assigned(y) | ||
definite-assignment.dfy(76,9): Error: variable 'y', which is subject to definite-assignment rules, might be uninitialized here | ||
Asserted expression: assigned(y) | ||
definite-assignment.dfy(77,4): Error: out-parameter 'z', which is subject to definite-assignment rules, might be uninitialized at this return point | ||
Asserted expression: assigned(z) | ||
definite-assignment.dfy(85,12): Error: variable 'y', which is subject to definite-assignment rules, might be uninitialized here | ||
Asserted expression: assigned(y) | ||
definite-assignment.dfy(85,15): Error: variable 'x', which is subject to definite-assignment rules, might be uninitialized here | ||
Asserted expression: assigned(x) | ||
|
||
Dafny program verifier finished with 0 verified, 15 errors |
Oops, something went wrong.