Skip to content

Commit

Permalink
Update the standard libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
sonmarcho committed Nov 21, 2023
1 parent dcd34ce commit c3b6ad3
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 78 deletions.
56 changes: 32 additions & 24 deletions backends/coq/Primitives.v
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,14 @@ Definition alloc_boxed_Box_deref_mut (T : Type) (x : T) : result T := Return x.
Definition alloc_boxed_Box_deref_mut_back (T : Type) (_ : T) (x : T) : result T := Return x.

(* Trait instance *)
Definition alloc_boxed_Box_coreOpsDerefInst (Self : Type) : core_ops_deref_Deref Self := {|
Definition alloc_boxed_Box_coreopsDerefInst (Self : Type) : core_ops_deref_Deref Self := {|
core_ops_deref_Deref_target := Self;
core_ops_deref_Deref_deref := alloc_boxed_Box_deref Self;
|}.

(* Trait instance *)
Definition alloc_boxed_Box_coreOpsDerefMutInst (Self : Type) : core_ops_deref_DerefMut Self := {|
core_ops_deref_DerefMut_derefInst := alloc_boxed_Box_coreOpsDerefInst Self;
Definition alloc_boxed_Box_coreopsDerefMutInst (Self : Type) : core_ops_deref_DerefMut Self := {|
core_ops_deref_DerefMut_derefInst := alloc_boxed_Box_coreopsDerefInst Self;
core_ops_deref_DerefMut_deref_mut := alloc_boxed_Box_deref_mut Self;
core_ops_deref_DerefMut_deref_mut_back := alloc_boxed_Box_deref_mut_back Self;
|}.
Expand Down Expand Up @@ -576,7 +576,7 @@ Definition alloc_vec_Vec_insert (T: Type) (v: alloc_vec_Vec T) (i: usize) (x: T)
else Fail_ Failure).

(* Helper *)
Axiom alloc_vec_Vec_index_usize : forall {T : Type} (v : alloc_vec_Vec T) (i : usize) (x : T), result T.
Axiom alloc_vec_Vec_index_usize : forall {T : Type} (v : alloc_vec_Vec T) (i : usize), result T.

(* Helper *)
Axiom alloc_vec_Vec_update_usize : forall {T : Type} (v : alloc_vec_Vec T) (i : usize) (x : T), result (alloc_vec_Vec T).
Expand Down Expand Up @@ -683,22 +683,14 @@ Axiom core_array_Array_index_mut_back :
forall (T Idx : Type) (N : usize) (inst : core_ops_index_IndexMut (slice T) Idx)
(a : array T N) (i : Idx) (x : inst.(core_ops_index_IndexMut_indexInst).(core_ops_index_Index_Output)), result (array T N).

(* Trait implementation: [core::slice::index::[T]] *)
Definition core_slice_index_Slice_coreopsindexIndexInst (T Idx : Type)
(inst : core_slice_index_SliceIndex Idx (slice T)) :
core_ops_index_Index (slice T) Idx := {|
core_ops_index_Index_Output := inst.(core_slice_index_SliceIndex_Output);
core_ops_index_Index_index := core_slice_index_Slice_index T Idx inst;
|}.

(* Trait implementation: [core::slice::index::private_slice_index::Range] *)
Definition core_slice_index_private_slice_index_Range_coresliceindexprivate_slice_indexSealedInst
Definition core_slice_index_private_slice_index_SealedRangeUsizeInst
: core_slice_index_private_slice_index_Sealed (core_ops_range_Range usize) := tt.

(* Trait implementation: [core::slice::index::Range] *)
Definition core_slice_index_Range_coresliceindexSliceIndexInst (T : Type) :
Definition core_slice_index_SliceIndexRangeUsizeSliceTInst (T : Type) :
core_slice_index_SliceIndex (core_ops_range_Range usize) (slice T) := {|
core_slice_index_SliceIndex_sealedInst := core_slice_index_private_slice_index_Range_coresliceindexprivate_slice_indexSealedInst;
core_slice_index_SliceIndex_sealedInst := core_slice_index_private_slice_index_SealedRangeUsizeInst;
core_slice_index_SliceIndex_Output := slice T;
core_slice_index_SliceIndex_get := core_slice_index_Range_get T;
core_slice_index_SliceIndex_get_mut := core_slice_index_Range_get_mut T;
Expand All @@ -711,27 +703,35 @@ Definition core_slice_index_Range_coresliceindexSliceIndexInst (T : Type) :
|}.

(* Trait implementation: [core::slice::index::[T]] *)
Definition core_slice_index_Slice_coreopsindexIndexMutInst (T Idx : Type)
Definition core_ops_index_IndexSliceTIInst (T Idx : Type)
(inst : core_slice_index_SliceIndex Idx (slice T)) :
core_ops_index_Index (slice T) Idx := {|
core_ops_index_Index_Output := inst.(core_slice_index_SliceIndex_Output);
core_ops_index_Index_index := core_slice_index_Slice_index T Idx inst;
|}.

(* Trait implementation: [core::slice::index::[T]] *)
Definition core_ops_index_IndexMutSliceTIInst (T Idx : Type)
(inst : core_slice_index_SliceIndex Idx (slice T)) :
core_ops_index_IndexMut (slice T) Idx := {|
core_ops_index_IndexMut_indexInst := core_slice_index_Slice_coreopsindexIndexInst T Idx inst;
core_ops_index_IndexMut_indexInst := core_ops_index_IndexSliceTIInst T Idx inst;
core_ops_index_IndexMut_index_mut := core_slice_index_Slice_index_mut T Idx inst;
core_ops_index_IndexMut_index_mut_back := core_slice_index_Slice_index_mut_back T Idx inst;
|}.

(* Trait implementation: [core::array::[T; N]] *)
Definition core_array_Array_coreopsindexIndexInst (T Idx : Type) (N : usize)
Definition core_ops_index_IndexArrayInst (T Idx : Type) (N : usize)
(inst : core_ops_index_Index (slice T) Idx) :
core_ops_index_Index (array T N) Idx := {|
core_ops_index_Index_Output := inst.(core_ops_index_Index_Output);
core_ops_index_Index_index := core_array_Array_index T Idx N inst;
|}.

(* Trait implementation: [core::array::[T; N]] *)
Definition core_array_Array_coreopsindexIndexMutInst (T Idx : Type) (N : usize)
Definition core_ops_index_IndexMutArrayInst (T Idx : Type) (N : usize)
(inst : core_ops_index_IndexMut (slice T) Idx) :
core_ops_index_IndexMut (array T N) Idx := {|
core_ops_index_IndexMut_indexInst := core_array_Array_coreopsindexIndexInst T Idx N inst.(core_ops_index_IndexMut_indexInst);
core_ops_index_IndexMut_indexInst := core_ops_index_IndexArrayInst T Idx N inst.(core_ops_index_IndexMut_indexInst);
core_ops_index_IndexMut_index_mut := core_array_Array_index_mut T Idx N inst;
core_ops_index_IndexMut_index_mut_back := core_array_Array_index_mut_back T Idx N inst;
|}.
Expand Down Expand Up @@ -765,13 +765,13 @@ Axiom core_slice_index_usize_index_mut_back :
forall (T : Type), usize -> slice T -> T -> result (slice T).

(* Trait implementation: [core::slice::index::private_slice_index::usize] *)
Definition core_slice_index_private_slice_index_usize_coresliceindexprivate_slice_indexSealedInst
Definition core_slice_index_private_slice_index_SealedUsizeInst
: core_slice_index_private_slice_index_Sealed usize := tt.

(* Trait implementation: [core::slice::index::usize] *)
Definition core_slice_index_usize_coresliceindexSliceIndexInst (T : Type) :
Definition core_slice_index_SliceIndexUsizeSliceTInst (T : Type) :
core_slice_index_SliceIndex usize (slice T) := {|
core_slice_index_SliceIndex_sealedInst := core_slice_index_private_slice_index_usize_coresliceindexprivate_slice_indexSealedInst;
core_slice_index_SliceIndex_sealedInst := core_slice_index_private_slice_index_SealedUsizeInst;
core_slice_index_SliceIndex_Output := T;
core_slice_index_SliceIndex_get := core_slice_index_usize_get T;
core_slice_index_SliceIndex_get_mut := core_slice_index_usize_get_mut T;
Expand Down Expand Up @@ -815,8 +815,16 @@ Definition alloc_vec_Vec_coreopsindexIndexMutInst (T Idx : Type)

(*** Theorems *)

Axiom alloc_vec_Vec_index_eq : forall {a : Type} (v : alloc_vec_Vec a) (i : usize) (x : a),
alloc_vec_Vec_index a usize (core_slice_index_SliceIndexUsizeSliceTInst a) v i =
alloc_vec_Vec_index_usize v i.

Axiom alloc_vec_Vec_index_mut_eq : forall {a : Type} (v : alloc_vec_Vec a) (i : usize) (x : a),
alloc_vec_Vec_index_mut a usize (core_slice_index_SliceIndexUsizeSliceTInst a) v i =
alloc_vec_Vec_index_usize v i.

Axiom alloc_vec_Vec_index_mut_back_eq : forall {a : Type} (v : alloc_vec_Vec a) (i : usize) (x : a),
alloc_vec_Vec_index_mut_back a usize (core_slice_index_usize_coresliceindexSliceIndexInst a) v i x =
alloc_vec_Vec_index_mut_back a usize (core_slice_index_SliceIndexUsizeSliceTInst a) v i x =
alloc_vec_Vec_update_usize v i x.

End Primitives.
56 changes: 28 additions & 28 deletions backends/fstar/Primitives.fst
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,14 @@ let alloc_boxed_Box_deref_mut (t : Type0) (x : t) : result t = Return x
let alloc_boxed_Box_deref_mut_back (t : Type) (_ : t) (x : t) : result t = Return x

// Trait instance
let alloc_boxed_Box_coreOpsDerefInst (self : Type0) : core_ops_deref_Deref self = {
let alloc_boxed_Box_coreopsDerefInst (self : Type0) : core_ops_deref_Deref self = {
target = self;
deref = alloc_boxed_Box_deref self;
}

// Trait instance
let alloc_boxed_Box_coreOpsDerefMutInst (self : Type0) : core_ops_deref_DerefMut self = {
derefInst = alloc_boxed_Box_coreOpsDerefInst self;
let alloc_boxed_Box_coreopsDerefMutInst (self : Type0) : core_ops_deref_DerefMut self = {
derefInst = alloc_boxed_Box_coreopsDerefInst self;
deref_mut = alloc_boxed_Box_deref_mut self;
deref_mut_back = alloc_boxed_Box_deref_mut_back self;
}
Expand Down Expand Up @@ -559,22 +559,14 @@ let core_array_Array_index_mut_back
(a : array t n) (i : idx) (x : inst.indexInst.output) : result (array t n) =
admit () // TODO

// Trait implementation: [core::slice::index::[T]]
let core_slice_index_Slice_coreopsindexIndexInst (t idx : Type0)
(inst : core_slice_index_SliceIndex idx (slice t)) :
core_ops_index_Index (slice t) idx = {
output = inst.output;
index = core_slice_index_Slice_index t idx inst;
}

// Trait implementation: [core::slice::index::private_slice_index::Range]
let core_slice_index_private_slice_index_Range_coresliceindexprivate_slice_indexSealedInst
let core_slice_index_private_slice_index_SealedRangeUsizeInst
: core_slice_index_private_slice_index_Sealed (core_ops_range_Range usize) = ()

// Trait implementation: [core::slice::index::Range]
let core_slice_index_Range_coresliceindexSliceIndexInst (t : Type0) :
let core_slice_index_SliceIndexRangeUsizeSliceTInst (t : Type0) :
core_slice_index_SliceIndex (core_ops_range_Range usize) (slice t) = {
sealedInst = core_slice_index_private_slice_index_Range_coresliceindexprivate_slice_indexSealedInst;
sealedInst = core_slice_index_private_slice_index_SealedRangeUsizeInst;
output = slice t;
get = core_slice_index_Range_get t;
get_mut = core_slice_index_Range_get_mut t;
Expand All @@ -587,27 +579,35 @@ let core_slice_index_Range_coresliceindexSliceIndexInst (t : Type0) :
}

// Trait implementation: [core::slice::index::[T]]
let core_slice_index_Slice_coreopsindexIndexMutInst (t idx : Type0)
let core_ops_index_IndexSliceTIInst (t idx : Type0)
(inst : core_slice_index_SliceIndex idx (slice t)) :
core_ops_index_Index (slice t) idx = {
output = inst.output;
index = core_slice_index_Slice_index t idx inst;
}

// Trait implementation: [core::slice::index::[T]]
let core_ops_index_IndexMutSliceTIInst (t idx : Type0)
(inst : core_slice_index_SliceIndex idx (slice t)) :
core_ops_index_IndexMut (slice t) idx = {
indexInst = core_slice_index_Slice_coreopsindexIndexInst t idx inst;
indexInst = core_ops_index_IndexSliceTIInst t idx inst;
index_mut = core_slice_index_Slice_index_mut t idx inst;
index_mut_back = core_slice_index_Slice_index_mut_back t idx inst;
}

// Trait implementation: [core::array::[T; N]]
let core_array_Array_coreopsindexIndexInst (t idx : Type0) (n : usize)
let core_ops_index_IndexArrayInst (t idx : Type0) (n : usize)
(inst : core_ops_index_Index (slice t) idx) :
core_ops_index_Index (array t n) idx = {
output = inst.output;
index = core_array_Array_index t idx n inst;
}

// Trait implementation: [core::array::[T; N]]
let core_array_Array_coreopsindexIndexMutInst (t idx : Type0) (n : usize)
let core_ops_index_IndexMutArrayIInst (t idx : Type0) (n : usize)
(inst : core_ops_index_IndexMut (slice t) idx) :
core_ops_index_IndexMut (array t n) idx = {
indexInst = core_array_Array_coreopsindexIndexInst t idx n inst.indexInst;
indexInst = core_ops_index_IndexArrayInst t idx n inst.indexInst;
index_mut = core_array_Array_index_mut t idx n inst;
index_mut_back = core_array_Array_index_mut_back t idx n inst;
}
Expand Down Expand Up @@ -651,13 +651,13 @@ let core_slice_index_usize_index_mut_back
admit () // TODO

// Trait implementation: [core::slice::index::private_slice_index::usize]
let core_slice_index_private_slice_index_usize_coresliceindexprivate_slice_indexSealedInst
let core_slice_index_private_slice_index_SealedUsizeInst
: core_slice_index_private_slice_index_Sealed usize = ()

// Trait implementation: [core::slice::index::usize]
let core_slice_index_usize_coresliceindexSliceIndexInst (t : Type0) :
let core_slice_index_SliceIndexUsizeSliceTInst (t : Type0) :
core_slice_index_SliceIndex usize (slice t) = {
sealedInst = core_slice_index_private_slice_index_usize_coresliceindexprivate_slice_indexSealedInst;
sealedInst = core_slice_index_private_slice_index_SealedUsizeInst;
output = t;
get = core_slice_index_usize_get t;
get_mut = core_slice_index_usize_get_mut t;
Expand Down Expand Up @@ -706,24 +706,24 @@ let alloc_vec_Vec_coreopsindexIndexMutInst (t idx : Type0)

let alloc_vec_Vec_index_eq (#a : Type0) (v : alloc_vec_Vec a) (i : usize) :
Lemma (
alloc_vec_Vec_index a usize (core_slice_index_usize_coresliceindexSliceIndexInst a) v i ==
alloc_vec_Vec_index a usize (core_slice_index_SliceIndexUsizeSliceTInst a) v i ==
alloc_vec_Vec_index_usize v i)
[SMTPat (alloc_vec_Vec_index a usize (core_slice_index_usize_coresliceindexSliceIndexInst a) v i)]
[SMTPat (alloc_vec_Vec_index a usize (core_slice_index_SliceIndexUsizeSliceTInst a) v i)]
=
admit()

let alloc_vec_Vec_index_mut_eq (#a : Type0) (v : alloc_vec_Vec a) (i : usize) :
Lemma (
alloc_vec_Vec_index_mut a usize (core_slice_index_usize_coresliceindexSliceIndexInst a) v i ==
alloc_vec_Vec_index_mut a usize (core_slice_index_SliceIndexUsizeSliceTInst a) v i ==
alloc_vec_Vec_index_usize v i)
[SMTPat (alloc_vec_Vec_index_mut a usize (core_slice_index_usize_coresliceindexSliceIndexInst a) v i)]
[SMTPat (alloc_vec_Vec_index_mut a usize (core_slice_index_SliceIndexUsizeSliceTInst a) v i)]
=
admit()

let alloc_vec_Vec_index_mut_back_eq (#a : Type0) (v : alloc_vec_Vec a) (i : usize) (x : a) :
Lemma (
alloc_vec_Vec_index_mut_back a usize (core_slice_index_usize_coresliceindexSliceIndexInst a) v i x ==
alloc_vec_Vec_index_mut_back a usize (core_slice_index_SliceIndexUsizeSliceTInst a) v i x ==
alloc_vec_Vec_update_usize v i x)
[SMTPat (alloc_vec_Vec_index_mut_back a usize (core_slice_index_usize_coresliceindexSliceIndexInst a) v i x)]
[SMTPat (alloc_vec_Vec_index_mut_back a usize (core_slice_index_SliceIndexUsizeSliceTInst a) v i x)]
=
admit()
6 changes: 3 additions & 3 deletions backends/lean/Base/Primitives/Alloc.lean
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def deref_mut (T : Type) (x : T) : Result T := ret x
def deref_mut_back (T : Type) (_ : T) (x : T) : Result T := ret x

/-- Trait instance -/
def coreOpsDerefInst (Self : Type) :
def coreopsDerefInst (Self : Type) :
core.ops.deref.Deref Self := {
Target := Self
deref := deref Self
}

/-- Trait instance -/
def coreOpsDerefMutInst (Self : Type) :
def coreopsDerefMutInst (Self : Type) :
core.ops.deref.DerefMut Self := {
derefInst := coreOpsDerefInst Self
derefInst := coreopsDerefInst Self
deref_mut := deref_mut Self
deref_mut_back := deref_mut_back Self
}
Expand Down
39 changes: 19 additions & 20 deletions backends/lean/Base/Primitives/ArraySlice.lean
Original file line number Diff line number Diff line change
Expand Up @@ -439,23 +439,14 @@ def core.array.Array.index_mut_back
(a : Array T N) (i : I) (x : inst.indexInst.Output) : Result (Array T N) :=
sorry -- TODO

/- Trait implementation: [core::slice::index::[T]] -/
def core.slice.index.Slice.coreopsindexIndexInst (T I : Type)
(inst : core.slice.index.SliceIndex I (Slice T)) :
core.ops.index.Index (Slice T) I := {
Output := inst.Output
index := core.slice.index.Slice.index T I inst
}

/- Trait implementation: [core::slice::index::private_slice_index::Range] -/
def core.slice.index.private_slice_index.Range.coresliceindexprivate_slice_indexSealedInst
def core.slice.index.private_slice_index.SealedRangeUsizeInst
: core.slice.index.private_slice_index.Sealed (Range Usize) := {}

/- Trait implementation: [core::slice::index::Range] -/
def core.slice.index.Range.coresliceindexSliceIndexInst (T : Type) :
def core.slice.index.SliceIndexRangeUsizeSliceTInst (T : Type) :
core.slice.index.SliceIndex (Range Usize) (Slice T) := {
sealedInst :=
core.slice.index.private_slice_index.Range.coresliceindexprivate_slice_indexSealedInst
sealedInst := core.slice.index.private_slice_index.SealedRangeUsizeInst
Output := Slice T
get := core.slice.index.Range.get T
get_mut := core.slice.index.Range.get_mut T
Expand All @@ -468,27 +459,35 @@ def core.slice.index.Range.coresliceindexSliceIndexInst (T : Type) :
}

/- Trait implementation: [core::slice::index::[T]] -/
def core.slice.index.Slice.coreopsindexIndexMutInst (T I : Type)
def core.ops.index.IndexSliceTIInst (T I : Type)
(inst : core.slice.index.SliceIndex I (Slice T)) :
core.ops.index.Index (Slice T) I := {
Output := inst.Output
index := core.slice.index.Slice.index T I inst
}

/- Trait implementation: [core::slice::index::[T]] -/
def core.ops.index.IndexMutSliceTIInst (T I : Type)
(inst : core.slice.index.SliceIndex I (Slice T)) :
core.ops.index.IndexMut (Slice T) I := {
indexInst := core.slice.index.Slice.coreopsindexIndexInst T I inst
indexInst := core.ops.index.IndexSliceTIInst T I inst
index_mut := core.slice.index.Slice.index_mut T I inst
index_mut_back := core.slice.index.Slice.index_mut_back T I inst
}

/- Trait implementation: [core::array::[T; N]] -/
def core.array.Array.coreopsindexIndexInst (T I : Type) (N : Usize)
def core.ops.index.IndexArrayIInst (T I : Type) (N : Usize)
(inst : core.ops.index.Index (Slice T) I) :
core.ops.index.Index (Array T N) I := {
Output := inst.Output
index := core.array.Array.index T I N inst
}

/- Trait implementation: [core::array::[T; N]] -/
def core.array.Array.coreopsindexIndexMutInst (T I : Type) (N : Usize)
def core.ops.index.IndexMutArrayIInst (T I : Type) (N : Usize)
(inst : core.ops.index.IndexMut (Slice T) I) :
core.ops.index.IndexMut (Array T N) I := {
indexInst := core.array.Array.coreopsindexIndexInst T I N inst.indexInst
indexInst := core.ops.index.IndexArrayIInst T I N inst.indexInst
index_mut := core.array.Array.index_mut T I N inst
index_mut_back := core.array.Array.index_mut_back T I N inst
}
Expand Down Expand Up @@ -532,13 +531,13 @@ def core.slice.index.Usize.index_mut_back
sorry -- TODO

/- Trait implementation: [core::slice::index::private_slice_index::usize] -/
def core.slice.index.private_slice_index.usize.coresliceindexprivate_slice_indexSealedInst
def core.slice.index.private_slice_index.SealedUsizeInst
: core.slice.index.private_slice_index.Sealed Usize := {}

/- Trait implementation: [core::slice::index::usize] -/
def core.slice.index.usize.coresliceindexSliceIndexInst (T : Type) :
def core.slice.index.SliceIndexUsizeSliceTInst (T : Type) :
core.slice.index.SliceIndex Usize (Slice T) := {
sealedInst := core.slice.index.private_slice_index.usize.coresliceindexprivate_slice_indexSealedInst
sealedInst := core.slice.index.private_slice_index.SealedUsizeInst
Output := T
get := core.slice.index.Usize.get T
get_mut := core.slice.index.Usize.get_mut T
Expand Down
6 changes: 3 additions & 3 deletions backends/lean/Base/Primitives/Vec.lean
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,19 @@ def Vec.coreopsindexIndexMutInst (T I : Type)

@[simp]
theorem Vec.index_slice_index {α : Type} (v : Vec α) (i : Usize) :
Vec.index α Usize (core.slice.index.usize.coresliceindexSliceIndexInst α) v i =
Vec.index α Usize (core.slice.index.SliceIndexUsizeSliceTInst α) v i =
Vec.index_usize v i :=
sorry

@[simp]
theorem Vec.index_mut_slice_index {α : Type} (v : Vec α) (i : Usize) :
Vec.index_mut α Usize (core.slice.index.usize.coresliceindexSliceIndexInst α) v i =
Vec.index_mut α Usize (core.slice.index.SliceIndexUsizeSliceTInst α) v i =
Vec.index_usize v i :=
sorry

@[simp]
theorem Vec.index_mut_back_slice_index {α : Type} (v : Vec α) (i : Usize) (x : α) :
Vec.index_mut_back α Usize (core.slice.index.usize.coresliceindexSliceIndexInst α) v i x =
Vec.index_mut_back α Usize (core.slice.index.SliceIndexUsizeSliceTInst α) v i x =
Vec.update_usize v i x :=
sorry

Expand Down

0 comments on commit c3b6ad3

Please sign in to comment.