@@ -48,17 +48,16 @@ instance (α : Type u) : Inhabited (Vec α) := by
48
48
constructor
49
49
apply Vec.new
50
50
51
- -- TODO: very annoying that the α is an explicit parameter
52
51
@[simp]
53
- abbrev Vec.len ( α : Type u) (v : Vec α) : Usize :=
52
+ abbrev Vec.len { α : Type u} (v : Vec α) : Usize :=
54
53
Usize.ofIntCore v.val.length (by constructor <;> scalar_tac)
55
54
56
55
@[simp]
57
- theorem Vec.len_val {α : Type u} (v : Vec α) : (Vec.len α v).val = v.length :=
56
+ theorem Vec.len_val {α : Type u} (v : Vec α) : (Vec.len v).val = v.length :=
58
57
by rfl
59
58
60
59
@[irreducible]
61
- def Vec.push ( α : Type u) (v : Vec α) (x : α) : Result (Vec α)
60
+ def Vec.push { α : Type u} (v : Vec α) (x : α) : Result (Vec α)
62
61
:=
63
62
let nlen := List.length v.val + 1
64
63
if h : nlen ≤ U32.max || nlen ≤ Usize.max then
@@ -72,21 +71,13 @@ def Vec.push (α : Type u) (v : Vec α) (x : α) : Result (Vec α)
72
71
73
72
@[pspec]
74
73
theorem Vec.push_spec {α : Type u} (v : Vec α) (x : α) (h : v.val.length < Usize.max) :
75
- ∃ v1, v.push α x = ok v1 ∧
74
+ ∃ v1, v.push x = ok v1 ∧
76
75
v1.val = v.val ++ [x] := by
77
76
rw [push]; simp
78
- split <;> simp_all <;>
77
+ split <;> simp_all
79
78
scalar_tac
80
79
81
- -- This shouldn't be used
82
- def Vec.insert_fwd (α : Type u) (v: Vec α) (i: Usize) (_: α) : Result Unit :=
83
- if i.val < v.length then
84
- ok ()
85
- else
86
- fail arrayOutOfBounds
87
-
88
- -- This is actually the backward function
89
- def Vec.insert (α : Type u) (v: Vec α) (i: Usize) (x: α) : Result (Vec α) :=
80
+ def Vec.insert {α : Type u} (v: Vec α) (i: Usize) (x: α) : Result (Vec α) :=
90
81
if i.val < v.length then
91
82
ok ⟨ v.val.update i.toNat x, by have := v.property; simp [*] ⟩
92
83
else
@@ -95,19 +86,14 @@ def Vec.insert (α : Type u) (v: Vec α) (i: Usize) (x: α) : Result (Vec α) :=
95
86
@[pspec]
96
87
theorem Vec.insert_spec {α : Type u} (v: Vec α) (i: Usize) (x: α)
97
88
(hbound : i.val < v.length) :
98
- ∃ nv, v.insert α i x = ok nv ∧ nv.val = v.val.update i.toNat x := by
89
+ ∃ nv, v.insert i x = ok nv ∧ nv.val = v.val.update i.toNat x := by
99
90
simp [insert, *]
100
91
101
92
def Vec.index_usize {α : Type u} (v: Vec α) (i: Usize) : Result α :=
102
93
match v.val.indexOpt i.toNat with
103
94
| none => fail .arrayOutOfBounds
104
95
| some x => ok x
105
96
106
- /- In the theorems below: we don't always need the `∃ ..`, but we use one
107
- so that `progress` introduces an opaque variable and an equality. This
108
- helps control the context.
109
- -/
110
-
111
97
@[pspec]
112
98
theorem Vec.index_usize_spec {α : Type u} [Inhabited α] (v: Vec α) (i: Usize)
113
99
(hbound : i.val < v.length) :
@@ -154,90 +140,90 @@ theorem Vec.index_mut_usize_spec {α : Type u} [Inhabited α] (v: Vec α) (i: Us
154
140
simp [h]
155
141
156
142
/- [ alloc::vec::Vec::index ] : forward function -/
157
- def Vec.index ( T I : Type ) (inst : core.slice.index.SliceIndex I (Slice T))
143
+ def Vec.index { T I : Type } (inst : core.slice.index.SliceIndex I (Slice T))
158
144
(self : Vec T) (i : I) : Result inst.Output :=
159
145
sorry -- TODO
160
146
161
147
/- [ alloc::vec::Vec::index_mut ] : forward function -/
162
- def Vec.index_mut ( T I : Type ) (inst : core.slice.index.SliceIndex I (Slice T))
148
+ def Vec.index_mut { T I : Type } (inst : core.slice.index.SliceIndex I (Slice T))
163
149
(self : Vec T) (i : I) :
164
150
Result (inst.Output × (inst.Output → Result (Vec T))) :=
165
151
sorry -- TODO
166
152
167
153
/- Trait implementation: [ alloc::vec::Vec ] -/
168
154
@[reducible]
169
- def Vec.coreopsindexIndexInst ( T I : Type )
155
+ def Vec.coreopsindexIndexInst { T I : Type }
170
156
(inst : core.slice.index.SliceIndex I (Slice T)) :
171
157
core.ops.index.Index (alloc.vec.Vec T) I := {
172
158
Output := inst.Output
173
- index := Vec.index T I inst
159
+ index := Vec.index inst
174
160
}
175
161
176
162
/- Trait implementation: [ alloc::vec::Vec ] -/
177
163
@[reducible]
178
- def Vec.coreopsindexIndexMutInst ( T I : Type )
164
+ def Vec.coreopsindexIndexMutInst { T I : Type }
179
165
(inst : core.slice.index.SliceIndex I (Slice T)) :
180
166
core.ops.index.IndexMut (alloc.vec.Vec T) I := {
181
- indexInst := Vec.coreopsindexIndexInst T I inst
182
- index_mut := Vec.index_mut T I inst
167
+ indexInst := Vec.coreopsindexIndexInst inst
168
+ index_mut := Vec.index_mut inst
183
169
}
184
170
185
171
@[simp]
186
172
theorem Vec.index_slice_index {α : Type } (v : Vec α) (i : Usize) :
187
- Vec.index α Usize (core.slice.index.SliceIndexUsizeSliceTInst α) v i =
173
+ Vec.index (core.slice.index.SliceIndexUsizeSliceTInst α) v i =
188
174
Vec.index_usize v i :=
189
175
sorry
190
176
191
177
@[simp]
192
178
theorem Vec.index_mut_slice_index {α : Type } (v : Vec α) (i : Usize) :
193
- Vec.index_mut α Usize (core.slice.index.SliceIndexUsizeSliceTInst α) v i =
179
+ Vec.index_mut (core.slice.index.SliceIndexUsizeSliceTInst α) v i =
194
180
index_mut_usize v i :=
195
181
sorry
196
182
197
183
end alloc.vec
198
184
199
185
/-- [ alloc::slice::{@Slice<T>}::to_vec ] -/
200
186
def alloc.slice.Slice.to_vec
201
- ( T : Type ) (cloneInst : core.clone.Clone T) (s : Slice T) : Result (alloc.vec.Vec T) :=
187
+ { T : Type } (cloneInst : core.clone.Clone T) (s : Slice T) : Result (alloc.vec.Vec T) :=
202
188
-- TODO: we need a monadic map
203
189
sorry
204
190
205
191
/-- [ core::slice::{@Slice<T>}::reverse ] -/
206
- def core.slice.Slice.reverse ( T : Type ) (s : Slice T) : Slice T :=
192
+ def core.slice.Slice.reverse { T : Type } (s : Slice T) : Slice T :=
207
193
⟨ s.val.reverse, by sorry ⟩
208
194
209
- def alloc.vec.Vec.with_capacity ( T : Type ) (_ : Usize) : alloc.vec.Vec T := Vec.new T
195
+ def alloc.vec.Vec.with_capacity { T : Type } (_ : Usize) : alloc.vec.Vec T := Vec.new T
210
196
211
197
/- [alloc::vec::{(core::ops::deref::Deref for alloc::vec::Vec<T, A>)#9}::deref]:
212
198
Source: '/rustc/d59363ad0b6391b7fc5bbb02c9ccf9300eef3753/library/alloc/src/vec/mod.rs', lines 2624:4-2624:27
213
199
Name pattern: alloc::vec::{core::ops::deref::Deref<alloc::vec::Vec<@T, @A>>}::deref -/
214
- def alloc.vec.DerefVec.deref ( T : Type ) (v : Vec T) : Slice T :=
200
+ def alloc.vec.DerefVec.deref { T : Type } (v : Vec T) : Slice T :=
215
201
⟨ v.val, v.property ⟩
216
202
217
203
@[reducible]
218
- def core.ops.deref.DerefVec ( T : Type ) : core.ops.deref.Deref (alloc.vec.Vec T) := {
204
+ def core.ops.deref.DerefVec { T : Type } : core.ops.deref.Deref (alloc.vec.Vec T) := {
219
205
Target := Slice T
220
- deref := fun v => ok (alloc.vec.DerefVec.deref T v)
206
+ deref := fun v => ok (alloc.vec.DerefVec.deref v)
221
207
}
222
208
223
209
/- [alloc::vec::{(core::ops::deref::DerefMut for alloc::vec::Vec<T, A>)#10}::deref_mut]:
224
210
Source: '/rustc/d59363ad0b6391b7fc5bbb02c9ccf9300eef3753/library/alloc/src/vec/mod.rs', lines 2632:4-2632:39
225
211
Name pattern: alloc::vec::{core::ops::deref::DerefMut<alloc::vec::Vec<@T, @A>>}::deref_mut -/
226
- def alloc.vec.DerefMutVec.deref_mut ( T : Type ) (v : alloc.vec.Vec T) :
212
+ def alloc.vec.DerefMutVec.deref_mut { T : Type } (v : alloc.vec.Vec T) :
227
213
Result ((Slice T) × (Slice T → Result (alloc.vec.Vec T))) :=
228
214
ok (⟨ v.val, v.property ⟩, λ s => ok ⟨ s.val, s.property ⟩)
229
215
230
216
/- Trait implementation: [alloc::vec::{(core::ops::deref::DerefMut for alloc::vec::Vec<T, A>)#10}]
231
217
Source: '/rustc/d59363ad0b6391b7fc5bbb02c9ccf9300eef3753/library/alloc/src/vec/mod.rs', lines 2630:0-2630:49
232
218
Name pattern: core::ops::deref::DerefMut<alloc::vec::Vec<@Self, @>> -/
233
219
@[reducible]
234
- def core.ops.deref.DerefMutVec ( T : Type ) :
220
+ def core.ops.deref.DerefMutVec { T : Type } :
235
221
core.ops.deref.DerefMut (alloc.vec.Vec T) := {
236
- derefInst := core.ops.deref.DerefVec T
237
- deref_mut := alloc.vec.DerefMutVec.deref_mut T
222
+ derefInst := core.ops.deref.DerefVec
223
+ deref_mut := alloc.vec.DerefMutVec.deref_mut
238
224
}
239
225
240
- def alloc.vec.Vec.resize ( T : Type ) (cloneInst : core.clone.Clone T)
226
+ def alloc.vec.Vec.resize { T : Type } (cloneInst : core.clone.Clone T)
241
227
(v : alloc.vec.Vec T) (new_len : Usize) (value : T) : Result (alloc.vec.Vec T) := do
242
228
if new_len.val < v.length then
243
229
ok ⟨ v.val.resize new_len.toNat value, by scalar_tac ⟩
@@ -249,7 +235,7 @@ def alloc.vec.Vec.resize (T : Type) (cloneInst : core.clone.Clone T)
249
235
theorem alloc.vec.Vec.resize_spec {T} (cloneInst : core.clone.Clone T)
250
236
(v : alloc.vec.Vec T) (new_len : Usize) (value : T)
251
237
(hClone : cloneInst.clone value = ok value) :
252
- ∃ nv, alloc.vec.Vec.resize T cloneInst v new_len value = ok nv ∧
238
+ ∃ nv, alloc.vec.Vec.resize cloneInst v new_len value = ok nv ∧
253
239
nv.val = v.val.resize new_len.toNat value := by
254
240
rw [resize]
255
241
split
0 commit comments