-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathadts_opaque.rs
More file actions
194 lines (163 loc) · 4.55 KB
/
Copy pathadts_opaque.rs
File metadata and controls
194 lines (163 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#![feature(rustc_private)]
#[macro_use]
mod common;
use common::*;
test_verify_one_file! {
#[test] test_needs_pub_abstract verus_code! {
mod M1 {
use verus_builtin::*;
#[derive(PartialEq, Eq)]
pub struct Car {
passengers: nat,
pub four_doors: bool,
}
pub open spec fn get_passengers(c: Car) -> nat {
c.passengers
}
}
} => Err(err) => assert_vir_error_msg(err, "disallowed: field expression for an opaque datatype")
}
test_verify_one_file! {
#[test] test_needs_pub_abstract2 verus_code! {
mod M1 {
use verus_builtin::*;
#[derive(PartialEq, Eq)]
pub struct Car {
passengers: nat,
pub four_doors: bool,
}
pub open spec fn get_passengers() -> Car {
Car { passengers: 0, four_doors: true }
}
}
} => Err(err) => assert_vir_error_msg(err, "disallowed: constructor for an opaque datatype")
}
test_verify_one_file! {
#[test] test_needs_pub_abstract3 verus_code! {
mod M1 {
use verus_builtin::*;
enum E {
C()
}
pub open spec fn get_passengers() -> bool {
let _ = E::C();
true
}
}
} => Err(err) => assert_vir_error_msg(err, "disallowed: constructor for a non-visible datatype")
}
test_verify_one_file! {
#[test] test_field_access_for_non_pub_datatype verus_code! {
struct X {
pub f: u8,
}
pub open spec fn f(x: X) -> bool {
x.f == 0
}
} => Err(err) => assert_vir_error_msg(err, "disallowed: field expression for a non-visible datatype")
}
const M1: &str = verus_code_str! {
mod M1 {
use verus_builtin::*;
#[derive(PartialEq, Eq)]
pub struct Car {
passengers: nat,
pub four_doors: bool,
}
pub closed spec fn get_passengers(c: Car) -> nat {
c.passengers
}
#[derive(PartialEq, Eq)]
pub struct Bike {
pub hard_tail: bool,
}
}
};
test_verify_one_file! {
#[test] test_transparent_struct_1 M1.to_string() + verus_code_str! {
mod M2 {
use crate::M1::{Car, Bike};
use verus_builtin::*;
fn test_transparent_struct_1() {
assert((Bike { hard_tail: true }).hard_tail);
}
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_opaque_struct_1 M1.to_string() + verus_code_str! {
mod M2 {
use crate::M1::{Car, get_passengers, Bike};
use verus_builtin::*;
use vstd::prelude::*;
fn test_opaque_struct_1(c: Car)
requires
get_passengers(c) == 12,
{
assert(get_passengers(c) == 12);
}
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_opaque_fn verus_code! {
struct A {}
impl A {
#[verifier(opaque)] /* vattr */
pub closed spec fn always(&self) -> bool {
true
}
}
fn main() {
let a = A {};
proof {
reveal(A::always);
}
assert(a.always());
}
} => Ok(())
}
const M1_OPAQUE: &str = verus_code_str! {
mod M1 {
use verus_builtin::*;
pub struct A {
field: u64,
}
impl A {
#[verifier(opaque_outside_module)] /* vattr */
pub open spec fn always(&self) -> bool {
true
}
}
fn test1() {
let a = A { field: 12 };
assert(a.always());
}
}
};
test_verify_one_file! {
#[test] test_opaque_fn_modules_within M1_OPAQUE.to_string() => Ok(())
}
test_verify_one_file! {
#[test] test_opaque_fn_modules_pass M1_OPAQUE.to_string() + verus_code_str! {
mod M2 {
use verus_builtin::*;
fn test(a: crate::M1::A) {
proof {
reveal(crate::M1::A::always);
}
assert(a.always());
}
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_opaque_fn_modules_fail M1_OPAQUE.to_string() + verus_code_str! {
mod M2 {
use verus_builtin::*;
fn test(a: crate::M1::A) {
assert(a.always()); // FAILS
}
}
} => Err(e) => assert_one_fails(e)
}