diff options
Diffstat (limited to '')
-rw-r--r-- | tests/coq/traits/Traits.v | 126 | ||||
-rw-r--r-- | tests/fstar/traits/Traits.fst | 121 | ||||
-rw-r--r-- | tests/lean/Traits.lean | 132 |
3 files changed, 195 insertions, 184 deletions
diff --git a/tests/coq/traits/Traits.v b/tests/coq/traits/Traits.v index e104fb66..a25d5089 100644 --- a/tests/coq/traits/Traits.v +++ b/tests/coq/traits/Traits.v @@ -16,12 +16,12 @@ Record BoolTrait_t (Self : Type) := mkBoolTrait_t { Arguments mkBoolTrait_t { _ }. Arguments BoolTrait_t_get_bool { _ }. -(** [traits::Bool::{0}::get_bool]: forward function *) +(** [traits::{bool}::get_bool]: forward function *) Definition bool_get_bool (self : bool) : result bool := Return self. -(** Trait implementation: [traits::Bool::{0}] *) -Definition Bool_BoolTraitInst : BoolTrait_t bool := {| +(** Trait implementation: [traits::{bool}] *) +Definition traits_BoolTraitBoolInst : BoolTrait_t bool := {| BoolTrait_t_get_bool := bool_get_bool; |}. @@ -34,23 +34,26 @@ Definition boolTrait_ret_true (** [traits::test_bool_trait_bool]: forward function *) Definition test_bool_trait_bool (x : bool) : result bool := b <- bool_get_bool x; - if b then boolTrait_ret_true Bool_BoolTraitInst x else Return false + if b then boolTrait_ret_true traits_BoolTraitBoolInst x else Return false . -(** [traits::Option::{1}::get_bool]: forward function *) +(** [traits::{core::option::Option<T>#1}::get_bool]: forward function *) Definition option_get_bool (T : Type) (self : option T) : result bool := match self with | None => Return false | Some t => Return true end . -(** Trait implementation: [traits::Option::{1}] *) -Definition Option_BoolTraitInst (T : Type) : BoolTrait_t (option T) := {| +(** Trait implementation: [traits::{core::option::Option<T>#1}] *) +Definition traits_BoolTraitcoreoptionOptionTInst (T : Type) : BoolTrait_t + (option T) := {| BoolTrait_t_get_bool := option_get_bool T; |}. (** [traits::test_bool_trait_option]: forward function *) Definition test_bool_trait_option (T : Type) (x : option T) : result bool := b <- option_get_bool T x; - if b then boolTrait_ret_true (Option_BoolTraitInst T) x else Return false + if b + then boolTrait_ret_true (traits_BoolTraitcoreoptionOptionTInst T) x + else Return false . (** [traits::test_bool_trait]: forward function *) @@ -67,15 +70,17 @@ Record ToU64_t (Self : Type) := mkToU64_t { Arguments mkToU64_t { _ }. Arguments ToU64_t_to_u64 { _ }. -(** [traits::u64::{2}::to_u64]: forward function *) +(** [traits::{u64#2}::to_u64]: forward function *) Definition u64_to_u64 (self : u64) : result u64 := Return self. -(** Trait implementation: [traits::u64::{2}] *) -Definition u64_ToU64Inst : ToU64_t u64 := {| ToU64_t_to_u64 := u64_to_u64; |}. +(** Trait implementation: [traits::{u64#2}] *) +Definition traits_ToU64U64Inst : ToU64_t u64 := {| + ToU64_t_to_u64 := u64_to_u64; +|}. -(** [traits::Tuple2::{3}::to_u64]: forward function *) -Definition tuple2_to_u64 +(** [traits::{(A, A)#3}::to_u64]: forward function *) +Definition pair_to_u64 (A : Type) (inst : ToU64_t A) (self : (A * A)) : result u64 := let (t, t0) := self in i <- inst.(ToU64_t_to_u64) t; @@ -83,15 +88,15 @@ Definition tuple2_to_u64 u64_add i i0 . -(** Trait implementation: [traits::Tuple2::{3}] *) -Definition Tuple2_ToU64Inst (A : Type) (inst : ToU64_t A) : ToU64_t (A * A) - := {| - ToU64_t_to_u64 := tuple2_to_u64 A inst; +(** Trait implementation: [traits::{(A, A)#3}] *) +Definition traits_ToU64TupleAAInst (A : Type) (inst : ToU64_t A) : ToU64_t (A * + A) := {| + ToU64_t_to_u64 := pair_to_u64 A inst; |}. (** [traits::f]: forward function *) Definition f (T : Type) (inst : ToU64_t T) (x : (T * T)) : result u64 := - tuple2_to_u64 T inst x + pair_to_u64 T inst x . (** [traits::g]: forward function *) @@ -109,21 +114,21 @@ Record Wrapper_t (T : Type) := mkWrapper_t { wrapper_x : T; }. Arguments mkWrapper_t { _ }. Arguments wrapper_x { _ }. -(** [traits::Wrapper::{4}::to_u64]: forward function *) +(** [traits::{traits::Wrapper<T>#4}::to_u64]: forward function *) Definition wrapper_to_u64 (T : Type) (inst : ToU64_t T) (self : Wrapper_t T) : result u64 := inst.(ToU64_t_to_u64) self.(wrapper_x) . -(** Trait implementation: [traits::Wrapper::{4}] *) -Definition Wrapper_ToU64Inst (T : Type) (inst : ToU64_t T) : ToU64_t (Wrapper_t - T) := {| +(** Trait implementation: [traits::{traits::Wrapper<T>#4}] *) +Definition traits_ToU64traitsWrapperTInst (T : Type) (inst : ToU64_t T) : + ToU64_t (Wrapper_t T) := {| ToU64_t_to_u64 := wrapper_to_u64 T inst; |}. (** [traits::h1]: forward function *) Definition h1 (x : Wrapper_t u64) : result u64 := - wrapper_to_u64 u64 u64_ToU64Inst x + wrapper_to_u64 u64 traits_ToU64U64Inst x . (** [traits::h2]: forward function *) @@ -139,12 +144,12 @@ Record ToType_t (Self T : Type) := mkToType_t { Arguments mkToType_t { _ _ }. Arguments ToType_t_to_type { _ _ }. -(** [traits::u64::{5}::to_type]: forward function *) +(** [traits::{u64#5}::to_type]: forward function *) Definition u64_to_type (self : u64) : result bool := Return (self s> 0%u64). -(** Trait implementation: [traits::u64::{5}] *) -Definition u64_ToTypeInst : ToType_t u64 bool := {| +(** Trait implementation: [traits::{u64#5}] *) +Definition traits_ToTypeU64BoolInst : ToType_t u64 bool := {| ToType_t_to_type := u64_to_type; |}. @@ -189,14 +194,14 @@ Record TestType_t (T : Type) := mkTestType_t { testType_0 : T; }. Arguments mkTestType_t { _ }. Arguments testType_0 { _ }. -(** [traits::TestType::{6}::test::TestType1] *) +(** [traits::{traits::TestType<T>#6}::test::TestType1] *) Record TestType_test_TestType1_t := mkTestType_test_TestType1_t { testType_test_TestType1_0 : u64; } . -(** Trait declaration: [traits::TestType::{6}::test::TestTrait] *) +(** Trait declaration: [traits::{traits::TestType<T>#6}::test::TestTrait] *) Record TestType_test_TestTrait_t (Self : Type) := mkTestType_test_TestTrait_t { TestType_test_TestTrait_t_test : Self -> result bool; }. @@ -204,19 +209,19 @@ Record TestType_test_TestTrait_t (Self : Type) := mkTestType_test_TestTrait_t { Arguments mkTestType_test_TestTrait_t { _ }. Arguments TestType_test_TestTrait_t_test { _ }. -(** [traits::TestType::{6}::test::TestType1::{0}::test]: forward function *) +(** [traits::{traits::TestType<T>#6}::test::{traits::{traits::TestType<T>#6}::test::TestType1}::test]: forward function *) Definition testType_test_TestType1_test (self : TestType_test_TestType1_t) : result bool := Return (self.(testType_test_TestType1_0) s> 1%u64) . -(** Trait implementation: [traits::TestType::{6}::test::TestType1::{0}] *) -Definition TestType_test_TestType1_TestType_test_TestTraitInst : - TestType_test_TestTrait_t TestType_test_TestType1_t := {| +(** Trait implementation: [traits::{traits::TestType<T>#6}::test::{traits::{traits::TestType<T>#6}::test::TestType1}] *) +Definition traits_TestType_test_TestTraittraitstraitsTestTypeTtestTestType1Inst + : TestType_test_TestTrait_t TestType_test_TestType1_t := {| TestType_test_TestTrait_t_test := testType_test_TestType1_test; |}. -(** [traits::TestType::{6}::test]: forward function *) +(** [traits::{traits::TestType<T>#6}::test]: forward function *) Definition testType_test (T : Type) (inst : ToU64_t T) (self : TestType_t T) (x : T) : result bool := x0 <- inst.(ToU64_t_to_u64) x; @@ -228,15 +233,15 @@ Definition testType_test (** [traits::BoolWrapper] *) Record BoolWrapper_t := mkBoolWrapper_t { boolWrapper_0 : bool; }. -(** [traits::BoolWrapper::{7}::to_type]: forward function *) +(** [traits::{traits::BoolWrapper#7}::to_type]: forward function *) Definition boolWrapper_to_type (T : Type) (inst : ToType_t bool T) (self : BoolWrapper_t) : result T := inst.(ToType_t_to_type) self.(boolWrapper_0) . -(** Trait implementation: [traits::BoolWrapper::{7}] *) -Definition BoolWrapper_ToTypeInst (T : Type) (inst : ToType_t bool T) : - ToType_t BoolWrapper_t T := {| +(** Trait implementation: [traits::{traits::BoolWrapper#7}] *) +Definition traits_ToTypetraitsBoolWrapperTInst (T : Type) (inst : ToType_t bool + T) : ToType_t BoolWrapper_t T := {| ToType_t_to_type := boolWrapper_to_type T inst; |}. @@ -263,22 +268,22 @@ Arguments WithConstTy_tWithConstTy_t_W { _ _ }. Arguments WithConstTy_tWithConstTy_t_W_clause_0 { _ _ }. Arguments WithConstTy_t_f { _ _ }. -(** [traits::Bool::{8}::LEN1] *) +(** [traits::{bool#8}::LEN1] *) Definition bool_len1_body : result usize := Return 12%usize. Definition bool_len1_c : usize := bool_len1_body%global. -(** [traits::Bool::{8}::f]: merged forward/backward function +(** [traits::{bool#8}::f]: merged forward/backward function (there is a single backward function, and the forward function returns ()) *) Definition bool_f (i : u64) (a : array u8 32%usize) : result u64 := Return i. -(** Trait implementation: [traits::Bool::{8}] *) -Definition Bool_WithConstTyInst : WithConstTy_t bool 32%usize := {| +(** Trait implementation: [traits::{bool#8}] *) +Definition traits_WithConstTyBool32Inst : WithConstTy_t bool 32%usize := {| WithConstTy_tWithConstTy_t_LEN1 := bool_len1_c; WithConstTy_tWithConstTy_t_LEN2 := with_const_ty_len2_c; WithConstTy_tWithConstTy_t_V := u8; WithConstTy_tWithConstTy_t_W := u64; - WithConstTy_tWithConstTy_t_W_clause_0 := u64_ToU64Inst; + WithConstTy_tWithConstTy_t_W_clause_0 := traits_ToU64U64Inst; WithConstTy_t_f := bool_f; |}. @@ -377,12 +382,13 @@ Record ChildTrait1_t (Self : Type) := mkChildTrait1_t { Arguments mkChildTrait1_t { _ }. Arguments ChildTrait1_tChildTrait1_t_parent_clause_0 { _ }. -(** Trait implementation: [traits::usize::{9}] *) -Definition usize_ParentTrait1Inst : ParentTrait1_t usize := mkParentTrait1_t. +(** Trait implementation: [traits::{usize#9}] *) +Definition traits_ParentTrait1UsizeInst : ParentTrait1_t usize + := mkParentTrait1_t. -(** Trait implementation: [traits::usize::{10}] *) -Definition usize_ChildTrait1Inst : ChildTrait1_t usize := {| - ChildTrait1_tChildTrait1_t_parent_clause_0 := usize_ParentTrait1Inst; +(** Trait implementation: [traits::{usize#10}] *) +Definition traits_ChildTrait1UsizeInst : ChildTrait1_t usize := {| + ChildTrait1_tChildTrait1_t_parent_clause_0 := traits_ParentTrait1UsizeInst; |}. (** Trait declaration: [traits::Iterator] *) @@ -456,31 +462,27 @@ Arguments mkChildTrait2_t { _ }. Arguments ChildTrait2_tChildTrait2_t_parent_clause_0 { _ }. Arguments ChildTrait2_t_convert { _ }. -(** Trait implementation: [traits::u32::{11}] *) -Definition u32_WithTargetInst : WithTarget_t u32 := {| +(** Trait implementation: [traits::{u32#11}] *) +Definition traits_WithTargetU32Inst : WithTarget_t u32 := {| WithTarget_tWithTarget_t_Target := u32; |}. -(** Trait implementation: [traits::u32::{12}] *) -Definition u32_ParentTrait2Inst : ParentTrait2_t u32 := {| +(** Trait implementation: [traits::{u32#12}] *) +Definition traits_ParentTrait2U32Inst : ParentTrait2_t u32 := {| ParentTrait2_tParentTrait2_t_U := u32; - ParentTrait2_tParentTrait2_t_U_clause_0 := u32_WithTargetInst; + ParentTrait2_tParentTrait2_t_U_clause_0 := traits_WithTargetU32Inst; |}. -(** [traits::u32::{13}::convert]: forward function *) +(** [traits::{u32#13}::convert]: forward function *) Definition u32_convert (x : u32) : result u32 := Return x. -(** Trait implementation: [traits::u32::{13}] *) -Definition u32_ChildTrait2Inst : ChildTrait2_t u32 := {| - ChildTrait2_tChildTrait2_t_parent_clause_0 := u32_ParentTrait2Inst; +(** Trait implementation: [traits::{u32#13}] *) +Definition traits_ChildTrait2U32Inst : ChildTrait2_t u32 := {| + ChildTrait2_tChildTrait2_t_parent_clause_0 := traits_ParentTrait2U32Inst; ChildTrait2_t_convert := u32_convert; |}. -(** [traits::incr_u32]: forward function *) -Definition incr_u32 (x : u32) : result u32 := - u32_add x 1%u32. - (** Trait declaration: [traits::CFnOnce] *) Record CFnOnce_t (Self Args : Type) := mkCFnOnce_t { CFnOnce_tCFnOnce_t_Output : Type; @@ -517,4 +519,8 @@ Arguments mkCFn_t { _ _ }. Arguments CFn_tCFn_t_parent_clause_0 { _ _ }. Arguments CFn_t_call_mut { _ _ }. +(** [traits::incr_u32]: forward function *) +Definition incr_u32 (x : u32) : result u32 := + u32_add x 1%u32. + End Traits . diff --git a/tests/fstar/traits/Traits.fst b/tests/fstar/traits/Traits.fst index 318efa2b..7edb27c1 100644 --- a/tests/fstar/traits/Traits.fst +++ b/tests/fstar/traits/Traits.fst @@ -8,12 +8,12 @@ open Primitives (** Trait declaration: [traits::BoolTrait] *) noeq type boolTrait_t (self : Type0) = { get_bool : self -> result bool; } -(** [traits::Bool::{0}::get_bool]: forward function *) +(** [traits::{bool}::get_bool]: forward function *) let bool_get_bool (self : bool) : result bool = Return self -(** Trait implementation: [traits::Bool::{0}] *) -let bool_BoolTraitInst : boolTrait_t bool = { get_bool = bool_get_bool; } +(** Trait implementation: [traits::{bool}] *) +let traits_BoolTraitBoolInst : boolTrait_t bool = { get_bool = bool_get_bool; } (** [traits::BoolTrait::ret_true]: forward function *) let boolTrait_ret_true @@ -25,21 +25,24 @@ let boolTrait_ret_true (** [traits::test_bool_trait_bool]: forward function *) let test_bool_trait_bool (x : bool) : result bool = let* b = bool_get_bool x in - if b then boolTrait_ret_true bool_BoolTraitInst x else Return false + if b then boolTrait_ret_true traits_BoolTraitBoolInst x else Return false -(** [traits::Option::{1}::get_bool]: forward function *) +(** [traits::{core::option::Option<T>#1}::get_bool]: forward function *) let option_get_bool (t : Type0) (self : option t) : result bool = begin match self with | None -> Return false | Some x -> Return true end -(** Trait implementation: [traits::Option::{1}] *) -let option_BoolTraitInst (t : Type0) : boolTrait_t (option t) = { +(** Trait implementation: [traits::{core::option::Option<T>#1}] *) +let traits_BoolTraitcoreoptionOptionTInst (t : Type0) : boolTrait_t (option t) + = { get_bool = option_get_bool t; } (** [traits::test_bool_trait_option]: forward function *) let test_bool_trait_option (t : Type0) (x : option t) : result bool = let* b = option_get_bool t x in - if b then boolTrait_ret_true (option_BoolTraitInst t) x else Return false + if b + then boolTrait_ret_true (traits_BoolTraitcoreoptionOptionTInst t) x + else Return false (** [traits::test_bool_trait]: forward function *) let test_bool_trait (t : Type0) (inst : boolTrait_t t) (x : t) : result bool = @@ -48,29 +51,29 @@ let test_bool_trait (t : Type0) (inst : boolTrait_t t) (x : t) : result bool = (** Trait declaration: [traits::ToU64] *) noeq type toU64_t (self : Type0) = { to_u64 : self -> result u64; } -(** [traits::u64::{2}::to_u64]: forward function *) +(** [traits::{u64#2}::to_u64]: forward function *) let u64_to_u64 (self : u64) : result u64 = Return self -(** Trait implementation: [traits::u64::{2}] *) -let u64_ToU64Inst : toU64_t u64 = { to_u64 = u64_to_u64; } +(** Trait implementation: [traits::{u64#2}] *) +let traits_ToU64U64Inst : toU64_t u64 = { to_u64 = u64_to_u64; } -(** [traits::Tuple2::{3}::to_u64]: forward function *) -let tuple2_to_u64 - (a : Type0) (inst : toU64_t a) (self : (a & a)) : result u64 = +(** [traits::{(A, A)#3}::to_u64]: forward function *) +let pair_to_u64 (a : Type0) (inst : toU64_t a) (self : (a & a)) : result u64 = let (x, x0) = self in let* i = inst.to_u64 x in let* i0 = inst.to_u64 x0 in u64_add i i0 -(** Trait implementation: [traits::Tuple2::{3}] *) -let tuple2_ToU64Inst (a : Type0) (inst : toU64_t a) : toU64_t (a & a) = { - to_u64 = tuple2_to_u64 a inst; +(** Trait implementation: [traits::{(A, A)#3}] *) +let traits_ToU64TupleAAInst (a : Type0) (inst : toU64_t a) : toU64_t (a & a) + = { + to_u64 = pair_to_u64 a inst; } (** [traits::f]: forward function *) let f (t : Type0) (inst : toU64_t t) (x : (t & t)) : result u64 = - tuple2_to_u64 t inst x + pair_to_u64 t inst x (** [traits::g]: forward function *) let g (t : Type0) (inst : toU64_t (t & t)) (x : (t & t)) : result u64 = @@ -83,20 +86,20 @@ let h0 (x : u64) : result u64 = (** [traits::Wrapper] *) type wrapper_t (t : Type0) = { x : t; } -(** [traits::Wrapper::{4}::to_u64]: forward function *) +(** [traits::{traits::Wrapper<T>#4}::to_u64]: forward function *) let wrapper_to_u64 (t : Type0) (inst : toU64_t t) (self : wrapper_t t) : result u64 = inst.to_u64 self.x -(** Trait implementation: [traits::Wrapper::{4}] *) -let wrapper_ToU64Inst (t : Type0) (inst : toU64_t t) : toU64_t (wrapper_t t) - = { +(** Trait implementation: [traits::{traits::Wrapper<T>#4}] *) +let traits_ToU64traitsWrapperTInst (t : Type0) (inst : toU64_t t) : toU64_t + (wrapper_t t) = { to_u64 = wrapper_to_u64 t inst; } (** [traits::h1]: forward function *) let h1 (x : wrapper_t u64) : result u64 = - wrapper_to_u64 u64 u64_ToU64Inst x + wrapper_to_u64 u64 traits_ToU64U64Inst x (** [traits::h2]: forward function *) let h2 (t : Type0) (inst : toU64_t t) (x : wrapper_t t) : result u64 = @@ -105,12 +108,12 @@ let h2 (t : Type0) (inst : toU64_t t) (x : wrapper_t t) : result u64 = (** Trait declaration: [traits::ToType] *) noeq type toType_t (self t : Type0) = { to_type : self -> result t; } -(** [traits::u64::{5}::to_type]: forward function *) +(** [traits::{u64#5}::to_type]: forward function *) let u64_to_type (self : u64) : result bool = Return (self > 0) -(** Trait implementation: [traits::u64::{5}] *) -let u64_ToTypeInst : toType_t u64 bool = { to_type = u64_to_type; } +(** Trait implementation: [traits::{u64#5}] *) +let traits_ToTypeU64BoolInst : toType_t u64 bool = { to_type = u64_to_type; } (** Trait declaration: [traits::OfType] *) noeq type ofType_t (self : Type0) = { @@ -141,26 +144,26 @@ let h4 (** [traits::TestType] *) type testType_t (t : Type0) = { _0 : t; } -(** [traits::TestType::{6}::test::TestType1] *) +(** [traits::{traits::TestType<T>#6}::test::TestType1] *) type testType_test_TestType1_t = { _0 : u64; } -(** Trait declaration: [traits::TestType::{6}::test::TestTrait] *) +(** Trait declaration: [traits::{traits::TestType<T>#6}::test::TestTrait] *) noeq type testType_test_TestTrait_t (self : Type0) = { test : self -> result bool; } -(** [traits::TestType::{6}::test::TestType1::{0}::test]: forward function *) +(** [traits::{traits::TestType<T>#6}::test::{traits::{traits::TestType<T>#6}::test::TestType1}::test]: forward function *) let testType_test_TestType1_test (self : testType_test_TestType1_t) : result bool = Return (self._0 > 1) -(** Trait implementation: [traits::TestType::{6}::test::TestType1::{0}] *) -let testType_test_TestType1_TestType_test_TestTraitInst : +(** Trait implementation: [traits::{traits::TestType<T>#6}::test::{traits::{traits::TestType<T>#6}::test::TestType1}] *) +let traits_TestType_test_TestTraittraitstraitsTestTypeTtestTestType1Inst : testType_test_TestTrait_t testType_test_TestType1_t = { test = testType_test_TestType1_test; } -(** [traits::TestType::{6}::test]: forward function *) +(** [traits::{traits::TestType<T>#6}::test]: forward function *) let testType_test (t : Type0) (inst : toU64_t t) (self : testType_t t) (x : t) : result bool = let* x0 = inst.to_u64 x in @@ -169,14 +172,14 @@ let testType_test (** [traits::BoolWrapper] *) type boolWrapper_t = { _0 : bool; } -(** [traits::BoolWrapper::{7}::to_type]: forward function *) +(** [traits::{traits::BoolWrapper#7}::to_type]: forward function *) let boolWrapper_to_type (t : Type0) (inst : toType_t bool t) (self : boolWrapper_t) : result t = inst.to_type self._0 -(** Trait implementation: [traits::BoolWrapper::{7}] *) -let boolWrapper_ToTypeInst (t : Type0) (inst : toType_t bool t) : toType_t - boolWrapper_t t = { +(** Trait implementation: [traits::{traits::BoolWrapper#7}] *) +let traits_ToTypetraitsBoolWrapperTInst (t : Type0) (inst : toType_t bool t) : + toType_t boolWrapper_t t = { to_type = boolWrapper_to_type t inst; } @@ -194,22 +197,22 @@ noeq type withConstTy_t (self : Type0) (len : usize) = { f : tW -> array u8 len -> result tW; } -(** [traits::Bool::{8}::LEN1] *) +(** [traits::{bool#8}::LEN1] *) let bool_len1_body : result usize = Return 12 let bool_len1_c : usize = eval_global bool_len1_body -(** [traits::Bool::{8}::f]: merged forward/backward function +(** [traits::{bool#8}::f]: merged forward/backward function (there is a single backward function, and the forward function returns ()) *) let bool_f (i : u64) (a : array u8 32) : result u64 = Return i -(** Trait implementation: [traits::Bool::{8}] *) -let bool_WithConstTyInst : withConstTy_t bool 32 = { +(** Trait implementation: [traits::{bool#8}] *) +let traits_WithConstTyBool32Inst : withConstTy_t bool 32 = { cLEN1 = bool_len1_c; cLEN2 = with_const_ty_len2_c; tV = u8; tW = u64; - tW_clause_0 = u64_ToU64Inst; + tW_clause_0 = traits_ToU64U64Inst; f = bool_f; } @@ -284,12 +287,12 @@ noeq type childTrait1_t (self : Type0) = { parent_clause_0 : parentTrait1_t self; } -(** Trait implementation: [traits::usize::{9}] *) -let usize_ParentTrait1Inst : parentTrait1_t usize = () +(** Trait implementation: [traits::{usize#9}] *) +let traits_ParentTrait1UsizeInst : parentTrait1_t usize = () -(** Trait implementation: [traits::usize::{10}] *) -let usize_ChildTrait1Inst : childTrait1_t usize = { - parent_clause_0 = usize_ParentTrait1Inst; +(** Trait implementation: [traits::{usize#10}] *) +let traits_ChildTrait1UsizeInst : childTrait1_t usize = { + parent_clause_0 = traits_ParentTrait1UsizeInst; } (** Trait declaration: [traits::Iterator] *) @@ -327,29 +330,25 @@ noeq type childTrait2_t (self : Type0) = { convert : parent_clause_0.tU -> result parent_clause_0.tU_clause_0.tTarget; } -(** Trait implementation: [traits::u32::{11}] *) -let u32_WithTargetInst : withTarget_t u32 = { tTarget = u32; } +(** Trait implementation: [traits::{u32#11}] *) +let traits_WithTargetU32Inst : withTarget_t u32 = { tTarget = u32; } -(** Trait implementation: [traits::u32::{12}] *) -let u32_ParentTrait2Inst : parentTrait2_t u32 = { +(** Trait implementation: [traits::{u32#12}] *) +let traits_ParentTrait2U32Inst : parentTrait2_t u32 = { tU = u32; - tU_clause_0 = u32_WithTargetInst; + tU_clause_0 = traits_WithTargetU32Inst; } -(** [traits::u32::{13}::convert]: forward function *) +(** [traits::{u32#13}::convert]: forward function *) let u32_convert (x : u32) : result u32 = Return x -(** Trait implementation: [traits::u32::{13}] *) -let u32_ChildTrait2Inst : childTrait2_t u32 = { - parent_clause_0 = u32_ParentTrait2Inst; +(** Trait implementation: [traits::{u32#13}] *) +let traits_ChildTrait2U32Inst : childTrait2_t u32 = { + parent_clause_0 = traits_ParentTrait2U32Inst; convert = u32_convert; } -(** [traits::incr_u32]: forward function *) -let incr_u32 (x : u32) : result u32 = - u32_add x 1 - (** Trait declaration: [traits::CFnOnce] *) noeq type cFnOnce_t (self args : Type0) = { tOutput : Type0; @@ -369,3 +368,7 @@ noeq type cFn_t (self args : Type0) = { call_mut : self -> args -> result parent_clause_0.parent_clause_0.tOutput; } +(** [traits::incr_u32]: forward function *) +let incr_u32 (x : u32) : result u32 = + u32_add x 1 + diff --git a/tests/lean/Traits.lean b/tests/lean/Traits.lean index 12e7eafa..51a05581 100644 --- a/tests/lean/Traits.lean +++ b/tests/lean/Traits.lean @@ -9,12 +9,12 @@ namespace traits structure BoolTrait (Self : Type) where get_bool : Self → Result Bool -/- [traits::Bool::{0}::get_bool]: forward function -/ +/- [traits::{bool}::get_bool]: forward function -/ def Bool.get_bool (self : Bool) : Result Bool := Result.ret self -/- Trait implementation: [traits::Bool::{0}] -/ -def Bool.BoolTraitInst : BoolTrait Bool := { +/- Trait implementation: [traits::{bool}] -/ +def traits.BoolTraitBoolInst : BoolTrait Bool := { get_bool := Bool.get_bool } @@ -28,17 +28,18 @@ def test_bool_trait_bool (x : Bool) : Result Bool := do let b ← Bool.get_bool x if b - then BoolTrait.ret_true Bool.BoolTraitInst x + then BoolTrait.ret_true traits.BoolTraitBoolInst x else Result.ret false -/- [traits::Option::{1}::get_bool]: forward function -/ +/- [traits::{core::option::Option<T>#1}::get_bool]: forward function -/ def Option.get_bool (T : Type) (self : Option T) : Result Bool := match self with | none => Result.ret false | some t => Result.ret true -/- Trait implementation: [traits::Option::{1}] -/ -def Option.BoolTraitInst (T : Type) : BoolTrait (Option T) := { +/- Trait implementation: [traits::{core::option::Option<T>#1}] -/ +def traits.BoolTraitcoreoptionOptionTInst (T : Type) : BoolTrait (Option T) + := { get_bool := Option.get_bool T } @@ -47,7 +48,7 @@ def test_bool_trait_option (T : Type) (x : Option T) : Result Bool := do let b ← Option.get_bool T x if b - then BoolTrait.ret_true (Option.BoolTraitInst T) x + then BoolTrait.ret_true (traits.BoolTraitcoreoptionOptionTInst T) x else Result.ret false /- [traits::test_bool_trait]: forward function -/ @@ -58,31 +59,31 @@ def test_bool_trait (T : Type) (inst : BoolTrait T) (x : T) : Result Bool := structure ToU64 (Self : Type) where to_u64 : Self → Result U64 -/- [traits::u64::{2}::to_u64]: forward function -/ -def u64.to_u64 (self : U64) : Result U64 := +/- [traits::{u64#2}::to_u64]: forward function -/ +def U64.to_u64 (self : U64) : Result U64 := Result.ret self -/- Trait implementation: [traits::u64::{2}] -/ -def u64.ToU64Inst : ToU64 U64 := { - to_u64 := u64.to_u64 +/- Trait implementation: [traits::{u64#2}] -/ +def traits.ToU64U64Inst : ToU64 U64 := { + to_u64 := U64.to_u64 } -/- [traits::Tuple2::{3}::to_u64]: forward function -/ -def Tuple2.to_u64 (A : Type) (inst : ToU64 A) (self : (A × A)) : Result U64 := +/- [traits::{(A, A)#3}::to_u64]: forward function -/ +def Pair.to_u64 (A : Type) (inst : ToU64 A) (self : (A × A)) : Result U64 := do let (t, t0) := self let i ← inst.to_u64 t let i0 ← inst.to_u64 t0 i + i0 -/- Trait implementation: [traits::Tuple2::{3}] -/ -def Tuple2.ToU64Inst (A : Type) (inst : ToU64 A) : ToU64 (A × A) := { - to_u64 := Tuple2.to_u64 A inst +/- Trait implementation: [traits::{(A, A)#3}] -/ +def traits.ToU64TupleAAInst (A : Type) (inst : ToU64 A) : ToU64 (A × A) := { + to_u64 := Pair.to_u64 A inst } /- [traits::f]: forward function -/ def f (T : Type) (inst : ToU64 T) (x : (T × T)) : Result U64 := - Tuple2.to_u64 T inst x + Pair.to_u64 T inst x /- [traits::g]: forward function -/ def g (T : Type) (inst : ToU64 (T × T)) (x : (T × T)) : Result U64 := @@ -90,25 +91,26 @@ def g (T : Type) (inst : ToU64 (T × T)) (x : (T × T)) : Result U64 := /- [traits::h0]: forward function -/ def h0 (x : U64) : Result U64 := - u64.to_u64 x + U64.to_u64 x /- [traits::Wrapper] -/ structure Wrapper (T : Type) where x : T -/- [traits::Wrapper::{4}::to_u64]: forward function -/ +/- [traits::{traits::Wrapper<T>#4}::to_u64]: forward function -/ def Wrapper.to_u64 (T : Type) (inst : ToU64 T) (self : Wrapper T) : Result U64 := inst.to_u64 self.x -/- Trait implementation: [traits::Wrapper::{4}] -/ -def Wrapper.ToU64Inst (T : Type) (inst : ToU64 T) : ToU64 (Wrapper T) := { +/- Trait implementation: [traits::{traits::Wrapper<T>#4}] -/ +def traits.ToU64traitsWrapperTInst (T : Type) (inst : ToU64 T) : ToU64 (Wrapper + T) := { to_u64 := Wrapper.to_u64 T inst } /- [traits::h1]: forward function -/ def h1 (x : Wrapper U64) : Result U64 := - Wrapper.to_u64 U64 u64.ToU64Inst x + Wrapper.to_u64 U64 traits.ToU64U64Inst x /- [traits::h2]: forward function -/ def h2 (T : Type) (inst : ToU64 T) (x : Wrapper T) : Result U64 := @@ -118,13 +120,13 @@ def h2 (T : Type) (inst : ToU64 T) (x : Wrapper T) : Result U64 := structure ToType (Self T : Type) where to_type : Self → Result T -/- [traits::u64::{5}::to_type]: forward function -/ -def u64.to_type (self : U64) : Result Bool := +/- [traits::{u64#5}::to_type]: forward function -/ +def U64.to_type (self : U64) : Result Bool := Result.ret (self > 0#u64) -/- Trait implementation: [traits::u64::{5}] -/ -def u64.ToTypeInst : ToType U64 Bool := { - to_type := u64.to_type +/- Trait implementation: [traits::{u64#5}] -/ +def traits.ToTypeU64BoolInst : ToType U64 Bool := { + to_type := U64.to_type } /- Trait declaration: [traits::OfType] -/ @@ -154,26 +156,26 @@ def h4 structure TestType (T : Type) where _0 : T -/- [traits::TestType::{6}::test::TestType1] -/ +/- [traits::{traits::TestType<T>#6}::test::TestType1] -/ structure TestType.test.TestType1 where _0 : U64 -/- Trait declaration: [traits::TestType::{6}::test::TestTrait] -/ +/- Trait declaration: [traits::{traits::TestType<T>#6}::test::TestTrait] -/ structure TestType.test.TestTrait (Self : Type) where test : Self → Result Bool -/- [traits::TestType::{6}::test::TestType1::{0}::test]: forward function -/ +/- [traits::{traits::TestType<T>#6}::test::{traits::{traits::TestType<T>#6}::test::TestType1}::test]: forward function -/ def TestType.test.TestType1.test (self : TestType.test.TestType1) : Result Bool := Result.ret (self._0 > 1#u64) -/- Trait implementation: [traits::TestType::{6}::test::TestType1::{0}] -/ -def TestType.test.TestType1.TestTypetestTestTraitInst : TestType.test.TestTrait - TestType.test.TestType1 := { +/- Trait implementation: [traits::{traits::TestType<T>#6}::test::{traits::{traits::TestType<T>#6}::test::TestType1}] -/ +def traits.TestType.test.TestTraittraitstraitsTestTypeTtestTestType1Inst : + TestType.test.TestTrait TestType.test.TestType1 := { test := TestType.test.TestType1.test } -/- [traits::TestType::{6}::test]: forward function -/ +/- [traits::{traits::TestType<T>#6}::test]: forward function -/ def TestType.test (T : Type) (inst : ToU64 T) (self : TestType T) (x : T) : Result Bool := do @@ -186,14 +188,14 @@ def TestType.test structure BoolWrapper where _0 : Bool -/- [traits::BoolWrapper::{7}::to_type]: forward function -/ +/- [traits::{traits::BoolWrapper#7}::to_type]: forward function -/ def BoolWrapper.to_type (T : Type) (inst : ToType Bool T) (self : BoolWrapper) : Result T := inst.to_type self._0 -/- Trait implementation: [traits::BoolWrapper::{7}] -/ -def BoolWrapper.ToTypeInst (T : Type) (inst : ToType Bool T) : ToType - BoolWrapper T := { +/- Trait implementation: [traits::{traits::BoolWrapper#7}] -/ +def traits.ToTypetraitsBoolWrapperTInst (T : Type) (inst : ToType Bool T) : + ToType BoolWrapper T := { to_type := BoolWrapper.to_type T inst } @@ -211,22 +213,22 @@ structure WithConstTy (Self : Type) (LEN : Usize) where W_clause_0 : ToU64 W f : W → Array U8 LEN → Result W -/- [traits::Bool::{8}::LEN1] -/ +/- [traits::{bool#8}::LEN1] -/ def bool_len1_body : Result Usize := Result.ret 12#usize def bool_len1_c : Usize := eval_global bool_len1_body (by simp) -/- [traits::Bool::{8}::f]: merged forward/backward function +/- [traits::{bool#8}::f]: merged forward/backward function (there is a single backward function, and the forward function returns ()) -/ def Bool.f (i : U64) (a : Array U8 32#usize) : Result U64 := Result.ret i -/- Trait implementation: [traits::Bool::{8}] -/ -def Bool.WithConstTyInst : WithConstTy Bool 32#usize := { +/- Trait implementation: [traits::{bool#8}] -/ +def traits.WithConstTyBool32Inst : WithConstTy Bool 32#usize := { LEN1 := bool_len1_c LEN2 := with_const_ty_len2_c V := U8 W := U64 - W_clause_0 := u64.ToU64Inst + W_clause_0 := traits.ToU64U64Inst f := Bool.f } @@ -297,13 +299,13 @@ def order1 structure ChildTrait1 (Self : Type) where parent_clause_0 : ParentTrait1 Self -/- Trait implementation: [traits::usize::{9}] -/ -def usize.ParentTrait1Inst : ParentTrait1 Usize := { +/- Trait implementation: [traits::{usize#9}] -/ +def traits.ParentTrait1UsizeInst : ParentTrait1 Usize := { } -/- Trait implementation: [traits::usize::{10}] -/ -def usize.ChildTrait1Inst : ChildTrait1 Usize := { - parent_clause_0 := usize.ParentTrait1Inst +/- Trait implementation: [traits::{usize#10}] -/ +def traits.ChildTrait1UsizeInst : ChildTrait1 Usize := { + parent_clause_0 := traits.ParentTrait1UsizeInst } /- Trait declaration: [traits::Iterator] -/ @@ -339,31 +341,27 @@ structure ChildTrait2 (Self : Type) where parent_clause_0 : ParentTrait2 Self convert : parent_clause_0.U → Result parent_clause_0.U_clause_0.Target -/- Trait implementation: [traits::u32::{11}] -/ -def u32.WithTargetInst : WithTarget U32 := { +/- Trait implementation: [traits::{u32#11}] -/ +def traits.WithTargetU32Inst : WithTarget U32 := { Target := U32 } -/- Trait implementation: [traits::u32::{12}] -/ -def u32.ParentTrait2Inst : ParentTrait2 U32 := { +/- Trait implementation: [traits::{u32#12}] -/ +def traits.ParentTrait2U32Inst : ParentTrait2 U32 := { U := U32 - U_clause_0 := u32.WithTargetInst + U_clause_0 := traits.WithTargetU32Inst } -/- [traits::u32::{13}::convert]: forward function -/ -def u32.convert (x : U32) : Result U32 := +/- [traits::{u32#13}::convert]: forward function -/ +def U32.convert (x : U32) : Result U32 := Result.ret x -/- Trait implementation: [traits::u32::{13}] -/ -def u32.ChildTrait2Inst : ChildTrait2 U32 := { - parent_clause_0 := u32.ParentTrait2Inst - convert := u32.convert +/- Trait implementation: [traits::{u32#13}] -/ +def traits.ChildTrait2U32Inst : ChildTrait2 U32 := { + parent_clause_0 := traits.ParentTrait2U32Inst + convert := U32.convert } -/- [traits::incr_u32]: forward function -/ -def incr_u32 (x : U32) : Result U32 := - x + 1#u32 - /- Trait declaration: [traits::CFnOnce] -/ structure CFnOnce (Self Args : Type) where Output : Type @@ -380,4 +378,8 @@ structure CFn (Self Args : Type) where parent_clause_0 : CFnMut Self Args call_mut : Self → Args → Result parent_clause_0.parent_clause_0.Output +/- [traits::incr_u32]: forward function -/ +def incr_u32 (x : U32) : Result U32 := + x + 1#u32 + end traits |