diff --git a/CoqOfRust/M.v b/CoqOfRust/M.v index 369e83aab..95efe5e4f 100644 --- a/CoqOfRust/M.v +++ b/CoqOfRust/M.v @@ -1,6 +1,8 @@ (** * The definition of a Rust monad. *) Require Coq.Strings.String. +Local Open Scope list. + Inductive sigS {A : Type} (P : A -> Set) : Set := | existS : forall (x : A), P x -> sigS P. Arguments existS {_ _}. @@ -79,11 +81,13 @@ Module LowM. | Pure : A -> t A | CallPrimitive {B : Set} : Primitive B -> (B -> t A) -> t A | Cast {B1 B2 : Set} : B1 -> (B2 -> t A) -> t A + | Loop {B : Set} : t B -> (B -> bool) -> (B -> t A) -> t A | Impossible : t A | Call {B : Set} : t B -> (B -> t A) -> t A. Arguments Pure {_}. Arguments CallPrimitive {_ _}. Arguments Cast {_ _ _}. + Arguments Loop {_ _}. Arguments Impossible {_}. Arguments Call {_ _}. @@ -94,6 +98,7 @@ Module LowM. CallPrimitive primitive (fun v => let_ (k v) f) | Cast v k => Cast v (fun v' => let_ (k v') f) + | Loop body is_break k => Loop body is_break (fun v => let_ (k v) f) | Impossible => Impossible | Call e k => Call e (fun v => let_ (k v) f) end. @@ -108,6 +113,8 @@ Module Exception. | Continue : t (** exceptions for Rust's `break` *) | Break : t + (** to translate the [match] patterns with (de)references *) + | BreakMatch : t | Panic : Coq.Strings.String.string -> t. End Exception. Definition Exception : Set := Exception.t. @@ -167,32 +174,15 @@ Definition continue {A : Set} : M A := Definition break {A : Set} : M A := raise Exception.Break. +Definition break_match {A : Set} : M A := + raise Exception.BreakMatch. + Definition panic {A : Set} (message : Coq.Strings.String.string) : M A := raise (Exception.Panic message). Definition call {A : Set} (e : M A) : M A := LowM.Call e LowM.Pure. -(* TODO: define for every (A : Set) in (M A) *) -(** the definition of a function representing the loop construction *) -(* Definition loop (m : M unit) : M unit := - fix F (fuel : nat) {struct fuel} := - match fuel with - | 0 => LowM.Pure (inr Exception.NonTermination) - | S fuel' => - let- v := m fuel in - match v with - (* only Break ends the loop *) - | inl tt => F fuel' - | inr Exception.Continue => F fuel' - | inr Exception.Break => LowM.Pure (inl tt) - (* every other exception is kept *) - | inr (Exception.Return _) - | inr (Exception.Panic _) - | inr Exception.NonTermination => LowM.Pure (v) - end - end. *) - Definition alloc {A : Set} (v : A) : M (Ref A) := let- ref := LowM.CallPrimitive (Primitive.StateAlloc v) LowM.Pure in LowM.Pure (inl ref). @@ -257,3 +247,51 @@ Definition catch_return {A : Set} (body : M A) : M A := | _ => raise exception end ). + +Definition catch_continue (body : M unit) : M unit := + catch + body + (fun exception => + match exception with + | Exception.Continue => pure tt + | _ => raise exception + end + ). + +Definition catch_break (body : M unit) : M unit := + catch + body + (fun exception => + match exception with + | Exception.Break => pure tt + | _ => raise exception + end + ). + +Definition loop (body : M unit) : M unit := + LowM.Loop + (catch_continue body) + (fun result => + match result with + | inl _ => false + | inr _ => true + end) + (fun result => + catch_break (LowM.Pure result)). + +Fixpoint match_operator {A B : Set} + (scrutinee : A) + (arms : list (A -> M B)) : + M B := + match arms with + | nil => impossible + | arm :: arms => + catch + (arm scrutinee) + (fun exception => + match exception with + | Exception.BreakMatch => match_operator scrutinee arms + | _ => raise exception + end + ) + end. diff --git a/CoqOfRust/core/iter.v b/CoqOfRust/core/iter.v index 322db5ad2..ca0728e6e 100644 --- a/CoqOfRust/core/iter.v +++ b/CoqOfRust/core/iter.v @@ -427,8 +427,8 @@ Module traits. where I: Iterator, *) - Global Instance I_Iterator (I Item : Set) - {H0 : iterator.Iterator.Trait I (Item := Item)} : + Global Instance I_Iterator {I Item : Set} + (H0 : iterator.Iterator.Trait I (Item := Item)) : IntoIterator.Trait I := { Item := Item; IntoIter := I; @@ -442,7 +442,7 @@ End traits. (* impl<'a, T> Iterator for Iter<'a, T> *) -Global Instance I_Iter (T : Set) : +Global Instance I_Iter {T : Set} : traits.iterator.Iterator.Trait (slice.iter.Iter.t T) (Item := T). Admitted. @@ -451,9 +451,9 @@ impl Iterator for Zipwhere A: Iterator, B: Iterator, *) -Global Instance I_Zip (A B Item_A Item_B : Set) - {H0 : traits.iterator.Iterator.Trait A (Item := Item_A)} - {H1 : traits.iterator.Iterator.Trait B (Item := Item_B)} : - traits.iterator.Iterator.Trait - (adapters.zip.Zip.t A B) (Item := Item_A * Item_B). +Global Instance I_Zip {A B Item_A Item_B : Set} + (H0 : traits.iterator.Iterator.Trait A (Item := Item_A)) + (H1 : traits.iterator.Iterator.Trait B (Item := Item_B)) : + traits.iterator.Iterator.Trait + (adapters.zip.Zip.t A B) (Item := Item_A * Item_B). Admitted. diff --git a/CoqOfRust/core/ops.v b/CoqOfRust/core/ops.v index 40d42fb71..86ed649bb 100644 --- a/CoqOfRust/core/ops.v +++ b/CoqOfRust/core/ops.v @@ -603,6 +603,22 @@ Module control_flow. | Break : B -> t B C. Arguments Continue {_ _}. Arguments Break {_ _}. + + Global Instance Get_Continue_0 {B C : Set} : Notations.Dot "Continue.0" := { + Notations.dot := + Ref.map (Big := t B C) + (fun α => match α with | Continue α0 => Some α0 | _ => None end) + (fun β α => + match α with | Continue _ => Some (Continue β) | _ => None end); + }. + + Global Instance Get_Break_0 {B C : Set} : Notations.Dot "Break.0" := { + Notations.dot := + Ref.map (Big := t B C) + (fun α => match α with | Break α0 => Some α0 | _ => None end) + (fun β α => + match α with | Break _ => Some (Break β) | _ => None end); + }. End ControlFlow. End control_flow. diff --git a/CoqOfRust/core/option.v b/CoqOfRust/core/option.v index 7f09bcf4a..3c38ee83a 100644 --- a/CoqOfRust/core/option.v +++ b/CoqOfRust/core/option.v @@ -44,6 +44,21 @@ Module Option. | Some : T -> t T. Arguments None {_}. Arguments Some {_}. + + Global Instance Get_Some_0 {T : Set} : Notations.Dot "Some.0" := { + Notations.dot := + Ref.map (Big := t T) + (fun α => + match α with + | Some α0 => Datatypes.Some α0 + | _ => Datatypes.None + end) + (fun β α => + match α with + | Some _ => Datatypes.Some (Some β) + | _ => Datatypes.None + end); + }. End Option. Module Impl_Option. Section Impl_Option. diff --git a/CoqOfRust/core/result_types.v b/CoqOfRust/core/result_types.v index 47b064db6..70ad81d0a 100644 --- a/CoqOfRust/core/result_types.v +++ b/CoqOfRust/core/result_types.v @@ -48,4 +48,18 @@ Module Result. | Err : E -> t T E. Arguments Ok {T E} _. Arguments Err {T E} _. + + Global Instance Get_Ok_0 {T E : Set} : Notations.Dot "Ok.0" := { + Notations.dot := + Ref.map (Big := t T E) + (fun α => match α with Ok α0 => Some α0 | _ => None end) + (fun β α => match α with Ok _ => Some (Ok β) | _ => None end); + }. + + Global Instance Get_Err_0 {T E : Set} : Notations.Dot "Err.0" := { + Notations.dot := + Ref.map (Big := t T E) + (fun α => match α with Err α0 => Some α0 | _ => None end) + (fun β α => match α with Err _ => Some (Err β) | _ => None end); + }. End Result. diff --git a/CoqOfRust/examples/default/examples/cargo/concurrent_tests.v b/CoqOfRust/examples/default/examples/cargo/concurrent_tests.v index b4494e80a..38baaee22 100644 --- a/CoqOfRust/examples/default/examples/cargo/concurrent_tests.v +++ b/CoqOfRust/examples/default/examples/cargo/concurrent_tests.v @@ -11,38 +11,54 @@ fn foo(o: Option) { *) Definition foo {A : Set} (o : core.option.Option.t A) : M unit := let* o := M.alloc o in - let* α0 : core.option.Option.t A := M.read o in - let* α1 : M.Val unit := - match α0 with - | core.option.Option.Some _a => - let* _a := M.alloc _a in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "some + let* α0 : M.Val unit := + match_operator + o + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* _a := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "some ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | core.option.Option.None => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "nothing + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "nothing ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in - M.read α1. + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. Module tests. (* @@ -88,51 +104,73 @@ Module tests. core.ops.range.Range.start := Integer.of_Z 0; core.ops.range.Range.end_ := Integer.of_Z 5; |}) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t i32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Ferris -") in - let* α1 : ref (slice u8.t) := M.call (str.t::["as_bytes"] α0) in - let* α2 : core.result.Result.t unit std.io.error.Error.t := + let* α1 : M.Val (core.ops.range.Range.t i32.t) := M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t i32.t := M.call - ((std.io.Write.write_all - (Self := std.fs.File.t) + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t i32.t) (Trait := ltac:(refine _))) - (borrow_mut file) - α1) in - let* α3 : ref str.t := - M.read (mk_str "Could not write to ferris.txt") in - let* α4 : unit := - M.call - ((core.result.Result.t - unit - std.io.error.Error.t)::["expect"] - α2 - α3) in - M.alloc α4 in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α1). + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t i32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Ferris +") in + let* α1 : ref (slice u8.t) := + M.call (str.t::["as_bytes"] α0) in + let* α2 : + core.result.Result.t unit std.io.error.Error.t := + M.call + ((std.io.Write.write_all + (Self := std.fs.File.t) + (Trait := ltac:(refine _))) + (borrow_mut file) + α1) in + let* α3 : ref str.t := + M.read (mk_str "Could not write to ferris.txt") in + let* α4 : unit := + M.call + ((core.result.Result.t + unit + std.io.error.Error.t)::["expect"] + α2 + α3) in + M.alloc α4 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α2). (* fn test_file_also() { @@ -177,51 +215,73 @@ Module tests. core.ops.range.Range.start := Integer.of_Z 0; core.ops.range.Range.end_ := Integer.of_Z 5; |}) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t i32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Corro -") in - let* α1 : ref (slice u8.t) := M.call (str.t::["as_bytes"] α0) in - let* α2 : core.result.Result.t unit std.io.error.Error.t := + let* α1 : M.Val (core.ops.range.Range.t i32.t) := M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t i32.t := M.call - ((std.io.Write.write_all - (Self := std.fs.File.t) + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t i32.t) (Trait := ltac:(refine _))) - (borrow_mut file) - α1) in - let* α3 : ref str.t := - M.read (mk_str "Could not write to ferris.txt") in - let* α4 : unit := - M.call - ((core.result.Result.t - unit - std.io.error.Error.t)::["expect"] - α2 - α3) in - M.alloc α4 in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α1). + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t i32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Corro +") in + let* α1 : ref (slice u8.t) := + M.call (str.t::["as_bytes"] α0) in + let* α2 : + core.result.Result.t unit std.io.error.Error.t := + M.call + ((std.io.Write.write_all + (Self := std.fs.File.t) + (Trait := ltac:(refine _))) + (borrow_mut file) + α1) in + let* α3 : ref str.t := + M.read (mk_str "Could not write to ferris.txt") in + let* α4 : unit := + M.call + ((core.result.Result.t + unit + std.io.error.Error.t)::["expect"] + α2 + α3) in + M.alloc α4 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α2). End tests. (* @@ -267,49 +327,73 @@ Definition test_file : M unit := core.ops.range.Range.start := Integer.of_Z 0; core.ops.range.Range.end_ := Integer.of_Z 5; |}) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t i32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Ferris -") in - let* α1 : ref (slice u8.t) := M.call (str.t::["as_bytes"] α0) in - let* α2 : core.result.Result.t unit std.io.error.Error.t := + let* α1 : M.Val (core.ops.range.Range.t i32.t) := M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t i32.t := M.call - ((std.io.Write.write_all - (Self := std.fs.File.t) + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t i32.t) (Trait := ltac:(refine _))) - (borrow_mut file) - α1) in - let* α3 : ref str.t := - M.read (mk_str "Could not write to ferris.txt") in - let* α4 : unit := - M.call - ((core.result.Result.t unit std.io.error.Error.t)::["expect"] - α2 - α3) in - M.alloc α4 in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α1). + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t i32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Ferris +") in + let* α1 : ref (slice u8.t) := + M.call (str.t::["as_bytes"] α0) in + let* α2 : + core.result.Result.t unit std.io.error.Error.t := + M.call + ((std.io.Write.write_all + (Self := std.fs.File.t) + (Trait := ltac:(refine _))) + (borrow_mut file) + α1) in + let* α3 : ref str.t := + M.read (mk_str "Could not write to ferris.txt") in + let* α4 : unit := + M.call + ((core.result.Result.t + unit + std.io.error.Error.t)::["expect"] + α2 + α3) in + M.alloc α4 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α2). (* fn test_file_also() { @@ -354,46 +438,70 @@ Definition test_file_also : M unit := core.ops.range.Range.start := Integer.of_Z 0; core.ops.range.Range.end_ := Integer.of_Z 5; |}) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t i32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Corro -") in - let* α1 : ref (slice u8.t) := M.call (str.t::["as_bytes"] α0) in - let* α2 : core.result.Result.t unit std.io.error.Error.t := + let* α1 : M.Val (core.ops.range.Range.t i32.t) := M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t i32.t := M.call - ((std.io.Write.write_all - (Self := std.fs.File.t) + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t i32.t) (Trait := ltac:(refine _))) - (borrow_mut file) - α1) in - let* α3 : ref str.t := - M.read (mk_str "Could not write to ferris.txt") in - let* α4 : unit := - M.call - ((core.result.Result.t unit std.io.error.Error.t)::["expect"] - α2 - α3) in - M.alloc α4 in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α1). + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t i32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Corro +") in + let* α1 : ref (slice u8.t) := + M.call (str.t::["as_bytes"] α0) in + let* α2 : + core.result.Result.t unit std.io.error.Error.t := + M.call + ((std.io.Write.write_all + (Self := std.fs.File.t) + (Trait := ltac:(refine _))) + (borrow_mut file) + α1) in + let* α3 : ref str.t := + M.read (mk_str "Could not write to ferris.txt") in + let* α4 : unit := + M.call + ((core.result.Result.t + unit + std.io.error.Error.t)::["expect"] + α2 + α3) in + M.alloc α4 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α2). diff --git a/CoqOfRust/examples/default/examples/conversion/try_from_and_try_into.v b/CoqOfRust/examples/default/examples/conversion/try_from_and_try_into.v index 39c21f4ec..fea7cff16 100644 --- a/CoqOfRust/examples/default/examples/conversion/try_from_and_try_into.v +++ b/CoqOfRust/examples/default/examples/conversion/try_from_and_try_into.v @@ -164,54 +164,82 @@ Definition main : M unit := M.alloc (core.result.Result.Ok (try_from_and_try_into.EvenNumber.Build_t (Integer.of_Z 8))) in - match (borrow α1, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : - ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := - M.read left_val in - let* α1 : - ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := - M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := - core.result.Result.t try_from_and_try_into.EvenNumber.t unit) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : - ref - (core.result.Result.t - try_from_and_try_into.EvenNumber.t - unit) := - M.read left_val in - let* α2 : - ref - (core.result.Result.t - try_from_and_try_into.EvenNumber.t - unit) := - M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : + M.Val + ((ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit)) + * + (ref + (core.result.Result.t try_from_and_try_into.EvenNumber.t unit))) := + M.alloc (borrow α1, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read left_val in + let* α1 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := + core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read left_val in + let* α2 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : core.result.Result.t try_from_and_try_into.EvenNumber.t unit := M.call @@ -225,54 +253,82 @@ Definition main : M unit := let* α2 : M.Val (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := M.alloc (core.result.Result.Err tt) in - match (borrow α1, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : - ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := - M.read left_val in - let* α1 : - ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := - M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := - core.result.Result.t try_from_and_try_into.EvenNumber.t unit) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : - ref - (core.result.Result.t - try_from_and_try_into.EvenNumber.t - unit) := - M.read left_val in - let* α2 : - ref - (core.result.Result.t - try_from_and_try_into.EvenNumber.t - unit) := - M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : + M.Val + ((ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit)) + * + (ref + (core.result.Result.t try_from_and_try_into.EvenNumber.t unit))) := + M.alloc (borrow α1, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read left_val in + let* α1 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := + core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read left_val in + let* α2 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* result : M.Val (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := let* α0 : core.result.Result.t try_from_and_try_into.EvenNumber.t unit := @@ -288,54 +344,82 @@ Definition main : M unit := M.alloc (core.result.Result.Ok (try_from_and_try_into.EvenNumber.Build_t (Integer.of_Z 8))) in - match (borrow result, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : - ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := - M.read left_val in - let* α1 : - ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := - M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := - core.result.Result.t try_from_and_try_into.EvenNumber.t unit) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : - ref - (core.result.Result.t - try_from_and_try_into.EvenNumber.t - unit) := - M.read left_val in - let* α2 : - ref - (core.result.Result.t - try_from_and_try_into.EvenNumber.t - unit) := - M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : + M.Val + ((ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit)) + * + (ref + (core.result.Result.t try_from_and_try_into.EvenNumber.t unit))) := + M.alloc (borrow result, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read left_val in + let* α1 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := + core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read left_val in + let* α2 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* result : M.Val (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := let* α0 : core.result.Result.t try_from_and_try_into.EvenNumber.t unit := @@ -349,53 +433,81 @@ Definition main : M unit := let* α0 : M.Val (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := M.alloc (core.result.Result.Err tt) in - match (borrow result, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : - ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := - M.read left_val in - let* α1 : - ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit) := - M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := - core.result.Result.t try_from_and_try_into.EvenNumber.t unit) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : - ref - (core.result.Result.t - try_from_and_try_into.EvenNumber.t - unit) := - M.read left_val in - let* α2 : - ref - (core.result.Result.t - try_from_and_try_into.EvenNumber.t - unit) := - M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : + M.Val + ((ref (core.result.Result.t try_from_and_try_into.EvenNumber.t unit)) + * + (ref + (core.result.Result.t try_from_and_try_into.EvenNumber.t unit))) := + M.alloc (borrow result, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read left_val in + let* α1 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := + core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read left_val in + let* α2 : + ref + (core.result.Result.t + try_from_and_try_into.EvenNumber.t + unit) := + M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/custom_types/enums.v b/CoqOfRust/examples/default/examples/custom_types/enums.v index cc197e0e2..88e40419f 100644 --- a/CoqOfRust/examples/default/examples/custom_types/enums.v +++ b/CoqOfRust/examples/default/examples/custom_types/enums.v @@ -71,118 +71,160 @@ fn inspect(event: WebEvent) { *) Definition inspect (event : enums.WebEvent.t) : M unit := let* event := M.alloc event in - let* α0 : enums.WebEvent.t := M.read event in - let* α1 : M.Val unit := - match α0 with - | enums.WebEvent.PageLoad => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read - (mk_str - ("page loaded, r" ++ - String.String "233" ("f" ++ String.String "233" " + let* α0 : M.Val unit := + match_operator + event + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums.WebEvent.PageLoad => + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read + (mk_str + ("page loaded, r" ++ + String.String "233" ("f" ++ String.String "233" " "))) in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | enums.WebEvent.PageUnload => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "page unloaded + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums.WebEvent.PageUnload => + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "page unloaded ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | enums.WebEvent.KeyPress c => - let* c := M.alloc c in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "pressed '") in - let* α1 : ref str.t := M.read (mk_str "'. + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums.WebEvent.KeyPress _ => + let γ0 := γ.["KeyPress.0"] in + let* c := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "pressed '") in + let* α1 : ref str.t := M.read (mk_str "'. ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow c)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | enums.WebEvent.Paste s => - let* s := M.alloc s in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "pasted "") in - let* α1 : ref str.t := M.read (mk_str "". + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow c)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums.WebEvent.Paste _ => + let γ0 := γ.["Paste.0"] in + let* s := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "pasted "") in + let* α1 : ref str.t := M.read (mk_str "". ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | - enums.WebEvent.Click - {| enums.WebEvent.Click.x := x; enums.WebEvent.Click.y := y; - |} - => - let* x := M.alloc x in - let* y := M.alloc y in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "clicked at x=") in - let* α1 : ref str.t := M.read (mk_str ", y=") in - let* α2 : ref str.t := M.read (mk_str ". + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | + enums.WebEvent.Click + {| enums.WebEvent.Click.x := _; enums.WebEvent.Click.y := _; + |} + => + let γ0 := γ.["Click.x"] in + let γ1 := γ.["Click.y"] in + let* x := M.copy γ0 in + let* y := M.copy γ1 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "clicked at x=") in + let* α1 : ref str.t := M.read (mk_str ", y=") in + let* α2 : ref str.t := M.read (mk_str ". ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow x)) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow y)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - M.alloc tt - end in - M.read α1. + let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow x)) in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow y)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/custom_types/enums_testcase_linked_list.v b/CoqOfRust/examples/default/examples/custom_types/enums_testcase_linked_list.v index dc16cda38..b2314a947 100644 --- a/CoqOfRust/examples/default/examples/custom_types/enums_testcase_linked_list.v +++ b/CoqOfRust/examples/default/examples/custom_types/enums_testcase_linked_list.v @@ -98,30 +98,46 @@ Section Impl_enums_testcase_linked_list_List_t. Definition len (self : ref Self) : M u32.t := let* self := M.alloc self in let* α0 : ref enums_testcase_linked_list.List.t := M.read self in - let* α1 : enums_testcase_linked_list.List.t := M.read (deref α0) in - let* α2 : M.Val u32.t := - match α1 with - | enums_testcase_linked_list.List.Cons _ tail => - let* tail := M.alloc tail in - let* α0 : - ref - (alloc.boxed.Box.t - enums_testcase_linked_list.List.t - alloc.alloc.Global.t) := - M.read tail in - let* α1 : - alloc.boxed.Box.t - enums_testcase_linked_list.List.t - alloc.alloc.Global.t := - M.read (deref α0) in - let* α2 : u32.t := - M.call - (enums_testcase_linked_list.List.t::["len"] (borrow (deref α1))) in - let* α3 : u32.t := BinOp.Panic.add (Integer.of_Z 1) α2 in - M.alloc α3 - | enums_testcase_linked_list.List.Nil => M.alloc (Integer.of_Z 0) - end in - M.read α2. + let* α1 : M.Val u32.t := + match_operator + (deref α0) + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums_testcase_linked_list.List.Cons _ _ => + let γ0 := γ.["Cons.0"] in + let γ1 := γ.["Cons.1"] in + let* tail := M.alloc (borrow_mut γ1) in + let* α0 : + ref + (alloc.boxed.Box.t + enums_testcase_linked_list.List.t + alloc.alloc.Global.t) := + M.read tail in + let* α1 : + alloc.boxed.Box.t + enums_testcase_linked_list.List.t + alloc.alloc.Global.t := + M.read (deref α0) in + let* α2 : u32.t := + M.call + (enums_testcase_linked_list.List.t::["len"] + (borrow (deref α1))) in + let* α3 : u32.t := BinOp.Panic.add (Integer.of_Z 1) α2 in + M.alloc α3 + | _ => M.break_match + end) : + M (M.Val u32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums_testcase_linked_list.List.Nil => M.alloc (Integer.of_Z 0) + | _ => M.break_match + end) : + M (M.Val u32.t) + ] in + M.read α1. Global Instance AssociatedFunction_len : Notations.DoubleColon Self "len" := { Notations.double_colon := len; @@ -144,64 +160,85 @@ Section Impl_enums_testcase_linked_list_List_t. Definition stringify (self : ref Self) : M alloc.string.String.t := let* self := M.alloc self in let* α0 : ref enums_testcase_linked_list.List.t := M.read self in - let* α1 : enums_testcase_linked_list.List.t := M.read (deref α0) in - let* α2 : M.Val alloc.string.String.t := - match α1 with - | enums_testcase_linked_list.List.Cons head tail => - let* head := M.alloc head in - let* tail := M.alloc tail in - let* res : M.Val alloc.string.String.t := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str ", ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow head)) in - let* α6 : - ref - (alloc.boxed.Box.t - enums_testcase_linked_list.List.t - alloc.alloc.Global.t) := - M.read tail in - let* α7 : - alloc.boxed.Box.t - enums_testcase_linked_list.List.t - alloc.alloc.Global.t := - M.read (deref α6) in - let* α8 : alloc.string.String.t := - M.call - (enums_testcase_linked_list.List.t::["stringify"] - (borrow (deref α7))) in - let* α9 : M.Val alloc.string.String.t := M.alloc α8 in - let* α10 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow α9)) in - let* α11 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5; α10 ] in - let* α12 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α11) in - let* α13 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α12) in - let* α14 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α13) in - let* α15 : alloc.string.String.t := M.call (alloc.fmt.format α14) in - M.alloc α15 in - M.pure res - | enums_testcase_linked_list.List.Nil => - let* res : M.Val alloc.string.String.t := - let* α0 : ref str.t := M.read (mk_str "Nil") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : alloc.string.String.t := M.call (alloc.fmt.format α4) in - M.alloc α5 in - M.pure res - end in - M.read α2. + let* α1 : M.Val alloc.string.String.t := + match_operator + (deref α0) + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums_testcase_linked_list.List.Cons _ _ => + let γ0 := γ.["Cons.0"] in + let γ1 := γ.["Cons.1"] in + let* head := M.copy γ0 in + let* tail := M.alloc (borrow_mut γ1) in + let* res : M.Val alloc.string.String.t := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str ", ") in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow head)) in + let* α6 : + ref + (alloc.boxed.Box.t + enums_testcase_linked_list.List.t + alloc.alloc.Global.t) := + M.read tail in + let* α7 : + alloc.boxed.Box.t + enums_testcase_linked_list.List.t + alloc.alloc.Global.t := + M.read (deref α6) in + let* α8 : alloc.string.String.t := + M.call + (enums_testcase_linked_list.List.t::["stringify"] + (borrow (deref α7))) in + let* α9 : M.Val alloc.string.String.t := M.alloc α8 in + let* α10 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow α9)) in + let* α11 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5; α10 ] in + let* α12 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α11) in + let* α13 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α12) in + let* α14 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α13) in + let* α15 : alloc.string.String.t := + M.call (alloc.fmt.format α14) in + M.alloc α15 in + M.pure res + | _ => M.break_match + end) : + M (M.Val alloc.string.String.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums_testcase_linked_list.List.Nil => + let* res : M.Val alloc.string.String.t := + let* α0 : ref str.t := M.read (mk_str "Nil") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : alloc.string.String.t := + M.call (alloc.fmt.format α4) in + M.alloc α5 in + M.pure res + | _ => M.break_match + end) : + M (M.Val alloc.string.String.t) + ] in + M.read α1. Global Instance AssociatedFunction_stringify : Notations.DoubleColon Self "stringify" := { diff --git a/CoqOfRust/examples/default/examples/custom_types/enums_type_aliases_v2.v b/CoqOfRust/examples/default/examples/custom_types/enums_type_aliases_v2.v index 59be046fc..64bc7c8fb 100644 --- a/CoqOfRust/examples/default/examples/custom_types/enums_type_aliases_v2.v +++ b/CoqOfRust/examples/default/examples/custom_types/enums_type_aliases_v2.v @@ -24,24 +24,44 @@ Section Impl_enums_type_aliases_v2_VeryVerboseEnumOfThingsToDoWithNumbers_t. let* self := M.alloc self in let* x := M.alloc x in let* y := M.alloc y in - let* α0 : - ref enums_type_aliases_v2.VeryVerboseEnumOfThingsToDoWithNumbers.t := - M.read self in - let* α1 := M.read α0 in - let* α2 : M.Val i32.t := - match α1 with - | enums_type_aliases_v2.VeryVerboseEnumOfThingsToDoWithNumbers.Add => - let* α0 : i32.t := M.read x in - let* α1 : i32.t := M.read y in - let* α2 : i32.t := BinOp.Panic.add α0 α1 in - M.alloc α2 - | enums_type_aliases_v2.VeryVerboseEnumOfThingsToDoWithNumbers.Subtract => - let* α0 : i32.t := M.read x in - let* α1 : i32.t := M.read y in - let* α2 : i32.t := BinOp.Panic.sub α0 α1 in - M.alloc α2 - end in - M.read α2. + let* α0 : M.Val i32.t := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + enums_type_aliases_v2.VeryVerboseEnumOfThingsToDoWithNumbers.Add + => + let* α0 : i32.t := M.read x in + let* α1 : i32.t := M.read y in + let* α2 : i32.t := BinOp.Panic.add α0 α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val i32.t); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + enums_type_aliases_v2.VeryVerboseEnumOfThingsToDoWithNumbers.Subtract + => + let* α0 : i32.t := M.read x in + let* α1 : i32.t := M.read y in + let* α2 : i32.t := BinOp.Panic.sub α0 α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val i32.t) + ] in + M.read α0. Global Instance AssociatedFunction_run : Notations.DoubleColon Self "run" := { Notations.double_colon := run; diff --git a/CoqOfRust/examples/default/examples/custom_types/enums_use.v b/CoqOfRust/examples/default/examples/custom_types/enums_use.v index ad5b32491..455486fde 100644 --- a/CoqOfRust/examples/default/examples/custom_types/enums_use.v +++ b/CoqOfRust/examples/default/examples/custom_types/enums_use.v @@ -38,64 +38,95 @@ Definition main : M unit := let* status : M.Val enums_use.Status.t := M.alloc enums_use.Status.Poor in let* work : M.Val enums_use.Work.t := M.alloc enums_use.Work.Civilian in let* _ : M.Val unit := - let* α0 : enums_use.Status.t := M.read status in - match α0 with - | enums_use.Status.Rich => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "The rich have lots of money! + match_operator + status + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums_use.Status.Rich => + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "The rich have lots of money! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | enums_use.Status.Poor => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "The poor have no money... + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums_use.Status.Poor => + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "The poor have no money... ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in - let* α0 : enums_use.Work.t := M.read work in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := - match α0 with - | enums_use.Work.Civilian => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Civilians work! + match_operator + work + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums_use.Work.Civilian => + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Civilians work! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | enums_use.Work.Soldier => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Soldiers fight! + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | enums_use.Work.Soldier => + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Soldiers fight! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/custom_types/structures.v b/CoqOfRust/examples/default/examples/custom_types/structures.v index 4af9a27b8..d25d8b304 100644 --- a/CoqOfRust/examples/default/examples/custom_types/structures.v +++ b/CoqOfRust/examples/default/examples/custom_types/structures.v @@ -290,76 +290,111 @@ Definition main : M unit := let* α12 : unit := M.call (std.io.stdio._print α11) in M.alloc α12 in M.alloc tt in - let* '{| structures.Point.x := left_edge; structures.Point.y := top_edge; |} : - structures.Point.t := - M.read point in - let* left_edge := M.alloc left_edge in - let* top_edge := M.alloc top_edge in - let* _rectangle : M.Val structures.Rectangle.t := - let* α0 : f32.t := M.read left_edge in - let* α1 : f32.t := M.read top_edge in - let* α2 : structures.Point.t := M.read bottom_right in - M.alloc - {| - structures.Rectangle.top_left := - {| structures.Point.x := α0; structures.Point.y := α1; |}; - structures.Rectangle.bottom_right := α2; - |} in - let* _unit : M.Val structures.Unit.t := M.alloc structures.Unit.Build in - let* pair : M.Val structures.Pair.t := - let* α0 : f32.t := M.read UnsupportedLiteral in - M.alloc (structures.Pair.Build_t (Integer.of_Z 1) α0) in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "pair contains ") in - let* α1 : ref str.t := M.read (mk_str " and ") in - let* α2 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + point + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | {| structures.Point.x := _; structures.Point.y := _; |} => + let γ0 := γ.["Point.x"] in + let γ1 := γ.["Point.y"] in + let* left_edge := M.copy γ0 in + let* top_edge := M.copy γ1 in + let* _rectangle : M.Val structures.Rectangle.t := + let* α0 : f32.t := M.read left_edge in + let* α1 : f32.t := M.read top_edge in + let* α2 : structures.Point.t := M.read bottom_right in + M.alloc + {| + structures.Rectangle.top_left := + {| structures.Point.x := α0; structures.Point.y := α1; |}; + structures.Rectangle.bottom_right := α2; + |} in + let* _unit : M.Val structures.Unit.t := + M.alloc structures.Unit.Build in + let* pair : M.Val structures.Pair.t := + let* α0 : f32.t := M.read UnsupportedLiteral in + M.alloc (structures.Pair.Build_t (Integer.of_Z 1) α0) in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "pair contains ") in + let* α1 : ref str.t := M.read (mk_str " and ") in + let* α2 : ref str.t := M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow pair.["0"])) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow pair.["1"])) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - let* 'structures.Pair.Build_t integer decimal : structures.Pair.t := - M.read pair in - let* integer := M.alloc integer in - let* decimal := M.alloc decimal in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "pair contains ") in - let* α1 : ref str.t := M.read (mk_str " and ") in - let* α2 : ref str.t := M.read (mk_str " + let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] + (borrow pair.["0"])) in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] + (borrow pair.["1"])) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + match_operator + pair + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | structures.Pair.Build_t _ _ => + let γ0 := γ.["Pair.0"] in + let γ1 := γ.["Pair.1"] in + let* integer := M.copy γ0 in + let* decimal := M.copy γ1 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "pair contains ") in + let* α1 : ref str.t := M.read (mk_str " and ") in + let* α2 : ref str.t := M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow integer)) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow decimal)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in + let* α3 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] + (borrow integer)) in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] + (borrow decimal)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + M.alloc tt + end) : + M (M.Val unit) + ] + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/error_handling/aliases_for_result.v b/CoqOfRust/examples/default/examples/error_handling/aliases_for_result.v index 5a41c3c06..50ec0d835 100644 --- a/CoqOfRust/examples/default/examples/error_handling/aliases_for_result.v +++ b/CoqOfRust/examples/default/examples/error_handling/aliases_for_result.v @@ -25,20 +25,37 @@ Definition multiply M.call ((core.result.Result.t i32.t core.num.error.ParseIntError.t)::["and_then"] α1 - (fun (first_number : i32.t) => - (let* first_number := M.alloc first_number in - let* α0 : ref str.t := M.read second_number_str in - let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call (str.t::["parse"] α0) in - M.call - ((core.result.Result.t i32.t core.num.error.ParseIntError.t)::["map"] - α1 - (fun (second_number : i32.t) => - (let* second_number := M.alloc second_number in - let* α0 : i32.t := M.read first_number in - let* α1 : i32.t := M.read second_number in - BinOp.Panic.mul α0 α1) : - M i32.t))) : + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* first_number := M.copy γ in + let* α0 : ref str.t := M.read second_number_str in + let* α1 : + core.result.Result.t i32.t core.num.error.ParseIntError.t := + M.call (str.t::["parse"] α0) in + M.call + ((core.result.Result.t + i32.t + core.num.error.ParseIntError.t)::["map"] + α1 + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* second_number := M.copy γ in + let* α0 : i32.t := M.read first_number in + let* α1 : i32.t := M.read second_number in + BinOp.Panic.mul α0 α1) : + M i32.t + ]) : + M i32.t))) : + M (core.result.Result.t i32.t core.num.error.ParseIntError.t) + ]) : M (core.result.Result.t i32.t core.num.error.ParseIntError.t))). (* @@ -53,56 +70,74 @@ Definition print (result : ltac:(aliases_for_result.AliasedResult i32.t)) : M unit := let* result := M.alloc result in - let* α0 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.read result in - let* α1 : M.Val unit := - match α0 with - | core.result.Result.Ok n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "n is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "n is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.result.Result.Err e => - let* e := M.alloc e in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Error: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Error: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α1. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/error_handling/boxing_errors.v b/CoqOfRust/examples/default/examples/error_handling/boxing_errors.v index e0f5916a1..5d4665348 100644 --- a/CoqOfRust/examples/default/examples/error_handling/boxing_errors.v +++ b/CoqOfRust/examples/default/examples/error_handling/boxing_errors.v @@ -153,40 +153,66 @@ Definition double_first (ref (ref str.t)) (alloc.boxed.Box.t dynamic alloc.alloc.Global.t))::["and_then"] α2 - (fun (s : ref (ref str.t)) => - (let* s := M.alloc s in - let* α0 : ref (ref str.t) := M.read s in - let* α1 : ref str.t := M.read (deref α0) in - let* α2 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call (str.t::["parse"] α1) in - let* α3 : - core.result.Result.t - i32.t - (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := - M.call - ((core.result.Result.t - i32.t - core.num.error.ParseIntError.t)::["map_err"] - α2 - (fun (e : core.num.error.ParseIntError.t) => - (let* e := M.alloc e in - let* α0 : core.num.error.ParseIntError.t := M.read e in + (fun (α0 : ref (ref str.t)) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* s := M.copy γ in + let* α0 : ref (ref str.t) := M.read s in + let* α1 : ref str.t := M.read (deref α0) in + let* α2 : + core.result.Result.t i32.t core.num.error.ParseIntError.t := + M.call (str.t::["parse"] α1) in + let* α3 : + core.result.Result.t + i32.t + (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := M.call - ((core.convert.Into.into - (Self := core.num.error.ParseIntError.t) - (Trait := ltac:(refine _))) - α0)) : - M (alloc.boxed.Box.t dynamic alloc.alloc.Global.t))) in - M.call - ((core.result.Result.t - i32.t - (alloc.boxed.Box.t dynamic alloc.alloc.Global.t))::["map"] - α3 - (fun (i : i32.t) => - (let* i := M.alloc i in - let* α0 : i32.t := M.read i in - BinOp.Panic.mul (Integer.of_Z 2) α0) : - M i32.t))) : + ((core.result.Result.t + i32.t + core.num.error.ParseIntError.t)::["map_err"] + α2 + (fun (α0 : core.num.error.ParseIntError.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* e := M.copy γ in + let* α0 : core.num.error.ParseIntError.t := + M.read e in + M.call + ((core.convert.Into.into + (Self := core.num.error.ParseIntError.t) + (Trait := ltac:(refine _))) + α0)) : + M (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) + ]) : + M (alloc.boxed.Box.t dynamic alloc.alloc.Global.t))) in + M.call + ((core.result.Result.t + i32.t + (alloc.boxed.Box.t dynamic alloc.alloc.Global.t))::["map"] + α3 + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* i := M.copy γ in + let* α0 : i32.t := M.read i in + BinOp.Panic.mul (Integer.of_Z 2) α0) : + M i32.t + ]) : + M i32.t))) : + M + (core.result.Result.t + i32.t + (alloc.boxed.Box.t dynamic alloc.alloc.Global.t)) + ]) : M (core.result.Result.t i32.t @@ -202,59 +228,74 @@ fn print(result: Result) { *) Definition print (result : ltac:(boxing_errors.Result i32.t)) : M unit := let* result := M.alloc result in - let* α0 : - core.result.Result.t - i32.t - (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := - M.read result in - let* α1 : M.Val unit := - match α0 with - | core.result.Result.Ok n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "The first doubled is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "The first doubled is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.result.Result.Err e => - let* e := M.alloc e in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Error: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Error: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α1. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/error_handling/combinators_and_then.v b/CoqOfRust/examples/default/examples/error_handling/combinators_and_then.v index 4571e1be1..7021f6d00 100644 --- a/CoqOfRust/examples/default/examples/error_handling/combinators_and_then.v +++ b/CoqOfRust/examples/default/examples/error_handling/combinators_and_then.v @@ -22,22 +22,49 @@ Section Impl_core_fmt_Debug_for_combinators_and_then_Food_t. let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref combinators_and_then.Food.t := M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | combinators_and_then.Food.CordonBleu => - let* α0 : ref str.t := M.read (mk_str "CordonBleu") in - M.alloc α0 - | combinators_and_then.Food.Steak => - let* α0 : ref str.t := M.read (mk_str "Steak") in - M.alloc α0 - | combinators_and_then.Food.Sushi => - let* α0 : ref str.t := M.read (mk_str "Sushi") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | combinators_and_then.Food.CordonBleu => + let* α0 : ref str.t := M.read (mk_str "CordonBleu") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | combinators_and_then.Food.Steak => + let* α0 : ref str.t := M.read (mk_str "Steak") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | combinators_and_then.Food.Sushi => + let* α0 : ref str.t := M.read (mk_str "Sushi") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; @@ -70,22 +97,49 @@ Section Impl_core_fmt_Debug_for_combinators_and_then_Day_t. let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref combinators_and_then.Day.t := M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | combinators_and_then.Day.Monday => - let* α0 : ref str.t := M.read (mk_str "Monday") in - M.alloc α0 - | combinators_and_then.Day.Tuesday => - let* α0 : ref str.t := M.read (mk_str "Tuesday") in - M.alloc α0 - | combinators_and_then.Day.Wednesday => - let* α0 : ref str.t := M.read (mk_str "Wednesday") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | combinators_and_then.Day.Monday => + let* α0 : ref str.t := M.read (mk_str "Monday") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | combinators_and_then.Day.Tuesday => + let* α0 : ref str.t := M.read (mk_str "Tuesday") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | combinators_and_then.Day.Wednesday => + let* α0 : ref str.t := M.read (mk_str "Wednesday") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; @@ -109,15 +163,23 @@ Definition have_ingredients (food : combinators_and_then.Food.t) : M (core.option.Option.t combinators_and_then.Food.t) := let* food := M.alloc food in - let* α0 : combinators_and_then.Food.t := M.read food in - let* α1 : M.Val (core.option.Option.t combinators_and_then.Food.t) := - match α0 with - | combinators_and_then.Food.Sushi => M.alloc core.option.Option.None - | _ => - let* α0 : combinators_and_then.Food.t := M.read food in - M.alloc (core.option.Option.Some α0) - end in - M.read α1. + let* α0 : M.Val (core.option.Option.t combinators_and_then.Food.t) := + match_operator + food + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | combinators_and_then.Food.Sushi => M.alloc core.option.Option.None + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t combinators_and_then.Food.t)); + fun γ => + (let* α0 : combinators_and_then.Food.t := M.read food in + M.alloc (core.option.Option.Some α0)) : + M (M.Val (core.option.Option.t combinators_and_then.Food.t)) + ] in + M.read α0. (* fn have_recipe(food: Food) -> Option { @@ -131,15 +193,24 @@ Definition have_recipe (food : combinators_and_then.Food.t) : M (core.option.Option.t combinators_and_then.Food.t) := let* food := M.alloc food in - let* α0 : combinators_and_then.Food.t := M.read food in - let* α1 : M.Val (core.option.Option.t combinators_and_then.Food.t) := - match α0 with - | combinators_and_then.Food.CordonBleu => M.alloc core.option.Option.None - | _ => - let* α0 : combinators_and_then.Food.t := M.read food in - M.alloc (core.option.Option.Some α0) - end in - M.read α1. + let* α0 : M.Val (core.option.Option.t combinators_and_then.Food.t) := + match_operator + food + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | combinators_and_then.Food.CordonBleu => + M.alloc core.option.Option.None + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t combinators_and_then.Food.t)); + fun γ => + (let* α0 : combinators_and_then.Food.t := M.read food in + M.alloc (core.option.Option.Some α0)) : + M (M.Val (core.option.Option.t combinators_and_then.Food.t)) + ] in + M.read α0. (* fn cookable_v1(food: Food) -> Option { @@ -160,22 +231,57 @@ Definition cookable_v1 let* α1 : core.option.Option.t combinators_and_then.Food.t := M.call (combinators_and_then.have_recipe α0) in let* α2 : M.Val (core.option.Option.t combinators_and_then.Food.t) := - match α1 with - | core.option.Option.None => M.alloc core.option.Option.None - | core.option.Option.Some food => - let* food := M.alloc food in - let* α0 : combinators_and_then.Food.t := M.read food in - let* α1 : core.option.Option.t combinators_and_then.Food.t := - M.call (combinators_and_then.have_ingredients α0) in - match α1 with - | core.option.Option.None => M.alloc core.option.Option.None - | core.option.Option.Some food => - let* food := M.alloc food in - let* α0 : combinators_and_then.Food.t := M.read food in - M.alloc (core.option.Option.Some α0) - end - end in - M.read α2. + M.alloc α1 in + let* α3 : M.Val (core.option.Option.t combinators_and_then.Food.t) := + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => M.alloc core.option.Option.None + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t combinators_and_then.Food.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* food := M.copy γ0 in + let* α0 : combinators_and_then.Food.t := M.read food in + let* α1 : core.option.Option.t combinators_and_then.Food.t := + M.call (combinators_and_then.have_ingredients α0) in + let* α2 : + M.Val (core.option.Option.t combinators_and_then.Food.t) := + M.alloc α1 in + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => M.alloc core.option.Option.None + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t combinators_and_then.Food.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* food := M.copy γ0 in + let* α0 : combinators_and_then.Food.t := M.read food in + M.alloc (core.option.Option.Some α0) + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t combinators_and_then.Food.t)) + ] + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t combinators_and_then.Food.t)) + ] in + M.read α3. (* fn cookable_v2(food: Food) -> Option { @@ -211,57 +317,78 @@ Definition eat let* α0 : combinators_and_then.Food.t := M.read food in let* α1 : core.option.Option.t combinators_and_then.Food.t := M.call (combinators_and_then.cookable_v2 α0) in - let* α2 : M.Val unit := - match α1 with - | core.option.Option.Some food => - let* food := M.alloc food in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Yay! On ") in - let* α1 : ref str.t := M.read (mk_str " we get to eat ") in - let* α2 : ref str.t := M.read (mk_str ". + let* α2 : M.Val (core.option.Option.t combinators_and_then.Food.t) := + M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* food := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Yay! On ") in + let* α1 : ref str.t := M.read (mk_str " we get to eat ") in + let* α2 : ref str.t := M.read (mk_str ". ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow day)) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow food)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt - | core.option.Option.None => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "Oh no. We don't get to eat on ") in - let* α1 : ref str.t := M.read (mk_str "? + let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow day)) in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow food)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Oh no. We don't get to eat on ") in + let* α1 : ref str.t := M.read (mk_str "? ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow day)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α2. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow day)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α3. (* fn main() { @@ -274,30 +401,55 @@ fn main() { *) (* #[allow(dead_code)] - function was ignored by the compiler *) Definition main : M unit := - let '(cordon_bleu, steak, sushi) : - (combinators_and_then.Food.t * combinators_and_then.Food.t) - * - combinators_and_then.Food.t := - (combinators_and_then.Food.CordonBleu, - combinators_and_then.Food.Steak, - combinators_and_then.Food.Sushi) in - let* cordon_bleu := M.alloc cordon_bleu in - let* steak := M.alloc steak in - let* sushi := M.alloc sushi in - let* _ : M.Val unit := - let* α0 : combinators_and_then.Food.t := M.read cordon_bleu in - let* α1 : unit := - M.call (combinators_and_then.eat α0 combinators_and_then.Day.Monday) in - M.alloc α1 in - let* _ : M.Val unit := - let* α0 : combinators_and_then.Food.t := M.read steak in - let* α1 : unit := - M.call (combinators_and_then.eat α0 combinators_and_then.Day.Tuesday) in - M.alloc α1 in - let* _ : M.Val unit := - let* α0 : combinators_and_then.Food.t := M.read sushi in - let* α1 : unit := - M.call (combinators_and_then.eat α0 combinators_and_then.Day.Wednesday) in - M.alloc α1 in - let* α0 : M.Val unit := M.alloc tt in - M.read α0. + let* α0 : + M.Val + ((combinators_and_then.Food.t * combinators_and_then.Food.t) + * + combinators_and_then.Food.t) := + M.alloc + (combinators_and_then.Food.CordonBleu, + combinators_and_then.Food.Steak, + combinators_and_then.Food.Sushi) in + let* α1 : M.Val unit := + match_operator + α0 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _, _) => + let γ0 := Tuple.Access.left (Tuple.Access.left γ) in + let γ1 := Tuple.Access.right (Tuple.Access.left γ) in + let γ2 := Tuple.Access.right γ in + let* cordon_bleu := M.copy γ0 in + let* steak := M.copy γ1 in + let* sushi := M.copy γ2 in + let* _ : M.Val unit := + let* α0 : combinators_and_then.Food.t := M.read cordon_bleu in + let* α1 : unit := + M.call + (combinators_and_then.eat + α0 + combinators_and_then.Day.Monday) in + M.alloc α1 in + let* _ : M.Val unit := + let* α0 : combinators_and_then.Food.t := M.read steak in + let* α1 : unit := + M.call + (combinators_and_then.eat + α0 + combinators_and_then.Day.Tuesday) in + M.alloc α1 in + let* _ : M.Val unit := + let* α0 : combinators_and_then.Food.t := M.read sushi in + let* α1 : unit := + M.call + (combinators_and_then.eat + α0 + combinators_and_then.Day.Wednesday) in + M.alloc α1 in + M.alloc tt + end) : + M (M.Val unit) + ] in + M.read α1. diff --git a/CoqOfRust/examples/default/examples/error_handling/combinators_map.v b/CoqOfRust/examples/default/examples/error_handling/combinators_map.v index 474e66cb2..0af53b128 100644 --- a/CoqOfRust/examples/default/examples/error_handling/combinators_map.v +++ b/CoqOfRust/examples/default/examples/error_handling/combinators_map.v @@ -22,22 +22,49 @@ Section Impl_core_fmt_Debug_for_combinators_map_Food_t. let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref combinators_map.Food.t := M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | combinators_map.Food.Apple => - let* α0 : ref str.t := M.read (mk_str "Apple") in - M.alloc α0 - | combinators_map.Food.Carrot => - let* α0 : ref str.t := M.read (mk_str "Carrot") in - M.alloc α0 - | combinators_map.Food.Potato => - let* α0 : ref str.t := M.read (mk_str "Potato") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | combinators_map.Food.Apple => + let* α0 : ref str.t := M.read (mk_str "Apple") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | combinators_map.Food.Carrot => + let* α0 : ref str.t := M.read (mk_str "Carrot") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | combinators_map.Food.Potato => + let* α0 : ref str.t := M.read (mk_str "Potato") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; @@ -196,16 +223,31 @@ Definition peel (food : core.option.Option.t combinators_map.Food.t) : M (core.option.Option.t combinators_map.Peeled.t) := let* food := M.alloc food in - let* α0 : core.option.Option.t combinators_map.Food.t := M.read food in - let* α1 : M.Val (core.option.Option.t combinators_map.Peeled.t) := - match α0 with - | core.option.Option.Some food => - let* food := M.alloc food in - let* α0 : combinators_map.Food.t := M.read food in - M.alloc (core.option.Option.Some (combinators_map.Peeled.Build_t α0)) - | core.option.Option.None => M.alloc core.option.Option.None - end in - M.read α1. + let* α0 : M.Val (core.option.Option.t combinators_map.Peeled.t) := + match_operator + food + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* food := M.copy γ0 in + let* α0 : combinators_map.Food.t := M.read food in + M.alloc + (core.option.Option.Some (combinators_map.Peeled.Build_t α0)) + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t combinators_map.Peeled.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => M.alloc core.option.Option.None + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t combinators_map.Peeled.t)) + ] in + M.read α0. (* fn chop(peeled: Option) -> Option { @@ -219,16 +261,36 @@ Definition chop (peeled : core.option.Option.t combinators_map.Peeled.t) : M (core.option.Option.t combinators_map.Chopped.t) := let* peeled := M.alloc peeled in - let* α0 : core.option.Option.t combinators_map.Peeled.t := M.read peeled in - let* α1 : M.Val (core.option.Option.t combinators_map.Chopped.t) := - match α0 with - | core.option.Option.Some (combinators_map.Peeled.Build_t food) => - let* food := M.alloc food in - let* α0 : combinators_map.Food.t := M.read food in - M.alloc (core.option.Option.Some (combinators_map.Chopped.Build_t α0)) - | core.option.Option.None => M.alloc core.option.Option.None - end in - M.read α1. + let* α0 : M.Val (core.option.Option.t combinators_map.Chopped.t) := + match_operator + peeled + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* α0 := M.read γ0 in + match α0 with + | combinators_map.Peeled.Build_t _ => + let γ0 := γ0.["Peeled.0"] in + let* food := M.copy γ0 in + let* α0 : combinators_map.Food.t := M.read food in + M.alloc + (core.option.Option.Some (combinators_map.Chopped.Build_t α0)) + end + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t combinators_map.Chopped.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => M.alloc core.option.Option.None + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t combinators_map.Chopped.t)) + ] in + M.read α0. (* fn cook(chopped: Option) -> Option { @@ -243,10 +305,22 @@ Definition cook M.call ((core.option.Option.t combinators_map.Chopped.t)::["map"] α0 - (fun (combinators_map.Chopped.Build_t food : combinators_map.Chopped.t) => - (let* food := M.alloc food in - let* α0 : combinators_map.Food.t := M.read food in - M.pure (combinators_map.Cooked.Build_t α0)) : + (fun (α0 : combinators_map.Chopped.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | combinators_map.Chopped.Build_t _ => + let γ0 := γ.["Chopped.0"] in + let* food := M.copy γ0 in + let* α0 : combinators_map.Food.t := M.read food in + M.pure (combinators_map.Cooked.Build_t α0) + end) : + M combinators_map.Cooked.t + ]) : M combinators_map.Cooked.t)). (* @@ -265,27 +339,58 @@ Definition process M.call ((core.option.Option.t combinators_map.Food.t)::["map"] α0 - (fun (f : combinators_map.Food.t) => - (let* f := M.alloc f in - let* α0 : combinators_map.Food.t := M.read f in - M.pure (combinators_map.Peeled.Build_t α0)) : + (fun (α0 : combinators_map.Food.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* f := M.copy γ in + let* α0 : combinators_map.Food.t := M.read f in + M.pure (combinators_map.Peeled.Build_t α0)) : + M combinators_map.Peeled.t + ]) : M combinators_map.Peeled.t)) in let* α2 : core.option.Option.t combinators_map.Chopped.t := M.call ((core.option.Option.t combinators_map.Peeled.t)::["map"] α1 - (fun (combinators_map.Peeled.Build_t f : combinators_map.Peeled.t) => - (let* f := M.alloc f in - let* α0 : combinators_map.Food.t := M.read f in - M.pure (combinators_map.Chopped.Build_t α0)) : + (fun (α0 : combinators_map.Peeled.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | combinators_map.Peeled.Build_t _ => + let γ0 := γ.["Peeled.0"] in + let* f := M.copy γ0 in + let* α0 : combinators_map.Food.t := M.read f in + M.pure (combinators_map.Chopped.Build_t α0) + end) : + M combinators_map.Chopped.t + ]) : M combinators_map.Chopped.t)) in M.call ((core.option.Option.t combinators_map.Chopped.t)::["map"] α2 - (fun (combinators_map.Chopped.Build_t f : combinators_map.Chopped.t) => - (let* f := M.alloc f in - let* α0 : combinators_map.Food.t := M.read f in - M.pure (combinators_map.Cooked.Build_t α0)) : + (fun (α0 : combinators_map.Chopped.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | combinators_map.Chopped.Build_t _ => + let γ0 := γ.["Chopped.0"] in + let* f := M.copy γ0 in + let* α0 : combinators_map.Food.t := M.read f in + M.pure (combinators_map.Cooked.Build_t α0) + end) : + M combinators_map.Cooked.t + ]) : M combinators_map.Cooked.t)). (* @@ -300,46 +405,64 @@ Definition eat (food : core.option.Option.t combinators_map.Cooked.t) : M unit := let* food := M.alloc food in - let* α0 : core.option.Option.t combinators_map.Cooked.t := M.read food in - let* α1 : M.Val unit := - match α0 with - | core.option.Option.Some food => - let* food := M.alloc food in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Mmm. I love ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + food + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* food := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Mmm. I love ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow food)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.option.Option.None => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Oh no! It wasn't edible. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow food)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Oh no! It wasn't edible. ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in - M.read α1. + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/error_handling/defining_an_error_type.v b/CoqOfRust/examples/default/examples/error_handling/defining_an_error_type.v index 1b22ba686..1f2cc4756 100644 --- a/CoqOfRust/examples/default/examples/error_handling/defining_an_error_type.v +++ b/CoqOfRust/examples/default/examples/error_handling/defining_an_error_type.v @@ -133,32 +133,59 @@ Definition double_first (ref (ref str.t)) defining_an_error_type.DoubleError.t)::["and_then"] α2 - (fun (s : ref (ref str.t)) => - (let* s := M.alloc s in - let* α0 : ref (ref str.t) := M.read s in - let* α1 : ref str.t := M.read (deref α0) in - let* α2 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call (str.t::["parse"] α1) in - let* α3 : - core.result.Result.t i32.t defining_an_error_type.DoubleError.t := - M.call - ((core.result.Result.t + (fun (α0 : ref (ref str.t)) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* s := M.copy γ in + let* α0 : ref (ref str.t) := M.read s in + let* α1 : ref str.t := M.read (deref α0) in + let* α2 : + core.result.Result.t i32.t core.num.error.ParseIntError.t := + M.call (str.t::["parse"] α1) in + let* α3 : + core.result.Result.t + i32.t + defining_an_error_type.DoubleError.t := + M.call + ((core.result.Result.t + i32.t + core.num.error.ParseIntError.t)::["map_err"] + α2 + (fun (α0 : core.num.error.ParseIntError.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (M.pure defining_an_error_type.DoubleError.Build) : + M defining_an_error_type.DoubleError.t + ]) : + M defining_an_error_type.DoubleError.t)) in + M.call + ((core.result.Result.t + i32.t + defining_an_error_type.DoubleError.t)::["map"] + α3 + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* i := M.copy γ in + let* α0 : i32.t := M.read i in + BinOp.Panic.mul (Integer.of_Z 2) α0) : + M i32.t + ]) : + M i32.t))) : + M + (core.result.Result.t i32.t - core.num.error.ParseIntError.t)::["map_err"] - α2 - (fun (_ : core.num.error.ParseIntError.t) => - (M.pure defining_an_error_type.DoubleError.Build) : - M defining_an_error_type.DoubleError.t)) in - M.call - ((core.result.Result.t - i32.t - defining_an_error_type.DoubleError.t)::["map"] - α3 - (fun (i : i32.t) => - (let* i := M.alloc i in - let* α0 : i32.t := M.read i in - BinOp.Panic.mul (Integer.of_Z 2) α0) : - M i32.t))) : + defining_an_error_type.DoubleError.t) + ]) : M (core.result.Result.t i32.t defining_an_error_type.DoubleError.t))). (* @@ -173,56 +200,74 @@ Definition print (result : ltac:(defining_an_error_type.Result i32.t)) : M unit := let* result := M.alloc result in - let* α0 : core.result.Result.t i32.t defining_an_error_type.DoubleError.t := - M.read result in - let* α1 : M.Val unit := - match α0 with - | core.result.Result.Ok n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "The first doubled is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "The first doubled is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.result.Result.Err e => - let* e := M.alloc e in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Error: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Error: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α1. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/error_handling/early_returns.v b/CoqOfRust/examples/default/examples/error_handling/early_returns.v index 08fc3842e..4d7a23452 100644 --- a/CoqOfRust/examples/default/examples/error_handling/early_returns.v +++ b/CoqOfRust/examples/default/examples/error_handling/early_returns.v @@ -30,38 +30,78 @@ Definition multiply let* α0 : ref str.t := M.read first_number_str in let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := M.call (str.t::["parse"] α0) in - let* α2 : M.Val i32.t := - match α1 with - | core.result.Result.Ok first_number => - let* first_number := M.alloc first_number in - M.pure first_number - | core.result.Result.Err e => - let* e := M.alloc e in - let* α0 : core.num.error.ParseIntError.t := M.read e in - let* α1 : M.Val never.t := return_ (core.result.Result.Err α0) in - let* α2 := M.read α1 in - let* α3 : i32.t := never_to_any α2 in - M.alloc α3 - end in - M.copy α2 in + let* α2 : + M.Val (core.result.Result.t i32.t core.num.error.ParseIntError.t) := + M.alloc α1 in + let* α3 : M.Val i32.t := + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* first_number := M.copy γ0 in + M.pure first_number + | _ => M.break_match + end) : + M (M.Val i32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* α0 : core.num.error.ParseIntError.t := M.read e in + let* α1 : M.Val never.t := + return_ (core.result.Result.Err α0) in + let* α2 := M.read α1 in + let* α3 : i32.t := never_to_any α2 in + M.alloc α3 + | _ => M.break_match + end) : + M (M.Val i32.t) + ] in + M.copy α3 in let* second_number : M.Val i32.t := let* α0 : ref str.t := M.read second_number_str in let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := M.call (str.t::["parse"] α0) in - let* α2 : M.Val i32.t := - match α1 with - | core.result.Result.Ok second_number => - let* second_number := M.alloc second_number in - M.pure second_number - | core.result.Result.Err e => - let* e := M.alloc e in - let* α0 : core.num.error.ParseIntError.t := M.read e in - let* α1 : M.Val never.t := return_ (core.result.Result.Err α0) in - let* α2 := M.read α1 in - let* α3 : i32.t := never_to_any α2 in - M.alloc α3 - end in - M.copy α2 in + let* α2 : + M.Val (core.result.Result.t i32.t core.num.error.ParseIntError.t) := + M.alloc α1 in + let* α3 : M.Val i32.t := + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* second_number := M.copy γ0 in + M.pure second_number + | _ => M.break_match + end) : + M (M.Val i32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* α0 : core.num.error.ParseIntError.t := M.read e in + let* α1 : M.Val never.t := + return_ (core.result.Result.Err α0) in + let* α2 := M.read α1 in + let* α3 : i32.t := never_to_any α2 in + M.alloc α3 + | _ => M.break_match + end) : + M (M.Val i32.t) + ] in + M.copy α3 in let* α0 : i32.t := M.read first_number in let* α1 : i32.t := M.read second_number in let* α2 : i32.t := BinOp.Panic.mul α0 α1 in @@ -82,56 +122,74 @@ Definition print (result : core.result.Result.t i32.t core.num.error.ParseIntError.t) : M unit := let* result := M.alloc result in - let* α0 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.read result in - let* α1 : M.Val unit := - match α0 with - | core.result.Result.Ok n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "n is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "n is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.result.Result.Err e => - let* e := M.alloc e in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Error: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Error: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α1. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/error_handling/introducing_question_mark.v b/CoqOfRust/examples/default/examples/error_handling/introducing_question_mark.v index 81082ca54..bdb33f3ed 100644 --- a/CoqOfRust/examples/default/examples/error_handling/introducing_question_mark.v +++ b/CoqOfRust/examples/default/examples/error_handling/introducing_question_mark.v @@ -35,31 +35,58 @@ Definition multiply core.result.Result.t i32.t core.num.error.ParseIntError.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val i32.t := - match α2 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α3 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - core.num.error.ParseIntError.t := - M.read residual in - let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := - core.result.Result.t i32.t core.num.error.ParseIntError.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : i32.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α3 in + core.num.error.ParseIntError.t) + i32.t) := + M.alloc α2 in + let* α4 : M.Val i32.t := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + core.num.error.ParseIntError.t := + M.read residual in + let* α1 : + core.result.Result.t i32.t core.num.error.ParseIntError.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + i32.t + core.num.error.ParseIntError.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : i32.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val i32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val i32.t) + ] in + M.copy α4 in let* second_number : M.Val i32.t := let* α0 : ref str.t := M.read second_number_str in let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := @@ -76,31 +103,58 @@ Definition multiply core.result.Result.t i32.t core.num.error.ParseIntError.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val i32.t := - match α2 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α3 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - core.num.error.ParseIntError.t := - M.read residual in - let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := - core.result.Result.t i32.t core.num.error.ParseIntError.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : i32.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α3 in + core.num.error.ParseIntError.t) + i32.t) := + M.alloc α2 in + let* α4 : M.Val i32.t := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + core.num.error.ParseIntError.t := + M.read residual in + let* α1 : + core.result.Result.t i32.t core.num.error.ParseIntError.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + i32.t + core.num.error.ParseIntError.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : i32.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val i32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val i32.t) + ] in + M.copy α4 in let* α0 : i32.t := M.read first_number in let* α1 : i32.t := M.read second_number in let* α2 : i32.t := BinOp.Panic.mul α0 α1 in @@ -121,56 +175,74 @@ Definition print (result : core.result.Result.t i32.t core.num.error.ParseIntError.t) : M unit := let* result := M.alloc result in - let* α0 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.read result in - let* α1 : M.Val unit := - match α0 with - | core.result.Result.Ok n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "n is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "n is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.result.Result.Err e => - let* e := M.alloc e in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Error: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Error: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α1. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/error_handling/introducing_question_mark_is_an_replacement_for_deprecated_try.v b/CoqOfRust/examples/default/examples/error_handling/introducing_question_mark_is_an_replacement_for_deprecated_try.v index f5a6c51bd..c802ac3dc 100644 --- a/CoqOfRust/examples/default/examples/error_handling/introducing_question_mark_is_an_replacement_for_deprecated_try.v +++ b/CoqOfRust/examples/default/examples/error_handling/introducing_question_mark_is_an_replacement_for_deprecated_try.v @@ -23,54 +23,92 @@ Definition multiply let* α0 : ref str.t := M.read first_number_str in let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := M.call (str.t::["parse"] α0) in - let* α2 : M.Val i32.t := - match α1 with - | core.result.Result.Ok val => - let* val := M.alloc val in - M.pure val - | core.result.Result.Err err => - let* err := M.alloc err in - let* _ : M.Val never.t := - let* α0 : core.num.error.ParseIntError.t := M.read err in - let* α1 : core.num.error.ParseIntError.t := - M.call - ((core.convert.From.from - (Self := core.num.error.ParseIntError.t) - (Trait := ltac:(refine _))) - α0) in - return_ (core.result.Result.Err α1) in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : i32.t := never_to_any α1 in - M.alloc α2 - end in - M.copy α2 in + let* α2 : + M.Val (core.result.Result.t i32.t core.num.error.ParseIntError.t) := + M.alloc α1 in + let* α3 : M.Val i32.t := + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val i32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* err := M.copy γ0 in + let* _ : M.Val never.t := + let* α0 : core.num.error.ParseIntError.t := M.read err in + let* α1 : core.num.error.ParseIntError.t := + M.call + ((core.convert.From.from + (Self := core.num.error.ParseIntError.t) + (Trait := ltac:(refine _))) + α0) in + return_ (core.result.Result.Err α1) in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : i32.t := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val i32.t) + ] in + M.copy α3 in let* second_number : M.Val i32.t := let* α0 : ref str.t := M.read second_number_str in let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := M.call (str.t::["parse"] α0) in - let* α2 : M.Val i32.t := - match α1 with - | core.result.Result.Ok val => - let* val := M.alloc val in - M.pure val - | core.result.Result.Err err => - let* err := M.alloc err in - let* _ : M.Val never.t := - let* α0 : core.num.error.ParseIntError.t := M.read err in - let* α1 : core.num.error.ParseIntError.t := - M.call - ((core.convert.From.from - (Self := core.num.error.ParseIntError.t) - (Trait := ltac:(refine _))) - α0) in - return_ (core.result.Result.Err α1) in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : i32.t := never_to_any α1 in - M.alloc α2 - end in - M.copy α2 in + let* α2 : + M.Val (core.result.Result.t i32.t core.num.error.ParseIntError.t) := + M.alloc α1 in + let* α3 : M.Val i32.t := + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val i32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* err := M.copy γ0 in + let* _ : M.Val never.t := + let* α0 : core.num.error.ParseIntError.t := M.read err in + let* α1 : core.num.error.ParseIntError.t := + M.call + ((core.convert.From.from + (Self := core.num.error.ParseIntError.t) + (Trait := ltac:(refine _))) + α0) in + return_ (core.result.Result.Err α1) in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : i32.t := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val i32.t) + ] in + M.copy α3 in let* α0 : i32.t := M.read first_number in let* α1 : i32.t := M.read second_number in let* α2 : i32.t := BinOp.Panic.mul α0 α1 in @@ -91,56 +129,74 @@ Definition print (result : core.result.Result.t i32.t core.num.error.ParseIntError.t) : M unit := let* result := M.alloc result in - let* α0 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.read result in - let* α1 : M.Val unit := - match α0 with - | core.result.Result.Ok n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "n is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "n is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.result.Result.Err e => - let* e := M.alloc e in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Error: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Error: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α1. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_valid_values_and_failures_via_partition.v b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_valid_values_and_failures_via_partition.v index 78f64bbe9..c530f1573 100644 --- a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_valid_values_and_failures_via_partition.v +++ b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_valid_values_and_failures_via_partition.v @@ -27,7 +27,38 @@ Definition main : M unit := let* α6 : alloc.vec.Vec.t (ref str.t) alloc.alloc.Global.t := M.call ((slice (ref str.t))::["into_vec"] α5) in M.alloc α6 in - let* '(numbers, errors) : + let* α0 : alloc.vec.Vec.t (ref str.t) alloc.alloc.Global.t := + M.read strings in + let* α1 : alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t := + M.call + ((core.iter.traits.collect.IntoIterator.into_iter + (Self := alloc.vec.Vec.t (ref str.t) alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : + core.iter.adapters.map.Map.t + (alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) + ((ref str.t) -> + M (core.result.Result.t i32.t core.num.error.ParseIntError.t)) := + M.call + ((core.iter.traits.iterator.Iterator.map + (Self := + alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + α1 + (fun (α0 : ref str.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* s := M.copy γ in + let* α0 : ref str.t := M.read s in + M.call (str.t::["parse"] α0)) : + M (core.result.Result.t i32.t core.num.error.ParseIntError.t) + ]) : + M (core.result.Result.t i32.t core.num.error.ParseIntError.t))) in + let* α3 : (alloc.vec.Vec.t (core.result.Result.t i32.t core.num.error.ParseIntError.t) alloc.alloc.Global.t) @@ -35,30 +66,6 @@ Definition main : M unit := (alloc.vec.Vec.t (core.result.Result.t i32.t core.num.error.ParseIntError.t) alloc.alloc.Global.t) := - let* α0 : alloc.vec.Vec.t (ref str.t) alloc.alloc.Global.t := - M.read strings in - let* α1 : alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t := - M.call - ((core.iter.traits.collect.IntoIterator.into_iter - (Self := alloc.vec.Vec.t (ref str.t) alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : - core.iter.adapters.map.Map.t - (alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) - ((ref str.t) -> - M (core.result.Result.t i32.t core.num.error.ParseIntError.t)) := - M.call - ((core.iter.traits.iterator.Iterator.map - (Self := - alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - α1 - (fun (s : ref str.t) => - (let* s := M.alloc s in - let* α0 : ref str.t := M.read s in - M.call (str.t::["parse"] α0)) : - M (core.result.Result.t i32.t core.num.error.ParseIntError.t))) in M.call ((core.iter.traits.iterator.Iterator.partition (Self := @@ -71,49 +78,78 @@ Definition main : M unit := (core.result.Result.t i32.t core.num.error.ParseIntError.t)::["is_ok"]) in - let* numbers := M.alloc numbers in - let* errors := M.alloc errors in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Numbers: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α4 : + M.Val + ((alloc.vec.Vec.t + (core.result.Result.t i32.t core.num.error.ParseIntError.t) + alloc.alloc.Global.t) + * + (alloc.vec.Vec.t + (core.result.Result.t i32.t core.num.error.ParseIntError.t) + alloc.alloc.Global.t)) := + M.alloc α3 in + let* α0 : M.Val unit := + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* numbers := M.copy γ0 in + let* errors := M.copy γ1 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Numbers: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow numbers)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Errors: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow numbers)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Errors: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow errors)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow errors)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_valid_values_and_failures_via_partition_unwrapped.v b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_valid_values_and_failures_via_partition_unwrapped.v index cbb0f5791..f6301221c 100644 --- a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_valid_values_and_failures_via_partition_unwrapped.v +++ b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_valid_values_and_failures_via_partition_unwrapped.v @@ -29,7 +29,38 @@ Definition main : M unit := let* α6 : alloc.vec.Vec.t (ref str.t) alloc.alloc.Global.t := M.call ((slice (ref str.t))::["into_vec"] α5) in M.alloc α6 in - let* '(numbers, errors) : + let* α0 : alloc.vec.Vec.t (ref str.t) alloc.alloc.Global.t := + M.read strings in + let* α1 : alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t := + M.call + ((core.iter.traits.collect.IntoIterator.into_iter + (Self := alloc.vec.Vec.t (ref str.t) alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : + core.iter.adapters.map.Map.t + (alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) + ((ref str.t) -> + M (core.result.Result.t i32.t core.num.error.ParseIntError.t)) := + M.call + ((core.iter.traits.iterator.Iterator.map + (Self := + alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + α1 + (fun (α0 : ref str.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* s := M.copy γ in + let* α0 : ref str.t := M.read s in + M.call (str.t::["parse"] α0)) : + M (core.result.Result.t i32.t core.num.error.ParseIntError.t) + ]) : + M (core.result.Result.t i32.t core.num.error.ParseIntError.t))) in + let* α3 : (alloc.vec.Vec.t (core.result.Result.t i32.t core.num.error.ParseIntError.t) alloc.alloc.Global.t) @@ -37,30 +68,6 @@ Definition main : M unit := (alloc.vec.Vec.t (core.result.Result.t i32.t core.num.error.ParseIntError.t) alloc.alloc.Global.t) := - let* α0 : alloc.vec.Vec.t (ref str.t) alloc.alloc.Global.t := - M.read strings in - let* α1 : alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t := - M.call - ((core.iter.traits.collect.IntoIterator.into_iter - (Self := alloc.vec.Vec.t (ref str.t) alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : - core.iter.adapters.map.Map.t - (alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) - ((ref str.t) -> - M (core.result.Result.t i32.t core.num.error.ParseIntError.t)) := - M.call - ((core.iter.traits.iterator.Iterator.map - (Self := - alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - α1 - (fun (s : ref str.t) => - (let* s := M.alloc s in - let* α0 : ref str.t := M.read s in - M.call (str.t::["parse"] α0)) : - M (core.result.Result.t i32.t core.num.error.ParseIntError.t))) in M.call ((core.iter.traits.iterator.Iterator.partition (Self := @@ -73,146 +80,195 @@ Definition main : M unit := (core.result.Result.t i32.t core.num.error.ParseIntError.t)::["is_ok"]) in - let* numbers := M.alloc numbers in - let* errors := M.alloc errors in - let* numbers : M.Val (alloc.vec.Vec.t i32.t alloc.alloc.Global.t) := - let* α0 : - alloc.vec.Vec.t - (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t := - M.read numbers in - let* α1 : - alloc.vec.into_iter.IntoIter.t - (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t := - M.call - ((core.iter.traits.collect.IntoIterator.into_iter - (Self := - alloc.vec.Vec.t - (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : - core.iter.adapters.map.Map.t - (alloc.vec.into_iter.IntoIter.t - (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t) - _ := - M.call - ((core.iter.traits.iterator.Iterator.map - (Self := - alloc.vec.into_iter.IntoIter.t - (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - α1 - (core.result.Result.t - i32.t - core.num.error.ParseIntError.t)::["unwrap"]) in - let* α3 : alloc.vec.Vec.t i32.t alloc.alloc.Global.t := - M.call - ((core.iter.traits.iterator.Iterator.collect - (Self := - core.iter.adapters.map.Map.t - (alloc.vec.into_iter.IntoIter.t - (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t) - _) - (Trait := ltac:(refine _))) - α2) in - M.alloc α3 in - let* errors : + let* α4 : M.Val - (alloc.vec.Vec.t core.num.error.ParseIntError.t alloc.alloc.Global.t) := - let* α0 : - alloc.vec.Vec.t + ((alloc.vec.Vec.t (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t := - M.read errors in - let* α1 : - alloc.vec.into_iter.IntoIter.t + alloc.alloc.Global.t) + * + (alloc.vec.Vec.t (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t := - M.call - ((core.iter.traits.collect.IntoIterator.into_iter - (Self := - alloc.vec.Vec.t - (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : - core.iter.adapters.map.Map.t - (alloc.vec.into_iter.IntoIter.t - (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t) - _ := - M.call - ((core.iter.traits.iterator.Iterator.map - (Self := - alloc.vec.into_iter.IntoIter.t - (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - α1 - (core.result.Result.t - i32.t - core.num.error.ParseIntError.t)::["unwrap_err"]) in - let* α3 : - alloc.vec.Vec.t core.num.error.ParseIntError.t alloc.alloc.Global.t := - M.call - ((core.iter.traits.iterator.Iterator.collect - (Self := - core.iter.adapters.map.Map.t - (alloc.vec.into_iter.IntoIter.t - (core.result.Result.t i32.t core.num.error.ParseIntError.t) - alloc.alloc.Global.t) - _) - (Trait := ltac:(refine _))) - α2) in + alloc.alloc.Global.t)) := M.alloc α3 in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Numbers: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* numbers := M.copy γ0 in + let* errors := M.copy γ1 in + let* numbers : M.Val (alloc.vec.Vec.t i32.t alloc.alloc.Global.t) := + let* α0 : + alloc.vec.Vec.t + (core.result.Result.t i32.t core.num.error.ParseIntError.t) + alloc.alloc.Global.t := + M.read numbers in + let* α1 : + alloc.vec.into_iter.IntoIter.t + (core.result.Result.t i32.t core.num.error.ParseIntError.t) + alloc.alloc.Global.t := + M.call + ((core.iter.traits.collect.IntoIterator.into_iter + (Self := + alloc.vec.Vec.t + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t) + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : + core.iter.adapters.map.Map.t + (alloc.vec.into_iter.IntoIter.t + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t) + alloc.alloc.Global.t) + _ := + M.call + ((core.iter.traits.iterator.Iterator.map + (Self := + alloc.vec.into_iter.IntoIter.t + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t) + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + α1 + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t)::["unwrap"]) in + let* α3 : alloc.vec.Vec.t i32.t alloc.alloc.Global.t := + M.call + ((core.iter.traits.iterator.Iterator.collect + (Self := + core.iter.adapters.map.Map.t + (alloc.vec.into_iter.IntoIter.t + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t) + alloc.alloc.Global.t) + _) + (Trait := ltac:(refine _))) + α2) in + M.alloc α3 in + let* errors : + M.Val + (alloc.vec.Vec.t + core.num.error.ParseIntError.t + alloc.alloc.Global.t) := + let* α0 : + alloc.vec.Vec.t + (core.result.Result.t i32.t core.num.error.ParseIntError.t) + alloc.alloc.Global.t := + M.read errors in + let* α1 : + alloc.vec.into_iter.IntoIter.t + (core.result.Result.t i32.t core.num.error.ParseIntError.t) + alloc.alloc.Global.t := + M.call + ((core.iter.traits.collect.IntoIterator.into_iter + (Self := + alloc.vec.Vec.t + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t) + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : + core.iter.adapters.map.Map.t + (alloc.vec.into_iter.IntoIter.t + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t) + alloc.alloc.Global.t) + _ := + M.call + ((core.iter.traits.iterator.Iterator.map + (Self := + alloc.vec.into_iter.IntoIter.t + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t) + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + α1 + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t)::["unwrap_err"]) in + let* α3 : + alloc.vec.Vec.t + core.num.error.ParseIntError.t + alloc.alloc.Global.t := + M.call + ((core.iter.traits.iterator.Iterator.collect + (Self := + core.iter.adapters.map.Map.t + (alloc.vec.into_iter.IntoIter.t + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t) + alloc.alloc.Global.t) + _) + (Trait := ltac:(refine _))) + α2) in + M.alloc α3 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Numbers: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow numbers)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Errors: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow numbers)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Errors: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow errors)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow errors)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_via_map_err_and_filter_map.v b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_via_map_err_and_filter_map.v index 172f50578..20f514ee3 100644 --- a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_via_map_err_and_filter_map.v +++ b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_collect_via_map_err_and_filter_map.v @@ -61,10 +61,17 @@ Definition main : M unit := alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) (Trait := ltac:(refine _))) α1 - (fun (s : ref str.t) => - (let* s := M.alloc s in - let* α0 : ref str.t := M.read s in - M.call (str.t::["parse"] α0)) : + (fun (α0 : ref str.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* s := M.copy γ in + let* α0 : ref str.t := M.read s in + M.call (str.t::["parse"] α0)) : + M (core.result.Result.t u8.t core.num.error.ParseIntError.t) + ]) : M (core.result.Result.t u8.t core.num.error.ParseIntError.t))) in let* α3 : core.iter.adapters.filter_map.FilterMap.t @@ -85,28 +92,46 @@ Definition main : M unit := M (core.result.Result.t u8.t core.num.error.ParseIntError.t))) (Trait := ltac:(refine _))) α2 - (fun (r : core.result.Result.t u8.t core.num.error.ParseIntError.t) => - (let* r := M.alloc r in - let* α0 : - core.result.Result.t u8.t core.num.error.ParseIntError.t := - M.read r in - let* α1 : core.result.Result.t u8.t unit := - M.call - ((core.result.Result.t - u8.t - core.num.error.ParseIntError.t)::["map_err"] - α0 - (fun (e : core.num.error.ParseIntError.t) => - (let* e := M.alloc e in - let* α0 : core.num.error.ParseIntError.t := M.read e in + (fun + (α0 : core.result.Result.t u8.t core.num.error.ParseIntError.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* r := M.copy γ in + let* α0 : + core.result.Result.t + u8.t + core.num.error.ParseIntError.t := + M.read r in + let* α1 : core.result.Result.t u8.t unit := M.call - ((alloc.vec.Vec.t - core.num.error.ParseIntError.t - alloc.alloc.Global.t)::["push"] - (borrow_mut errors) - α0)) : - M unit)) in - M.call ((core.result.Result.t u8.t unit)::["ok"] α1)) : + ((core.result.Result.t + u8.t + core.num.error.ParseIntError.t)::["map_err"] + α0 + (fun (α0 : core.num.error.ParseIntError.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* e := M.copy γ in + let* α0 : core.num.error.ParseIntError.t := + M.read e in + M.call + ((alloc.vec.Vec.t + core.num.error.ParseIntError.t + alloc.alloc.Global.t)::["push"] + (borrow_mut errors) + α0)) : + M unit + ]) : + M unit)) in + M.call ((core.result.Result.t u8.t unit)::["ok"] α1)) : + M (core.option.Option.t u8.t) + ]) : M (core.option.Option.t u8.t))) in let* α4 : alloc.vec.Vec.t u8.t alloc.alloc.Global.t := M.call diff --git a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_fail_entire_operation_via_collect.v b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_fail_entire_operation_via_collect.v index 64326ebe6..55e1df576 100644 --- a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_fail_entire_operation_via_collect.v +++ b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_fail_entire_operation_via_collect.v @@ -47,10 +47,17 @@ Definition main : M unit := alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) (Trait := ltac:(refine _))) α1 - (fun (s : ref str.t) => - (let* s := M.alloc s in - let* α0 : ref str.t := M.read s in - M.call (str.t::["parse"] α0)) : + (fun (α0 : ref str.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* s := M.copy γ in + let* α0 : ref str.t := M.read s in + M.call (str.t::["parse"] α0)) : + M (core.result.Result.t i32.t core.num.error.ParseIntError.t) + ]) : M (core.result.Result.t i32.t core.num.error.ParseIntError.t))) in let* α3 : core.result.Result.t diff --git a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_failed.v b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_failed.v index 9fdf8bc30..48b251855 100644 --- a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_failed.v +++ b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_failed.v @@ -47,10 +47,17 @@ Definition main : M unit := alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) (Trait := ltac:(refine _))) α1 - (fun (s : ref str.t) => - (let* s := M.alloc s in - let* α0 : ref str.t := M.read s in - M.call (str.t::["parse"] α0)) : + (fun (α0 : ref str.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* s := M.copy γ in + let* α0 : ref str.t := M.read s in + M.call (str.t::["parse"] α0)) : + M (core.result.Result.t i32.t core.num.error.ParseIntError.t) + ]) : M (core.result.Result.t i32.t core.num.error.ParseIntError.t))) in let* α3 : alloc.vec.Vec.t diff --git a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_handle_via_filter_map.v b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_handle_via_filter_map.v index 88e461eb0..f8bc59698 100644 --- a/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_handle_via_filter_map.v +++ b/CoqOfRust/examples/default/examples/error_handling/iterating_over_results_handle_via_filter_map.v @@ -45,17 +45,26 @@ Definition main : M unit := alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) (Trait := ltac:(refine _))) α1 - (fun (s : ref str.t) => - (let* s := M.alloc s in - let* α0 : ref str.t := M.read s in - let* α1 : - core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call (str.t::["parse"] α0) in - M.call - ((core.result.Result.t - i32.t - core.num.error.ParseIntError.t)::["ok"] - α1)) : + (fun (α0 : ref str.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* s := M.copy γ in + let* α0 : ref str.t := M.read s in + let* α1 : + core.result.Result.t + i32.t + core.num.error.ParseIntError.t := + M.call (str.t::["parse"] α0) in + M.call + ((core.result.Result.t + i32.t + core.num.error.ParseIntError.t)::["ok"] + α1)) : + M (core.option.Option.t i32.t) + ]) : M (core.option.Option.t i32.t))) in let* α3 : alloc.vec.Vec.t i32.t alloc.alloc.Global.t := M.call diff --git a/CoqOfRust/examples/default/examples/error_handling/map_in_result_via_combinators.v b/CoqOfRust/examples/default/examples/error_handling/map_in_result_via_combinators.v index d6db53a06..fd4eeb5c7 100644 --- a/CoqOfRust/examples/default/examples/error_handling/map_in_result_via_combinators.v +++ b/CoqOfRust/examples/default/examples/error_handling/map_in_result_via_combinators.v @@ -22,20 +22,37 @@ Definition multiply M.call ((core.result.Result.t i32.t core.num.error.ParseIntError.t)::["and_then"] α1 - (fun (first_number : i32.t) => - (let* first_number := M.alloc first_number in - let* α0 : ref str.t := M.read second_number_str in - let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call (str.t::["parse"] α0) in - M.call - ((core.result.Result.t i32.t core.num.error.ParseIntError.t)::["map"] - α1 - (fun (second_number : i32.t) => - (let* second_number := M.alloc second_number in - let* α0 : i32.t := M.read first_number in - let* α1 : i32.t := M.read second_number in - BinOp.Panic.mul α0 α1) : - M i32.t))) : + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* first_number := M.copy γ in + let* α0 : ref str.t := M.read second_number_str in + let* α1 : + core.result.Result.t i32.t core.num.error.ParseIntError.t := + M.call (str.t::["parse"] α0) in + M.call + ((core.result.Result.t + i32.t + core.num.error.ParseIntError.t)::["map"] + α1 + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* second_number := M.copy γ in + let* α0 : i32.t := M.read first_number in + let* α1 : i32.t := M.read second_number in + BinOp.Panic.mul α0 α1) : + M i32.t + ]) : + M i32.t))) : + M (core.result.Result.t i32.t core.num.error.ParseIntError.t) + ]) : M (core.result.Result.t i32.t core.num.error.ParseIntError.t))). (* @@ -50,56 +67,74 @@ Definition print (result : core.result.Result.t i32.t core.num.error.ParseIntError.t) : M unit := let* result := M.alloc result in - let* α0 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.read result in - let* α1 : M.Val unit := - match α0 with - | core.result.Result.Ok n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "n is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "n is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.result.Result.Err e => - let* e := M.alloc e in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Error: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Error: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α1. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/error_handling/map_in_result_via_match.v b/CoqOfRust/examples/default/examples/error_handling/map_in_result_via_match.v index 1c33a132b..8eeede0c4 100644 --- a/CoqOfRust/examples/default/examples/error_handling/map_in_result_via_match.v +++ b/CoqOfRust/examples/default/examples/error_handling/map_in_result_via_match.v @@ -22,30 +22,77 @@ Definition multiply let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := M.call (str.t::["parse"] α0) in let* α2 : M.Val (core.result.Result.t i32.t core.num.error.ParseIntError.t) := - match α1 with - | core.result.Result.Ok first_number => - let* first_number := M.alloc first_number in - let* α0 : ref str.t := M.read second_number_str in - let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call (str.t::["parse"] α0) in - match α1 with - | core.result.Result.Ok second_number => - let* second_number := M.alloc second_number in - let* α0 : i32.t := M.read first_number in - let* α1 : i32.t := M.read second_number in - let* α2 : i32.t := BinOp.Panic.mul α0 α1 in - M.alloc (core.result.Result.Ok α2) - | core.result.Result.Err e => - let* e := M.alloc e in - let* α0 : core.num.error.ParseIntError.t := M.read e in - M.alloc (core.result.Result.Err α0) - end - | core.result.Result.Err e => - let* e := M.alloc e in - let* α0 : core.num.error.ParseIntError.t := M.read e in - M.alloc (core.result.Result.Err α0) - end in - M.read α2. + M.alloc α1 in + let* α3 : M.Val (core.result.Result.t i32.t core.num.error.ParseIntError.t) := + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* first_number := M.copy γ0 in + let* α0 : ref str.t := M.read second_number_str in + let* α1 : + core.result.Result.t i32.t core.num.error.ParseIntError.t := + M.call (str.t::["parse"] α0) in + let* α2 : + M.Val + (core.result.Result.t i32.t core.num.error.ParseIntError.t) := + M.alloc α1 in + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* second_number := M.copy γ0 in + let* α0 : i32.t := M.read first_number in + let* α1 : i32.t := M.read second_number in + let* α2 : i32.t := BinOp.Panic.mul α0 α1 in + M.alloc (core.result.Result.Ok α2) + | _ => M.break_match + end) : + M + (M.Val + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* α0 : core.num.error.ParseIntError.t := M.read e in + M.alloc (core.result.Result.Err α0) + | _ => M.break_match + end) : + M + (M.Val + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t)) + ] + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t i32.t core.num.error.ParseIntError.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* α0 : core.num.error.ParseIntError.t := M.read e in + M.alloc (core.result.Result.Err α0) + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t i32.t core.num.error.ParseIntError.t)) + ] in + M.read α3. (* fn print(result: Result) { @@ -59,56 +106,74 @@ Definition print (result : core.result.Result.t i32.t core.num.error.ParseIntError.t) : M unit := let* result := M.alloc result in - let* α0 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.read result in - let* α1 : M.Val unit := - match α0 with - | core.result.Result.Ok n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "n is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "n is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.result.Result.Err e => - let* e := M.alloc e in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Error: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Error: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α1. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/error_handling/option_and_unwrap.v b/CoqOfRust/examples/default/examples/error_handling/option_and_unwrap.v index 168558729..11853bba5 100644 --- a/CoqOfRust/examples/default/examples/error_handling/option_and_unwrap.v +++ b/CoqOfRust/examples/default/examples/error_handling/option_and_unwrap.v @@ -13,59 +13,85 @@ fn give_adult(drink: Option<&str>) { *) Definition give_adult (drink : core.option.Option.t (ref str.t)) : M unit := let* drink := M.alloc drink in - let* α0 : core.option.Option.t (ref str.t) := M.read drink in - let* α1 : M.Val unit := - match α0 with - | core.option.Option.Some _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Yuck! Too sugary. + let* α0 : M.Val unit := + match_operator + drink + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Yuck! Too sugary. ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | core.option.Option.Some inner => - let* inner := M.alloc inner in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str "? How nice. + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* inner := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str "? How nice. ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow inner)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.option.Option.None => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "No drink? Oh well. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow inner)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "No drink? Oh well. ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in - M.read α1. + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn drink(drink: Option<&str>) { diff --git a/CoqOfRust/examples/default/examples/error_handling/other_uses_of_question_mark.v b/CoqOfRust/examples/default/examples/error_handling/other_uses_of_question_mark.v index c7e0db9ce..cc1115038 100644 --- a/CoqOfRust/examples/default/examples/error_handling/other_uses_of_question_mark.v +++ b/CoqOfRust/examples/default/examples/error_handling/other_uses_of_question_mark.v @@ -134,36 +134,60 @@ Definition double_first other_uses_of_question_mark.EmptyVec.t) (Trait := ltac:(refine _))) α2) in - let* α4 : M.Val (ref (ref str.t)) := - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - other_uses_of_question_mark.EmptyVec.t := - M.read residual in - let* α1 : - core.result.Result.t - i32.t - (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := + other_uses_of_question_mark.EmptyVec.t) + (ref (ref str.t))) := + M.alloc α3 in + let* α5 : M.Val (ref (ref str.t)) := + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + other_uses_of_question_mark.EmptyVec.t := + M.read residual in + let* α1 : core.result.Result.t i32.t - (alloc.boxed.Box.t dynamic alloc.alloc.Global.t)) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : ref (ref str.t) := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α4 in + (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + i32.t + (alloc.boxed.Box.t dynamic alloc.alloc.Global.t)) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : ref (ref str.t) := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val (ref (ref str.t))); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val (ref (ref str.t))) + ] in + M.copy α5 in let* parsed : M.Val i32.t := let* α0 : ref (ref str.t) := M.read first in let* α1 : ref str.t := M.read (deref α0) in @@ -181,36 +205,60 @@ Definition double_first core.result.Result.t i32.t core.num.error.ParseIntError.t) (Trait := ltac:(refine _))) α2) in - let* α4 : M.Val i32.t := - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - core.num.error.ParseIntError.t := - M.read residual in - let* α1 : - core.result.Result.t - i32.t - (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := + core.num.error.ParseIntError.t) + i32.t) := + M.alloc α3 in + let* α5 : M.Val i32.t := + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + core.num.error.ParseIntError.t := + M.read residual in + let* α1 : core.result.Result.t i32.t - (alloc.boxed.Box.t dynamic alloc.alloc.Global.t)) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : i32.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α4 in + (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + i32.t + (alloc.boxed.Box.t dynamic alloc.alloc.Global.t)) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : i32.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val i32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val i32.t) + ] in + M.copy α5 in let* α0 : i32.t := M.read parsed in let* α1 : i32.t := BinOp.Panic.mul (Integer.of_Z 2) α0 in let* α0 : @@ -233,59 +281,74 @@ Definition print (result : ltac:(other_uses_of_question_mark.Result i32.t)) : M unit := let* result := M.alloc result in - let* α0 : - core.result.Result.t - i32.t - (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := - M.read result in - let* α1 : M.Val unit := - match α0 with - | core.result.Result.Ok n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "The first doubled is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "The first doubled is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.result.Result.Err e => - let* e := M.alloc e in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Error: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Error: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α1. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/error_handling/pulling_results_out_of_options.v b/CoqOfRust/examples/default/examples/error_handling/pulling_results_out_of_options.v index 7a6034f95..ea3894a76 100644 --- a/CoqOfRust/examples/default/examples/error_handling/pulling_results_out_of_options.v +++ b/CoqOfRust/examples/default/examples/error_handling/pulling_results_out_of_options.v @@ -24,20 +24,37 @@ Definition double_first M.call ((core.option.Option.t (ref (ref str.t)))::["map"] α1 - (fun (first : ref (ref str.t)) => - (let* first := M.alloc first in - let* α0 : ref (ref str.t) := M.read first in - let* α1 : ref str.t := M.read (deref α0) in - let* α2 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call (str.t::["parse"] α1) in - M.call - ((core.result.Result.t i32.t core.num.error.ParseIntError.t)::["map"] - α2 - (fun (n : i32.t) => - (let* n := M.alloc n in - let* α0 : i32.t := M.read n in - BinOp.Panic.mul (Integer.of_Z 2) α0) : - M i32.t))) : + (fun (α0 : ref (ref str.t)) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* first := M.copy γ in + let* α0 : ref (ref str.t) := M.read first in + let* α1 : ref str.t := M.read (deref α0) in + let* α2 : + core.result.Result.t i32.t core.num.error.ParseIntError.t := + M.call (str.t::["parse"] α1) in + M.call + ((core.result.Result.t + i32.t + core.num.error.ParseIntError.t)::["map"] + α2 + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* n := M.copy γ in + let* α0 : i32.t := M.read n in + BinOp.Panic.mul (Integer.of_Z 2) α0) : + M i32.t + ]) : + M i32.t))) : + M (core.result.Result.t i32.t core.num.error.ParseIntError.t) + ]) : M (core.result.Result.t i32.t core.num.error.ParseIntError.t))). (* diff --git a/CoqOfRust/examples/default/examples/error_handling/pulling_results_out_of_options_with_stop_error_processing.v b/CoqOfRust/examples/default/examples/error_handling/pulling_results_out_of_options_with_stop_error_processing.v index ea47effaa..742fda645 100644 --- a/CoqOfRust/examples/default/examples/error_handling/pulling_results_out_of_options_with_stop_error_processing.v +++ b/CoqOfRust/examples/default/examples/error_handling/pulling_results_out_of_options_with_stop_error_processing.v @@ -34,23 +34,39 @@ Definition double_first M.call ((core.option.Option.t (ref (ref str.t)))::["map"] α1 - (fun (first : ref (ref str.t)) => - (let* first := M.alloc first in - let* α0 : ref (ref str.t) := M.read first in - let* α1 : ref str.t := M.read (deref α0) in - let* α2 : - core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call (str.t::["parse"] α1) in - M.call - ((core.result.Result.t - i32.t - core.num.error.ParseIntError.t)::["map"] - α2 - (fun (n : i32.t) => - (let* n := M.alloc n in - let* α0 : i32.t := M.read n in - BinOp.Panic.mul (Integer.of_Z 2) α0) : - M i32.t))) : + (fun (α0 : ref (ref str.t)) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* first := M.copy γ in + let* α0 : ref (ref str.t) := M.read first in + let* α1 : ref str.t := M.read (deref α0) in + let* α2 : + core.result.Result.t + i32.t + core.num.error.ParseIntError.t := + M.call (str.t::["parse"] α1) in + M.call + ((core.result.Result.t + i32.t + core.num.error.ParseIntError.t)::["map"] + α2 + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* n := M.copy γ in + let* α0 : i32.t := M.read n in + BinOp.Panic.mul (Integer.of_Z 2) α0) : + M i32.t + ]) : + M i32.t))) : + M (core.result.Result.t i32.t core.num.error.ParseIntError.t) + ]) : M (core.result.Result.t i32.t core.num.error.ParseIntError.t))) in M.alloc α2 in let* α0 : @@ -68,16 +84,27 @@ Definition double_first core.num.error.ParseIntError.t))::["map_or"] α0 (core.result.Result.Ok core.option.Option.None) - (fun (r : core.result.Result.t i32.t core.num.error.ParseIntError.t) => - (let* r := M.alloc r in - let* α0 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.read r in - M.call - ((core.result.Result.t - i32.t - core.num.error.ParseIntError.t)::["map"] - α0 - core.option.Option.Some)) : + (fun (α0 : core.result.Result.t i32.t core.num.error.ParseIntError.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* r := M.copy γ in + let* α0 : + core.result.Result.t i32.t core.num.error.ParseIntError.t := + M.read r in + M.call + ((core.result.Result.t + i32.t + core.num.error.ParseIntError.t)::["map"] + α0 + core.option.Option.Some)) : + M + (core.result.Result.t + (core.option.Option.t i32.t) + core.num.error.ParseIntError.t) + ]) : M (core.result.Result.t (core.option.Option.t i32.t) diff --git a/CoqOfRust/examples/default/examples/error_handling/result_use_in_main.v b/CoqOfRust/examples/default/examples/error_handling/result_use_in_main.v index b7e6487b5..168f77664 100644 --- a/CoqOfRust/examples/default/examples/error_handling/result_use_in_main.v +++ b/CoqOfRust/examples/default/examples/error_handling/result_use_in_main.v @@ -23,20 +23,40 @@ Definition main let* α0 : ref str.t := M.read number_str in let* α1 : core.result.Result.t i32.t core.num.error.ParseIntError.t := M.call (str.t::["parse"] α0) in - let* α2 : M.Val i32.t := - match α1 with - | core.result.Result.Ok number => - let* number := M.alloc number in - M.pure number - | core.result.Result.Err e => - let* e := M.alloc e in - let* α0 : core.num.error.ParseIntError.t := M.read e in - let* α1 : M.Val never.t := return_ (core.result.Result.Err α0) in - let* α2 := M.read α1 in - let* α3 : i32.t := never_to_any α2 in - M.alloc α3 - end in - M.copy α2 in + let* α2 : + M.Val (core.result.Result.t i32.t core.num.error.ParseIntError.t) := + M.alloc α1 in + let* α3 : M.Val i32.t := + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* number := M.copy γ0 in + M.pure number + | _ => M.break_match + end) : + M (M.Val i32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* α0 : core.num.error.ParseIntError.t := M.read e in + let* α1 : M.Val never.t := + return_ (core.result.Result.Err α0) in + let* α2 := M.read α1 in + let* α3 : i32.t := never_to_any α2 in + M.alloc α3 + | _ => M.break_match + end) : + M (M.Val i32.t) + ] in + M.copy α3 in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "") in diff --git a/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_get_or_insert.v b/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_get_or_insert.v index 55af69961..821065bf6 100644 --- a/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_get_or_insert.v +++ b/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_get_or_insert.v @@ -25,29 +25,73 @@ Section Impl_core_fmt_Debug_for_unpacking_options_and_defaults_via_get_or_insert let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref unpacking_options_and_defaults_via_get_or_insert.Fruit.t := - M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | unpacking_options_and_defaults_via_get_or_insert.Fruit.Apple => - let* α0 : ref str.t := M.read (mk_str "Apple") in - M.alloc α0 - | unpacking_options_and_defaults_via_get_or_insert.Fruit.Orange => - let* α0 : ref str.t := M.read (mk_str "Orange") in - M.alloc α0 - | unpacking_options_and_defaults_via_get_or_insert.Fruit.Banana => - let* α0 : ref str.t := M.read (mk_str "Banana") in - M.alloc α0 - | unpacking_options_and_defaults_via_get_or_insert.Fruit.Kiwi => - let* α0 : ref str.t := M.read (mk_str "Kiwi") in - M.alloc α0 - | unpacking_options_and_defaults_via_get_or_insert.Fruit.Lemon => - let* α0 : ref str.t := M.read (mk_str "Lemon") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_get_or_insert.Fruit.Apple => + let* α0 : ref str.t := M.read (mk_str "Apple") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_get_or_insert.Fruit.Orange => + let* α0 : ref str.t := M.read (mk_str "Orange") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_get_or_insert.Fruit.Banana => + let* α0 : ref str.t := M.read (mk_str "Banana") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_get_or_insert.Fruit.Kiwi => + let* α0 : ref str.t := M.read (mk_str "Kiwi") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_get_or_insert.Fruit.Lemon => + let* α0 : ref str.t := M.read (mk_str "Lemon") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; diff --git a/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_get_or_insert_with.v b/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_get_or_insert_with.v index 55e717f64..c900c021e 100644 --- a/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_get_or_insert_with.v +++ b/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_get_or_insert_with.v @@ -25,30 +25,83 @@ Section Impl_core_fmt_Debug_for_unpacking_options_and_defaults_via_get_or_insert let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : - ref unpacking_options_and_defaults_via_get_or_insert_with.Fruit.t := - M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | unpacking_options_and_defaults_via_get_or_insert_with.Fruit.Apple => - let* α0 : ref str.t := M.read (mk_str "Apple") in - M.alloc α0 - | unpacking_options_and_defaults_via_get_or_insert_with.Fruit.Orange => - let* α0 : ref str.t := M.read (mk_str "Orange") in - M.alloc α0 - | unpacking_options_and_defaults_via_get_or_insert_with.Fruit.Banana => - let* α0 : ref str.t := M.read (mk_str "Banana") in - M.alloc α0 - | unpacking_options_and_defaults_via_get_or_insert_with.Fruit.Kiwi => - let* α0 : ref str.t := M.read (mk_str "Kiwi") in - M.alloc α0 - | unpacking_options_and_defaults_via_get_or_insert_with.Fruit.Lemon => - let* α0 : ref str.t := M.read (mk_str "Lemon") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + unpacking_options_and_defaults_via_get_or_insert_with.Fruit.Apple + => + let* α0 : ref str.t := M.read (mk_str "Apple") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + unpacking_options_and_defaults_via_get_or_insert_with.Fruit.Orange + => + let* α0 : ref str.t := M.read (mk_str "Orange") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + unpacking_options_and_defaults_via_get_or_insert_with.Fruit.Banana + => + let* α0 : ref str.t := M.read (mk_str "Banana") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + unpacking_options_and_defaults_via_get_or_insert_with.Fruit.Kiwi + => + let* α0 : ref str.t := M.read (mk_str "Kiwi") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + unpacking_options_and_defaults_via_get_or_insert_with.Fruit.Lemon + => + let* α0 : ref str.t := M.read (mk_str "Lemon") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; diff --git a/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_or.v b/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_or.v index 444f1f399..1e834594a 100644 --- a/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_or.v +++ b/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_or.v @@ -24,29 +24,73 @@ Section Impl_core_fmt_Debug_for_unpacking_options_and_defaults_via_or_Fruit_t. let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref unpacking_options_and_defaults_via_or.Fruit.t := - M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | unpacking_options_and_defaults_via_or.Fruit.Apple => - let* α0 : ref str.t := M.read (mk_str "Apple") in - M.alloc α0 - | unpacking_options_and_defaults_via_or.Fruit.Orange => - let* α0 : ref str.t := M.read (mk_str "Orange") in - M.alloc α0 - | unpacking_options_and_defaults_via_or.Fruit.Banana => - let* α0 : ref str.t := M.read (mk_str "Banana") in - M.alloc α0 - | unpacking_options_and_defaults_via_or.Fruit.Kiwi => - let* α0 : ref str.t := M.read (mk_str "Kiwi") in - M.alloc α0 - | unpacking_options_and_defaults_via_or.Fruit.Lemon => - let* α0 : ref str.t := M.read (mk_str "Lemon") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_or.Fruit.Apple => + let* α0 : ref str.t := M.read (mk_str "Apple") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_or.Fruit.Orange => + let* α0 : ref str.t := M.read (mk_str "Orange") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_or.Fruit.Banana => + let* α0 : ref str.t := M.read (mk_str "Banana") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_or.Fruit.Kiwi => + let* α0 : ref str.t := M.read (mk_str "Kiwi") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_or.Fruit.Lemon => + let* α0 : ref str.t := M.read (mk_str "Lemon") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; diff --git a/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_or_else.v b/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_or_else.v index 8ea128272..d1aa2e4d2 100644 --- a/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_or_else.v +++ b/CoqOfRust/examples/default/examples/error_handling/unpacking_options_and_defaults_via_or_else.v @@ -24,29 +24,73 @@ Section Impl_core_fmt_Debug_for_unpacking_options_and_defaults_via_or_else_Fruit let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref unpacking_options_and_defaults_via_or_else.Fruit.t := - M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | unpacking_options_and_defaults_via_or_else.Fruit.Apple => - let* α0 : ref str.t := M.read (mk_str "Apple") in - M.alloc α0 - | unpacking_options_and_defaults_via_or_else.Fruit.Orange => - let* α0 : ref str.t := M.read (mk_str "Orange") in - M.alloc α0 - | unpacking_options_and_defaults_via_or_else.Fruit.Banana => - let* α0 : ref str.t := M.read (mk_str "Banana") in - M.alloc α0 - | unpacking_options_and_defaults_via_or_else.Fruit.Kiwi => - let* α0 : ref str.t := M.read (mk_str "Kiwi") in - M.alloc α0 - | unpacking_options_and_defaults_via_or_else.Fruit.Lemon => - let* α0 : ref str.t := M.read (mk_str "Lemon") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_or_else.Fruit.Apple => + let* α0 : ref str.t := M.read (mk_str "Apple") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_or_else.Fruit.Orange => + let* α0 : ref str.t := M.read (mk_str "Orange") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_or_else.Fruit.Banana => + let* α0 : ref str.t := M.read (mk_str "Banana") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_or_else.Fruit.Kiwi => + let* α0 : ref str.t := M.read (mk_str "Kiwi") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | unpacking_options_and_defaults_via_or_else.Fruit.Lemon => + let* α0 : ref str.t := M.read (mk_str "Lemon") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; diff --git a/CoqOfRust/examples/default/examples/error_handling/unpacking_options_via_question_mark.v b/CoqOfRust/examples/default/examples/error_handling/unpacking_options_via_question_mark.v index b86077bc3..8fa3814ee 100644 --- a/CoqOfRust/examples/default/examples/error_handling/unpacking_options_via_question_mark.v +++ b/CoqOfRust/examples/default/examples/error_handling/unpacking_options_via_question_mark.v @@ -48,9 +48,18 @@ Section Impl_core_clone_Clone_for_unpacking_options_via_question_mark_Job_t. (self : ref Self) : M unpacking_options_via_question_mark.Job.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref unpacking_options_via_question_mark.Job.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val unpacking_options_via_question_mark.Job.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref unpacking_options_via_question_mark.Job.t := + M.read self in + M.pure (deref α0)) : + M (M.Val unpacking_options_via_question_mark.Job.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -112,11 +121,26 @@ Section Impl_core_clone_Clone_for_unpacking_options_via_question_mark_PhoneNumbe (self : ref Self) : M unpacking_options_via_question_mark.PhoneNumber.t := let* self := M.alloc self in - let _ : unit := tt in - let _ : unit := tt in - let* α0 : ref unpacking_options_via_question_mark.PhoneNumber.t := - M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val unpacking_options_via_question_mark.PhoneNumber.t := + match_operator + α0 + [ + fun γ => + (let* α0 : M.Val unit := M.alloc tt in + match_operator + α0 + [ + fun γ => + (let* α0 : + ref unpacking_options_via_question_mark.PhoneNumber.t := + M.read self in + M.pure (deref α0)) : + M (M.Val unpacking_options_via_question_mark.PhoneNumber.t) + ]) : + M (M.Val unpacking_options_via_question_mark.PhoneNumber.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -172,32 +196,54 @@ Section Impl_unpacking_options_via_question_mark_Person_t. core.option.Option.t unpacking_options_via_question_mark.Job.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val unpacking_options_via_question_mark.Job.t := - match α2 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : core.option.Option.t core.convert.Infallible.t := - M.read residual in - let* α1 : core.option.Option.t u8.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.option.Option.t u8.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unpacking_options_via_question_mark.Job.t := - never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - let* α4 : + let* α3 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.option.Option.t core.convert.Infallible.t) + unpacking_options_via_question_mark.Job.t) := + M.alloc α2 in + let* α4 : M.Val unpacking_options_via_question_mark.Job.t := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : core.option.Option.t core.convert.Infallible.t := + M.read residual in + let* α1 : core.option.Option.t u8.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.option.Option.t u8.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unpacking_options_via_question_mark.Job.t := + never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unpacking_options_via_question_mark.Job.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unpacking_options_via_question_mark.Job.t) + ] in + let* α5 : core.option.Option.t unpacking_options_via_question_mark.PhoneNumber.t := - M.read α3.["phone_number"] in - let* α5 : + M.read α4.["phone_number"] in + let* α6 : core.ops.control_flow.ControlFlow.t (core.option.Option.t core.convert.Infallible.t) unpacking_options_via_question_mark.PhoneNumber.t := @@ -207,29 +253,51 @@ Section Impl_unpacking_options_via_question_mark_Person_t. core.option.Option.t unpacking_options_via_question_mark.PhoneNumber.t) (Trait := ltac:(refine _))) - α4) in - let* α6 : M.Val unpacking_options_via_question_mark.PhoneNumber.t := - match α5 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : core.option.Option.t core.convert.Infallible.t := - M.read residual in - let* α1 : core.option.Option.t u8.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.option.Option.t u8.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unpacking_options_via_question_mark.PhoneNumber.t := - never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.read α6.["area_code"]). + α5) in + let* α7 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.option.Option.t core.convert.Infallible.t) + unpacking_options_via_question_mark.PhoneNumber.t) := + M.alloc α6 in + let* α8 : M.Val unpacking_options_via_question_mark.PhoneNumber.t := + match_operator + α7 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : core.option.Option.t core.convert.Infallible.t := + M.read residual in + let* α1 : core.option.Option.t u8.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.option.Option.t u8.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unpacking_options_via_question_mark.PhoneNumber.t := + never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unpacking_options_via_question_mark.PhoneNumber.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unpacking_options_via_question_mark.PhoneNumber.t) + ] in + M.read α8.["area_code"]). Global Instance AssociatedFunction_work_phone_area_code : Notations.DoubleColon Self "work_phone_area_code" := { @@ -278,38 +346,57 @@ Definition main : M unit := let* α1 : M.Val (core.option.Option.t u8.t) := M.alloc α0 in let* α2 : M.Val (core.option.Option.t u8.t) := M.alloc (core.option.Option.Some (Integer.of_Z 61)) in - match (borrow α1, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref (core.option.Option.t u8.t) := M.read left_val in - let* α1 : ref (core.option.Option.t u8.t) := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := core.option.Option.t u8.t) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref (core.option.Option.t u8.t) := M.read left_val in - let* α2 : ref (core.option.Option.t u8.t) := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : + M.Val + ((ref (core.option.Option.t u8.t)) + * + (ref (core.option.Option.t u8.t))) := + M.alloc (borrow α1, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref (core.option.Option.t u8.t) := M.read left_val in + let* α1 : ref (core.option.Option.t u8.t) := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := core.option.Option.t u8.t) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref (core.option.Option.t u8.t) := M.read left_val in + let* α2 : ref (core.option.Option.t u8.t) := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/error_handling/wrapping_errors.v b/CoqOfRust/examples/default/examples/error_handling/wrapping_errors.v index c415e1405..3d338fc2b 100644 --- a/CoqOfRust/examples/default/examples/error_handling/wrapping_errors.v +++ b/CoqOfRust/examples/default/examples/error_handling/wrapping_errors.v @@ -29,28 +29,51 @@ Section Impl_core_fmt_Debug_for_wrapping_errors_DoubleError_t. : M ltac:(core.fmt.Result) := let* self := M.alloc self in let* f := M.alloc f in - let* α0 : ref wrapping_errors.DoubleError.t := M.read self in - let* α1 : M.Val (core.result.Result.t unit core.fmt.Error.t) := - match α0 with - | wrapping_errors.DoubleError.EmptyVec => - let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref str.t := M.read (mk_str "EmptyVec") in - let* α2 : core.result.Result.t unit core.fmt.Error.t := - M.call (core.fmt.Formatter.t::["write_str"] α0 α1) in - M.alloc α2 - | wrapping_errors.DoubleError.Parse __self_0 => - let* __self_0 := M.alloc __self_0 in - let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref str.t := M.read (mk_str "Parse") in - let* α2 : M.Val (ref (ref core.num.error.ParseIntError.t)) := - M.alloc (borrow __self_0) in - let* α3 : ref dynamic := M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.result.Result.t unit core.fmt.Error.t := - M.call - (core.fmt.Formatter.t::["debug_tuple_field1_finish"] α0 α1 α3) in - M.alloc α4 - end in - M.read α1. + let* α0 : M.Val (core.result.Result.t unit core.fmt.Error.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | wrapping_errors.DoubleError.EmptyVec => + let* α0 : mut_ref core.fmt.Formatter.t := M.read f in + let* α1 : ref str.t := M.read (mk_str "EmptyVec") in + let* α2 : core.result.Result.t unit core.fmt.Error.t := + M.call (core.fmt.Formatter.t::["write_str"] α0 α1) in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit core.fmt.Error.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | wrapping_errors.DoubleError.Parse _ => + let γ0 := γ.["Parse.0"] in + let* __self_0 := M.alloc (borrow_mut γ0) in + let* α0 : mut_ref core.fmt.Formatter.t := M.read f in + let* α1 : ref str.t := M.read (mk_str "Parse") in + let* α2 : M.Val (ref (ref core.num.error.ParseIntError.t)) := + M.alloc (borrow __self_0) in + let* α3 : ref dynamic := M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.result.Result.t unit core.fmt.Error.t := + M.call + (core.fmt.Formatter.t::["debug_tuple_field1_finish"] + α0 + α1 + α3) in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit core.fmt.Error.t)) + ] in + M.read α0. Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; @@ -83,37 +106,54 @@ Section Impl_core_fmt_Display_for_wrapping_errors_DoubleError_t. let* self := M.alloc self in let* f := M.alloc f in let* α0 : ref wrapping_errors.DoubleError.t := M.read self in - let* α1 : wrapping_errors.DoubleError.t := M.read (deref α0) in - let* α2 : M.Val (core.result.Result.t unit core.fmt.Error.t) := - match α1 with - | wrapping_errors.DoubleError.EmptyVec => - let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref str.t := - M.read (mk_str "please use a vector with at least one element") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α4) in - let* α6 : core.result.Result.t unit core.fmt.Error.t := - M.call (core.fmt.Formatter.t::["write_fmt"] α0 α5) in - M.alloc α6 - | wrapping_errors.DoubleError.Parse => - let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref str.t := - M.read (mk_str "the provided string could not be parsed as int") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α4) in - let* α6 : core.result.Result.t unit core.fmt.Error.t := - M.call (core.fmt.Formatter.t::["write_fmt"] α0 α5) in - M.alloc α6 - end in - M.read α2. + let* α1 : M.Val (core.result.Result.t unit core.fmt.Error.t) := + match_operator + (deref α0) + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | wrapping_errors.DoubleError.EmptyVec => + let* α0 : mut_ref core.fmt.Formatter.t := M.read f in + let* α1 : ref str.t := + M.read + (mk_str "please use a vector with at least one element") in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α4) in + let* α6 : core.result.Result.t unit core.fmt.Error.t := + M.call (core.fmt.Formatter.t::["write_fmt"] α0 α5) in + M.alloc α6 + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit core.fmt.Error.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | wrapping_errors.DoubleError.Parse => + let* α0 : mut_ref core.fmt.Formatter.t := M.read f in + let* α1 : ref str.t := + M.read + (mk_str "the provided string could not be parsed as int") in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α4) in + let* α6 : core.result.Result.t unit core.fmt.Error.t := + M.call (core.fmt.Formatter.t::["write_fmt"] α0 α5) in + M.alloc α6 + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit core.fmt.Error.t)) + ] in + M.read α1. Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; @@ -145,18 +185,34 @@ Section Impl_core_error_Error_for_wrapping_errors_DoubleError_t. : M (core.option.Option.t (ref _ (* dyn *))) := let* self := M.alloc self in let* α0 : ref wrapping_errors.DoubleError.t := M.read self in - let* α1 : wrapping_errors.DoubleError.t := M.read (deref α0) in - let* α2 : M.Val (core.option.Option.t (ref dynamic)) := - match α1 with - | wrapping_errors.DoubleError.EmptyVec => M.alloc core.option.Option.None - | wrapping_errors.DoubleError.Parse e => - let* e := M.alloc e in - let* α0 : ref core.num.error.ParseIntError.t := M.read e in - let* α1 : M.Val (ref core.num.error.ParseIntError.t) := M.alloc α0 in - let* α2 : ref dynamic := M.read (pointer_coercion "Unsize" α1) in - M.alloc (core.option.Option.Some α2) - end in - M.read α2. + let* α1 : M.Val (core.option.Option.t (ref dynamic)) := + match_operator + (deref α0) + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | wrapping_errors.DoubleError.EmptyVec => + M.alloc core.option.Option.None + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t (ref dynamic))); + fun γ => + (let* α0 := M.read γ in + match α0 with + | wrapping_errors.DoubleError.Parse _ => + let γ0 := γ.["Parse.0"] in + let* e := M.alloc (borrow_mut γ0) in + let* α0 : ref core.num.error.ParseIntError.t := M.read e in + let* α1 : M.Val (ref core.num.error.ParseIntError.t) := + M.alloc α0 in + let* α2 : ref dynamic := M.read (pointer_coercion "Unsize" α1) in + M.alloc (core.option.Option.Some α2) + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t (ref dynamic))) + ] in + M.read α1. Global Instance AssociatedFunction_source : Notations.DoubleColon Self "source" := { @@ -248,31 +304,58 @@ Definition double_first wrapping_errors.DoubleError.t) (Trait := ltac:(refine _))) α2) in - let* α4 : M.Val (ref (ref str.t)) := - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - wrapping_errors.DoubleError.t := - M.read residual in - let* α1 : core.result.Result.t i32.t wrapping_errors.DoubleError.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := - core.result.Result.t i32.t wrapping_errors.DoubleError.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : ref (ref str.t) := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α4 in + wrapping_errors.DoubleError.t) + (ref (ref str.t))) := + M.alloc α3 in + let* α5 : M.Val (ref (ref str.t)) := + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + wrapping_errors.DoubleError.t := + M.read residual in + let* α1 : + core.result.Result.t i32.t wrapping_errors.DoubleError.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + i32.t + wrapping_errors.DoubleError.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : ref (ref str.t) := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val (ref (ref str.t))); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val (ref (ref str.t))) + ] in + M.copy α5 in let* parsed : M.Val i32.t := let* α0 : ref (ref str.t) := M.read first in let* α1 : ref str.t := M.read (deref α0) in @@ -290,31 +373,58 @@ Definition double_first core.result.Result.t i32.t core.num.error.ParseIntError.t) (Trait := ltac:(refine _))) α2) in - let* α4 : M.Val i32.t := - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - core.num.error.ParseIntError.t := - M.read residual in - let* α1 : core.result.Result.t i32.t wrapping_errors.DoubleError.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := - core.result.Result.t i32.t wrapping_errors.DoubleError.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : i32.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α4 in + core.num.error.ParseIntError.t) + i32.t) := + M.alloc α3 in + let* α5 : M.Val i32.t := + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + core.num.error.ParseIntError.t := + M.read residual in + let* α1 : + core.result.Result.t i32.t wrapping_errors.DoubleError.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + i32.t + wrapping_errors.DoubleError.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : i32.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val i32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val i32.t) + ] in + M.copy α5 in let* α0 : i32.t := M.read parsed in let* α1 : i32.t := BinOp.Panic.mul (Integer.of_Z 2) α0 in let* α0 : @@ -337,92 +447,115 @@ fn print(result: Result) { *) Definition print (result : ltac:(wrapping_errors.Result i32.t)) : M unit := let* result := M.alloc result in - let* α0 : core.result.Result.t i32.t wrapping_errors.DoubleError.t := - M.read result in - let* α1 : M.Val unit := - match α0 with - | core.result.Result.Ok n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "The first doubled is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "The first doubled is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.result.Result.Err e => - let* e := M.alloc e in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Error: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Error: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* α0 : core.option.Option.t (ref dynamic) := - M.call - ((core.error.Error.source - (Self := wrapping_errors.DoubleError.t) - (Trait := ltac:(refine _))) - (borrow e)) in - let* α1 : M.Val (core.option.Option.t (ref dynamic)) := M.alloc α0 in - let* α2 : M.Val bool.t := let_if core.option.Option.Some source := α1 in - let* α3 : bool.t := M.read α2 in - if α3 then - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str " Caused by: ") in - let* α1 : ref str.t := M.read (mk_str " -") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + let* α0 : core.option.Option.t (ref dynamic) := M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow source)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - else - M.alloc tt - end in - M.read α1. + ((core.error.Error.source + (Self := wrapping_errors.DoubleError.t) + (Trait := ltac:(refine _))) + (borrow e)) in + let* α1 : M.Val (core.option.Option.t (ref dynamic)) := + M.alloc α0 in + let* α2 : M.Val bool.t := + let_if core.option.Option.Some source := α1 in + let* α3 : bool.t := M.read α2 in + if α3 then + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str " Caused by: ") in + let* α1 : ref str.t := M.read (mk_str " +") in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow source)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + else + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α0. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_into_iter.v b/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_into_iter.v index 48c32e1b5..76928121e 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_into_iter.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_into_iter.v @@ -45,73 +45,107 @@ Definition main : M unit := alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val unit := - match α2 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (ref str.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - alloc.vec.into_iter.IntoIter.t - (ref str.t) - alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some name => - let* name := M.alloc name in - let* α0 : ref str.t := M.read name in - let* α1 := M.read α0 in - match α1 with - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "There is a rustacean among us! + let* α3 : + M.Val (alloc.vec.into_iter.IntoIter.t (ref str.t) alloc.alloc.Global.t) := + M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (ref str.t) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + alloc.vec.into_iter.IntoIter.t + (ref str.t) + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t (ref str.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* name := M.copy γ0 in + match_operator + name + [ + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := + M.read + (mk_str "There is a rustacean among us! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Hello ") in - let* α1 : ref str.t := M.read (mk_str " + let* α1 : M.Val (array (ref str.t)) := + M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := + M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Hello ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow name)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end - end in - M.alloc tt) - end in - M.read (use α3). + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow name)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt) : + M (M.Val unit) + ] + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α4). diff --git a/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_iter.v b/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_iter.v index 433008093..a5fef44e1 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_iter.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_iter.v @@ -46,73 +46,112 @@ Definition main : M unit := (Self := core.slice.iter.Iter.t (ref str.t)) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val unit := - match α2 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (ref (ref str.t)) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.slice.iter.Iter.t (ref str.t)) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some name => - let* name := M.alloc name in - let* α0 : ref (ref str.t) := M.read name in - let* α1 := M.read α0 in - match α1 with - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "There is a rustacean among us! + let* α3 : M.Val (core.slice.iter.Iter.t (ref str.t)) := M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (ref (ref str.t)) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.slice.iter.Iter.t (ref str.t)) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t (ref (ref str.t))) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* name := M.copy γ0 in + match_operator + name + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read + (mk_str + "There is a rustacean among us! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Hello ") in - let* α1 : ref str.t := M.read (mk_str " + let* α1 : M.Val (array (ref str.t)) := + M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := + M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Hello ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow name)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end - end in - M.alloc tt) - end in - M.pure (use α3) in + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow name)) in + let* α6 : + M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val + (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt) : + M (M.Val unit) + ] + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α4) in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "names: ") in diff --git a/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_iter_mut.v b/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_iter_mut.v index 58a9fe2eb..cda774039 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_iter_mut.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/for_and_iterators_iter_mut.v @@ -45,45 +45,73 @@ Definition main : M unit := (Self := core.slice.iter.IterMut.t (ref str.t)) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val unit := - match α2 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (mut_ref (ref str.t)) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.slice.iter.IterMut.t (ref str.t)) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some name => - let* name := M.alloc name in - let* α0 : mut_ref (ref str.t) := M.read name in - let* α1 : mut_ref (ref str.t) := M.read name in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | _ => - let* α0 : ref str.t := - M.read (mk_str "There is a rustacean among us!") in - M.alloc α0 - | _ => - let* α0 : ref str.t := M.read (mk_str "Hello") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - assign (deref α0) α4 - end in - M.alloc tt) - end in - M.pure (use α3) in + let* α3 : M.Val (core.slice.iter.IterMut.t (ref str.t)) := M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (mut_ref (ref str.t)) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.slice.iter.IterMut.t (ref str.t)) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t (mut_ref (ref str.t))) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* name := M.copy γ0 in + let* α0 : mut_ref (ref str.t) := M.read name in + let* α1 : M.Val (ref str.t) := + match_operator + name + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 : ref str.t := + M.read + (mk_str "There is a rustacean among us!") in + M.alloc α0) : + M (M.Val (ref str.t)); + fun γ => + (let* α0 : ref str.t := + M.read (mk_str "Hello") in + M.alloc α0) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + assign (deref α0) α2 + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α4) in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "names: ") in diff --git a/CoqOfRust/examples/default/examples/flow_of_control/for_and_range_completely_inclusive.v b/CoqOfRust/examples/default/examples/flow_of_control/for_and_range_completely_inclusive.v index 24eb48bda..fd476cf35 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/for_and_range_completely_inclusive.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/for_and_range_completely_inclusive.v @@ -30,120 +30,156 @@ Definition main : M unit := (Self := core.ops.range.RangeInclusive.t i32.t) (Trait := ltac:(refine _))) α0) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t i32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.RangeInclusive.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some n => - let* n := M.alloc n in - let* α0 : i32.t := M.read n in - let* α1 : i32.t := BinOp.Panic.rem α0 (Integer.of_Z 15) in - let* α2 : M.Val bool.t := - M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "fizzbuzz + let* α2 : M.Val (core.ops.range.RangeInclusive.t i32.t) := M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t i32.t := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.RangeInclusive.t i32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t i32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* n := M.copy γ0 in + let* α0 : i32.t := M.read n in + let* α1 : i32.t := BinOp.Panic.rem α0 (Integer.of_Z 15) in + let* α2 : M.Val bool.t := + M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "fizzbuzz ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt in - M.alloc tt - else - let* α0 : i32.t := M.read n in - let* α1 : i32.t := BinOp.Panic.rem α0 (Integer.of_Z 3) in - let* α2 : M.Val bool.t := - M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "fizz + let* α1 : M.Val (array (ref str.t)) := + M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt in + M.alloc tt + else + let* α0 : i32.t := M.read n in + let* α1 : i32.t := + BinOp.Panic.rem α0 (Integer.of_Z 3) in + let* α2 : M.Val bool.t := + M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "fizz ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt in - M.alloc tt - else - let* α0 : i32.t := M.read n in - let* α1 : i32.t := BinOp.Panic.rem α0 (Integer.of_Z 5) in - let* α2 : M.Val bool.t := - M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "buzz + let* α1 : M.Val (array (ref str.t)) := + M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := + M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt in + M.alloc tt + else + let* α0 : i32.t := M.read n in + let* α1 : i32.t := + BinOp.Panic.rem α0 (Integer.of_Z 5) in + let* α2 : M.Val bool.t := + M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "buzz ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt in - M.alloc tt - else - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " + let* α1 : M.Val (array (ref str.t)) := + M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := + M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt in + M.alloc tt + else + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := - M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] - (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α2). + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow n)) in + let* α6 : + M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val + (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α3). diff --git a/CoqOfRust/examples/default/examples/flow_of_control/for_and_range_inclusive_to_exclusive.v b/CoqOfRust/examples/default/examples/flow_of_control/for_and_range_inclusive_to_exclusive.v index fba288468..b4d4c2bb3 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/for_and_range_inclusive_to_exclusive.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/for_and_range_inclusive_to_exclusive.v @@ -28,120 +28,156 @@ Definition main : M unit := core.ops.range.Range.start := Integer.of_Z 1; core.ops.range.Range.end_ := Integer.of_Z 101; |}) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t i32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some n => - let* n := M.alloc n in - let* α0 : i32.t := M.read n in - let* α1 : i32.t := BinOp.Panic.rem α0 (Integer.of_Z 15) in - let* α2 : M.Val bool.t := - M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "fizzbuzz + let* α1 : M.Val (core.ops.range.Range.t i32.t) := M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t i32.t := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t i32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t i32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* n := M.copy γ0 in + let* α0 : i32.t := M.read n in + let* α1 : i32.t := BinOp.Panic.rem α0 (Integer.of_Z 15) in + let* α2 : M.Val bool.t := + M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "fizzbuzz ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt in - M.alloc tt - else - let* α0 : i32.t := M.read n in - let* α1 : i32.t := BinOp.Panic.rem α0 (Integer.of_Z 3) in - let* α2 : M.Val bool.t := - M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "fizz + let* α1 : M.Val (array (ref str.t)) := + M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt in + M.alloc tt + else + let* α0 : i32.t := M.read n in + let* α1 : i32.t := + BinOp.Panic.rem α0 (Integer.of_Z 3) in + let* α2 : M.Val bool.t := + M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "fizz ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt in - M.alloc tt - else - let* α0 : i32.t := M.read n in - let* α1 : i32.t := BinOp.Panic.rem α0 (Integer.of_Z 5) in - let* α2 : M.Val bool.t := - M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "buzz + let* α1 : M.Val (array (ref str.t)) := + M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := + M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt in + M.alloc tt + else + let* α0 : i32.t := M.read n in + let* α1 : i32.t := + BinOp.Panic.rem α0 (Integer.of_Z 5) in + let* α2 : M.Val bool.t := + M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 0)) in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "buzz ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt in - M.alloc tt - else - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " + let* α1 : M.Val (array (ref str.t)) := + M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := + M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt in + M.alloc tt + else + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := - M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] - (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α1). + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow n)) in + let* α6 : + M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val + (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α2). diff --git a/CoqOfRust/examples/default/examples/flow_of_control/if_let_dont_use_match.v b/CoqOfRust/examples/default/examples/flow_of_control/if_let_dont_use_match.v index 4e8a1345e..c777a08d1 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/if_let_dont_use_match.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/if_let_dont_use_match.v @@ -23,34 +23,44 @@ Definition main : M unit := let* optional : M.Val (core.option.Option.t i32.t) := M.alloc (core.option.Option.Some (Integer.of_Z 7)) in let* _ : M.Val unit := - let* α0 : core.option.Option.t i32.t := M.read optional in - match α0 with - | core.option.Option.Some i => - let* i := M.alloc i in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "This is a really long string and `") in - let* α1 : ref str.t := M.read (mk_str "` + match_operator + optional + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* i := M.copy γ0 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "This is a really long string and `") in + let* α1 : ref str.t := M.read (mk_str "` ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow i)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - | _ => M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow i)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => (M.alloc tt) : M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/infinite_loop.v b/CoqOfRust/examples/default/examples/flow_of_control/infinite_loop.v index 51244cc02..a8f174747 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/infinite_loop.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/infinite_loop.v @@ -46,7 +46,7 @@ Definition main : M unit := M.alloc α5 in M.alloc tt in let* α0 : M.Val unit := - loop + M.loop (let* _ : M.Val unit := let β : M.Val u32.t := count in let* α0 := M.read β in @@ -71,7 +71,7 @@ Definition main : M unit := let* α5 : unit := M.call (std.io.stdio._print α4) in M.alloc α5 in M.alloc tt in - let* _ : M.Val never.t := Continue in + let* _ : M.Val never.t := M.continue in let* α0 : M.Val unit := M.alloc tt in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in @@ -116,7 +116,7 @@ Definition main : M unit := let* α5 : unit := M.call (std.io.stdio._print α4) in M.alloc α5 in M.alloc tt in - let* _ : M.Val never.t := Break in + let* _ : M.Val never.t := M.break in let* α0 : M.Val unit := M.alloc tt in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in diff --git a/CoqOfRust/examples/default/examples/flow_of_control/loop_nesting_and_labels.v b/CoqOfRust/examples/default/examples/flow_of_control/loop_nesting_and_labels.v index eb26ac153..060f11fa7 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/loop_nesting_and_labels.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/loop_nesting_and_labels.v @@ -25,7 +25,7 @@ fn main() { (* #[allow(dead_code)] - function was ignored by the compiler *) Definition main : M unit := let* _ : M.Val unit := - loop + M.loop (let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "Entered the outer loop @@ -41,7 +41,7 @@ Definition main : M unit := M.alloc tt in let* _ : M.Val unit := let* α0 : M.Val never.t := - loop + M.loop (let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := @@ -57,7 +57,7 @@ Definition main : M unit := let* α5 : unit := M.call (std.io.stdio._print α4) in M.alloc α5 in M.alloc tt in - let* _ : M.Val never.t := Break in + let* _ : M.Val never.t := M.break in M.alloc tt) in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in diff --git a/CoqOfRust/examples/default/examples/flow_of_control/loop_returning_from_loops.v b/CoqOfRust/examples/default/examples/flow_of_control/loop_returning_from_loops.v index 4c13d8ead..affb459e5 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/loop_returning_from_loops.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/loop_returning_from_loops.v @@ -21,7 +21,7 @@ Definition main : M unit := let* counter : M.Val i32.t := M.alloc (Integer.of_Z 0) in let* result : M.Val i32.t := let* α0 : M.Val i32.t := - loop + M.loop (let* _ : M.Val unit := let β : M.Val i32.t := counter in let* α0 := M.read β in @@ -32,7 +32,7 @@ Definition main : M unit := M.alloc (BinOp.Pure.eq α0 (Integer.of_Z 10)) in let* α2 : bool.t := M.read (use α1) in if α2 then - let* _ : M.Val never.t := Break in + let* _ : M.Val never.t := M.break in let* α0 : M.Val unit := M.alloc tt in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in @@ -42,33 +42,49 @@ Definition main : M unit := M.copy α0 in let* _ : M.Val unit := let* α0 : M.Val i32.t := M.alloc (Integer.of_Z 20) in - match (borrow result, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref i32.t := M.read left_val in - let* α1 : i32.t := M.read (deref α0) in - let* α2 : ref i32.t := M.read right_val in - let* α3 : i32.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref i32.t := M.read left_val in - let* α2 : ref i32.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : M.Val ((ref i32.t) * (ref i32.t)) := + M.alloc (borrow result, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref i32.t := M.read left_val in + let* α1 : i32.t := M.read (deref α0) in + let* α2 : ref i32.t := M.read right_val in + let* α3 : i32.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref i32.t := M.read left_val in + let* α2 : ref i32.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/match.v b/CoqOfRust/examples/default/examples/flow_of_control/match.v index f85bf2180..49d4748bf 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/match.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/match.v @@ -57,70 +57,132 @@ Definition main : M unit := M.alloc α10 in M.alloc tt in let* _ : M.Val unit := - let* α0 : i32.t := M.read number in - match α0 with - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "One! + match_operator + number + [ + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "One! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | _ | _ | _ | _ | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "This is a prime + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "This is a prime ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "A teen + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "This is a prime ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Ain't special + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "This is a prime ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "This is a prime +") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "This is a prime +") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "A teen +") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Ain't special +") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit) + ] in let* boolean : M.Val bool.t := M.alloc true in let* binary : M.Val i32.t := - let* α0 : bool.t := M.read boolean in - let* α1 : M.Val i32.t := - match α0 with - | _ => M.alloc (Integer.of_Z 0) - | _ => M.alloc (Integer.of_Z 1) - end in - M.copy α1 in + let* α0 : M.Val i32.t := + match_operator + boolean + [ + fun γ => (M.alloc (Integer.of_Z 0)) : M (M.Val i32.t); + fun γ => (M.alloc (Integer.of_Z 1)) : M (M.Val i32.t) + ] in + M.copy α0 in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "") in diff --git a/CoqOfRust/examples/default/examples/flow_of_control/match_binding.v b/CoqOfRust/examples/default/examples/flow_of_control/match_binding.v index e100b4455..55a3b2f4e 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/match_binding.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/match_binding.v @@ -41,87 +41,95 @@ Definition main : M unit := M.alloc α5 in M.alloc tt in let* α0 : u32.t := M.call match_binding.age in + let* α1 : M.Val u32.t := M.alloc α0 in let* α0 : M.Val unit := - match α0 with - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "I haven't celebrated my first birthday yet + match_operator + α1 + [ + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "I haven't celebrated my first birthday yet ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | (_ as n) => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "I'm a child of age ") in - let* α1 : ref str.t := M.read (mk_str " + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* n := M.copy γ in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "I'm a child of age ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | (_ as n) => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "I'm a teen of age ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* n := M.copy γ in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "I'm a teen of age ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "I'm an old person of age ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* n := M.copy γ in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "I'm an old person of age ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/match_binding_destructure_enum_variants.v b/CoqOfRust/examples/default/examples/flow_of_control/match_binding_destructure_enum_variants.v index b7e7b13d5..0a4f12bd3 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/match_binding_destructure_enum_variants.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/match_binding_destructure_enum_variants.v @@ -26,52 +26,73 @@ fn main() { Definition main : M unit := let* α0 : core.option.Option.t u32.t := M.call match_binding_destructure_enum_variants.some_number in - let* α1 : M.Val unit := - match α0 with - | core.option.Option.Some (_ as n) => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "The Answer: ") in - let* α1 : ref str.t := M.read (mk_str "! + let* α1 : M.Val (core.option.Option.t u32.t) := M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "The Answer: ") in + let* α1 : ref str.t := M.read (mk_str "! ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.option.Option.Some n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Not interesting... ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Not interesting... ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | _ => M.alloc tt - end in - M.read α1. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow n)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => (M.alloc tt) : M (M.Val unit) + ] in + M.read α2. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_arrays_slices.v b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_arrays_slices.v index dc1fec85f..7d69b97c6 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_arrays_slices.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_arrays_slices.v @@ -44,134 +44,190 @@ fn main() { Definition main : M unit := let* array : M.Val (array i32.t) := M.alloc [ Integer.of_Z 1; Integer.of_Z (-2); Integer.of_Z 6 ] in - let* α0 : array i32.t := M.read array in let* α0 : M.Val unit := - match α0 with - | [_; second; third] => - let* second := M.alloc second in - let* third := M.alloc third in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "array[0] = 0, array[1] = ") in - let* α1 : ref str.t := M.read (mk_str ", array[2] = ") in - let* α2 : ref str.t := M.read (mk_str " + match_operator + array + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | [_; _; _] => + let γ0 := γ.["[0]"] in + let γ1 := γ.["[1]"] in + let γ2 := γ.["[2]"] in + let* second := M.copy γ1 in + let* third := M.copy γ2 in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "array[0] = 0, array[1] = ") in + let* α1 : ref str.t := M.read (mk_str ", array[2] = ") in + let* α2 : ref str.t := M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow second)) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow third)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt - | [_; _; third] => - let* third := M.alloc third in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "array[0] = 1, array[2] = ") in - let* α1 : ref str.t := M.read (mk_str " and array[1] was ignored + let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow second)) in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow third)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | [_; _; _] => + let γ0 := γ.["[0]"] in + let γ1 := γ.["[1]"] in + let γ2 := γ.["[2]"] in + let* third := M.copy γ2 in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "array[0] = 1, array[2] = ") in + let* α1 : ref str.t := + M.read (mk_str " and array[1] was ignored ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow third)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | (_:: second:: _) => - let* second := M.alloc second in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "array[0] = -1, array[1] = ") in - let* α1 : ref str.t := - M.read (mk_str " and all the other ones were ignored + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow third)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_:: _:: _) => + let γ0 := γ.["[0]"] in + let γ1 := γ.["[1]"] in + let γ := γ.["[2].slice"] in + let* second := M.copy γ1 in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "array[0] = -1, array[1] = ") in + let* α1 : ref str.t := + M.read (mk_str " and all the other ones were ignored ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow second)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | (_:: second:: (_ as tail)) => - let* second := M.alloc second in - let* tail := M.alloc tail in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "array[0] = 3, array[1] = ") in - let* α1 : ref str.t := - M.read (mk_str " and the other elements were ") in - let* α2 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow second)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_:: _:: _) => + let γ0 := γ.["[0]"] in + let γ1 := γ.["[1]"] in + let γ := γ.["[2].slice"] in + let* second := M.copy γ1 in + let* tail := M.copy γ in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "array[0] = 3, array[1] = ") in + let* α1 : ref str.t := + M.read (mk_str " and the other elements were ") in + let* α2 : ref str.t := M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow second)) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow tail)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "array[0] = ") in - let* α1 : ref str.t := M.read (mk_str ", middle = ") in - let* α2 : ref str.t := M.read (mk_str ", array[2] = ") in - let* α3 : ref str.t := M.read (mk_str " + let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow second)) in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow tail)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "array[0] = ") in + let* α1 : ref str.t := M.read (mk_str ", middle = ") in + let* α2 : ref str.t := M.read (mk_str ", array[2] = ") in + let* α3 : ref str.t := M.read (mk_str " ") in - let* α4 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2; α3 ] in - let* α5 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α4) in - let* α6 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α5) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow first)) in - let* α8 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow middle)) in - let* α9 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow last)) in - let* α10 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7; α8; α9 ] in - let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α10) in - let* α12 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α11) in - let* α13 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in - let* α14 : unit := M.call (std.io.stdio._print α13) in - M.alloc α14 in - M.alloc tt - end in + let* α4 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2; α3 ] in + let* α5 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α4) in + let* α6 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α5) in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow first)) in + let* α8 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow middle)) in + let* α9 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow last)) in + let* α10 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7; α8; α9 ] in + let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α10) in + let* α12 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α11) in + let* α13 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in + let* α14 : unit := M.call (std.io.stdio._print α13) in + M.alloc α14 in + M.alloc tt) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_enums.v b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_enums.v index 3957bea03..d58913515 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_enums.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_enums.v @@ -197,206 +197,284 @@ Definition main : M unit := let* α5 : unit := M.call (std.io.stdio._print α4) in M.alloc α5 in M.alloc tt in - let* α0 : match_destructuring_enums.Color.t := M.read color in let* α0 : M.Val unit := - match α0 with - | match_destructuring_enums.Color.Red => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "The color is Red! + match_operator + color + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_destructuring_enums.Color.Red => + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "The color is Red! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | match_destructuring_enums.Color.Blue => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "The color is Blue! + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_destructuring_enums.Color.Blue => + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "The color is Blue! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | match_destructuring_enums.Color.Green => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "The color is Green! + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_destructuring_enums.Color.Green => + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "The color is Green! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | match_destructuring_enums.Color.RGB r g b => - let* r := M.alloc r in - let* g := M.alloc g in - let* b := M.alloc b in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Red: ") in - let* α1 : ref str.t := M.read (mk_str ", green: ") in - let* α2 : ref str.t := M.read (mk_str ", and blue: ") in - let* α3 : ref str.t := M.read (mk_str "! + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_destructuring_enums.Color.RGB _ _ _ => + let γ0 := γ.["RGB.0"] in + let γ1 := γ.["RGB.1"] in + let γ2 := γ.["RGB.2"] in + let* r := M.copy γ0 in + let* g := M.copy γ1 in + let* b := M.copy γ2 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Red: ") in + let* α1 : ref str.t := M.read (mk_str ", green: ") in + let* α2 : ref str.t := M.read (mk_str ", and blue: ") in + let* α3 : ref str.t := M.read (mk_str "! ") in - let* α4 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2; α3 ] in - let* α5 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α4) in - let* α6 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α5) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow r)) in - let* α8 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow g)) in - let* α9 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow b)) in - let* α10 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7; α8; α9 ] in - let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α10) in - let* α12 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α11) in - let* α13 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in - let* α14 : unit := M.call (std.io.stdio._print α13) in - M.alloc α14 in - M.alloc tt - | match_destructuring_enums.Color.HSV h s v => - let* h := M.alloc h in - let* s := M.alloc s in - let* v := M.alloc v in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Hue: ") in - let* α1 : ref str.t := M.read (mk_str ", saturation: ") in - let* α2 : ref str.t := M.read (mk_str ", value: ") in - let* α3 : ref str.t := M.read (mk_str "! + let* α4 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2; α3 ] in + let* α5 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α4) in + let* α6 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α5) in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow r)) in + let* α8 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow g)) in + let* α9 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow b)) in + let* α10 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7; α8; α9 ] in + let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α10) in + let* α12 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α11) in + let* α13 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in + let* α14 : unit := M.call (std.io.stdio._print α13) in + M.alloc α14 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_destructuring_enums.Color.HSV _ _ _ => + let γ0 := γ.["HSV.0"] in + let γ1 := γ.["HSV.1"] in + let γ2 := γ.["HSV.2"] in + let* h := M.copy γ0 in + let* s := M.copy γ1 in + let* v := M.copy γ2 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Hue: ") in + let* α1 : ref str.t := M.read (mk_str ", saturation: ") in + let* α2 : ref str.t := M.read (mk_str ", value: ") in + let* α3 : ref str.t := M.read (mk_str "! ") in - let* α4 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2; α3 ] in - let* α5 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α4) in - let* α6 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α5) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow h)) in - let* α8 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in - let* α9 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow v)) in - let* α10 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7; α8; α9 ] in - let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α10) in - let* α12 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α11) in - let* α13 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in - let* α14 : unit := M.call (std.io.stdio._print α13) in - M.alloc α14 in - M.alloc tt - | match_destructuring_enums.Color.HSL h s l => - let* h := M.alloc h in - let* s := M.alloc s in - let* l := M.alloc l in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Hue: ") in - let* α1 : ref str.t := M.read (mk_str ", saturation: ") in - let* α2 : ref str.t := M.read (mk_str ", lightness: ") in - let* α3 : ref str.t := M.read (mk_str "! + let* α4 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2; α3 ] in + let* α5 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α4) in + let* α6 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α5) in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow h)) in + let* α8 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in + let* α9 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow v)) in + let* α10 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7; α8; α9 ] in + let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α10) in + let* α12 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α11) in + let* α13 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in + let* α14 : unit := M.call (std.io.stdio._print α13) in + M.alloc α14 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_destructuring_enums.Color.HSL _ _ _ => + let γ0 := γ.["HSL.0"] in + let γ1 := γ.["HSL.1"] in + let γ2 := γ.["HSL.2"] in + let* h := M.copy γ0 in + let* s := M.copy γ1 in + let* l := M.copy γ2 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Hue: ") in + let* α1 : ref str.t := M.read (mk_str ", saturation: ") in + let* α2 : ref str.t := M.read (mk_str ", lightness: ") in + let* α3 : ref str.t := M.read (mk_str "! ") in - let* α4 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2; α3 ] in - let* α5 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α4) in - let* α6 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α5) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow h)) in - let* α8 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in - let* α9 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow l)) in - let* α10 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7; α8; α9 ] in - let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α10) in - let* α12 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α11) in - let* α13 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in - let* α14 : unit := M.call (std.io.stdio._print α13) in - M.alloc α14 in - M.alloc tt - | match_destructuring_enums.Color.CMY c m y => - let* c := M.alloc c in - let* m := M.alloc m in - let* y := M.alloc y in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Cyan: ") in - let* α1 : ref str.t := M.read (mk_str ", magenta: ") in - let* α2 : ref str.t := M.read (mk_str ", yellow: ") in - let* α3 : ref str.t := M.read (mk_str "! + let* α4 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2; α3 ] in + let* α5 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α4) in + let* α6 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α5) in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow h)) in + let* α8 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in + let* α9 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow l)) in + let* α10 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7; α8; α9 ] in + let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α10) in + let* α12 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α11) in + let* α13 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in + let* α14 : unit := M.call (std.io.stdio._print α13) in + M.alloc α14 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_destructuring_enums.Color.CMY _ _ _ => + let γ0 := γ.["CMY.0"] in + let γ1 := γ.["CMY.1"] in + let γ2 := γ.["CMY.2"] in + let* c := M.copy γ0 in + let* m := M.copy γ1 in + let* y := M.copy γ2 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Cyan: ") in + let* α1 : ref str.t := M.read (mk_str ", magenta: ") in + let* α2 : ref str.t := M.read (mk_str ", yellow: ") in + let* α3 : ref str.t := M.read (mk_str "! ") in - let* α4 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2; α3 ] in - let* α5 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α4) in - let* α6 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α5) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow c)) in - let* α8 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow m)) in - let* α9 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow y)) in - let* α10 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7; α8; α9 ] in - let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α10) in - let* α12 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α11) in - let* α13 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in - let* α14 : unit := M.call (std.io.stdio._print α13) in - M.alloc α14 in - M.alloc tt - | match_destructuring_enums.Color.CMYK c m y k => - let* c := M.alloc c in - let* m := M.alloc m in - let* y := M.alloc y in - let* k := M.alloc k in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Cyan: ") in - let* α1 : ref str.t := M.read (mk_str ", magenta: ") in - let* α2 : ref str.t := M.read (mk_str ", yellow: ") in - let* α3 : ref str.t := M.read (mk_str ", key (black): ") in - let* α4 : ref str.t := M.read (mk_str "! + let* α4 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2; α3 ] in + let* α5 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α4) in + let* α6 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α5) in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow c)) in + let* α8 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow m)) in + let* α9 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow y)) in + let* α10 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7; α8; α9 ] in + let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α10) in + let* α12 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α11) in + let* α13 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in + let* α14 : unit := M.call (std.io.stdio._print α13) in + M.alloc α14 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_destructuring_enums.Color.CMYK _ _ _ _ => + let γ0 := γ.["CMYK.0"] in + let γ1 := γ.["CMYK.1"] in + let γ2 := γ.["CMYK.2"] in + let γ3 := γ.["CMYK.3"] in + let* c := M.copy γ0 in + let* m := M.copy γ1 in + let* y := M.copy γ2 in + let* k := M.copy γ3 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Cyan: ") in + let* α1 : ref str.t := M.read (mk_str ", magenta: ") in + let* α2 : ref str.t := M.read (mk_str ", yellow: ") in + let* α3 : ref str.t := M.read (mk_str ", key (black): ") in + let* α4 : ref str.t := M.read (mk_str "! ") in - let* α5 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2; α3; α4 ] in - let* α6 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α5) in - let* α7 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α6) in - let* α8 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow c)) in - let* α9 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow m)) in - let* α10 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow y)) in - let* α11 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow k)) in - let* α12 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α8; α9; α10; α11 ] in - let* α13 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α12) in - let* α14 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α13) in - let* α15 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α7 α14) in - let* α16 : unit := M.call (std.io.stdio._print α15) in - M.alloc α16 in - M.alloc tt - end in + let* α5 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2; α3; α4 ] in + let* α6 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α5) in + let* α7 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α6) in + let* α8 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow c)) in + let* α9 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow m)) in + let* α10 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow y)) in + let* α11 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow k)) in + let* α12 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α8; α9; α10; α11 ] in + let* α13 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α12) in + let* α14 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α13) in + let* α15 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α7 α14) in + let* α16 : unit := M.call (std.io.stdio._print α15) in + M.alloc α16 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_pointers_ref.v b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_pointers_ref.v index 880055ce5..dc8016055 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_pointers_ref.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_pointers_ref.v @@ -59,123 +59,138 @@ Definition main : M unit := let* α0 : M.Val i32.t := M.alloc (Integer.of_Z 4) in M.alloc (borrow α0) in let* _ : M.Val unit := - let* α0 : ref i32.t := M.read reference in - match α0 with - | val => - let* val := M.alloc val in - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "Got a value via destructuring: ") in - let* α1 : ref str.t := M.read (mk_str " + match_operator + reference + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* val := M.copy γ in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Got a value via destructuring: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow val)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow val)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : ref i32.t := M.read reference in - let* α1 : i32.t := M.read (deref α0) in - match α1 with - | val => - let* val := M.alloc val in - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "Got a value via dereferencing: ") in - let* α1 : ref str.t := M.read (mk_str " + match_operator + (deref α0) + [ + fun γ => + (let* val := M.copy γ in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Got a value via dereferencing: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow val)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow val)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt) : + M (M.Val unit) + ] in let* _not_a_reference : M.Val i32.t := M.alloc (Integer.of_Z 3) in let* _is_a_reference : M.Val i32.t := M.alloc (Integer.of_Z 3) in let* value : M.Val i32.t := M.alloc (Integer.of_Z 5) in let* mut_value : M.Val i32.t := M.alloc (Integer.of_Z 6) in let* _ : M.Val unit := - let* α0 : i32.t := M.read value in - match α0 with - | r => - let* r := M.alloc r in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Got a reference to a value: ") in - let* α1 : ref str.t := M.read (mk_str " + match_operator + value + [ + fun γ => + (let* r := M.alloc (borrow_mut γ) in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Got a reference to a value: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow r)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - let* α0 : i32.t := M.read mut_value in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow r)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt) : + M (M.Val unit) + ] in let* α0 : M.Val unit := - match α0 with - | m => - let* m := M.alloc m in - let* _ : M.Val unit := - let* β : M.Val i32.t := - let* α0 : mut_ref i32.t := M.read m in - M.pure (deref α0) in - let* α0 := M.read β in - let* α1 := BinOp.Panic.add α0 (Integer.of_Z 10) in - assign β α1 in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "We added 10. `mut_value`: ") in - let* α1 : ref str.t := M.read (mk_str " + match_operator + mut_value + [ + fun γ => + (let* m := M.alloc (borrow γ) in + let* _ : M.Val unit := + let* β : M.Val i32.t := + let* α0 : mut_ref i32.t := M.read m in + M.pure (deref α0) in + let* α0 := M.read β in + let* α1 := BinOp.Panic.add α0 (Integer.of_Z 10) in + assign β α1 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "We added 10. `mut_value`: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow m)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow m)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_structs.v b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_structs.v index 22ab7c83a..cca5b6ec5 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_structs.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_structs.v @@ -52,88 +52,123 @@ Definition main : M unit := match_destructuring_structs.Foo.x := (Integer.of_Z 1, Integer.of_Z 2); match_destructuring_structs.Foo.y := Integer.of_Z 3; |} in - let* α0 : match_destructuring_structs.Foo.t := M.read foo in let* α0 : M.Val unit := - match α0 with - | - {| - match_destructuring_structs.Foo.x := (_, b); - match_destructuring_structs.Foo.y := y; - |} - => - let* b := M.alloc b in - let* y := M.alloc y in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "First of x is 1, b = ") in - let* α1 : ref str.t := M.read (mk_str ", y = ") in - let* α2 : ref str.t := M.read (mk_str " + match_operator + foo + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | + {| + match_destructuring_structs.Foo.x := _; + match_destructuring_structs.Foo.y := _; + |} + => + let γ0 := γ.["Foo.x"] in + let γ1 := γ.["Foo.y"] in + let* α0 := M.read γ0 in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ0 in + let γ1 := Tuple.Access.right γ0 in + let* b := M.copy γ1 in + let* y := M.copy γ1 in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "First of x is 1, b = ") in + let* α1 : ref str.t := M.read (mk_str ", y = ") in + let* α2 : ref str.t := M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow b)) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow y)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt - | - {| - match_destructuring_structs.Foo.y := _; - match_destructuring_structs.Foo.x := i; - |} - => - let* i := M.alloc i in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "y is 2, i = ") in - let* α1 : ref str.t := M.read (mk_str " + let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow b)) in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow y)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt + end + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | + {| + match_destructuring_structs.Foo.y := _; + match_destructuring_structs.Foo.x := _; + |} + => + let γ0 := γ.["Foo.y"] in + let γ1 := γ.["Foo.x"] in + let* i := M.copy γ1 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "y is 2, i = ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow i)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | {| match_destructuring_structs.Foo.y := y; |} => - let* y := M.alloc y in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "y = ") in - let* α1 : ref str.t := M.read (mk_str ", we don't care about x + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow i)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | {| match_destructuring_structs.Foo.y := _; |} => + let γ0 := γ.["Foo.y"] in + let* y := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "y = ") in + let* α1 : ref str.t := + M.read (mk_str ", we don't care about x ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow y)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow y)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_tuples.v b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_tuples.v index 7c44508c5..f4b6bab73 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_tuples.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_tuples.v @@ -45,92 +45,126 @@ Definition main : M unit := let* α10 : unit := M.call (std.io.stdio._print α9) in M.alloc α10 in M.alloc tt in - let* α0 : (i32.t * i32.t) * i32.t := M.read triple in let* α0 : M.Val unit := - match α0 with - | (_, y, z) => - let* y := M.alloc y in - let* z := M.alloc z in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "First is `0`, `y` is ") in - let* α1 : ref str.t := M.read (mk_str ", and `z` is ") in - let* α2 : ref str.t := M.read (mk_str " + match_operator + triple + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _, _) => + let γ0 := Tuple.Access.left (Tuple.Access.left γ) in + let γ1 := Tuple.Access.right (Tuple.Access.left γ) in + let γ2 := Tuple.Access.right γ in + let* y := M.copy γ1 in + let* z := M.copy γ2 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "First is `0`, `y` is ") in + let* α1 : ref str.t := M.read (mk_str ", and `z` is ") in + let* α2 : ref str.t := M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow y)) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow z)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt - | (_) => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "First is `1` and the rest doesn't matter + let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow y)) in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow z)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_) => + let γ0 := γ in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "First is `1` and the rest doesn't matter ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | (_) => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "last is `2` and the rest doesn't matter + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_) => + let γ0 := γ in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "last is `2` and the rest doesn't matter ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | (_, _) => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read - (mk_str - "First is `3`, last is `4`, and the rest doesn't matter + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read + (mk_str + "First is `3`, last is `4`, and the rest doesn't matter ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "It doesn't matter what they are + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + end) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "It doesn't matter what they are ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_tuples_fixed.v b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_tuples_fixed.v index 990be1a8b..735e0d478 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_tuples_fixed.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/match_destructuring_tuples_fixed.v @@ -45,92 +45,129 @@ Definition main : M unit := let* α10 : unit := M.call (std.io.stdio._print α9) in M.alloc α10 in M.alloc tt in - let* α0 : (i32.t * i32.t) * i32.t := M.read triple in let* α0 : M.Val unit := - match α0 with - | (_, y, z) => - let* y := M.alloc y in - let* z := M.alloc z in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "First is `0`, `y` is ") in - let* α1 : ref str.t := M.read (mk_str ", and `z` is ") in - let* α2 : ref str.t := M.read (mk_str " + match_operator + triple + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _, _) => + let γ0 := Tuple.Access.left (Tuple.Access.left γ) in + let γ1 := Tuple.Access.right (Tuple.Access.left γ) in + let γ2 := Tuple.Access.right γ in + let* y := M.copy γ1 in + let* z := M.copy γ2 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "First is `0`, `y` is ") in + let* α1 : ref str.t := M.read (mk_str ", and `z` is ") in + let* α2 : ref str.t := M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow y)) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow z)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt - | (_, _, _) => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "First is `1` and the rest doesn't matter + let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow y)) in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow z)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _, _) => + let γ0 := Tuple.Access.left (Tuple.Access.left γ) in + let γ1 := Tuple.Access.right (Tuple.Access.left γ) in + let γ2 := Tuple.Access.right γ in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "First is `1` and the rest doesn't matter ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | (_) => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "last is `2` and the rest doesn't matter + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_) => + let γ0 := γ in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "last is `2` and the rest doesn't matter ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | (_, _, _) => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read - (mk_str - "First is `3`, last is `4`, and the rest doesn't matter + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _, _) => + let γ0 := Tuple.Access.left (Tuple.Access.left γ) in + let γ1 := Tuple.Access.right (Tuple.Access.left γ) in + let γ2 := Tuple.Access.right γ in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read + (mk_str + "First is `3`, last is `4`, and the rest doesn't matter ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "It doesn't matter what they are + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + end) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "It doesn't matter what they are ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/match_guards.v b/CoqOfRust/examples/default/examples/flow_of_control/match_guards.v index 5346db87b..92481c25a 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/match_guards.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/match_guards.v @@ -42,96 +42,135 @@ fn main() { Definition main : M unit := let* temperature : M.Val match_guards.Temperature.t := M.alloc (match_guards.Temperature.Celsius (Integer.of_Z 35)) in - let* α0 : match_guards.Temperature.t := M.read temperature in let* α0 : M.Val unit := - match α0 with - | match_guards.Temperature.Celsius t => - let* t := M.alloc t in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str "C is above 30 Celsius + match_operator + temperature + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_guards.Temperature.Celsius _ => + let γ0 := γ.["Celsius.0"] in + let* t := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str "C is above 30 Celsius ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow t)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | match_guards.Temperature.Celsius t => - let* t := M.alloc t in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str "C is below 30 Celsius + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow t)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_guards.Temperature.Celsius _ => + let γ0 := γ.["Celsius.0"] in + let* t := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str "C is below 30 Celsius ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow t)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | match_guards.Temperature.Fahrenheit t => - let* t := M.alloc t in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str "F is above 86 Fahrenheit + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow t)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_guards.Temperature.Fahrenheit _ => + let γ0 := γ.["Fahrenheit.0"] in + let* t := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := + M.read (mk_str "F is above 86 Fahrenheit ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow t)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | match_guards.Temperature.Fahrenheit t => - let* t := M.alloc t in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str "F is below 86 Fahrenheit + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow t)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | match_guards.Temperature.Fahrenheit _ => + let γ0 := γ.["Fahrenheit.0"] in + let* t := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := + M.read (mk_str "F is below 86 Fahrenheit ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow t)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow t)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/match_guards_unreachable.v b/CoqOfRust/examples/default/examples/flow_of_control/match_guards_unreachable.v index 344ca2f03..17c28a94c 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/match_guards_unreachable.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/match_guards_unreachable.v @@ -16,43 +16,47 @@ fn main() { (* #[allow(dead_code)] - function was ignored by the compiler *) Definition main : M unit := let* number : M.Val u8.t := M.alloc (Integer.of_Z 4) in - let* α0 : u8.t := M.read number in let* α0 : M.Val unit := - match α0 with - | i => - let* i := M.alloc i in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Zero + match_operator + number + [ + fun γ => + (let* i := M.copy γ in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Zero ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | i => - let* i := M.alloc i in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Greater than zero + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* i := M.copy γ in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Greater than zero ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | _ => - let* α0 : never.t := - M.call - (core.panicking.unreachable_display - (borrow (mk_str "Should never happen."))) in - let* α1 : unit := never_to_any α0 in - M.alloc α1 - end in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* α0 : never.t := + M.call + (core.panicking.unreachable_display + (borrow (mk_str "Should never happen."))) in + let* α1 : unit := never_to_any α0 in + M.alloc α1) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/flow_of_control/while.v b/CoqOfRust/examples/default/examples/flow_of_control/while.v index 73a96d2e8..a0c741bc7 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/while.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/while.v @@ -27,7 +27,7 @@ fn main() { Definition main : M unit := let* n : M.Val i32.t := M.alloc (Integer.of_Z 1) in let* α0 : M.Val unit := - loop + M.loop (let* α0 : i32.t := M.read n in let* α1 : M.Val bool.t := M.alloc (BinOp.Pure.lt α0 (Integer.of_Z 101)) in let* α2 : bool.t := M.read (use α1) in @@ -132,7 +132,7 @@ Definition main : M unit := M.alloc tt else let* _ : M.Val unit := - let* α0 : M.Val never.t := Break in + let* α0 : M.Val never.t := M.break in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in M.alloc α2 in diff --git a/CoqOfRust/examples/default/examples/flow_of_control/while_let.v b/CoqOfRust/examples/default/examples/flow_of_control/while_let.v index f427a1aa3..95e5611cd 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/while_let.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/while_let.v @@ -28,7 +28,7 @@ Definition main : M unit := let* optional : M.Val (core.option.Option.t i32.t) := M.alloc (core.option.Option.Some (Integer.of_Z 0)) in let* α0 : M.Val unit := - loop + M.loop (let* α0 : M.Val bool.t := let_if core.option.Option.Some i := optional in let* α1 : bool.t := M.read α0 in if α1 then @@ -83,7 +83,7 @@ Definition main : M unit := M.alloc tt else let* _ : M.Val unit := - let* α0 : M.Val never.t := Break in + let* α0 : M.Val never.t := M.break in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in M.alloc α2 in diff --git a/CoqOfRust/examples/default/examples/flow_of_control/while_let_match_is_weird.v b/CoqOfRust/examples/default/examples/flow_of_control/while_let_match_is_weird.v index 585e79585..8d33da637 100644 --- a/CoqOfRust/examples/default/examples/flow_of_control/while_let_match_is_weird.v +++ b/CoqOfRust/examples/default/examples/flow_of_control/while_let_match_is_weird.v @@ -33,65 +33,78 @@ Definition main : M unit := let* optional : M.Val (core.option.Option.t i32.t) := M.alloc (core.option.Option.Some (Integer.of_Z 0)) in let* α0 : M.Val unit := - loop - (let* α0 : core.option.Option.t i32.t := M.read optional in - match α0 with - | core.option.Option.Some i => - let* i := M.alloc i in - let* α0 : i32.t := M.read i in - let* α1 : M.Val bool.t := M.alloc (BinOp.Pure.gt α0 (Integer.of_Z 9)) in - let* α2 : bool.t := M.read (use α1) in - if α2 then - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Greater than 9, quit! + M.loop + (match_operator + optional + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* i := M.copy γ0 in + let* α0 : i32.t := M.read i in + let* α1 : M.Val bool.t := + M.alloc (BinOp.Pure.gt α0 (Integer.of_Z 9)) in + let* α2 : bool.t := M.read (use α1) in + if α2 then + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Greater than 9, quit! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt in - let* _ : M.Val unit := assign optional core.option.Option.None in - M.alloc tt - else - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "`i` is `") in - let* α1 : ref str.t := M.read (mk_str "`. Try again. + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt in + let* _ : M.Val unit := + assign optional core.option.Option.None in + M.alloc tt + else + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "`i` is `") in + let* α1 : ref str.t := M.read (mk_str "`. Try again. ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow i)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* _ : M.Val unit := - let* α0 : i32.t := M.read i in - let* α1 : i32.t := BinOp.Panic.add α0 (Integer.of_Z 1) in - assign optional (core.option.Option.Some α1) in - M.alloc tt - | _ => - let* _ : M.Val never.t := Break in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - end) in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow i)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + let* _ : M.Val unit := + let* α0 : i32.t := M.read i in + let* α1 : i32.t := BinOp.Panic.add α0 (Integer.of_Z 1) in + assign optional (core.option.Option.Some α1) in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* _ : M.Val never.t := M.break in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2) : + M (M.Val unit) + ]) in M.read α0. diff --git a/CoqOfRust/examples/default/examples/functions/associated_functions_and_methods.v b/CoqOfRust/examples/default/examples/functions/associated_functions_and_methods.v index ff0bcefb3..7359e565f 100644 --- a/CoqOfRust/examples/default/examples/functions/associated_functions_and_methods.v +++ b/CoqOfRust/examples/default/examples/functions/associated_functions_and_methods.v @@ -131,36 +131,58 @@ Section Impl_associated_functions_and_methods_Rectangle_t. *) Definition area (self : ref Self) : M f64.t := let* self := M.alloc self in - let* '{| - associated_functions_and_methods.Point.x := x1; - associated_functions_and_methods.Point.y := y1; - |} : - associated_functions_and_methods.Point.t := - let* α0 : ref associated_functions_and_methods.Rectangle.t := - M.read self in - M.read (deref α0).["p1"] in - let* x1 := M.alloc x1 in - let* y1 := M.alloc y1 in - let* '{| - associated_functions_and_methods.Point.x := x2; - associated_functions_and_methods.Point.y := y2; - |} : - associated_functions_and_methods.Point.t := - let* α0 : ref associated_functions_and_methods.Rectangle.t := - M.read self in - M.read (deref α0).["p2"] in - let* x2 := M.alloc x2 in - let* y2 := M.alloc y2 in - let* α0 : f64.t := M.read x1 in - let* α1 : f64.t := M.read x2 in - let* α2 : f64.t := BinOp.Panic.sub α0 α1 in - let* α3 : f64.t := M.read y1 in - let* α4 : f64.t := M.read y2 in - let* α5 : f64.t := BinOp.Panic.sub α3 α4 in - let* α6 : f64.t := BinOp.Panic.mul α2 α5 in - let* α7 : f64.t := M.call (f64.t::["abs"] α6) in - let* α0 : M.Val f64.t := M.alloc α7 in - M.read α0. + let* α0 : ref associated_functions_and_methods.Rectangle.t := M.read self in + let* α1 : M.Val f64.t := + match_operator + (deref α0).["p1"] + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | + {| + associated_functions_and_methods.Point.x := _; + associated_functions_and_methods.Point.y := _; + |} + => + let γ0 := γ.["Point.x"] in + let γ1 := γ.["Point.y"] in + let* x1 := M.copy γ0 in + let* y1 := M.copy γ1 in + let* α0 : ref associated_functions_and_methods.Rectangle.t := + M.read self in + match_operator + (deref α0).["p2"] + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | + {| + associated_functions_and_methods.Point.x := _; + associated_functions_and_methods.Point.y := _; + |} + => + let γ0 := γ.["Point.x"] in + let γ1 := γ.["Point.y"] in + let* x2 := M.copy γ0 in + let* y2 := M.copy γ1 in + let* α0 : f64.t := M.read x1 in + let* α1 : f64.t := M.read x2 in + let* α2 : f64.t := BinOp.Panic.sub α0 α1 in + let* α3 : f64.t := M.read y1 in + let* α4 : f64.t := M.read y2 in + let* α5 : f64.t := BinOp.Panic.sub α3 α4 in + let* α6 : f64.t := BinOp.Panic.mul α2 α5 in + let* α7 : f64.t := M.call (f64.t::["abs"] α6) in + M.alloc α7 + end) : + M (M.Val f64.t) + ] + end) : + M (M.Val f64.t) + ] in + M.read α1. Global Instance AssociatedFunction_area : Notations.DoubleColon Self "area" := { @@ -177,39 +199,61 @@ Section Impl_associated_functions_and_methods_Rectangle_t. *) Definition perimeter (self : ref Self) : M f64.t := let* self := M.alloc self in - let* '{| - associated_functions_and_methods.Point.x := x1; - associated_functions_and_methods.Point.y := y1; - |} : - associated_functions_and_methods.Point.t := - let* α0 : ref associated_functions_and_methods.Rectangle.t := - M.read self in - M.read (deref α0).["p1"] in - let* x1 := M.alloc x1 in - let* y1 := M.alloc y1 in - let* '{| - associated_functions_and_methods.Point.x := x2; - associated_functions_and_methods.Point.y := y2; - |} : - associated_functions_and_methods.Point.t := - let* α0 : ref associated_functions_and_methods.Rectangle.t := - M.read self in - M.read (deref α0).["p2"] in - let* x2 := M.alloc x2 in - let* y2 := M.alloc y2 in - let* α0 : f64.t := M.read UnsupportedLiteral in - let* α1 : f64.t := M.read x1 in - let* α2 : f64.t := M.read x2 in - let* α3 : f64.t := BinOp.Panic.sub α1 α2 in - let* α4 : f64.t := M.call (f64.t::["abs"] α3) in - let* α5 : f64.t := M.read y1 in - let* α6 : f64.t := M.read y2 in - let* α7 : f64.t := BinOp.Panic.sub α5 α6 in - let* α8 : f64.t := M.call (f64.t::["abs"] α7) in - let* α9 : f64.t := BinOp.Panic.add α4 α8 in - let* α10 : f64.t := BinOp.Panic.mul α0 α9 in - let* α0 : M.Val f64.t := M.alloc α10 in - M.read α0. + let* α0 : ref associated_functions_and_methods.Rectangle.t := M.read self in + let* α1 : M.Val f64.t := + match_operator + (deref α0).["p1"] + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | + {| + associated_functions_and_methods.Point.x := _; + associated_functions_and_methods.Point.y := _; + |} + => + let γ0 := γ.["Point.x"] in + let γ1 := γ.["Point.y"] in + let* x1 := M.copy γ0 in + let* y1 := M.copy γ1 in + let* α0 : ref associated_functions_and_methods.Rectangle.t := + M.read self in + match_operator + (deref α0).["p2"] + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | + {| + associated_functions_and_methods.Point.x := _; + associated_functions_and_methods.Point.y := _; + |} + => + let γ0 := γ.["Point.x"] in + let γ1 := γ.["Point.y"] in + let* x2 := M.copy γ0 in + let* y2 := M.copy γ1 in + let* α0 : f64.t := M.read UnsupportedLiteral in + let* α1 : f64.t := M.read x1 in + let* α2 : f64.t := M.read x2 in + let* α3 : f64.t := BinOp.Panic.sub α1 α2 in + let* α4 : f64.t := M.call (f64.t::["abs"] α3) in + let* α5 : f64.t := M.read y1 in + let* α6 : f64.t := M.read y2 in + let* α7 : f64.t := BinOp.Panic.sub α5 α6 in + let* α8 : f64.t := M.call (f64.t::["abs"] α7) in + let* α9 : f64.t := BinOp.Panic.add α4 α8 in + let* α10 : f64.t := BinOp.Panic.mul α0 α9 in + M.alloc α10 + end) : + M (M.Val f64.t) + ] + end) : + M (M.Val f64.t) + ] in + M.read α1. Global Instance AssociatedFunction_perimeter : Notations.DoubleColon Self "perimeter" := { @@ -309,36 +353,53 @@ Section Impl_associated_functions_and_methods_Pair_t. *) Definition destroy (self : Self) : M unit := let* self := M.alloc self in - let* 'associated_functions_and_methods.Pair.Build_t first second : - associated_functions_and_methods.Pair.t := - M.read self in - let* first := M.alloc first in - let* second := M.alloc second in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Destroying Pair(") in - let* α1 : ref str.t := M.read (mk_str ", ") in - let* α2 : ref str.t := M.read (mk_str ") + let* α0 : M.Val unit := + match_operator + self + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | associated_functions_and_methods.Pair.Build_t _ _ => + let γ0 := γ.["Pair.0"] in + let γ1 := γ.["Pair.1"] in + let* first := M.copy γ0 in + let* second := M.copy γ1 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Destroying Pair(") in + let* α1 : ref str.t := M.read (mk_str ", ") in + let* α2 : ref str.t := M.read (mk_str ") ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow first)) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow second)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in + let* α3 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow first)) in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow second)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + M.alloc tt + end) : + M (M.Val unit) + ] in M.read α0. Global Instance AssociatedFunction_destroy : diff --git a/CoqOfRust/examples/default/examples/functions/diverging_functions_example_sum_odd_numbers.v b/CoqOfRust/examples/default/examples/functions/diverging_functions_example_sum_odd_numbers.v index d3a2f3cac..f4b29edbc 100644 --- a/CoqOfRust/examples/default/examples/functions/diverging_functions_example_sum_odd_numbers.v +++ b/CoqOfRust/examples/default/examples/functions/diverging_functions_example_sum_odd_numbers.v @@ -89,48 +89,74 @@ Definition sum_odd_numbers (up_to : u32.t) : M u32.t := core.ops.range.Range.start := Integer.of_Z 0; core.ops.range.Range.end_ := α0; |}) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t u32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t u32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some i => - let* i := M.alloc i in - let* addition : M.Val u32.t := - let* α0 : u32.t := M.read i in - let* α1 : u32.t := BinOp.Panic.rem α0 (Integer.of_Z 2) in - let* α2 : M.Val u32.t := - match BinOp.Pure.eq α1 (Integer.of_Z 1) with - | _ => M.pure i - | _ => - let* α0 : M.Val never.t := Continue in - let* α1 := M.read α0 in - let* α2 : u32.t := never_to_any α1 in - M.alloc α2 - end in - M.copy α2 in - let* _ : M.Val unit := - let β : M.Val u32.t := acc in - let* α0 := M.read β in - let* α1 : u32.t := M.read addition in - let* α2 := BinOp.Panic.add α0 α1 in - assign β α2 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α2) in + let* α2 : M.Val (core.ops.range.Range.t u32.t) := M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t u32.t := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t u32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t u32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* i := M.copy γ0 in + let* addition : M.Val u32.t := + let* α0 : u32.t := M.read i in + let* α1 : u32.t := + BinOp.Panic.rem α0 (Integer.of_Z 2) in + let* α2 : M.Val bool.t := + M.alloc (BinOp.Pure.eq α1 (Integer.of_Z 1)) in + let* α3 : M.Val u32.t := + match_operator + α2 + [ + fun γ => (M.pure i) : M (M.Val u32.t); + fun γ => + (let* α0 : M.Val never.t := M.continue in + let* α1 := M.read α0 in + let* α2 : u32.t := never_to_any α1 in + M.alloc α2) : + M (M.Val u32.t) + ] in + M.copy α3 in + let* _ : M.Val unit := + let β : M.Val u32.t := acc in + let* α0 := M.read β in + let* α1 : u32.t := M.read addition in + let* α2 := BinOp.Panic.add α0 α1 in + assign β α2 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α3) in M.read acc. diff --git a/CoqOfRust/examples/default/examples/functions/functions.v b/CoqOfRust/examples/default/examples/functions/functions.v index 274389c80..649ad757e 100644 --- a/CoqOfRust/examples/default/examples/functions/functions.v +++ b/CoqOfRust/examples/default/examples/functions/functions.v @@ -173,32 +173,52 @@ Definition fizzbuzz_to (n : u32.t) : M unit := (Self := core.ops.range.RangeInclusive.t u32.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val unit := - match α2 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t u32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.RangeInclusive.t u32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some n => - let* n := M.alloc n in - let* _ : M.Val unit := - let* α0 : u32.t := M.read n in - let* α1 : unit := M.call (functions.fizzbuzz α0) in - M.alloc α1 in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α3). + let* α3 : M.Val (core.ops.range.RangeInclusive.t u32.t) := M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t u32.t := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.RangeInclusive.t u32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t u32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* n := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : u32.t := M.read n in + let* α1 : unit := M.call (functions.fizzbuzz α0) in + M.alloc α1 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α4). diff --git a/CoqOfRust/examples/default/examples/functions/functions_closures.v b/CoqOfRust/examples/default/examples/functions/functions_closures.v index ad369cbc4..11ab304a0 100644 --- a/CoqOfRust/examples/default/examples/functions/functions_closures.v +++ b/CoqOfRust/examples/default/examples/functions/functions_closures.v @@ -35,19 +35,33 @@ Definition main : M unit := let* outer_var : M.Val i32.t := M.alloc (Integer.of_Z 42) in let* closure_annotated : M.Val (i32.t -> M i32.t) := M.alloc - (fun (i : i32.t) => - (let* i := M.alloc i in - let* α0 : i32.t := M.read i in - let* α1 : i32.t := M.read outer_var in - BinOp.Panic.add α0 α1) : + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* i := M.copy γ in + let* α0 : i32.t := M.read i in + let* α1 : i32.t := M.read outer_var in + BinOp.Panic.add α0 α1) : + M i32.t + ]) : M i32.t) in let* closure_inferred : M.Val (i32.t -> M i32.t) := M.alloc - (fun (i : i32.t) => - (let* i := M.alloc i in - let* α0 : i32.t := M.read i in - let* α1 : i32.t := M.read outer_var in - BinOp.Panic.add α0 α1) : + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* i := M.copy γ in + let* α0 : i32.t := M.read i in + let* α1 : i32.t := M.read outer_var in + BinOp.Panic.add α0 α1) : + M i32.t + ]) : M i32.t) in let* _ : M.Val unit := let* _ : M.Val unit := diff --git a/CoqOfRust/examples/default/examples/functions/functions_closures_as_input_parameters.v b/CoqOfRust/examples/default/examples/functions/functions_closures_as_input_parameters.v index 792f214d8..43eb8d252 100644 --- a/CoqOfRust/examples/default/examples/functions/functions_closures_as_input_parameters.v +++ b/CoqOfRust/examples/default/examples/functions/functions_closures_as_input_parameters.v @@ -177,10 +177,17 @@ Definition main : M unit := M.alloc α1 in let* double : M.Val (i32.t -> M i32.t) := M.alloc - (fun (x : i32.t) => - (let* x := M.alloc x in - let* α0 : i32.t := M.read x in - BinOp.Panic.mul (Integer.of_Z 2) α0) : + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* x := M.copy γ in + let* α0 : i32.t := M.read x in + BinOp.Panic.mul (Integer.of_Z 2) α0) : + M i32.t + ]) : M i32.t) in let* _ : M.Val unit := let* _ : M.Val unit := diff --git a/CoqOfRust/examples/default/examples/functions/functions_closures_example_Iterator_any.v b/CoqOfRust/examples/default/examples/functions/functions_closures_example_Iterator_any.v index b0d5cb2ab..0223ddc6b 100644 --- a/CoqOfRust/examples/default/examples/functions/functions_closures_example_Iterator_any.v +++ b/CoqOfRust/examples/default/examples/functions/functions_closures_example_Iterator_any.v @@ -74,10 +74,20 @@ Definition main : M unit := (Self := core.slice.iter.Iter.t i32.t) (Trait := ltac:(refine _))) (borrow_mut α7) - (fun (x : ref i32.t) => - (let* x := M.alloc x in - let* α0 : i32.t := M.read x in - M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + (fun (α0 : ref i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* x := M.copy γ in + let* α0 : i32.t := M.read x in + M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + M bool.t + ]) : M bool.t)) in let* α9 : M.Val bool.t := M.alloc α8 in let* α10 : core.fmt.rt.Argument.t := @@ -118,10 +128,17 @@ Definition main : M unit := alloc.vec.into_iter.IntoIter.t i32.t alloc.alloc.Global.t) (Trait := ltac:(refine _))) (borrow_mut α7) - (fun (x : i32.t) => - (let* x := M.alloc x in - let* α0 : i32.t := M.read x in - M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* x := M.copy γ in + let* α0 : i32.t := M.read x in + M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + M bool.t + ]) : M bool.t)) in let* α9 : M.Val bool.t := M.alloc α8 in let* α10 : core.fmt.rt.Argument.t := @@ -214,10 +231,20 @@ Definition main : M unit := (Self := core.slice.iter.Iter.t i32.t) (Trait := ltac:(refine _))) (borrow_mut α8) - (fun (x : ref i32.t) => - (let* x := M.alloc x in - let* α0 : i32.t := M.read x in - M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + (fun (α0 : ref i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* x := M.copy γ in + let* α0 : i32.t := M.read x in + M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + M bool.t + ]) : M bool.t)) in let* α10 : M.Val bool.t := M.alloc α9 in let* α11 : core.fmt.rt.Argument.t := @@ -254,11 +281,18 @@ Definition main : M unit := (Self := core.slice.iter.Iter.t i32.t) (Trait := ltac:(refine _))) (borrow_mut α6) - (fun (x : ref i32.t) => - (let* x := M.alloc x in - let* α0 : ref i32.t := M.read x in - let* α1 : i32.t := M.read (deref α0) in - M.pure (BinOp.Pure.eq α1 (Integer.of_Z 2))) : + (fun (α0 : ref i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* x := M.copy γ in + let* α0 : ref i32.t := M.read x in + let* α1 : i32.t := M.read (deref α0) in + M.pure (BinOp.Pure.eq α1 (Integer.of_Z 2))) : + M bool.t + ]) : M bool.t)) in let* α8 : M.Val bool.t := M.alloc α7 in let* α9 : core.fmt.rt.Argument.t := diff --git a/CoqOfRust/examples/default/examples/functions/functions_closures_example_searching_through_iterators_Iterator_find.v b/CoqOfRust/examples/default/examples/functions/functions_closures_example_searching_through_iterators_Iterator_find.v index e3fef8169..bdbd3029b 100644 --- a/CoqOfRust/examples/default/examples/functions/functions_closures_example_searching_through_iterators_Iterator_find.v +++ b/CoqOfRust/examples/default/examples/functions/functions_closures_example_searching_through_iterators_Iterator_find.v @@ -87,10 +87,23 @@ Definition main : M unit := (Self := core.slice.iter.Iter.t i32.t) (Trait := ltac:(refine _))) (borrow_mut iter) - (fun (x : ref (ref i32.t)) => - (let* x := M.alloc x in - let* α0 : i32.t := M.read x in - M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + (fun (α0 : ref (ref i32.t)) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* x := M.copy γ in + let* α0 : i32.t := M.read x in + M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + M bool.t + ]) : M bool.t)) in let* α6 : M.Val (core.option.Option.t (ref i32.t)) := M.alloc α5 in let* α7 : core.fmt.rt.Argument.t := @@ -121,10 +134,20 @@ Definition main : M unit := alloc.vec.into_iter.IntoIter.t i32.t alloc.alloc.Global.t) (Trait := ltac:(refine _))) (borrow_mut into_iter) - (fun (x : ref i32.t) => - (let* x := M.alloc x in - let* α0 : i32.t := M.read x in - M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + (fun (α0 : ref i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* x := M.copy γ in + let* α0 : i32.t := M.read x in + M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + M bool.t + ]) : M bool.t)) in let* α6 : M.Val (core.option.Option.t i32.t) := M.alloc α5 in let* α7 : core.fmt.rt.Argument.t := @@ -163,10 +186,23 @@ Definition main : M unit := (Self := core.slice.iter.Iter.t i32.t) (Trait := ltac:(refine _))) (borrow_mut α8) - (fun (x : ref (ref i32.t)) => - (let* x := M.alloc x in - let* α0 : i32.t := M.read x in - M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + (fun (α0 : ref (ref i32.t)) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* x := M.copy γ in + let* α0 : i32.t := M.read x in + M.pure (BinOp.Pure.eq α0 (Integer.of_Z 2))) : + M bool.t + ]) : M bool.t)) in let* α10 : M.Val (core.option.Option.t (ref i32.t)) := M.alloc α9 in let* α11 : core.fmt.rt.Argument.t := @@ -203,11 +239,21 @@ Definition main : M unit := (Self := core.slice.iter.Iter.t i32.t) (Trait := ltac:(refine _))) (borrow_mut α6) - (fun (x : ref (ref i32.t)) => - (let* x := M.alloc x in - let* α0 : ref i32.t := M.read x in - let* α1 : i32.t := M.read (deref α0) in - M.pure (BinOp.Pure.eq α1 (Integer.of_Z 2))) : + (fun (α0 : ref (ref i32.t)) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* x := M.copy γ in + let* α0 : ref i32.t := M.read x in + let* α1 : i32.t := M.read (deref α0) in + M.pure (BinOp.Pure.eq α1 (Integer.of_Z 2))) : + M bool.t + ]) : M bool.t)) in let* α8 : M.Val (core.option.Option.t (ref i32.t)) := M.alloc α7 in let* α9 : core.fmt.rt.Argument.t := diff --git a/CoqOfRust/examples/default/examples/functions/functions_closures_example_searching_through_iterators_Iterator_position.v b/CoqOfRust/examples/default/examples/functions/functions_closures_example_searching_through_iterators_Iterator_position.v index b62e2c9c8..1c0a68322 100644 --- a/CoqOfRust/examples/default/examples/functions/functions_closures_example_searching_through_iterators_Iterator_position.v +++ b/CoqOfRust/examples/default/examples/functions/functions_closures_example_searching_through_iterators_Iterator_position.v @@ -52,49 +52,80 @@ Definition main : M unit := (Self := core.slice.iter.Iter.t i32.t) (Trait := ltac:(refine _))) (borrow_mut α2) - (fun (x : ref i32.t) => - (let* x := M.alloc x in - let* α0 : i32.t := M.read x in - let* α1 : i32.t := BinOp.Panic.rem α0 (Integer.of_Z 2) in - M.pure (BinOp.Pure.eq α1 (Integer.of_Z 0))) : + (fun (α0 : ref i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* x := M.copy γ in + let* α0 : i32.t := M.read x in + let* α1 : i32.t := BinOp.Panic.rem α0 (Integer.of_Z 2) in + M.pure (BinOp.Pure.eq α1 (Integer.of_Z 0))) : + M bool.t + ]) : M bool.t)) in M.alloc α3 in let* _ : M.Val unit := let* α0 : M.Val (core.option.Option.t usize.t) := M.alloc (core.option.Option.Some (Integer.of_Z 5)) in - match (borrow index_of_first_even_number, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref (core.option.Option.t usize.t) := M.read left_val in - let* α1 : ref (core.option.Option.t usize.t) := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := core.option.Option.t usize.t) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref (core.option.Option.t usize.t) := M.read left_val in - let* α2 : ref (core.option.Option.t usize.t) := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : + M.Val + ((ref (core.option.Option.t usize.t)) + * + (ref (core.option.Option.t usize.t))) := + M.alloc (borrow index_of_first_even_number, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref (core.option.Option.t usize.t) := M.read left_val in + let* α1 : ref (core.option.Option.t usize.t) := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := core.option.Option.t usize.t) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref (core.option.Option.t usize.t) := + M.read left_val in + let* α2 : ref (core.option.Option.t usize.t) := + M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* index_of_first_negative_number : M.Val (core.option.Option.t usize.t) := let* α0 : alloc.vec.Vec.t i32.t alloc.alloc.Global.t := M.read vec in let* α1 : alloc.vec.into_iter.IntoIter.t i32.t alloc.alloc.Global.t := @@ -112,47 +143,75 @@ Definition main : M unit := (Self := alloc.vec.into_iter.IntoIter.t i32.t alloc.alloc.Global.t) (Trait := ltac:(refine _))) (borrow_mut α2) - (fun (x : i32.t) => - (let* x := M.alloc x in - let* α0 : i32.t := M.read x in - M.pure (BinOp.Pure.lt α0 (Integer.of_Z 0))) : + (fun (α0 : i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* x := M.copy γ in + let* α0 : i32.t := M.read x in + M.pure (BinOp.Pure.lt α0 (Integer.of_Z 0))) : + M bool.t + ]) : M bool.t)) in M.alloc α3 in let* _ : M.Val unit := let* α0 : M.Val (core.option.Option.t usize.t) := M.alloc core.option.Option.None in - match (borrow index_of_first_negative_number, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref (core.option.Option.t usize.t) := M.read left_val in - let* α1 : ref (core.option.Option.t usize.t) := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := core.option.Option.t usize.t) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref (core.option.Option.t usize.t) := M.read left_val in - let* α2 : ref (core.option.Option.t usize.t) := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : + M.Val + ((ref (core.option.Option.t usize.t)) + * + (ref (core.option.Option.t usize.t))) := + M.alloc (borrow index_of_first_negative_number, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref (core.option.Option.t usize.t) := M.read left_val in + let* α1 : ref (core.option.Option.t usize.t) := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := core.option.Option.t usize.t) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref (core.option.Option.t usize.t) := + M.read left_val in + let* α2 : ref (core.option.Option.t usize.t) := + M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/functions/functions_closures_forced_capturing_with_move.v b/CoqOfRust/examples/default/examples/functions/functions_closures_forced_capturing_with_move.v index 8461be4c1..512df1e58 100644 --- a/CoqOfRust/examples/default/examples/functions/functions_closures_forced_capturing_with_move.v +++ b/CoqOfRust/examples/default/examples/functions/functions_closures_forced_capturing_with_move.v @@ -35,16 +35,23 @@ Definition main : M unit := M.alloc α3 in let* contains : M.Val ((ref i32.t) -> M bool.t) := M.alloc - (fun (needle : ref i32.t) => - (let* needle := M.alloc needle in - let* α0 : ref (slice i32.t) := - M.call - ((core.ops.deref.Deref.deref - (Self := alloc.vec.Vec.t i32.t alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - (borrow haystack)) in - let* α1 : ref i32.t := M.read needle in - M.call ((slice i32.t)::["contains"] α0 α1)) : + (fun (α0 : ref i32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* needle := M.copy γ in + let* α0 : ref (slice i32.t) := + M.call + ((core.ops.deref.Deref.deref + (Self := alloc.vec.Vec.t i32.t alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + (borrow haystack)) in + let* α1 : ref i32.t := M.read needle in + M.call ((slice i32.t)::["contains"] α0 α1)) : + M bool.t + ]) : M bool.t) in let* _ : M.Val unit := let* _ : M.Val unit := diff --git a/CoqOfRust/examples/default/examples/functions/higher_order_functions.v b/CoqOfRust/examples/default/examples/functions/higher_order_functions.v index 0b2990e2e..b896df19a 100644 --- a/CoqOfRust/examples/default/examples/functions/higher_order_functions.v +++ b/CoqOfRust/examples/default/examples/functions/higher_order_functions.v @@ -70,60 +70,82 @@ Definition main : M unit := (Self := core.ops.range.RangeFrom.t u32.t) (Trait := ltac:(refine _))) {| core.ops.range.RangeFrom.start := Integer.of_Z 0; |}) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t u32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.RangeFrom.t u32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some n => - let* n := M.alloc n in - let* n_squared : M.Val u32.t := - let* α0 : u32.t := M.read n in - let* α1 : u32.t := M.read n in - let* α2 : u32.t := BinOp.Panic.mul α0 α1 in - M.alloc α2 in - let* α0 : u32.t := M.read n_squared in - let* α1 : u32.t := M.read upper in - let* α2 : M.Val bool.t := M.alloc (BinOp.Pure.ge α0 α1) in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val never.t := Break in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - let* α0 : u32.t := M.read n_squared in - let* α1 : bool.t := M.call (higher_order_functions.is_odd α0) in - let* α2 : M.Val bool.t := M.alloc α1 in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val unit := - let β : M.Val u32.t := acc in - let* α0 := M.read β in - let* α1 : u32.t := M.read n_squared in - let* α2 := BinOp.Panic.add α0 α1 in - assign β α2 in - M.alloc tt - else - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α1) in + let* α1 : M.Val (core.ops.range.RangeFrom.t u32.t) := M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t u32.t := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.RangeFrom.t u32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t u32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* n := M.copy γ0 in + let* n_squared : M.Val u32.t := + let* α0 : u32.t := M.read n in + let* α1 : u32.t := M.read n in + let* α2 : u32.t := BinOp.Panic.mul α0 α1 in + M.alloc α2 in + let* α0 : u32.t := M.read n_squared in + let* α1 : u32.t := M.read upper in + let* α2 : M.Val bool.t := + M.alloc (BinOp.Pure.ge α0 α1) in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val never.t := M.break in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + let* α0 : u32.t := M.read n_squared in + let* α1 : bool.t := + M.call (higher_order_functions.is_odd α0) in + let* α2 : M.Val bool.t := M.alloc α1 in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val unit := + let β : M.Val u32.t := acc in + let* α0 := M.read β in + let* α1 : u32.t := M.read n_squared in + let* α2 := BinOp.Panic.add α0 α1 in + assign β α2 in + M.alloc tt + else + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α2) in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "imperative style: ") in @@ -155,11 +177,18 @@ Definition main : M unit := (Self := core.ops.range.RangeFrom.t u32.t) (Trait := ltac:(refine _))) {| core.ops.range.RangeFrom.start := Integer.of_Z 0; |} - (fun (n : u32.t) => - (let* n := M.alloc n in - let* α0 : u32.t := M.read n in - let* α1 : u32.t := M.read n in - BinOp.Panic.mul α0 α1) : + (fun (α0 : u32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* n := M.copy γ in + let* α0 : u32.t := M.read n in + let* α1 : u32.t := M.read n in + BinOp.Panic.mul α0 α1) : + M u32.t + ]) : M u32.t)) in let* α1 : core.iter.adapters.take_while.TakeWhile.t @@ -175,11 +204,21 @@ Definition main : M unit := (u32.t -> M u32.t)) (Trait := ltac:(refine _))) α0 - (fun (n_squared : ref u32.t) => - (let* n_squared := M.alloc n_squared in - let* α0 : u32.t := M.read n_squared in - let* α1 : u32.t := M.read upper in - M.pure (BinOp.Pure.lt α0 α1)) : + (fun (α0 : ref u32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* n_squared := M.copy γ in + let* α0 : u32.t := M.read n_squared in + let* α1 : u32.t := M.read upper in + M.pure (BinOp.Pure.lt α0 α1)) : + M bool.t + ]) : M bool.t)) in let* α2 : core.iter.adapters.filter.Filter.t @@ -199,10 +238,20 @@ Definition main : M unit := ((ref u32.t) -> M bool.t)) (Trait := ltac:(refine _))) α1 - (fun (n_squared : ref u32.t) => - (let* n_squared := M.alloc n_squared in - let* α0 : u32.t := M.read n_squared in - M.call (higher_order_functions.is_odd α0)) : + (fun (α0 : ref u32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* n_squared := M.copy γ in + let* α0 : u32.t := M.read n_squared in + M.call (higher_order_functions.is_odd α0)) : + M bool.t + ]) : M bool.t)) in let* α3 : u32.t := M.call diff --git a/CoqOfRust/examples/default/examples/generics/generics_new_type_idiom_as_base_type.v b/CoqOfRust/examples/default/examples/generics/generics_new_type_idiom_as_base_type.v index 89922a7cb..af34b6f00 100644 --- a/CoqOfRust/examples/default/examples/generics/generics_new_type_idiom_as_base_type.v +++ b/CoqOfRust/examples/default/examples/generics/generics_new_type_idiom_as_base_type.v @@ -27,10 +27,18 @@ Definition main : M unit := M.alloc (generics_new_type_idiom_as_base_type.Years.Build_t (Integer.of_Z 42)) in let* years_as_primitive_1 : M.Val i64.t := M.copy years.["0"] in - let* 'generics_new_type_idiom_as_base_type.Years.Build_t - years_as_primitive_2 : - generics_new_type_idiom_as_base_type.Years.t := - M.read years in - let* years_as_primitive_2 := M.alloc years_as_primitive_2 in - let* α0 : M.Val unit := M.alloc tt in + let* α0 : M.Val unit := + match_operator + years + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | generics_new_type_idiom_as_base_type.Years.Build_t _ => + let γ0 := γ.["Years.0"] in + let* years_as_primitive_2 := M.copy γ0 in + M.alloc tt + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/guessing_game/guessing_game.v b/CoqOfRust/examples/default/examples/guessing_game/guessing_game.v index 0ccb875e2..0cd3b756c 100644 --- a/CoqOfRust/examples/default/examples/guessing_game/guessing_game.v +++ b/CoqOfRust/examples/default/examples/guessing_game/guessing_game.v @@ -64,7 +64,7 @@ Definition main : M unit := let* α0 : u32.t := M.call guessing_game.gen_range in M.alloc α0 in let* α0 : M.Val unit := - loop + M.loop (let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "Please input your guess. @@ -107,18 +107,37 @@ Definition main : M unit := let* α1 : ref str.t := M.call (str.t::["trim"] α0) in let* α2 : core.result.Result.t u32.t core.num.error.ParseIntError.t := M.call (str.t::["parse"] α1) in - let* α3 : M.Val u32.t := - match α2 with - | core.result.Result.Ok num => - let* num := M.alloc num in - M.pure num - | core.result.Result.Err _ => - let* α0 : M.Val never.t := Continue in - let* α1 := M.read α0 in - let* α2 : u32.t := never_to_any α1 in - M.alloc α2 - end in - M.copy α3 in + let* α3 : + M.Val (core.result.Result.t u32.t core.num.error.ParseIntError.t) := + M.alloc α2 in + let* α4 : M.Val u32.t := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* num := M.copy γ0 in + M.pure num + | _ => M.break_match + end) : + M (M.Val u32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* α0 : M.Val never.t := M.continue in + let* α1 := M.read α0 in + let* α2 : u32.t := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val u32.t) + ] in + M.copy α4 in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "You guessed: ") in @@ -145,51 +164,75 @@ Definition main : M unit := ((core.cmp.Ord.cmp (Self := u32.t) (Trait := ltac:(refine _))) (borrow guess) (borrow secret_number)) in - match α0 with - | core.cmp.Ordering.Less => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Too small! + let* α1 : M.Val core.cmp.Ordering.t := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.cmp.Ordering.Less => + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Too small! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | core.cmp.Ordering.Greater => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Too big! + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.cmp.Ordering.Greater => + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Too big! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | core.cmp.Ordering.Equal => - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "You win! + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.cmp.Ordering.Equal => + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "You win! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt in - let* _ : M.Val never.t := Break in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - end) in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt in + let* _ : M.Val never.t := M.break in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit) + ]) in M.read α0. diff --git a/CoqOfRust/examples/default/examples/ink_contracts/basic_contract_caller.v b/CoqOfRust/examples/default/examples/ink_contracts/basic_contract_caller.v index c649cecf9..9c397b020 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/basic_contract_caller.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/basic_contract_caller.v @@ -49,9 +49,17 @@ Section Impl_core_clone_Clone_for_basic_contract_caller_AccountId_t. *) Definition clone (self : ref Self) : M basic_contract_caller.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref basic_contract_caller.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val basic_contract_caller.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref basic_contract_caller.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val basic_contract_caller.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/call_runtime.v b/CoqOfRust/examples/default/examples/ink_contracts/call_runtime.v index 0a0461b93..d30e2b035 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/call_runtime.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/call_runtime.v @@ -49,9 +49,17 @@ Section Impl_core_clone_Clone_for_call_runtime_AccountId_t. *) Definition clone (self : ref Self) : M call_runtime.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref call_runtime.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val call_runtime.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref call_runtime.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val call_runtime.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -319,19 +327,27 @@ Section Impl_core_convert_From_call_runtime_EnvError_t_for_call_runtime_RuntimeE *) Definition from (e : call_runtime.EnvError.t) : M Self := let* e := M.alloc e in - let* α0 : call_runtime.EnvError.t := M.read e in - let* α1 : M.Val call_runtime.RuntimeError.t := - match α0 with - | call_runtime.EnvError.CallRuntimeFailed => - M.alloc call_runtime.RuntimeError.CallRuntimeFailed - | _ => - let* α0 : ref str.t := - M.read (mk_str "Unexpected error from `pallet-contracts`.") in - let* α1 : never.t := M.call (std.panicking.begin_panic α0) in - let* α2 : call_runtime.RuntimeError.t := never_to_any α1 in - M.alloc α2 - end in - M.read α1. + let* α0 : M.Val call_runtime.RuntimeError.t := + match_operator + e + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | call_runtime.EnvError.CallRuntimeFailed => + M.alloc call_runtime.RuntimeError.CallRuntimeFailed + | _ => M.break_match + end) : + M (M.Val call_runtime.RuntimeError.t); + fun γ => + (let* α0 : ref str.t := + M.read (mk_str "Unexpected error from `pallet-contracts`.") in + let* α1 : never.t := M.call (std.panicking.begin_panic α0) in + let* α2 : call_runtime.RuntimeError.t := never_to_any α1 in + M.alloc α2) : + M (M.Val call_runtime.RuntimeError.t) + ] in + M.read α0. Global Instance AssociatedFunction_from : Notations.DoubleColon Self "from" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/conditional_compilation.v b/CoqOfRust/examples/default/examples/ink_contracts/conditional_compilation.v index 5ea281d25..90acf199f 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/conditional_compilation.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/conditional_compilation.v @@ -49,9 +49,17 @@ Section Impl_core_clone_Clone_for_conditional_compilation_AccountId_t. *) Definition clone (self : ref Self) : M conditional_compilation.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref conditional_compilation.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val conditional_compilation.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref conditional_compilation.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val conditional_compilation.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/contract_terminate.v b/CoqOfRust/examples/default/examples/ink_contracts/contract_terminate.v index 3200ade53..387cff43d 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/contract_terminate.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/contract_terminate.v @@ -49,9 +49,17 @@ Section Impl_core_clone_Clone_for_contract_terminate_AccountId_t. *) Definition clone (self : ref Self) : M contract_terminate.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref contract_terminate.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val contract_terminate.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref contract_terminate.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val contract_terminate.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/contract_transfer.v b/CoqOfRust/examples/default/examples/ink_contracts/contract_transfer.v index a310ddb9c..4f770ed0a 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/contract_transfer.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/contract_transfer.v @@ -49,9 +49,17 @@ Section Impl_core_clone_Clone_for_contract_transfer_AccountId_t. *) Definition clone (self : ref Self) : M contract_transfer.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref contract_transfer.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val contract_transfer.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref contract_transfer.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val contract_transfer.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/custom_environment.v b/CoqOfRust/examples/default/examples/ink_contracts/custom_environment.v index 747f16d44..8025f1dbf 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/custom_environment.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/custom_environment.v @@ -49,9 +49,17 @@ Section Impl_core_clone_Clone_for_custom_environment_AccountId_t. *) Definition clone (self : ref Self) : M custom_environment.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref custom_environment.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val custom_environment.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref custom_environment.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val custom_environment.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/dns.v b/CoqOfRust/examples/default/examples/ink_contracts/dns.v index 82bfb28d4..4e899f3c8 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/dns.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/dns.v @@ -248,9 +248,17 @@ Section Impl_core_clone_Clone_for_dns_AccountId_t. *) Definition clone (self : ref Self) : M dns.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref dns.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val dns.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref dns.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val dns.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/e2e_call_runtime.v b/CoqOfRust/examples/default/examples/ink_contracts/e2e_call_runtime.v index b5a2d7e99..c60ff97aa 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/e2e_call_runtime.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/e2e_call_runtime.v @@ -49,9 +49,17 @@ Section Impl_core_clone_Clone_for_e2e_call_runtime_AccountId_t. *) Definition clone (self : ref Self) : M e2e_call_runtime.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref e2e_call_runtime.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val e2e_call_runtime.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref e2e_call_runtime.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val e2e_call_runtime.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/erc1155.v b/CoqOfRust/examples/default/examples/ink_contracts/erc1155.v index 9659415b1..3eb77d8c6 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/erc1155.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/erc1155.v @@ -234,9 +234,17 @@ Section Impl_core_clone_Clone_for_erc1155_AccountId_t. *) Definition clone (self : ref Self) : M erc1155.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref erc1155.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val erc1155.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref erc1155.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val erc1155.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -1765,63 +1773,107 @@ Section Impl_erc1155_Erc1155_for_erc1155_Contract_t. (core.slice.iter.Iter.t u128.t)) (Trait := ltac:(refine _))) α0) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t ((ref u128.t) * (ref u128.t)) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - core.iter.adapters.zip.Zip.t - (core.slice.iter.Iter.t u128.t) - (core.slice.iter.Iter.t u128.t)) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some (id, v) => - let* id := M.alloc id in - let* v := M.alloc v in - let* balance : M.Val u128.t := - let* α0 : mut_ref erc1155.Contract.t := M.read self in - let* α1 : erc1155.AccountId.t := M.read from in - let* α2 : u128.t := M.read id in - let* α3 : u128.t := - M.call (balance_of (borrow (deref α0)) α1 α2) in - M.alloc α3 in - let* _ : M.Val unit := - let* α0 : u128.t := M.read balance in - let* α1 : u128.t := M.read v in - let* α2 : M.Val bool.t := - M.alloc (UnOp.not (BinOp.Pure.ge α0 α1)) in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val never.t := - let* α0 : erc1155.Error.t := - M.call - ((core.convert.Into.into - (Self := erc1155.Error.t) - (Trait := ltac:(refine _))) - erc1155.Error.InsufficientBalance) in - return_ (core.result.Result.Err α0) in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α2) in + let* α2 : + M.Val + (core.iter.adapters.zip.Zip.t + (core.slice.iter.Iter.t u128.t) + (core.slice.iter.Iter.t u128.t)) := + M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : + core.option.Option.t ((ref u128.t) * (ref u128.t)) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + core.iter.adapters.zip.Zip.t + (core.slice.iter.Iter.t u128.t) + (core.slice.iter.Iter.t u128.t)) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val + (core.option.Option.t + ((ref u128.t) * (ref u128.t))) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* α0 := M.read γ0 in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ0 in + let γ1 := Tuple.Access.right γ0 in + let* γ0 := + let* α0 := M.read γ0 in + M.pure (deref α0) in + let* id := M.copy γ0 in + let* γ1 := + let* α0 := M.read γ1 in + M.pure (deref α0) in + let* v := M.copy γ1 in + let* balance : M.Val u128.t := + let* α0 : mut_ref erc1155.Contract.t := + M.read self in + let* α1 : erc1155.AccountId.t := M.read from in + let* α2 : u128.t := M.read id in + let* α3 : u128.t := + M.call + (balance_of (borrow (deref α0)) α1 α2) in + M.alloc α3 in + let* _ : M.Val unit := + let* α0 : u128.t := M.read balance in + let* α1 : u128.t := M.read v in + let* α2 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.ge α0 α1)) in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val never.t := + let* α0 : erc1155.Error.t := + M.call + ((core.convert.Into.into + (Self := erc1155.Error.t) + (Trait := ltac:(refine _))) + erc1155.Error.InsufficientBalance) in + return_ (core.result.Result.Err α0) in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt in + M.alloc tt + end + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α3) in let* _ : M.Val unit := let* α0 : core.iter.adapters.zip.Zip.t @@ -1840,50 +1892,93 @@ Section Impl_erc1155_Erc1155_for_erc1155_Contract_t. (core.slice.iter.Iter.t u128.t)) (Trait := ltac:(refine _))) α0) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t ((ref u128.t) * (ref u128.t)) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - core.iter.adapters.zip.Zip.t - (core.slice.iter.Iter.t u128.t) - (core.slice.iter.Iter.t u128.t)) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some (id, v) => - let* id := M.alloc id in - let* v := M.alloc v in - let* _ : M.Val unit := - let* α0 : mut_ref erc1155.Contract.t := M.read self in - let* α1 : erc1155.AccountId.t := M.read from in - let* α2 : erc1155.AccountId.t := M.read to in - let* α3 : u128.t := M.read id in - let* α4 : u128.t := M.read v in - let* α5 : unit := + let* α2 : + M.Val + (core.iter.adapters.zip.Zip.t + (core.slice.iter.Iter.t u128.t) + (core.slice.iter.Iter.t u128.t)) := + M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : + core.option.Option.t ((ref u128.t) * (ref u128.t)) := M.call - (erc1155.Contract.t::["perform_transfer"] - α0 - α1 - α2 - α3 - α4) in - M.alloc α5 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α2) in + ((core.iter.traits.iterator.Iterator.next + (Self := + core.iter.adapters.zip.Zip.t + (core.slice.iter.Iter.t u128.t) + (core.slice.iter.Iter.t u128.t)) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val + (core.option.Option.t + ((ref u128.t) * (ref u128.t))) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* α0 := M.read γ0 in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ0 in + let γ1 := Tuple.Access.right γ0 in + let* γ0 := + let* α0 := M.read γ0 in + M.pure (deref α0) in + let* id := M.copy γ0 in + let* γ1 := + let* α0 := M.read γ1 in + M.pure (deref α0) in + let* v := M.copy γ1 in + let* _ : M.Val unit := + let* α0 : mut_ref erc1155.Contract.t := + M.read self in + let* α1 : erc1155.AccountId.t := M.read from in + let* α2 : erc1155.AccountId.t := M.read to in + let* α3 : u128.t := M.read id in + let* α4 : u128.t := M.read v in + let* α5 : unit := + M.call + (erc1155.Contract.t::["perform_transfer"] + α0 + α1 + α2 + α3 + α4) in + M.alloc α5 in + M.alloc tt + end + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α3) in let* _ : M.Val unit := let* α0 : mut_ref erc1155.Contract.t := M.read self in let* α1 : erc1155.AccountId.t := M.read caller in @@ -1960,81 +2055,145 @@ Section Impl_erc1155_Erc1155_for_erc1155_Contract_t. ref (alloc.vec.Vec.t erc1155.AccountId.t alloc.alloc.Global.t)) (Trait := ltac:(refine _))) (borrow owners)) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (ref erc1155.AccountId.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.slice.iter.Iter.t erc1155.AccountId.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some o => - let* o := M.alloc o in - let* α0 : core.slice.iter.Iter.t u128.t := - M.call - ((core.iter.traits.collect.IntoIterator.into_iter - (Self := - ref (alloc.vec.Vec.t u128.t alloc.alloc.Global.t)) - (Trait := ltac:(refine _))) - (borrow token_ids)) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (ref u128.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.slice.iter.Iter.t u128.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in + let* α1 : M.Val (core.slice.iter.Iter.t erc1155.AccountId.t) := + M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (ref erc1155.AccountId.t) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.slice.iter.Iter.t erc1155.AccountId.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val (core.option.Option.t (ref erc1155.AccountId.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in match α0 with | core.option.Option.None => - let* α0 : M.Val never.t := Break in + let* α0 : M.Val never.t := M.break in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in M.alloc α2 - | core.option.Option.Some t => - let* t := M.alloc t in - let* amount : M.Val u128.t := - let* α0 : ref erc1155.Contract.t := M.read self in - let* α1 : ref erc1155.AccountId.t := M.read o in - let* α2 : erc1155.AccountId.t := - M.read (deref α1) in - let* α3 : ref u128.t := M.read t in - let* α4 : u128.t := M.read (deref α3) in - let* α5 : u128.t := M.call (balance_of α0 α2 α4) in - M.alloc α5 in - let* _ : M.Val unit := - let* α0 : u128.t := M.read amount in - let* α1 : unit := - M.call - ((alloc.vec.Vec.t - u128.t - alloc.alloc.Global.t)::["push"] - (borrow_mut output) - α0) in - M.alloc α1 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α1) - end in - M.alloc tt) - end in - M.pure (use α1) in + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* o := M.copy γ0 in + let* α0 : core.slice.iter.Iter.t u128.t := + M.call + ((core.iter.traits.collect.IntoIterator.into_iter + (Self := + ref + (alloc.vec.Vec.t + u128.t + alloc.alloc.Global.t)) + (Trait := ltac:(refine _))) + (borrow token_ids)) in + let* α1 : M.Val (core.slice.iter.Iter.t u128.t) := + M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : + core.option.Option.t (ref u128.t) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + core.slice.iter.Iter.t u128.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val + (core.option.Option.t + (ref u128.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := + M.break in + let* α1 := M.read α0 in + let* α2 : unit := + never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* t := M.copy γ0 in + let* amount : M.Val u128.t := + let* α0 : + ref erc1155.Contract.t := + M.read self in + let* α1 : + ref erc1155.AccountId.t := + M.read o in + let* α2 : erc1155.AccountId.t := + M.read (deref α1) in + let* α3 : ref u128.t := + M.read t in + let* α4 : u128.t := + M.read (deref α3) in + let* α5 : u128.t := + M.call + (balance_of α0 α2 α4) in + M.alloc α5 in + let* _ : M.Val unit := + let* α0 : u128.t := + M.read amount in + let* α1 : unit := + M.call + ((alloc.vec.Vec.t + u128.t + alloc.alloc.Global.t)::["push"] + (borrow_mut output) + α0) in + M.alloc α1 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α2) + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α2) in M.read output. Global Instance AssociatedFunction_balance_of_batch : diff --git a/CoqOfRust/examples/default/examples/ink_contracts/erc20.v b/CoqOfRust/examples/default/examples/ink_contracts/erc20.v index 67c248f88..6fda21ea7 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/erc20.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/erc20.v @@ -163,9 +163,17 @@ Section Impl_core_clone_Clone_for_erc20_AccountId_t. *) Definition clone (self : ref Self) : M erc20.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref erc20.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val erc20.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref erc20.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val erc20.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -953,26 +961,50 @@ Section Impl_erc20_Erc20_t_2. (Self := core.result.Result.t unit erc20.Error.t) (Trait := ltac:(refine _))) α2) in - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t core.convert.Infallible.t erc20.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit erc20.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit erc20.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t erc20.Error.t) + unit) := + M.alloc α3 in + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + erc20.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit erc20.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.result.Result.t unit erc20.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : mut_ref erc20.Erc20.t := M.read self in let* α1 : erc20.AccountId.t := M.read from in diff --git a/CoqOfRust/examples/default/examples/ink_contracts/erc721.v b/CoqOfRust/examples/default/examples/ink_contracts/erc721.v index f08a00b10..b4d89252e 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/erc721.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/erc721.v @@ -234,9 +234,17 @@ Section Impl_core_clone_Clone_for_erc721_AccountId_t. *) Definition clone (self : ref Self) : M erc721.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref erc721.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val erc721.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref erc721.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val erc721.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -1211,26 +1219,50 @@ Section Impl_erc721_Erc721_t. (Self := core.result.Result.t unit erc721.Error.t) (Trait := ltac:(refine _))) α3) in - match α4 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t core.convert.Infallible.t erc721.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit erc721.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit erc721.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α5 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t erc721.Error.t) + unit) := + M.alloc α4 in + match_operator + α5 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + erc721.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit erc721.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.result.Result.t unit erc721.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* α0 : M.Val (core.result.Result.t unit erc721.Error.t) := M.alloc (core.result.Result.Ok tt) in M.read α0). @@ -1441,26 +1473,50 @@ Section Impl_erc721_Erc721_t. (Self := core.result.Result.t unit erc721.Error.t) (Trait := ltac:(refine _))) α2) in - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t core.convert.Infallible.t erc721.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit erc721.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit erc721.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t erc721.Error.t) + unit) := + M.alloc α3 in + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + erc721.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit erc721.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.result.Result.t unit erc721.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* α0 : M.Val (core.result.Result.t unit erc721.Error.t) := M.alloc (core.result.Result.Ok tt) in M.read α0). @@ -1502,112 +1558,168 @@ Section Impl_erc721_Erc721_t. let* id := M.alloc id in let return_ := M.return_ (R := core.result.Result.t unit erc721.Error.t) in M.catch_return - (let* '{| - erc721.Erc721.token_owner := token_owner; - erc721.Erc721.owned_tokens_count := owned_tokens_count; - |} : - mut_ref erc721.Erc721.t := - M.read self in - let* token_owner := M.alloc token_owner in - let* owned_tokens_count := M.alloc owned_tokens_count in - let* _ : M.Val unit := - let* α0 : mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := - M.read token_owner in - let* α1 : bool.t := - M.call - ((erc721.Mapping.t u32.t erc721.AccountId.t)::["contains"] - (borrow (deref α0)) - (borrow id)) in - let* α2 : M.Val bool.t := M.alloc (UnOp.not α1) in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val never.t := - return_ (core.result.Result.Err erc721.Error.TokenNotFound) in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt in - let* count : M.Val u32.t := - let* α0 : mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := - M.read owned_tokens_count in - let* α1 : ref erc721.AccountId.t := M.read from in - let* α2 : core.option.Option.t u32.t := - M.call - ((erc721.Mapping.t erc721.AccountId.t u32.t)::["get"] - (borrow (deref α0)) - α1) in - let* α3 : core.option.Option.t u32.t := - M.call - ((core.option.Option.t u32.t)::["map"] - α2 - (fun (c : u32.t) => - (let* c := M.alloc c in - let* α0 : u32.t := M.read c in - BinOp.Panic.sub α0 (Integer.of_Z 1)) : - M u32.t)) in - let* α4 : core.result.Result.t u32.t erc721.Error.t := - M.call - ((core.option.Option.t u32.t)::["ok_or"] - α3 - erc721.Error.CannotFetchValue) in - let* α5 : - core.ops.control_flow.ControlFlow.t - (core.result.Result.t core.convert.Infallible.t erc721.Error.t) - u32.t := - M.call - ((core.ops.try_trait.Try.branch - (Self := core.result.Result.t u32.t erc721.Error.t) - (Trait := ltac:(refine _))) - α4) in - let* α6 : M.Val u32.t := - match α5 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t core.convert.Infallible.t erc721.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit erc721.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit erc721.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : u32.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α6 in - let* _ : M.Val (core.option.Option.t u32.t) := - let* α0 : mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := - M.read owned_tokens_count in - let* α1 : ref erc721.AccountId.t := M.read from in - let* α2 : erc721.AccountId.t := M.read (deref α1) in - let* α3 : u32.t := M.read count in - let* α4 : core.option.Option.t u32.t := - M.call - ((erc721.Mapping.t erc721.AccountId.t u32.t)::["insert"] - α0 - α2 - α3) in - M.alloc α4 in - let* _ : M.Val unit := - let* α0 : mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := - M.read token_owner in - let* α1 : u32.t := M.read id in - let* α2 : unit := - M.call - ((erc721.Mapping.t u32.t erc721.AccountId.t)::["remove"] - (borrow (deref α0)) - α1) in - M.alloc α2 in - let* α0 : M.Val (core.result.Result.t unit erc721.Error.t) := - M.alloc (core.result.Result.Ok tt) in + (let* α0 : M.Val (core.result.Result.t unit erc721.Error.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + {| + erc721.Erc721.token_owner := _; + erc721.Erc721.owned_tokens_count := _; + |} + => + let γ0 := γ.["Erc721.token_owner"] in + let γ1 := γ.["Erc721.owned_tokens_count"] in + let* token_owner := M.alloc (borrow γ0) in + let* owned_tokens_count := M.alloc (borrow γ1) in + let* _ : M.Val unit := + let* α0 : + mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := + M.read token_owner in + let* α1 : bool.t := + M.call + ((erc721.Mapping.t u32.t erc721.AccountId.t)::["contains"] + (borrow (deref α0)) + (borrow id)) in + let* α2 : M.Val bool.t := M.alloc (UnOp.not α1) in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val never.t := + return_ + (core.result.Result.Err erc721.Error.TokenNotFound) in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt in + let* count : M.Val u32.t := + let* α0 : + mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := + M.read owned_tokens_count in + let* α1 : ref erc721.AccountId.t := M.read from in + let* α2 : core.option.Option.t u32.t := + M.call + ((erc721.Mapping.t erc721.AccountId.t u32.t)::["get"] + (borrow (deref α0)) + α1) in + let* α3 : core.option.Option.t u32.t := + M.call + ((core.option.Option.t u32.t)::["map"] + α2 + (fun (α0 : u32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* c := M.copy γ in + let* α0 : u32.t := M.read c in + BinOp.Panic.sub α0 (Integer.of_Z 1)) : + M u32.t + ]) : + M u32.t)) in + let* α4 : core.result.Result.t u32.t erc721.Error.t := + M.call + ((core.option.Option.t u32.t)::["ok_or"] + α3 + erc721.Error.CannotFetchValue) in + let* α5 : + core.ops.control_flow.ControlFlow.t + (core.result.Result.t + core.convert.Infallible.t + erc721.Error.t) + u32.t := + M.call + ((core.ops.try_trait.Try.branch + (Self := core.result.Result.t u32.t erc721.Error.t) + (Trait := ltac:(refine _))) + α4) in + let* α6 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t + core.convert.Infallible.t + erc721.Error.t) + u32.t) := + M.alloc α5 in + let* α7 : M.Val u32.t := + match_operator + α6 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + erc721.Error.t := + M.read residual in + let* α1 : + core.result.Result.t unit erc721.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t unit erc721.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : u32.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val u32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val u32.t) + ] in + M.copy α7 in + let* _ : M.Val (core.option.Option.t u32.t) := + let* α0 : + mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := + M.read owned_tokens_count in + let* α1 : ref erc721.AccountId.t := M.read from in + let* α2 : erc721.AccountId.t := M.read (deref α1) in + let* α3 : u32.t := M.read count in + let* α4 : core.option.Option.t u32.t := + M.call + ((erc721.Mapping.t erc721.AccountId.t u32.t)::["insert"] + α0 + α2 + α3) in + M.alloc α4 in + let* _ : M.Val unit := + let* α0 : + mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := + M.read token_owner in + let* α1 : u32.t := M.read id in + let* α2 : unit := + M.call + ((erc721.Mapping.t u32.t erc721.AccountId.t)::["remove"] + (borrow (deref α0)) + α1) in + M.alloc α2 in + M.alloc (core.result.Result.Ok tt) + end) : + M (M.Val (core.result.Result.t unit erc721.Error.t)) + ] in M.read α0). Global Instance AssociatedFunction_remove_token_from : @@ -1649,110 +1761,139 @@ Section Impl_erc721_Erc721_t. let* id := M.alloc id in let return_ := M.return_ (R := core.result.Result.t unit erc721.Error.t) in M.catch_return - (let* '{| - erc721.Erc721.token_owner := token_owner; - erc721.Erc721.owned_tokens_count := owned_tokens_count; - |} : - mut_ref erc721.Erc721.t := - M.read self in - let* token_owner := M.alloc token_owner in - let* owned_tokens_count := M.alloc owned_tokens_count in - let* _ : M.Val unit := - let* α0 : mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := - M.read token_owner in - let* α1 : bool.t := - M.call - ((erc721.Mapping.t u32.t erc721.AccountId.t)::["contains"] - (borrow (deref α0)) - (borrow id)) in - let* α2 : M.Val bool.t := M.alloc α1 in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val never.t := - return_ (core.result.Result.Err erc721.Error.TokenExists) in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt in - let* _ : M.Val unit := - let* α0 : ref erc721.AccountId.t := M.read to in - let* α1 : erc721.AccountId.t := - M.call - ((core.convert.From.from - (Self := erc721.AccountId.t) - (Trait := ltac:(refine _))) - (repeat (Integer.of_Z 0) 32)) in - let* α2 : M.Val erc721.AccountId.t := M.alloc α1 in - let* α3 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := erc721.AccountId.t) - (Trait := ltac:(refine _))) - α0 - (borrow α2)) in - let* α4 : M.Val bool.t := M.alloc α3 in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* _ : M.Val never.t := - return_ (core.result.Result.Err erc721.Error.NotAllowed) in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt in - let* count : M.Val u32.t := - let* α0 : mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := - M.read owned_tokens_count in - let* α1 : ref erc721.AccountId.t := M.read to in - let* α2 : core.option.Option.t u32.t := - M.call - ((erc721.Mapping.t erc721.AccountId.t u32.t)::["get"] - (borrow (deref α0)) - α1) in - let* α3 : core.option.Option.t u32.t := - M.call - ((core.option.Option.t u32.t)::["map"] - α2 - (fun (c : u32.t) => - (let* c := M.alloc c in - let* α0 : u32.t := M.read c in - BinOp.Panic.add α0 (Integer.of_Z 1)) : - M u32.t)) in - let* α4 : u32.t := - M.call - ((core.option.Option.t u32.t)::["unwrap_or"] α3 (Integer.of_Z 1)) in - M.alloc α4 in - let* _ : M.Val (core.option.Option.t u32.t) := - let* α0 : mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := - M.read owned_tokens_count in - let* α1 : ref erc721.AccountId.t := M.read to in - let* α2 : erc721.AccountId.t := M.read (deref α1) in - let* α3 : u32.t := M.read count in - let* α4 : core.option.Option.t u32.t := - M.call - ((erc721.Mapping.t erc721.AccountId.t u32.t)::["insert"] - α0 - α2 - α3) in - M.alloc α4 in - let* _ : M.Val (core.option.Option.t u32.t) := - let* α0 : mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := - M.read token_owner in - let* α1 : u32.t := M.read id in - let* α2 : ref erc721.AccountId.t := M.read to in - let* α3 : erc721.AccountId.t := M.read (deref α2) in - let* α4 : core.option.Option.t u32.t := - M.call - ((erc721.Mapping.t u32.t erc721.AccountId.t)::["insert"] - α0 - α1 - α3) in - M.alloc α4 in - let* α0 : M.Val (core.result.Result.t unit erc721.Error.t) := - M.alloc (core.result.Result.Ok tt) in + (let* α0 : M.Val (core.result.Result.t unit erc721.Error.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + {| + erc721.Erc721.token_owner := _; + erc721.Erc721.owned_tokens_count := _; + |} + => + let γ0 := γ.["Erc721.token_owner"] in + let γ1 := γ.["Erc721.owned_tokens_count"] in + let* token_owner := M.alloc (borrow γ0) in + let* owned_tokens_count := M.alloc (borrow γ1) in + let* _ : M.Val unit := + let* α0 : + mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := + M.read token_owner in + let* α1 : bool.t := + M.call + ((erc721.Mapping.t u32.t erc721.AccountId.t)::["contains"] + (borrow (deref α0)) + (borrow id)) in + let* α2 : M.Val bool.t := M.alloc α1 in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val never.t := + return_ + (core.result.Result.Err erc721.Error.TokenExists) in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt in + let* _ : M.Val unit := + let* α0 : ref erc721.AccountId.t := M.read to in + let* α1 : erc721.AccountId.t := + M.call + ((core.convert.From.from + (Self := erc721.AccountId.t) + (Trait := ltac:(refine _))) + (repeat (Integer.of_Z 0) 32)) in + let* α2 : M.Val erc721.AccountId.t := M.alloc α1 in + let* α3 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := erc721.AccountId.t) + (Trait := ltac:(refine _))) + α0 + (borrow α2)) in + let* α4 : M.Val bool.t := M.alloc α3 in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* _ : M.Val never.t := + return_ + (core.result.Result.Err erc721.Error.NotAllowed) in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt in + let* count : M.Val u32.t := + let* α0 : + mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := + M.read owned_tokens_count in + let* α1 : ref erc721.AccountId.t := M.read to in + let* α2 : core.option.Option.t u32.t := + M.call + ((erc721.Mapping.t erc721.AccountId.t u32.t)::["get"] + (borrow (deref α0)) + α1) in + let* α3 : core.option.Option.t u32.t := + M.call + ((core.option.Option.t u32.t)::["map"] + α2 + (fun (α0 : u32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* c := M.copy γ in + let* α0 : u32.t := M.read c in + BinOp.Panic.add α0 (Integer.of_Z 1)) : + M u32.t + ]) : + M u32.t)) in + let* α4 : u32.t := + M.call + ((core.option.Option.t u32.t)::["unwrap_or"] + α3 + (Integer.of_Z 1)) in + M.alloc α4 in + let* _ : M.Val (core.option.Option.t u32.t) := + let* α0 : + mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := + M.read owned_tokens_count in + let* α1 : ref erc721.AccountId.t := M.read to in + let* α2 : erc721.AccountId.t := M.read (deref α1) in + let* α3 : u32.t := M.read count in + let* α4 : core.option.Option.t u32.t := + M.call + ((erc721.Mapping.t erc721.AccountId.t u32.t)::["insert"] + α0 + α2 + α3) in + M.alloc α4 in + let* _ : M.Val (core.option.Option.t u32.t) := + let* α0 : + mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := + M.read token_owner in + let* α1 : u32.t := M.read id in + let* α2 : ref erc721.AccountId.t := M.read to in + let* α3 : erc721.AccountId.t := M.read (deref α2) in + let* α4 : core.option.Option.t u32.t := + M.call + ((erc721.Mapping.t u32.t erc721.AccountId.t)::["insert"] + α0 + α1 + α3) in + M.alloc α4 in + M.alloc (core.result.Result.Ok tt) + end) : + M (M.Val (core.result.Result.t unit erc721.Error.t)) + ] in M.read α0). Global Instance AssociatedFunction_add_token_to : @@ -1862,26 +2003,50 @@ Section Impl_erc721_Erc721_t. (Self := core.result.Result.t unit erc721.Error.t) (Trait := ltac:(refine _))) α3) in - match α4 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t core.convert.Infallible.t erc721.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit erc721.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit erc721.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α5 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t erc721.Error.t) + unit) := + M.alloc α4 in + match_operator + α5 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + erc721.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit erc721.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.result.Result.t unit erc721.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : mut_ref erc721.Erc721.t := M.read self in let* α1 : ref erc721.AccountId.t := M.read to in @@ -1897,26 +2062,50 @@ Section Impl_erc721_Erc721_t. (Self := core.result.Result.t unit erc721.Error.t) (Trait := ltac:(refine _))) α3) in - match α4 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t core.convert.Infallible.t erc721.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit erc721.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit erc721.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α5 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t erc721.Error.t) + unit) := + M.alloc α4 in + match_operator + α5 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + erc721.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit erc721.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.result.Result.t unit erc721.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : mut_ref erc721.Erc721.t := M.read self in let* α1 : erc721.Env.t := @@ -1991,26 +2180,50 @@ Section Impl_erc721_Erc721_t. (Self := core.result.Result.t unit erc721.Error.t) (Trait := ltac:(refine _))) α2) in - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t core.convert.Infallible.t erc721.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit erc721.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit erc721.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t erc721.Error.t) + unit) := + M.alloc α3 in + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + erc721.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit erc721.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.result.Result.t unit erc721.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* α0 : M.Val (core.result.Result.t unit erc721.Error.t) := M.alloc (core.result.Result.Ok tt) in M.read α0). @@ -2062,26 +2275,50 @@ Section Impl_erc721_Erc721_t. (Self := core.result.Result.t unit erc721.Error.t) (Trait := ltac:(refine _))) α2) in - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t core.convert.Infallible.t erc721.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit erc721.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit erc721.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t erc721.Error.t) + unit) := + M.alloc α3 in + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + erc721.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit erc721.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.result.Result.t unit erc721.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* α0 : M.Val (core.result.Result.t unit erc721.Error.t) := M.alloc (core.result.Result.Ok tt) in M.read α0). @@ -2133,26 +2370,50 @@ Section Impl_erc721_Erc721_t. (Self := core.result.Result.t unit erc721.Error.t) (Trait := ltac:(refine _))) α2) in - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t core.convert.Infallible.t erc721.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit erc721.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit erc721.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t erc721.Error.t) + unit) := + M.alloc α3 in + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + erc721.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit erc721.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.result.Result.t unit erc721.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : mut_ref erc721.Erc721.t := M.read self in let* α1 : erc721.Env.t := @@ -2232,178 +2493,267 @@ Section Impl_erc721_Erc721_t. let* α3 : erc721.AccountId.t := M.call (erc721.Env.t::["caller"] (borrow α2)) in M.alloc α3 in - let* '{| - erc721.Erc721.token_owner := token_owner; - erc721.Erc721.owned_tokens_count := owned_tokens_count; - |} : - mut_ref erc721.Erc721.t := - M.read self in - let* token_owner := M.alloc token_owner in - let* owned_tokens_count := M.alloc owned_tokens_count in - let* owner : M.Val erc721.AccountId.t := - let* α0 : mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := - M.read token_owner in - let* α1 : core.option.Option.t erc721.AccountId.t := - M.call - ((erc721.Mapping.t u32.t erc721.AccountId.t)::["get"] - (borrow (deref α0)) - (borrow id)) in - let* α2 : core.result.Result.t erc721.AccountId.t erc721.Error.t := - M.call - ((core.option.Option.t erc721.AccountId.t)::["ok_or"] - α1 - erc721.Error.TokenNotFound) in - let* α3 : - core.ops.control_flow.ControlFlow.t - (core.result.Result.t core.convert.Infallible.t erc721.Error.t) - erc721.AccountId.t := - M.call - ((core.ops.try_trait.Try.branch - (Self := core.result.Result.t erc721.AccountId.t erc721.Error.t) - (Trait := ltac:(refine _))) - α2) in - let* α4 : M.Val erc721.AccountId.t := - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t core.convert.Infallible.t erc721.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit erc721.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit erc721.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : erc721.AccountId.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α4 in - let* _ : M.Val unit := - let* α0 : bool.t := - M.call - ((core.cmp.PartialEq.ne - (Self := erc721.AccountId.t) - (Trait := ltac:(refine _))) - (borrow owner) - (borrow caller)) in - let* α1 : M.Val bool.t := M.alloc α0 in - let* α2 : bool.t := M.read (use α1) in - if α2 then - let* _ : M.Val never.t := - return_ (core.result.Result.Err erc721.Error.NotOwner) in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt in - let* count : M.Val u32.t := - let* α0 : mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := - M.read owned_tokens_count in - let* α1 : core.option.Option.t u32.t := - M.call - ((erc721.Mapping.t erc721.AccountId.t u32.t)::["get"] - (borrow (deref α0)) - (borrow caller)) in - let* α2 : core.option.Option.t u32.t := - M.call - ((core.option.Option.t u32.t)::["map"] - α1 - (fun (c : u32.t) => - (let* c := M.alloc c in - let* α0 : u32.t := M.read c in - BinOp.Panic.sub α0 (Integer.of_Z 1)) : - M u32.t)) in - let* α3 : core.result.Result.t u32.t erc721.Error.t := - M.call - ((core.option.Option.t u32.t)::["ok_or"] - α2 - erc721.Error.CannotFetchValue) in - let* α4 : - core.ops.control_flow.ControlFlow.t - (core.result.Result.t core.convert.Infallible.t erc721.Error.t) - u32.t := - M.call - ((core.ops.try_trait.Try.branch - (Self := core.result.Result.t u32.t erc721.Error.t) - (Trait := ltac:(refine _))) - α3) in - let* α5 : M.Val u32.t := - match α4 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t core.convert.Infallible.t erc721.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit erc721.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit erc721.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : u32.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α5 in - let* _ : M.Val (core.option.Option.t u32.t) := - let* α0 : mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := - M.read owned_tokens_count in - let* α1 : erc721.AccountId.t := M.read caller in - let* α2 : u32.t := M.read count in - let* α3 : core.option.Option.t u32.t := - M.call - ((erc721.Mapping.t erc721.AccountId.t u32.t)::["insert"] - α0 - α1 - α2) in - M.alloc α3 in - let* _ : M.Val unit := - let* α0 : mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := - M.read token_owner in - let* α1 : u32.t := M.read id in - let* α2 : unit := - M.call - ((erc721.Mapping.t u32.t erc721.AccountId.t)::["remove"] - (borrow (deref α0)) - α1) in - M.alloc α2 in - let* _ : M.Val unit := - let* α0 : mut_ref erc721.Erc721.t := M.read self in - let* α1 : erc721.Env.t := - M.call (erc721.Erc721.t::["env"] (borrow (deref α0))) in - let* α2 : M.Val erc721.Env.t := M.alloc α1 in - let* α3 : erc721.AccountId.t := M.read caller in - let* α4 : erc721.AccountId.t := - M.call - ((core.convert.From.from - (Self := erc721.AccountId.t) - (Trait := ltac:(refine _))) - (repeat (Integer.of_Z 0) 32)) in - let* α5 : u32.t := M.read id in - let* α6 : unit := - M.call - (erc721.Env.t::["emit_event"] - (borrow α2) - (erc721.Event.Transfer - {| - erc721.Transfer.from := core.option.Option.Some α3; - erc721.Transfer.to := core.option.Option.Some α4; - erc721.Transfer.id := α5; - |})) in - M.alloc α6 in let* α0 : M.Val (core.result.Result.t unit erc721.Error.t) := - M.alloc (core.result.Result.Ok tt) in + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + {| + erc721.Erc721.token_owner := _; + erc721.Erc721.owned_tokens_count := _; + |} + => + let γ0 := γ.["Erc721.token_owner"] in + let γ1 := γ.["Erc721.owned_tokens_count"] in + let* token_owner := M.alloc (borrow γ0) in + let* owned_tokens_count := M.alloc (borrow γ1) in + let* owner : M.Val erc721.AccountId.t := + let* α0 : + mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := + M.read token_owner in + let* α1 : core.option.Option.t erc721.AccountId.t := + M.call + ((erc721.Mapping.t u32.t erc721.AccountId.t)::["get"] + (borrow (deref α0)) + (borrow id)) in + let* α2 : + core.result.Result.t erc721.AccountId.t erc721.Error.t := + M.call + ((core.option.Option.t erc721.AccountId.t)::["ok_or"] + α1 + erc721.Error.TokenNotFound) in + let* α3 : + core.ops.control_flow.ControlFlow.t + (core.result.Result.t + core.convert.Infallible.t + erc721.Error.t) + erc721.AccountId.t := + M.call + ((core.ops.try_trait.Try.branch + (Self := + core.result.Result.t + erc721.AccountId.t + erc721.Error.t) + (Trait := ltac:(refine _))) + α2) in + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t + core.convert.Infallible.t + erc721.Error.t) + erc721.AccountId.t) := + M.alloc α3 in + let* α5 : M.Val erc721.AccountId.t := + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + erc721.Error.t := + M.read residual in + let* α1 : + core.result.Result.t unit erc721.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t unit erc721.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : erc721.AccountId.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val erc721.AccountId.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val erc721.AccountId.t) + ] in + M.copy α5 in + let* _ : M.Val unit := + let* α0 : bool.t := + M.call + ((core.cmp.PartialEq.ne + (Self := erc721.AccountId.t) + (Trait := ltac:(refine _))) + (borrow owner) + (borrow caller)) in + let* α1 : M.Val bool.t := M.alloc α0 in + let* α2 : bool.t := M.read (use α1) in + if α2 then + let* _ : M.Val never.t := + return_ (core.result.Result.Err erc721.Error.NotOwner) in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt in + let* count : M.Val u32.t := + let* α0 : + mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := + M.read owned_tokens_count in + let* α1 : core.option.Option.t u32.t := + M.call + ((erc721.Mapping.t erc721.AccountId.t u32.t)::["get"] + (borrow (deref α0)) + (borrow caller)) in + let* α2 : core.option.Option.t u32.t := + M.call + ((core.option.Option.t u32.t)::["map"] + α1 + (fun (α0 : u32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* c := M.copy γ in + let* α0 : u32.t := M.read c in + BinOp.Panic.sub α0 (Integer.of_Z 1)) : + M u32.t + ]) : + M u32.t)) in + let* α3 : core.result.Result.t u32.t erc721.Error.t := + M.call + ((core.option.Option.t u32.t)::["ok_or"] + α2 + erc721.Error.CannotFetchValue) in + let* α4 : + core.ops.control_flow.ControlFlow.t + (core.result.Result.t + core.convert.Infallible.t + erc721.Error.t) + u32.t := + M.call + ((core.ops.try_trait.Try.branch + (Self := core.result.Result.t u32.t erc721.Error.t) + (Trait := ltac:(refine _))) + α3) in + let* α5 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t + core.convert.Infallible.t + erc721.Error.t) + u32.t) := + M.alloc α4 in + let* α6 : M.Val u32.t := + match_operator + α5 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + erc721.Error.t := + M.read residual in + let* α1 : + core.result.Result.t unit erc721.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t unit erc721.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : u32.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val u32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val u32.t) + ] in + M.copy α6 in + let* _ : M.Val (core.option.Option.t u32.t) := + let* α0 : + mut_ref (erc721.Mapping.t erc721.AccountId.t u32.t) := + M.read owned_tokens_count in + let* α1 : erc721.AccountId.t := M.read caller in + let* α2 : u32.t := M.read count in + let* α3 : core.option.Option.t u32.t := + M.call + ((erc721.Mapping.t erc721.AccountId.t u32.t)::["insert"] + α0 + α1 + α2) in + M.alloc α3 in + let* _ : M.Val unit := + let* α0 : + mut_ref (erc721.Mapping.t u32.t erc721.AccountId.t) := + M.read token_owner in + let* α1 : u32.t := M.read id in + let* α2 : unit := + M.call + ((erc721.Mapping.t u32.t erc721.AccountId.t)::["remove"] + (borrow (deref α0)) + α1) in + M.alloc α2 in + let* _ : M.Val unit := + let* α0 : mut_ref erc721.Erc721.t := M.read self in + let* α1 : erc721.Env.t := + M.call (erc721.Erc721.t::["env"] (borrow (deref α0))) in + let* α2 : M.Val erc721.Env.t := M.alloc α1 in + let* α3 : erc721.AccountId.t := M.read caller in + let* α4 : erc721.AccountId.t := + M.call + ((core.convert.From.from + (Self := erc721.AccountId.t) + (Trait := ltac:(refine _))) + (repeat (Integer.of_Z 0) 32)) in + let* α5 : u32.t := M.read id in + let* α6 : unit := + M.call + (erc721.Env.t::["emit_event"] + (borrow α2) + (erc721.Event.Transfer + {| + erc721.Transfer.from := core.option.Option.Some α3; + erc721.Transfer.to := core.option.Option.Some α4; + erc721.Transfer.id := α5; + |})) in + M.alloc α6 in + M.alloc (core.result.Result.Ok tt) + end) : + M (M.Val (core.result.Result.t unit erc721.Error.t)) + ] in M.read α0). Global Instance AssociatedFunction_burn : diff --git a/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/call_builder.v b/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/call_builder.v index a43f5dfc2..b796ceadb 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/call_builder.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/call_builder.v @@ -49,9 +49,17 @@ Section Impl_core_clone_Clone_for_call_builder_AccountId_t. *) Definition clone (self : ref Self) : M call_builder.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref call_builder.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val call_builder.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref call_builder.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val call_builder.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -190,38 +198,64 @@ Section Impl_call_builder_CallBuilderTest_t. let* α2 : core.result.Result.t unit call_builder.LangError.t := never_to_any α1 in M.alloc α2 in - let* α0 : core.result.Result.t unit call_builder.LangError.t := - M.read result in let* α0 : M.Val (core.option.Option.t call_builder.LangError.t) := - match α0 with - | core.result.Result.Ok _ => M.alloc core.option.Option.None - | - core.result.Result.Err (call_builder.LangError.CouldNotReadInput as e) - => - let* e := M.alloc e in - let* α0 : call_builder.LangError.t := M.read e in - M.alloc (core.option.Option.Some α0) - | core.result.Result.Err _ => - let* α0 : ref str.t := - M.read - (mk_str - "not implemented: No other `LangError` variants exist at the moment.") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ ] in - let* α5 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α4) in - let* α6 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α5) in - let* α7 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α3 α6) in - let* α8 : never.t := M.call (core.panicking.panic_fmt α7) in - let* α9 : core.option.Option.t call_builder.LangError.t := - never_to_any α8 in - M.alloc α9 - end in + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + M.alloc core.option.Option.None + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t call_builder.LangError.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* α0 := M.read γ0 in + match α0 with + | call_builder.LangError.CouldNotReadInput => + let* α0 : call_builder.LangError.t := M.read e in + M.alloc (core.option.Option.Some α0) + | _ => M.break_match + end + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t call_builder.LangError.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* α0 : ref str.t := + M.read + (mk_str + "not implemented: No other `LangError` variants exist at the moment.") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ ] in + let* α5 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α4) in + let* α6 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α5) in + let* α7 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α3 α6) in + let* α8 : never.t := M.call (core.panicking.panic_fmt α7) in + let* α9 : core.option.Option.t call_builder.LangError.t := + never_to_any α8 in + M.alloc α9 + | _ => M.break_match + end) : + M (M.Val (core.option.Option.t call_builder.LangError.t)) + ] in M.read α0. Global Instance AssociatedFunction_call : diff --git a/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/constructors_return_value.v b/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/constructors_return_value.v index 87e698c3a..b7bacb994 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/constructors_return_value.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/constructors_return_value.v @@ -51,9 +51,18 @@ Section Impl_core_clone_Clone_for_constructors_return_value_AccountId_t. (self : ref Self) : M constructors_return_value.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref constructors_return_value.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val constructors_return_value.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref constructors_return_value.AccountId.t := + M.read self in + M.pure (deref α0)) : + M (M.Val constructors_return_value.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/contract_ref.v b/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/contract_ref.v index 95b6cac1f..4a746c001 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/contract_ref.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/lang_err_integration_tests/contract_ref.v @@ -49,9 +49,17 @@ Section Impl_core_clone_Clone_for_contract_ref_AccountId_t. *) Definition clone (self : ref Self) : M contract_ref.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref contract_ref.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val contract_ref.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref contract_ref.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val contract_ref.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/mapping_integration_tests.v b/CoqOfRust/examples/default/examples/ink_contracts/mapping_integration_tests.v index 41130714b..ae9506217 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/mapping_integration_tests.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/mapping_integration_tests.v @@ -254,9 +254,18 @@ Section Impl_core_clone_Clone_for_mapping_integration_tests_AccountId_t. (self : ref Self) : M mapping_integration_tests.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref mapping_integration_tests.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val mapping_integration_tests.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref mapping_integration_tests.AccountId.t := + M.read self in + M.pure (deref α0)) : + M (M.Val mapping_integration_tests.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/mother.v b/CoqOfRust/examples/default/examples/ink_contracts/mother.v index 9d4a53f48..bb191296e 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/mother.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/mother.v @@ -159,9 +159,17 @@ Section Impl_core_clone_Clone_for_mother_AccountId_t. *) Definition clone (self : ref Self) : M mother.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref mother.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val mother.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref mother.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val mother.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -240,9 +248,10 @@ Section Impl_core_cmp_Eq_for_mother_AccountId_t. *) Definition assert_receiver_is_total_eq (self : ref Self) : M unit := let* self := M.alloc self in - let _ : unit := tt in let* α0 : M.Val unit := M.alloc tt in - M.read α0. + let* α1 : M.Val unit := + match_operator α0 [ fun γ => (M.alloc tt) : M (M.Val unit) ] in + M.read α1. Global Instance AssociatedFunction_assert_receiver_is_total_eq : Notations.DoubleColon Self "assert_receiver_is_total_eq" := { @@ -398,9 +407,10 @@ Section Impl_core_cmp_Eq_for_mother_Bids_t. *) Definition assert_receiver_is_total_eq (self : ref Self) : M unit := let* self := M.alloc self in - let _ : unit := tt in let* α0 : M.Val unit := M.alloc tt in - M.read α0. + let* α1 : M.Val unit := + match_operator α0 [ fun γ => (M.alloc tt) : M (M.Val unit) ] in + M.read α1. Global Instance AssociatedFunction_assert_receiver_is_total_eq : Notations.DoubleColon Self "assert_receiver_is_total_eq" := { @@ -547,15 +557,44 @@ Section Impl_core_clone_Clone_for_mother_Outline_t. *) Definition clone (self : ref Self) : M mother.Outline.t := let* self := M.alloc self in - let* α0 : ref mother.Outline.t := M.read self in - let* α1 := M.read α0 in - let* α2 : M.Val mother.Outline.t := - match α1 with - | mother.Outline.NoWinner => M.alloc mother.Outline.NoWinner - | mother.Outline.WinnerDetected => M.alloc mother.Outline.WinnerDetected - | mother.Outline.PayoutCompleted => M.alloc mother.Outline.PayoutCompleted - end in - M.read α2. + let* α0 : M.Val mother.Outline.t := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | mother.Outline.NoWinner => M.alloc mother.Outline.NoWinner + | _ => M.break_match + end) : + M (M.Val mother.Outline.t); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | mother.Outline.WinnerDetected => + M.alloc mother.Outline.WinnerDetected + | _ => M.break_match + end) : + M (M.Val mother.Outline.t); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | mother.Outline.PayoutCompleted => + M.alloc mother.Outline.PayoutCompleted + | _ => M.break_match + end) : + M (M.Val mother.Outline.t) + ] in + M.read α0. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -635,45 +674,121 @@ Section Impl_core_cmp_PartialEq_for_mother_Status_t. let* α1 : isize.t := M.read __arg1_tag in let* α2 : ref mother.Status.t := M.read self in let* α3 : ref mother.Status.t := M.read other in - let* α4 : M.Val bool.t := - match (α2, α3) with - | - (mother.Status.EndingPeriod __self_0, - mother.Status.EndingPeriod __arg1_0) - => - let* __self_0 := M.alloc __self_0 in - let* __arg1_0 := M.alloc __arg1_0 in - let* α0 : ref u32.t := M.read __self_0 in - let* α1 : u32.t := M.read (deref α0) in - let* α2 : ref u32.t := M.read __arg1_0 in - let* α3 : u32.t := M.read (deref α2) in - M.alloc (BinOp.Pure.eq α1 α3) - | (mother.Status.Ended __self_0, mother.Status.Ended __arg1_0) => - let* __self_0 := M.alloc __self_0 in - let* __arg1_0 := M.alloc __arg1_0 in - let* α0 : ref mother.Outline.t := M.read __self_0 in - let* α1 : ref mother.Outline.t := M.read __arg1_0 in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := mother.Outline.t) - (Trait := ltac:(refine _))) - α0 - α1) in - M.alloc α2 - | (mother.Status.RfDelay __self_0, mother.Status.RfDelay __arg1_0) => - let* __self_0 := M.alloc __self_0 in - let* __arg1_0 := M.alloc __arg1_0 in - let* α0 : ref u32.t := M.read __self_0 in - let* α1 : u32.t := M.read (deref α0) in - let* α2 : ref u32.t := M.read __arg1_0 in - let* α3 : u32.t := M.read (deref α2) in - M.alloc (BinOp.Pure.eq α1 α3) - | _ => M.alloc true - end in - let* α5 : bool.t := M.read α4 in + let* α4 : M.Val ((ref mother.Status.t) * (ref mother.Status.t)) := + M.alloc (α2, α3) in + let* α5 : M.Val bool.t := + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* γ0 := + let* α0 := M.read γ0 in + M.pure (deref α0) in + let* α0 := M.read γ0 in + match α0 with + | mother.Status.EndingPeriod _ => + let γ0 := γ0.["EndingPeriod.0"] in + let* __self_0 := M.alloc (borrow_mut γ0) in + let* γ1 := + let* α0 := M.read γ1 in + M.pure (deref α0) in + let* α0 := M.read γ1 in + match α0 with + | mother.Status.EndingPeriod _ => + let γ0 := γ1.["EndingPeriod.0"] in + let* __arg1_0 := M.alloc (borrow_mut γ0) in + let* α0 : ref u32.t := M.read __self_0 in + let* α1 : u32.t := M.read (deref α0) in + let* α2 : ref u32.t := M.read __arg1_0 in + let* α3 : u32.t := M.read (deref α2) in + M.alloc (BinOp.Pure.eq α1 α3) + | _ => M.break_match + end + | _ => M.break_match + end + end) : + M (M.Val bool.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* γ0 := + let* α0 := M.read γ0 in + M.pure (deref α0) in + let* α0 := M.read γ0 in + match α0 with + | mother.Status.Ended _ => + let γ0 := γ0.["Ended.0"] in + let* __self_0 := M.alloc (borrow_mut γ0) in + let* γ1 := + let* α0 := M.read γ1 in + M.pure (deref α0) in + let* α0 := M.read γ1 in + match α0 with + | mother.Status.Ended _ => + let γ0 := γ1.["Ended.0"] in + let* __arg1_0 := M.alloc (borrow_mut γ0) in + let* α0 : ref mother.Outline.t := M.read __self_0 in + let* α1 : ref mother.Outline.t := M.read __arg1_0 in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := mother.Outline.t) + (Trait := ltac:(refine _))) + α0 + α1) in + M.alloc α2 + | _ => M.break_match + end + | _ => M.break_match + end + end) : + M (M.Val bool.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* γ0 := + let* α0 := M.read γ0 in + M.pure (deref α0) in + let* α0 := M.read γ0 in + match α0 with + | mother.Status.RfDelay _ => + let γ0 := γ0.["RfDelay.0"] in + let* __self_0 := M.alloc (borrow_mut γ0) in + let* γ1 := + let* α0 := M.read γ1 in + M.pure (deref α0) in + let* α0 := M.read γ1 in + match α0 with + | mother.Status.RfDelay _ => + let γ0 := γ1.["RfDelay.0"] in + let* __arg1_0 := M.alloc (borrow_mut γ0) in + let* α0 : ref u32.t := M.read __self_0 in + let* α1 : u32.t := M.read (deref α0) in + let* α2 : ref u32.t := M.read __arg1_0 in + let* α3 : u32.t := M.read (deref α2) in + M.alloc (BinOp.Pure.eq α1 α3) + | _ => M.break_match + end + | _ => M.break_match + end + end) : + M (M.Val bool.t); + fun γ => (M.alloc true) : M (M.Val bool.t) + ] in + let* α6 : bool.t := M.read α5 in let* α0 : M.Val bool.t := - M.alloc (BinOp.Pure.and (BinOp.Pure.eq α0 α1) α5) in + M.alloc (BinOp.Pure.and (BinOp.Pure.eq α0 α1) α6) in M.read α0. Global Instance AssociatedFunction_eq : Notations.DoubleColon Self "eq" := { @@ -707,10 +822,17 @@ Section Impl_core_cmp_Eq_for_mother_Status_t. *) Definition assert_receiver_is_total_eq (self : ref Self) : M unit := let* self := M.alloc self in - let _ : unit := tt in - let _ : unit := tt in let* α0 : M.Val unit := M.alloc tt in - M.read α0. + let* α1 : M.Val unit := + match_operator + α0 + [ + fun γ => + (let* α0 : M.Val unit := M.alloc tt in + match_operator α0 [ fun γ => (M.alloc tt) : M (M.Val unit) ]) : + M (M.Val unit) + ] in + M.read α1. Global Instance AssociatedFunction_assert_receiver_is_total_eq : Notations.DoubleColon Self "assert_receiver_is_total_eq" := { @@ -733,39 +855,92 @@ Section Impl_core_clone_Clone_for_mother_Status_t. *) Definition clone (self : ref Self) : M mother.Status.t := let* self := M.alloc self in - let* α0 : ref mother.Status.t := M.read self in - let* α1 : M.Val mother.Status.t := - match α0 with - | mother.Status.NotStarted => M.alloc mother.Status.NotStarted - | mother.Status.OpeningPeriod => M.alloc mother.Status.OpeningPeriod - | mother.Status.EndingPeriod __self_0 => - let* __self_0 := M.alloc __self_0 in - let* α0 : ref u32.t := M.read __self_0 in - let* α1 : u32.t := - M.call - ((core.clone.Clone.clone (Self := u32.t) (Trait := ltac:(refine _))) - α0) in - M.alloc (mother.Status.EndingPeriod α1) - | mother.Status.Ended __self_0 => - let* __self_0 := M.alloc __self_0 in - let* α0 : ref mother.Outline.t := M.read __self_0 in - let* α1 : mother.Outline.t := - M.call - ((core.clone.Clone.clone - (Self := mother.Outline.t) - (Trait := ltac:(refine _))) - α0) in - M.alloc (mother.Status.Ended α1) - | mother.Status.RfDelay __self_0 => - let* __self_0 := M.alloc __self_0 in - let* α0 : ref u32.t := M.read __self_0 in - let* α1 : u32.t := - M.call - ((core.clone.Clone.clone (Self := u32.t) (Trait := ltac:(refine _))) - α0) in - M.alloc (mother.Status.RfDelay α1) - end in - M.read α1. + let* α0 : M.Val mother.Status.t := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | mother.Status.NotStarted => M.alloc mother.Status.NotStarted + | _ => M.break_match + end) : + M (M.Val mother.Status.t); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | mother.Status.OpeningPeriod => M.alloc mother.Status.OpeningPeriod + | _ => M.break_match + end) : + M (M.Val mother.Status.t); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | mother.Status.EndingPeriod _ => + let γ0 := γ.["EndingPeriod.0"] in + let* __self_0 := M.alloc (borrow_mut γ0) in + let* α0 : ref u32.t := M.read __self_0 in + let* α1 : u32.t := + M.call + ((core.clone.Clone.clone + (Self := u32.t) + (Trait := ltac:(refine _))) + α0) in + M.alloc (mother.Status.EndingPeriod α1) + | _ => M.break_match + end) : + M (M.Val mother.Status.t); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | mother.Status.Ended _ => + let γ0 := γ.["Ended.0"] in + let* __self_0 := M.alloc (borrow_mut γ0) in + let* α0 : ref mother.Outline.t := M.read __self_0 in + let* α1 : mother.Outline.t := + M.call + ((core.clone.Clone.clone + (Self := mother.Outline.t) + (Trait := ltac:(refine _))) + α0) in + M.alloc (mother.Status.Ended α1) + | _ => M.break_match + end) : + M (M.Val mother.Status.t); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | mother.Status.RfDelay _ => + let γ0 := γ.["RfDelay.0"] in + let* __self_0 := M.alloc (borrow_mut γ0) in + let* α0 : ref u32.t := M.read __self_0 in + let* α1 : u32.t := + M.call + ((core.clone.Clone.clone + (Self := u32.t) + (Trait := ltac:(refine _))) + α0) in + M.alloc (mother.Status.RfDelay α1) + | _ => M.break_match + end) : + M (M.Val mother.Status.t) + ] in + M.read α0. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -932,7 +1107,7 @@ Section Impl_core_cmp_PartialEq_for_mother_Auction_t. (BinOp.Pure.and (BinOp.Pure.and (BinOp.Pure.and (BinOp.Pure.and α2 α5) α8) α11) α14) - (BinOp.Pure.eq α16 α18)) + (Bool.eqb α16 α18)) α21). Global Instance AssociatedFunction_eq : Notations.DoubleColon Self "eq" := { @@ -966,15 +1141,57 @@ Section Impl_core_cmp_Eq_for_mother_Auction_t. *) Definition assert_receiver_is_total_eq (self : ref Self) : M unit := let* self := M.alloc self in - let _ : unit := tt in - let _ : unit := tt in - let _ : unit := tt in - let _ : unit := tt in - let _ : unit := tt in - let _ : unit := tt in - let _ : unit := tt in let* α0 : M.Val unit := M.alloc tt in - M.read α0. + let* α1 : M.Val unit := + match_operator + α0 + [ + fun γ => + (let* α0 : M.Val unit := M.alloc tt in + match_operator + α0 + [ + fun γ => + (let* α0 : M.Val unit := M.alloc tt in + match_operator + α0 + [ + fun γ => + (let* α0 : M.Val unit := M.alloc tt in + match_operator + α0 + [ + fun γ => + (let* α0 : M.Val unit := M.alloc tt in + match_operator + α0 + [ + fun γ => + (let* α0 : M.Val unit := M.alloc tt in + match_operator + α0 + [ + fun γ => + (let* α0 : M.Val unit := M.alloc tt in + match_operator + α0 + [ + fun γ => + (M.alloc tt) : M (M.Val unit) + ]) : + M (M.Val unit) + ]) : + M (M.Val unit) + ]) : + M (M.Val unit) + ]) : + M (M.Val unit) + ]) : + M (M.Val unit) + ]) : + M (M.Val unit) + ] in + M.read α1. Global Instance AssociatedFunction_assert_receiver_is_total_eq : Notations.DoubleColon Self "assert_receiver_is_total_eq" := { @@ -1176,26 +1393,55 @@ Section Impl_core_cmp_PartialEq_for_mother_Failure_t. let* α1 : isize.t := M.read __arg1_tag in let* α2 : ref mother.Failure.t := M.read self in let* α3 : ref mother.Failure.t := M.read other in - let* α4 : M.Val bool.t := - match (α2, α3) with - | (mother.Failure.Revert __self_0, mother.Failure.Revert __arg1_0) => - let* __self_0 := M.alloc __self_0 in - let* __arg1_0 := M.alloc __arg1_0 in - let* α0 : ref alloc.string.String.t := M.read __self_0 in - let* α1 : ref alloc.string.String.t := M.read __arg1_0 in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := alloc.string.String.t) - (Trait := ltac:(refine _))) - α0 - α1) in - M.alloc α2 - | _ => M.alloc true - end in - let* α5 : bool.t := M.read α4 in + let* α4 : M.Val ((ref mother.Failure.t) * (ref mother.Failure.t)) := + M.alloc (α2, α3) in + let* α5 : M.Val bool.t := + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* γ0 := + let* α0 := M.read γ0 in + M.pure (deref α0) in + let* α0 := M.read γ0 in + match α0 with + | mother.Failure.Revert _ => + let γ0 := γ0.["Revert.0"] in + let* __self_0 := M.alloc (borrow_mut γ0) in + let* γ1 := + let* α0 := M.read γ1 in + M.pure (deref α0) in + let* α0 := M.read γ1 in + match α0 with + | mother.Failure.Revert _ => + let γ0 := γ1.["Revert.0"] in + let* __arg1_0 := M.alloc (borrow_mut γ0) in + let* α0 : ref alloc.string.String.t := M.read __self_0 in + let* α1 : ref alloc.string.String.t := M.read __arg1_0 in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := alloc.string.String.t) + (Trait := ltac:(refine _))) + α0 + α1) in + M.alloc α2 + | _ => M.break_match + end + | _ => M.break_match + end + end) : + M (M.Val bool.t); + fun γ => (M.alloc true) : M (M.Val bool.t) + ] in + let* α6 : bool.t := M.read α5 in let* α0 : M.Val bool.t := - M.alloc (BinOp.Pure.and (BinOp.Pure.eq α0 α1) α5) in + M.alloc (BinOp.Pure.and (BinOp.Pure.eq α0 α1) α6) in M.read α0. Global Instance AssociatedFunction_eq : Notations.DoubleColon Self "eq" := { @@ -1229,9 +1475,10 @@ Section Impl_core_cmp_Eq_for_mother_Failure_t. *) Definition assert_receiver_is_total_eq (self : ref Self) : M unit := let* self := M.alloc self in - let _ : unit := tt in let* α0 : M.Val unit := M.alloc tt in - M.read α0. + let* α1 : M.Val unit := + match_operator α0 [ fun γ => (M.alloc tt) : M (M.Val unit) ] in + M.read α1. Global Instance AssociatedFunction_assert_receiver_is_total_eq : Notations.DoubleColon Self "assert_receiver_is_total_eq" := { @@ -1539,27 +1786,61 @@ Section Impl_mother_Mother_t. : M (core.result.Result.t unit mother.Failure.t) := let* self := M.alloc self in let* fail := M.alloc fail in - let* α0 : core.option.Option.t mother.Failure.t := M.read fail in - let* α1 : M.Val (core.result.Result.t unit mother.Failure.t) := - match α0 with - | core.option.Option.Some (mother.Failure.Revert _) => - let* α0 : ref str.t := M.read (mk_str "Reverting on user demand!") in - let* α1 : alloc.string.String.t := - M.call - ((alloc.string.ToString.to_string - (Self := str.t) - (Trait := ltac:(refine _))) - α0) in - M.alloc (core.result.Result.Err (mother.Failure.Revert α1)) - | core.option.Option.Some mother.Failure.Panic => - let* α0 : ref str.t := M.read (mk_str "Trapping on user demand!") in - let* α1 : never.t := M.call (std.panicking.begin_panic α0) in - let* α2 : core.result.Result.t unit mother.Failure.t := - never_to_any α1 in - M.alloc α2 - | core.option.Option.None => M.alloc (core.result.Result.Ok tt) - end in - M.read α1. + let* α0 : M.Val (core.result.Result.t unit mother.Failure.t) := + match_operator + fail + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* α0 := M.read γ0 in + match α0 with + | mother.Failure.Revert _ => + let γ0 := γ0.["Revert.0"] in + let* α0 : ref str.t := + M.read (mk_str "Reverting on user demand!") in + let* α1 : alloc.string.String.t := + M.call + ((alloc.string.ToString.to_string + (Self := str.t) + (Trait := ltac:(refine _))) + α0) in + M.alloc (core.result.Result.Err (mother.Failure.Revert α1)) + | _ => M.break_match + end + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit mother.Failure.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* α0 := M.read γ0 in + match α0 with + | mother.Failure.Panic => + let* α0 : ref str.t := + M.read (mk_str "Trapping on user demand!") in + let* α1 : never.t := M.call (std.panicking.begin_panic α0) in + let* α2 : core.result.Result.t unit mother.Failure.t := + never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit mother.Failure.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => M.alloc (core.result.Result.Ok tt) + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit mother.Failure.t)) + ] in + M.read α0. Global Instance AssociatedFunction_revert_or_trap : Notations.DoubleColon Self "revert_or_trap" := { diff --git a/CoqOfRust/examples/default/examples/ink_contracts/multisig.v b/CoqOfRust/examples/default/examples/ink_contracts/multisig.v index da52aeed8..366afbf4c 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/multisig.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/multisig.v @@ -265,9 +265,17 @@ Section Impl_core_clone_Clone_for_multisig_AccountId_t. *) Definition clone (self : ref Self) : M multisig.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref multisig.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val multisig.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref multisig.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val multisig.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -349,9 +357,10 @@ Section Impl_core_cmp_Eq_for_multisig_AccountId_t. *) Definition assert_receiver_is_total_eq (self : ref Self) : M unit := let* self := M.alloc self in - let _ : unit := tt in let* α0 : M.Val unit := M.alloc tt in - M.read α0. + let* α1 : M.Val unit := + match_operator α0 [ fun γ => (M.alloc tt) : M (M.Val unit) ] in + M.read α1. Global Instance AssociatedFunction_assert_receiver_is_total_eq : Notations.DoubleColon Self "assert_receiver_is_total_eq" := { @@ -506,9 +515,17 @@ Section Impl_core_clone_Clone_for_multisig_ConfirmationStatus_t. *) Definition clone (self : ref Self) : M multisig.ConfirmationStatus.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref multisig.ConfirmationStatus.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val multisig.ConfirmationStatus.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref multisig.ConfirmationStatus.t := M.read self in + M.pure (deref α0)) : + M (M.Val multisig.ConfirmationStatus.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -1429,43 +1446,68 @@ Section Impl_multisig_Multisig_t. ref (alloc.vec.Vec.t multisig.AccountId.t alloc.alloc.Global.t)) (Trait := ltac:(refine _))) (borrow owners)) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (ref multisig.AccountId.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.slice.iter.Iter.t multisig.AccountId.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some owner => - let* owner := M.alloc owner in - let* _ : M.Val (core.option.Option.t u32.t) := - let* α0 : ref multisig.AccountId.t := M.read owner in - let* α1 : multisig.AccountId.t := M.read (deref α0) in - let* α2 : core.option.Option.t u32.t := + let* α1 : M.Val (core.slice.iter.Iter.t multisig.AccountId.t) := + M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (ref multisig.AccountId.t) := M.call - ((multisig.Mapping.t - multisig.AccountId.t - unit)::["insert"] - (borrow_mut contract.["is_owner"]) - α1 - tt) in - M.alloc α2 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α1) in + ((core.iter.traits.iterator.Iterator.next + (Self := core.slice.iter.Iter.t multisig.AccountId.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val (core.option.Option.t (ref multisig.AccountId.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* owner := M.copy γ0 in + let* _ : M.Val (core.option.Option.t u32.t) := + let* α0 : ref multisig.AccountId.t := + M.read owner in + let* α1 : multisig.AccountId.t := + M.read (deref α0) in + let* α2 : core.option.Option.t u32.t := + M.call + ((multisig.Mapping.t + multisig.AccountId.t + unit)::["insert"] + (borrow_mut contract.["is_owner"]) + α1 + tt) in + M.alloc α2 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α2) in let* _ : M.Val unit := let* α0 : alloc.vec.Vec.t multisig.AccountId.t alloc.alloc.Global.t := M.read owners in @@ -2293,20 +2335,31 @@ Section Impl_multisig_Multisig_t. never_to_any α1 in M.alloc α2 in let* result : M.Val (core.result.Result.t unit multisig.Error.t) := - let* α0 : - core.result.Result.t - (core.result.Result.t - (alloc.vec.Vec.t u8.t alloc.alloc.Global.t) - unit) - unit := - M.read result in - let* α1 : M.Val (core.result.Result.t unit multisig.Error.t) := - match α0 with - | core.result.Result.Ok (core.result.Result.Ok _) => - M.alloc (core.result.Result.Ok tt) - | _ => M.alloc (core.result.Result.Err multisig.Error.TransactionFailed) - end in - M.copy α1 in + let* α0 : M.Val (core.result.Result.t unit multisig.Error.t) := + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* α0 := M.read γ0 in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ0.["Ok.0"] in + M.alloc (core.result.Result.Ok tt) + | _ => M.break_match + end + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit multisig.Error.t)); + fun γ => + (M.alloc + (core.result.Result.Err multisig.Error.TransactionFailed)) : + M (M.Val (core.result.Result.t unit multisig.Error.t)) + ] in + M.copy α0 in let* _ : M.Val unit := let* α0 : mut_ref multisig.Multisig.t := M.read self in let* α1 : multisig.Env.t := @@ -2321,8 +2374,17 @@ Section Impl_multisig_Multisig_t. M.call ((core.result.Result.t unit multisig.Error.t)::["map"] α4 - (fun (_ : unit) => - (M.pure core.option.Option.None) : + (fun (α0 : unit) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (M.pure core.option.Option.None) : + M + (core.option.Option.t + (alloc.vec.Vec.t u8.t alloc.alloc.Global.t)) + ]) : M (core.option.Option.t (alloc.vec.Vec.t u8.t alloc.alloc.Global.t)))) in @@ -2419,25 +2481,45 @@ Section Impl_multisig_Multisig_t. (alloc.vec.Vec.t u8.t alloc.alloc.Global.t) multisig.Error.t) := let* α0 : - core.result.Result.t - (core.result.Result.t - (alloc.vec.Vec.t u8.t alloc.alloc.Global.t) - unit) - unit := - M.read result in - let* α1 : M.Val (core.result.Result.t (alloc.vec.Vec.t u8.t alloc.alloc.Global.t) multisig.Error.t) := - match α0 with - | core.result.Result.Ok (core.result.Result.Ok v) => - let* v := M.alloc v in - let* α0 : alloc.vec.Vec.t u8.t alloc.alloc.Global.t := M.read v in - M.alloc (core.result.Result.Ok α0) - | _ => M.alloc (core.result.Result.Err multisig.Error.TransactionFailed) - end in - M.copy α1 in + match_operator + result + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* α0 := M.read γ0 in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ0.["Ok.0"] in + let* v := M.copy γ0 in + let* α0 : alloc.vec.Vec.t u8.t alloc.alloc.Global.t := + M.read v in + M.alloc (core.result.Result.Ok α0) + | _ => M.break_match + end + | _ => M.break_match + end) : + M + (M.Val + (core.result.Result.t + (alloc.vec.Vec.t u8.t alloc.alloc.Global.t) + multisig.Error.t)); + fun γ => + (M.alloc + (core.result.Result.Err multisig.Error.TransactionFailed)) : + M + (M.Val + (core.result.Result.t + (alloc.vec.Vec.t u8.t alloc.alloc.Global.t) + multisig.Error.t)) + ] in + M.copy α0 in let* _ : M.Val unit := let* α0 : mut_ref multisig.Multisig.t := M.read self in let* α1 : multisig.Env.t := @@ -2660,16 +2742,23 @@ Section Impl_multisig_Multisig_t. (Self := core.slice.iter.Iter.t multisig.AccountId.t) (Trait := ltac:(refine _))) (borrow_mut α3) - (fun (x : ref multisig.AccountId.t) => - (let* x := M.alloc x in - let* α0 : ref multisig.AccountId.t := M.read x in - let* α1 : ref multisig.AccountId.t := M.read owner in - M.call - ((core.cmp.PartialEq.eq - (Self := multisig.AccountId.t) - (Trait := ltac:(refine _))) - α0 - α1)) : + (fun (α0 : ref multisig.AccountId.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* x := M.copy γ in + let* α0 : ref multisig.AccountId.t := M.read x in + let* α1 : ref multisig.AccountId.t := M.read owner in + M.call + ((core.cmp.PartialEq.eq + (Self := multisig.AccountId.t) + (Trait := ltac:(refine _))) + α0 + α1)) : + M bool.t + ]) : M bool.t)) in let* α5 : ref str.t := M.read @@ -2753,15 +2842,23 @@ Section Impl_multisig_Multisig_t. (Self := core.slice.iter.Iter.t u32.t) (Trait := ltac:(refine _))) (borrow_mut α3) - (fun (t : ref u32.t) => - (let* t := M.alloc t in - let* α0 : M.Val (ref u32.t) := M.alloc (borrow trans_id) in - M.call - ((core.cmp.PartialEq.eq - (Self := ref u32.t) - (Trait := ltac:(refine _))) - (borrow t) - (borrow α0))) : + (fun (α0 : ref u32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* t := M.copy γ in + let* α0 : M.Val (ref u32.t) := + M.alloc (borrow trans_id) in + M.call + ((core.cmp.PartialEq.eq + (Self := ref u32.t) + (Trait := ltac:(refine _))) + (borrow t) + (borrow α0))) : + M bool.t + ]) : M bool.t)) in let* α5 : ref str.t := M.read @@ -2796,44 +2893,73 @@ Section Impl_multisig_Multisig_t. (Self := core.slice.iter.Iter.t multisig.AccountId.t) (Trait := ltac:(refine _))) α2) in - let* α4 : M.Val unit := - match α3 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (ref multisig.AccountId.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.slice.iter.Iter.t multisig.AccountId.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some owner => - let* owner := M.alloc owner in - let* _ : M.Val unit := - let* α0 : mut_ref multisig.Multisig.t := M.read self in - let* α1 : u32.t := M.read trans_id in - let* α2 : ref multisig.AccountId.t := M.read owner in - let* α3 : multisig.AccountId.t := M.read (deref α2) in - let* α4 : unit := + let* α4 : M.Val (core.slice.iter.Iter.t multisig.AccountId.t) := + M.alloc α3 in + let* α5 : M.Val unit := + match_operator + α4 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : + core.option.Option.t (ref multisig.AccountId.t) := M.call - ((multisig.Mapping.t - (u32.t * multisig.AccountId.t) - unit)::["remove"] - (borrow (deref α0).["confirmations"]) - (α1, α3)) in - M.alloc α4 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α4) in + ((core.iter.traits.iterator.Iterator.next + (Self := + core.slice.iter.Iter.t multisig.AccountId.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val + (core.option.Option.t (ref multisig.AccountId.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* owner := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : mut_ref multisig.Multisig.t := + M.read self in + let* α1 : u32.t := M.read trans_id in + let* α2 : ref multisig.AccountId.t := + M.read owner in + let* α3 : multisig.AccountId.t := + M.read (deref α2) in + let* α4 : unit := + M.call + ((multisig.Mapping.t + (u32.t * multisig.AccountId.t) + unit)::["remove"] + (borrow (deref α0).["confirmations"]) + (α1, α3)) in + M.alloc α4 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α5) in let* _ : M.Val unit := let* α0 : mut_ref multisig.Multisig.t := M.read self in let* α1 : u32.t := M.read trans_id in @@ -2879,92 +3005,117 @@ Section Impl_multisig_Multisig_t. (Self := ref (alloc.vec.Vec.t u32.t alloc.alloc.Global.t)) (Trait := ltac:(refine _))) (borrow (deref α0).["transaction_list"].["transactions"])) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (ref u32.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.slice.iter.Iter.t u32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some trans_id => - let* trans_id := M.alloc trans_id in - let* key : M.Val (u32.t * multisig.AccountId.t) := - let* α0 : ref u32.t := M.read trans_id in - let* α1 : u32.t := M.read (deref α0) in - let* α2 : ref multisig.AccountId.t := M.read owner in - let* α3 : multisig.AccountId.t := M.read (deref α2) in - M.alloc (α1, α3) in - let* α0 : mut_ref multisig.Multisig.t := M.read self in - let* α1 : bool.t := - M.call - ((multisig.Mapping.t - (u32.t * multisig.AccountId.t) - unit)::["contains"] - (borrow (deref α0).["confirmations"]) - (borrow key)) in - let* α2 : M.Val bool.t := M.alloc α1 in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val unit := - let* α0 : mut_ref multisig.Multisig.t := M.read self in - let* α1 : u32.t * multisig.AccountId.t := M.read key in - let* α2 : unit := - M.call - ((multisig.Mapping.t - (u32.t * multisig.AccountId.t) - unit)::["remove"] - (borrow (deref α0).["confirmations"]) - α1) in - M.alloc α2 in - let* count : M.Val u32.t := - let* α0 : mut_ref multisig.Multisig.t := M.read self in - let* α1 : ref u32.t := M.read trans_id in - let* α2 : core.option.Option.t u32.t := - M.call - ((multisig.Mapping.t u32.t u32.t)::["get"] - (borrow (deref α0).["confirmation_count"]) - α1) in - let* α3 : u32.t := - M.call - ((core.option.Option.t u32.t)::["unwrap_or"] - α2 - (Integer.of_Z 0)) in - M.alloc α3 in - let* _ : M.Val unit := - let β : M.Val u32.t := count in - let* α0 := M.read β in - let* α1 := BinOp.Panic.sub α0 (Integer.of_Z 1) in - assign β α1 in - let* _ : M.Val (core.option.Option.t u32.t) := - let* α0 : mut_ref multisig.Multisig.t := M.read self in - let* α1 : ref u32.t := M.read trans_id in - let* α2 : u32.t := M.read (deref α1) in - let* α3 : u32.t := M.read count in - let* α4 : core.option.Option.t u32.t := - M.call - ((multisig.Mapping.t u32.t u32.t)::["insert"] - (borrow_mut (deref α0).["confirmation_count"]) - α2 - α3) in - M.alloc α4 in - M.alloc tt - else - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α2). + let* α2 : M.Val (core.slice.iter.Iter.t u32.t) := M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (ref u32.t) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.slice.iter.Iter.t u32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t (ref u32.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* trans_id := M.copy γ0 in + let* key : M.Val (u32.t * multisig.AccountId.t) := + let* α0 : ref u32.t := M.read trans_id in + let* α1 : u32.t := M.read (deref α0) in + let* α2 : ref multisig.AccountId.t := M.read owner in + let* α3 : multisig.AccountId.t := M.read (deref α2) in + M.alloc (α1, α3) in + let* α0 : mut_ref multisig.Multisig.t := M.read self in + let* α1 : bool.t := + M.call + ((multisig.Mapping.t + (u32.t * multisig.AccountId.t) + unit)::["contains"] + (borrow (deref α0).["confirmations"]) + (borrow key)) in + let* α2 : M.Val bool.t := M.alloc α1 in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val unit := + let* α0 : mut_ref multisig.Multisig.t := + M.read self in + let* α1 : u32.t * multisig.AccountId.t := + M.read key in + let* α2 : unit := + M.call + ((multisig.Mapping.t + (u32.t * multisig.AccountId.t) + unit)::["remove"] + (borrow (deref α0).["confirmations"]) + α1) in + M.alloc α2 in + let* count : M.Val u32.t := + let* α0 : mut_ref multisig.Multisig.t := + M.read self in + let* α1 : ref u32.t := M.read trans_id in + let* α2 : core.option.Option.t u32.t := + M.call + ((multisig.Mapping.t u32.t u32.t)::["get"] + (borrow (deref α0).["confirmation_count"]) + α1) in + let* α3 : u32.t := + M.call + ((core.option.Option.t u32.t)::["unwrap_or"] + α2 + (Integer.of_Z 0)) in + M.alloc α3 in + let* _ : M.Val unit := + let β : M.Val u32.t := count in + let* α0 := M.read β in + let* α1 := BinOp.Panic.sub α0 (Integer.of_Z 1) in + assign β α1 in + let* _ : M.Val (core.option.Option.t u32.t) := + let* α0 : mut_ref multisig.Multisig.t := + M.read self in + let* α1 : ref u32.t := M.read trans_id in + let* α2 : u32.t := M.read (deref α1) in + let* α3 : u32.t := M.read count in + let* α4 : core.option.Option.t u32.t := + M.call + ((multisig.Mapping.t u32.t u32.t)::["insert"] + (borrow_mut (deref α0).["confirmation_count"]) + α2 + α3) in + M.alloc α4 in + M.alloc tt + else + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α3). Global Instance AssociatedFunction_clean_owner_confirmations : Notations.DoubleColon Self "clean_owner_confirmations" := { @@ -3098,43 +3249,55 @@ Section Impl_multisig_Multisig_t. let* α8 : multisig.AccountId.t := M.call (multisig.Env.t::["account_id"] (borrow α7)) in let* α9 : M.Val multisig.AccountId.t := M.alloc α8 in - match (borrow α4, borrow α9) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref multisig.AccountId.t := M.read left_val in - let* α1 : ref multisig.AccountId.t := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := multisig.AccountId.t) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref multisig.AccountId.t := M.read left_val in - let* α2 : ref multisig.AccountId.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed - α0 - α1 - α2 - core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α10 : + M.Val ((ref multisig.AccountId.t) * (ref multisig.AccountId.t)) := + M.alloc (borrow α4, borrow α9) in + match_operator + α10 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref multisig.AccountId.t := M.read left_val in + let* α1 : ref multisig.AccountId.t := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := multisig.AccountId.t) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref multisig.AccountId.t := M.read left_val in + let* α2 : ref multisig.AccountId.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/ink_contracts/payment_channel.v b/CoqOfRust/examples/default/examples/ink_contracts/payment_channel.v index 34f45ce32..8d4084cc1 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/payment_channel.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/payment_channel.v @@ -49,9 +49,17 @@ Section Impl_core_clone_Clone_for_payment_channel_AccountId_t. *) Definition clone (self : ref Self) : M payment_channel.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref payment_channel.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val payment_channel.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref payment_channel.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val payment_channel.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -133,9 +141,10 @@ Section Impl_core_cmp_Eq_for_payment_channel_AccountId_t. *) Definition assert_receiver_is_total_eq (self : ref Self) : M unit := let* self := M.alloc self in - let _ : unit := tt in let* α0 : M.Val unit := M.alloc tt in - M.read α0. + let* α1 : M.Val unit := + match_operator α0 [ fun γ => (M.alloc tt) : M (M.Val unit) ] in + M.read α1. Global Instance AssociatedFunction_assert_receiver_is_total_eq : Notations.DoubleColon Self "assert_receiver_is_total_eq" := { @@ -915,12 +924,20 @@ Section Impl_payment_channel_PaymentChannel_t. unit payment_channel.Error.t)::["unwrap_or_else"] α0 - (fun (err : payment_channel.Error.t) => - (let* err := M.alloc err in - let* α0 : ref str.t := - M.read (mk_str "recover failed: {err:?}") in - let* α1 : never.t := M.call (std.panicking.begin_panic α0) in - never_to_any α1) : + (fun (α0 : payment_channel.Error.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* err := M.copy γ in + let* α0 : ref str.t := + M.read (mk_str "recover failed: {err:?}") in + let* α1 : never.t := + M.call (std.panicking.begin_panic α0) in + never_to_any α1) : + M unit + ]) : M unit)) in M.alloc α1 in let* signature_account_id : M.Val (array u8.t) := @@ -1117,8 +1134,15 @@ Section Impl_payment_channel_PaymentChannel_t. M.call ((core.result.Result.t unit payment_channel.Error.t)::["map_err"] α9 - (fun (_ : payment_channel.Error.t) => - (M.pure payment_channel.Error.TransferFailed) : + (fun (α0 : payment_channel.Error.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (M.pure payment_channel.Error.TransferFailed) : + M payment_channel.Error.t + ]) : M payment_channel.Error.t)) in let* α11 : core.ops.control_flow.ControlFlow.t @@ -1131,28 +1155,53 @@ Section Impl_payment_channel_PaymentChannel_t. (Self := core.result.Result.t unit payment_channel.Error.t) (Trait := ltac:(refine _))) α10) in - match α11 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t - core.convert.Infallible.t - payment_channel.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit payment_channel.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit payment_channel.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α12 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t + core.convert.Infallible.t + payment_channel.Error.t) + unit) := + M.alloc α11 in + match_operator + α12 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + payment_channel.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit payment_channel.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t unit payment_channel.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* α0 : M.Val (core.result.Result.t unit payment_channel.Error.t) := M.alloc (core.result.Result.Ok tt) in M.read α0). @@ -1197,28 +1246,53 @@ Section Impl_payment_channel_PaymentChannel_t. (Self := core.result.Result.t unit payment_channel.Error.t) (Trait := ltac:(refine _))) α3) in - match α4 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t - core.convert.Infallible.t - payment_channel.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit payment_channel.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit payment_channel.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α5 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t + core.convert.Infallible.t + payment_channel.Error.t) + unit) := + M.alloc α4 in + match_operator + α5 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + payment_channel.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit payment_channel.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t unit payment_channel.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : mut_ref payment_channel.PaymentChannel.t := M.read self in let* α1 : payment_channel.Env.t := @@ -1370,59 +1444,78 @@ Section Impl_payment_channel_PaymentChannel_t. let return_ := M.return_ (R := ltac:(payment_channel.Result unit)) in M.catch_return (let* α0 : mut_ref payment_channel.PaymentChannel.t := M.read self in - let* α1 : core.option.Option.t u64.t := - M.read (deref α0).["expiration"] in - let* α2 : M.Val (core.result.Result.t unit payment_channel.Error.t) := - match α1 with - | core.option.Option.Some expiration => - let* expiration := M.alloc expiration in - let* now : M.Val u64.t := - let* α0 : mut_ref payment_channel.PaymentChannel.t := M.read self in - let* α1 : payment_channel.Env.t := - M.call - (payment_channel.PaymentChannel.t::["env"] - (borrow (deref α0))) in - let* α2 : M.Val payment_channel.Env.t := M.alloc α1 in - let* α3 : u64.t := - M.call (payment_channel.Env.t::["block_timestamp"] (borrow α2)) in - M.alloc α3 in - let* _ : M.Val unit := - let* α0 : u64.t := M.read now in - let* α1 : u64.t := M.read expiration in - let* α2 : M.Val bool.t := M.alloc (BinOp.Pure.lt α0 α1) in - let* α3 : bool.t := M.read (use α2) in - if α3 then - let* _ : M.Val never.t := - return_ - (core.result.Result.Err - payment_channel.Error.NotYetExpired) in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt in - let* _ : M.Val unit := - let* α0 : mut_ref payment_channel.PaymentChannel.t := M.read self in - let* α1 : payment_channel.Env.t := - M.call - (payment_channel.PaymentChannel.t::["env"] - (borrow (deref α0))) in - let* α2 : M.Val payment_channel.Env.t := M.alloc α1 in - let* α3 : mut_ref payment_channel.PaymentChannel.t := M.read self in - let* α4 : payment_channel.AccountId.t := - M.read (deref α3).["sender"] in - let* α5 : unit := - M.call - (payment_channel.Env.t::["terminate_contract"] - (borrow α2) - α4) in - M.alloc α5 in - M.alloc (core.result.Result.Ok tt) - | core.option.Option.None => - M.alloc (core.result.Result.Err payment_channel.Error.NotYetExpired) - end in - M.read α2). + let* α1 : M.Val (core.result.Result.t unit payment_channel.Error.t) := + match_operator + (deref α0).["expiration"] + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* expiration := M.copy γ0 in + let* now : M.Val u64.t := + let* α0 : mut_ref payment_channel.PaymentChannel.t := + M.read self in + let* α1 : payment_channel.Env.t := + M.call + (payment_channel.PaymentChannel.t::["env"] + (borrow (deref α0))) in + let* α2 : M.Val payment_channel.Env.t := M.alloc α1 in + let* α3 : u64.t := + M.call + (payment_channel.Env.t::["block_timestamp"] + (borrow α2)) in + M.alloc α3 in + let* _ : M.Val unit := + let* α0 : u64.t := M.read now in + let* α1 : u64.t := M.read expiration in + let* α2 : M.Val bool.t := M.alloc (BinOp.Pure.lt α0 α1) in + let* α3 : bool.t := M.read (use α2) in + if α3 then + let* _ : M.Val never.t := + return_ + (core.result.Result.Err + payment_channel.Error.NotYetExpired) in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt in + let* _ : M.Val unit := + let* α0 : mut_ref payment_channel.PaymentChannel.t := + M.read self in + let* α1 : payment_channel.Env.t := + M.call + (payment_channel.PaymentChannel.t::["env"] + (borrow (deref α0))) in + let* α2 : M.Val payment_channel.Env.t := M.alloc α1 in + let* α3 : mut_ref payment_channel.PaymentChannel.t := + M.read self in + let* α4 : payment_channel.AccountId.t := + M.read (deref α3).["sender"] in + let* α5 : unit := + M.call + (payment_channel.Env.t::["terminate_contract"] + (borrow α2) + α4) in + M.alloc α5 in + M.alloc (core.result.Result.Ok tt) + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit payment_channel.Error.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + M.alloc + (core.result.Result.Err payment_channel.Error.NotYetExpired) + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit payment_channel.Error.t)) + ] in + M.read α1). Global Instance AssociatedFunction_claim_timeout : Notations.DoubleColon Self "claim_timeout" := { @@ -1564,8 +1657,15 @@ Section Impl_payment_channel_PaymentChannel_t. M.call ((core.result.Result.t unit payment_channel.Error.t)::["map_err"] α6 - (fun (_ : payment_channel.Error.t) => - (M.pure payment_channel.Error.TransferFailed) : + (fun (α0 : payment_channel.Error.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (M.pure payment_channel.Error.TransferFailed) : + M payment_channel.Error.t + ]) : M payment_channel.Error.t)) in let* α8 : core.ops.control_flow.ControlFlow.t @@ -1578,28 +1678,53 @@ Section Impl_payment_channel_PaymentChannel_t. (Self := core.result.Result.t unit payment_channel.Error.t) (Trait := ltac:(refine _))) α7) in - match α8 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t - core.convert.Infallible.t - payment_channel.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit payment_channel.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit payment_channel.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α9 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t + core.convert.Infallible.t + payment_channel.Error.t) + unit) := + M.alloc α8 in + match_operator + α9 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + payment_channel.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit payment_channel.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t unit payment_channel.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* α0 : M.Val (core.result.Result.t unit payment_channel.Error.t) := M.alloc (core.result.Result.Ok tt) in M.read α0). diff --git a/CoqOfRust/examples/default/examples/ink_contracts/trait_erc20.v b/CoqOfRust/examples/default/examples/ink_contracts/trait_erc20.v index 72f0417c3..ecdce956c 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/trait_erc20.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/trait_erc20.v @@ -160,9 +160,17 @@ Section Impl_core_clone_Clone_for_trait_erc20_AccountId_t. *) Definition clone (self : ref Self) : M trait_erc20.AccountId.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref trait_erc20.AccountId.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val trait_erc20.AccountId.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref trait_erc20.AccountId.t := M.read self in + M.pure (deref α0)) : + M (M.Val trait_erc20.AccountId.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -225,19 +233,37 @@ Section Impl_core_fmt_Debug_for_trait_erc20_Error_t. let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref trait_erc20.Error.t := M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | trait_erc20.Error.InsufficientBalance => - let* α0 : ref str.t := M.read (mk_str "InsufficientBalance") in - M.alloc α0 - | trait_erc20.Error.InsufficientAllowance => - let* α0 : ref str.t := M.read (mk_str "InsufficientAllowance") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | trait_erc20.Error.InsufficientBalance => + let* α0 : ref str.t := M.read (mk_str "InsufficientBalance") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | trait_erc20.Error.InsufficientAllowance => + let* α0 : ref str.t := M.read (mk_str "InsufficientAllowance") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; @@ -1129,28 +1155,52 @@ Section Impl_trait_erc20_BaseErc20_for_trait_erc20_Erc20_t. (Self := core.result.Result.t unit trait_erc20.Error.t) (Trait := ltac:(refine _))) α2) in - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t - core.convert.Infallible.t - trait_erc20.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit trait_erc20.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit trait_erc20.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : unit := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t + core.convert.Infallible.t + trait_erc20.Error.t) + unit) := + M.alloc α3 in + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + trait_erc20.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit trait_erc20.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.result.Result.t unit trait_erc20.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : unit := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : mut_ref trait_erc20.Erc20.t := M.read self in let* α1 : trait_erc20.AccountId.t := M.read from in diff --git a/CoqOfRust/examples/default/examples/ink_contracts/wildcard_selector.v b/CoqOfRust/examples/default/examples/ink_contracts/wildcard_selector.v index d6566cd28..db6e3314f 100644 --- a/CoqOfRust/examples/default/examples/ink_contracts/wildcard_selector.v +++ b/CoqOfRust/examples/default/examples/ink_contracts/wildcard_selector.v @@ -40,43 +40,65 @@ Section Impl_wildcard_selector_WildcardSelector_t. *) Definition wildcard (self : mut_ref Self) : M unit := let* self := M.alloc self in - let* '(_selector, _message) : (array u8.t) * alloc.string.String.t := - let* α0 : - core.result.Result.t ((array u8.t) * alloc.string.String.t) unit := - M.call wildcard_selector.decode_input in + let* α0 : + core.result.Result.t ((array u8.t) * alloc.string.String.t) unit := + M.call wildcard_selector.decode_input in + let* α1 : (array u8.t) * alloc.string.String.t := M.call ((core.result.Result.t ((array u8.t) * alloc.string.String.t) unit)::["unwrap"] α0) in - let* _selector := M.alloc _selector in - let* _message := M.alloc _message in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Wildcard selector: ") in - let* α1 : ref str.t := M.read (mk_str ", message: ") in - let* α2 : ref str.t := M.read (mk_str " + let* α2 : M.Val ((array u8.t) * alloc.string.String.t) := M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* _selector := M.copy γ0 in + let* _message := M.copy γ1 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Wildcard selector: ") in + let* α1 : ref str.t := M.read (mk_str ", message: ") in + let* α2 : ref str.t := M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow _selector)) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow _message)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in - M.read α0. + let* α3 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] + (borrow _selector)) in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow _message)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + M.alloc tt + end) : + M (M.Val unit) + ] in + M.read α3. Global Instance AssociatedFunction_wildcard : Notations.DoubleColon Self "wildcard" := { diff --git a/CoqOfRust/examples/default/examples/monadic_transformation/example02.v b/CoqOfRust/examples/default/examples/monadic_transformation/example02.v index c347869f6..a0dd7cacf 100644 --- a/CoqOfRust/examples/default/examples/monadic_transformation/example02.v +++ b/CoqOfRust/examples/default/examples/monadic_transformation/example02.v @@ -26,10 +26,13 @@ fn main() { (* #[allow(dead_code)] - function was ignored by the compiler *) Definition main : M unit := let* _ : M.Val bool.t := - match Integer.of_Z 1 with - | _ => M.alloc false - | _ => M.alloc true - end in + let* α0 : M.Val i32.t := M.alloc (Integer.of_Z 1) in + match_operator + α0 + [ + fun γ => (M.alloc false) : M (M.Val bool.t); + fun γ => (M.alloc true) : M (M.Val bool.t) + ] in let* _ : M.Val i32.t := let* α0 : M.Val bool.t := M.alloc true in let* α1 : bool.t := M.read (use α0) in diff --git a/CoqOfRust/examples/default/examples/primitives/arrays_and_slices.v b/CoqOfRust/examples/default/examples/primitives/arrays_and_slices.v index c5d60ff47..57548d51d 100644 --- a/CoqOfRust/examples/default/examples/primitives/arrays_and_slices.v +++ b/CoqOfRust/examples/default/examples/primitives/arrays_and_slices.v @@ -266,39 +266,54 @@ Definition main : M unit := let* α0 : M.Val (ref (array u32.t)) := M.alloc (borrow empty_array) in let* α1 : M.Val (array u32.t) := M.alloc [ ] in let* α2 : M.Val (ref (array u32.t)) := M.alloc (borrow α1) in - match (borrow α0, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref (ref (array u32.t)) := M.read left_val in - let* α1 : ref (ref (array u32.t)) := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := ref (array u32.t)) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref (ref (array u32.t)) := M.read left_val in - let* α2 : ref (ref (array u32.t)) := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : M.Val ((ref (ref (array u32.t))) * (ref (ref (array u32.t)))) := + M.alloc (borrow α0, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref (ref (array u32.t)) := M.read left_val in + let* α1 : ref (ref (array u32.t)) := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := ref (array u32.t)) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref (ref (array u32.t)) := M.read left_val in + let* α2 : ref (ref (array u32.t)) := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : M.Val (ref (array u32.t)) := M.alloc (borrow empty_array) in let* α1 : M.Val (array u32.t) := M.alloc [ ] in @@ -310,39 +325,54 @@ Definition main : M unit := (borrow α1) core.ops.range.RangeFull.Build) in let* α3 : M.Val (ref (slice u32.t)) := M.alloc α2 in - match (borrow α0, borrow α3) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref (ref (array u32.t)) := M.read left_val in - let* α1 : ref (ref (slice u32.t)) := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := ref (array u32.t)) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref (ref (array u32.t)) := M.read left_val in - let* α2 : ref (ref (slice u32.t)) := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α4 : M.Val ((ref (ref (array u32.t))) * (ref (ref (slice u32.t)))) := + M.alloc (borrow α0, borrow α3) in + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref (ref (array u32.t)) := M.read left_val in + let* α1 : ref (ref (slice u32.t)) := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := ref (array u32.t)) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref (ref (array u32.t)) := M.read left_val in + let* α2 : ref (ref (slice u32.t)) := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val (ref (array i32.t)) := M.alloc (borrow xs) in let* α1 : ref (slice i32.t) := M.read (pointer_coercion "Unsize" α0) in let* α2 : usize.t := M.call ((slice i32.t)::["len"] α1) in @@ -356,86 +386,143 @@ Definition main : M unit := core.ops.range.Range.start := Integer.of_Z 0; core.ops.range.Range.end_ := α3; |}) in - let* α5 : M.Val unit := - match α4 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t usize.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t usize.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some i => - let* i := M.alloc i in - let* α0 : M.Val (ref (array i32.t)) := M.alloc (borrow xs) in - let* α1 : ref (slice i32.t) := - M.read (pointer_coercion "Unsize" α0) in - let* α2 : usize.t := M.read i in - let* α3 : core.option.Option.t (ref i32.t) := - M.call ((slice i32.t)::["get"] α1 α2) in - match α3 with - | core.option.Option.Some xval => - let* xval := M.alloc xval in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str ": ") in - let* α2 : ref str.t := M.read (mk_str " + let* α5 : M.Val (core.ops.range.Range.t usize.t) := M.alloc α4 in + let* α6 : M.Val unit := + match_operator + α5 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t usize.t := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t usize.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t usize.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* i := M.copy γ0 in + let* α0 : M.Val (ref (array i32.t)) := + M.alloc (borrow xs) in + let* α1 : ref (slice i32.t) := + M.read (pointer_coercion "Unsize" α0) in + let* α2 : usize.t := M.read i in + let* α3 : core.option.Option.t (ref i32.t) := + M.call ((slice i32.t)::["get"] α1 α2) in + let* α4 : M.Val (core.option.Option.t (ref i32.t)) := + M.alloc α3 in + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* xval := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str ": ") in + let* α2 : ref str.t := M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow i)) in - let* α7 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow xval)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt - | core.option.Option.None => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Slow down! ") in - let* α1 : ref str.t := M.read (mk_str " is too far! + let* α3 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow i)) in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow xval)) in + let* α8 : + M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : + M.Val + (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := + M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Slow down! ") in + let* α1 : ref str.t := + M.read (mk_str " is too far! ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow i)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end - end in - M.alloc tt) - end in - M.read (use α5). + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow i)) in + let* α6 : + M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val + (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α6). diff --git a/CoqOfRust/examples/default/examples/primitives/tuples.v b/CoqOfRust/examples/default/examples/primitives/tuples.v index 424ef5c09..b7ea87999 100644 --- a/CoqOfRust/examples/default/examples/primitives/tuples.v +++ b/CoqOfRust/examples/default/examples/primitives/tuples.v @@ -11,12 +11,24 @@ fn reverse(pair: (i32, bool)) -> (bool, i32) { *) Definition reverse (pair : i32.t * bool.t) : M (bool.t * i32.t) := let* pair := M.alloc pair in - let* '(int_param, bool_param) : i32.t * bool.t := M.read pair in - let* int_param := M.alloc int_param in - let* bool_param := M.alloc bool_param in - let* α0 : bool.t := M.read bool_param in - let* α1 : i32.t := M.read int_param in - let* α0 : M.Val (bool.t * i32.t) := M.alloc (α0, α1) in + let* α0 : M.Val (bool.t * i32.t) := + match_operator + pair + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* int_param := M.copy γ0 in + let* bool_param := M.copy γ1 in + let* α0 : bool.t := M.read bool_param in + let* α1 : i32.t := M.read int_param in + M.alloc (α0, α1) + end) : + M (M.Val (bool.t * i32.t)) + ] in M.read α0. Module Matrix. @@ -328,69 +340,89 @@ Definition main : M unit := let* α0 : ref str.t := M.read (mk_str "hello") in let* α1 : f64.t := M.read UnsupportedLiteral in M.alloc (Integer.of_Z 1, α0, α1, true) in - let* '(a, b, c, d) : ((i32.t * (ref str.t)) * f64.t) * bool.t := - M.read tuple in - let* a := M.alloc a in - let* b := M.alloc b in - let* c := M.alloc c in - let* d := M.alloc d in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str ", ") in - let* α2 : ref str.t := M.read (mk_str ", ") in - let* α3 : ref str.t := M.read (mk_str ", ") in - let* α4 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + tuple + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _, _, _) => + let γ0 := + Tuple.Access.left (Tuple.Access.left (Tuple.Access.left γ)) in + let γ1 := + Tuple.Access.right (Tuple.Access.left (Tuple.Access.left γ)) in + let γ2 := Tuple.Access.right (Tuple.Access.left γ) in + let γ3 := Tuple.Access.right γ in + let* a := M.copy γ0 in + let* b := M.copy γ1 in + let* c := M.copy γ2 in + let* d := M.copy γ3 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str ", ") in + let* α2 : ref str.t := M.read (mk_str ", ") in + let* α3 : ref str.t := M.read (mk_str ", ") in + let* α4 : ref str.t := M.read (mk_str " ") in - let* α5 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2; α3; α4 ] in - let* α6 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α5) in - let* α7 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α6) in - let* α8 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow a)) in - let* α9 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow b)) in - let* α10 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow c)) in - let* α11 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow d)) in - let* α12 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α8; α9; α10; α11 ] in - let* α13 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α12) in - let* α14 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α13) in - let* α15 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α7 α14) in - let* α16 : unit := M.call (std.io.stdio._print α15) in - M.alloc α16 in - M.alloc tt in - let* matrix : M.Val tuples.Matrix.t := - let* α0 : f32.t := M.read UnsupportedLiteral in - let* α1 : f32.t := M.read UnsupportedLiteral in - let* α2 : f32.t := M.read UnsupportedLiteral in - let* α3 : f32.t := M.read UnsupportedLiteral in - M.alloc (tuples.Matrix.Build_t α0 α1 α2 α3) in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " + let* α5 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2; α3; α4 ] in + let* α6 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α5) in + let* α7 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α6) in + let* α8 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow a)) in + let* α9 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow b)) in + let* α10 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow c)) in + let* α11 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow d)) in + let* α12 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α8; α9; α10; α11 ] in + let* α13 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α12) in + let* α14 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α13) in + let* α15 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α7 α14) in + let* α16 : unit := M.call (std.io.stdio._print α15) in + M.alloc α16 in + M.alloc tt in + let* matrix : M.Val tuples.Matrix.t := + let* α0 : f32.t := M.read UnsupportedLiteral in + let* α1 : f32.t := M.read UnsupportedLiteral in + let* α2 : f32.t := M.read UnsupportedLiteral in + let* α3 : f32.t := M.read UnsupportedLiteral in + M.alloc (tuples.Matrix.Build_t α0 α1 α2 α3) in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow matrix)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow matrix)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_borrowing_mutablity.v b/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_borrowing_mutablity.v index d43732e16..11fbf3d24 100644 --- a/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_borrowing_mutablity.v +++ b/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_borrowing_mutablity.v @@ -48,11 +48,33 @@ Section Impl_core_clone_Clone_for_scoping_rules_borrowing_mutablity_Book_t. (self : ref Self) : M scoping_rules_borrowing_mutablity.Book.t := let* self := M.alloc self in - let _ : unit := tt in - let _ : unit := tt in - let _ : unit := tt in - let* α0 : ref scoping_rules_borrowing_mutablity.Book.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val scoping_rules_borrowing_mutablity.Book.t := + match_operator + α0 + [ + fun γ => + (let* α0 : M.Val unit := M.alloc tt in + match_operator + α0 + [ + fun γ => + (let* α0 : M.Val unit := M.alloc tt in + match_operator + α0 + [ + fun γ => + (let* α0 : + ref scoping_rules_borrowing_mutablity.Book.t := + M.read self in + M.pure (deref α0)) : + M (M.Val scoping_rules_borrowing_mutablity.Book.t) + ]) : + M (M.Val scoping_rules_borrowing_mutablity.Book.t) + ]) : + M (M.Val scoping_rules_borrowing_mutablity.Book.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_borrowing_the_ref_pattern.v b/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_borrowing_the_ref_pattern.v index 2cafa6771..d0417660e 100644 --- a/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_borrowing_the_ref_pattern.v +++ b/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_borrowing_the_ref_pattern.v @@ -36,10 +36,18 @@ Section Impl_core_clone_Clone_for_scoping_rules_borrowing_the_ref_pattern_Point_ (self : ref Self) : M scoping_rules_borrowing_the_ref_pattern.Point.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref scoping_rules_borrowing_the_ref_pattern.Point.t := - M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val scoping_rules_borrowing_the_ref_pattern.Point.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref scoping_rules_borrowing_the_ref_pattern.Point.t := + M.read self in + M.pure (deref α0)) : + M (M.Val scoping_rules_borrowing_the_ref_pattern.Point.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -157,29 +165,53 @@ Definition main : M unit := scoping_rules_borrowing_the_ref_pattern.Point.y := Integer.of_Z 0; |} in let* _copy_of_x : M.Val i32.t := - let* '{| - scoping_rules_borrowing_the_ref_pattern.Point.x := ref_to_x; - scoping_rules_borrowing_the_ref_pattern.Point.y := _; - |} : - scoping_rules_borrowing_the_ref_pattern.Point.t := - M.read point in - let* ref_to_x := M.alloc ref_to_x in - let* α0 : ref i32.t := M.read ref_to_x in - M.copy (deref α0) in + let* α0 : M.Val i32.t := + match_operator + point + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | + {| + scoping_rules_borrowing_the_ref_pattern.Point.x := _; + scoping_rules_borrowing_the_ref_pattern.Point.y := _; + |} + => + let γ0 := γ.["Point.x"] in + let γ1 := γ.["Point.y"] in + let* ref_to_x := M.alloc (borrow_mut γ0) in + let* α0 : ref i32.t := M.read ref_to_x in + M.pure (deref α0) + end) : + M (M.Val i32.t) + ] in + M.copy α0 in let* mutable_point : M.Val scoping_rules_borrowing_the_ref_pattern.Point.t := M.copy point in let* _ : M.Val unit := - let* '{| - scoping_rules_borrowing_the_ref_pattern.Point.x := _; - scoping_rules_borrowing_the_ref_pattern.Point.y := mut_ref_to_y; - |} : - scoping_rules_borrowing_the_ref_pattern.Point.t := - M.read mutable_point in - let* mut_ref_to_y := M.alloc mut_ref_to_y in - let* _ : M.Val unit := - let* α0 : mut_ref i32.t := M.read mut_ref_to_y in - assign (deref α0) (Integer.of_Z 1) in - M.alloc tt in + match_operator + mutable_point + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | + {| + scoping_rules_borrowing_the_ref_pattern.Point.x := _; + scoping_rules_borrowing_the_ref_pattern.Point.y := _; + |} + => + let γ0 := γ.["Point.x"] in + let γ1 := γ.["Point.y"] in + let* mut_ref_to_y := M.alloc (borrow γ1) in + let* _ : M.Val unit := + let* α0 : mut_ref i32.t := M.read mut_ref_to_y in + assign (deref α0) (Integer.of_Z 1) in + M.alloc tt + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "point is (") in @@ -240,13 +272,23 @@ Definition main : M unit := (Integer.of_Z 5)) in M.alloc (α0, Integer.of_Z 3) in let* _ : M.Val unit := - let* '(_, last) : (alloc.boxed.Box.t u32.t alloc.alloc.Global.t) * u32.t := - M.read mutable_tuple in - let* last := M.alloc last in - let* _ : M.Val unit := - let* α0 : mut_ref u32.t := M.read last in - assign (deref α0) (Integer.of_Z 2) in - M.alloc tt in + match_operator + mutable_tuple + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* last := M.alloc (borrow γ1) in + let* _ : M.Val unit := + let* α0 : mut_ref u32.t := M.read last in + assign (deref α0) (Integer.of_Z 2) in + M.alloc tt + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "tuple is ") in diff --git a/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_lifetimes_structs.v b/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_lifetimes_structs.v index 793376010..0f318899f 100644 --- a/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_lifetimes_structs.v +++ b/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_lifetimes_structs.v @@ -141,31 +141,59 @@ Section Impl_core_fmt_Debug_for_scoping_rules_lifetimes_structs_Either_t. : M ltac:(core.fmt.Result) := let* self := M.alloc self in let* f := M.alloc f in - let* α0 : ref scoping_rules_lifetimes_structs.Either.t := M.read self in - let* α1 : M.Val (core.result.Result.t unit core.fmt.Error.t) := - match α0 with - | scoping_rules_lifetimes_structs.Either.Num __self_0 => - let* __self_0 := M.alloc __self_0 in - let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref str.t := M.read (mk_str "Num") in - let* α2 : M.Val (ref (ref i32.t)) := M.alloc (borrow __self_0) in - let* α3 : ref dynamic := M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.result.Result.t unit core.fmt.Error.t := - M.call - (core.fmt.Formatter.t::["debug_tuple_field1_finish"] α0 α1 α3) in - M.alloc α4 - | scoping_rules_lifetimes_structs.Either.Ref __self_0 => - let* __self_0 := M.alloc __self_0 in - let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref str.t := M.read (mk_str "Ref") in - let* α2 : M.Val (ref (ref (ref i32.t))) := M.alloc (borrow __self_0) in - let* α3 : ref dynamic := M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.result.Result.t unit core.fmt.Error.t := - M.call - (core.fmt.Formatter.t::["debug_tuple_field1_finish"] α0 α1 α3) in - M.alloc α4 - end in - M.read α1. + let* α0 : M.Val (core.result.Result.t unit core.fmt.Error.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | scoping_rules_lifetimes_structs.Either.Num _ => + let γ0 := γ.["Num.0"] in + let* __self_0 := M.alloc (borrow_mut γ0) in + let* α0 : mut_ref core.fmt.Formatter.t := M.read f in + let* α1 : ref str.t := M.read (mk_str "Num") in + let* α2 : M.Val (ref (ref i32.t)) := M.alloc (borrow __self_0) in + let* α3 : ref dynamic := M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.result.Result.t unit core.fmt.Error.t := + M.call + (core.fmt.Formatter.t::["debug_tuple_field1_finish"] + α0 + α1 + α3) in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit core.fmt.Error.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | scoping_rules_lifetimes_structs.Either.Ref _ => + let γ0 := γ.["Ref.0"] in + let* __self_0 := M.alloc (borrow_mut γ0) in + let* α0 : mut_ref core.fmt.Formatter.t := M.read f in + let* α1 : ref str.t := M.read (mk_str "Ref") in + let* α2 : M.Val (ref (ref (ref i32.t))) := + M.alloc (borrow __self_0) in + let* α3 : ref dynamic := M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.result.Result.t unit core.fmt.Error.t := + M.call + (core.fmt.Formatter.t::["debug_tuple_field1_finish"] + α0 + α1 + α3) in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit core.fmt.Error.t)) + ] in + M.read α0. Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; diff --git a/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_ownership_and_rules_partial_moves.v b/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_ownership_and_rules_partial_moves.v index a35935b45..6cd4d6385 100644 --- a/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_ownership_and_rules_partial_moves.v +++ b/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_ownership_and_rules_partial_moves.v @@ -48,82 +48,106 @@ Definition main : M unit := scoping_rules_ownership_and_rules_partial_moves.main.Person.name := α1; scoping_rules_ownership_and_rules_partial_moves.main.Person.age := α2; |} in - let* '{| - scoping_rules_ownership_and_rules_partial_moves.main.Person.name - := - name; - scoping_rules_ownership_and_rules_partial_moves.main.Person.age := age; - |} : - scoping_rules_ownership_and_rules_partial_moves.main.Person.t := - M.read person in - let* name := M.alloc name in - let* age := M.alloc age in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "The person's age is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : M.Val unit := + match_operator + person + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | + {| + scoping_rules_ownership_and_rules_partial_moves.main.Person.name + := + _; + scoping_rules_ownership_and_rules_partial_moves.main.Person.age + := + _; + |} + => + let γ0 := γ.["Person.name"] in + let γ1 := γ.["Person.age"] in + let* name := M.copy γ0 in + let* age := M.alloc (borrow_mut γ1) in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "The person's age is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow age)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "The person's name is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow age)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "The person's name is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow name)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "The person's age from person struct is ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow name)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "The person's age from person struct is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow person.["age"])) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow person.["age"])) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + end) : + M (M.Val unit) + ] in M.read α0. Module Person. diff --git a/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_raii.v b/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_raii.v index 9cfcc07f8..bc8e729b9 100644 --- a/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_raii.v +++ b/CoqOfRust/examples/default/examples/scoping_rules/scoping_rules_raii.v @@ -66,30 +66,51 @@ Definition main : M unit := core.ops.range.Range.start := Integer.of_Z 0; core.ops.range.Range.end_ := Integer.of_Z 1000; |}) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t u32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t u32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some _ => - let* _ : M.Val unit := - let* α0 : unit := M.call scoping_rules_raii.create_box in - M.alloc α0 in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α1). + let* α1 : M.Val (core.ops.range.Range.t u32.t) := M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t u32.t := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t u32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t u32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* _ : M.Val unit := + let* α0 : unit := + M.call scoping_rules_raii.create_box in + M.alloc α0 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α2). diff --git a/CoqOfRust/examples/default/examples/std_library_types/arc.v b/CoqOfRust/examples/default/examples/std_library_types/arc.v index b85f89017..0516f0f7d 100644 --- a/CoqOfRust/examples/default/examples/std_library_types/arc.v +++ b/CoqOfRust/examples/default/examples/std_library_types/arc.v @@ -39,73 +39,102 @@ Definition main : M unit := core.ops.range.Range.start := Integer.of_Z 0; core.ops.range.Range.end_ := Integer.of_Z 10; |}) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t i32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some _ => - let* apple : M.Val (alloc.sync.Arc.t (ref str.t)) := - let* α0 : alloc.sync.Arc.t (ref str.t) := + let* α1 : M.Val (core.ops.range.Range.t i32.t) := M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t i32.t := M.call - ((core.clone.Clone.clone - (Self := alloc.sync.Arc.t (ref str.t)) + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t i32.t) (Trait := ltac:(refine _))) - (borrow apple)) in - M.alloc α0 in - let* _ : M.Val (std.thread.JoinHandle.t unit) := - let* α0 : std.thread.JoinHandle.t unit := - M.call - (std.thread.spawn - ((let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " -") in - let* α2 : M.Val (array (ref str.t)) := - M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t i32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* apple : M.Val (alloc.sync.Arc.t (ref str.t)) := + let* α0 : alloc.sync.Arc.t (ref str.t) := M.call - (core.fmt.rt.Argument.t::["new_debug"] + ((core.clone.Clone.clone + (Self := alloc.sync.Arc.t (ref str.t)) + (Trait := ltac:(refine _))) (borrow apple)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : - M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in - M.read α0) : - M unit)) in - M.alloc α0 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α1) in + M.alloc α0 in + let* _ : M.Val (std.thread.JoinHandle.t unit) := + let* α0 : std.thread.JoinHandle.t unit := + M.call + (std.thread.spawn + ((let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := + M.read (mk_str " +") in + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] + (borrow apple)) in + let* α6 : + M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val + (ref + (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : + ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] + α4 + α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + let* α0 : M.Val unit := M.alloc tt in + M.read α0) : + M unit)) in + M.alloc α0 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α2) in let* _ : M.Val unit := let* α0 : core.time.Duration.t := M.call (core.time.Duration.t::["from_secs"] (Integer.of_Z 1)) in diff --git a/CoqOfRust/examples/default/examples/std_library_types/box_stack_heap.v b/CoqOfRust/examples/default/examples/std_library_types/box_stack_heap.v index aebebd0b7..e50786d1e 100644 --- a/CoqOfRust/examples/default/examples/std_library_types/box_stack_heap.v +++ b/CoqOfRust/examples/default/examples/std_library_types/box_stack_heap.v @@ -74,9 +74,17 @@ Section Impl_core_clone_Clone_for_box_stack_heap_Point_t. (* #[allow(dead_code)] - function was ignored by the compiler *) Definition clone (self : ref Self) : M box_stack_heap.Point.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref box_stack_heap.Point.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val box_stack_heap.Point.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref box_stack_heap.Point.t := M.read self in + M.pure (deref α0)) : + M (M.Val box_stack_heap.Point.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/std_library_types/hash_map.v b/CoqOfRust/examples/default/examples/std_library_types/hash_map.v index 3fef840f3..c01770510 100644 --- a/CoqOfRust/examples/default/examples/std_library_types/hash_map.v +++ b/CoqOfRust/examples/default/examples/std_library_types/hash_map.v @@ -18,29 +18,32 @@ fn call(number: &str) -> &str { *) Definition call (number : ref str.t) : M (ref str.t) := let* number := M.alloc number in - let* α0 : ref str.t := M.read number in - let* α1 := M.read α0 in - let* α2 : M.Val (ref str.t) := - match α1 with - | _ => - let* α0 : ref str.t := - M.read - (mk_str - "We're sorry, the call cannot be completed as dialed. + let* α0 : M.Val (ref str.t) := + match_operator + number + [ + fun γ => + (let* α0 : ref str.t := + M.read + (mk_str + "We're sorry, the call cannot be completed as dialed. Please hang up and try again.") in - M.alloc α0 - | _ => - let* α0 : ref str.t := - M.read - (mk_str - "Hello, this is Mr. Awesome's Pizza. My name is Fred. + M.alloc α0) : + M (M.Val (ref str.t)); + fun γ => + (let* α0 : ref str.t := + M.read + (mk_str + "Hello, this is Mr. Awesome's Pizza. My name is Fred. What can I get for you today?") in - M.alloc α0 - | _ => - let* α0 : ref str.t := M.read (mk_str "Hi! Who is this again?") in - M.alloc α0 - end in - M.read α2. + M.alloc α0) : + M (M.Val (ref str.t)); + fun γ => + (let* α0 : ref str.t := M.read (mk_str "Hi! Who is this again?") in + M.alloc α0) : + M (M.Val (ref str.t)) + ] in + M.read α0. (* fn main() { @@ -155,46 +158,63 @@ Definition main : M unit := std.collections.hash.map.RandomState.t)::["get"] (borrow contacts) (borrow (mk_str "Daniel"))) in - match α0 with - | core.option.Option.Some number => - let* number := M.alloc number in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Calling Daniel: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α1 : M.Val (core.option.Option.t (ref (ref str.t))) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* γ0 := + let* α0 := M.read γ0 in + M.pure (deref α0) in + let* number := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Calling Daniel: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : ref str.t := M.read number in - let* α6 : ref str.t := M.call (hash_map.call α5) in - let* α7 : M.Val (ref str.t) := M.alloc α6 in - let* α8 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow α7)) in - let* α9 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α8 ] in - let* α10 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α9) in - let* α11 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α10) in - let* α12 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α11) in - let* α13 : unit := M.call (std.io.stdio._print α12) in - M.alloc α13 in - M.alloc tt - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Don't have Daniel's number. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : ref str.t := M.read number in + let* α6 : ref str.t := M.call (hash_map.call α5) in + let* α7 : M.Val (ref str.t) := M.alloc α6 in + let* α8 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow α7)) in + let* α9 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α8 ] in + let* α10 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α9) in + let* α11 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α10) in + let* α12 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α11) in + let* α13 : unit := M.call (std.io.stdio._print α12) in + M.alloc α13 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Don't have Daniel's number. ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit) + ] in let* _ : M.Val (core.option.Option.t (ref str.t)) := let* α0 : ref str.t := M.read (mk_str "Daniel") in let* α1 : ref str.t := M.read (mk_str "164-6743") in @@ -217,46 +237,63 @@ Definition main : M unit := std.collections.hash.map.RandomState.t)::["get"] (borrow contacts) (borrow (mk_str "Ashley"))) in - match α0 with - | core.option.Option.Some number => - let* number := M.alloc number in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Calling Ashley: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α1 : M.Val (core.option.Option.t (ref (ref str.t))) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* γ0 := + let* α0 := M.read γ0 in + M.pure (deref α0) in + let* number := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Calling Ashley: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : ref str.t := M.read number in - let* α6 : ref str.t := M.call (hash_map.call α5) in - let* α7 : M.Val (ref str.t) := M.alloc α6 in - let* α8 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow α7)) in - let* α9 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α8 ] in - let* α10 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α9) in - let* α11 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α10) in - let* α12 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α11) in - let* α13 : unit := M.call (std.io.stdio._print α12) in - M.alloc α13 in - M.alloc tt - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Don't have Ashley's number. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : ref str.t := M.read number in + let* α6 : ref str.t := M.call (hash_map.call α5) in + let* α7 : M.Val (ref str.t) := M.alloc α6 in + let* α8 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow α7)) in + let* α9 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α8 ] in + let* α10 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α9) in + let* α11 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α10) in + let* α12 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α11) in + let* α13 : unit := M.call (std.io.stdio._print α12) in + M.alloc α13 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Don't have Ashley's number. ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit) + ] in let* _ : M.Val (core.option.Option.t (ref str.t)) := let* α0 : core.option.Option.t (ref str.t) := M.call @@ -280,63 +317,103 @@ Definition main : M unit := (Self := std.collections.hash.map.Iter.t (ref str.t) (ref str.t)) (Trait := ltac:(refine _))) α0) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : - core.option.Option.t ((ref (ref str.t)) * (ref (ref str.t))) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - std.collections.hash.map.Iter.t (ref str.t) (ref str.t)) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some (contact, number) => - let* contact := M.alloc contact in - let* number := M.alloc number in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Calling ") in - let* α1 : ref str.t := M.read (mk_str ": ") in - let* α2 : ref str.t := M.read (mk_str " + let* α2 : M.Val (std.collections.hash.map.Iter.t (ref str.t) (ref str.t)) := + M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : + core.option.Option.t + ((ref (ref str.t)) * (ref (ref str.t))) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + std.collections.hash.map.Iter.t (ref str.t) (ref str.t)) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val + (core.option.Option.t + ((ref (ref str.t)) * (ref (ref str.t)))) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* α0 := M.read γ0 in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ0 in + let γ1 := Tuple.Access.right γ0 in + let* contact := M.copy γ0 in + let* γ1 := + let* α0 := M.read γ1 in + M.pure (deref α0) in + let* number := M.copy γ1 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Calling ") in + let* α1 : ref str.t := M.read (mk_str ": ") in + let* α2 : ref str.t := M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] - (borrow contact)) in - let* α7 : ref str.t := M.read number in - let* α8 : ref str.t := M.call (hash_map.call α7) in - let* α9 : M.Val (ref str.t) := M.alloc α8 in - let* α10 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow α9)) in - let* α11 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α6; α10 ] in - let* α12 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α11) in - let* α13 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α12) in - let* α14 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α13) in - let* α15 : unit := M.call (std.io.stdio._print α14) in - M.alloc α15 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α2). + let* α3 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow contact)) in + let* α7 : ref str.t := M.read number in + let* α8 : ref str.t := M.call (hash_map.call α7) in + let* α9 : M.Val (ref str.t) := M.alloc α8 in + let* α10 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow α9)) in + let* α11 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α10 ] in + let* α12 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α11) in + let* α13 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α12) in + let* α14 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] α5 α13) in + let* α15 : unit := + M.call (std.io.stdio._print α14) in + M.alloc α15 in + M.alloc tt in + M.alloc tt + end + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α3). diff --git a/CoqOfRust/examples/default/examples/std_library_types/hash_map_alternate_or_custom_key_types.v b/CoqOfRust/examples/default/examples/std_library_types/hash_map_alternate_or_custom_key_types.v index d22c5a115..bea0134fb 100644 --- a/CoqOfRust/examples/default/examples/std_library_types/hash_map_alternate_or_custom_key_types.v +++ b/CoqOfRust/examples/default/examples/std_library_types/hash_map_alternate_or_custom_key_types.v @@ -102,10 +102,17 @@ Section Impl_core_cmp_Eq_for_hash_map_alternate_or_custom_key_types_Account_t. *) Definition assert_receiver_is_total_eq (self : ref Self) : M unit := let* self := M.alloc self in - let _ : unit := tt in - let _ : unit := tt in let* α0 : M.Val unit := M.alloc tt in - M.read α0. + let* α1 : M.Val unit := + match_operator + α0 + [ + fun γ => + (let* α0 : M.Val unit := M.alloc tt in + match_operator α0 [ fun γ => (M.alloc tt) : M (M.Val unit) ]) : + M (M.Val unit) + ] in + M.read α1. Global Instance AssociatedFunction_assert_receiver_is_total_eq : Notations.DoubleColon Self "assert_receiver_is_total_eq" := { @@ -307,88 +314,110 @@ Definition try_logon std.collections.hash.map.RandomState.t)::["get"] α0 (borrow logon)) in + let* α2 : + M.Val + (core.option.Option.t + (ref hash_map_alternate_or_custom_key_types.AccountInfo.t)) := + M.alloc α1 in let* α0 : M.Val unit := - match α1 with - | core.option.Option.Some account_info => - let* account_info := M.alloc account_info in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Successful logon! + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* account_info := M.copy γ0 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Successful logon! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Name: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Name: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : ref hash_map_alternate_or_custom_key_types.AccountInfo.t := - M.read account_info in - let* α6 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] - (borrow (deref α5).["name"])) in - let* α7 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6 ] in - let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α7) in - let* α9 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α8) in - let* α10 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in - let* α11 : unit := M.call (std.io.stdio._print α10) in - M.alloc α11 in - M.alloc tt in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Email: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : + ref hash_map_alternate_or_custom_key_types.AccountInfo.t := + M.read account_info in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow (deref α5).["name"])) in + let* α7 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6 ] in + let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α7) in + let* α9 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α8) in + let* α10 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in + let* α11 : unit := M.call (std.io.stdio._print α10) in + M.alloc α11 in + M.alloc tt in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Email: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : ref hash_map_alternate_or_custom_key_types.AccountInfo.t := - M.read account_info in - let* α6 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] - (borrow (deref α5).["email"])) in - let* α7 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6 ] in - let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α7) in - let* α9 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α8) in - let* α10 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in - let* α11 : unit := M.call (std.io.stdio._print α10) in - M.alloc α11 in - M.alloc tt in - M.alloc tt - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Login failed! + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : + ref hash_map_alternate_or_custom_key_types.AccountInfo.t := + M.read account_info in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow (deref α5).["email"])) in + let* α7 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6 ] in + let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α7) in + let* α9 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α8) in + let* α10 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in + let* α11 : unit := M.call (std.io.stdio._print α10) in + M.alloc α11 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Login failed! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit) + ] in M.read α0. (* diff --git a/CoqOfRust/examples/default/examples/std_library_types/option.v b/CoqOfRust/examples/default/examples/std_library_types/option.v index ef4daa67b..6eb47039d 100644 --- a/CoqOfRust/examples/default/examples/std_library_types/option.v +++ b/CoqOfRust/examples/default/examples/std_library_types/option.v @@ -49,63 +49,88 @@ Definition try_division (dividend : i32.t) (divisor : i32.t) : M unit := let* α1 : i32.t := M.read divisor in let* α2 : core.option.Option.t i32.t := M.call (option.checked_division α0 α1) in - let* α3 : M.Val unit := - match α2 with - | core.option.Option.None => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " / ") in - let* α2 : ref str.t := M.read (mk_str " failed! + let* α3 : M.Val (core.option.Option.t i32.t) := M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str " / ") in + let* α2 : ref str.t := M.read (mk_str " failed! ") in - let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow dividend)) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow divisor)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt - | core.option.Option.Some quotient => - let* quotient := M.alloc quotient in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " / ") in - let* α2 : ref str.t := M.read (mk_str " = ") in - let* α3 : ref str.t := M.read (mk_str " + let* α3 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow dividend)) in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow divisor)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* quotient := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str " / ") in + let* α2 : ref str.t := M.read (mk_str " = ") in + let* α3 : ref str.t := M.read (mk_str " ") in - let* α4 : M.Val (array (ref str.t)) := M.alloc [ α0; α1; α2; α3 ] in - let* α5 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α4) in - let* α6 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α5) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow dividend)) in - let* α8 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow divisor)) in - let* α9 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow quotient)) in - let* α10 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7; α8; α9 ] in - let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α10) in - let* α12 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α11) in - let* α13 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in - let* α14 : unit := M.call (std.io.stdio._print α13) in - M.alloc α14 in - M.alloc tt - end in - M.read α3. + let* α4 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2; α3 ] in + let* α5 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α4) in + let* α6 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α5) in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow dividend)) in + let* α8 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow divisor)) in + let* α9 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow quotient)) in + let* α10 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7; α8; α9 ] in + let* α11 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α10) in + let* α12 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α11) in + let* α13 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α6 α12) in + let* α14 : unit := M.call (std.io.stdio._print α13) in + M.alloc α14 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α4. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/std_library_types/result.v b/CoqOfRust/examples/default/examples/std_library_types/result.v index 46b057ca0..2d2113a26 100644 --- a/CoqOfRust/examples/default/examples/std_library_types/result.v +++ b/CoqOfRust/examples/default/examples/std_library_types/result.v @@ -23,22 +23,49 @@ Module checked. let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref result.checked.MathError.t := M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | result.checked.MathError.DivisionByZero => - let* α0 : ref str.t := M.read (mk_str "DivisionByZero") in - M.alloc α0 - | result.checked.MathError.NonPositiveLogarithm => - let* α0 : ref str.t := M.read (mk_str "NonPositiveLogarithm") in - M.alloc α0 - | result.checked.MathError.NegativeSquareRoot => - let* α0 : ref str.t := M.read (mk_str "NegativeSquareRoot") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | result.checked.MathError.DivisionByZero => + let* α0 : ref str.t := M.read (mk_str "DivisionByZero") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | result.checked.MathError.NonPositiveLogarithm => + let* α0 : ref str.t := M.read (mk_str "NonPositiveLogarithm") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | result.checked.MathError.NegativeSquareRoot => + let* α0 : ref str.t := M.read (mk_str "NegativeSquareRoot") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { @@ -155,22 +182,49 @@ Section Impl_core_fmt_Debug_for_result_checked_MathError_t. let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref result.checked.MathError.t := M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | result.checked.MathError.DivisionByZero => - let* α0 : ref str.t := M.read (mk_str "DivisionByZero") in - M.alloc α0 - | result.checked.MathError.NonPositiveLogarithm => - let* α0 : ref str.t := M.read (mk_str "NonPositiveLogarithm") in - M.alloc α0 - | result.checked.MathError.NegativeSquareRoot => - let* α0 : ref str.t := M.read (mk_str "NegativeSquareRoot") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | result.checked.MathError.DivisionByZero => + let* α0 : ref str.t := M.read (mk_str "DivisionByZero") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | result.checked.MathError.NonPositiveLogarithm => + let* α0 : ref str.t := M.read (mk_str "NonPositiveLogarithm") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | result.checked.MathError.NegativeSquareRoot => + let* α0 : ref str.t := M.read (mk_str "NegativeSquareRoot") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; @@ -286,84 +340,154 @@ Definition op (x : f64.t) (y : f64.t) : M f64.t := let* α1 : f64.t := M.read y in let* α2 : core.result.Result.t f64.t result.checked.MathError.t := M.call (result.checked.div α0 α1) in - let* α3 : M.Val f64.t := - match α2 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow why)) in - let* α5 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α4 ] in - let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α5) in - let* α7 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α6) in - let* α8 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in - let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in - let* α10 : f64.t := never_to_any α9 in - M.alloc α10 - | core.result.Result.Ok ratio => - let* ratio := M.alloc ratio in - let* α0 : f64.t := M.read ratio in - let* α1 : core.result.Result.t f64.t result.checked.MathError.t := - M.call (result.checked.ln α0) in - match α1 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow why)) in - let* α5 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α4 ] in - let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α5) in - let* α7 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α6) in - let* α8 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in - let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in - let* α10 : f64.t := never_to_any α9 in - M.alloc α10 - | core.result.Result.Ok ln => - let* ln := M.alloc ln in - let* α0 : f64.t := M.read ln in - let* α1 : core.result.Result.t f64.t result.checked.MathError.t := - M.call (result.checked.sqrt α0) in - match α1 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow why)) in - let* α5 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α4 ] in - let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α5) in - let* α7 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α6) in - let* α8 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in - let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in - let* α10 : f64.t := never_to_any α9 in - M.alloc α10 - | core.result.Result.Ok sqrt => - let* sqrt := M.alloc sqrt in - M.pure sqrt - end - end - end in - M.read α3. + let* α3 : M.Val (core.result.Result.t f64.t result.checked.MathError.t) := + M.alloc α2 in + let* α4 : M.Val f64.t := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow why)) in + let* α5 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α4 ] in + let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α5) in + let* α7 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α6) in + let* α8 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in + let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in + let* α10 : f64.t := never_to_any α9 in + M.alloc α10 + | _ => M.break_match + end) : + M (M.Val f64.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* ratio := M.copy γ0 in + let* α0 : f64.t := M.read ratio in + let* α1 : core.result.Result.t f64.t result.checked.MathError.t := + M.call (result.checked.ln α0) in + let* α2 : + M.Val (core.result.Result.t f64.t result.checked.MathError.t) := + M.alloc α1 in + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow why)) in + let* α5 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α4 ] in + let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α5) in + let* α7 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α6) in + let* α8 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in + let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in + let* α10 : f64.t := never_to_any α9 in + M.alloc α10 + | _ => M.break_match + end) : + M (M.Val f64.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* ln := M.copy γ0 in + let* α0 : f64.t := M.read ln in + let* α1 : + core.result.Result.t f64.t result.checked.MathError.t := + M.call (result.checked.sqrt α0) in + let* α2 : + M.Val + (core.result.Result.t + f64.t + result.checked.MathError.t) := + M.alloc α1 in + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : M.Val (array (ref str.t)) := + M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] + (borrow why)) in + let* α5 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α4 ] in + let* α6 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α5) in + let* α7 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α6) in + let* α8 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in + let* α9 : never.t := + M.call (core.panicking.panic_fmt α8) in + let* α10 : f64.t := never_to_any α9 in + M.alloc α10 + | _ => M.break_match + end) : + M (M.Val f64.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* sqrt := M.copy γ0 in + M.pure sqrt + | _ => M.break_match + end) : + M (M.Val f64.t) + ] + | _ => M.break_match + end) : + M (M.Val f64.t) + ] + | _ => M.break_match + end) : + M (M.Val f64.t) + ] in + M.read α4. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/std_library_types/result_chaining_with_question_mark.v b/CoqOfRust/examples/default/examples/std_library_types/result_chaining_with_question_mark.v index a0affb14c..467b7a118 100644 --- a/CoqOfRust/examples/default/examples/std_library_types/result_chaining_with_question_mark.v +++ b/CoqOfRust/examples/default/examples/std_library_types/result_chaining_with_question_mark.v @@ -24,27 +24,55 @@ Module checked. let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref result_chaining_with_question_mark.checked.MathError.t := - M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | result_chaining_with_question_mark.checked.MathError.DivisionByZero => - let* α0 : ref str.t := M.read (mk_str "DivisionByZero") in - M.alloc α0 - | - result_chaining_with_question_mark.checked.MathError.NonPositiveLogarithm - => - let* α0 : ref str.t := M.read (mk_str "NonPositiveLogarithm") in - M.alloc α0 - | - result_chaining_with_question_mark.checked.MathError.NegativeSquareRoot - => - let* α0 : ref str.t := M.read (mk_str "NegativeSquareRoot") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.DivisionByZero + => + let* α0 : ref str.t := M.read (mk_str "DivisionByZero") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.NonPositiveLogarithm + => + let* α0 : ref str.t := M.read (mk_str "NonPositiveLogarithm") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.NegativeSquareRoot + => + let* α0 : ref str.t := M.read (mk_str "NegativeSquareRoot") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { @@ -205,36 +233,60 @@ Module checked. result_chaining_with_question_mark.checked.MathError.t) (Trait := ltac:(refine _))) α2) in - let* α4 : M.Val f64.t := - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - result_chaining_with_question_mark.checked.MathError.t := - M.read residual in - let* α1 : - core.result.Result.t - f64.t - result_chaining_with_question_mark.checked.MathError.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := + result_chaining_with_question_mark.checked.MathError.t) + f64.t) := + M.alloc α3 in + let* α5 : M.Val f64.t := + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + result_chaining_with_question_mark.checked.MathError.t := + M.read residual in + let* α1 : core.result.Result.t f64.t - result_chaining_with_question_mark.checked.MathError.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : f64.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α4 in + result_chaining_with_question_mark.checked.MathError.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + f64.t + result_chaining_with_question_mark.checked.MathError.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : f64.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val f64.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val f64.t) + ] in + M.copy α5 in let* ln : M.Val f64.t := let* α0 : f64.t := M.read ratio in let* α1 : @@ -256,36 +308,60 @@ Module checked. result_chaining_with_question_mark.checked.MathError.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val f64.t := - match α2 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α3 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - result_chaining_with_question_mark.checked.MathError.t := - M.read residual in - let* α1 : - core.result.Result.t - f64.t - result_chaining_with_question_mark.checked.MathError.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := + result_chaining_with_question_mark.checked.MathError.t) + f64.t) := + M.alloc α2 in + let* α4 : M.Val f64.t := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + result_chaining_with_question_mark.checked.MathError.t := + M.read residual in + let* α1 : core.result.Result.t f64.t - result_chaining_with_question_mark.checked.MathError.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : f64.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α3 in + result_chaining_with_question_mark.checked.MathError.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + f64.t + result_chaining_with_question_mark.checked.MathError.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : f64.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val f64.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val f64.t) + ] in + M.copy α4 in let* α0 : f64.t := M.read ln in let* α1 : core.result.Result.t @@ -325,58 +401,102 @@ Module checked. f64.t result_chaining_with_question_mark.checked.MathError.t := M.call (result_chaining_with_question_mark.checked.op_ α0 α1) in - let* α3 : M.Val unit := - match α2 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : result_chaining_with_question_mark.checked.MathError.t := - M.read why in - let* α1 : M.Val (ref str.t) := - match α0 with - | - result_chaining_with_question_mark.checked.MathError.NonPositiveLogarithm - => - M.pure (mk_str "logarithm of non-positive number") - | - result_chaining_with_question_mark.checked.MathError.DivisionByZero - => - let* α0 : ref str.t := M.read (mk_str "division by zero") in - M.alloc α0 - | - result_chaining_with_question_mark.checked.MathError.NegativeSquareRoot - => - let* α0 : ref str.t := - M.read (mk_str "square root of negative number") in - M.alloc α0 - end in - let* α2 : never.t := - M.call (core.panicking.panic_display (borrow α1)) in - let* α3 : unit := never_to_any α2 in - M.alloc α3 - | core.result.Result.Ok value => - let* value := M.alloc value in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " + let* α3 : + M.Val + (core.result.Result.t + f64.t + result_chaining_with_question_mark.checked.MathError.t) := + M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : M.Val (ref str.t) := + match_operator + why + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.NonPositiveLogarithm + => + M.pure (mk_str "logarithm of non-positive number") + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.DivisionByZero + => + let* α0 : ref str.t := + M.read (mk_str "division by zero") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.NegativeSquareRoot + => + let* α0 : ref str.t := + M.read (mk_str "square root of negative number") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α1 : never.t := + M.call (core.panicking.panic_display (borrow α0)) in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* value := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow value)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α3. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow value)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α4. End checked. Module MathError. @@ -401,27 +521,55 @@ Section Impl_core_fmt_Debug_for_result_chaining_with_question_mark_checked_MathE let* self := M.alloc self in let* f := M.alloc f in let* α0 : mut_ref core.fmt.Formatter.t := M.read f in - let* α1 : ref result_chaining_with_question_mark.checked.MathError.t := - M.read self in - let* α2 := M.read α1 in - let* α3 : M.Val (ref str.t) := - match α2 with - | result_chaining_with_question_mark.checked.MathError.DivisionByZero => - let* α0 : ref str.t := M.read (mk_str "DivisionByZero") in - M.alloc α0 - | - result_chaining_with_question_mark.checked.MathError.NonPositiveLogarithm - => - let* α0 : ref str.t := M.read (mk_str "NonPositiveLogarithm") in - M.alloc α0 - | - result_chaining_with_question_mark.checked.MathError.NegativeSquareRoot - => - let* α0 : ref str.t := M.read (mk_str "NegativeSquareRoot") in - M.alloc α0 - end in - let* α4 : ref str.t := M.read α3 in - M.call (core.fmt.Formatter.t::["write_str"] α0 α4). + let* α1 : M.Val (ref str.t) := + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.DivisionByZero + => + let* α0 : ref str.t := M.read (mk_str "DivisionByZero") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.NonPositiveLogarithm + => + let* α0 : ref str.t := M.read (mk_str "NonPositiveLogarithm") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.NegativeSquareRoot + => + let* α0 : ref str.t := M.read (mk_str "NegativeSquareRoot") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α2 : ref str.t := M.read α1 in + M.call (core.fmt.Formatter.t::["write_str"] α0 α2). Global Instance AssociatedFunction_fmt : Notations.DoubleColon Self "fmt" := { Notations.double_colon := fmt; @@ -581,36 +729,60 @@ Definition op_ result_chaining_with_question_mark.checked.MathError.t) (Trait := ltac:(refine _))) α2) in - let* α4 : M.Val f64.t := - match α3 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α4 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - result_chaining_with_question_mark.checked.MathError.t := - M.read residual in - let* α1 : - core.result.Result.t - f64.t - result_chaining_with_question_mark.checked.MathError.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := + result_chaining_with_question_mark.checked.MathError.t) + f64.t) := + M.alloc α3 in + let* α5 : M.Val f64.t := + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + result_chaining_with_question_mark.checked.MathError.t := + M.read residual in + let* α1 : core.result.Result.t f64.t - result_chaining_with_question_mark.checked.MathError.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : f64.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α4 in + result_chaining_with_question_mark.checked.MathError.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + f64.t + result_chaining_with_question_mark.checked.MathError.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : f64.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val f64.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val f64.t) + ] in + M.copy α5 in let* ln : M.Val f64.t := let* α0 : f64.t := M.read ratio in let* α1 : @@ -632,36 +804,60 @@ Definition op_ result_chaining_with_question_mark.checked.MathError.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val f64.t := - match α2 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α3 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - result_chaining_with_question_mark.checked.MathError.t := - M.read residual in - let* α1 : - core.result.Result.t - f64.t - result_chaining_with_question_mark.checked.MathError.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := + result_chaining_with_question_mark.checked.MathError.t) + f64.t) := + M.alloc α2 in + let* α4 : M.Val f64.t := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + result_chaining_with_question_mark.checked.MathError.t := + M.read residual in + let* α1 : core.result.Result.t f64.t - result_chaining_with_question_mark.checked.MathError.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : f64.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α3 in + result_chaining_with_question_mark.checked.MathError.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + f64.t + result_chaining_with_question_mark.checked.MathError.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : f64.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val f64.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val f64.t) + ] in + M.copy α4 in let* α0 : f64.t := M.read ln in let* α1 : core.result.Result.t @@ -701,55 +897,102 @@ Definition op (x : f64.t) (y : f64.t) : M unit := f64.t result_chaining_with_question_mark.checked.MathError.t := M.call (result_chaining_with_question_mark.checked.op_ α0 α1) in - let* α3 : M.Val unit := - match α2 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : result_chaining_with_question_mark.checked.MathError.t := - M.read why in - let* α1 : M.Val (ref str.t) := - match α0 with - | - result_chaining_with_question_mark.checked.MathError.NonPositiveLogarithm - => - M.pure (mk_str "logarithm of non-positive number") - | result_chaining_with_question_mark.checked.MathError.DivisionByZero => - let* α0 : ref str.t := M.read (mk_str "division by zero") in - M.alloc α0 - | - result_chaining_with_question_mark.checked.MathError.NegativeSquareRoot - => - let* α0 : ref str.t := - M.read (mk_str "square root of negative number") in - M.alloc α0 - end in - let* α2 : never.t := M.call (core.panicking.panic_display (borrow α1)) in - let* α3 : unit := never_to_any α2 in - M.alloc α3 - | core.result.Result.Ok value => - let* value := M.alloc value in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " + let* α3 : + M.Val + (core.result.Result.t + f64.t + result_chaining_with_question_mark.checked.MathError.t) := + M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : M.Val (ref str.t) := + match_operator + why + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.NonPositiveLogarithm + => + M.pure (mk_str "logarithm of non-positive number") + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.DivisionByZero + => + let* α0 : ref str.t := + M.read (mk_str "division by zero") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | + result_chaining_with_question_mark.checked.MathError.NegativeSquareRoot + => + let* α0 : ref str.t := + M.read (mk_str "square root of negative number") in + M.alloc α0 + | _ => M.break_match + end) : + M (M.Val (ref str.t)) + ] in + let* α1 : never.t := + M.call (core.panicking.panic_display (borrow α0)) in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* value := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow value)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in - M.read α3. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow value)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.read α4. (* fn main() { diff --git a/CoqOfRust/examples/default/examples/std_library_types/strings.v b/CoqOfRust/examples/default/examples/std_library_types/strings.v index b83b0166d..807acff76 100644 --- a/CoqOfRust/examples/default/examples/std_library_types/strings.v +++ b/CoqOfRust/examples/default/examples/std_library_types/strings.v @@ -98,57 +98,84 @@ Definition main : M unit := core.iter.adapters.rev.Rev.t core.str.iter.SplitWhitespace.t) (Trait := ltac:(refine _))) α2) in - let* α4 : M.Val unit := - match α3 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (ref str.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - core.iter.adapters.rev.Rev.t - core.str.iter.SplitWhitespace.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some word => - let* word := M.alloc word in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "> ") in - let* α1 : ref str.t := M.read (mk_str " + let* α4 : + M.Val (core.iter.adapters.rev.Rev.t core.str.iter.SplitWhitespace.t) := + M.alloc α3 in + let* α5 : M.Val unit := + match_operator + α4 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (ref str.t) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + core.iter.adapters.rev.Rev.t + core.str.iter.SplitWhitespace.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t (ref str.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* word := M.copy γ0 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "> ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow word)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α4) in + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow word)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α5) in let* chars : M.Val (alloc.vec.Vec.t char.t alloc.alloc.Global.t) := let* α0 : ref str.t := M.read pangram in let* α1 : core.str.iter.Chars.t := M.call (str.t::["chars"] α0) in @@ -185,48 +212,72 @@ Definition main : M unit := (Self := alloc.vec.Vec.t char.t alloc.alloc.Global.t) (Trait := ltac:(refine _))) α0) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t char.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - alloc.vec.into_iter.IntoIter.t - char.t - alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some c => - let* c := M.alloc c in - let* _ : M.Val unit := - let* α0 : char.t := M.read c in - let* α1 : unit := - M.call - (alloc.string.String.t::["push"] (borrow_mut string) α0) in - M.alloc α1 in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str ", ") in - let* α1 : unit := + let* α2 : + M.Val (alloc.vec.into_iter.IntoIter.t char.t alloc.alloc.Global.t) := + M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t char.t := M.call - (alloc.string.String.t::["push_str"] - (borrow_mut string) - α0) in - M.alloc α1 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α2) in + ((core.iter.traits.iterator.Iterator.next + (Self := + alloc.vec.into_iter.IntoIter.t + char.t + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t char.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* c := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : char.t := M.read c in + let* α1 : unit := + M.call + (alloc.string.String.t::["push"] + (borrow_mut string) + α0) in + M.alloc α1 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str ", ") in + let* α1 : unit := + M.call + (alloc.string.String.t::["push_str"] + (borrow_mut string) + α0) in + M.alloc α1 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α3) in let* chars_to_trim : M.Val (ref (slice char.t)) := let* α0 : M.Val (array char.t) := M.alloc [ " "%char; ","%char ] in let* α1 : M.Val (ref (array char.t)) := M.alloc (borrow α0) in diff --git a/CoqOfRust/examples/default/examples/std_library_types/strings_byte_strings_as_non_utf8.v b/CoqOfRust/examples/default/examples/std_library_types/strings_byte_strings_as_non_utf8.v index 0eff822a2..a842961fd 100644 --- a/CoqOfRust/examples/default/examples/std_library_types/strings_byte_strings_as_non_utf8.v +++ b/CoqOfRust/examples/default/examples/std_library_types/strings_byte_strings_as_non_utf8.v @@ -152,51 +152,76 @@ Definition main : M unit := let* α2 : ref (slice u8.t) := M.read (pointer_coercion "Unsize" α1) in let* α3 : core.result.Result.t (ref str.t) core.str.error.Utf8Error.t := M.call (core.str.converts.from_utf8 α2) in - match α3 with - | core.result.Result.Ok my_str => - let* my_str := M.alloc my_str in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Conversion successful: '") in - let* α1 : ref str.t := M.read (mk_str "' + let* α4 : + M.Val (core.result.Result.t (ref str.t) core.str.error.Utf8Error.t) := + M.alloc α3 in + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* my_str := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "Conversion successful: '") in + let* α1 : ref str.t := M.read (mk_str "' ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow my_str)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - | core.result.Result.Err e => - let* e := M.alloc e in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "Conversion failed: ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow my_str)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "Conversion failed: ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow e)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow e)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/std_library_types/vectors.v b/CoqOfRust/examples/default/examples/std_library_types/vectors.v index f6db4718f..2a1b95d47 100644 --- a/CoqOfRust/examples/default/examples/std_library_types/vectors.v +++ b/CoqOfRust/examples/default/examples/std_library_types/vectors.v @@ -268,55 +268,80 @@ Definition main : M unit := (Self := core.slice.iter.Iter.t i32.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val unit := - match α2 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (ref i32.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.slice.iter.Iter.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some x => - let* x := M.alloc x in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "> ") in - let* α1 : ref str.t := M.read (mk_str " + let* α3 : M.Val (core.slice.iter.Iter.t i32.t) := M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (ref i32.t) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.slice.iter.Iter.t i32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t (ref i32.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* x := M.copy γ0 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "> ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow x)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α3) in + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow x)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α4) in let* _ : M.Val unit := let* α0 : ref (slice i32.t) := M.call @@ -344,63 +369,102 @@ Definition main : M unit := (core.slice.iter.Iter.t i32.t)) (Trait := ltac:(refine _))) α2) in - let* α4 : M.Val unit := - match α3 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (usize.t * (ref i32.t)) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - core.iter.adapters.enumerate.Enumerate.t - (core.slice.iter.Iter.t i32.t)) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some (i, x) => - let* i := M.alloc i in - let* x := M.alloc x in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "In position ") in - let* α1 : ref str.t := M.read (mk_str " we have value ") in - let* α2 : ref str.t := M.read (mk_str " + let* α4 : + M.Val + (core.iter.adapters.enumerate.Enumerate.t + (core.slice.iter.Iter.t i32.t)) := + M.alloc α3 in + let* α5 : M.Val unit := + match_operator + α4 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (usize.t * (ref i32.t)) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + core.iter.adapters.enumerate.Enumerate.t + (core.slice.iter.Iter.t i32.t)) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val (core.option.Option.t (usize.t * (ref i32.t))) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* α0 := M.read γ0 in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ0 in + let γ1 := Tuple.Access.right γ0 in + let* i := M.copy γ0 in + let* x := M.copy γ1 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "In position ") in + let* α1 : ref str.t := + M.read (mk_str " we have value ") in + let* α2 : ref str.t := M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := - M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow i)) in - let* α7 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow x)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α4) in + let* α3 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow i)) in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow x)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := + M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + M.alloc tt + end + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α5) in let* _ : M.Val unit := let* α0 : mut_ref (slice i32.t) := M.call @@ -416,38 +480,59 @@ Definition main : M unit := (Self := core.slice.iter.IterMut.t i32.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val unit := - match α2 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (mut_ref i32.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.slice.iter.IterMut.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some x => - let* x := M.alloc x in - let* _ : M.Val unit := - let* β : M.Val i32.t := - let* α0 : mut_ref i32.t := M.read x in - M.pure (deref α0) in - let* α0 := M.read β in - let* α1 := BinOp.Panic.mul α0 (Integer.of_Z 3) in - assign β α1 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α3) in + let* α3 : M.Val (core.slice.iter.IterMut.t i32.t) := M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (mut_ref i32.t) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.slice.iter.IterMut.t i32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t (mut_ref i32.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* x := M.copy γ0 in + let* _ : M.Val unit := + let* β : M.Val i32.t := + let* α0 : mut_ref i32.t := M.read x in + M.pure (deref α0) in + let* α0 := M.read β in + let* α1 := BinOp.Panic.mul α0 (Integer.of_Z 3) in + assign β α1 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α4) in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "Updated vector: ") in diff --git a/CoqOfRust/examples/default/examples/std_misc/channels.v b/CoqOfRust/examples/default/examples/std_misc/channels.v index 99eb7f971..fb77421a0 100644 --- a/CoqOfRust/examples/default/examples/std_misc/channels.v +++ b/CoqOfRust/examples/default/examples/std_misc/channels.v @@ -48,278 +48,423 @@ fn main() { *) (* #[allow(dead_code)] - function was ignored by the compiler *) Definition main : M unit := - let* '(tx, rx) : - (std.sync.mpsc.Sender.t i32.t) * (std.sync.mpsc.Receiver.t i32.t) := + let* α0 : (std.sync.mpsc.Sender.t i32.t) * (std.sync.mpsc.Receiver.t i32.t) := M.call std.sync.mpsc.channel in - let* tx := M.alloc tx in - let* rx := M.alloc rx in - let* children : + let* α1 : M.Val - (alloc.vec.Vec.t (std.thread.JoinHandle.t unit) alloc.alloc.Global.t) := - let* α0 : - alloc.vec.Vec.t (std.thread.JoinHandle.t unit) alloc.alloc.Global.t := - M.call - (alloc.vec.Vec.t - (std.thread.JoinHandle.t unit) - alloc.alloc.Global.t)::["new"] in + ((std.sync.mpsc.Sender.t i32.t) * (std.sync.mpsc.Receiver.t i32.t)) := M.alloc α0 in - let* _ : M.Val unit := - let* α0 : ref i32.t := M.read channels.NTHREADS in - let* α1 : i32.t := M.read (deref α0) in - let* α2 : core.ops.range.Range.t i32.t := - M.call - ((core.iter.traits.collect.IntoIterator.into_iter - (Self := core.ops.range.Range.t i32.t) - (Trait := ltac:(refine _))) - {| - core.ops.range.Range.start := Integer.of_Z 0; - core.ops.range.Range.end_ := α1; - |}) in - let* α3 : M.Val unit := - match α2 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t i32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some id => - let* id := M.alloc id in - let* thread_tx : M.Val (std.sync.mpsc.Sender.t i32.t) := - let* α0 : std.sync.mpsc.Sender.t i32.t := - M.call - ((core.clone.Clone.clone - (Self := std.sync.mpsc.Sender.t i32.t) - (Trait := ltac:(refine _))) - (borrow tx)) in - M.alloc α0 in - let* child : M.Val (std.thread.JoinHandle.t unit) := - let* α0 : std.thread.JoinHandle.t unit := - M.call - (std.thread.spawn - ((let* _ : M.Val unit := - let* α0 : i32.t := M.read id in - let* α1 : - core.result.Result.t - unit - (std.sync.mpsc.SendError.t i32.t) := - M.call - ((std.sync.mpsc.Sender.t i32.t)::["send"] - (borrow thread_tx) - α0) in - let* α2 : unit := - M.call - ((core.result.Result.t - unit - (std.sync.mpsc.SendError.t i32.t))::["unwrap"] - α1) in - M.alloc α2 in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "thread ") in - let* α1 : ref str.t := M.read (mk_str " finished + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* tx := M.copy γ0 in + let* rx := M.copy γ1 in + let* children : + M.Val + (alloc.vec.Vec.t + (std.thread.JoinHandle.t unit) + alloc.alloc.Global.t) := + let* α0 : + alloc.vec.Vec.t + (std.thread.JoinHandle.t unit) + alloc.alloc.Global.t := + M.call + (alloc.vec.Vec.t + (std.thread.JoinHandle.t unit) + alloc.alloc.Global.t)::["new"] in + M.alloc α0 in + let* _ : M.Val unit := + let* α0 : ref i32.t := M.read channels.NTHREADS in + let* α1 : i32.t := M.read (deref α0) in + let* α2 : core.ops.range.Range.t i32.t := + M.call + ((core.iter.traits.collect.IntoIterator.into_iter + (Self := core.ops.range.Range.t i32.t) + (Trait := ltac:(refine _))) + {| + core.ops.range.Range.start := Integer.of_Z 0; + core.ops.range.Range.end_ := α1; + |}) in + let* α3 : M.Val (core.ops.range.Range.t i32.t) := M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t i32.t := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t i32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t i32.t) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* id := M.copy γ0 in + let* thread_tx : + M.Val (std.sync.mpsc.Sender.t i32.t) := + let* α0 : std.sync.mpsc.Sender.t i32.t := + M.call + ((core.clone.Clone.clone + (Self := + std.sync.mpsc.Sender.t i32.t) + (Trait := ltac:(refine _))) + (borrow tx)) in + M.alloc α0 in + let* child : + M.Val (std.thread.JoinHandle.t unit) := + let* α0 : std.thread.JoinHandle.t unit := + M.call + (std.thread.spawn + ((let* _ : M.Val unit := + let* α0 : i32.t := M.read id in + let* α1 : + core.result.Result.t + unit + (std.sync.mpsc.SendError.t + i32.t) := + M.call + ((std.sync.mpsc.Sender.t + i32.t)::["send"] + (borrow thread_tx) + α0) in + let* α2 : unit := + M.call + ((core.result.Result.t + unit + (std.sync.mpsc.SendError.t + i32.t))::["unwrap"] + α1) in + M.alloc α2 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "thread ") in + let* α1 : ref str.t := + M.read (mk_str " finished ") in - let* α2 : M.Val (array (ref str.t)) := - M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := + let* α2 : + M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : + M.Val + (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : + ref (slice (ref str.t)) := + M.read + (pointer_coercion + "Unsize" + α3) in + let* α5 : + core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow id)) in + let* α6 : + M.Val + (array + core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val + (ref + (array + core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : + ref + (slice + core.fmt.rt.Argument.t) := + M.read + (pointer_coercion + "Unsize" + α7) in + let* α9 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] + α4 + α8) in + let* α10 : unit := + M.call + (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + let* α0 : M.Val unit := M.alloc tt in + M.read α0) : + M unit)) in + M.alloc α0 in + let* _ : M.Val unit := + let* α0 : std.thread.JoinHandle.t unit := + M.read child in + let* α1 : unit := + M.call + ((alloc.vec.Vec.t + (std.thread.JoinHandle.t unit) + alloc.alloc.Global.t)::["push"] + (borrow_mut children) + α0) in + M.alloc α1 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α4) in + let* ids : + M.Val + (alloc.vec.Vec.t + (core.result.Result.t i32.t std.sync.mpsc.RecvError.t) + alloc.alloc.Global.t) := + let* α0 : ref i32.t := M.read channels.NTHREADS in + let* α1 : i32.t := M.read (deref α0) in + let* α2 : usize.t := cast α1 in + let* α3 : + alloc.vec.Vec.t + (core.result.Result.t i32.t std.sync.mpsc.RecvError.t) + alloc.alloc.Global.t := + M.call + ((alloc.vec.Vec.t + (core.result.Result.t i32.t std.sync.mpsc.RecvError.t) + alloc.alloc.Global.t)::["with_capacity"] + α2) in + M.alloc α3 in + let* _ : M.Val unit := + let* α0 : ref i32.t := M.read channels.NTHREADS in + let* α1 : i32.t := M.read (deref α0) in + let* α2 : core.ops.range.Range.t i32.t := + M.call + ((core.iter.traits.collect.IntoIterator.into_iter + (Self := core.ops.range.Range.t i32.t) + (Trait := ltac:(refine _))) + {| + core.ops.range.Range.start := Integer.of_Z 0; + core.ops.range.Range.end_ := α1; + |}) in + let* α3 : M.Val (core.ops.range.Range.t i32.t) := M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t i32.t := M.call - (core.fmt.rt.Argument.t::["new_display"] - (borrow id)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : - M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in - M.read α0) : - M unit)) in - M.alloc α0 in - let* _ : M.Val unit := - let* α0 : std.thread.JoinHandle.t unit := M.read child in - let* α1 : unit := - M.call - ((alloc.vec.Vec.t + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t i32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t i32.t) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* _ : M.Val unit := + let* α0 : + core.result.Result.t + i32.t + std.sync.mpsc.RecvError.t := + M.call + ((std.sync.mpsc.Receiver.t + i32.t)::["recv"] + (borrow rx)) in + let* α1 : unit := + M.call + ((alloc.vec.Vec.t + (core.result.Result.t + i32.t + std.sync.mpsc.RecvError.t) + alloc.alloc.Global.t)::["push"] + (borrow_mut ids) + α0) in + M.alloc α1 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α4) in + let* _ : M.Val unit := + let* α0 : + alloc.vec.Vec.t + (std.thread.JoinHandle.t unit) + alloc.alloc.Global.t := + M.read children in + let* α1 : + alloc.vec.into_iter.IntoIter.t + (std.thread.JoinHandle.t unit) + alloc.alloc.Global.t := + M.call + ((core.iter.traits.collect.IntoIterator.into_iter + (Self := + alloc.vec.Vec.t (std.thread.JoinHandle.t unit) - alloc.alloc.Global.t)::["push"] - (borrow_mut children) - α0) in - M.alloc α1 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α3) in - let* ids : - M.Val - (alloc.vec.Vec.t - (core.result.Result.t i32.t std.sync.mpsc.RecvError.t) - alloc.alloc.Global.t) := - let* α0 : ref i32.t := M.read channels.NTHREADS in - let* α1 : i32.t := M.read (deref α0) in - let* α2 : usize.t := cast α1 in - let* α3 : - alloc.vec.Vec.t - (core.result.Result.t i32.t std.sync.mpsc.RecvError.t) - alloc.alloc.Global.t := - M.call - ((alloc.vec.Vec.t - (core.result.Result.t i32.t std.sync.mpsc.RecvError.t) - alloc.alloc.Global.t)::["with_capacity"] - α2) in - M.alloc α3 in - let* _ : M.Val unit := - let* α0 : ref i32.t := M.read channels.NTHREADS in - let* α1 : i32.t := M.read (deref α0) in - let* α2 : core.ops.range.Range.t i32.t := - M.call - ((core.iter.traits.collect.IntoIterator.into_iter - (Self := core.ops.range.Range.t i32.t) - (Trait := ltac:(refine _))) - {| - core.ops.range.Range.start := Integer.of_Z 0; - core.ops.range.Range.end_ := α1; - |}) in - let* α3 : M.Val unit := - match α2 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t i32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some _ => - let* _ : M.Val unit := - let* α0 : - core.result.Result.t i32.t std.sync.mpsc.RecvError.t := - M.call - ((std.sync.mpsc.Receiver.t i32.t)::["recv"] (borrow rx)) in - let* α1 : unit := - M.call - ((alloc.vec.Vec.t - (core.result.Result.t i32.t std.sync.mpsc.RecvError.t) - alloc.alloc.Global.t)::["push"] - (borrow_mut ids) - α0) in + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : + M.Val + (alloc.vec.into_iter.IntoIter.t + (std.thread.JoinHandle.t unit) + alloc.alloc.Global.t) := M.alloc α1 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α3) in - let* _ : M.Val unit := - let* α0 : - alloc.vec.Vec.t (std.thread.JoinHandle.t unit) alloc.alloc.Global.t := - M.read children in - let* α1 : - alloc.vec.into_iter.IntoIter.t - (std.thread.JoinHandle.t unit) - alloc.alloc.Global.t := - M.call - ((core.iter.traits.collect.IntoIterator.into_iter - (Self := - alloc.vec.Vec.t - (std.thread.JoinHandle.t unit) - alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (std.thread.JoinHandle.t unit) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - alloc.vec.into_iter.IntoIter.t - (std.thread.JoinHandle.t unit) - alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some child => - let* child := M.alloc child in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : + core.option.Option.t + (std.thread.JoinHandle.t unit) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + alloc.vec.into_iter.IntoIter.t + (std.thread.JoinHandle.t unit) + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val + (core.option.Option.t + (std.thread.JoinHandle.t unit)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* child := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : std.thread.JoinHandle.t unit := + M.read child in + let* α1 : + core.result.Result.t + unit + (alloc.boxed.Box.t + dynamic + alloc.alloc.Global.t) := + M.call + ((std.thread.JoinHandle.t + unit)::["join"] + α0) in + let* α2 : ref str.t := + M.read + (mk_str + "oops! the child thread panicked") in + let* α3 : unit := + M.call + ((core.result.Result.t + unit + (alloc.boxed.Box.t + dynamic + alloc.alloc.Global.t))::["expect"] + α1 + α2) in + M.alloc α3 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α3) in + let* _ : M.Val unit := let* _ : M.Val unit := - let* α0 : std.thread.JoinHandle.t unit := M.read child in - let* α1 : - core.result.Result.t - unit - (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := - M.call ((std.thread.JoinHandle.t unit)::["join"] α0) in - let* α2 : ref str.t := - M.read (mk_str "oops! the child thread panicked") in - let* α3 : unit := - M.call - ((core.result.Result.t - unit - (alloc.boxed.Box.t - dynamic - alloc.alloc.Global.t))::["expect"] - α1 - α2) in - M.alloc α3 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α2) in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow ids)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in - M.read α0. + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow ids)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + end) : + M (M.Val unit) + ] in + M.read α2. diff --git a/CoqOfRust/examples/default/examples/std_misc/child_processes.v b/CoqOfRust/examples/default/examples/std_misc/child_processes.v index 8d5cae806..bc78532f2 100644 --- a/CoqOfRust/examples/default/examples/std_misc/child_processes.v +++ b/CoqOfRust/examples/default/examples/std_misc/child_processes.v @@ -37,25 +37,35 @@ Definition main : M unit := std.process.Output.t std.io.error.Error.t)::["unwrap_or_else"] α5 - (fun (e : std.io.error.Error.t) => - (let* e := M.alloc e in - let* α0 : ref str.t := - M.read (mk_str "failed to execute process: ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in - let* α5 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α4 ] in - let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α5) in - let* α7 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α6) in - let* α8 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in - let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in - never_to_any α9) : + (fun (α0 : std.io.error.Error.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* e := M.copy γ in + let* α0 : ref str.t := + M.read (mk_str "failed to execute process: ") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow e)) in + let* α5 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α4 ] in + let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α5) in + let* α7 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α6) in + let* α8 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in + let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in + never_to_any α9) : + M std.process.Output.t + ]) : M std.process.Output.t)) in M.alloc α6 in let* α0 : bool.t := diff --git a/CoqOfRust/examples/default/examples/std_misc/child_processes_pipes.v b/CoqOfRust/examples/default/examples/std_misc/child_processes_pipes.v index 7e246394e..cef078594 100644 --- a/CoqOfRust/examples/default/examples/std_misc/child_processes_pipes.v +++ b/CoqOfRust/examples/default/examples/std_misc/child_processes_pipes.v @@ -55,32 +55,53 @@ Definition main : M unit := M.call (std.process.Command.t::["stdout"] α4 α5) in let* α7 : core.result.Result.t std.process.Child.t std.io.error.Error.t := M.call (std.process.Command.t::["spawn"] α6) in - let* α8 : M.Val std.process.Child.t := - match α7 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : ref str.t := M.read (mk_str "couldn't spawn wc: ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in - let* α5 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α4 ] in - let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α5) in - let* α7 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α6) in - let* α8 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in - let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in - let* α10 : std.process.Child.t := never_to_any α9 in - M.alloc α10 - | core.result.Result.Ok process => - let* process := M.alloc process in - M.pure process - end in - M.copy α8 in + let* α8 : + M.Val (core.result.Result.t std.process.Child.t std.io.error.Error.t) := + M.alloc α7 in + let* α9 : M.Val std.process.Child.t := + match_operator + α8 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : ref str.t := M.read (mk_str "couldn't spawn wc: ") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in + let* α5 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α4 ] in + let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α5) in + let* α7 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α6) in + let* α8 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in + let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in + let* α10 : std.process.Child.t := never_to_any α9 in + M.alloc α10 + | _ => M.break_match + end) : + M (M.Val std.process.Child.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* process := M.copy γ0 in + M.pure process + | _ => M.break_match + end) : + M (M.Val std.process.Child.t) + ] in + M.copy α9 in let* _ : M.Val unit := let* α0 : core.option.Option.t std.process.ChildStdin.t := M.read process.["stdin"] in @@ -97,40 +118,60 @@ Definition main : M unit := (Trait := ltac:(refine _))) (borrow_mut α2) α5) in - match α6 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : ref str.t := M.read (mk_str "couldn't write to wc stdin: ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in - let* α5 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α4 ] in - let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α5) in - let* α7 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α6) in - let* α8 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in - let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in - let* α10 : unit := never_to_any α9 in - M.alloc α10 - | core.result.Result.Ok _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "sent pangram to wc + let* α7 : M.Val (core.result.Result.t unit std.io.error.Error.t) := + M.alloc α6 in + match_operator + α7 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : ref str.t := + M.read (mk_str "couldn't write to wc stdin: ") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in + let* α5 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α4 ] in + let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α5) in + let* α7 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α6) in + let* α8 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in + let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in + let* α10 : unit := never_to_any α9 in + M.alloc α10 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "sent pangram to wc ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* s : M.Val alloc.string.String.t := let* α0 : alloc.string.String.t := M.call alloc.string.String.t::["new"] in M.alloc α0 in @@ -146,46 +187,67 @@ Definition main : M unit := (Trait := ltac:(refine _))) (borrow_mut α2) (borrow_mut s)) in + let* α4 : M.Val (core.result.Result.t usize.t std.io.error.Error.t) := + M.alloc α3 in let* α0 : M.Val unit := - match α3 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : ref str.t := M.read (mk_str "couldn't read wc stdout: ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in - let* α5 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α4 ] in - let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α5) in - let* α7 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α6) in - let* α8 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in - let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in - let* α10 : unit := never_to_any α9 in - M.alloc α10 - | core.result.Result.Ok _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "wc responded with: + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : ref str.t := + M.read (mk_str "couldn't read wc stdout: ") in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in + let* α5 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α4 ] in + let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α5) in + let* α7 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α6) in + let* α8 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in + let* α9 : never.t := M.call (core.panicking.panic_fmt α8) in + let* α10 : unit := never_to_any α9 in + M.alloc α10 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "wc responded with: ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in - let* α5 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α4 ] in - let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α5) in - let* α7 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α6) in - let* α8 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in - let* α9 : unit := M.call (std.io.stdio._print α8) in - M.alloc α9 in - M.alloc tt - end in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in + let* α5 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α4 ] in + let* α6 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α5) in + let* α7 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α6) in + let* α8 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α3 α7) in + let* α9 : unit := M.call (std.io.stdio._print α8) in + M.alloc α9 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/std_misc/file_io_create.v b/CoqOfRust/examples/default/examples/std_misc/file_io_create.v index 2da8e30c4..11a126187 100644 --- a/CoqOfRust/examples/default/examples/std_misc/file_io_create.v +++ b/CoqOfRust/examples/default/examples/std_misc/file_io_create.v @@ -44,35 +44,56 @@ Definition main : M unit := let* file : M.Val std.fs.File.t := let* α0 : core.result.Result.t std.fs.File.t std.io.error.Error.t := M.call (std.fs.File.t::["create"] (borrow path)) in - let* α1 : M.Val std.fs.File.t := - match α0 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : ref str.t := M.read (mk_str "couldn't create ") in - let* α1 : ref str.t := M.read (mk_str ": ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in - let* α7 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5; α6 ] in - let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α7) in - let* α9 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α8) in - let* α10 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in - let* α11 : never.t := M.call (core.panicking.panic_fmt α10) in - let* α12 : std.fs.File.t := never_to_any α11 in - M.alloc α12 - | core.result.Result.Ok file => - let* file := M.alloc file in - M.pure file - end in - M.copy α1 in + let* α1 : M.Val (core.result.Result.t std.fs.File.t std.io.error.Error.t) := + M.alloc α0 in + let* α2 : M.Val std.fs.File.t := + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : ref str.t := M.read (mk_str "couldn't create ") in + let* α1 : ref str.t := M.read (mk_str ": ") in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in + let* α6 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in + let* α7 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5; α6 ] in + let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α7) in + let* α9 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α8) in + let* α10 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in + let* α11 : never.t := M.call (core.panicking.panic_fmt α10) in + let* α12 : std.fs.File.t := never_to_any α11 in + M.alloc α12 + | _ => M.break_match + end) : + M (M.Val std.fs.File.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* file := M.copy γ0 in + M.pure file + | _ => M.break_match + end) : + M (M.Val std.fs.File.t) + ] in + M.copy α2 in let* α0 : ref (ref str.t) := M.read file_io_create.LOREM_IPSUM in let* α1 : ref str.t := M.read (deref α0) in let* α2 : ref (slice u8.t) := M.call (str.t::["as_bytes"] α1) in @@ -83,50 +104,73 @@ Definition main : M unit := (Trait := ltac:(refine _))) (borrow_mut file) α2) in + let* α4 : M.Val (core.result.Result.t unit std.io.error.Error.t) := + M.alloc α3 in let* α0 : M.Val unit := - match α3 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : ref str.t := M.read (mk_str "couldn't write to ") in - let* α1 : ref str.t := M.read (mk_str ": ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in - let* α7 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5; α6 ] in - let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α7) in - let* α9 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α8) in - let* α10 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in - let* α11 : never.t := M.call (core.panicking.panic_fmt α10) in - let* α12 : unit := never_to_any α11 in - M.alloc α12 - | core.result.Result.Ok _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "successfully wrote to ") in - let* α1 : ref str.t := M.read (mk_str " + match_operator + α4 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : ref str.t := M.read (mk_str "couldn't write to ") in + let* α1 : ref str.t := M.read (mk_str ": ") in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in + let* α6 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in + let* α7 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5; α6 ] in + let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α7) in + let* α9 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α8) in + let* α10 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in + let* α11 : never.t := M.call (core.panicking.panic_fmt α10) in + let* α12 : unit := never_to_any α11 in + M.alloc α12 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "successfully wrote to ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/std_misc/file_io_open.v b/CoqOfRust/examples/default/examples/std_misc/file_io_open.v index 186bfce98..0bb0a664f 100644 --- a/CoqOfRust/examples/default/examples/std_misc/file_io_open.v +++ b/CoqOfRust/examples/default/examples/std_misc/file_io_open.v @@ -36,35 +36,56 @@ Definition main : M unit := let* file : M.Val std.fs.File.t := let* α0 : core.result.Result.t std.fs.File.t std.io.error.Error.t := M.call (std.fs.File.t::["open"] (borrow path)) in - let* α1 : M.Val std.fs.File.t := - match α0 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : ref str.t := M.read (mk_str "couldn't open ") in - let* α1 : ref str.t := M.read (mk_str ": ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in - let* α7 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5; α6 ] in - let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α7) in - let* α9 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α8) in - let* α10 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in - let* α11 : never.t := M.call (core.panicking.panic_fmt α10) in - let* α12 : std.fs.File.t := never_to_any α11 in - M.alloc α12 - | core.result.Result.Ok file => - let* file := M.alloc file in - M.pure file - end in - M.copy α1 in + let* α1 : M.Val (core.result.Result.t std.fs.File.t std.io.error.Error.t) := + M.alloc α0 in + let* α2 : M.Val std.fs.File.t := + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : ref str.t := M.read (mk_str "couldn't open ") in + let* α1 : ref str.t := M.read (mk_str ": ") in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in + let* α6 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in + let* α7 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5; α6 ] in + let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α7) in + let* α9 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α8) in + let* α10 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in + let* α11 : never.t := M.call (core.panicking.panic_fmt α10) in + let* α12 : std.fs.File.t := never_to_any α11 in + M.alloc α12 + | _ => M.break_match + end) : + M (M.Val std.fs.File.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* file := M.copy γ0 in + M.pure file + | _ => M.break_match + end) : + M (M.Val std.fs.File.t) + ] in + M.copy α2 in let* s : M.Val alloc.string.String.t := let* α0 : alloc.string.String.t := M.call alloc.string.String.t::["new"] in M.alloc α0 in @@ -75,52 +96,75 @@ Definition main : M unit := (Trait := ltac:(refine _))) (borrow_mut file) (borrow_mut s)) in + let* α1 : M.Val (core.result.Result.t usize.t std.io.error.Error.t) := + M.alloc α0 in let* α0 : M.Val unit := - match α0 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* α0 : ref str.t := M.read (mk_str "couldn't read ") in - let* α1 : ref str.t := M.read (mk_str ": ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in - let* α7 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5; α6 ] in - let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α7) in - let* α9 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α8) in - let* α10 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in - let* α11 : never.t := M.call (core.panicking.panic_fmt α10) in - let* α12 : unit := never_to_any α11 in - M.alloc α12 - | core.result.Result.Ok _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " contains: + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* α0 : ref str.t := M.read (mk_str "couldn't read ") in + let* α1 : ref str.t := M.read (mk_str ": ") in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in + let* α6 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow why)) in + let* α7 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5; α6 ] in + let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α7) in + let* α9 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α8) in + let* α10 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in + let* α11 : never.t := M.call (core.panicking.panic_fmt α10) in + let* α12 : unit := never_to_any α11 in + M.alloc α12 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str " contains: ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in - let* α6 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in - let* α7 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5; α6 ] in - let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α7) in - let* α9 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α8) in - let* α10 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in - let* α11 : unit := M.call (std.io.stdio._print α10) in - M.alloc α11 in - M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow display)) in + let* α6 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in + let* α7 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5; α6 ] in + let* α8 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α7) in + let* α9 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α8) in + let* α10 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α9) in + let* α11 : unit := M.call (std.io.stdio._print α10) in + M.alloc α11 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/std_misc/file_io_read_lines.v b/CoqOfRust/examples/default/examples/std_misc/file_io_read_lines.v index 8d853b68f..0198e69b6 100644 --- a/CoqOfRust/examples/default/examples/std_misc/file_io_read_lines.v +++ b/CoqOfRust/examples/default/examples/std_misc/file_io_read_lines.v @@ -87,70 +87,103 @@ Definition main : M unit := (std.io.buffered.bufreader.BufReader.t std.fs.File.t)) (Trait := ltac:(refine _))) α0) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : - core.option.Option.t - (core.result.Result.t - alloc.string.String.t - std.io.error.Error.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - std.io.Lines.t - (std.io.buffered.bufreader.BufReader.t std.fs.File.t)) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some line => - let* line := M.alloc line in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " -") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : - core.result.Result.t + let* α2 : + M.Val + (std.io.Lines.t + (std.io.buffered.bufreader.BufReader.t std.fs.File.t)) := + M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : + core.option.Option.t + (core.result.Result.t alloc.string.String.t - std.io.error.Error.t := - M.read line in - let* α6 : alloc.string.String.t := - M.call - ((core.result.Result.t - alloc.string.String.t - std.io.error.Error.t)::["unwrap"] - α5) in - let* α7 : M.Val alloc.string.String.t := M.alloc α6 in - let* α8 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow α7)) in - let* α9 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α8 ] in - let* α10 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α9) in - let* α11 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α10) in - let* α12 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α11) in - let* α13 : unit := M.call (std.io.stdio._print α12) in - M.alloc α13 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α2). + std.io.error.Error.t) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + std.io.Lines.t + (std.io.buffered.bufreader.BufReader.t std.fs.File.t)) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val + (core.option.Option.t + (core.result.Result.t + alloc.string.String.t + std.io.error.Error.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* line := M.copy γ0 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str " +") in + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : + core.result.Result.t + alloc.string.String.t + std.io.error.Error.t := + M.read line in + let* α6 : alloc.string.String.t := + M.call + ((core.result.Result.t + alloc.string.String.t + std.io.error.Error.t)::["unwrap"] + α5) in + let* α7 : M.Val alloc.string.String.t := M.alloc α6 in + let* α8 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow α7)) in + let* α9 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α8 ] in + let* α10 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α9) in + let* α11 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α10) in + let* α12 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α11) in + let* α13 : unit := M.call (std.io.stdio._print α12) in + M.alloc α13 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α3). diff --git a/CoqOfRust/examples/default/examples/std_misc/file_io_read_lines_efficient_method.v b/CoqOfRust/examples/default/examples/std_misc/file_io_read_lines_efficient_method.v index 8cd1a4e82..52d841441 100644 --- a/CoqOfRust/examples/default/examples/std_misc/file_io_read_lines_efficient_method.v +++ b/CoqOfRust/examples/default/examples/std_misc/file_io_read_lines_efficient_method.v @@ -46,69 +46,105 @@ Definition main : M unit := (std.io.buffered.bufreader.BufReader.t std.fs.File.t)) (Trait := ltac:(refine _))) α0) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : - core.option.Option.t - (core.result.Result.t - alloc.string.String.t - std.io.error.Error.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - std.io.Lines.t - (std.io.buffered.bufreader.BufReader.t std.fs.File.t)) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some line => - let* line := M.alloc line in - let* α0 : M.Val bool.t := - let_if core.result.Result.Ok ip := line in - let* α1 : bool.t := M.read α0 in - if α1 then - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : + M.Val + (std.io.Lines.t + (std.io.buffered.bufreader.BufReader.t std.fs.File.t)) := + M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : + core.option.Option.t + (core.result.Result.t + alloc.string.String.t + std.io.error.Error.t) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + std.io.Lines.t + (std.io.buffered.bufreader.BufReader.t + std.fs.File.t)) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val + (core.option.Option.t + (core.result.Result.t + alloc.string.String.t + std.io.error.Error.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* line := M.copy γ0 in + let* α0 : M.Val bool.t := + let_if core.result.Result.Ok ip := line in + let* α1 : bool.t := M.read α0 in + if α1 then + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := - M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] - (borrow ip)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - else - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α2) + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow ip)) in + let* α6 : + M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val + (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + else + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α3) else M.alloc tt in M.read α5. @@ -154,38 +190,63 @@ Definition read_lines (Self := core.result.Result.t std.fs.File.t std.io.error.Error.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val std.fs.File.t := - match α2 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α3 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - std.io.error.Error.t := - M.read residual in - let* α1 : - core.result.Result.t - (std.io.Lines.t - (std.io.buffered.bufreader.BufReader.t std.fs.File.t)) - std.io.error.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := + std.io.error.Error.t) + std.fs.File.t) := + M.alloc α2 in + let* α4 : M.Val std.fs.File.t := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + std.io.error.Error.t := + M.read residual in + let* α1 : core.result.Result.t (std.io.Lines.t (std.io.buffered.bufreader.BufReader.t std.fs.File.t)) - std.io.error.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : std.fs.File.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α3 in + std.io.error.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + (std.io.Lines.t + (std.io.buffered.bufreader.BufReader.t + std.fs.File.t)) + std.io.error.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : std.fs.File.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val std.fs.File.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val std.fs.File.t) + ] in + M.copy α4 in let* α0 : std.fs.File.t := M.read file in let* α1 : std.io.buffered.bufreader.BufReader.t std.fs.File.t := M.call diff --git a/CoqOfRust/examples/default/examples/std_misc/filesystem_operations.v b/CoqOfRust/examples/default/examples/std_misc/filesystem_operations.v index e5c9311e3..04b50a7ec 100644 --- a/CoqOfRust/examples/default/examples/std_misc/filesystem_operations.v +++ b/CoqOfRust/examples/default/examples/std_misc/filesystem_operations.v @@ -33,34 +33,60 @@ Definition cat (Self := core.result.Result.t std.fs.File.t std.io.error.Error.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val std.fs.File.t := - match α2 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α3 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - std.io.error.Error.t := - M.read residual in - let* α1 : - core.result.Result.t alloc.string.String.t std.io.error.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := + std.io.error.Error.t) + std.fs.File.t) := + M.alloc α2 in + let* α4 : M.Val std.fs.File.t := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + std.io.error.Error.t := + M.read residual in + let* α1 : core.result.Result.t alloc.string.String.t - std.io.error.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : std.fs.File.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α3 in + std.io.error.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := + core.result.Result.t + alloc.string.String.t + std.io.error.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : std.fs.File.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val std.fs.File.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val std.fs.File.t) + ] in + M.copy α4 in let* s : M.Val alloc.string.String.t := let* α0 : alloc.string.String.t := M.call alloc.string.String.t::["new"] in @@ -72,18 +98,44 @@ Definition cat (Trait := ltac:(refine _))) (borrow_mut f) (borrow_mut s)) in + let* α1 : M.Val (core.result.Result.t usize.t std.io.error.Error.t) := + M.alloc α0 in let* α0 : M.Val (core.result.Result.t alloc.string.String.t std.io.error.Error.t) := - match α0 with - | core.result.Result.Ok _ => - let* α0 : alloc.string.String.t := M.read s in - M.alloc (core.result.Result.Ok α0) - | core.result.Result.Err e => - let* e := M.alloc e in - let* α0 : std.io.error.Error.t := M.read e in - M.alloc (core.result.Result.Err α0) - end in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* α0 : alloc.string.String.t := M.read s in + M.alloc (core.result.Result.Ok α0) + | _ => M.break_match + end) : + M + (M.Val + (core.result.Result.t + alloc.string.String.t + std.io.error.Error.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* α0 : std.io.error.Error.t := M.read e in + M.alloc (core.result.Result.Err α0) + | _ => M.break_match + end) : + M + (M.Val + (core.result.Result.t + alloc.string.String.t + std.io.error.Error.t)) + ] in M.read α0). (* @@ -116,30 +168,54 @@ Definition echo (Self := core.result.Result.t std.fs.File.t std.io.error.Error.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val std.fs.File.t := - match α2 with - | core.ops.control_flow.ControlFlow.Break residual => - let* residual := M.alloc residual in - let* α0 : - core.result.Result.t + let* α3 : + M.Val + (core.ops.control_flow.ControlFlow.t + (core.result.Result.t core.convert.Infallible.t - std.io.error.Error.t := - M.read residual in - let* α1 : core.result.Result.t unit std.io.error.Error.t := - M.call - ((core.ops.try_trait.FromResidual.from_residual - (Self := core.result.Result.t unit std.io.error.Error.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val never.t := return_ α1 in - let* α3 := M.read α2 in - let* α4 : std.fs.File.t := never_to_any α3 in - M.alloc α4 - | core.ops.control_flow.ControlFlow.Continue val => - let* val := M.alloc val in - M.pure val - end in - M.copy α3 in + std.io.error.Error.t) + std.fs.File.t) := + M.alloc α2 in + let* α4 : M.Val std.fs.File.t := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Break _ => + let γ0 := γ.["Break.0"] in + let* residual := M.copy γ0 in + let* α0 : + core.result.Result.t + core.convert.Infallible.t + std.io.error.Error.t := + M.read residual in + let* α1 : core.result.Result.t unit std.io.error.Error.t := + M.call + ((core.ops.try_trait.FromResidual.from_residual + (Self := core.result.Result.t unit std.io.error.Error.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val never.t := return_ α1 in + let* α3 := M.read α2 in + let* α4 : std.fs.File.t := never_to_any α3 in + M.alloc α4 + | _ => M.break_match + end) : + M (M.Val std.fs.File.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.ops.control_flow.ControlFlow.Continue _ => + let γ0 := γ.["Continue.0"] in + let* val := M.copy γ0 in + M.pure val + | _ => M.break_match + end) : + M (M.Val std.fs.File.t) + ] in + M.copy α4 in let* α0 : ref str.t := M.read s in let* α1 : ref (slice u8.t) := M.call (str.t::["as_bytes"] α0) in let* α2 : core.result.Result.t unit std.io.error.Error.t := @@ -174,15 +250,34 @@ Definition touch let* α4 : ref std.path.Path.t := M.read path in let* α5 : core.result.Result.t std.fs.File.t std.io.error.Error.t := M.call (std.fs.OpenOptions.t::["open"] (borrow (deref α3)) α4) in - let* α6 : M.Val (core.result.Result.t unit std.io.error.Error.t) := - match α5 with - | core.result.Result.Ok _ => M.alloc (core.result.Result.Ok tt) - | core.result.Result.Err e => - let* e := M.alloc e in - let* α0 : std.io.error.Error.t := M.read e in - M.alloc (core.result.Result.Err α0) - end in - M.read α6. + let* α6 : M.Val (core.result.Result.t std.fs.File.t std.io.error.Error.t) := + M.alloc α5 in + let* α7 : M.Val (core.result.Result.t unit std.io.error.Error.t) := + match_operator + α6 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + M.alloc (core.result.Result.Ok tt) + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit std.io.error.Error.t)); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* e := M.copy γ0 in + let* α0 : std.io.error.Error.t := M.read e in + M.alloc (core.result.Result.Err α0) + | _ => M.break_match + end) : + M (M.Val (core.result.Result.t unit std.io.error.Error.t)) + ] in + M.read α7. (* fn main() { @@ -267,34 +362,55 @@ Definition main : M unit := let* α0 : ref str.t := M.read (mk_str "a") in let* α1 : core.result.Result.t unit std.io.error.Error.t := M.call (std.fs.create_dir α0) in - match α1 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "! ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (core.result.Result.t unit std.io.error.Error.t) := + M.alloc α1 in + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "! ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : std.io.error.ErrorKind.t := - M.call (std.io.error.Error.t::["kind"] (borrow why)) in - let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt - | core.result.Result.Ok _ => M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : std.io.error.ErrorKind.t := + M.call (std.io.error.Error.t::["kind"] (borrow why)) in + let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "`echo hello > a/b.txt` @@ -318,36 +434,45 @@ Definition main : M unit := M.call ((core.result.Result.t unit std.io.error.Error.t)::["unwrap_or_else"] α3 - (fun (why : std.io.error.Error.t) => - (let* why := M.alloc why in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "! ") in - let* α1 : ref str.t := M.read (mk_str " + (fun (α0 : std.io.error.Error.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* why := M.copy γ in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "! ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : std.io.error.ErrorKind.t := - M.call (std.io.error.Error.t::["kind"] (borrow why)) in - let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in - M.read α0) : + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : std.io.error.ErrorKind.t := + M.call (std.io.error.Error.t::["kind"] (borrow why)) in + let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + let* α0 : M.Val unit := M.alloc tt in + M.read α0) : + M unit + ]) : M unit)) in M.alloc α4 in let* _ : M.Val unit := @@ -371,36 +496,45 @@ Definition main : M unit := M.call ((core.result.Result.t unit std.io.error.Error.t)::["unwrap_or_else"] α1 - (fun (why : std.io.error.Error.t) => - (let* why := M.alloc why in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "! ") in - let* α1 : ref str.t := M.read (mk_str " + (fun (α0 : std.io.error.Error.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* why := M.copy γ in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "! ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : std.io.error.ErrorKind.t := - M.call (std.io.error.Error.t::["kind"] (borrow why)) in - let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in - M.read α0) : + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : std.io.error.ErrorKind.t := + M.call (std.io.error.Error.t::["kind"] (borrow why)) in + let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + let* α0 : M.Val unit := M.alloc tt in + M.read α0) : + M unit + ]) : M unit)) in M.alloc α2 in let* _ : M.Val unit := @@ -425,36 +559,45 @@ Definition main : M unit := M.call ((core.result.Result.t unit std.io.error.Error.t)::["unwrap_or_else"] α2 - (fun (why : std.io.error.Error.t) => - (let* why := M.alloc why in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "! ") in - let* α1 : ref str.t := M.read (mk_str " + (fun (α0 : std.io.error.Error.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* why := M.copy γ in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "! ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : std.io.error.ErrorKind.t := - M.call (std.io.error.Error.t::["kind"] (borrow why)) in - let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in - M.read α0) : + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : std.io.error.ErrorKind.t := + M.call (std.io.error.Error.t::["kind"] (borrow why)) in + let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + let* α0 : M.Val unit := M.alloc tt in + M.read α0) : + M unit + ]) : M unit)) in M.alloc α3 in let* _ : M.Val unit := @@ -485,37 +628,49 @@ Definition main : M unit := unit std.io.error.Error.t)::["unwrap_or_else"] α2 - (fun (why : std.io.error.Error.t) => - (let* why := M.alloc why in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "! ") in - let* α1 : ref str.t := M.read (mk_str " + (fun (α0 : std.io.error.Error.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* why := M.copy γ in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "! ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : std.io.error.ErrorKind.t := - M.call (std.io.error.Error.t::["kind"] (borrow why)) in - let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in - let* α7 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in - M.read α0) : + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : std.io.error.ErrorKind.t := + M.call + (std.io.error.Error.t::["kind"] (borrow why)) in + let* α6 : M.Val std.io.error.ErrorKind.t := + M.alloc α5 in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] + (borrow α6)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7 ] in + let* α9 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + let* α0 : M.Val unit := M.alloc tt in + M.read α0) : + M unit + ]) : M unit)) in M.alloc α3 in M.alloc tt @@ -539,55 +694,79 @@ Definition main : M unit := let* α1 : ref std.path.Path.t := M.call (std.path.Path.t::["new"] α0) in let* α2 : core.result.Result.t alloc.string.String.t std.io.error.Error.t := M.call (filesystem_operations.cat α1) in - match α2 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "! ") in - let* α1 : ref str.t := M.read (mk_str " + let* α3 : + M.Val + (core.result.Result.t alloc.string.String.t std.io.error.Error.t) := + M.alloc α2 in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "! ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : std.io.error.ErrorKind.t := - M.call (std.io.error.Error.t::["kind"] (borrow why)) in - let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt - | core.result.Result.Ok s => - let* s := M.alloc s in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "> ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : std.io.error.ErrorKind.t := + M.call (std.io.error.Error.t::["kind"] (borrow why)) in + let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* s := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "> ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "`ls a` @@ -605,110 +784,174 @@ Definition main : M unit := let* α0 : ref str.t := M.read (mk_str "a") in let* α1 : core.result.Result.t std.fs.ReadDir.t std.io.error.Error.t := M.call (std.fs.read_dir α0) in - match α1 with - | core.result.Result.Err why => - let* why := M.alloc why in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "! ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : + M.Val (core.result.Result.t std.fs.ReadDir.t std.io.error.Error.t) := + M.alloc α1 in + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* why := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "! ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : std.io.error.ErrorKind.t := - M.call (std.io.error.Error.t::["kind"] (borrow why)) in - let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt - | core.result.Result.Ok paths => - let* paths := M.alloc paths in - let* α0 : std.fs.ReadDir.t := M.read paths in - let* α1 : std.fs.ReadDir.t := - M.call - ((core.iter.traits.collect.IntoIterator.into_iter - (Self := std.fs.ReadDir.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : - core.option.Option.t - (core.result.Result.t - std.fs.DirEntry.t - std.io.error.Error.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := std.fs.ReadDir.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some path => - let* path := M.alloc path in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "> ") in - let* α1 : ref str.t := M.read (mk_str " + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : std.io.error.ErrorKind.t := + M.call (std.io.error.Error.t::["kind"] (borrow why)) in + let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in + let* α7 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* paths := M.copy γ0 in + let* α0 : std.fs.ReadDir.t := M.read paths in + let* α1 : std.fs.ReadDir.t := + M.call + ((core.iter.traits.collect.IntoIterator.into_iter + (Self := std.fs.ReadDir.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : M.Val std.fs.ReadDir.t := M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : + core.option.Option.t + (core.result.Result.t + std.fs.DirEntry.t + std.io.error.Error.t) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := std.fs.ReadDir.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val + (core.option.Option.t + (core.result.Result.t + std.fs.DirEntry.t + std.io.error.Error.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* path := M.copy γ0 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "> ") in + let* α1 : ref str.t := + M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : - core.result.Result.t - std.fs.DirEntry.t - std.io.error.Error.t := - M.read path in - let* α6 : std.fs.DirEntry.t := - M.call - ((core.result.Result.t - std.fs.DirEntry.t - std.io.error.Error.t)::["unwrap"] - α5) in - let* α7 : M.Val std.fs.DirEntry.t := M.alloc α6 in - let* α8 : std.path.PathBuf.t := - M.call (std.fs.DirEntry.t::["path"] (borrow α7)) in - let* α9 : M.Val std.path.PathBuf.t := M.alloc α8 in - let* α10 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_debug"] (borrow α9)) in - let* α11 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α10 ] in - let* α12 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α11) in - let* α13 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α12) in - let* α14 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α13) in - let* α15 : unit := M.call (std.io.stdio._print α14) in - M.alloc α15 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α2) - end in + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : + core.result.Result.t + std.fs.DirEntry.t + std.io.error.Error.t := + M.read path in + let* α6 : std.fs.DirEntry.t := + M.call + ((core.result.Result.t + std.fs.DirEntry.t + std.io.error.Error.t)::["unwrap"] + α5) in + let* α7 : M.Val std.fs.DirEntry.t := + M.alloc α6 in + let* α8 : std.path.PathBuf.t := + M.call + (std.fs.DirEntry.t::["path"] + (borrow α7)) in + let* α9 : M.Val std.path.PathBuf.t := + M.alloc α8 in + let* α10 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] + (borrow α9)) in + let* α11 : + M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α10 ] in + let* α12 : + M.Val + (ref + (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α11) in + let* α13 : + ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α12) in + let* α14 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] + α4 + α13) in + let* α15 : unit := + M.call (std.io.stdio._print α14) in + M.alloc α15 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α3) + | _ => M.break_match + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "`rm a/c/e.txt` @@ -730,36 +973,45 @@ Definition main : M unit := M.call ((core.result.Result.t unit std.io.error.Error.t)::["unwrap_or_else"] α1 - (fun (why : std.io.error.Error.t) => - (let* why := M.alloc why in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "! ") in - let* α1 : ref str.t := M.read (mk_str " + (fun (α0 : std.io.error.Error.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* why := M.copy γ in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "! ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : std.io.error.ErrorKind.t := - M.call (std.io.error.Error.t::["kind"] (borrow why)) in - let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in - M.read α0) : + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : std.io.error.ErrorKind.t := + M.call (std.io.error.Error.t::["kind"] (borrow why)) in + let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + let* α0 : M.Val unit := M.alloc tt in + M.read α0) : + M unit + ]) : M unit)) in M.alloc α2 in let* _ : M.Val unit := @@ -783,36 +1035,45 @@ Definition main : M unit := M.call ((core.result.Result.t unit std.io.error.Error.t)::["unwrap_or_else"] α1 - (fun (why : std.io.error.Error.t) => - (let* why := M.alloc why in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "! ") in - let* α1 : ref str.t := M.read (mk_str " + (fun (α0 : std.io.error.Error.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* why := M.copy γ in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "! ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : std.io.error.ErrorKind.t := - M.call (std.io.error.Error.t::["kind"] (borrow why)) in - let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in - M.read α0) : + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : std.io.error.ErrorKind.t := + M.call (std.io.error.Error.t::["kind"] (borrow why)) in + let* α6 : M.Val std.io.error.ErrorKind.t := M.alloc α5 in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_debug"] (borrow α6)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α10) in + let* α12 : unit := M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + let* α0 : M.Val unit := M.alloc tt in + M.read α0) : + M unit + ]) : M unit)) in M.alloc α2 in let* α0 : M.Val unit := M.alloc tt in diff --git a/CoqOfRust/examples/default/examples/std_misc/foreign_function_interface.v b/CoqOfRust/examples/default/examples/std_misc/foreign_function_interface.v index 3cd425801..24a42f640 100644 --- a/CoqOfRust/examples/default/examples/std_misc/foreign_function_interface.v +++ b/CoqOfRust/examples/default/examples/std_misc/foreign_function_interface.v @@ -132,9 +132,18 @@ Section Impl_core_clone_Clone_for_foreign_function_interface_Complex_t. *) Definition clone (self : ref Self) : M foreign_function_interface.Complex.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref foreign_function_interface.Complex.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val foreign_function_interface.Complex.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref foreign_function_interface.Complex.t := + M.read self in + M.pure (deref α0)) : + M (M.Val foreign_function_interface.Complex.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { diff --git a/CoqOfRust/examples/default/examples/std_misc/path.v b/CoqOfRust/examples/default/examples/std_misc/path.v index 10d01ba85..ce99b0210 100644 --- a/CoqOfRust/examples/default/examples/std_misc/path.v +++ b/CoqOfRust/examples/default/examples/std_misc/path.v @@ -74,35 +74,53 @@ Definition main : M unit := (borrow new_path)) in let* α1 : core.option.Option.t (ref str.t) := M.call (std.path.Path.t::["to_str"] α0) in + let* α2 : M.Val (core.option.Option.t (ref str.t)) := M.alloc α1 in let* α0 : M.Val unit := - match α1 with - | core.option.Option.None => - let* α0 : ref str.t := - M.read (mk_str "new path is not a valid UTF-8 sequence") in - let* α1 : never.t := M.call (std.panicking.begin_panic α0) in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some s => - let* s := M.alloc s in - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "new path is ") in - let* α1 : ref str.t := M.read (mk_str " + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : ref str.t := + M.read (mk_str "new path is not a valid UTF-8 sequence") in + let* α1 : never.t := M.call (std.panicking.begin_panic α0) in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* s := M.copy γ0 in + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "new path is ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt - end in + let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call (core.fmt.rt.Argument.t::["new_display"] (borrow s)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in M.read α0. diff --git a/CoqOfRust/examples/default/examples/std_misc/program_arguments_parsing.v b/CoqOfRust/examples/default/examples/std_misc/program_arguments_parsing.v index a39c1d318..cf9f53469 100644 --- a/CoqOfRust/examples/default/examples/std_misc/program_arguments_parsing.v +++ b/CoqOfRust/examples/default/examples/std_misc/program_arguments_parsing.v @@ -167,178 +167,246 @@ Definition main : M unit := M.call ((alloc.vec.Vec.t alloc.string.String.t alloc.alloc.Global.t)::["len"] (borrow args)) in + let* α1 : M.Val usize.t := M.alloc α0 in let* α0 : M.Val unit := - match α0 with - | _ => - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read - (mk_str - "My name is 'match_args'. Try passing some arguments! + match_operator + α1 + [ + fun γ => + (let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read + (mk_str + "My name is 'match_args'. Try passing some arguments! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt in - M.alloc tt - | _ => - let* α0 : ref alloc.string.String.t := - M.call - ((core.ops.index.Index.index - (Self := - alloc.vec.Vec.t alloc.string.String.t alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - (borrow args) - (Integer.of_Z 1)) in - let* α1 : ref str.t := - M.call - ((core.ops.deref.Deref.deref - (Self := alloc.string.String.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call (str.t::["parse"] α1) in - match α2 with - | core.result.Result.Ok _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "This is the answer! + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt in + M.alloc tt) : + M (M.Val unit); + fun γ => + (let* α0 : ref alloc.string.String.t := + M.call + ((core.ops.index.Index.index + (Self := + alloc.vec.Vec.t + alloc.string.String.t + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + (borrow args) + (Integer.of_Z 1)) in + let* α1 : ref str.t := + M.call + ((core.ops.deref.Deref.deref + (Self := alloc.string.String.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : + core.result.Result.t i32.t core.num.error.ParseIntError.t := + M.call (str.t::["parse"] α1) in + let* α3 : + M.Val + (core.result.Result.t i32.t core.num.error.ParseIntError.t) := + M.alloc α2 in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "This is the answer! ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - | _ => - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "This is not the answer. + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "This is not the answer. ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._print α4) in - M.alloc α5 in - M.alloc tt - end - | _ => - let* cmd : M.Val (ref alloc.string.String.t) := - let* α0 : ref alloc.string.String.t := - M.call - ((core.ops.index.Index.index - (Self := - alloc.vec.Vec.t alloc.string.String.t alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - (borrow args) - (Integer.of_Z 1)) in - M.alloc α0 in - let* num : M.Val (ref alloc.string.String.t) := - let* α0 : ref alloc.string.String.t := - M.call - ((core.ops.index.Index.index - (Self := - alloc.vec.Vec.t alloc.string.String.t alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - (borrow args) - (Integer.of_Z 2)) in - M.alloc α0 in - let* number : M.Val i32.t := - let* α0 : ref alloc.string.String.t := M.read num in - let* α1 : ref str.t := - M.call - ((core.ops.deref.Deref.deref - (Self := alloc.string.String.t) - (Trait := ltac:(refine _))) - α0) in - let* α2 : core.result.Result.t i32.t core.num.error.ParseIntError.t := - M.call (str.t::["parse"] α1) in - let* α3 : M.Val i32.t := - match α2 with - | core.result.Result.Ok n => - let* n := M.alloc n in - M.pure n - | core.result.Result.Err _ => - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "error: second argument not an integer + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._print α4) in + M.alloc α5 in + M.alloc tt) : + M (M.Val unit) + ]) : + M (M.Val unit); + fun γ => + (let* cmd : M.Val (ref alloc.string.String.t) := + let* α0 : ref alloc.string.String.t := + M.call + ((core.ops.index.Index.index + (Self := + alloc.vec.Vec.t + alloc.string.String.t + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + (borrow args) + (Integer.of_Z 1)) in + M.alloc α0 in + let* num : M.Val (ref alloc.string.String.t) := + let* α0 : ref alloc.string.String.t := + M.call + ((core.ops.index.Index.index + (Self := + alloc.vec.Vec.t + alloc.string.String.t + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + (borrow args) + (Integer.of_Z 2)) in + M.alloc α0 in + let* number : M.Val i32.t := + let* α0 : ref alloc.string.String.t := M.read num in + let* α1 : ref str.t := + M.call + ((core.ops.deref.Deref.deref + (Self := alloc.string.String.t) + (Trait := ltac:(refine _))) + α0) in + let* α2 : + core.result.Result.t i32.t core.num.error.ParseIntError.t := + M.call (str.t::["parse"] α1) in + let* α3 : + M.Val + (core.result.Result.t + i32.t + core.num.error.ParseIntError.t) := + M.alloc α2 in + let* α4 : M.Val i32.t := + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Ok _ => + let γ0 := γ.["Ok.0"] in + let* n := M.copy γ0 in + M.pure n + | _ => M.break_match + end) : + M (M.Val i32.t); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.result.Result.Err _ => + let γ0 := γ.["Err.0"] in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read + (mk_str + "error: second argument not an integer ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._eprint α4) in - M.alloc α5 in - M.alloc tt in - let* _ : M.Val unit := - let* α0 : unit := M.call program_arguments_parsing.help in - M.alloc α0 in - let* _ : M.Val never.t := - let* α0 : M.Val unit := M.alloc tt in - return_ α0 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : i32.t := never_to_any α1 in - M.alloc α2 - end in - M.copy α3 in - let* α0 : ref alloc.string.String.t := M.read cmd in - let* α1 : ref str.t := - M.call - ((core.ops.index.Index.index - (Self := alloc.string.String.t) - (Trait := ltac:(refine _))) - α0 - core.ops.range.RangeFull.Build) in - let* α2 := M.read α1 in - match α2 with - | _ => - let* α0 : i32.t := M.read number in - let* α1 : unit := M.call (program_arguments_parsing.increase α0) in - M.alloc α1 - | _ => - let* α0 : i32.t := M.read number in - let* α1 : unit := M.call (program_arguments_parsing.decrease α0) in - M.alloc α1 - | _ => - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "error: invalid command + let* α1 : M.Val (array (ref str.t)) := + M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := + M.call (std.io.stdio._eprint α4) in + M.alloc α5 in + M.alloc tt in + let* _ : M.Val unit := + let* α0 : unit := + M.call program_arguments_parsing.help in + M.alloc α0 in + let* _ : M.Val never.t := + let* α0 : M.Val unit := M.alloc tt in + return_ α0 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : i32.t := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val i32.t) + ] in + M.copy α4 in + let* α0 : ref alloc.string.String.t := M.read cmd in + let* α1 : ref str.t := + M.call + ((core.ops.index.Index.index + (Self := alloc.string.String.t) + (Trait := ltac:(refine _))) + α0 + core.ops.range.RangeFull.Build) in + let* α2 : M.Val (ref str.t) := M.alloc α1 in + match_operator + α2 + [ + fun γ => + (let* α0 : i32.t := M.read number in + let* α1 : unit := + M.call (program_arguments_parsing.increase α0) in + M.alloc α1) : + M (M.Val unit); + fun γ => + (let* α0 : i32.t := M.read number in + let* α1 : unit := + M.call (program_arguments_parsing.decrease α0) in + M.alloc α1) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "error: invalid command ") in - let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in - let* α2 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α1) in - let* α3 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α2) in - let* α4 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_const"] α3) in - let* α5 : unit := M.call (std.io.stdio._eprint α4) in - M.alloc α5 in - M.alloc tt in - let* _ : M.Val unit := - let* α0 : unit := M.call program_arguments_parsing.help in - M.alloc α0 in - M.alloc tt - end - | _ => - let* _ : M.Val unit := - let* α0 : unit := M.call program_arguments_parsing.help in - M.alloc α0 in - M.alloc tt - end in + let* α1 : M.Val (array (ref str.t)) := M.alloc [ α0 ] in + let* α2 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α1) in + let* α3 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α2) in + let* α4 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_const"] α3) in + let* α5 : unit := M.call (std.io.stdio._eprint α4) in + M.alloc α5 in + M.alloc tt in + let* _ : M.Val unit := + let* α0 : unit := M.call program_arguments_parsing.help in + M.alloc α0 in + M.alloc tt) : + M (M.Val unit) + ]) : + M (M.Val unit); + fun γ => + (let* _ : M.Val unit := + let* α0 : unit := M.call program_arguments_parsing.help in + M.alloc α0 in + M.alloc tt) : + M (M.Val unit) + ] in M.read α0). diff --git a/CoqOfRust/examples/default/examples/std_misc/threads.v b/CoqOfRust/examples/default/examples/std_misc/threads.v index d664620e3..c443f3299 100644 --- a/CoqOfRust/examples/default/examples/std_misc/threads.v +++ b/CoqOfRust/examples/default/examples/std_misc/threads.v @@ -44,74 +44,104 @@ Definition main : M unit := core.ops.range.Range.start := Integer.of_Z 0; core.ops.range.Range.end_ := α0; |}) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t u32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t u32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some i => - let* i := M.alloc i in - let* _ : M.Val unit := - let* α0 : std.thread.JoinHandle.t unit := + let* α2 : M.Val (core.ops.range.Range.t u32.t) := M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t u32.t := M.call - (std.thread.spawn - ((let* _ : M.Val unit := + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t u32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t u32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* i := M.copy γ0 in let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "this is thread number ") in - let* α1 : ref str.t := M.read (mk_str " + let* α0 : std.thread.JoinHandle.t unit := + M.call + (std.thread.spawn + ((let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read + (mk_str "this is thread number ") in + let* α1 : ref str.t := + M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := - M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow i)) in + let* α6 : + M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val + (ref + (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : + ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] + α4 + α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + let* α0 : M.Val unit := M.alloc tt in + M.read α0) : + M unit)) in + let* α1 : unit := M.call - (core.fmt.rt.Argument.t::["new_display"] - (borrow i)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : - M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - let* α0 : M.Val unit := M.alloc tt in - M.read α0) : - M unit)) in - let* α1 : unit := - M.call - ((alloc.vec.Vec.t - (std.thread.JoinHandle.t unit) - alloc.alloc.Global.t)::["push"] - (borrow_mut children) - α0) in - M.alloc α1 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α2) in + ((alloc.vec.Vec.t + (std.thread.JoinHandle.t unit) + alloc.alloc.Global.t)::["push"] + (borrow_mut children) + α0) in + M.alloc α1 in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α3) in let* α0 : alloc.vec.Vec.t (std.thread.JoinHandle.t unit) alloc.alloc.Global.t := M.read children in @@ -125,37 +155,74 @@ Definition main : M unit := alloc.vec.Vec.t (std.thread.JoinHandle.t unit) alloc.alloc.Global.t) (Trait := ltac:(refine _))) α0) in - let* α2 : M.Val unit := - match α1 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (std.thread.JoinHandle.t unit) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - alloc.vec.into_iter.IntoIter.t - (std.thread.JoinHandle.t unit) - alloc.alloc.Global.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some child => - let* child := M.alloc child in - let* _ : - core.result.Result.t - unit - (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := - let* α0 : std.thread.JoinHandle.t unit := M.read child in - M.call ((std.thread.JoinHandle.t unit)::["join"] α0) in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α2). + let* α2 : + M.Val + (alloc.vec.into_iter.IntoIter.t + (std.thread.JoinHandle.t unit) + alloc.alloc.Global.t) := + M.alloc α1 in + let* α3 : M.Val unit := + match_operator + α2 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (std.thread.JoinHandle.t unit) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + alloc.vec.into_iter.IntoIter.t + (std.thread.JoinHandle.t unit) + alloc.alloc.Global.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val (core.option.Option.t (std.thread.JoinHandle.t unit)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* child := M.copy γ0 in + let* α0 : std.thread.JoinHandle.t unit := M.read child in + let* α1 : + core.result.Result.t + unit + (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := + M.call ((std.thread.JoinHandle.t unit)::["join"] α0) in + let* α2 : + M.Val + (core.result.Result.t + unit + (alloc.boxed.Box.t + dynamic + alloc.alloc.Global.t)) := + M.alloc α1 in + match_operator + α2 + [ fun γ => (M.alloc tt) : M (M.Val unit) ] + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α3). diff --git a/CoqOfRust/examples/default/examples/std_misc/threads_test_case_map_reduce.v b/CoqOfRust/examples/default/examples/std_misc/threads_test_case_map_reduce.v index ae354280f..441de57d1 100644 --- a/CoqOfRust/examples/default/examples/std_misc/threads_test_case_map_reduce.v +++ b/CoqOfRust/examples/default/examples/std_misc/threads_test_case_map_reduce.v @@ -138,149 +138,212 @@ Definition main : M unit := core.str.iter.SplitWhitespace.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val unit := - match α2 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (usize.t * (ref str.t)) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - core.iter.adapters.enumerate.Enumerate.t - core.str.iter.SplitWhitespace.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some (i, data_segment) => - let* i := M.alloc i in - let* data_segment := M.alloc data_segment in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "data segment ") in - let* α1 : ref str.t := M.read (mk_str " is "") in - let* α2 : ref str.t := M.read (mk_str "" -") in - let* α3 : M.Val (array (ref str.t)) := - M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow i)) in - let* α7 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] - (borrow data_segment)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α6; α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - let* _ : M.Val unit := - let* α0 : std.thread.JoinHandle.t u32.t := + let* α3 : + M.Val + (core.iter.adapters.enumerate.Enumerate.t + core.str.iter.SplitWhitespace.t) := + M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (usize.t * (ref str.t)) := M.call - (std.thread.spawn - ((let* result : M.Val u32.t := - let* α0 : ref str.t := M.read data_segment in - let* α1 : core.str.iter.Chars.t := - M.call (str.t::["chars"] α0) in - let* α2 : - core.iter.adapters.map.Map.t - core.str.iter.Chars.t - (char.t -> M u32.t) := - M.call - ((core.iter.traits.iterator.Iterator.map - (Self := core.str.iter.Chars.t) - (Trait := ltac:(refine _))) - α1 - (fun (c : char.t) => - (let* c := M.alloc c in - let* α0 : char.t := M.read c in - let* α1 : core.option.Option.t u32.t := - M.call - (char.t::["to_digit"] - α0 - (Integer.of_Z 10)) in - let* α2 : ref str.t := - M.read (mk_str "should be a digit") in + ((core.iter.traits.iterator.Iterator.next + (Self := + core.iter.adapters.enumerate.Enumerate.t + core.str.iter.SplitWhitespace.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : + M.Val (core.option.Option.t (usize.t * (ref str.t))) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* α0 := M.read γ0 in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ0 in + let γ1 := Tuple.Access.right γ0 in + let* i := M.copy γ0 in + let* data_segment := M.copy γ1 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "data segment ") in + let* α1 : ref str.t := M.read (mk_str " is "") in + let* α2 : ref str.t := M.read (mk_str "" +") in + let* α3 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2 ] in + let* α4 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow i)) in + let* α7 : core.fmt.rt.Argument.t := M.call - ((core.option.Option.t u32.t)::["expect"] - α1 - α2)) : - M u32.t)) in - let* α3 : u32.t := - M.call - ((core.iter.traits.iterator.Iterator.sum - (Self := - core.iter.adapters.map.Map.t - core.str.iter.Chars.t - (char.t -> M u32.t)) - (Trait := ltac:(refine _))) - α2) in - M.alloc α3 in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := - M.read (mk_str "processed segment ") in - let* α1 : ref str.t := M.read (mk_str ", result=") in - let* α2 : ref str.t := M.read (mk_str " + (core.fmt.rt.Argument.t::["new_display"] + (borrow data_segment)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] α5 α10) in + let* α12 : unit := + M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + let* _ : M.Val unit := + let* α0 : std.thread.JoinHandle.t u32.t := + M.call + (std.thread.spawn + ((let* result : M.Val u32.t := + let* α0 : ref str.t := + M.read data_segment in + let* α1 : core.str.iter.Chars.t := + M.call (str.t::["chars"] α0) in + let* α2 : + core.iter.adapters.map.Map.t + core.str.iter.Chars.t + (char.t -> M u32.t) := + M.call + ((core.iter.traits.iterator.Iterator.map + (Self := core.str.iter.Chars.t) + (Trait := ltac:(refine _))) + α1 + (fun (α0 : char.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* c := M.copy γ in + let* α0 : char.t := + M.read c in + let* α1 : + core.option.Option.t + u32.t := + M.call + (char.t::["to_digit"] + α0 + (Integer.of_Z 10)) in + let* α2 : ref str.t := + M.read + (mk_str + "should be a digit") in + M.call + ((core.option.Option.t + u32.t)::["expect"] + α1 + α2)) : + M u32.t + ]) : + M u32.t)) in + let* α3 : u32.t := + M.call + ((core.iter.traits.iterator.Iterator.sum + (Self := + core.iter.adapters.map.Map.t + core.str.iter.Chars.t + (char.t -> M u32.t)) + (Trait := ltac:(refine _))) + α2) in + M.alloc α3 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := + M.read (mk_str "processed segment ") in + let* α1 : ref str.t := + M.read (mk_str ", result=") in + let* α2 : ref str.t := + M.read (mk_str " ") in - let* α3 : M.Val (array (ref str.t)) := - M.alloc [ α0; α1; α2 ] in - let* α4 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α3) in - let* α5 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α4) in - let* α6 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] - (borrow i)) in - let* α7 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] - (borrow result)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α6; α7 ] in - let* α9 : - M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α5 α10) in - let* α12 : unit := M.call (std.io.stdio._print α11) in - M.alloc α12 in - M.alloc tt in - M.read result) : - M u32.t)) in - let* α1 : unit := - M.call - ((alloc.vec.Vec.t - (std.thread.JoinHandle.t u32.t) - alloc.alloc.Global.t)::["push"] - (borrow_mut children) - α0) in - M.alloc α1 in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α3) in + let* α3 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1; α2 ] in + let* α4 : + M.Val (ref (array (ref str.t))) := + M.alloc (borrow α3) in + let* α5 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α4) in + let* α6 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow i)) in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow result)) in + let* α8 : + M.Val + (array core.fmt.rt.Argument.t) := + M.alloc [ α6; α7 ] in + let* α9 : + M.Val + (ref + (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : + ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call + (core.fmt.Arguments.t::["new_v1"] + α5 + α10) in + let* α12 : unit := + M.call (std.io.stdio._print α11) in + M.alloc α12 in + M.alloc tt in + M.read result) : + M u32.t)) in + let* α1 : unit := + M.call + ((alloc.vec.Vec.t + (std.thread.JoinHandle.t u32.t) + alloc.alloc.Global.t)::["push"] + (borrow_mut children) + α0) in + M.alloc α1 in + M.alloc tt + end + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α4) in let* final_result : M.Val u32.t := let* α0 : alloc.vec.Vec.t (std.thread.JoinHandle.t u32.t) alloc.alloc.Global.t := @@ -311,21 +374,28 @@ Definition main : M unit := alloc.alloc.Global.t) (Trait := ltac:(refine _))) α1 - (fun (c : std.thread.JoinHandle.t u32.t) => - (let* c := M.alloc c in - let* α0 : std.thread.JoinHandle.t u32.t := M.read c in - let* α1 : - core.result.Result.t - u32.t - (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := - M.call ((std.thread.JoinHandle.t u32.t)::["join"] α0) in - M.call - ((core.result.Result.t - u32.t - (alloc.boxed.Box.t - dynamic - alloc.alloc.Global.t))::["unwrap"] - α1)) : + (fun (α0 : std.thread.JoinHandle.t u32.t) => + (let* α0 := M.alloc α0 in + match_operator + α0 + [ + fun γ => + (let* c := M.copy γ in + let* α0 : std.thread.JoinHandle.t u32.t := M.read c in + let* α1 : + core.result.Result.t + u32.t + (alloc.boxed.Box.t dynamic alloc.alloc.Global.t) := + M.call ((std.thread.JoinHandle.t u32.t)::["join"] α0) in + M.call + ((core.result.Result.t + u32.t + (alloc.boxed.Box.t + dynamic + alloc.alloc.Global.t))::["unwrap"] + α1)) : + M u32.t + ]) : M u32.t)) in let* α3 : u32.t := M.call diff --git a/CoqOfRust/examples/default/examples/subtle.v b/CoqOfRust/examples/default/examples/subtle.v index 28dda387c..2b3d5af30 100644 --- a/CoqOfRust/examples/default/examples/subtle.v +++ b/CoqOfRust/examples/default/examples/subtle.v @@ -32,9 +32,17 @@ Section Impl_core_clone_Clone_for_subtle_Choice_t. *) Definition clone (self : ref Self) : M subtle.Choice.t := let* self := M.alloc self in - let _ : unit := tt in - let* α0 : ref subtle.Choice.t := M.read self in - M.read (deref α0). + let* α0 : M.Val unit := M.alloc tt in + let* α1 : M.Val subtle.Choice.t := + match_operator + α0 + [ + fun γ => + (let* α0 : ref subtle.Choice.t := M.read self in + M.pure (deref α0)) : + M (M.Val subtle.Choice.t) + ] in + M.read α1. Global Instance AssociatedFunction_clone : Notations.DoubleColon Self "clone" := { @@ -606,51 +614,86 @@ Section Impl_subtle_ConstantTimeEq_for_slice_T. (core.slice.iter.Iter.t T)) (Trait := ltac:(refine _))) α4) in - let* α6 : M.Val unit := - match α5 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t ((ref T) * (ref T)) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - core.iter.adapters.zip.Zip.t - (core.slice.iter.Iter.t T) - (core.slice.iter.Iter.t T)) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some (ai, bi) => - let* ai := M.alloc ai in - let* bi := M.alloc bi in - let* _ : M.Val unit := - let β : M.Val u8.t := x in - let* α0 := M.read β in - let* α1 : ref T := M.read ai in - let* α2 : ref T := M.read bi in - let* α3 : subtle.Choice.t := + let* α6 : + M.Val + (core.iter.adapters.zip.Zip.t + (core.slice.iter.Iter.t T) + (core.slice.iter.Iter.t T)) := + M.alloc α5 in + let* α7 : M.Val unit := + match_operator + α6 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t ((ref T) * (ref T)) := M.call - ((subtle.ConstantTimeEq.ct_eq - (Self := T) + ((core.iter.traits.iterator.Iterator.next + (Self := + core.iter.adapters.zip.Zip.t + (core.slice.iter.Iter.t T) + (core.slice.iter.Iter.t T)) (Trait := ltac:(refine _))) - α1 - α2) in - let* α4 : M.Val subtle.Choice.t := M.alloc α3 in - let* α5 : u8.t := - M.call (subtle.Choice.t::["unwrap_u8"] (borrow α4)) in - assign β (BinOp.Pure.bit_and α0 α5) in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α6) in + (borrow_mut iter)) in + let* α1 : + M.Val (core.option.Option.t ((ref T) * (ref T))) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* α0 := M.read γ0 in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ0 in + let γ1 := Tuple.Access.right γ0 in + let* ai := M.copy γ0 in + let* bi := M.copy γ1 in + let* _ : M.Val unit := + let β : M.Val u8.t := x in + let* α0 := M.read β in + let* α1 : ref T := M.read ai in + let* α2 : ref T := M.read bi in + let* α3 : subtle.Choice.t := + M.call + ((subtle.ConstantTimeEq.ct_eq + (Self := T) + (Trait := ltac:(refine _))) + α1 + α2) in + let* α4 : M.Val subtle.Choice.t := M.alloc α3 in + let* α5 : u8.t := + M.call + (subtle.Choice.t::["unwrap_u8"] + (borrow α4)) in + assign β (BinOp.Pure.bit_and α0 α5) in + M.alloc tt + end + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α7) in let* α0 : u8.t := M.read x in let* α1 : subtle.Choice.t := M.call @@ -2853,52 +2896,67 @@ Section Impl_subtle_CtOption_t_T. M.call (subtle.Choice.t::["unwrap_u8"] (borrow self.["is_some"])) in let* α1 : M.Val u8.t := M.alloc α0 in let* α2 : M.Val u8.t := M.alloc (Integer.of_Z 1) in - match (borrow α1, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u8.t := M.read left_val in - let* α1 : u8.t := M.read (deref α0) in - let* α2 : ref u8.t := M.read right_val in - let* α3 : u8.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u8.t := M.read left_val in - let* α2 : ref u8.t := M.read right_val in - let* α3 : ref str.t := M.read (mk_str "") in - let* α4 : M.Val (array (ref str.t)) := M.alloc [ α3 ] in - let* α5 : M.Val (ref (array (ref str.t))) := M.alloc (borrow α4) in - let* α6 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α5) in - let* α7 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow msg)) in - let* α8 : M.Val (array core.fmt.rt.Argument.t) := M.alloc [ α7 ] in - let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α8) in - let* α10 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α9) in - let* α11 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α6 α10) in - let* α12 : never.t := - M.call - (core.panicking.assert_failed - α0 - α1 - α2 - (core.option.Option.Some α11)) in - M.alloc α12 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : M.Val ((ref u8.t) * (ref u8.t)) := + M.alloc (borrow α1, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u8.t := M.read left_val in + let* α1 : u8.t := M.read (deref α0) in + let* α2 : ref u8.t := M.read right_val in + let* α3 : u8.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u8.t := M.read left_val in + let* α2 : ref u8.t := M.read right_val in + let* α3 : ref str.t := M.read (mk_str "") in + let* α4 : M.Val (array (ref str.t)) := M.alloc [ α3 ] in + let* α5 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α4) in + let* α6 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α5) in + let* α7 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] (borrow msg)) in + let* α8 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α7 ] in + let* α9 : M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α8) in + let* α10 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α9) in + let* α11 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α6 α10) in + let* α12 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + (core.option.Option.Some α11)) in + M.alloc α12 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in M.read self.["value"]. Global Instance AssociatedFunction_expect : @@ -2920,38 +2978,50 @@ Section Impl_subtle_CtOption_t_T. M.call (subtle.Choice.t::["unwrap_u8"] (borrow self.["is_some"])) in let* α1 : M.Val u8.t := M.alloc α0 in let* α2 : M.Val u8.t := M.alloc (Integer.of_Z 1) in - match (borrow α1, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u8.t := M.read left_val in - let* α1 : u8.t := M.read (deref α0) in - let* α2 : ref u8.t := M.read right_val in - let* α3 : u8.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u8.t := M.read left_val in - let* α2 : ref u8.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed - α0 - α1 - α2 - core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : M.Val ((ref u8.t) * (ref u8.t)) := + M.alloc (borrow α1, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u8.t := M.read left_val in + let* α1 : u8.t := M.read (deref α0) in + let* α2 : ref u8.t := M.read right_val in + let* α3 : u8.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u8.t := M.read left_val in + let* α2 : ref u8.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in M.read self.["value"]. Global Instance AssociatedFunction_unwrap : @@ -3486,7 +3556,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u8_t. M.alloc α3 in let* pow : M.Val i32.t := M.alloc (Integer.of_Z 1) in let* _ : M.Val unit := - loop + M.loop (let* α0 : i32.t := M.read pow in let* α1 : M.Val bool.t := M.alloc (BinOp.Pure.lt α0 (Integer.of_Z 8)) in let* α2 : bool.t := M.read (use α1) in @@ -3507,7 +3577,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u8_t. M.alloc tt else let* _ : M.Val unit := - let* α0 : M.Val never.t := Break in + let* α0 : M.Val never.t := M.break in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in M.alloc α2 in @@ -3521,7 +3591,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u8_t. M.alloc (BinOp.Pure.bit_and α0 (UnOp.not α1)) in let* pow : M.Val i32.t := M.alloc (Integer.of_Z 1) in let* _ : M.Val unit := - loop + M.loop (let* α0 : i32.t := M.read pow in let* α1 : M.Val bool.t := M.alloc (BinOp.Pure.lt α0 (Integer.of_Z 8)) in let* α2 : bool.t := M.read (use α1) in @@ -3542,7 +3612,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u8_t. M.alloc tt else let* _ : M.Val unit := - let* α0 : M.Val never.t := Break in + let* α0 : M.Val never.t := M.break in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in M.alloc α2 in @@ -3635,7 +3705,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u16_t. M.alloc α3 in let* pow : M.Val i32.t := M.alloc (Integer.of_Z 1) in let* _ : M.Val unit := - loop + M.loop (let* α0 : i32.t := M.read pow in let* α1 : M.Val bool.t := M.alloc (BinOp.Pure.lt α0 (Integer.of_Z 16)) in @@ -3657,7 +3727,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u16_t. M.alloc tt else let* _ : M.Val unit := - let* α0 : M.Val never.t := Break in + let* α0 : M.Val never.t := M.break in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in M.alloc α2 in @@ -3671,7 +3741,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u16_t. M.alloc (BinOp.Pure.bit_and α0 (UnOp.not α1)) in let* pow : M.Val i32.t := M.alloc (Integer.of_Z 1) in let* _ : M.Val unit := - loop + M.loop (let* α0 : i32.t := M.read pow in let* α1 : M.Val bool.t := M.alloc (BinOp.Pure.lt α0 (Integer.of_Z 16)) in @@ -3693,7 +3763,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u16_t. M.alloc tt else let* _ : M.Val unit := - let* α0 : M.Val never.t := Break in + let* α0 : M.Val never.t := M.break in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in M.alloc α2 in @@ -3785,7 +3855,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u32_t. M.alloc α3 in let* pow : M.Val i32.t := M.alloc (Integer.of_Z 1) in let* _ : M.Val unit := - loop + M.loop (let* α0 : i32.t := M.read pow in let* α1 : M.Val bool.t := M.alloc (BinOp.Pure.lt α0 (Integer.of_Z 32)) in @@ -3807,7 +3877,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u32_t. M.alloc tt else let* _ : M.Val unit := - let* α0 : M.Val never.t := Break in + let* α0 : M.Val never.t := M.break in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in M.alloc α2 in @@ -3821,7 +3891,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u32_t. M.alloc (BinOp.Pure.bit_and α0 (UnOp.not α1)) in let* pow : M.Val i32.t := M.alloc (Integer.of_Z 1) in let* _ : M.Val unit := - loop + M.loop (let* α0 : i32.t := M.read pow in let* α1 : M.Val bool.t := M.alloc (BinOp.Pure.lt α0 (Integer.of_Z 32)) in @@ -3843,7 +3913,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u32_t. M.alloc tt else let* _ : M.Val unit := - let* α0 : M.Val never.t := Break in + let* α0 : M.Val never.t := M.break in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in M.alloc α2 in @@ -3935,7 +4005,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u64_t. M.alloc α3 in let* pow : M.Val i32.t := M.alloc (Integer.of_Z 1) in let* _ : M.Val unit := - loop + M.loop (let* α0 : i32.t := M.read pow in let* α1 : M.Val bool.t := M.alloc (BinOp.Pure.lt α0 (Integer.of_Z 64)) in @@ -3957,7 +4027,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u64_t. M.alloc tt else let* _ : M.Val unit := - let* α0 : M.Val never.t := Break in + let* α0 : M.Val never.t := M.break in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in M.alloc α2 in @@ -3971,7 +4041,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u64_t. M.alloc (BinOp.Pure.bit_and α0 (UnOp.not α1)) in let* pow : M.Val i32.t := M.alloc (Integer.of_Z 1) in let* _ : M.Val unit := - loop + M.loop (let* α0 : i32.t := M.read pow in let* α1 : M.Val bool.t := M.alloc (BinOp.Pure.lt α0 (Integer.of_Z 64)) in @@ -3993,7 +4063,7 @@ Section Impl_subtle_ConstantTimeGreater_for_u64_t. M.alloc tt else let* _ : M.Val unit := - let* α0 : M.Val never.t := Break in + let* α0 : M.Val never.t := M.break in let* α1 := M.read α0 in let* α2 : unit := never_to_any α1 in M.alloc α2 in diff --git a/CoqOfRust/examples/default/examples/testing/unit_testing.v b/CoqOfRust/examples/default/examples/testing/unit_testing.v index 86c861132..2af01571e 100644 --- a/CoqOfRust/examples/default/examples/testing/unit_testing.v +++ b/CoqOfRust/examples/default/examples/testing/unit_testing.v @@ -38,38 +38,50 @@ Module tests. M.call (unit_testing.add (Integer.of_Z 1) (Integer.of_Z 2)) in let* α1 : M.Val i32.t := M.alloc α0 in let* α2 : M.Val i32.t := M.alloc (Integer.of_Z 3) in - match (borrow α1, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref i32.t := M.read left_val in - let* α1 : i32.t := M.read (deref α0) in - let* α2 : ref i32.t := M.read right_val in - let* α3 : i32.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref i32.t := M.read left_val in - let* α2 : ref i32.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed - α0 - α1 - α2 - core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : M.Val ((ref i32.t) * (ref i32.t)) := + M.alloc (borrow α1, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref i32.t := M.read left_val in + let* α1 : i32.t := M.read (deref α0) in + let* α2 : ref i32.t := M.read right_val in + let* α3 : i32.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref i32.t := M.read left_val in + let* α2 : ref i32.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. @@ -86,38 +98,50 @@ Module tests. M.call (unit_testing.bad_add (Integer.of_Z 1) (Integer.of_Z 2)) in let* α1 : M.Val i32.t := M.alloc α0 in let* α2 : M.Val i32.t := M.alloc (Integer.of_Z 3) in - match (borrow α1, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref i32.t := M.read left_val in - let* α1 : i32.t := M.read (deref α0) in - let* α2 : ref i32.t := M.read right_val in - let* α3 : i32.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref i32.t := M.read left_val in - let* α2 : ref i32.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed - α0 - α1 - α2 - core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : M.Val ((ref i32.t) * (ref i32.t)) := + M.alloc (borrow α1, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref i32.t := M.read left_val in + let* α1 : i32.t := M.read (deref α0) in + let* α2 : ref i32.t := M.read right_val in + let* α3 : i32.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref i32.t := M.read left_val in + let* α2 : ref i32.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. End tests. @@ -133,34 +157,50 @@ Definition test_add : M unit := M.call (unit_testing.add (Integer.of_Z 1) (Integer.of_Z 2)) in let* α1 : M.Val i32.t := M.alloc α0 in let* α2 : M.Val i32.t := M.alloc (Integer.of_Z 3) in - match (borrow α1, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref i32.t := M.read left_val in - let* α1 : i32.t := M.read (deref α0) in - let* α2 : ref i32.t := M.read right_val in - let* α3 : i32.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref i32.t := M.read left_val in - let* α2 : ref i32.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : M.Val ((ref i32.t) * (ref i32.t)) := + M.alloc (borrow α1, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref i32.t := M.read left_val in + let* α1 : i32.t := M.read (deref α0) in + let* α2 : ref i32.t := M.read right_val in + let* α3 : i32.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref i32.t := M.read left_val in + let* α2 : ref i32.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. @@ -177,33 +217,49 @@ Definition test_bad_add : M unit := M.call (unit_testing.bad_add (Integer.of_Z 1) (Integer.of_Z 2)) in let* α1 : M.Val i32.t := M.alloc α0 in let* α2 : M.Val i32.t := M.alloc (Integer.of_Z 3) in - match (borrow α1, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref i32.t := M.read left_val in - let* α1 : i32.t := M.read (deref α0) in - let* α2 : ref i32.t := M.read right_val in - let* α3 : i32.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref i32.t := M.read left_val in - let* α2 : ref i32.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : M.Val ((ref i32.t) * (ref i32.t)) := + M.alloc (borrow α1, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref i32.t := M.read left_val in + let* α1 : i32.t := M.read (deref α0) in + let* α2 : ref i32.t := M.read right_val in + let* α3 : i32.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref i32.t := M.read left_val in + let* α2 : ref i32.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/traits/derive.v b/CoqOfRust/examples/default/examples/traits/derive.v index 2e1207786..fdbfef5ce 100644 --- a/CoqOfRust/examples/default/examples/traits/derive.v +++ b/CoqOfRust/examples/default/examples/traits/derive.v @@ -151,14 +151,27 @@ Section Impl_derive_Inches_t. *) Definition to_centimeters (self : ref Self) : M derive.Centimeters.t := let* self := M.alloc self in - let* 'derive.Inches.Build_t inches : ref derive.Inches.t := M.read self in - let* inches := M.alloc inches in - let* α0 : i32.t := M.read inches in - let* α1 : f64.t := cast α0 in - let* α2 : f64.t := M.read UnsupportedLiteral in - let* α3 : f64.t := BinOp.Panic.mul α1 α2 in let* α0 : M.Val derive.Centimeters.t := - M.alloc (derive.Centimeters.Build_t α3) in + match_operator + self + [ + fun γ => + (let* γ := + let* α0 := M.read γ in + M.pure (deref α0) in + let* α0 := M.read γ in + match α0 with + | derive.Inches.Build_t _ => + let γ0 := γ.["Inches.0"] in + let* inches := M.copy γ0 in + let* α0 : i32.t := M.read inches in + let* α1 : f64.t := cast α0 in + let* α2 : f64.t := M.read UnsupportedLiteral in + let* α3 : f64.t := BinOp.Panic.mul α1 α2 in + M.alloc (derive.Centimeters.Build_t α3) + end) : + M (M.Val derive.Centimeters.t) + ] in M.read α0. Global Instance AssociatedFunction_to_centimeters : diff --git a/CoqOfRust/examples/default/examples/traits/disambiguating_overlapping_traits.v b/CoqOfRust/examples/default/examples/traits/disambiguating_overlapping_traits.v index 08b5ecedc..20b2b752a 100644 --- a/CoqOfRust/examples/default/examples/traits/disambiguating_overlapping_traits.v +++ b/CoqOfRust/examples/default/examples/traits/disambiguating_overlapping_traits.v @@ -149,39 +149,55 @@ Definition main : M unit := (Trait := ltac:(refine _))) α0) in let* α2 : M.Val alloc.string.String.t := M.alloc α1 in - match (borrow α2, borrow username) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref alloc.string.String.t := M.read left_val in - let* α1 : ref alloc.string.String.t := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := alloc.string.String.t) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref alloc.string.String.t := M.read left_val in - let* α2 : ref alloc.string.String.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : + M.Val ((ref alloc.string.String.t) * (ref alloc.string.String.t)) := + M.alloc (borrow α2, borrow username) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref alloc.string.String.t := M.read left_val in + let* α1 : ref alloc.string.String.t := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := alloc.string.String.t) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref alloc.string.String.t := M.read left_val in + let* α2 : ref alloc.string.String.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* age : M.Val u8.t := let* α0 : u8.t := M.call @@ -192,33 +208,49 @@ Definition main : M unit := M.alloc α0 in let* _ : M.Val unit := let* α0 : M.Val u8.t := M.alloc (Integer.of_Z 28) in - match (borrow α0, borrow age) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u8.t := M.read left_val in - let* α1 : u8.t := M.read (deref α0) in - let* α2 : ref u8.t := M.read right_val in - let* α3 : u8.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u8.t := M.read left_val in - let* α2 : ref u8.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : M.Val ((ref u8.t) * (ref u8.t)) := + M.alloc (borrow α0, borrow age) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u8.t := M.read left_val in + let* α1 : u8.t := M.read (deref α0) in + let* α2 : ref u8.t := M.read right_val in + let* α3 : u8.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u8.t := M.read left_val in + let* α2 : ref u8.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/traits/impl_trait_as_return_type.v b/CoqOfRust/examples/default/examples/traits/impl_trait_as_return_type.v index 098903110..817e41aaf 100644 --- a/CoqOfRust/examples/default/examples/traits/impl_trait_as_return_type.v +++ b/CoqOfRust/examples/default/examples/traits/impl_trait_as_return_type.v @@ -154,39 +154,59 @@ Definition main : M unit := (Trait := ltac:(refine _))) (borrow_mut v3)) in let* α2 : M.Val (core.option.Option.t i32.t) := M.alloc α1 in - match (borrow α0, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref (core.option.Option.t i32.t) := M.read left_val in - let* α1 : ref (core.option.Option.t i32.t) := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := core.option.Option.t i32.t) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref (core.option.Option.t i32.t) := M.read left_val in - let* α2 : ref (core.option.Option.t i32.t) := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : + M.Val + ((ref (core.option.Option.t i32.t)) + * + (ref (core.option.Option.t i32.t))) := + M.alloc (borrow α0, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref (core.option.Option.t i32.t) := M.read left_val in + let* α1 : ref (core.option.Option.t i32.t) := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := core.option.Option.t i32.t) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref (core.option.Option.t i32.t) := M.read left_val in + let* α2 : ref (core.option.Option.t i32.t) := + M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : M.Val (core.option.Option.t i32.t) := M.alloc (core.option.Option.Some (Integer.of_Z 2)) in @@ -197,39 +217,59 @@ Definition main : M unit := (Trait := ltac:(refine _))) (borrow_mut v3)) in let* α2 : M.Val (core.option.Option.t i32.t) := M.alloc α1 in - match (borrow α0, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref (core.option.Option.t i32.t) := M.read left_val in - let* α1 : ref (core.option.Option.t i32.t) := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := core.option.Option.t i32.t) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref (core.option.Option.t i32.t) := M.read left_val in - let* α2 : ref (core.option.Option.t i32.t) := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : + M.Val + ((ref (core.option.Option.t i32.t)) + * + (ref (core.option.Option.t i32.t))) := + M.alloc (borrow α0, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref (core.option.Option.t i32.t) := M.read left_val in + let* α1 : ref (core.option.Option.t i32.t) := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := core.option.Option.t i32.t) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref (core.option.Option.t i32.t) := M.read left_val in + let* α2 : ref (core.option.Option.t i32.t) := + M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : M.Val (core.option.Option.t i32.t) := M.alloc (core.option.Option.Some (Integer.of_Z 3)) in @@ -240,39 +280,59 @@ Definition main : M unit := (Trait := ltac:(refine _))) (borrow_mut v3)) in let* α2 : M.Val (core.option.Option.t i32.t) := M.alloc α1 in - match (borrow α0, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref (core.option.Option.t i32.t) := M.read left_val in - let* α1 : ref (core.option.Option.t i32.t) := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := core.option.Option.t i32.t) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref (core.option.Option.t i32.t) := M.read left_val in - let* α2 : ref (core.option.Option.t i32.t) := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : + M.Val + ((ref (core.option.Option.t i32.t)) + * + (ref (core.option.Option.t i32.t))) := + M.alloc (borrow α0, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref (core.option.Option.t i32.t) := M.read left_val in + let* α1 : ref (core.option.Option.t i32.t) := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := core.option.Option.t i32.t) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref (core.option.Option.t i32.t) := M.read left_val in + let* α2 : ref (core.option.Option.t i32.t) := + M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : M.Val (core.option.Option.t i32.t) := M.alloc (core.option.Option.Some (Integer.of_Z 4)) in @@ -283,39 +343,59 @@ Definition main : M unit := (Trait := ltac:(refine _))) (borrow_mut v3)) in let* α2 : M.Val (core.option.Option.t i32.t) := M.alloc α1 in - match (borrow α0, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref (core.option.Option.t i32.t) := M.read left_val in - let* α1 : ref (core.option.Option.t i32.t) := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := core.option.Option.t i32.t) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref (core.option.Option.t i32.t) := M.read left_val in - let* α2 : ref (core.option.Option.t i32.t) := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : + M.Val + ((ref (core.option.Option.t i32.t)) + * + (ref (core.option.Option.t i32.t))) := + M.alloc (borrow α0, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref (core.option.Option.t i32.t) := M.read left_val in + let* α1 : ref (core.option.Option.t i32.t) := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := core.option.Option.t i32.t) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref (core.option.Option.t i32.t) := M.read left_val in + let* α2 : ref (core.option.Option.t i32.t) := + M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* α0 : M.Val (core.option.Option.t i32.t) := M.alloc (core.option.Option.Some (Integer.of_Z 5)) in @@ -326,39 +406,59 @@ Definition main : M unit := (Trait := ltac:(refine _))) (borrow_mut v3)) in let* α2 : M.Val (core.option.Option.t i32.t) := M.alloc α1 in - match (borrow α0, borrow α2) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref (core.option.Option.t i32.t) := M.read left_val in - let* α1 : ref (core.option.Option.t i32.t) := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := core.option.Option.t i32.t) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref (core.option.Option.t i32.t) := M.read left_val in - let* α2 : ref (core.option.Option.t i32.t) := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α3 : + M.Val + ((ref (core.option.Option.t i32.t)) + * + (ref (core.option.Option.t i32.t))) := + M.alloc (borrow α0, borrow α2) in + match_operator + α3 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref (core.option.Option.t i32.t) := M.read left_val in + let* α1 : ref (core.option.Option.t i32.t) := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := core.option.Option.t i32.t) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref (core.option.Option.t i32.t) := M.read left_val in + let* α2 : ref (core.option.Option.t i32.t) := + M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := M.read (mk_str "all done diff --git a/CoqOfRust/examples/default/examples/traits/iterators.v b/CoqOfRust/examples/default/examples/traits/iterators.v index fa0a474e9..0c3d70b21 100644 --- a/CoqOfRust/examples/default/examples/traits/iterators.v +++ b/CoqOfRust/examples/default/examples/traits/iterators.v @@ -366,55 +366,79 @@ Definition main : M unit := core.ops.range.Range.start := Integer.of_Z 0; core.ops.range.Range.end_ := Integer.of_Z 3; |}) in - let* α1 : M.Val unit := - match α0 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t i32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.ops.range.Range.t i32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some i => - let* i := M.alloc i in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "> ") in - let* α1 : ref str.t := M.read (mk_str " + let* α1 : M.Val (core.ops.range.Range.t i32.t) := M.alloc α0 in + let* α2 : M.Val unit := + match_operator + α1 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t i32.t := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.ops.range.Range.t i32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t i32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* i := M.copy γ0 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "> ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow i)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α1) in + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow i)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α2) in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := @@ -445,56 +469,81 @@ Definition main : M unit := (Self := core.iter.adapters.take.Take.t iterators.Fibonacci.t) (Trait := ltac:(refine _))) α1) in - let* α3 : M.Val unit := - match α2 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t u32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - core.iter.adapters.take.Take.t iterators.Fibonacci.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some i => - let* i := M.alloc i in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "> ") in - let* α1 : ref str.t := M.read (mk_str " + let* α3 : M.Val (core.iter.adapters.take.Take.t iterators.Fibonacci.t) := + M.alloc α2 in + let* α4 : M.Val unit := + match_operator + α3 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t u32.t := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + core.iter.adapters.take.Take.t iterators.Fibonacci.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t u32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* i := M.copy γ0 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "> ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow i)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α3) in + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow i)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α4) in let* _ : M.Val unit := let* _ : M.Val unit := let* α0 : ref str.t := @@ -538,57 +587,86 @@ Definition main : M unit := (core.iter.adapters.skip.Skip.t iterators.Fibonacci.t)) (Trait := ltac:(refine _))) α2) in - let* α4 : M.Val unit := - match α3 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t u32.t := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := - core.iter.adapters.take.Take.t - (core.iter.adapters.skip.Skip.t iterators.Fibonacci.t)) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some i => - let* i := M.alloc i in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "> ") in - let* α1 : ref str.t := M.read (mk_str " + let* α4 : + M.Val + (core.iter.adapters.take.Take.t + (core.iter.adapters.skip.Skip.t iterators.Fibonacci.t)) := + M.alloc α3 in + let* α5 : M.Val unit := + match_operator + α4 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t u32.t := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := + core.iter.adapters.take.Take.t + (core.iter.adapters.skip.Skip.t + iterators.Fibonacci.t)) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t u32.t) := M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* i := M.copy γ0 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "> ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call - (core.fmt.rt.Argument.t::["new_display"] (borrow i)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.pure (use α4) in + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow i)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := + M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.pure (use α5) in let* array : M.Val (array u32.t) := M.alloc [ Integer.of_Z 1; Integer.of_Z 3; Integer.of_Z 3; Integer.of_Z 7 ] in @@ -624,51 +702,76 @@ Definition main : M unit := (Self := core.slice.iter.Iter.t u32.t) (Trait := ltac:(refine _))) α2) in - let* α4 : M.Val unit := - match α3 with - | iter => - let* iter := M.alloc iter in - loop - (let* _ : M.Val unit := - let* α0 : core.option.Option.t (ref u32.t) := - M.call - ((core.iter.traits.iterator.Iterator.next - (Self := core.slice.iter.Iter.t u32.t) - (Trait := ltac:(refine _))) - (borrow_mut iter)) in - match α0 with - | core.option.Option.None => - let* α0 : M.Val never.t := Break in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - | core.option.Option.Some i => - let* i := M.alloc i in - let* _ : M.Val unit := - let* _ : M.Val unit := - let* α0 : ref str.t := M.read (mk_str "> ") in - let* α1 : ref str.t := M.read (mk_str " + let* α4 : M.Val (core.slice.iter.Iter.t u32.t) := M.alloc α3 in + let* α5 : M.Val unit := + match_operator + α4 + [ + fun γ => + (let* iter := M.copy γ in + M.loop + (let* _ : M.Val unit := + let* α0 : core.option.Option.t (ref u32.t) := + M.call + ((core.iter.traits.iterator.Iterator.next + (Self := core.slice.iter.Iter.t u32.t) + (Trait := ltac:(refine _))) + (borrow_mut iter)) in + let* α1 : M.Val (core.option.Option.t (ref u32.t)) := + M.alloc α0 in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.None => + let* α0 : M.Val never.t := M.break in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + | _ => M.break_match + end) : + M (M.Val unit); + fun γ => + (let* α0 := M.read γ in + match α0 with + | core.option.Option.Some _ => + let γ0 := γ.["Some.0"] in + let* i := M.copy γ0 in + let* _ : M.Val unit := + let* _ : M.Val unit := + let* α0 : ref str.t := M.read (mk_str "> ") in + let* α1 : ref str.t := M.read (mk_str " ") in - let* α2 : M.Val (array (ref str.t)) := M.alloc [ α0; α1 ] in - let* α3 : M.Val (ref (array (ref str.t))) := - M.alloc (borrow α2) in - let* α4 : ref (slice (ref str.t)) := - M.read (pointer_coercion "Unsize" α3) in - let* α5 : core.fmt.rt.Argument.t := - M.call (core.fmt.rt.Argument.t::["new_display"] (borrow i)) in - let* α6 : M.Val (array core.fmt.rt.Argument.t) := - M.alloc [ α5 ] in - let* α7 : M.Val (ref (array core.fmt.rt.Argument.t)) := - M.alloc (borrow α6) in - let* α8 : ref (slice core.fmt.rt.Argument.t) := - M.read (pointer_coercion "Unsize" α7) in - let* α9 : core.fmt.Arguments.t := - M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in - let* α10 : unit := M.call (std.io.stdio._print α9) in - M.alloc α10 in - M.alloc tt in - M.alloc tt - end in - M.alloc tt) - end in - M.read (use α4). + let* α2 : M.Val (array (ref str.t)) := + M.alloc [ α0; α1 ] in + let* α3 : M.Val (ref (array (ref str.t))) := + M.alloc (borrow α2) in + let* α4 : ref (slice (ref str.t)) := + M.read (pointer_coercion "Unsize" α3) in + let* α5 : core.fmt.rt.Argument.t := + M.call + (core.fmt.rt.Argument.t::["new_display"] + (borrow i)) in + let* α6 : M.Val (array core.fmt.rt.Argument.t) := + M.alloc [ α5 ] in + let* α7 : + M.Val (ref (array core.fmt.rt.Argument.t)) := + M.alloc (borrow α6) in + let* α8 : ref (slice core.fmt.rt.Argument.t) := + M.read (pointer_coercion "Unsize" α7) in + let* α9 : core.fmt.Arguments.t := + M.call (core.fmt.Arguments.t::["new_v1"] α4 α8) in + let* α10 : unit := M.call (std.io.stdio._print α9) in + M.alloc α10 in + M.alloc tt in + M.alloc tt + | _ => M.break_match + end) : + M (M.Val unit) + ] in + M.alloc tt)) : + M (M.Val unit) + ] in + M.read (use α5). diff --git a/CoqOfRust/examples/default/examples/unsafe_operations/calling_unsafe_functions.v b/CoqOfRust/examples/default/examples/unsafe_operations/calling_unsafe_functions.v index 6c100307b..b4380d9ab 100644 --- a/CoqOfRust/examples/default/examples/unsafe_operations/calling_unsafe_functions.v +++ b/CoqOfRust/examples/default/examples/unsafe_operations/calling_unsafe_functions.v @@ -52,38 +52,53 @@ Definition main : M unit := ((alloc.vec.Vec.t u32.t alloc.alloc.Global.t)::["as_slice"] (borrow some_vector)) in let* α1 : M.Val (ref (slice u32.t)) := M.alloc α0 in - match (borrow α1, borrow my_slice) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref (ref (slice u32.t)) := M.read left_val in - let* α1 : ref (ref (slice u32.t)) := M.read right_val in - let* α2 : bool.t := - M.call - ((core.cmp.PartialEq.eq - (Self := ref (slice u32.t)) - (Trait := ltac:(refine _))) - α0 - α1) in - let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in - let* α4 : bool.t := M.read (use α3) in - if α4 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref (ref (slice u32.t)) := M.read left_val in - let* α2 : ref (ref (slice u32.t)) := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α2 : M.Val ((ref (ref (slice u32.t))) * (ref (ref (slice u32.t)))) := + M.alloc (borrow α1, borrow my_slice) in + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref (ref (slice u32.t)) := M.read left_val in + let* α1 : ref (ref (slice u32.t)) := M.read right_val in + let* α2 : bool.t := + M.call + ((core.cmp.PartialEq.eq + (Self := ref (slice u32.t)) + (Trait := ltac:(refine _))) + α0 + α1) in + let* α3 : M.Val bool.t := M.alloc (UnOp.not α2) in + let* α4 : bool.t := M.read (use α3) in + if α4 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref (ref (slice u32.t)) := M.read left_val in + let* α2 : ref (ref (slice u32.t)) := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inlateout_case_implemented.v b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inlateout_case_implemented.v index b594d2c52..8fe8ac985 100644 --- a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inlateout_case_implemented.v +++ b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inlateout_case_implemented.v @@ -22,33 +22,49 @@ Definition main : M unit := M.alloc tt in let* _ : M.Val unit := let* α0 : M.Val u64.t := M.alloc (Integer.of_Z 8) in - match (borrow a, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u64.t := M.read left_val in - let* α1 : u64.t := M.read (deref α0) in - let* α2 : ref u64.t := M.read right_val in - let* α3 : u64.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u64.t := M.read left_val in - let* α2 : ref u64.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : M.Val ((ref u64.t) * (ref u64.t)) := + M.alloc (borrow a, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u64.t := M.read left_val in + let* α1 : u64.t := M.read (deref α0) in + let* α2 : ref u64.t := M.read right_val in + let* α3 : u64.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u64.t := M.read left_val in + let* α2 : ref u64.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inlateout_case_non_used.v b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inlateout_case_non_used.v index 0781cb379..2cabfee67 100644 --- a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inlateout_case_non_used.v +++ b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inlateout_case_non_used.v @@ -30,33 +30,49 @@ Definition main : M unit := M.alloc tt in let* _ : M.Val unit := let* α0 : M.Val u64.t := M.alloc (Integer.of_Z 12) in - match (borrow a, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u64.t := M.read left_val in - let* α1 : u64.t := M.read (deref α0) in - let* α2 : ref u64.t := M.read right_val in - let* α3 : u64.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u64.t := M.read left_val in - let* α2 : ref u64.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : M.Val ((ref u64.t) * (ref u64.t)) := + M.alloc (borrow a, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u64.t := M.read left_val in + let* α1 : u64.t := M.read (deref α0) in + let* α2 : ref u64.t := M.read right_val in + let* α3 : u64.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u64.t := M.read left_val in + let* α2 : ref u64.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inout.v b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inout.v index fe91c3fd2..4e04a1c4d 100644 --- a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inout.v +++ b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inout.v @@ -22,33 +22,49 @@ Definition main : M unit := M.alloc tt in let* _ : M.Val unit := let* α0 : M.Val u64.t := M.alloc (Integer.of_Z 8) in - match (borrow y, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u64.t := M.read left_val in - let* α1 : u64.t := M.read (deref α0) in - let* α2 : ref u64.t := M.read right_val in - let* α3 : u64.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u64.t := M.read left_val in - let* α2 : ref u64.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : M.Val ((ref u64.t) * (ref u64.t)) := + M.alloc (borrow y, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u64.t := M.read left_val in + let* α1 : u64.t := M.read (deref α0) in + let* α2 : ref u64.t := M.read right_val in + let* α3 : u64.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u64.t := M.read left_val in + let* α2 : ref u64.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs.v b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs.v index 125545c2c..ac95a298a 100644 --- a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs.v +++ b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs.v @@ -20,33 +20,49 @@ Definition main : M unit := M.alloc tt in let* _ : M.Val unit := let* α0 : M.Val u64.t := M.alloc (Integer.of_Z 5) in - match (borrow x, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u64.t := M.read left_val in - let* α1 : u64.t := M.read (deref α0) in - let* α2 : ref u64.t := M.read right_val in - let* α3 : u64.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u64.t := M.read left_val in - let* α2 : ref u64.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : M.Val ((ref u64.t) * (ref u64.t)) := + M.alloc (borrow x, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u64.t := M.read left_val in + let* α1 : u64.t := M.read (deref α0) in + let* α2 : ref u64.t := M.read right_val in + let* α3 : u64.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u64.t := M.read left_val in + let* α2 : ref u64.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs_another_example.v b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs_another_example.v index ba1c2e900..1cfe6535c 100644 --- a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs_another_example.v +++ b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs_another_example.v @@ -27,33 +27,49 @@ Definition main : M unit := M.alloc tt in let* _ : M.Val unit := let* α0 : M.Val u64.t := M.alloc (Integer.of_Z 8) in - match (borrow o, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u64.t := M.read left_val in - let* α1 : u64.t := M.read (deref α0) in - let* α2 : ref u64.t := M.read right_val in - let* α3 : u64.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u64.t := M.read left_val in - let* α2 : ref u64.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : M.Val ((ref u64.t) * (ref u64.t)) := + M.alloc (borrow o, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u64.t := M.read left_val in + let* α1 : u64.t := M.read (deref α0) in + let* α2 : ref u64.t := M.read right_val in + let* α3 : u64.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u64.t := M.read left_val in + let* α2 : ref u64.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs_another_example_without_mov.v b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs_another_example_without_mov.v index 0754c590b..7c68d2c82 100644 --- a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs_another_example_without_mov.v +++ b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_inputs_and_outputs_another_example_without_mov.v @@ -20,33 +20,49 @@ Definition main : M unit := M.alloc tt in let* _ : M.Val unit := let* α0 : M.Val u64.t := M.alloc (Integer.of_Z 8) in - match (borrow x, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u64.t := M.read left_val in - let* α1 : u64.t := M.read (deref α0) in - let* α2 : ref u64.t := M.read right_val in - let* α3 : u64.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u64.t := M.read left_val in - let* α2 : ref u64.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : M.Val ((ref u64.t) * (ref u64.t)) := + M.alloc (borrow x, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u64.t := M.read left_val in + let* α1 : u64.t := M.read (deref α0) in + let* α2 : ref u64.t := M.read right_val in + let* α3 : u64.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u64.t := M.read left_val in + let* α2 : ref u64.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_labels.v b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_labels.v index 5ad6af17a..838fbc317 100644 --- a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_labels.v +++ b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_labels.v @@ -30,33 +30,49 @@ Definition main : M unit := M.alloc tt in let* _ : M.Val unit := let* α0 : M.Val i32.t := M.alloc (Integer.of_Z 5) in - match (borrow a, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref i32.t := M.read left_val in - let* α1 : i32.t := M.read (deref α0) in - let* α2 : ref i32.t := M.read right_val in - let* α3 : i32.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref i32.t := M.read left_val in - let* α2 : ref i32.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : M.Val ((ref i32.t) * (ref i32.t)) := + M.alloc (borrow a, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref i32.t := M.read left_val in + let* α1 : i32.t := M.read (deref α0) in + let* α2 : ref i32.t := M.read right_val in + let* α3 : i32.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref i32.t := M.read left_val in + let* α2 : ref i32.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_options.v b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_options.v index 15ab89f02..3525c1511 100644 --- a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_options.v +++ b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_options.v @@ -26,33 +26,49 @@ Definition main : M unit := M.alloc tt in let* _ : M.Val unit := let* α0 : M.Val u64.t := M.alloc (Integer.of_Z 8) in - match (borrow a, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u64.t := M.read left_val in - let* α1 : u64.t := M.read (deref α0) in - let* α2 : ref u64.t := M.read right_val in - let* α3 : u64.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u64.t := M.read left_val in - let* α2 : ref u64.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : M.Val ((ref u64.t) * (ref u64.t)) := + M.alloc (borrow a, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u64.t := M.read left_val in + let* α1 : u64.t := M.read (deref α0) in + let* α2 : ref u64.t := M.read right_val in + let* α3 : u64.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u64.t := M.read left_val in + let* α2 : ref u64.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_register_template_modifiers.v b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_register_template_modifiers.v index 43e4e2ad9..99171a663 100644 --- a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_register_template_modifiers.v +++ b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_register_template_modifiers.v @@ -22,33 +22,49 @@ Definition main : M unit := M.alloc tt in let* _ : M.Val unit := let* α0 : M.Val u16.t := M.alloc (Integer.of_Z 43947) in - match (borrow x, borrow α0) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u16.t := M.read left_val in - let* α1 : u16.t := M.read (deref α0) in - let* α2 : ref u16.t := M.read right_val in - let* α3 : u16.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u16.t := M.read left_val in - let* α2 : ref u16.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α1 : M.Val ((ref u16.t) * (ref u16.t)) := + M.alloc (borrow x, borrow α0) in + match_operator + α1 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u16.t := M.read left_val in + let* α1 : u16.t := M.read (deref α0) in + let* α2 : ref u16.t := M.read right_val in + let* α3 : u16.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u16.t := M.read left_val in + let* α2 : ref u16.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_scratch_register.v b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_scratch_register.v index 0dce03188..e66f57706 100644 --- a/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_scratch_register.v +++ b/CoqOfRust/examples/default/examples/unsafe_operations/inline_assembly_scratch_register.v @@ -29,33 +29,49 @@ Definition main : M unit := let* _ : M.Val unit := let* α0 : u64.t := BinOp.Panic.mul (Integer.of_Z 4) (Integer.of_Z 6) in let* α1 : M.Val u64.t := M.alloc α0 in - match (borrow x, borrow α1) with - | (left_val, right_val) => - let* left_val := M.alloc left_val in - let* right_val := M.alloc right_val in - let* α0 : ref u64.t := M.read left_val in - let* α1 : u64.t := M.read (deref α0) in - let* α2 : ref u64.t := M.read right_val in - let* α3 : u64.t := M.read (deref α2) in - let* α4 : M.Val bool.t := M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in - let* α5 : bool.t := M.read (use α4) in - if α5 then - let* kind : M.Val core.panicking.AssertKind.t := - M.alloc core.panicking.AssertKind.Eq in - let* _ : M.Val never.t := - let* α0 : core.panicking.AssertKind.t := M.read kind in - let* α1 : ref u64.t := M.read left_val in - let* α2 : ref u64.t := M.read right_val in - let* α3 : never.t := - M.call - (core.panicking.assert_failed α0 α1 α2 core.option.Option.None) in - M.alloc α3 in - let* α0 : M.Val unit := M.alloc tt in - let* α1 := M.read α0 in - let* α2 : unit := never_to_any α1 in - M.alloc α2 - else - M.alloc tt - end in + let* α2 : M.Val ((ref u64.t) * (ref u64.t)) := + M.alloc (borrow x, borrow α1) in + match_operator + α2 + [ + fun γ => + (let* α0 := M.read γ in + match α0 with + | (_, _) => + let γ0 := Tuple.Access.left γ in + let γ1 := Tuple.Access.right γ in + let* left_val := M.copy γ0 in + let* right_val := M.copy γ1 in + let* α0 : ref u64.t := M.read left_val in + let* α1 : u64.t := M.read (deref α0) in + let* α2 : ref u64.t := M.read right_val in + let* α3 : u64.t := M.read (deref α2) in + let* α4 : M.Val bool.t := + M.alloc (UnOp.not (BinOp.Pure.eq α1 α3)) in + let* α5 : bool.t := M.read (use α4) in + if α5 then + let* kind : M.Val core.panicking.AssertKind.t := + M.alloc core.panicking.AssertKind.Eq in + let* _ : M.Val never.t := + let* α0 : core.panicking.AssertKind.t := M.read kind in + let* α1 : ref u64.t := M.read left_val in + let* α2 : ref u64.t := M.read right_val in + let* α3 : never.t := + M.call + (core.panicking.assert_failed + α0 + α1 + α2 + core.option.Option.None) in + M.alloc α3 in + let* α0 : M.Val unit := M.alloc tt in + let* α1 := M.read α0 in + let* α2 : unit := never_to_any α1 in + M.alloc α2 + else + M.alloc tt + end) : + M (M.Val unit) + ] in let* α0 : M.Val unit := M.alloc tt in M.read α0. diff --git a/CoqOfRust/lib/lib.v b/CoqOfRust/lib/lib.v index 99ded15e6..8885cfeb9 100644 --- a/CoqOfRust/lib/lib.v +++ b/CoqOfRust/lib/lib.v @@ -514,3 +514,19 @@ Fixpoint repeat_nat {A : Set} (times : nat) (v : A) : list A := (** The repeat operator to create new arrays, like in `[0; 32]`. *) Definition repeat {A : Set} (v : A) (times : Z) : list A := repeat_nat (Z.to_nat times) v. + +Module Tuple. + Module Access. + Definition left {A1 A0 : Set} := + Ref.map + (Big := A1 * A0) + (fun '(x1, _) => Some x1) + (fun β '(_, x0) => Some (β, x0)). + + Definition right {A1 A0 : Set} := + Ref.map + (Big := A1 * A0) + (fun '(_, x0) => Some x0) + (fun β '(x1, _) => Some (x1, β)). + End Access. +End Tuple. diff --git a/lib/src/coq.rs b/lib/src/coq.rs index 5a31c3154..b2c2bab2c 100644 --- a/lib/src/coq.rs +++ b/lib/src/coq.rs @@ -3,6 +3,7 @@ use crate::render::{ self, concat, curly_brackets, group, hardline, intersperse, line, nest, nil, optional_insert, optional_insert_vec, optional_insert_with, paren, text, Doc, }; +use std::rc::Rc; #[derive(Clone)] /// a list of coq top level items @@ -129,7 +130,7 @@ pub(crate) enum Expression<'a> { /// an (curried) application of a function to some arguments Application { /// the function that is applied - func: Box>, + func: Rc>, /// a nonempty list of arguments /// (we accept many arguments to control their indentation better, /// the application is curried when it gets printed) @@ -138,10 +139,10 @@ pub(crate) enum Expression<'a> { /// a (curried) function Function { parameters: Vec>, - body: Box>, + body: Rc>, }, Match { - scrutinee: Box>, + scrutinee: Rc>, arms: Vec<(Expression<'a>, Expression<'a>)>, }, /// a (curried) function type @@ -151,7 +152,7 @@ pub(crate) enum Expression<'a> { /// the type is curried when it gets printed) domains: Vec>, /// the image (range, co-domain) of functions of the type - image: Box>, + image: Rc>, }, /// a dependent product of types /// (like `forall (x : A), B(x)`) @@ -159,35 +160,35 @@ pub(crate) enum Expression<'a> { /// a list of arguments of `forall` args: Vec>, /// the expression for the resulting type - image: Box>, + image: Rc>, }, /// a product of two variables (they can be types or numbers) Product { /// left hand side - lhs: Box>, + lhs: Rc>, /// right hand side - rhs: Box>, + rhs: Rc>, }, Record { fields: Vec>, }, RecordField { - record: Box>, + record: Rc>, field: String, }, RecordUpdate { - record: Box>, + record: Rc>, field: String, - update: Box>, + update: Rc>, }, NotationsDot { - value: Box>, + value: Rc>, field: String, }, /// For example ltac:(...) or constr:(...) ModeWrapper { mode: String, - expr: Box>, + expr: Rc>, }, /// Set constant (the type of our types) Set, @@ -197,7 +198,7 @@ pub(crate) enum Expression<'a> { /// a list of arguments of `Sigma` args: Vec>, /// the expression for the resulting type - image: Box>, + image: Rc>, }, /// a string String(String), @@ -963,7 +964,7 @@ impl<'a> Expression<'a> { /// apply the expression as a function to one argument pub(crate) fn apply_arg(&self, name: &Option, arg: &Self) -> Self { Expression::Application { - func: Box::new(self.clone()), + func: Rc::new(self.clone()), args: vec![(name.clone(), arg.clone())], } } @@ -980,7 +981,7 @@ impl<'a> Expression<'a> { } Expression::Application { - func: Box::new(self.to_owned()), + func: Rc::new(self.to_owned()), args: args.to_vec(), } } @@ -998,14 +999,14 @@ impl<'a> Expression<'a> { pub(crate) fn arrows_from(&self, domains: &[Self]) -> Self { Expression::FunctionType { domains: domains.to_owned(), - image: Box::new(self.to_owned()), + image: Rc::new(self.to_owned()), } } pub(crate) fn multiply(lhs: Self, rhs: Self) -> Self { Expression::Product { - lhs: Box::new(lhs), - rhs: Box::new(rhs), + lhs: Rc::new(lhs), + rhs: Rc::new(rhs), } } diff --git a/lib/src/expression.rs b/lib/src/expression.rs index 7d3396b63..36030a34d 100644 --- a/lib/src/expression.rs +++ b/lib/src/expression.rs @@ -1,11 +1,10 @@ -use core::panic; -use std::rc::Rc; - use crate::env::*; use crate::path::*; use crate::pattern::*; use crate::render::*; use crate::ty::*; +use core::panic; +use std::rc::Rc; /// Struct [FreshVars] represents a set of fresh variables #[derive(Debug)] @@ -23,10 +22,10 @@ impl FreshVars { /// Struct [MatchArm] represents a pattern-matching branch: [pat] is the /// matched pattern and [body] the expression on which it is mapped -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Debug, Eq, Hash, PartialEq)] pub(crate) struct MatchArm { - pub(crate) pattern: Pattern, - pub(crate) body: Expr, + pub(crate) pattern: Rc, + pub(crate) body: Rc, } /// [LoopControlFlow] represents the expressions responsible for @@ -43,7 +42,7 @@ pub(crate) enum Purity { Effectful, } -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Debug, Eq, Hash, PartialEq)] pub(crate) enum Literal { Bool(bool), Integer { value: u128, neg: bool }, @@ -52,16 +51,16 @@ pub(crate) enum Literal { Error, } -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Debug, Eq, Hash, PartialEq)] pub(crate) struct Expr { - pub(crate) kind: ExprKind, + pub(crate) kind: Rc, pub(crate) ty: Option>, } /// Enum [ExprKind] represents the AST of rust terms. -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Debug, Eq, Hash, PartialEq)] pub(crate) enum ExprKind { - Pure(Box), + Pure(Rc), LocalVar(String), Var(Path), Constructor(Path), @@ -81,8 +80,8 @@ pub(crate) enum ExprKind { Literal(Literal), NonHirLiteral(rustc_middle::ty::ScalarInt), Call { - func: Box, - args: Vec, + func: Rc, + args: Vec>, purity: Purity, from_user: bool, }, @@ -90,93 +89,101 @@ pub(crate) enum ExprKind { /// form once the monadic translation is done. MonadicOperator { name: String, - arg: Box, + arg: Rc, }, Lambda { - args: Vec<(Pattern, Rc)>, - body: Box, + args: Vec<(String, Option>)>, + body: Rc, + is_for_match: bool, }, Array { - elements: Vec, + elements: Vec>, }, Tuple { - elements: Vec, + elements: Vec>, }, Let { is_monadic: bool, - pattern: Box, - init: Box, - body: Box, + name: Option, + init: Rc, + body: Rc, }, LetIf { - pat: Box, - init: Box, + pat: Rc, + init: Rc, }, If { - condition: Box, - success: Box, - failure: Box, + condition: Rc, + success: Rc, + failure: Rc, }, Loop { - body: Box, + body: Rc, }, Match { - scrutinee: Box, - arms: Vec, + scrutinee: Rc, + arms: Vec>, }, #[allow(dead_code)] IndexedField { - base: Box, + base: Rc, index: u32, }, NamedField { - base: Box, + base: Rc, name: String, }, Index { - base: Box, - index: Box, + base: Rc, + index: Rc, }, ControlFlow(LoopControlFlow), StructStruct { path: Path, - fields: Vec<(String, Expr)>, - base: Option>, + fields: Vec<(String, Rc)>, + base: Option>, struct_or_variant: StructOrVariant, }, StructTuple { path: Path, - fields: Vec, + fields: Vec>, struct_or_variant: StructOrVariant, }, StructUnit { path: Path, struct_or_variant: StructOrVariant, }, - Use(Box), - Return(Box), + Use(Rc), + Return(Rc), /// Useful for error messages or annotations Message(String), } impl ExprKind { - pub(crate) fn tt() -> Self { - ExprKind::LocalVar("tt".to_string()).alloc(Some(CoqType::unit())) + pub(crate) fn tt() -> Rc { + Rc::new(ExprKind::LocalVar("tt".to_string())).alloc(Some(CoqType::unit())) } } impl Expr { /// The Coq value [tt] (the inhabitant of the [unit] type) is used as default /// value - pub(crate) fn tt() -> Self { - Expr { + pub(crate) fn tt() -> Rc { + Rc::new(Expr { kind: ExprKind::tt(), ty: Some(CoqType::unit().val()), - } + }) + } + + pub(crate) fn local_var(name: &str) -> Rc { + Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar(name.to_string())), + ty: None, + }) } pub(crate) fn has_return(&self) -> bool { - match &self.kind { + match self.kind.as_ref() { ExprKind::Pure(expr) => expr.has_return(), ExprKind::LocalVar(_) => false, ExprKind::Var(_) => false, @@ -198,14 +205,18 @@ impl Expr { args, purity: _, from_user: _, - } => func.has_return() || args.iter().any(Self::has_return), + } => func.has_return() || args.iter().any(|arg| arg.has_return()), ExprKind::MonadicOperator { name: _, arg } => arg.has_return(), - ExprKind::Lambda { .. } => false, - ExprKind::Array { elements } => elements.iter().any(Self::has_return), - ExprKind::Tuple { elements } => elements.iter().any(Self::has_return), + ExprKind::Lambda { + args: _, + body, + is_for_match, + } => *is_for_match && body.has_return(), + ExprKind::Array { elements } => elements.iter().any(|element| element.has_return()), + ExprKind::Tuple { elements } => elements.iter().any(|element| element.has_return()), ExprKind::Let { is_monadic: _, - pattern: _, + name: _, init, body, } => init.has_return() || body.has_return(), @@ -217,10 +228,7 @@ impl Expr { } => condition.has_return() || success.has_return() || failure.has_return(), ExprKind::Loop { body } => body.has_return(), ExprKind::Match { scrutinee, arms } => { - scrutinee.has_return() - || arms - .iter() - .any(|MatchArm { pattern: _, body }| body.has_return()) + scrutinee.has_return() || arms.iter().any(|arm| arm.body.has_return()) } ExprKind::IndexedField { base, index: _ } => base.has_return(), ExprKind::NamedField { base, name: _ } => base.has_return(), @@ -239,7 +247,7 @@ impl Expr { path: _, fields, struct_or_variant: _, - } => fields.iter().any(Self::has_return), + } => fields.iter().any(|field| field.has_return()), ExprKind::StructUnit { path: _, struct_or_variant: _, @@ -251,39 +259,39 @@ impl Expr { } } -fn pure(e: Expr) -> Expr { - Expr { +fn pure(e: Rc) -> Rc { + Rc::new(Expr { ty: e.ty.clone(), - kind: ExprKind::Pure(Box::new(e)), - } + kind: Rc::new(ExprKind::Pure(e)), + }) } /// creates a monadic let statement with [e1] as the initializer /// and the result of [f] as the body fn monadic_let_in_stmt( fresh_vars: FreshVars, - e1: Expr, - f: impl FnOnce(FreshVars, Expr) -> (Expr, FreshVars), -) -> (Expr, FreshVars) { - match e1.kind { - ExprKind::Pure(e) => f(fresh_vars, *e), + e1: Rc, + f: impl FnOnce(FreshVars, Rc) -> (Rc, FreshVars), +) -> (Rc, FreshVars) { + match e1.kind.as_ref() { + ExprKind::Pure(e) => f(fresh_vars, e.clone()), ExprKind::Let { is_monadic, - pattern, + name, init, body, } => { - let (body, fresh_vars) = monadic_let_in_stmt(fresh_vars, *body, f); + let (body, fresh_vars) = monadic_let_in_stmt(fresh_vars, body.clone(), f); ( - Expr { + Rc::new(Expr { ty: body.ty.clone(), - kind: ExprKind::Let { - is_monadic, - pattern, - init, - body: Box::new(body), - }, - }, + kind: Rc::new(ExprKind::Let { + is_monadic: *is_monadic, + name: name.clone(), + init: init.clone(), + body, + }), + }), fresh_vars, ) } @@ -291,21 +299,21 @@ fn monadic_let_in_stmt( let (var_name, fresh_vars) = fresh_vars.next(); let (body, fresh_vars) = f( fresh_vars, - Expr { - kind: ExprKind::LocalVar(var_name.clone()), + Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar(var_name.clone())), ty: None, - }, + }), ); ( - Expr { + Rc::new(Expr { ty: body.ty.clone(), - kind: ExprKind::Let { + kind: Rc::new(ExprKind::Let { is_monadic: true, - pattern: Box::new(Pattern::Variable(var_name)), - init: Box::new(e1), - body: Box::new(body), - }, - }, + name: Some(var_name), + init: e1, + body, + }), + }), fresh_vars, ) } @@ -314,31 +322,27 @@ fn monadic_let_in_stmt( fn monadic_let( fresh_vars: FreshVars, - e1: Expr, - f: impl FnOnce(FreshVars, Expr) -> (Expr, FreshVars), -) -> (Expr, FreshVars) { + e1: Rc, + f: impl FnOnce(FreshVars, Rc) -> (Rc, FreshVars), +) -> (Rc, FreshVars) { let (e1, fresh_vars) = mt_expression(fresh_vars, e1); monadic_let_in_stmt(fresh_vars, e1, f) } fn monadic_optional_let( fresh_vars: FreshVars, - e1: Option>, - f: impl FnOnce(FreshVars, Option>) -> (Expr, FreshVars), -) -> (Expr, FreshVars) { + e1: Option>, + f: impl FnOnce(FreshVars, Option>) -> (Rc, FreshVars), +) -> (Rc, FreshVars) { match e1 { None => f(fresh_vars, None), - Some(e1) => monadic_let(fresh_vars, *e1, |fresh_vars, e1| { - f(fresh_vars, Some(Box::new(e1))) - }), + Some(e1) => monadic_let(fresh_vars, e1, |fresh_vars, e1| f(fresh_vars, Some(e1))), } } -fn monadic_lets( - fresh_vars: FreshVars, - es: Vec, - f: Box) -> (Expr, FreshVars)>, -) -> (Expr, FreshVars) { +type DynLetFn = Box>) -> (Rc, FreshVars)>; + +fn monadic_lets(fresh_vars: FreshVars, es: Vec>, f: DynLetFn) -> (Rc, FreshVars) { match &es[..] { [] => f(fresh_vars, vec![]), [e1, es @ ..] => monadic_let(fresh_vars, e1.clone(), |fresh_vars, e1| { @@ -359,274 +363,287 @@ fn monadic_lets( /// may lead to infinite loops because of the mutual recursion between /// the functions. In practice this means translating every subexpression /// before translating the expression itself. -pub(crate) fn mt_expression(fresh_vars: FreshVars, expr: Expr) -> (Expr, FreshVars) { +pub(crate) fn mt_expression(fresh_vars: FreshVars, expr: Rc) -> (Rc, FreshVars) { let ty = expr.ty.clone().map(mt_ty); - match expr.kind { + + match expr.kind.as_ref() { ExprKind::Pure(_) => panic!("Expressions should not be monadic yet."), - ExprKind::LocalVar(_) => (pure(expr), fresh_vars), - ExprKind::Var(_) => (pure(expr), fresh_vars), - ExprKind::Constructor(_) => (pure(expr), fresh_vars), + ExprKind::LocalVar(_) => (pure(expr.clone()), fresh_vars), + ExprKind::Var(_) => (pure(expr.clone()), fresh_vars), + ExprKind::Constructor(_) => (pure(expr.clone()), fresh_vars), ExprKind::VarWithTy { path, ty_name, ty: var_ty, } => ( - pure(Expr { - kind: ExprKind::VarWithTy { - path, - ty_name, - ty: mt_ty(var_ty), - }, + pure(Rc::new(Expr { + kind: Rc::new(ExprKind::VarWithTy { + path: path.clone(), + ty_name: ty_name.clone(), + ty: mt_ty(var_ty.clone()), + }), ty, - }), + })), fresh_vars, ), ExprKind::VarWithSelfTy { path, self_ty } => ( - pure(Expr { - kind: ExprKind::VarWithSelfTy { - path, - self_ty: mt_ty(self_ty), - }, + pure(Rc::new(Expr { + kind: Rc::new(ExprKind::VarWithSelfTy { + path: path.clone(), + self_ty: mt_ty(self_ty.clone()), + }), ty, - }), + })), fresh_vars, ), - ExprKind::AssociatedFunction { .. } => (pure(expr), fresh_vars), - ExprKind::Literal { .. } => (pure(expr), fresh_vars), - ExprKind::NonHirLiteral { .. } => (pure(expr), fresh_vars), + ExprKind::AssociatedFunction { .. } => (pure(expr.clone()), fresh_vars), + ExprKind::Literal { .. } => (pure(expr.clone()), fresh_vars), + ExprKind::NonHirLiteral { .. } => (pure(expr.clone()), fresh_vars), ExprKind::Call { func, args, purity, from_user, - } => monadic_let(fresh_vars, *func, |fresh_vars, func| { - monadic_lets( - fresh_vars, - args, - Box::new(move |fresh_vars, args| { - ( - { - let expr = Expr { - kind: ExprKind::Call { - func: Box::new(func), - args, - purity, - from_user, - }, - ty, - }; - match purity { - Purity::Pure => pure(expr), - Purity::Effectful => expr, - } - }, - fresh_vars, - ) - }), - ) - }), + } => { + let purity = *purity; + let from_user = *from_user; + + monadic_let(fresh_vars, func.clone(), |fresh_vars, func| { + monadic_lets( + fresh_vars, + args.clone(), + Box::new(move |fresh_vars, args| { + ( + { + let call = Rc::new(Expr { + kind: Rc::new(ExprKind::Call { + func: func.clone(), + args, + purity, + from_user, + }), + ty, + }); + + match purity { + Purity::Pure => pure(call), + Purity::Effectful => call, + } + }, + fresh_vars, + ) + }), + ) + }) + } ExprKind::MonadicOperator { name, arg } => { - let (arg, fresh_vars) = mt_expression(fresh_vars, *arg); + let (arg, fresh_vars) = mt_expression(fresh_vars, arg.clone()); ( - Expr { - kind: ExprKind::MonadicOperator { - name, - arg: Box::new(arg), - }, + Rc::new(Expr { + kind: Rc::new(ExprKind::MonadicOperator { + name: name.clone(), + arg, + }), ty, - }, + }), fresh_vars, ) } - ExprKind::Lambda { args, body } => { - let (body, _) = mt_expression(FreshVars::new(), *body); + ExprKind::Lambda { + args, + body, + is_for_match, + } => { + let (body, _) = mt_expression(FreshVars::new(), body.clone()); ( - pure(Expr { - kind: ExprKind::Lambda { - args, - body: Box::new(body), - }, + pure(Rc::new(Expr { + kind: Rc::new(ExprKind::Lambda { + args: args.clone(), + body, + is_for_match: *is_for_match, + }), ty, - }), + })), fresh_vars, ) } ExprKind::Array { elements } => monadic_lets( fresh_vars, - elements, + elements.clone(), Box::new(|fresh_vars, elements| { ( - pure(Expr { - kind: ExprKind::Array { elements }, + pure(Rc::new(Expr { + kind: Rc::new(ExprKind::Array { elements }), ty, - }), + })), fresh_vars, ) }), ), ExprKind::Tuple { elements } => monadic_lets( fresh_vars, - elements, + elements.clone(), Box::new(|fresh_vars, elements| { ( - pure(Expr { - kind: ExprKind::Tuple { elements }, + pure(Rc::new(Expr { + kind: Rc::new(ExprKind::Tuple { elements }), ty, - }), + })), fresh_vars, ) }), ), ExprKind::Let { is_monadic, - pattern, + name, init, body, } => { - if is_monadic { + if *is_monadic { panic!("The let statement should not be monadic yet.") } - let (init, _fresh_vars) = mt_expression(FreshVars::new(), *init); - let (body, _fresh_vars) = mt_expression(FreshVars::new(), *body); - let body = Box::new(body); - let pure_init: Option> = get_pure_from_stmt(init.clone()); + let (init, _fresh_vars) = mt_expression(FreshVars::new(), init.clone()); + let (body, _fresh_vars) = mt_expression(FreshVars::new(), body.clone()); + let pure_init: Option> = get_pure_from_stmt(init.clone()); ( match pure_init { - Some(pure_init) => Expr { - kind: ExprKind::Let { + Some(pure_init) => Rc::new(Expr { + kind: Rc::new(ExprKind::Let { is_monadic: false, - pattern, + name: name.clone(), init: pure_init, body, - }, + }), ty, - }, - None => Expr { - kind: ExprKind::Let { + }), + None => Rc::new(Expr { + kind: Rc::new(ExprKind::Let { is_monadic: true, - pattern, - init: Box::new(init), + name: name.clone(), + init, body, - }, + }), ty, - }, + }), }, fresh_vars, ) } - ExprKind::LetIf { pat, init } => monadic_let(fresh_vars, *init, |fresh_vars, init| { - ( - Expr { - kind: ExprKind::LetIf { - pat, - init: Box::new(init), - }, - ty: ty.clone(), - }, - fresh_vars, - ) - }), + ExprKind::LetIf { pat, init } => { + monadic_let(fresh_vars, init.clone(), |fresh_vars, init| { + ( + Rc::new(Expr { + kind: Rc::new(ExprKind::LetIf { + pat: pat.clone(), + init, + }), + ty: ty.clone(), + }), + fresh_vars, + ) + }) + } ExprKind::If { condition, success, failure, - } => monadic_let(fresh_vars, *condition, |fresh_vars, condition| { - let (success, _fresh_vars) = mt_expression(FreshVars::new(), *success); - let (failure, _fresh_vars) = mt_expression(FreshVars::new(), *failure); + } => monadic_let(fresh_vars, condition.clone(), |fresh_vars, condition| { + let (success, _fresh_vars) = mt_expression(FreshVars::new(), success.clone()); + let (failure, _fresh_vars) = mt_expression(FreshVars::new(), failure.clone()); ( - Expr { - kind: ExprKind::If { - condition: Box::new(condition), - success: Box::new(success), - failure: Box::new(failure), - }, + Rc::new(Expr { + kind: Rc::new(ExprKind::If { + condition, + success, + failure, + }), ty: ty.clone(), - }, + }), fresh_vars, ) }), ExprKind::Loop { body, .. } => { - let (body, fresh_vars) = mt_expression(fresh_vars, *body); + let (body, fresh_vars) = mt_expression(fresh_vars, body.clone()); ( - Expr { - kind: ExprKind::Loop { - body: Box::new(body), - }, + Rc::new(Expr { + kind: Rc::new(ExprKind::Loop { body }), ty, - }, + }), fresh_vars, ) } ExprKind::Match { scrutinee, arms } => { - monadic_let(fresh_vars, *scrutinee, |fresh_vars, scrutinee| { + monadic_let(fresh_vars, scrutinee.clone(), |fresh_vars, scrutinee| { ( - Expr { - kind: ExprKind::Match { - scrutinee: Box::new(scrutinee), + Rc::new(Expr { + kind: Rc::new(ExprKind::Match { + scrutinee, arms: arms .iter() - .map(|MatchArm { pattern, body }| { + .map(|arm| { let (body, _fresh_vars) = - mt_expression(FreshVars::new(), body.clone()); - MatchArm { - pattern: pattern.clone(), + mt_expression(FreshVars::new(), arm.body.clone()); + Rc::new(MatchArm { + pattern: arm.pattern.clone(), body, - } + }) }) .collect(), - }, + }), ty: ty.clone(), - }, + }), fresh_vars, ) }) } ExprKind::IndexedField { base, index } => { - monadic_let(fresh_vars, *base, |fresh_vars, base| { + monadic_let(fresh_vars, base.clone(), |fresh_vars, base| { ( - pure(Expr { - kind: ExprKind::IndexedField { - base: Box::new(base), - index, - }, + pure(Rc::new(Expr { + kind: Rc::new(ExprKind::IndexedField { + base, + index: *index, + }), ty, - }), + })), fresh_vars, ) }) } ExprKind::NamedField { base, name } => { - monadic_let(fresh_vars, *base, |fresh_vars, base| { + monadic_let(fresh_vars, base.clone(), |fresh_vars, base| { ( - pure(Expr { - kind: ExprKind::NamedField { - base: Box::new(base), - name, - }, + pure(Rc::new(Expr { + kind: Rc::new(ExprKind::NamedField { + base, + name: name.clone(), + }), ty: ty.clone(), - }), + })), + fresh_vars, + ) + }) + } + ExprKind::Index { base, index } => { + monadic_let(fresh_vars, base.clone(), |fresh_vars, base| { + ( + pure(Rc::new(Expr { + kind: Rc::new(ExprKind::Index { + base, + index: index.clone(), + }), + ty, + })), fresh_vars, ) }) } - ExprKind::Index { base, index } => monadic_let(fresh_vars, *base, |fresh_vars, base| { - ( - pure(Expr { - kind: ExprKind::Index { - base: Box::new(base), - index, - }, - ty, - }), - fresh_vars, - ) - }), // control flow expressions are responsible for side effects, so they are monadic already ExprKind::ControlFlow(lcf_expression) => ( - Expr { - kind: ExprKind::ControlFlow(lcf_expression), + Rc::new(Expr { + kind: Rc::new(ExprKind::ControlFlow(*lcf_expression)), ty, - }, + }), fresh_vars, ), ExprKind::StructStruct { @@ -635,7 +652,13 @@ pub(crate) fn mt_expression(fresh_vars: FreshVars, expr: Expr) -> (Expr, FreshVa base, struct_or_variant, } => { - let fields_values: Vec = fields.iter().map(|(_, field)| field.clone()).collect(); + let path = path.clone(); + let fields = fields.clone(); + let base = base.clone(); + let struct_or_variant = *struct_or_variant; + let fields_values: Vec> = + fields.iter().map(|(_, field)| field.clone()).collect(); + monadic_lets( fresh_vars, fields_values, @@ -644,8 +667,8 @@ pub(crate) fn mt_expression(fresh_vars: FreshVars, expr: Expr) -> (Expr, FreshVa let fields_names: Vec = fields.iter().map(|(name, _)| name.clone()).collect(); ( - pure(Expr { - kind: ExprKind::StructStruct { + pure(Rc::new(Expr { + kind: Rc::new(ExprKind::StructStruct { path, fields: fields_names .iter() @@ -654,9 +677,9 @@ pub(crate) fn mt_expression(fresh_vars: FreshVars, expr: Expr) -> (Expr, FreshVa .collect(), base, struct_or_variant, - }, + }), ty, - }), + })), fresh_vars, ) }) @@ -667,80 +690,86 @@ pub(crate) fn mt_expression(fresh_vars: FreshVars, expr: Expr) -> (Expr, FreshVa path, fields, struct_or_variant, - } => monadic_lets( - fresh_vars, - fields, - Box::new(|fresh_vars, fields| { - ( - pure(Expr { - kind: ExprKind::StructTuple { - path, - fields, - struct_or_variant, - }, - ty, - }), - fresh_vars, - ) - }), - ), - ExprKind::StructUnit { .. } => (pure(expr), fresh_vars), - ExprKind::Use(expr) => monadic_let(fresh_vars, *expr, |fresh_vars, expr| { + } => { + let path = path.clone(); + let struct_or_variant = *struct_or_variant; + + monadic_lets( + fresh_vars, + fields.clone(), + Box::new(move |fresh_vars, fields| { + ( + pure(Rc::new(Expr { + kind: Rc::new(ExprKind::StructTuple { + path, + fields, + struct_or_variant, + }), + ty, + })), + fresh_vars, + ) + }), + ) + } + ExprKind::StructUnit { .. } => (pure(expr.clone()), fresh_vars), + ExprKind::Use(expr) => monadic_let(fresh_vars, expr.clone(), |fresh_vars, expr| { ( - pure(Expr { - kind: ExprKind::Use(Box::new(expr)), + pure(Rc::new(Expr { + kind: Rc::new(ExprKind::Use(expr)), ty, - }), + })), fresh_vars, ) }), - ExprKind::Return(expr) => monadic_let(fresh_vars, *expr, |fresh_vars, expr| { + ExprKind::Return(expr) => monadic_let(fresh_vars, expr.clone(), |fresh_vars, expr| { ( - Expr { - kind: ExprKind::Return(Box::new(expr)), + Rc::new(Expr { + kind: Rc::new(ExprKind::Return(expr)), ty, - }, + }), fresh_vars, ) }), - ExprKind::Message(_) => (pure(expr), fresh_vars), + ExprKind::Message(_) => (pure(expr.clone()), fresh_vars), } } /// Get the pure part of a statement, if possible, as a statement. -fn get_pure_from_stmt(statement: Expr) -> Option> { - match statement.kind { - ExprKind::Pure(e) => Some(e), +fn get_pure_from_stmt(statement: Rc) -> Option> { + match statement.kind.as_ref() { + ExprKind::Pure(e) => Some(e.clone()), ExprKind::Let { is_monadic: true, .. } => None, ExprKind::Let { is_monadic: false, - pattern, + name, init, body, - } => get_pure_from_stmt(*body).map(|body| { - Box::new(Expr { - kind: ExprKind::Let { + } => get_pure_from_stmt(body.clone()).map(|body| { + Rc::new(Expr { + kind: Rc::new(ExprKind::Let { is_monadic: false, - pattern, - init, + name: name.clone(), + init: init.clone(), body, - }, - ty: statement.ty, + }), + ty: statement.ty.clone(), }) }), _ => None, } } -pub(crate) fn compile_hir_id(env: &mut Env, hir_id: rustc_hir::hir_id::HirId) -> Expr { +pub(crate) fn compile_hir_id(env: &mut Env, hir_id: rustc_hir::hir_id::HirId) -> Rc { let local_def_id = hir_id.owner.def_id; let thir = env.tcx.thir_body(local_def_id); let Ok((thir, expr_id)) = thir else { panic!("thir failed to compile"); }; let thir = thir.borrow(); + crate::thir_expression::compile_expr(env, &thir, &expr_id) } @@ -763,8 +792,8 @@ impl MatchArm { impl LoopControlFlow { pub fn to_doc<'a>(self) -> Doc<'a> { match self { - LoopControlFlow::Break => text("Break"), - LoopControlFlow::Continue => text("Continue"), + LoopControlFlow::Break => text("M.break"), + LoopControlFlow::Continue => text("M.continue"), } } } @@ -882,7 +911,11 @@ impl ExprKind { ExprKind::MonadicOperator { name, arg } => { paren(with_paren, nest([text(name), line(), arg.to_doc(true)])) } - ExprKind::Lambda { args, body } => { + ExprKind::Lambda { + args, + body, + is_for_match: _, + } => { let body = group([ body.to_doc(true), text(" :"), @@ -903,15 +936,16 @@ impl ExprKind { text("fun"), line(), intersperse( - args.iter().map(|(pattern, ty)| { - nest([ + args.iter().map(|(name, ty)| match ty { + None => text(name), + Some(ty) => nest([ text("("), - pattern.to_doc(false), + text(name), text(" :"), line(), ty.to_coq().to_doc(false), text(")"), - ]) + ]), }), [line()], ), @@ -944,7 +978,7 @@ impl ExprKind { ), ExprKind::Let { is_monadic, - pattern, + name, init, body, } => paren( @@ -956,9 +990,11 @@ impl ExprKind { text("let"), optional_insert(!*is_monadic, text("*")), line(), - optional_insert(pattern.is_single_binding(), text("'")), + text(match name { + Some(name) => name, + None => "_", + }), ]), - pattern.to_doc(false), match &init.ty { Some(ty) => concat([text(" :"), line(), ty.to_coq().to_doc(false)]), None => nil(), @@ -999,12 +1035,9 @@ impl ExprKind { nest([text("else"), hardline(), failure.to_doc(false)]), ]), ), - ExprKind::Loop { - body, /*loop_source*/ - .. - } => paren( + ExprKind::Loop { body } => paren( with_paren, - nest([text("loop"), line(), paren(true, body.to_doc(with_paren))]), + nest([text("M.loop"), line(), paren(true, body.to_doc(with_paren))]), ), ExprKind::Match { scrutinee, arms } => group([ group([ diff --git a/lib/src/path.rs b/lib/src/path.rs index 06e385b5a..f21d74497 100644 --- a/lib/src/path.rs +++ b/lib/src/path.rs @@ -157,7 +157,7 @@ pub(crate) fn get_path_generics<'a>( .map(|def_id| env.tcx.generics_of(def_id)) } -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub(crate) enum StructOrVariant { Struct, Variant, diff --git a/lib/src/pattern.rs b/lib/src/pattern.rs index 62eddf5e8..30185662e 100644 --- a/lib/src/pattern.rs +++ b/lib/src/pattern.rs @@ -1,83 +1,171 @@ use crate::path::*; use crate::render::*; - +use itertools::Itertools; use rustc_ast::LitKind; +use std::rc::Rc; +use std::vec; /// The enum [Pat] represents the patterns which can be matched -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Debug, Eq, Hash, PartialEq)] pub(crate) enum Pattern { Wild, - Variable(String), - Binding(String, Box), - StructStruct(Path, Vec<(String, Pattern)>, StructOrVariant), - StructTuple(Path, Vec, StructOrVariant), - Or(Vec), - Tuple(Vec), + Binding { + name: String, + /// Wether the reference is mutable, if any + is_with_ref: Option, + pattern: Option>, + }, + StructStruct(Path, Vec<(String, Rc)>, StructOrVariant), + StructTuple(Path, Vec>, StructOrVariant), + Deref(Rc), + Or(Vec>), + Tuple(Vec>), #[allow(dead_code)] Lit(LitKind), // TODO: modify if necessary to fully implement the case of Slice in compile_pattern below Slice { - init_patterns: Vec, - slice_pattern: Option>, + init_patterns: Vec>, + slice_pattern: Option>, }, } impl Pattern { - /// Returns wether a pattern is a single binding, to know if we need a quote - /// in the "let" in Coq. - pub(crate) fn is_single_binding(&self) -> bool { - matches!(self, Pattern::Variable(_) | Pattern::Wild) + /// Because the function from the standard library returns nothing instead + /// of an empty iterator when the input is empty. + fn multi_cartesian_product_with_empty_case( + iterator: A, + ) -> Vec::Item>> + where + A: Sized, + A::Item: IntoIterator, + ::IntoIter: Clone, + ::Item: Clone, + { + let combinations = iterator.multi_cartesian_product().collect::>(); + if combinations.is_empty() { + vec![vec![]] + } else { + combinations + } } - pub(crate) fn get_bindings(&self) -> Vec { - match self { - Pattern::Wild => vec![], - Pattern::Variable(name) => vec![name.clone()], - Pattern::Binding(name, pattern) => { - vec![vec![name.clone()], pattern.get_bindings()].concat() + pub(crate) fn flatten_ors(self: &Rc) -> Vec> { + match self.as_ref() { + Pattern::Wild => vec![self.clone()], + Pattern::Binding { + name, + is_with_ref, + pattern, + } => match pattern { + None => vec![self.clone()], + Some(pattern) => pattern + .flatten_ors() + .into_iter() + .map(|pattern| { + Rc::new(Pattern::Binding { + name: name.clone(), + is_with_ref: *is_with_ref, + pattern: Some(pattern), + }) + }) + .collect(), + }, + Pattern::StructStruct(path, fields, struct_or_variant) => { + Pattern::multi_cartesian_product_with_empty_case(fields.iter().map( + |(name, pattern)| { + pattern + .flatten_ors() + .into_iter() + .map(|pattern| (name.clone(), pattern)) + }, + )) + .into_iter() + .map(|fields| { + Rc::new(Pattern::StructStruct( + path.clone(), + fields, + *struct_or_variant, + )) + }) + .collect() } - Pattern::StructStruct(_, fields, _) => fields + Pattern::StructTuple(path, patterns, struct_or_variant) => { + Pattern::multi_cartesian_product_with_empty_case( + patterns.iter().map(|pattern| pattern.flatten_ors()), + ) + .into_iter() + .map(|patterns| { + Rc::new(Pattern::StructTuple( + path.clone(), + patterns, + *struct_or_variant, + )) + }) + .collect() + } + Pattern::Deref(pattern) => pattern + .flatten_ors() + .into_iter() + .map(|pattern| Rc::new(Pattern::Deref(pattern))) + .collect(), + Pattern::Or(patterns) => patterns .iter() - .flat_map(|(_, pattern)| pattern.get_bindings()) + .flat_map(|pattern| pattern.flatten_ors()) .collect(), - Pattern::StructTuple(_, patterns, _) => { - patterns.iter().flat_map(Pattern::get_bindings).collect() - } - Pattern::Or(patterns) => optional_insert_vec( - patterns.is_empty(), - patterns.first().unwrap().get_bindings(), - ), - Pattern::Tuple(patterns) => patterns.iter().flat_map(Pattern::get_bindings).collect(), - Pattern::Lit(_) => vec![], + Pattern::Tuple(patterns) => Pattern::multi_cartesian_product_with_empty_case( + patterns.iter().map(|pattern| pattern.flatten_ors()), + ) + .into_iter() + .map(|patterns| Rc::new(Pattern::Tuple(patterns))) + .collect(), + Pattern::Lit(_) => vec![self.clone()], Pattern::Slice { init_patterns, slice_pattern, - } => vec![ + } => Pattern::multi_cartesian_product_with_empty_case( init_patterns .iter() - .flat_map(Pattern::get_bindings) + .map(|init_pattern| init_pattern.flatten_ors()), + ) + .into_iter() + .flat_map(|init_patterns| match slice_pattern { + None => vec![Rc::new(Pattern::Slice { + init_patterns, + slice_pattern: None, + })], + Some(slice_pattern) => slice_pattern + .flatten_ors() + .into_iter() + .map(|slice_pattern| { + Rc::new(Pattern::Slice { + init_patterns: init_patterns.clone(), + slice_pattern: Some(slice_pattern), + }) + }) .collect(), - match slice_pattern { - None => vec![], - Some(pattern) => pattern.get_bindings(), - }, - ] - .concat(), + }) + .collect(), } } pub(crate) fn to_doc(&self, with_paren: bool) -> Doc { match self { Pattern::Wild => text("_"), - Pattern::Variable(name) => text(name), - Pattern::Binding(name, pat) => nest([ - text("("), - pat.to_doc(false), - text(" as"), - line(), - text(name), - text(")"), - ]), + Pattern::Binding { + name, + is_with_ref: _, + pattern, + } => match pattern { + None => text(name), + Some(pattern) => nest([ + text("("), + pattern.to_doc(false), + text(" as"), + line(), + text(name), + text(")"), + ]), + }, Pattern::StructStruct(path, fields, struct_or_variant) => paren( with_paren && matches!(struct_or_variant, StructOrVariant::Variant) @@ -134,6 +222,7 @@ impl Pattern { ), ]), ), + Pattern::Deref(pattern) => pattern.to_doc(with_paren), Pattern::Or(pats) => paren( with_paren, nest([intersperse( diff --git a/lib/src/thir_expression.rs b/lib/src/thir_expression.rs index 9f04127a0..1065bb295 100644 --- a/lib/src/thir_expression.rs +++ b/lib/src/thir_expression.rs @@ -12,20 +12,20 @@ use rustc_middle::ty::TyKind; use std::rc::Rc; impl ExprKind { - pub(crate) fn alloc(self, ty: Option>) -> Self { - ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::LocalVar("M.alloc".to_string()), + pub(crate) fn alloc(self: Rc, ty: Option>) -> Rc { + Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("M.alloc".to_string())), ty: None, }), - args: vec![Expr { kind: self, ty }], + args: vec![Rc::new(Expr { kind: self, ty })], purity: Purity::Effectful, from_user: false, - } + }) } } -fn path_of_bin_op(bin_op: &BinOp) -> (Path, Purity) { +fn path_of_bin_op(bin_op: &BinOp, ty_left: &Rc, ty_right: &Rc) -> (Path, Purity) { match bin_op { BinOp::Add => (Path::new(&["BinOp", "Panic", "add"]), Purity::Effectful), BinOp::Sub => (Path::new(&["BinOp", "Panic", "sub"]), Purity::Effectful), @@ -37,7 +37,15 @@ fn path_of_bin_op(bin_op: &BinOp) -> (Path, Purity) { BinOp::BitOr => (Path::new(&["BinOp", "Pure", "bit_or"]), Purity::Pure), BinOp::Shl => (Path::new(&["BinOp", "Panic", "shl"]), Purity::Effectful), BinOp::Shr => (Path::new(&["BinOp", "Panic", "shr"]), Purity::Effectful), - BinOp::Eq => (Path::new(&["BinOp", "Pure", "eq"]), Purity::Pure), + BinOp::Eq => { + if matches!(ty_left.as_ref(), CoqType::Path { path } if path.segments == ["bool", "t"]) + && matches!(ty_right.as_ref(), CoqType::Path { path } if path.segments == ["bool", "t"]) + { + (Path::new(&["Bool", "eqb"]), Purity::Pure) + } else { + (Path::new(&["BinOp", "Pure", "eq"]), Purity::Pure) + } + } BinOp::Ne => (Path::new(&["BinOp", "Pure", "ne"]), Purity::Pure), BinOp::Lt => (Path::new(&["BinOp", "Pure", "lt"]), Purity::Pure), BinOp::Le => (Path::new(&["BinOp", "Pure", "le"]), Purity::Pure), @@ -51,23 +59,23 @@ pub(crate) fn compile_expr<'a>( env: &mut Env<'a>, thir: &rustc_middle::thir::Thir<'a>, expr_id: &rustc_middle::thir::ExprId, -) -> Expr { +) -> Rc { let expr = thir.exprs.get(*expr_id).unwrap(); let kind = compile_expr_kind(env, thir, expr_id); let ty = compile_type(env, &expr.ty).val(); - Expr { kind, ty: Some(ty) } + Rc::new(Expr { kind, ty: Some(ty) }) } impl Expr { - fn match_simple_call(&self, name_in: &[&str]) -> Option { + fn match_simple_call(self: Rc, name_in: &[&str]) -> Option> { if let ExprKind::Call { func, args, purity: _, from_user: _, - } = &self.kind + } = self.kind.as_ref() { - if let ExprKind::LocalVar(func) = &func.kind { + if let ExprKind::LocalVar(func) = func.kind.as_ref() { if name_in.contains(&func.as_str()) && args.len() == 1 { return Some(args.get(0).unwrap().clone()); } @@ -78,21 +86,21 @@ impl Expr { } /// Return the borrowed expression if the expression is a borrow. - fn match_borrow(&self) -> Option { + fn match_borrow(self: Rc) -> Option> { self.match_simple_call(&["borrow", "borrow_mut"]) } - fn match_deref(&self) -> Option { + fn match_deref(self: Rc) -> Option> { self.match_simple_call(&["deref"]) } - pub(crate) fn read(self) -> Self { + pub(crate) fn read(self: Rc) -> Rc { // If we read an allocated expression, we just return the expression. - if let Some(expr) = self.match_simple_call(&["M.alloc"]) { + if let Some(expr) = self.clone().match_simple_call(&["M.alloc"]) { return expr; } - Expr { + Rc::new(Expr { ty: match self.ty.clone() { None => None, Some(ty) => { @@ -114,95 +122,486 @@ impl Expr { } } }, - kind: ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::LocalVar("M.read".to_string()), + kind: Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("M.read".to_string())), ty: None, }), args: vec![self], purity: Purity::Effectful, from_user: false, - }, - } + }), + }) } - fn copy(self) -> Self { - if self.match_simple_call(&["M.alloc"]).is_some() { + fn copy(self: Rc) -> Rc { + if self.clone().match_simple_call(&["M.alloc"]).is_some() { return self; } - Expr { + Rc::new(Expr { ty: self.ty.clone(), - kind: ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::LocalVar("M.copy".to_string()), + kind: Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("M.copy".to_string())), ty: None, }), args: vec![self], purity: Purity::Effectful, from_user: false, - }, - } + }), + }) + } +} + +pub(crate) fn is_mutable_borrow_kind(borrow_kind: &BorrowKind) -> bool { + match borrow_kind { + BorrowKind::Shared | BorrowKind::Shallow => false, + BorrowKind::Unique | BorrowKind::Mut { .. } => true, } } -fn compile_borrow(borrow_kind: &BorrowKind, arg: Expr) -> ExprKind { - let func = match borrow_kind { - BorrowKind::Shared | BorrowKind::Shallow => "borrow".to_string(), - BorrowKind::Unique | BorrowKind::Mut { .. } => "borrow_mut".to_string(), +fn compile_borrow(borrow_kind: &BorrowKind, arg: Rc) -> Rc { + let func = if is_mutable_borrow_kind(borrow_kind) { + "borrow_mut".to_string() + } else { + "borrow".to_string() }; - if let Some(derefed) = arg.match_deref() { - if let Some(ty) = derefed.ty { + if let Some(derefed) = arg.clone().match_deref() { + if let Some(ty) = derefed.ty.clone() { if let Some((ref_name, _, _)) = ty.match_ref() { if (func == "borrow" && ref_name == "ref") || (func == "borrow_mut" && ref_name == "mut_ref") { - return derefed.kind; + return derefed.kind.clone(); } } } } - ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::LocalVar(func), + Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar(func)), ty: None, }), args: vec![arg], purity: Purity::Pure, from_user: false, - } + }) } -pub(crate) fn allocate_bindings(bindings: &[String], body: Box) -> Box { +pub(crate) fn allocate_bindings(bindings: &[String], body: Rc) -> Rc { bindings.iter().rfold(body, |body, binding| { - Box::new(Expr { + Rc::new(Expr { ty: body.ty.clone(), - kind: ExprKind::Let { + kind: Rc::new(ExprKind::Let { is_monadic: false, - pattern: Box::new(Pattern::Variable(binding.clone())), - init: Box::new(Expr { - kind: ExprKind::LocalVar(binding.clone()).alloc(None), + name: Some(binding.clone()), + init: Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar(binding.clone())).alloc(None), ty: None, }), body, - }, + }), }) }) } -/// Allocate all the bindings in the [pattern] to some [M.Val] -fn allocate_bindings_in_pattern(pattern: &Pattern, body: Box) -> Box { - let bindings = pattern.get_bindings(); - allocate_bindings(&bindings, body) +fn build_inner_match(patterns: Vec<(String, Rc)>, body: Rc) -> Rc { + let default_match_arm = Rc::new(MatchArm { + pattern: Rc::new(Pattern::Wild), + body: Rc::new(Expr { + kind: Rc::new(ExprKind::Call { + func: Expr::local_var("M.break_match"), + args: vec![], + purity: Purity::Effectful, + from_user: false, + }), + ty: None, + }), + }); + + patterns + .into_iter() + .rfold(body, |body, (scrutinee, pattern)| match pattern.as_ref() { + Pattern::Wild => body, + Pattern::Binding { + name, + is_with_ref, + pattern, + } => Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Let { + is_monadic: false, + name: Some(name.clone()), + init: match is_with_ref { + None => Expr::local_var(&scrutinee).copy(), + Some(is_with_ref) => { + let func = if *is_with_ref { "borrow" } else { "borrow_mut" }; + + Rc::new(Expr { + ty: None, + kind: Rc::new(ExprKind::Call { + func: Expr::local_var(func), + args: vec![Expr::local_var(&scrutinee)], + purity: Purity::Pure, + from_user: false, + }) + .alloc(None), + }) + } + }, + body: match pattern { + None => body, + Some(pattern) => { + build_inner_match(vec![(scrutinee, pattern.clone())], body) + } + }, + }), + }), + Pattern::StructStruct(path, fields, struct_or_variant) => Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Match { + scrutinee: Expr::local_var(&scrutinee).read(), + arms: [ + vec![Rc::new(MatchArm { + pattern: Rc::new(Pattern::StructStruct( + path.clone(), + fields + .iter() + .map(|(field_name, _)| { + (field_name.clone(), Rc::new(Pattern::Wild)) + }) + .collect(), + *struct_or_variant, + )), + body: { + let body = build_inner_match( + fields + .iter() + .enumerate() + .map(|(index, (_, field_pattern))| { + (format!("γ{index}"), field_pattern.clone()) + }) + .collect(), + body, + ); + + fields.iter().enumerate().rfold( + body, + |body, (index, (field_name, _))| { + Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Let { + is_monadic: false, + name: Some(format!("γ{index}")), + init: Rc::new(Expr { + ty: None, + kind: Rc::new(ExprKind::NamedField { + base: Expr::local_var(&scrutinee), + name: format!( + "{}.{field_name}", + path.segments.last().unwrap(), + ), + }), + }), + body, + }), + }) + }, + ) + }, + })], + match struct_or_variant { + StructOrVariant::Struct => vec![], + StructOrVariant::Variant => vec![default_match_arm.clone()], + }, + ] + .concat(), + }), + }), + Pattern::StructTuple(path, patterns, struct_or_variant) => Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Match { + scrutinee: Expr::local_var(&scrutinee).read(), + arms: [ + vec![Rc::new(MatchArm { + pattern: Rc::new(Pattern::StructTuple( + path.clone(), + patterns.iter().map(|_| Rc::new(Pattern::Wild)).collect(), + *struct_or_variant, + )), + body: { + let body = build_inner_match( + patterns + .iter() + .enumerate() + .map(|(index, pattern)| { + (format!("γ{index}"), pattern.clone()) + }) + .collect(), + body, + ); + + patterns.iter().enumerate().rfold(body, |body, (index, _)| { + Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Let { + is_monadic: false, + name: Some(format!("γ{index}")), + init: Rc::new(Expr { + ty: None, + kind: Rc::new(ExprKind::NamedField { + base: Expr::local_var(&scrutinee), + name: format!( + "{}.{index}", + path.segments.last().unwrap(), + ), + }), + }), + body, + }), + }) + }) + }, + })], + match struct_or_variant { + StructOrVariant::Struct => vec![], + StructOrVariant::Variant => vec![default_match_arm.clone()], + }, + ] + .concat(), + }), + }), + Pattern::Deref(pattern) => Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Let { + is_monadic: false, + name: Some(scrutinee.clone()), + init: Rc::new(Expr { + ty: None, + kind: Rc::new(ExprKind::Call { + func: Expr::local_var("deref"), + args: vec![Expr::local_var(&scrutinee).read()], + purity: Purity::Pure, + from_user: false, + }), + }), + body: build_inner_match(vec![(scrutinee.clone(), pattern.clone())], body), + }), + }), + Pattern::Or(_) => panic!("Or pattern should have been flattened"), + Pattern::Tuple(patterns) => Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Match { + scrutinee: Expr::local_var(&scrutinee).read(), + arms: vec![Rc::new(MatchArm { + pattern: Rc::new(Pattern::Tuple( + patterns.iter().map(|_| Rc::new(Pattern::Wild)).collect(), + )), + body: { + let body = build_inner_match( + patterns + .iter() + .enumerate() + .map(|(index, pattern)| (format!("γ{index}"), pattern.clone())) + .collect(), + body, + ); + + patterns.iter().enumerate().rfold(body, |body, (index, _)| { + Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Let { + is_monadic: false, + name: Some(format!("γ{index}")), + init: { + let init = (0..(patterns.len() - 1 - index)).fold( + Expr::local_var(&scrutinee), + |init, _| { + Rc::new(Expr { + ty: None, + kind: Rc::new(ExprKind::Call { + func: Expr::local_var( + "Tuple.Access.left", + ), + args: vec![init], + purity: Purity::Pure, + from_user: false, + }), + }) + }, + ); + + if index == 0 { + init + } else { + Rc::new(Expr { + ty: None, + kind: Rc::new(ExprKind::Call { + func: Expr::local_var("Tuple.Access.right"), + args: vec![init], + purity: Purity::Pure, + from_user: false, + }), + }) + } + }, + body, + }), + }) + }) + }, + })], + }), + }), + Pattern::Lit(_) => Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Match { + scrutinee: Expr::local_var(&scrutinee).read(), + arms: vec![ + Rc::new(MatchArm { + pattern: pattern.clone(), + body, + }), + default_match_arm.clone(), + ], + }), + }), + Pattern::Slice { + init_patterns, + slice_pattern, + } => Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Match { + scrutinee: Expr::local_var(&scrutinee).read(), + arms: vec![ + Rc::new(MatchArm { + pattern: Rc::new(Pattern::Slice { + init_patterns: init_patterns + .iter() + .map(|_| Rc::new(Pattern::Wild)) + .collect(), + slice_pattern: slice_pattern + .as_ref() + .map(|_| Rc::new(Pattern::Wild)), + }), + body: { + let body = build_inner_match( + vec![ + init_patterns + .iter() + .enumerate() + .map(|(index, pattern)| { + (format!("γ{index}"), pattern.clone()) + }) + .collect(), + match slice_pattern { + None => vec![], + Some(slice_pattern) => { + vec![("γ".to_string(), slice_pattern.clone())] + } + }, + ] + .concat(), + body, + ); + + let body = match slice_pattern { + None => body, + Some(_) => Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Let { + is_monadic: false, + name: Some("γ".to_string()), + init: Rc::new(Expr { + ty: None, + kind: Rc::new(ExprKind::NamedField { + base: Expr::local_var(&scrutinee), + name: format!( + "[{}].slice", + init_patterns.len() + ), + }), + }), + body, + }), + }), + }; + + init_patterns + .iter() + .enumerate() + .rfold(body, |body, (index, _)| { + Rc::new(Expr { + ty: body.ty.clone(), + kind: Rc::new(ExprKind::Let { + is_monadic: false, + name: Some(format!("γ{index}")), + init: Rc::new(Expr { + ty: None, + kind: Rc::new(ExprKind::NamedField { + base: Expr::local_var(&scrutinee), + name: format!("[{index}]",), + }), + }), + body, + }), + }) + }) + }, + }), + default_match_arm.clone(), + ], + }), + }), + }) +} + +fn build_match(scrutinee: Rc, arms: Vec, _ty: Option>) -> Rc { + let arms_with_flatten_patterns = arms.into_iter().flat_map(|MatchArm { pattern, body }| { + pattern + .flatten_ors() + .into_iter() + .map(move |pattern| MatchArm { + pattern, + body: body.clone(), + }) + }); + + Rc::new(ExprKind::Call { + func: Expr::local_var("match_operator"), + args: vec![ + scrutinee, + Rc::new(Expr { + kind: Rc::new(ExprKind::Array { + elements: arms_with_flatten_patterns + .map(|MatchArm { pattern, body }| { + Rc::new(Expr { + kind: Rc::new(ExprKind::Lambda { + args: vec![("γ".to_string(), None)], + body: build_inner_match(vec![("γ".to_string(), pattern)], body), + is_for_match: true, + }), + ty: None, + }) + }) + .collect(), + }), + ty: None, + }), + ], + purity: Purity::Effectful, + from_user: false, + }) } fn compile_expr_kind<'a>( env: &mut Env<'a>, thir: &rustc_middle::thir::Thir<'a>, expr_id: &rustc_middle::thir::ExprId, -) -> ExprKind { +) -> Rc { let expr = thir.exprs.get(*expr_id).unwrap(); let ty = compile_type(env, &expr.ty); @@ -210,17 +609,18 @@ fn compile_expr_kind<'a>( thir::ExprKind::Scope { value, .. } => compile_expr_kind(env, thir, value), thir::ExprKind::Box { value } => { let value = compile_expr(env, thir, value); - ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::LocalVar( + + Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar( "(alloc.boxed.Box _ alloc.boxed.Box.Default.A)::[\"new\"]".to_string(), - ), + )), ty: None, }), args: vec![value], purity: Purity::Effectful, from_user: true, - } + }) } thir::ExprKind::If { cond, @@ -228,17 +628,17 @@ fn compile_expr_kind<'a>( else_opt, .. } => { - let condition = Box::new(compile_expr(env, thir, cond).read()); - let success = Box::new(compile_expr(env, thir, then)); + let condition = compile_expr(env, thir, cond).read(); + let success = compile_expr(env, thir, then); let failure = match else_opt { - Some(else_expr) => Box::new(compile_expr(env, thir, else_expr)), - None => Box::new(Expr::tt()), + Some(else_expr) => compile_expr(env, thir, else_expr), + None => Expr::tt(), }; - ExprKind::If { + Rc::new(ExprKind::If { condition, success, failure, - } + }) } thir::ExprKind::Call { fun, args, .. } => { let args = args @@ -246,53 +646,59 @@ fn compile_expr_kind<'a>( .map(|arg| compile_expr(env, thir, arg).read()) .collect(); let func = compile_expr(env, thir, fun); - let (purity, from_user) = match &func.match_simple_call(&["M.alloc"]) { - Some(Expr { - kind: ExprKind::Constructor(_), - .. - }) => (Purity::Pure, false), - _ => (Purity::Effectful, true), + let (purity, from_user) = { + let default = (Purity::Effectful, true); + + match func.clone().match_simple_call(&["M.alloc"]).as_ref() { + Some(expr) => match expr.kind.as_ref() { + ExprKind::Constructor(_) => (Purity::Pure, false), + _ => default, + }, + _ => default, + } }; - let func = Box::new(func.read()); + let func = func.read(); - ExprKind::Call { + Rc::new(ExprKind::Call { func, args, purity, from_user, - } + }) .alloc(Some(ty)) } thir::ExprKind::Deref { arg } => { let arg = compile_expr(env, thir, arg).read(); - if let Some(borrowed) = Expr::match_borrow(&arg) { - return borrowed.kind; + if let Some(borrowed) = Expr::match_borrow(arg.clone()) { + return borrowed.kind.clone(); } - ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::LocalVar("deref".to_string()), + Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("deref".to_string())), ty: None, }), args: vec![arg], purity: Purity::Pure, from_user: false, - } + }) } thir::ExprKind::Binary { op, lhs, rhs } => { - let (path, purity) = path_of_bin_op(op); + let left_ty = compile_type(env, &thir.exprs.get(*lhs).unwrap().ty); + let right_ty = compile_type(env, &thir.exprs.get(*rhs).unwrap().ty); + let (path, purity) = path_of_bin_op(op, &left_ty, &right_ty); let lhs = compile_expr(env, thir, lhs); let rhs = compile_expr(env, thir, rhs); - ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::Var(path), + Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::Var(path)), ty: None, }), args: vec![lhs.read(), rhs.read()], purity, from_user: false, - } + }) .alloc(Some(ty)) } thir::ExprKind::LogicalOp { op, lhs, rhs } => { @@ -302,15 +708,15 @@ fn compile_expr_kind<'a>( }; let lhs = compile_expr(env, thir, lhs); let rhs = compile_expr(env, thir, rhs); - ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::Var(path), + Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::Var(path)), ty: None, }), args: vec![lhs.read(), rhs.read()], purity: Purity::Pure, from_user: false, - } + }) .alloc(Some(ty)) } thir::ExprKind::Unary { op, arg } => { @@ -319,198 +725,185 @@ fn compile_expr_kind<'a>( UnOp::Neg => (Path::new(&["UnOp", "neg"]), Purity::Effectful), }; let arg = compile_expr(env, thir, arg); - ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::Var(path), + Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::Var(path)), ty: None, }), args: vec![arg.read()], purity, from_user: false, - } + }) .alloc(Some(ty)) } thir::ExprKind::Cast { source } => { - let func = Box::new(Expr { - kind: ExprKind::LocalVar("cast".to_string()), + let func = Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("cast".to_string())), ty: None, }); let source = compile_expr(env, thir, source); - ExprKind::Call { + Rc::new(ExprKind::Call { func, args: vec![source.read()], purity: Purity::Effectful, from_user: false, - } + }) .alloc(Some(ty)) } thir::ExprKind::Use { source } => { let source = compile_expr(env, thir, source); - ExprKind::Use(Box::new(source)) + + Rc::new(ExprKind::Use(source)) } thir::ExprKind::NeverToAny { source } => { - let func = Box::new(Expr { - kind: ExprKind::LocalVar("never_to_any".to_string()), + let func = Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("never_to_any".to_string())), ty: None, }); let source = compile_expr(env, thir, source); - ExprKind::Call { + Rc::new(ExprKind::Call { func, args: vec![source.read()], purity: Purity::Effectful, from_user: false, - } + }) .alloc(Some(ty)) } thir::ExprKind::Pointer { source, cast } => { - let func = Box::new(Expr { - kind: ExprKind::LocalVar("pointer_coercion".to_string()), + let func = Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("pointer_coercion".to_string())), ty: None, }); let source = compile_expr(env, thir, source); - let cast = Expr { - kind: ExprKind::Message(format!("{cast:?}")), + let cast = Rc::new(Expr { + kind: Rc::new(ExprKind::Message(format!("{cast:?}"))), ty: None, - }; - ExprKind::Call { + }); + Rc::new(ExprKind::Call { func, args: vec![cast, source], purity: Purity::Pure, from_user: false, - } + }) } thir::ExprKind::Loop { body, .. } => { - let body = Box::new(compile_expr(env, thir, body)); - ExprKind::Loop { body } + let body = compile_expr(env, thir, body); + Rc::new(ExprKind::Loop { body }) } thir::ExprKind::Let { expr, pat } => { - let pat = Box::new(crate::thir_pattern::compile_pattern(env, pat)); - let init = Box::new(compile_expr(env, thir, expr)); - ExprKind::LetIf { pat, init } + let pat = crate::thir_pattern::compile_pattern(env, pat); + let init = compile_expr(env, thir, expr); + Rc::new(ExprKind::LetIf { pat, init }) } thir::ExprKind::Match { scrutinee, arms } => { - let scrutinee = compile_expr(env, thir, scrutinee).read(); + let scrutinee = compile_expr(env, thir, scrutinee); let arms: Vec = arms .iter() .map(|arm_id| { let arm = thir.arms.get(*arm_id).unwrap(); let pattern = crate::thir_pattern::compile_pattern(env, &arm.pattern); - let body = Box::new(compile_expr(env, thir, &arm.body)); - let body = allocate_bindings_in_pattern(&pattern, body); - MatchArm { - pattern, - body: *body, - } + let body = compile_expr(env, thir, &arm.body); + MatchArm { pattern, body } }) .collect(); - let is_reference = match &scrutinee.ty { - Some(ty) => matches!(ty.clone().match_ref(), Some((_, _, _))), - None => false, - }; - let are_all_bindings_empty = - arms.iter().all(|arm| arm.pattern.get_bindings().is_empty()); - let scrutinee = Box::new(if is_reference && are_all_bindings_empty { - // This is a simple case of `match` on a reference, when all - // patterns are without bindings. - scrutinee.read() - } else { - scrutinee - }); - - ExprKind::Match { scrutinee, arms } + build_match(scrutinee, arms, Some(ty.val())) + } + thir::ExprKind::Block { block: block_id } => { + compile_block(env, thir, block_id).kind.clone() } - thir::ExprKind::Block { block: block_id } => compile_block(env, thir, block_id).kind, thir::ExprKind::Assign { lhs, rhs } => { - let func = Box::new(Expr { - kind: ExprKind::LocalVar("assign".to_string()), + let func = Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("assign".to_string())), ty: None, }); let args = vec![ compile_expr(env, thir, lhs), compile_expr(env, thir, rhs).read(), ]; - ExprKind::Call { + Rc::new(ExprKind::Call { func, args, purity: Purity::Effectful, from_user: false, - } + }) } thir::ExprKind::AssignOp { op, lhs, rhs } => { - let (path, purity) = path_of_bin_op(op); + let left_ty = compile_type(env, &thir.exprs.get(*lhs).unwrap().ty); + let right_ty = compile_type(env, &thir.exprs.get(*rhs).unwrap().ty); + let (path, purity) = path_of_bin_op(op, &left_ty, &right_ty); let lhs = compile_expr(env, thir, lhs); let rhs = compile_expr(env, thir, rhs); - ExprKind::Let { + Rc::new(ExprKind::Let { is_monadic: false, - pattern: Box::new(Pattern::Variable("β".to_string())), - init: Box::new(lhs), - body: Box::new(Expr { - kind: ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::Var(Path::new(&["assign"])), + name: Some("β".to_string()), + init: lhs, + body: Rc::new(Expr { + kind: Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::Var(Path::new(&["assign"]))), ty: None, }), args: vec![ - Expr { - kind: ExprKind::LocalVar("β".to_string()), + Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("β".to_string())), ty: None, - }, - Expr { - kind: ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::Var(path), + }), + Rc::new(Expr { + kind: Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::Var(path)), ty: None, }), args: vec![ - Expr { - kind: ExprKind::LocalVar("β".to_string()), + Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("β".to_string())), ty: None, - } + }) .read(), rhs.read(), ], purity, from_user: false, - }, + }), ty: None, - }, + }), ], purity: Purity::Effectful, from_user: false, - }, + }), ty: None, }), - } + }) } thir::ExprKind::Field { lhs, variant_index, name, } => { - let base = Box::new(compile_expr(env, thir, lhs)); + let base = compile_expr(env, thir, lhs); let ty = thir.exprs.get(*lhs).unwrap().ty; match ty.ty_adt_def() { Some(adt_def) => { let variant = adt_def.variant(*variant_index); let name = variant.fields.get(*name).unwrap().name.to_string(); - ExprKind::NamedField { base, name } + Rc::new(ExprKind::NamedField { base, name }) } - None => ExprKind::Message("Unknown Field".to_string()), + None => Rc::new(ExprKind::Message("Unknown Field".to_string())), } } thir::ExprKind::Index { lhs, index } => { - let base = Box::new(compile_expr(env, thir, lhs)); - let index = Box::new(compile_expr(env, thir, index)); - ExprKind::Index { base, index } + let base = compile_expr(env, thir, lhs); + let index = compile_expr(env, thir, index); + Rc::new(ExprKind::Index { base, index }) } thir::ExprKind::VarRef { id } => { let name = to_valid_coq_name(env.tcx.hir().opt_name(id.0).unwrap().as_str()); - ExprKind::LocalVar(name) + Rc::new(ExprKind::LocalVar(name)) } thir::ExprKind::UpvarRef { var_hir_id, .. } => { let name = to_valid_coq_name(env.tcx.hir().opt_name(var_hir_id.0).unwrap().as_str()); - ExprKind::LocalVar(name) + Rc::new(ExprKind::LocalVar(name)) } thir::ExprKind::Borrow { borrow_kind, arg } => { let arg = compile_expr(env, thir, arg); @@ -523,52 +916,54 @@ fn compile_expr_kind<'a>( rustc_middle::mir::Mutability::Mut => "addr_of_mut".to_string(), }; let arg = compile_expr(env, thir, arg); - ExprKind::Call { - func: Box::new(Expr { - kind: ExprKind::LocalVar(func), + Rc::new(ExprKind::Call { + func: Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar(func)), ty: None, }), args: vec![arg], purity: Purity::Pure, from_user: false, - } + }) + } + thir::ExprKind::Break { .. } => Rc::new(ExprKind::ControlFlow(LoopControlFlow::Break)), + thir::ExprKind::Continue { .. } => { + Rc::new(ExprKind::ControlFlow(LoopControlFlow::Continue)) } - thir::ExprKind::Break { .. } => ExprKind::ControlFlow(LoopControlFlow::Break), - thir::ExprKind::Continue { .. } => ExprKind::ControlFlow(LoopControlFlow::Continue), thir::ExprKind::Return { value } => { let value = match value { Some(value) => compile_expr(env, thir, value).read(), None => Expr::tt(), }; - ExprKind::Return(Box::new(value)) + Rc::new(ExprKind::Return(value)) } - thir::ExprKind::ConstBlock { did, .. } => ExprKind::Var(compile_def_id(env, *did)), + thir::ExprKind::ConstBlock { did, .. } => Rc::new(ExprKind::Var(compile_def_id(env, *did))), thir::ExprKind::Repeat { value, count } => { - let func = Box::new(Expr { - kind: ExprKind::LocalVar("repeat".to_string()), + let func = Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("repeat".to_string())), ty: None, }); let args = vec![ compile_expr(env, thir, value).read(), - Expr { - kind: ExprKind::LocalVar(count.to_string()), + Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar(count.to_string())), ty: None, - }, + }), ]; - ExprKind::Call { + Rc::new(ExprKind::Call { func, args, purity: Purity::Pure, from_user: false, - } + }) .alloc(Some(ty)) } - thir::ExprKind::Array { fields } => ExprKind::Array { + thir::ExprKind::Array { fields } => Rc::new(ExprKind::Array { elements: fields .iter() .map(|field| compile_expr(env, thir, field).read()) .collect(), - } + }) .alloc(Some(ty)), thir::ExprKind::Tuple { fields } => { let elements: Vec<_> = fields @@ -578,7 +973,7 @@ fn compile_expr_kind<'a>( if elements.is_empty() { ExprKind::tt() } else { - ExprKind::Tuple { elements }.alloc(Some(ty)) + Rc::new(ExprKind::Tuple { elements }).alloc(Some(ty)) } } thir::ExprKind::Adt(adt_expr) => { @@ -609,27 +1004,27 @@ fn compile_expr_kind<'a>( StructOrVariant::Struct }; if fields.is_empty() { - return ExprKind::StructUnit { + return Rc::new(ExprKind::StructUnit { path, struct_or_variant, - } + }) .alloc(Some(ty)); } if is_a_tuple { let fields = fields.into_iter().map(|(_, pattern)| pattern).collect(); - ExprKind::StructTuple { + Rc::new(ExprKind::StructTuple { path, fields, struct_or_variant, - } + }) .alloc(Some(ty)) } else { - ExprKind::StructStruct { + Rc::new(ExprKind::StructStruct { path, fields, base: None, struct_or_variant, - } + }) .alloc(Some(ty)) } } @@ -644,7 +1039,7 @@ fn compile_expr_kind<'a>( panic!("thir failed to compile"); }; let thir = thir.borrow(); - let args: Vec<(Pattern, Rc)> = thir + let args: Vec<(Rc, Rc)> = thir .params .iter() .filter_map(|param| match ¶m.pat { @@ -656,39 +1051,66 @@ fn compile_expr_kind<'a>( None => None, }) .collect(); - let body = Box::new(compile_expr(env, &thir, &expr_id).read()); - let body = allocate_bindings( - &args - .iter() - .map(|(pattern, _)| pattern.get_bindings()) - .collect::>() - .concat(), - body, - ); + let body = compile_expr(env, &thir, &expr_id).read(); + let body = args + .iter() + .enumerate() + .rfold(body, |body, (index, (pattern, _))| { + let ty = body.ty.clone(); + + Rc::new(Expr { + kind: build_match( + Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar(format!("α{index}"))).alloc(None), + ty: None, + }), + vec![MatchArm { + pattern: pattern.clone(), + body, + }], + ty.clone(), + ), + ty, + }) + }); + let args = args + .iter() + .enumerate() + .map(|(index, (_, ty))| (format!("α{index}"), Some(ty.clone()))) + .collect(); - ExprKind::Lambda { args, body }.alloc(Some(ty)) + Rc::new(ExprKind::Lambda { + args, + body, + is_for_match: false, + }) + .alloc(Some(ty)) } thir::ExprKind::Literal { lit, neg } => match lit.node { rustc_ast::LitKind::Str(symbol, _) => { - ExprKind::Literal(Literal::String(symbol.to_string())) + Rc::new(ExprKind::Literal(Literal::String(symbol.to_string()))) + } + rustc_ast::LitKind::Char(c) => { + Rc::new(ExprKind::Literal(Literal::Char(c))).alloc(Some(ty)) } - rustc_ast::LitKind::Char(c) => ExprKind::Literal(Literal::Char(c)).alloc(Some(ty)), - rustc_ast::LitKind::Int(i, _) => ExprKind::Literal(Literal::Integer { + rustc_ast::LitKind::Int(i, _) => Rc::new(ExprKind::Literal(Literal::Integer { value: i, neg: *neg, - }) + })) .alloc(Some(ty)), - rustc_ast::LitKind::Bool(c) => ExprKind::Literal(Literal::Bool(c)).alloc(Some(ty)), - _ => ExprKind::Literal(Literal::Error), + rustc_ast::LitKind::Bool(c) => { + Rc::new(ExprKind::Literal(Literal::Bool(c))).alloc(Some(ty)) + } + _ => Rc::new(ExprKind::Literal(Literal::Error)), }, - thir::ExprKind::NonHirLiteral { lit, .. } => ExprKind::NonHirLiteral(*lit), + thir::ExprKind::NonHirLiteral { lit, .. } => Rc::new(ExprKind::NonHirLiteral(*lit)), thir::ExprKind::ZstLiteral { .. } => match &expr.ty.kind() { TyKind::FnDef(def_id, generic_args) => { let key = env.tcx.def_key(def_id); let symbol = key.get_opt_name(); let parent = env.tcx.opt_parent(*def_id).unwrap(); let parent_kind = env.tcx.opt_def_kind(parent).unwrap(); - match parent_kind { + Rc::new(match parent_kind { DefKind::Impl { .. } => { let parent_type = env.tcx.type_of(parent).subst(env.tcx, generic_args); let ty = compile_type(env, &parent_type); @@ -719,7 +1141,7 @@ fn compile_expr_kind<'a>( println!("expression: {:#?}", expr); ExprKind::Message("unimplemented parent_kind".to_string()) } - } + }) .alloc(Some(ty)) } _ => { @@ -728,35 +1150,41 @@ fn compile_expr_kind<'a>( .sess .struct_span_warn(expr.span, error_message) .emit(); - ExprKind::Message(error_message.to_string()) + Rc::new(ExprKind::Message(error_message.to_string())) } }, thir::ExprKind::NamedConst { def_id, substs, .. } => { let path = compile_def_id(env, *def_id); if substs.is_empty() { - return ExprKind::Var(path); + return Rc::new(ExprKind::Var(path)); } let self_ty = substs.type_at(0); let self_ty = crate::thir_ty::compile_type(env, &self_ty); - ExprKind::VarWithSelfTy { path, self_ty } + Rc::new(ExprKind::VarWithSelfTy { path, self_ty }) + } + thir::ExprKind::ConstParam { def_id, .. } => { + Rc::new(ExprKind::Var(compile_def_id(env, *def_id))) + } + thir::ExprKind::StaticRef { def_id, .. } => { + Rc::new(ExprKind::Var(compile_def_id(env, *def_id))) + } + thir::ExprKind::InlineAsm(_) => Rc::new(ExprKind::LocalVar("InlineAssembly".to_string())), + thir::ExprKind::OffsetOf { .. } => Rc::new(ExprKind::LocalVar("OffsetOf".to_string())), + thir::ExprKind::ThreadLocalRef(def_id) => { + Rc::new(ExprKind::Var(compile_def_id(env, *def_id))) } - thir::ExprKind::ConstParam { def_id, .. } => ExprKind::Var(compile_def_id(env, *def_id)), - thir::ExprKind::StaticRef { def_id, .. } => ExprKind::Var(compile_def_id(env, *def_id)), - thir::ExprKind::InlineAsm(_) => ExprKind::LocalVar("InlineAssembly".to_string()), - thir::ExprKind::OffsetOf { .. } => ExprKind::LocalVar("OffsetOf".to_string()), - thir::ExprKind::ThreadLocalRef(def_id) => ExprKind::Var(compile_def_id(env, *def_id)), thir::ExprKind::Yield { value } => { - let func = Box::new(Expr { - kind: ExprKind::LocalVar("yield".to_string()), + let func = Rc::new(Expr { + kind: Rc::new(ExprKind::LocalVar("yield".to_string())), ty: None, }); let args = vec![compile_expr(env, thir, value)]; - ExprKind::Call { + Rc::new(ExprKind::Call { func, args, purity: Purity::Effectful, from_user: false, - } + }) } } } @@ -766,7 +1194,7 @@ fn compile_stmts<'a>( thir: &rustc_middle::thir::Thir<'a>, stmt_ids: &[rustc_middle::thir::StmtId], expr_id: Option, -) -> Expr { +) -> Rc { stmt_ids.iter().rev().fold( { match &expr_id { @@ -775,7 +1203,6 @@ fn compile_stmts<'a>( } }, |body, stmt_id| { - let body = Box::new(body); let stmt = thir.stmts.get(*stmt_id).unwrap(); match &stmt.kind { thir::StmtKind::Let { @@ -783,42 +1210,39 @@ fn compile_stmts<'a>( initializer, .. } => { - let pattern = Box::new(crate::thir_pattern::compile_pattern(env, pattern)); + let pattern = crate::thir_pattern::compile_pattern(env, pattern); let init = match initializer { Some(initializer) => compile_expr(env, thir, initializer), None => Expr::tt(), }; - let (init, body) = if matches!(pattern.as_ref(), Pattern::Variable(_)) { - (init.copy(), body) - } else { - ( - init.read(), - allocate_bindings_in_pattern(pattern.as_ref(), body), - ) - }; let ty = body.ty.clone(); - Expr { - kind: ExprKind::Let { + let kind = match pattern.as_ref() { + Pattern::Binding { + name, + pattern: None, + .. + } => Rc::new(ExprKind::Let { is_monadic: false, - pattern, - init: Box::new(init), + name: Some(name.clone()), + init: init.copy(), body, - }, - ty, - } + }), + _ => build_match(init, vec![MatchArm { pattern, body }], ty.clone()), + }; + Rc::new(Expr { kind, ty }) } thir::StmtKind::Expr { expr: expr_id, .. } => { - let init = Box::new(compile_expr(env, thir, expr_id)); + let init = compile_expr(env, thir, expr_id); let ty = body.ty.clone(); - Expr { - kind: ExprKind::Let { + Rc::new(Expr { + kind: Rc::new(ExprKind::Let { is_monadic: false, - pattern: Box::new(Pattern::Wild), + name: None, init, body, - }, + }), ty, - } + }) } } }, @@ -829,7 +1253,7 @@ fn compile_block<'a>( env: &mut Env<'a>, thir: &rustc_middle::thir::Thir<'a>, block_id: &rustc_middle::thir::BlockId, -) -> Expr { +) -> Rc { let block = thir.blocks.get(*block_id).unwrap(); compile_stmts(env, thir, &block.stmts, block.expr) } diff --git a/lib/src/thir_pattern.rs b/lib/src/thir_pattern.rs index 337a928bf..063d5f96c 100644 --- a/lib/src/thir_pattern.rs +++ b/lib/src/thir_pattern.rs @@ -3,6 +3,7 @@ use crate::path::*; use crate::pattern::*; use rustc_middle::thir::{Pat, PatKind}; use rustc_type_ir::sty::TyKind; +use std::rc::Rc; // fn const_to_lit_kind(constant: rustc_middle::mir::ConstantKind) -> rustc_ast::LitKind { // match constant { @@ -23,20 +24,31 @@ use rustc_type_ir::sty::TyKind; // panic!("constant {:#?} not yet handled", constant); // } -pub(crate) fn compile_pattern(env: &Env, pat: &Pat) -> Pattern { +pub(crate) fn compile_pattern(env: &Env, pat: &Pat) -> Rc { match &pat.kind { - PatKind::Wild => Pattern::Wild, + PatKind::Wild => Rc::new(Pattern::Wild), PatKind::AscribeUserType { subpattern, .. } => compile_pattern(env, subpattern), PatKind::Binding { - name, subpattern, .. + name, + mode, + subpattern, + .. } => { let name = name.to_string(); - match subpattern { - None => Pattern::Variable(name), - Some(subpattern) => { - Pattern::Binding(name, Box::new(compile_pattern(env, subpattern))) + let is_with_ref = match mode { + rustc_middle::thir::BindingMode::ByValue => None, + rustc_middle::thir::BindingMode::ByRef(borrow_kind) => { + Some(crate::thir_expression::is_mutable_borrow_kind(borrow_kind)) } - } + }; + let pattern = subpattern + .as_ref() + .map(|subpattern| compile_pattern(env, subpattern)); + Rc::new(Pattern::Binding { + name, + is_with_ref, + pattern, + }) } PatKind::Variant { adt_def, @@ -64,19 +76,19 @@ pub(crate) fn compile_pattern(env: &Env, pat: &Pat) -> Pattern { .all(|(name, _)| name.starts_with(|c: char| c.is_ascii_digit())); if is_a_tuple { let fields = fields.into_iter().map(|(_, pattern)| pattern).collect(); - Pattern::StructTuple(path, fields, struct_or_variant) + Rc::new(Pattern::StructTuple(path, fields, struct_or_variant)) } else { - Pattern::StructStruct(path, fields, struct_or_variant) + Rc::new(Pattern::StructStruct(path, fields, struct_or_variant)) } } PatKind::Leaf { subpatterns } => { if let TyKind::Tuple(_) = pat.ty.kind() { - return Pattern::Tuple( + return Rc::new(Pattern::Tuple( subpatterns .iter() .map(|field| compile_pattern(env, &field.pattern)) .collect(), - ); + )); } let adt_def = pat.ty.ty_adt_def().unwrap(); let path = compile_def_id(env, adt_def.did()); @@ -96,12 +108,12 @@ pub(crate) fn compile_pattern(env: &Env, pat: &Pat) -> Pattern { .all(|(name, _)| name.starts_with(|c: char| c.is_ascii_digit())); if is_a_tuple { let fields = fields.into_iter().map(|(_, pattern)| pattern).collect(); - Pattern::StructTuple(path, fields, struct_or_variant) + Rc::new(Pattern::StructTuple(path, fields, struct_or_variant)) } else { - Pattern::StructStruct(path, fields, struct_or_variant) + Rc::new(Pattern::StructStruct(path, fields, struct_or_variant)) } } - PatKind::Deref { subpattern } => compile_pattern(env, subpattern), + PatKind::Deref { subpattern } => Rc::new(Pattern::Deref(compile_pattern(env, subpattern))), // PatKind::Constant { value } => { // let literal = const_to_lit_kind(*value); // Pattern::Lit(literal) @@ -111,14 +123,14 @@ pub(crate) fn compile_pattern(env: &Env, pat: &Pat) -> Pattern { .sess .struct_span_warn(pat.span, "Constants in patterns are not yet supported.") .emit(); - Pattern::Wild + Rc::new(Pattern::Wild) } PatKind::Range(_) => { env.tcx .sess .struct_span_warn(pat.span, "Ranges in patterns are not yet supported.") .emit(); - Pattern::Wild + Rc::new(Pattern::Wild) } PatKind::Slice { prefix, @@ -130,16 +142,18 @@ pub(crate) fn compile_pattern(env: &Env, pat: &Pat) -> Pattern { slice, suffix, } => { - let prefix: Vec = prefix.iter().map(|pat| compile_pattern(env, pat)).collect(); - let suffix: Vec = suffix.iter().map(|pat| compile_pattern(env, pat)).collect(); + let prefix: Vec> = + prefix.iter().map(|pat| compile_pattern(env, pat)).collect(); + let suffix: Vec> = + suffix.iter().map(|pat| compile_pattern(env, pat)).collect(); match slice { Some(pat_middle) => { if suffix.is_empty() { let pat_middle = compile_pattern(env, pat_middle); - Pattern::Slice { + Rc::new(Pattern::Slice { init_patterns: prefix, - slice_pattern: Some(Box::new(pat_middle)), - } + slice_pattern: Some(pat_middle), + }) } else { env.tcx .sess @@ -149,20 +163,20 @@ pub(crate) fn compile_pattern(env: &Env, pat: &Pat) -> Pattern { ) .help("Reverse the slice instead.") .emit(); - Pattern::Wild + Rc::new(Pattern::Wild) } } None => { let all_patterns = [prefix, suffix].concat().to_vec(); - Pattern::Slice { + Rc::new(Pattern::Slice { init_patterns: all_patterns, slice_pattern: None, - } + }) } } } - PatKind::Or { pats } => { - Pattern::Or(pats.iter().map(|pat| compile_pattern(env, pat)).collect()) - } + PatKind::Or { pats } => Rc::new(Pattern::Or( + pats.iter().map(|pat| compile_pattern(env, pat)).collect(), + )), } } diff --git a/lib/src/thir_ty.rs b/lib/src/thir_ty.rs index cef023434..d7f4a9ae9 100644 --- a/lib/src/thir_ty.rs +++ b/lib/src/thir_ty.rs @@ -32,7 +32,7 @@ pub(crate) fn compile_type<'a>(env: &Env<'a>, ty: &rustc_middle::ty::Ty<'a>) -> .collect(); Rc::new(CoqType::Application { func: Rc::new(CoqType::Path { - path: Box::new(path.suffix_last_with_dot_t()), + path: Rc::new(path.suffix_last_with_dot_t()), }), args, is_alias: false, diff --git a/lib/src/top_level.rs b/lib/src/top_level.rs index 297f73a7e..3de2b24c8 100644 --- a/lib/src/top_level.rs +++ b/lib/src/top_level.rs @@ -4,7 +4,6 @@ use crate::env::*; use crate::expression::*; use crate::header::*; use crate::path::*; -use crate::pattern::*; use crate::render::*; use crate::reorder::*; use crate::ty::*; @@ -40,7 +39,7 @@ struct HirFnSigAndBody<'a> { struct FnSigAndBody { args: Vec<(String, Rc)>, ret_ty: Rc, - body: Option>, + body: Option>, } #[derive(Debug, Eq, Hash, PartialEq)] @@ -71,7 +70,7 @@ struct FunDefinition { enum ImplItemKind { Const { ty: Rc, - body: Option>, + body: Option>, is_dead_code: bool, }, Definition { @@ -137,7 +136,7 @@ enum TopLevelItem { Const { name: String, ty: Rc, - value: Option>, + value: Option>, }, Definition { name: String, @@ -392,7 +391,7 @@ fn compile_top_level_item(tcx: &TyCtxt, env: &mut Env, item: &Item) -> Vec)], body: &rustc_hir::Body, ret_ty: Rc, -) -> Option> { +) -> Option> { if env.axiomatize { return None; } let body = compile_hir_id(env, body.value.hir_id).read(); let has_return = body.has_return(); let body = if has_return { - Box::new(Expr { - kind: ExprKind::Let { + Rc::new(Expr { + kind: Rc::new(ExprKind::Let { is_monadic: false, - pattern: Box::new(Pattern::Variable("return_".to_string())), - init: Box::new(Expr { - kind: ExprKind::VarWithTy { + name: Some("return_".to_string()), + init: Rc::new(Expr { + kind: Rc::new(ExprKind::VarWithTy { path: Path::local("M.return_"), ty_name: "R".to_string(), ty: ret_ty, - }, + }), ty: None, }), - body: Box::new(Expr { - kind: ExprKind::MonadicOperator { + body: Rc::new(Expr { + kind: Rc::new(ExprKind::MonadicOperator { name: "M.catch_return".to_string(), - arg: Box::new(body), - }, + arg: body, + }), ty: None, }), - }, + }), ty: None, }) } else { - Box::new(body) + body }; let body = crate::thir_expression::allocate_bindings( &args @@ -1073,8 +1072,9 @@ fn mt_impl_item(item: Rc) -> Rc { let body = match body { None => body.clone(), Some(body) => { - let body = mt_expression(FreshVars::new(), *body.clone()).0; - Some(Box::new(body)) + let body = mt_expression(FreshVars::new(), body.clone()).0; + + Some(body) } }; Rc::new(ImplItemKind::Const { @@ -1098,8 +1098,8 @@ impl FnSigAndBody { body: match &self.body { None => self.body.clone(), Some(body) => { - let (body, _fresh_vars) = mt_expression(FreshVars::new(), *body.clone()); - Some(Box::new(body)) + let (body, _fresh_vars) = mt_expression(FreshVars::new(), body.clone()); + Some(body) } }, }) @@ -1145,8 +1145,8 @@ fn mt_top_level_item(item: Rc) -> Rc { value: match value { None => value.clone(), Some(value) => { - let (value, _fresh_vars) = mt_expression(FreshVars::new(), *value.clone()); - Some(Box::new(value)) + let (value, _fresh_vars) = mt_expression(FreshVars::new(), value.clone()); + Some(value) } }, }), @@ -1429,7 +1429,7 @@ impl FunDefinition { .collect::>(), ] .concat(), - image: Box::new(coq::Expression::Unit), + image: Rc::new(coq::Expression::Unit), }, }, )) @@ -1473,7 +1473,7 @@ impl FunDefinition { ), ] .concat(), - image: Box::new( + image: Rc::new( // return type ret_ty // argument types @@ -1693,7 +1693,7 @@ impl TraitBound { fn to_coq<'a>(&self, self_ty: coq::Expression<'a>) -> coq::Expression<'a> { coq::Expression::Application { - func: Box::new( + func: Rc::new( coq::Expression::Variable { ident: Path::concat(&[self.name.to_owned(), Path::new(&["Trait"])]), no_implicit: false, @@ -2451,9 +2451,9 @@ fn struct_field_value<'a>(name: String) -> coq::Expression<'a> { coq::Expression::just_name("Ref.map").apply_many(&[ coq::Expression::Function { parameters: vec![coq::Expression::just_name("α")], - body: Box::new(coq::Expression::just_name("Some").apply( + body: Rc::new(coq::Expression::just_name("Some").apply( &coq::Expression::RecordField { - record: Box::new(coq::Expression::just_name("α")), + record: Rc::new(coq::Expression::just_name("α")), field: name.to_owned(), }, )), @@ -2463,11 +2463,11 @@ fn struct_field_value<'a>(name: String) -> coq::Expression<'a> { coq::Expression::just_name("β"), coq::Expression::just_name("α"), ], - body: Box::new(coq::Expression::just_name("Some").apply( + body: Rc::new(coq::Expression::just_name("Some").apply( &coq::Expression::RecordUpdate { - record: Box::new(coq::Expression::just_name("α")), + record: Rc::new(coq::Expression::just_name("α")), field: name, - update: Box::new(coq::Expression::just_name("β")), + update: Rc::new(coq::Expression::just_name("β")), }, )), }, @@ -2488,14 +2488,14 @@ fn enum_struct_field_value<'a>( coq::Expression::just_name("Ref.map").apply_many(&[ coq::Expression::Function { parameters: vec![coq::Expression::just_name("α")], - body: Box::new(coq::Expression::Match { - scrutinee: Box::new(coq::Expression::just_name("α")), + body: Rc::new(coq::Expression::Match { + scrutinee: Rc::new(coq::Expression::just_name("α")), arms: [ vec![( coq::Expression::just_name(constructor_name) .apply(&coq::Expression::just_name("α")), coq::Expression::just_name("Some").apply(&coq::Expression::RecordField { - record: Box::new(coq::Expression::just_name("α")), + record: Rc::new(coq::Expression::just_name("α")), field: format!("{constructor_name}.{field_name}"), }), )], @@ -2509,8 +2509,8 @@ fn enum_struct_field_value<'a>( coq::Expression::just_name("β"), coq::Expression::just_name("α"), ], - body: Box::new(coq::Expression::Match { - scrutinee: Box::new(coq::Expression::just_name("α")), + body: Rc::new(coq::Expression::Match { + scrutinee: Rc::new(coq::Expression::just_name("α")), arms: [ vec![( coq::Expression::just_name(constructor_name) @@ -2518,9 +2518,9 @@ fn enum_struct_field_value<'a>( coq::Expression::just_name("Some").apply( &coq::Expression::just_name(constructor_name).apply( &coq::Expression::RecordUpdate { - record: Box::new(coq::Expression::just_name("α")), + record: Rc::new(coq::Expression::just_name("α")), field: format!("{constructor_name}.{field_name}"), - update: Box::new(coq::Expression::just_name("β")), + update: Rc::new(coq::Expression::just_name("β")), }, ), ), @@ -2548,8 +2548,8 @@ fn enum_tuple_field_value( coq::Expression::just_name("Ref.map").apply_many(&[ coq::Expression::Function { parameters: vec![coq::Expression::just_name("α")], - body: Box::new(coq::Expression::Match { - scrutinee: Box::new(coq::Expression::just_name("α")), + body: Rc::new(coq::Expression::Match { + scrutinee: Rc::new(coq::Expression::just_name("α")), arms: [ vec![( coq::Expression::just_name(constructor_name).apply_many( @@ -2576,8 +2576,8 @@ fn enum_tuple_field_value( coq::Expression::just_name("β"), coq::Expression::just_name("α"), ], - body: Box::new(coq::Expression::Match { - scrutinee: Box::new(coq::Expression::just_name("α")), + body: Rc::new(coq::Expression::Match { + scrutinee: Rc::new(coq::Expression::just_name("α")), arms: [ vec![( coq::Expression::just_name(constructor_name).apply_many( @@ -2755,7 +2755,7 @@ impl TypeStructStruct { // .collect() // ] // .concat(), - // image: Box::new( + // image: Rc::new( // coq::Expression::just_name("t") // .arrows_from(&[ // coq::Expression::just_name("A"), @@ -2847,7 +2847,7 @@ impl TypeStructStruct { ]), &[struct_projection_pattern()], &coq::Expression::NotationsDot { - value: Box::new( + value: Rc::new( coq::Expression::just_name("α"), ), field: name.to_owned(), diff --git a/lib/src/ty.rs b/lib/src/ty.rs index b72828d17..2ec921f10 100644 --- a/lib/src/ty.rs +++ b/lib/src/ty.rs @@ -12,10 +12,10 @@ use std::rc::Rc; pub(crate) enum CoqType { Var(String), Path { - path: Box, + path: Rc, }, PathInTrait { - path: Box, + path: Rc, self_ty: Rc, }, Application { @@ -44,7 +44,7 @@ impl CoqType { pub(crate) fn path(segments: &[&str]) -> Rc { Rc::new(CoqType::Path { - path: Box::new(Path::new(segments)), + path: Rc::new(Path::new(segments)), }) } @@ -72,7 +72,7 @@ impl CoqType { } = &*self { if let CoqType::Path { path, .. } = &**func { - let Path { segments } = *path.clone(); + let Path { segments } = path.as_ref(); if segments.len() == 1 && args.len() == 1 { let name = segments.first().unwrap(); if name == "ref" || name == "mut_ref" { @@ -179,13 +179,13 @@ pub(crate) fn compile_type(env: &Env, ty: &Ty) -> Rc { let coq_path = compile_qpath(env, qpath); let func = Rc::new(match self_ty { Some(self_ty) => CoqType::PathInTrait { - path: Box::new(coq_path.clone()), + path: Rc::new(coq_path.clone()), self_ty, }, None => match is_variable { Some(name) => CoqType::Var(name), None => CoqType::Path { - path: Box::new(if is_alias { + path: Rc::new(if is_alias { coq_path.clone() } else { coq_path.suffix_last_with_dot_t() @@ -212,7 +212,7 @@ pub(crate) fn compile_type(env: &Env, ty: &Ty) -> Rc { segments.push("Default".to_string()); segments.push(name); Rc::new(CoqType::Path { - path: Box::new(Path { segments }), + path: Rc::new(Path { segments }), }) } else { Rc::new(CoqType::Infer) @@ -362,11 +362,11 @@ impl CoqType { no_implicit: false, }, CoqType::Path { path } => coq::Expression::Variable { - ident: *path.clone(), + ident: path.as_ref().clone(), no_implicit: false, }, CoqType::PathInTrait { path, self_ty } => coq::Expression::Variable { - ident: *path.clone(), + ident: path.as_ref().clone(), no_implicit: false, } .apply_many_args(&[ @@ -387,7 +387,7 @@ impl CoqType { if *is_alias { coq::Expression::ModeWrapper { mode: "ltac".to_string(), - expr: Box::new(application), + expr: Rc::new(application), } } else { application