From 87d6f6c7c90bf7b427397d6bd2e2c70d610678e3 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Tue, 4 Jul 2023 14:57:51 +0200 Subject: Reorganize the Lean tests --- tests/lean/External/Funs.lean | 88 +++++++++++++++++++++++++++++++++++++++++ tests/lean/External/Opaque.lean | 28 +++++++++++++ tests/lean/External/Types.lean | 11 ++++++ 3 files changed, 127 insertions(+) create mode 100644 tests/lean/External/Funs.lean create mode 100644 tests/lean/External/Opaque.lean create mode 100644 tests/lean/External/Types.lean (limited to 'tests/lean/External') diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean new file mode 100644 index 00000000..73e45938 --- /dev/null +++ b/tests/lean/External/Funs.lean @@ -0,0 +1,88 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [external]: function definitions +import Base +import External.Types +import External.ExternalFuns +open Primitives + +/- [external::swap] -/ +def swap_fwd + (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := + do + let (st0, _) ← opaque_defs.core_mem_swap_fwd T x y st + let (st1, _) ← opaque_defs.core_mem_swap_back0 T x y st st0 + let (st2, _) ← opaque_defs.core_mem_swap_back1 T x y st st1 + Result.ret (st2, ()) + +/- [external::swap] -/ +def swap_back + (T : Type) (x : T) (y : T) (st : State) (st0 : State) : + Result (State × (T × T)) + := + do + let (st1, _) ← opaque_defs.core_mem_swap_fwd T x y st + let (st2, x0) ← opaque_defs.core_mem_swap_back0 T x y st st1 + let (_, y0) ← opaque_defs.core_mem_swap_back1 T x y st st2 + Result.ret (st0, (x0, y0)) + +/- [external::test_new_non_zero_u32] -/ +def test_new_non_zero_u32_fwd + (x : U32) (st : State) : Result (State × core_num_nonzero_non_zero_u32_t) := + do + let (st0, opt) ← opaque_defs.core_num_nonzero_non_zero_u32_new_fwd x st + opaque_defs.core_option_option_unwrap_fwd core_num_nonzero_non_zero_u32_t + opt st0 + +/- [external::test_vec] -/ +def test_vec_fwd : Result Unit := + do + let v := vec_new U32 + let _ ← vec_push_back U32 v (U32.ofInt 0 (by intlit)) + Result.ret () + +/- Unit test for [external::test_vec] -/ +#assert (test_vec_fwd == .ret ()) + +/- [external::custom_swap] -/ +def custom_swap_fwd + (T : Type) (x : T) (y : T) (st : State) : Result (State × T) := + do + let (st0, _) ← opaque_defs.core_mem_swap_fwd T x y st + let (st1, x0) ← opaque_defs.core_mem_swap_back0 T x y st st0 + let (st2, _) ← opaque_defs.core_mem_swap_back1 T x y st st1 + Result.ret (st2, x0) + +/- [external::custom_swap] -/ +def custom_swap_back + (T : Type) (x : T) (y : T) (st : State) (ret0 : T) (st0 : State) : + Result (State × (T × T)) + := + do + let (st1, _) ← opaque_defs.core_mem_swap_fwd T x y st + let (st2, _) ← opaque_defs.core_mem_swap_back0 T x y st st1 + let (_, y0) ← opaque_defs.core_mem_swap_back1 T x y st st2 + Result.ret (st0, (ret0, y0)) + +/- [external::test_custom_swap] -/ +def test_custom_swap_fwd + (x : U32) (y : U32) (st : State) : Result (State × Unit) := + do + let (st0, _) ← custom_swap_fwd U32 x y st + Result.ret (st0, ()) + +/- [external::test_custom_swap] -/ +def test_custom_swap_back + (x : U32) (y : U32) (st : State) (st0 : State) : + Result (State × (U32 × U32)) + := + custom_swap_back U32 x y st (U32.ofInt 1 (by intlit)) st0 + +/- [external::test_swap_non_zero] -/ +def test_swap_non_zero_fwd (x : U32) (st : State) : Result (State × U32) := + do + let (st0, _) ← swap_fwd U32 x (U32.ofInt 0 (by intlit)) st + let (st1, (x0, _)) ← swap_back U32 x (U32.ofInt 0 (by intlit)) st st0 + if x0 = (U32.ofInt 0 (by intlit)) + then Result.fail Error.panic + else Result.ret (st1, x0) + diff --git a/tests/lean/External/Opaque.lean b/tests/lean/External/Opaque.lean new file mode 100644 index 00000000..5483c3a9 --- /dev/null +++ b/tests/lean/External/Opaque.lean @@ -0,0 +1,28 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [external]: opaque function definitions +import Base +import External.Types +open Primitives + +structure OpaqueDefs where + + /- [core::mem::swap] -/ + core_mem_swap_fwd (T : Type) : T -> T -> State -> Result (State × Unit) + + /- [core::mem::swap] -/ + core_mem_swap_back0 + (T : Type) : T -> T -> State -> State -> Result (State × T) + + /- [core::mem::swap] -/ + core_mem_swap_back1 + (T : Type) : T -> T -> State -> State -> Result (State × T) + + /- [core::num::nonzero::NonZeroU32::{14}::new] -/ + core_num_nonzero_non_zero_u32_new_fwd + : + U32 -> State -> Result (State × (Option core_num_nonzero_non_zero_u32_t)) + + /- [core::option::Option::{0}::unwrap] -/ + core_option_option_unwrap_fwd + (T : Type) : Option T -> State -> Result (State × T) + diff --git a/tests/lean/External/Types.lean b/tests/lean/External/Types.lean new file mode 100644 index 00000000..25907da2 --- /dev/null +++ b/tests/lean/External/Types.lean @@ -0,0 +1,11 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [external]: type definitions +import Base +open Primitives + +/- [core::num::nonzero::NonZeroU32] -/ +axiom core_num_nonzero_non_zero_u32_t : Type + +/- The state type used in the state-error monad -/ +axiom State : Type + -- cgit v1.2.3 From b643bd00747e75d69b6066c55a1798b61277c4b6 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Tue, 4 Jul 2023 18:09:36 +0200 Subject: Regenerate the Lean test files --- tests/lean/External/ExternalFuns.lean | 9 +++++++++ tests/lean/External/Funs.lean | 3 +++ tests/lean/External/Opaque.lean | 14 +++++++++----- tests/lean/External/Types.lean | 3 +++ 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 tests/lean/External/ExternalFuns.lean (limited to 'tests/lean/External') diff --git a/tests/lean/External/ExternalFuns.lean b/tests/lean/External/ExternalFuns.lean new file mode 100644 index 00000000..d63db2ac --- /dev/null +++ b/tests/lean/External/ExternalFuns.lean @@ -0,0 +1,9 @@ +import Base +import External.Types +import External.Opaque + +namespace External + +def opaque_defs : OpaqueDefs := sorry + +end External diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean index 73e45938..e36987e0 100644 --- a/tests/lean/External/Funs.lean +++ b/tests/lean/External/Funs.lean @@ -5,6 +5,8 @@ import External.Types import External.ExternalFuns open Primitives +namespace External + /- [external::swap] -/ def swap_fwd (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := @@ -86,3 +88,4 @@ def test_swap_non_zero_fwd (x : U32) (st : State) : Result (State × U32) := then Result.fail Error.panic else Result.ret (st1, x0) +end External diff --git a/tests/lean/External/Opaque.lean b/tests/lean/External/Opaque.lean index 5483c3a9..1c0db095 100644 --- a/tests/lean/External/Opaque.lean +++ b/tests/lean/External/Opaque.lean @@ -4,25 +4,29 @@ import Base import External.Types open Primitives +namespace External + structure OpaqueDefs where /- [core::mem::swap] -/ - core_mem_swap_fwd (T : Type) : T -> T -> State -> Result (State × Unit) + core_mem_swap_fwd (T : Type) : T → T → State → Result (State × Unit) /- [core::mem::swap] -/ core_mem_swap_back0 - (T : Type) : T -> T -> State -> State -> Result (State × T) + (T : Type) : T → T → State → State → Result (State × T) /- [core::mem::swap] -/ core_mem_swap_back1 - (T : Type) : T -> T -> State -> State -> Result (State × T) + (T : Type) : T → T → State → State → Result (State × T) /- [core::num::nonzero::NonZeroU32::{14}::new] -/ core_num_nonzero_non_zero_u32_new_fwd : - U32 -> State -> Result (State × (Option core_num_nonzero_non_zero_u32_t)) + U32 → State → Result (State × (Option + core_num_nonzero_non_zero_u32_t)) /- [core::option::Option::{0}::unwrap] -/ core_option_option_unwrap_fwd - (T : Type) : Option T -> State -> Result (State × T) + (T : Type) : Option T → State → Result (State × T) +end External diff --git a/tests/lean/External/Types.lean b/tests/lean/External/Types.lean index 25907da2..fda0670e 100644 --- a/tests/lean/External/Types.lean +++ b/tests/lean/External/Types.lean @@ -3,9 +3,12 @@ import Base open Primitives +namespace External + /- [core::num::nonzero::NonZeroU32] -/ axiom core_num_nonzero_non_zero_u32_t : Type /- The state type used in the state-error monad -/ axiom State : Type +end External -- cgit v1.2.3 From 0a0445c72e005c328b4764f5fb0f8f38e7a55d60 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Wed, 5 Jul 2023 14:52:23 +0200 Subject: Start using namespaces in the Lean backend --- tests/lean/External/ExternalFuns.lean | 9 ------- tests/lean/External/Funs.lean | 36 ++++++++++++-------------- tests/lean/External/FunsExternal.lean | 33 +++++++++++++++++++++++ tests/lean/External/FunsExternal_Template.lean | 29 +++++++++++++++++++++ tests/lean/External/Opaque.lean | 14 +++++----- tests/lean/External/Types.lean | 5 ++-- 6 files changed, 88 insertions(+), 38 deletions(-) delete mode 100644 tests/lean/External/ExternalFuns.lean create mode 100644 tests/lean/External/FunsExternal.lean create mode 100644 tests/lean/External/FunsExternal_Template.lean (limited to 'tests/lean/External') diff --git a/tests/lean/External/ExternalFuns.lean b/tests/lean/External/ExternalFuns.lean deleted file mode 100644 index d63db2ac..00000000 --- a/tests/lean/External/ExternalFuns.lean +++ /dev/null @@ -1,9 +0,0 @@ -import Base -import External.Types -import External.Opaque - -namespace External - -def opaque_defs : OpaqueDefs := sorry - -end External diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean index e36987e0..6bfffc33 100644 --- a/tests/lean/External/Funs.lean +++ b/tests/lean/External/Funs.lean @@ -2,18 +2,17 @@ -- [external]: function definitions import Base import External.Types -import External.ExternalFuns +import External.FunsExternal open Primitives - -namespace External +namespace external /- [external::swap] -/ def swap_fwd (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := do - let (st0, _) ← opaque_defs.core_mem_swap_fwd T x y st - let (st1, _) ← opaque_defs.core_mem_swap_back0 T x y st st0 - let (st2, _) ← opaque_defs.core_mem_swap_back1 T x y st st1 + let (st0, _) ← core.mem.swap_fwd T x y st + let (st1, _) ← core.mem.swap_back0 T x y st st0 + let (st2, _) ← core.mem.swap_back1 T x y st st1 Result.ret (st2, ()) /- [external::swap] -/ @@ -22,18 +21,17 @@ def swap_back Result (State × (T × T)) := do - let (st1, _) ← opaque_defs.core_mem_swap_fwd T x y st - let (st2, x0) ← opaque_defs.core_mem_swap_back0 T x y st st1 - let (_, y0) ← opaque_defs.core_mem_swap_back1 T x y st st2 + let (st1, _) ← core.mem.swap_fwd T x y st + let (st2, x0) ← core.mem.swap_back0 T x y st st1 + let (_, y0) ← core.mem.swap_back1 T x y st st2 Result.ret (st0, (x0, y0)) /- [external::test_new_non_zero_u32] -/ def test_new_non_zero_u32_fwd (x : U32) (st : State) : Result (State × core_num_nonzero_non_zero_u32_t) := do - let (st0, opt) ← opaque_defs.core_num_nonzero_non_zero_u32_new_fwd x st - opaque_defs.core_option_option_unwrap_fwd core_num_nonzero_non_zero_u32_t - opt st0 + let (st0, opt) ← core.num.nonzero.NonZeroU32.new_fwd x st + core.option.Option.unwrap_fwd core_num_nonzero_non_zero_u32_t opt st0 /- [external::test_vec] -/ def test_vec_fwd : Result Unit := @@ -49,9 +47,9 @@ def test_vec_fwd : Result Unit := def custom_swap_fwd (T : Type) (x : T) (y : T) (st : State) : Result (State × T) := do - let (st0, _) ← opaque_defs.core_mem_swap_fwd T x y st - let (st1, x0) ← opaque_defs.core_mem_swap_back0 T x y st st0 - let (st2, _) ← opaque_defs.core_mem_swap_back1 T x y st st1 + let (st0, _) ← core.mem.swap_fwd T x y st + let (st1, x0) ← core.mem.swap_back0 T x y st st0 + let (st2, _) ← core.mem.swap_back1 T x y st st1 Result.ret (st2, x0) /- [external::custom_swap] -/ @@ -60,9 +58,9 @@ def custom_swap_back Result (State × (T × T)) := do - let (st1, _) ← opaque_defs.core_mem_swap_fwd T x y st - let (st2, _) ← opaque_defs.core_mem_swap_back0 T x y st st1 - let (_, y0) ← opaque_defs.core_mem_swap_back1 T x y st st2 + let (st1, _) ← core.mem.swap_fwd T x y st + let (st2, _) ← core.mem.swap_back0 T x y st st1 + let (_, y0) ← core.mem.swap_back1 T x y st st2 Result.ret (st0, (ret0, y0)) /- [external::test_custom_swap] -/ @@ -88,4 +86,4 @@ def test_swap_non_zero_fwd (x : U32) (st : State) : Result (State × U32) := then Result.fail Error.panic else Result.ret (st1, x0) -end External +end external diff --git a/tests/lean/External/FunsExternal.lean b/tests/lean/External/FunsExternal.lean new file mode 100644 index 00000000..5326dd77 --- /dev/null +++ b/tests/lean/External/FunsExternal.lean @@ -0,0 +1,33 @@ +-- [external]: templates for the external functions. +import Base +import External.Types +open Primitives +open external + +-- TODO: fill those bodies + +/- [core::mem::swap] -/ +def core.mem.swap_fwd + (T : Type) : T → T → State → Result (State × Unit) := + fun _x _y s => .ret (s, ()) + +/- [core::mem::swap] -/ +def core.mem.swap_back0 + (T : Type) : T → T → State → State → Result (State × T) := + fun _x y _s0 s1 => .ret (s1, y) + +/- [core::mem::swap] -/ +def core.mem.swap_back1 + (T : Type) : T → T → State → State → Result (State × T) := + fun x _y _s0 s1 => .ret (s1, x) + +/- [core::num::nonzero::NonZeroU32::{14}::new] -/ +def core.num.nonzero.NonZeroU32.new_fwd + : + U32 → State → Result (State × (Option core_num_nonzero_non_zero_u32_t)) := + fun _ _ => .fail .panic + +/- [core::option::Option::{0}::unwrap] -/ +def core.option.Option.unwrap_fwd + (T : Type) : Option T → State → Result (State × T) := + fun _ _ => .fail .panic diff --git a/tests/lean/External/FunsExternal_Template.lean b/tests/lean/External/FunsExternal_Template.lean new file mode 100644 index 00000000..d6c0eb1d --- /dev/null +++ b/tests/lean/External/FunsExternal_Template.lean @@ -0,0 +1,29 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [external]: external functions. +-- This is a template file: rename it to "FunsExternal.lean" and fill the holes. +import Base +import External.Types +open Primitives +open external + +/- [core::mem::swap] -/ +axiom core.mem.swap_fwd + (T : Type) : T → T → State → Result (State × Unit) + +/- [core::mem::swap] -/ +axiom core.mem.swap_back0 + (T : Type) : T → T → State → State → Result (State × T) + +/- [core::mem::swap] -/ +axiom core.mem.swap_back1 + (T : Type) : T → T → State → State → Result (State × T) + +/- [core::num::nonzero::NonZeroU32::{14}::new] -/ +axiom core.num.nonzero.NonZeroU32.new_fwd + : + U32 → State → Result (State × (Option core_num_nonzero_non_zero_u32_t)) + +/- [core::option::Option::{0}::unwrap] -/ +axiom core.option.Option.unwrap_fwd + (T : Type) : Option T → State → Result (State × T) + diff --git a/tests/lean/External/Opaque.lean b/tests/lean/External/Opaque.lean index 1c0db095..d0297523 100644 --- a/tests/lean/External/Opaque.lean +++ b/tests/lean/External/Opaque.lean @@ -4,29 +4,29 @@ import Base import External.Types open Primitives -namespace External +namespace external structure OpaqueDefs where /- [core::mem::swap] -/ - core_mem_swap_fwd (T : Type) : T → T → State → Result (State × Unit) + core.mem.swap_fwd (T : Type) : T → T → State → Result (State × Unit) /- [core::mem::swap] -/ - core_mem_swap_back0 + core.mem.swap_back0 (T : Type) : T → T → State → State → Result (State × T) /- [core::mem::swap] -/ - core_mem_swap_back1 + core.mem.swap_back1 (T : Type) : T → T → State → State → Result (State × T) /- [core::num::nonzero::NonZeroU32::{14}::new] -/ - core_num_nonzero_non_zero_u32_new_fwd + core.num.nonzero.NonZeroU32.new_fwd : U32 → State → Result (State × (Option core_num_nonzero_non_zero_u32_t)) /- [core::option::Option::{0}::unwrap] -/ - core_option_option_unwrap_fwd + core.option.Option.unwrap_fwd (T : Type) : Option T → State → Result (State × T) -end External +end external diff --git a/tests/lean/External/Types.lean b/tests/lean/External/Types.lean index fda0670e..316f6474 100644 --- a/tests/lean/External/Types.lean +++ b/tests/lean/External/Types.lean @@ -2,8 +2,7 @@ -- [external]: type definitions import Base open Primitives - -namespace External +namespace external /- [core::num::nonzero::NonZeroU32] -/ axiom core_num_nonzero_non_zero_u32_t : Type @@ -11,4 +10,4 @@ axiom core_num_nonzero_non_zero_u32_t : Type /- The state type used in the state-error monad -/ axiom State : Type -end External +end external -- cgit v1.2.3 From c07721dedb2cfe4c726c42606e623395cdfe5b80 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Wed, 5 Jul 2023 15:09:07 +0200 Subject: Simplify the generated names for the types in Lean --- tests/lean/External/Funs.lean | 4 ++-- tests/lean/External/FunsExternal_Template.lean | 3 +-- tests/lean/External/Types.lean | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'tests/lean/External') diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean index 6bfffc33..10efc3db 100644 --- a/tests/lean/External/Funs.lean +++ b/tests/lean/External/Funs.lean @@ -28,10 +28,10 @@ def swap_back /- [external::test_new_non_zero_u32] -/ def test_new_non_zero_u32_fwd - (x : U32) (st : State) : Result (State × core_num_nonzero_non_zero_u32_t) := + (x : U32) (st : State) : Result (State × core.num.nonzero.NonZeroU32) := do let (st0, opt) ← core.num.nonzero.NonZeroU32.new_fwd x st - core.option.Option.unwrap_fwd core_num_nonzero_non_zero_u32_t opt st0 + core.option.Option.unwrap_fwd core.num.nonzero.NonZeroU32 opt st0 /- [external::test_vec] -/ def test_vec_fwd : Result Unit := diff --git a/tests/lean/External/FunsExternal_Template.lean b/tests/lean/External/FunsExternal_Template.lean index d6c0eb1d..669fe91b 100644 --- a/tests/lean/External/FunsExternal_Template.lean +++ b/tests/lean/External/FunsExternal_Template.lean @@ -20,8 +20,7 @@ axiom core.mem.swap_back1 /- [core::num::nonzero::NonZeroU32::{14}::new] -/ axiom core.num.nonzero.NonZeroU32.new_fwd - : - U32 → State → Result (State × (Option core_num_nonzero_non_zero_u32_t)) + : U32 → State → Result (State × (Option core.num.nonzero.NonZeroU32)) /- [core::option::Option::{0}::unwrap] -/ axiom core.option.Option.unwrap_fwd diff --git a/tests/lean/External/Types.lean b/tests/lean/External/Types.lean index 316f6474..ba984e2a 100644 --- a/tests/lean/External/Types.lean +++ b/tests/lean/External/Types.lean @@ -5,7 +5,7 @@ open Primitives namespace external /- [core::num::nonzero::NonZeroU32] -/ -axiom core_num_nonzero_non_zero_u32_t : Type +axiom core.num.nonzero.NonZeroU32 : Type /- The state type used in the state-error monad -/ axiom State : Type -- cgit v1.2.3 From 5ca36bfc50083a01af2b7ae5f75993a520757ef5 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Wed, 5 Jul 2023 15:17:58 +0200 Subject: Simplify the names used in Primitives.lean --- tests/lean/External/Funs.lean | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/lean/External') diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean index 10efc3db..3fc21d91 100644 --- a/tests/lean/External/Funs.lean +++ b/tests/lean/External/Funs.lean @@ -36,8 +36,8 @@ def test_new_non_zero_u32_fwd /- [external::test_vec] -/ def test_vec_fwd : Result Unit := do - let v := vec_new U32 - let _ ← vec_push_back U32 v (U32.ofInt 0 (by intlit)) + let v := Vec.new U32 + let _ ← Vec.push U32 v (U32.ofInt 0 (by intlit)) Result.ret () /- Unit test for [external::test_vec] -/ -- cgit v1.2.3 From 7c95800cefc87fad894f8bf855cfc047e713b3a7 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Thu, 6 Jul 2023 12:20:28 +0200 Subject: Improve the generated comments --- tests/lean/External/Funs.lean | 49 +++++++++++++------------- tests/lean/External/FunsExternal.lean | 6 ++-- tests/lean/External/FunsExternal_Template.lean | 17 +++++---- 3 files changed, 35 insertions(+), 37 deletions(-) (limited to 'tests/lean/External') diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean index 3fc21d91..122f94da 100644 --- a/tests/lean/External/Funs.lean +++ b/tests/lean/External/Funs.lean @@ -6,81 +6,80 @@ import External.FunsExternal open Primitives namespace external -/- [external::swap] -/ -def swap_fwd - (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := +/- [external::swap]: forward function -/ +def swap (T : Type) (x : T) (y : T) (st : State) : Result (State × Unit) := do - let (st0, _) ← core.mem.swap_fwd T x y st + let (st0, _) ← core.mem.swap T x y st let (st1, _) ← core.mem.swap_back0 T x y st st0 let (st2, _) ← core.mem.swap_back1 T x y st st1 Result.ret (st2, ()) -/- [external::swap] -/ +/- [external::swap]: backward function 0 -/ def swap_back (T : Type) (x : T) (y : T) (st : State) (st0 : State) : Result (State × (T × T)) := do - let (st1, _) ← core.mem.swap_fwd T x y st + let (st1, _) ← core.mem.swap T x y st let (st2, x0) ← core.mem.swap_back0 T x y st st1 let (_, y0) ← core.mem.swap_back1 T x y st st2 Result.ret (st0, (x0, y0)) -/- [external::test_new_non_zero_u32] -/ -def test_new_non_zero_u32_fwd +/- [external::test_new_non_zero_u32]: forward function -/ +def test_new_non_zero_u32 (x : U32) (st : State) : Result (State × core.num.nonzero.NonZeroU32) := do - let (st0, opt) ← core.num.nonzero.NonZeroU32.new_fwd x st - core.option.Option.unwrap_fwd core.num.nonzero.NonZeroU32 opt st0 + let (st0, opt) ← core.num.nonzero.NonZeroU32.new x st + core.option.Option.unwrap core.num.nonzero.NonZeroU32 opt st0 -/- [external::test_vec] -/ -def test_vec_fwd : Result Unit := +/- [external::test_vec]: forward function -/ +def test_vec : Result Unit := do let v := Vec.new U32 let _ ← Vec.push U32 v (U32.ofInt 0 (by intlit)) Result.ret () /- Unit test for [external::test_vec] -/ -#assert (test_vec_fwd == .ret ()) +#assert (test_vec == .ret ()) -/- [external::custom_swap] -/ -def custom_swap_fwd +/- [external::custom_swap]: forward function -/ +def custom_swap (T : Type) (x : T) (y : T) (st : State) : Result (State × T) := do - let (st0, _) ← core.mem.swap_fwd T x y st + let (st0, _) ← core.mem.swap T x y st let (st1, x0) ← core.mem.swap_back0 T x y st st0 let (st2, _) ← core.mem.swap_back1 T x y st st1 Result.ret (st2, x0) -/- [external::custom_swap] -/ +/- [external::custom_swap]: backward function 0 -/ def custom_swap_back (T : Type) (x : T) (y : T) (st : State) (ret0 : T) (st0 : State) : Result (State × (T × T)) := do - let (st1, _) ← core.mem.swap_fwd T x y st + let (st1, _) ← core.mem.swap T x y st let (st2, _) ← core.mem.swap_back0 T x y st st1 let (_, y0) ← core.mem.swap_back1 T x y st st2 Result.ret (st0, (ret0, y0)) -/- [external::test_custom_swap] -/ -def test_custom_swap_fwd +/- [external::test_custom_swap]: forward function -/ +def test_custom_swap (x : U32) (y : U32) (st : State) : Result (State × Unit) := do - let (st0, _) ← custom_swap_fwd U32 x y st + let (st0, _) ← custom_swap U32 x y st Result.ret (st0, ()) -/- [external::test_custom_swap] -/ +/- [external::test_custom_swap]: backward function 0 -/ def test_custom_swap_back (x : U32) (y : U32) (st : State) (st0 : State) : Result (State × (U32 × U32)) := custom_swap_back U32 x y st (U32.ofInt 1 (by intlit)) st0 -/- [external::test_swap_non_zero] -/ -def test_swap_non_zero_fwd (x : U32) (st : State) : Result (State × U32) := +/- [external::test_swap_non_zero]: forward function -/ +def test_swap_non_zero (x : U32) (st : State) : Result (State × U32) := do - let (st0, _) ← swap_fwd U32 x (U32.ofInt 0 (by intlit)) st + let (st0, _) ← swap U32 x (U32.ofInt 0 (by intlit)) st let (st1, (x0, _)) ← swap_back U32 x (U32.ofInt 0 (by intlit)) st st0 if x0 = (U32.ofInt 0 (by intlit)) then Result.fail Error.panic diff --git a/tests/lean/External/FunsExternal.lean b/tests/lean/External/FunsExternal.lean index 5326dd77..aae11ba1 100644 --- a/tests/lean/External/FunsExternal.lean +++ b/tests/lean/External/FunsExternal.lean @@ -7,7 +7,7 @@ open external -- TODO: fill those bodies /- [core::mem::swap] -/ -def core.mem.swap_fwd +def core.mem.swap (T : Type) : T → T → State → Result (State × Unit) := fun _x _y s => .ret (s, ()) @@ -22,12 +22,12 @@ def core.mem.swap_back1 fun x _y _s0 s1 => .ret (s1, x) /- [core::num::nonzero::NonZeroU32::{14}::new] -/ -def core.num.nonzero.NonZeroU32.new_fwd +def core.num.nonzero.NonZeroU32.new : U32 → State → Result (State × (Option core_num_nonzero_non_zero_u32_t)) := fun _ _ => .fail .panic /- [core::option::Option::{0}::unwrap] -/ -def core.option.Option.unwrap_fwd +def core.option.Option.unwrap (T : Type) : Option T → State → Result (State × T) := fun _ _ => .fail .panic diff --git a/tests/lean/External/FunsExternal_Template.lean b/tests/lean/External/FunsExternal_Template.lean index 669fe91b..c8bc397f 100644 --- a/tests/lean/External/FunsExternal_Template.lean +++ b/tests/lean/External/FunsExternal_Template.lean @@ -6,23 +6,22 @@ import External.Types open Primitives open external -/- [core::mem::swap] -/ -axiom core.mem.swap_fwd - (T : Type) : T → T → State → Result (State × Unit) +/- [core::mem::swap]: forward function -/ +axiom core.mem.swap (T : Type) : T → T → State → Result (State × Unit) -/- [core::mem::swap] -/ +/- [core::mem::swap]: backward function 0 -/ axiom core.mem.swap_back0 (T : Type) : T → T → State → State → Result (State × T) -/- [core::mem::swap] -/ +/- [core::mem::swap]: backward function 1 -/ axiom core.mem.swap_back1 (T : Type) : T → T → State → State → Result (State × T) -/- [core::num::nonzero::NonZeroU32::{14}::new] -/ -axiom core.num.nonzero.NonZeroU32.new_fwd +/- [core::num::nonzero::NonZeroU32::{14}::new]: forward function -/ +axiom core.num.nonzero.NonZeroU32.new : U32 → State → Result (State × (Option core.num.nonzero.NonZeroU32)) -/- [core::option::Option::{0}::unwrap] -/ -axiom core.option.Option.unwrap_fwd +/- [core::option::Option::{0}::unwrap]: forward function -/ +axiom core.option.Option.unwrap (T : Type) : Option T → State → Result (State × T) -- cgit v1.2.3 From e010c10fb9a1e2d88b52a4f6b4a0865448276013 Mon Sep 17 00:00:00 2001 From: Son Ho Date: Wed, 12 Jul 2023 15:58:38 +0200 Subject: Make the `by inlit` implicit --- tests/lean/External/Funs.lean | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/lean/External') diff --git a/tests/lean/External/Funs.lean b/tests/lean/External/Funs.lean index 122f94da..674aaebd 100644 --- a/tests/lean/External/Funs.lean +++ b/tests/lean/External/Funs.lean @@ -36,7 +36,7 @@ def test_new_non_zero_u32 def test_vec : Result Unit := do let v := Vec.new U32 - let _ ← Vec.push U32 v (U32.ofInt 0 (by intlit)) + let _ ← Vec.push U32 v (U32.ofInt 0) Result.ret () /- Unit test for [external::test_vec] -/ @@ -74,14 +74,14 @@ def test_custom_swap_back (x : U32) (y : U32) (st : State) (st0 : State) : Result (State × (U32 × U32)) := - custom_swap_back U32 x y st (U32.ofInt 1 (by intlit)) st0 + custom_swap_back U32 x y st (U32.ofInt 1) st0 /- [external::test_swap_non_zero]: forward function -/ def test_swap_non_zero (x : U32) (st : State) : Result (State × U32) := do - let (st0, _) ← swap U32 x (U32.ofInt 0 (by intlit)) st - let (st1, (x0, _)) ← swap_back U32 x (U32.ofInt 0 (by intlit)) st st0 - if x0 = (U32.ofInt 0 (by intlit)) + let (st0, _) ← swap U32 x (U32.ofInt 0) st + let (st1, (x0, _)) ← swap_back U32 x (U32.ofInt 0) st st0 + if x0 = (U32.ofInt 0) then Result.fail Error.panic else Result.ret (st1, x0) -- cgit v1.2.3