Skip to content

Commit f41ad35

Browse files
committed
Improve test
1 parent 251db3d commit f41ad35

File tree

4 files changed

+177
-66
lines changed

4 files changed

+177
-66
lines changed
Lines changed: 144 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11

2-
module Core_Option_Option_Type
3-
type t_option 't =
4-
| C_None
5-
| C_Some 't
2+
module Generated_Sum10_Type
3+
use prelude.Int
4+
use prelude.Int32
5+
type t_sum10 =
6+
| C_Sum10 int32 int32
7+
8+
let function sum10_0 (self : t_sum10) : int32 = [@vc:do_not_keep_trace] [@vc:sp]
9+
match (self) with
10+
| C_Sum10 a _ -> a
11+
end
12+
let function sum10_1 (self : t_sum10) : int32 = [@vc:do_not_keep_trace] [@vc:sp]
13+
match (self) with
14+
| C_Sum10 _ a -> a
15+
end
16+
end
17+
module Generated_Impl0_UserInv_Stub
18+
use Generated_Sum10_Type as Generated_Sum10_Type
19+
predicate user_inv [#"../generated.rs" 11 4 11 29] (self : Generated_Sum10_Type.t_sum10)
20+
end
21+
module Generated_Impl0_UserInv_Interface
22+
use Generated_Sum10_Type as Generated_Sum10_Type
23+
predicate user_inv [#"../generated.rs" 11 4 11 29] (self : Generated_Sum10_Type.t_sum10)
24+
val user_inv [#"../generated.rs" 11 4 11 29] (self : Generated_Sum10_Type.t_sum10) : bool
25+
ensures { result = user_inv self }
626

727
end
8-
module Generated_List_Type
9-
use Core_Option_Option_Type as Core_Option_Option_Type
10-
type t_list 't =
11-
| C_List 't (Core_Option_Option_Type.t_option (t_list 't))
28+
module Generated_Impl0_UserInv
29+
use prelude.Int32
30+
use prelude.Int
31+
use Generated_Sum10_Type as Generated_Sum10_Type
32+
predicate user_inv [#"../generated.rs" 11 4 11 29] (self : Generated_Sum10_Type.t_sum10) =
33+
[#"../generated.rs" 12 20 12 43] Int32.to_int (Generated_Sum10_Type.sum10_0 self) + Int32.to_int (Generated_Sum10_Type.sum10_1 self) = 10
34+
val user_inv [#"../generated.rs" 11 4 11 29] (self : Generated_Sum10_Type.t_sum10) : bool
35+
ensures { result = user_inv self }
1236

1337
end
1438
module CreusotContracts_Invariant_Inv_Stub
@@ -29,6 +53,16 @@ module CreusotContracts_Invariant_Inv
2953
val inv (_x : t) : bool
3054
ensures { result = inv _x }
3155

56+
end
57+
module Generated_Foo_Type
58+
use prelude.Borrow
59+
use prelude.Int
60+
use prelude.UIntSize
61+
use Generated_Sum10_Type as Generated_Sum10_Type
62+
type t_foo 't =
63+
| C_A (borrowed (Generated_Sum10_Type.t_sum10)) usize
64+
| C_B 't
65+
3266
end
3367
module CreusotContracts_Invariant_UserInv_UserInv_Stub
3468
type self
@@ -48,20 +82,22 @@ module CreusotContracts_Invariant_UserInv_UserInv
4882
ensures { result = user_inv self }
4983

5084
end
51-
module Generated_List_Type_Inv
85+
module Generated_Foo_Type_Inv
5286
type t
53-
use Generated_List_Type as Generated_List_Type
54-
use Core_Option_Option_Type as Core_Option_Option_Type
87+
use prelude.Borrow
88+
use Generated_Sum10_Type as Generated_Sum10_Type
5589
clone CreusotContracts_Invariant_Inv_Stub as Inv2 with
56-
type t = Core_Option_Option_Type.t_option (Generated_List_Type.t_list t)
57-
clone CreusotContracts_Invariant_Inv_Stub as Inv1 with
5890
type t = t
91+
use Generated_Foo_Type as Generated_Foo_Type
92+
clone CreusotContracts_Invariant_Inv_Stub as Inv1 with
93+
type t = borrowed (Generated_Sum10_Type.t_sum10)
5994
clone CreusotContracts_Invariant_UserInv_UserInv_Stub as UserInv0 with
60-
type self = Generated_List_Type.t_list t
95+
type self = Generated_Foo_Type.t_foo t
6196
clone CreusotContracts_Invariant_Inv_Stub as Inv0 with
62-
type t = Generated_List_Type.t_list t
63-
axiom inv_t_list : forall self : Generated_List_Type.t_list t . Inv0.inv self = (UserInv0.user_inv self /\ match (self) with
64-
| Generated_List_Type.C_List a_0 a_1 -> Inv1.inv a_0 /\ Inv2.inv a_1
97+
type t = Generated_Foo_Type.t_foo t
98+
axiom inv_t_foo : forall self : Generated_Foo_Type.t_foo t . Inv0.inv self = (UserInv0.user_inv self /\ match (self) with
99+
| Generated_Foo_Type.C_A f1 _ -> Inv1.inv f1
100+
| Generated_Foo_Type.C_B a_0 -> Inv2.inv a_0
65101
end)
66102
end
67103
module CreusotContracts_Invariant_Impl0_UserInv_Stub
@@ -83,84 +119,129 @@ module CreusotContracts_Invariant_Impl0_UserInv
83119
ensures { result = user_inv self }
84120

85121
end
86-
module TyInv_Trivial
87-
type t
88-
clone CreusotContracts_Invariant_Inv_Stub as Inv0 with
89-
type t = t
90-
axiom inv_trivial : forall self : t . Inv0.inv self = true
91-
end
92-
module Core_Option_Option_Type_Inv
122+
module TyInv_Borrow
93123
type t
124+
use prelude.Borrow
94125
clone CreusotContracts_Invariant_Inv_Stub as Inv1 with
95126
type t = t
96-
use Core_Option_Option_Type as Core_Option_Option_Type
97127
clone CreusotContracts_Invariant_UserInv_UserInv_Stub as UserInv0 with
98-
type self = Core_Option_Option_Type.t_option t
128+
type self = borrowed t
99129
clone CreusotContracts_Invariant_Inv_Stub as Inv0 with
100-
type t = Core_Option_Option_Type.t_option t
101-
axiom inv_t_option : forall self : Core_Option_Option_Type.t_option t . Inv0.inv self = (UserInv0.user_inv self /\ match (self) with
102-
| Core_Option_Option_Type.C_None -> true
103-
| Core_Option_Option_Type.C_Some a_0 -> Inv1.inv a_0
104-
end)
130+
type t = borrowed t
131+
axiom inv_borrow : forall self : borrowed t . Inv0.inv self = (UserInv0.user_inv self /\ (let a = * self in Inv1.inv a))
105132
end
106-
module Generated_UseList_Interface
133+
module TyInv_Tuple2
134+
type t0
135+
type t1
136+
clone CreusotContracts_Invariant_Inv_Stub as Inv2 with
137+
type t = t1
138+
clone CreusotContracts_Invariant_Inv_Stub as Inv1 with
139+
type t = t0
140+
clone CreusotContracts_Invariant_Inv_Stub as Inv0 with
141+
type t = (t0, t1)
142+
axiom inv_tuple2 : forall self : (t0, t1) . Inv0.inv self = (let (a_0, a_1) = self in Inv1.inv a_0 /\ Inv2.inv a_1)
143+
end
144+
module Generated_Sum10_Type_Inv
145+
use Generated_Sum10_Type as Generated_Sum10_Type
146+
clone Generated_Impl0_UserInv_Stub as UserInv0
147+
clone CreusotContracts_Invariant_Inv_Stub as Inv0 with
148+
type t = Generated_Sum10_Type.t_sum10
149+
axiom inv_t_sum10 : forall self : Generated_Sum10_Type.t_sum10 . Inv0.inv self = UserInv0.user_inv self
150+
end
151+
module TyInv_Trivial
152+
type t
153+
clone CreusotContracts_Invariant_Inv_Stub as Inv0 with
154+
type t = t
155+
axiom inv_trivial : forall self : t . Inv0.inv self = true
156+
end
157+
module Generated_UseFoo_Interface
107158
use prelude.Int
108-
use prelude.Int32
109-
use Generated_List_Type as Generated_List_Type
110-
val use_list [#"../generated.rs" 6 0 6 29] (l : Generated_List_Type.t_list int32) : ()
159+
use prelude.UInt32
160+
use prelude.Borrow
161+
use Generated_Sum10_Type as Generated_Sum10_Type
162+
use Generated_Foo_Type as Generated_Foo_Type
163+
clone CreusotContracts_Invariant_Inv_Stub as Inv0 with
164+
type t = Generated_Foo_Type.t_foo (Generated_Foo_Type.t_foo uint32, borrowed (Generated_Sum10_Type.t_sum10))
165+
val use_foo [#"../generated.rs" 22 0 22 61] (x : Generated_Foo_Type.t_foo (Generated_Foo_Type.t_foo uint32, borrowed (Generated_Sum10_Type.t_sum10))) : ()
166+
requires {[#"../generated.rs" 21 11 21 28] Inv0.inv x}
167+
111168
end
112-
module Generated_UseList
169+
module Generated_UseFoo
113170
use prelude.Int
114-
use prelude.Int32
115-
use Generated_List_Type as Generated_List_Type
171+
use prelude.UInt32
172+
use prelude.Borrow
173+
clone CreusotContracts_Invariant_Inv_Interface as Inv5 with
174+
type t = uint32
175+
clone TyInv_Trivial as TyInv_Trivial0 with
176+
type t = uint32,
177+
predicate Inv0.inv = Inv5.inv,
178+
axiom .
179+
use Generated_Foo_Type as Generated_Foo_Type
180+
clone CreusotContracts_Invariant_Impl0_UserInv as UserInv3 with
181+
type t = Generated_Foo_Type.t_foo uint32
182+
use Generated_Sum10_Type as Generated_Sum10_Type
183+
clone Generated_Impl0_UserInv as UserInv2
184+
clone CreusotContracts_Invariant_Inv_Interface as Inv1 with
185+
type t = borrowed (Generated_Sum10_Type.t_sum10)
186+
clone CreusotContracts_Invariant_Inv_Interface as Inv4 with
187+
type t = Generated_Foo_Type.t_foo uint32
188+
clone Generated_Foo_Type_Inv as Generated_Foo_Type_Inv1 with
189+
type t = uint32,
190+
predicate Inv0.inv = Inv4.inv,
191+
predicate UserInv0.user_inv = UserInv3.user_inv,
192+
predicate Inv1.inv = Inv1.inv,
193+
predicate Inv2.inv = Inv5.inv,
194+
axiom .
116195
clone CreusotContracts_Invariant_Inv_Interface as Inv3 with
117-
type t = Generated_List_Type.t_list int32
118-
use Core_Option_Option_Type as Core_Option_Option_Type
196+
type t = Generated_Sum10_Type.t_sum10
197+
clone Generated_Sum10_Type_Inv as Generated_Sum10_Type_Inv0 with
198+
predicate Inv0.inv = Inv3.inv,
199+
predicate UserInv0.user_inv = UserInv2.user_inv,
200+
axiom .
119201
clone CreusotContracts_Invariant_Impl0_UserInv as UserInv1 with
120-
type t = Core_Option_Option_Type.t_option (Generated_List_Type.t_list int32)
202+
type t = borrowed (Generated_Sum10_Type.t_sum10)
121203
clone CreusotContracts_Invariant_Inv_Interface as Inv2 with
122-
type t = Core_Option_Option_Type.t_option (Generated_List_Type.t_list int32)
123-
clone Core_Option_Option_Type_Inv as Core_Option_Option_Type_Inv0 with
124-
type t = Generated_List_Type.t_list int32,
204+
type t = (Generated_Foo_Type.t_foo uint32, borrowed (Generated_Sum10_Type.t_sum10))
205+
clone TyInv_Tuple2 as TyInv_Tuple20 with
206+
type t0 = Generated_Foo_Type.t_foo uint32,
207+
type t1 = borrowed (Generated_Sum10_Type.t_sum10),
125208
predicate Inv0.inv = Inv2.inv,
126-
predicate UserInv0.user_inv = UserInv1.user_inv,
127-
predicate Inv1.inv = Inv3.inv,
209+
predicate Inv1.inv = Inv4.inv,
210+
predicate Inv2.inv = Inv1.inv,
128211
axiom .
129-
clone CreusotContracts_Invariant_Inv_Interface as Inv1 with
130-
type t = int32
131-
clone TyInv_Trivial as TyInv_Trivial0 with
132-
type t = int32,
212+
clone TyInv_Borrow as TyInv_Borrow0 with
213+
type t = Generated_Sum10_Type.t_sum10,
133214
predicate Inv0.inv = Inv1.inv,
215+
predicate UserInv0.user_inv = UserInv1.user_inv,
216+
predicate Inv1.inv = Inv3.inv,
134217
axiom .
135218
clone CreusotContracts_Invariant_Impl0_UserInv as UserInv0 with
136-
type t = Generated_List_Type.t_list int32
219+
type t = Generated_Foo_Type.t_foo (Generated_Foo_Type.t_foo uint32, borrowed (Generated_Sum10_Type.t_sum10))
137220
clone CreusotContracts_Invariant_Inv_Interface as Inv0 with
138-
type t = Generated_List_Type.t_list int32
139-
clone Generated_List_Type_Inv as Generated_List_Type_Inv0 with
140-
type t = int32,
221+
type t = Generated_Foo_Type.t_foo (Generated_Foo_Type.t_foo uint32, borrowed (Generated_Sum10_Type.t_sum10))
222+
clone Generated_Foo_Type_Inv as Generated_Foo_Type_Inv0 with
223+
type t = (Generated_Foo_Type.t_foo uint32, borrowed (Generated_Sum10_Type.t_sum10)),
141224
predicate Inv0.inv = Inv0.inv,
142225
predicate UserInv0.user_inv = UserInv0.user_inv,
143226
predicate Inv1.inv = Inv1.inv,
144227
predicate Inv2.inv = Inv2.inv,
145228
axiom .
146-
let rec cfg use_list [#"../generated.rs" 6 0 6 29] [@cfg:stackify] [@cfg:subregion_analysis] (l : Generated_List_Type.t_list int32) : ()
229+
let rec cfg use_foo [#"../generated.rs" 22 0 22 61] [@cfg:stackify] [@cfg:subregion_analysis] (x : Generated_Foo_Type.t_foo (Generated_Foo_Type.t_foo uint32, borrowed (Generated_Sum10_Type.t_sum10))) : ()
230+
requires {[#"../generated.rs" 21 11 21 28] Inv0.inv x}
147231

148232
= [@vc:do_not_keep_trace] [@vc:sp]
149233
var _0 : ();
150-
var l : Generated_List_Type.t_list int32 = l;
234+
var x : Generated_Foo_Type.t_foo (Generated_Foo_Type.t_foo uint32, borrowed (Generated_Sum10_Type.t_sum10)) = x;
151235
{
152236
goto BB0
153237
}
154238
BB0 {
155-
assert { [@expl:assertion] [#"../generated.rs" 7 18 7 35] Inv0.inv l };
156-
goto BB1
157-
}
158-
BB1 {
239+
assert { [@expl:assertion] [#"../generated.rs" 23 18 23 35] Inv0.inv x };
159240
_0 <- ();
160-
goto BB2
161-
}
162-
BB2 {
163241
return _0
164242
}
165243

166244
end
245+
module Generated_Impl0
246+
247+
end
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1+
#![allow(incomplete_features)]
2+
#![feature(specialization)]
13
extern crate creusot_contracts;
24
use creusot_contracts::{invariant, *};
35

4-
pub struct List<T>(T, Option<Box<List<T>>>);
6+
pub struct Sum10(i32, i32);
57

6-
pub fn use_list(l: List<i32>) {
7-
proof_assert!(invariant::inv(l))
8+
impl invariant::UserInv for Sum10 {
9+
#[predicate]
10+
#[open]
11+
fn user_inv(self) -> bool {
12+
pearlite! { self.0@ + self.1@ == 10 }
13+
}
14+
}
15+
16+
pub enum Foo<'a, T> {
17+
A { f1: &'a mut Sum10, f2: usize },
18+
B(T),
19+
}
20+
21+
#[requires(invariant::inv(x))]
22+
pub fn use_foo<'a>(x: Foo<'a, (Foo<'a, u32>, &'a mut Sum10)>) {
23+
proof_assert!(invariant::inv(x));
824
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE why3session PUBLIC "-//Why3//proof session v5//EN"
3+
"http://why3.lri.fr/why3session.dtd">
4+
<why3session shape_version="6">
5+
<prover id="0" name="Alt-Ergo" version="2.4.2" timelimit="1" steplimit="0" memlimit="1000"/>
6+
<file format="mlcfg" proved="true">
7+
<path name=".."/><path name="generated.mlcfg"/>
8+
<theory name="Generated_UseFoo" proved="true">
9+
<goal name="use_foo&#39;vc" expl="VC for use_foo" proved="true">
10+
<proof prover="0"><result status="valid" time="0.01" steps="5"/></proof>
11+
</goal>
12+
</theory>
13+
</file>
14+
</why3session>
Binary file not shown.

0 commit comments

Comments
 (0)