1- use crate :: { logic:: IndexLogic , std:: alloc:: Allocator , * } ;
1+ use crate :: { invariant:: Invariant , logic:: IndexLogic , std:: alloc:: Allocator , * } ;
2+ use :: std:: collections:: vec_deque:: { IntoIter , Iter } ;
23pub use :: std:: collections:: VecDeque ;
34
45impl < T , A : Allocator > ShallowModel for VecDeque < T , A > {
@@ -13,6 +14,131 @@ impl<T, A: Allocator> ShallowModel for VecDeque<T, A> {
1314 }
1415}
1516
17+ impl < ' a , T > Invariant for Iter < ' a , T > { }
18+
19+ impl < T , A : Allocator > ShallowModel for IntoIter < T , A > {
20+ type ShallowModelTy = Seq < T > ;
21+
22+ #[ open( self ) ]
23+ #[ ghost]
24+ #[ trusted]
25+ fn shallow_model ( self ) -> Self :: ShallowModelTy {
26+ absurd
27+ }
28+ }
29+
30+ impl < ' a , T > ShallowModel for Iter < ' a , T > {
31+ // TODO : This seems wrong
32+ type ShallowModelTy = & ' a [ T ] ;
33+
34+ #[ ghost]
35+ #[ open( self ) ]
36+ #[ trusted]
37+ fn shallow_model ( self ) -> Self :: ShallowModelTy {
38+ absurd
39+ }
40+ }
41+
42+ impl < ' a , T > Iterator for Iter < ' a , T > {
43+ #[ predicate]
44+ #[ open]
45+ fn completed ( & mut self ) -> bool {
46+ pearlite ! { self . resolve( ) && ( * self ) @@ == Seq :: EMPTY }
47+ }
48+
49+ #[ predicate]
50+ #[ open]
51+ fn produces ( self , visited : Seq < Self :: Item > , tl : Self ) -> bool {
52+ pearlite ! {
53+ self @. to_ref_seq( ) == visited. concat( tl@. to_ref_seq( ) )
54+ }
55+ }
56+
57+ #[ law]
58+ #[ open]
59+ #[ ensures( a. produces( Seq :: EMPTY , a) ) ]
60+ fn produces_refl ( a : Self ) { }
61+
62+ #[ law]
63+ #[ open]
64+ #[ requires( a. produces( ab, b) ) ]
65+ #[ requires( b. produces( bc, c) ) ]
66+ #[ ensures( a. produces( ab. concat( bc) , c) ) ]
67+ fn produces_trans ( a : Self , ab : Seq < Self :: Item > , b : Self , bc : Seq < Self :: Item > , c : Self ) { }
68+ }
69+
70+ impl < T , A : Allocator > Invariant for IntoIter < T , A > { }
71+
72+ impl < T , A : Allocator > Iterator for IntoIter < T , A > {
73+ #[ predicate]
74+ #[ open]
75+ fn completed ( & mut self ) -> bool {
76+ pearlite ! { self . resolve( ) && self @ == Seq :: EMPTY }
77+ }
78+
79+ #[ predicate]
80+ #[ open]
81+ fn produces ( self , visited : Seq < T > , rhs : Self ) -> bool {
82+ pearlite ! {
83+ self @ == visited. concat( rhs@)
84+ }
85+ }
86+
87+ #[ law]
88+ #[ open]
89+ #[ ensures( a. produces( Seq :: EMPTY , a) ) ]
90+ fn produces_refl ( a : Self ) { }
91+
92+ #[ law]
93+ #[ open]
94+ #[ requires( a. produces( ab, b) ) ]
95+ #[ requires( b. produces( bc, c) ) ]
96+ #[ ensures( a. produces( ab. concat( bc) , c) ) ]
97+ fn produces_trans ( a : Self , ab : Seq < T > , b : Self , bc : Seq < T > , c : Self ) { }
98+ }
99+
100+ impl < T , A : Allocator > IntoIterator for VecDeque < T , A > {
101+ #[ predicate]
102+ #[ open]
103+ fn into_iter_pre ( self ) -> bool {
104+ pearlite ! { true }
105+ }
106+
107+ #[ predicate]
108+ #[ open]
109+ fn into_iter_post ( self , res : Self :: IntoIter ) -> bool {
110+ pearlite ! { self @ == res@ }
111+ }
112+ }
113+
114+ impl < T , A : Allocator > IntoIterator for & VecDeque < T , A > {
115+ #[ predicate]
116+ #[ open]
117+ fn into_iter_pre ( self ) -> bool {
118+ pearlite ! { true }
119+ }
120+
121+ #[ predicate]
122+ #[ open]
123+ fn into_iter_post ( self , res : Self :: IntoIter ) -> bool {
124+ pearlite ! { self @ == res@@ }
125+ }
126+ }
127+
128+ // impl<T, A: Allocator> IntoIterator for &mut VecDeque<T, A> {
129+ // #[predicate]
130+ // #[open]
131+ // fn into_iter_pre(self) -> bool {
132+ // pearlite! { true }
133+ // }
134+
135+ // #[predicate]
136+ // #[open]
137+ // fn into_iter_post(self, res: Self::IntoIter) -> bool {
138+ // pearlite! { self@ == res@@ }
139+ // }
140+ // }
141+
16142impl < T : DeepModel , A : Allocator > DeepModel for VecDeque < T , A > {
17143 type DeepModelTy = Seq < T :: DeepModelTy > ;
18144
0 commit comments