diff options
-rw-r--r-- | compiler/Contexts.ml | 19 | ||||
-rw-r--r-- | compiler/InterpreterLoops.ml | 18 | ||||
-rw-r--r-- | compiler/InterpreterLoopsCore.ml | 69 | ||||
-rw-r--r-- | compiler/InterpreterLoopsJoinCtxs.ml | 29 | ||||
-rw-r--r-- | compiler/InterpreterLoopsMatchCtxs.ml | 501 | ||||
-rw-r--r-- | compiler/InterpreterUtils.ml | 30 | ||||
-rw-r--r-- | flake.lock | 48 | ||||
-rw-r--r-- | tests/coq/misc/Loops.v | 93 | ||||
-rw-r--r-- | tests/coq/traits/Traits.v | 53 | ||||
-rw-r--r-- | tests/fstar-split/misc/Loops.Clauses.Template.fst | 39 | ||||
-rw-r--r-- | tests/fstar-split/misc/Loops.Clauses.fst | 5 | ||||
-rw-r--r-- | tests/fstar-split/misc/Loops.Funs.fst | 129 | ||||
-rw-r--r-- | tests/fstar-split/misc/Loops.Types.fst | 2 | ||||
-rw-r--r-- | tests/fstar-split/traits/Traits.fst | 52 | ||||
-rw-r--r-- | tests/fstar/misc/Loops.Clauses.Template.fst | 39 | ||||
-rw-r--r-- | tests/fstar/misc/Loops.Clauses.fst | 5 | ||||
-rw-r--r-- | tests/fstar/misc/Loops.Funs.fst | 87 | ||||
-rw-r--r-- | tests/fstar/misc/Loops.Types.fst | 2 | ||||
-rw-r--r-- | tests/fstar/traits/Traits.fst | 52 | ||||
-rw-r--r-- | tests/lean/Loops.lean | 88 | ||||
-rw-r--r-- | tests/lean/Traits.lean | 52 |
21 files changed, 886 insertions, 526 deletions
diff --git a/compiler/Contexts.ml b/compiler/Contexts.ml index 5d646a61..b1dd9553 100644 --- a/compiler/Contexts.ml +++ b/compiler/Contexts.ml @@ -153,6 +153,7 @@ and env_elem = and env = env_elem list [@@deriving show, + ord, visitors { name = "iter_env"; @@ -170,6 +171,17 @@ and env = env_elem list concrete = true; }] +module OrderedBinder : Collections.OrderedType with type t = binder = struct + type t = binder + + let compare x y = compare_binder x y + let to_string x = show_binder x + let pp_t fmt x = Format.pp_print_string fmt (show_binder x) + let show_t x = show_binder x +end + +module BinderMap = Collections.MakeMap (OrderedBinder) + type interpreter_mode = ConcreteMode | SymbolicMode [@@deriving show] type config = { @@ -394,6 +406,13 @@ let ctx_push_dummy_var (ctx : eval_ctx) (vid : DummyVarId.id) (v : typed_value) : eval_ctx = { ctx with env = EBinding (BDummy vid, v) :: ctx.env } +let ctx_push_fresh_dummy_var (ctx : eval_ctx) (v : typed_value) : eval_ctx = + ctx_push_dummy_var ctx (fresh_dummy_var_id ()) v + +let ctx_push_fresh_dummy_vars (ctx : eval_ctx) (vl : typed_value list) : + eval_ctx = + List.fold_left (fun ctx v -> ctx_push_fresh_dummy_var ctx v) ctx vl + (** Remove a dummy variable from a context's environment. *) let ctx_remove_dummy_var (ctx : eval_ctx) (vid : DummyVarId.id) : eval_ctx * typed_value = diff --git a/compiler/InterpreterLoops.ml b/compiler/InterpreterLoops.ml index ed2a9587..6ee08e47 100644 --- a/compiler/InterpreterLoops.ml +++ b/compiler/InterpreterLoops.ml @@ -93,10 +93,20 @@ let eval_loop_symbolic (config : config) (meta : meta) let fp_bl_corresp = compute_fixed_point_id_correspondance fixed_ids ctx fp_ctx in - let end_expr = + log#ldebug + (lazy + ("eval_loop_symbolic: about to match the fixed-point context with the \ + original context:\n\ + - src ctx (fixed-point ctx)" ^ eval_ctx_to_string fp_ctx + ^ "\n\n-tgt ctx (original context):\n" ^ eval_ctx_to_string ctx)); + let end_expr : SymbolicAst.expression option = match_ctx_with_target config loop_id true fp_bl_corresp fp_input_svalues fixed_ids fp_ctx cf ctx in + log#ldebug + (lazy + "eval_loop_symbolic: matched the fixed-point context with the original \ + context"); (* Synthesize the loop body by evaluating it, with the continuation for after the loop starting at the *fixed point*, but with a special @@ -115,6 +125,12 @@ let eval_loop_symbolic (config : config) (meta : meta) | Continue i -> (* We don't support nested loops for now *) assert (i = 0); + log#ldebug + (lazy + ("eval_loop_symbolic: about to match the fixed-point context with \ + the context at a continue:\n\ + - src ctx (fixed-point ctx)" ^ eval_ctx_to_string fp_ctx + ^ "\n\n-tgt ctx (ctx at continue):\n" ^ eval_ctx_to_string ctx)); let cc = match_ctx_with_target config loop_id false fp_bl_corresp fp_input_svalues fixed_ids fp_ctx diff --git a/compiler/InterpreterLoopsCore.ml b/compiler/InterpreterLoopsCore.ml index ca1f8f31..e663eb42 100644 --- a/compiler/InterpreterLoopsCore.ml +++ b/compiler/InterpreterLoopsCore.ml @@ -45,16 +45,22 @@ type abs_borrows_loans_maps = { This module contains primitive match functions to instantiate the generic {!module:Aeneas.InterpreterLoopsMatchCtxs.MakeMatcher} functor. - *) + + Remark: all the functions receive as input the left context and the right context. + This is useful for printing, lookups, and also in order to check the ended + regions. + *) module type PrimMatcher = sig - val match_etys : ety -> ety -> ety - val match_rtys : rty -> rty -> rty + val match_etys : eval_ctx -> eval_ctx -> ety -> ety -> ety + val match_rtys : eval_ctx -> eval_ctx -> rty -> rty -> rty (** The input primitive values are not equal *) - val match_distinct_literals : ety -> literal -> literal -> typed_value + val match_distinct_literals : + eval_ctx -> eval_ctx -> ety -> literal -> literal -> typed_value (** The input ADTs don't have the same variant *) - val match_distinct_adts : ety -> adt_value -> adt_value -> typed_value + val match_distinct_adts : + eval_ctx -> eval_ctx -> ety -> adt_value -> adt_value -> typed_value (** The meta-value is the result of a match. @@ -67,6 +73,8 @@ module type PrimMatcher = sig calling the match function. *) val match_shared_borrows : + eval_ctx -> + eval_ctx -> (typed_value -> typed_value -> typed_value) -> ety -> borrow_id -> @@ -82,6 +90,8 @@ module type PrimMatcher = sig - [bv]: the result of matching [bv0] with [bv1] *) val match_mut_borrows : + eval_ctx -> + eval_ctx -> ety -> borrow_id -> typed_value -> @@ -97,16 +107,20 @@ module type PrimMatcher = sig [v]: the result of matching the shared values coming from the two loans *) val match_shared_loans : + eval_ctx -> + eval_ctx -> ety -> loan_id_set -> loan_id_set -> typed_value -> loan_id_set * typed_value - val match_mut_loans : ety -> loan_id -> loan_id -> loan_id + val match_mut_loans : + eval_ctx -> eval_ctx -> ety -> loan_id -> loan_id -> loan_id (** There are no constraints on the input symbolic values *) - val match_symbolic_values : symbolic_value -> symbolic_value -> symbolic_value + val match_symbolic_values : + eval_ctx -> eval_ctx -> symbolic_value -> symbolic_value -> symbolic_value (** Match a symbolic value with a value which is not symbolic. @@ -116,7 +130,7 @@ module type PrimMatcher = sig end loans in one of the two environments). *) val match_symbolic_with_other : - bool -> symbolic_value -> typed_value -> typed_value + eval_ctx -> eval_ctx -> bool -> symbolic_value -> typed_value -> typed_value (** Match a bottom value with a value which is not bottom. @@ -125,11 +139,19 @@ module type PrimMatcher = sig is important when throwing exceptions, for instance when we need to end loans in one of the two environments). *) - val match_bottom_with_other : bool -> typed_value -> typed_value + val match_bottom_with_other : + eval_ctx -> eval_ctx -> bool -> typed_value -> typed_value (** The input ADTs don't have the same variant *) val match_distinct_aadts : - rty -> adt_avalue -> rty -> adt_avalue -> rty -> typed_avalue + eval_ctx -> + eval_ctx -> + rty -> + adt_avalue -> + rty -> + adt_avalue -> + rty -> + typed_avalue (** Parameters: [ty0] @@ -139,7 +161,14 @@ module type PrimMatcher = sig [ty]: result of matching ty0 and ty1 *) val match_ashared_borrows : - rty -> borrow_id -> rty -> borrow_id -> rty -> typed_avalue + eval_ctx -> + eval_ctx -> + rty -> + borrow_id -> + rty -> + borrow_id -> + rty -> + typed_avalue (** Parameters: [ty0] @@ -152,6 +181,8 @@ module type PrimMatcher = sig [av]: result of matching av0 and av1 *) val match_amut_borrows : + eval_ctx -> + eval_ctx -> rty -> borrow_id -> typed_avalue -> @@ -176,6 +207,8 @@ module type PrimMatcher = sig [av]: result of matching av0 and av1 *) val match_ashared_loans : + eval_ctx -> + eval_ctx -> rty -> loan_id_set -> typed_value -> @@ -200,6 +233,8 @@ module type PrimMatcher = sig [av]: result of matching av0 and av1 *) val match_amut_loans : + eval_ctx -> + eval_ctx -> rty -> borrow_id -> typed_avalue -> @@ -213,7 +248,8 @@ module type PrimMatcher = sig (** Match two arbitrary avalues whose constructors don't match (this function is typically used to raise the proper exception). *) - val match_avalues : typed_avalue -> typed_avalue -> typed_avalue + val match_avalues : + eval_ctx -> eval_ctx -> typed_avalue -> typed_avalue -> typed_avalue end module type Matcher = sig @@ -221,14 +257,15 @@ module type Matcher = sig Rem.: this function raises exceptions of type {!Aeneas.InterpreterLoopsCore.ValueMatchFailure}. *) - val match_typed_values : eval_ctx -> typed_value -> typed_value -> typed_value + val match_typed_values : + eval_ctx -> eval_ctx -> typed_value -> typed_value -> typed_value (** Match two avalues. Rem.: this function raises exceptions of type {!Aeneas.InterpreterLoopsCore.ValueMatchFailure}. *) val match_typed_avalues : - eval_ctx -> typed_avalue -> typed_avalue -> typed_avalue + eval_ctx -> eval_ctx -> typed_avalue -> typed_avalue -> typed_avalue end (** See {!module:InterpreterLoopsMatchCtxs.MakeCheckEquivMatcher} and @@ -241,7 +278,6 @@ module type MatchCheckEquivState = sig a source context with a target context. *) val check_equiv : bool - val ctx : eval_ctx val rid_map : RegionId.InjSubst.t ref (** Substitution for the loan and borrow ids - used only if [check_equiv] is true *) @@ -302,9 +338,6 @@ type borrow_loan_corresp = { (* Very annoying: functors only take modules as inputs... *) module type MatchJoinState = sig - (** The current context *) - val ctx : eval_ctx - (** The current loop *) val loop_id : LoopId.id diff --git a/compiler/InterpreterLoopsJoinCtxs.ml b/compiler/InterpreterLoopsJoinCtxs.ml index 445e5abf..88f290c4 100644 --- a/compiler/InterpreterLoopsJoinCtxs.ml +++ b/compiler/InterpreterLoopsJoinCtxs.ml @@ -289,7 +289,6 @@ let mk_collapse_ctx_merge_duplicate_funs (loop_id : LoopId.id) (ctx : eval_ctx) : merge_duplicates_funcs = (* Rem.: the merge functions raise exceptions (that we catch). *) let module S : MatchJoinState = struct - let ctx = ctx let loop_id = loop_id let nabs = ref [] end in @@ -360,7 +359,7 @@ let mk_collapse_ctx_merge_duplicate_funs (loop_id : LoopId.id) (ctx : eval_ctx) assert (not (value_has_loans_or_borrows ctx sv1.value)); let ty = ty0 in let child = child0 in - let sv = M.match_typed_values ctx sv0 sv1 in + let sv = M.match_typed_values ctx ctx sv0 sv1 in let value = ALoan (ASharedLoan (ids, sv, child)) in { value; ty } in @@ -404,14 +403,6 @@ let join_ctxs (loop_id : LoopId.id) (fixed_ids : ids_sets) (ctx0 : eval_ctx) let env0 = List.rev ctx0.env in let env1 = List.rev ctx1.env in - - (* We need to pick a context for some functions like [match_typed_values]: - the context is only used to lookup module data, so we can pick whichever - we want. - TODO: this is not very clean. Maybe we should just carry this data around. - *) - let ctx = ctx0 in - let nabs = ref [] in (* Explore the environments. *) @@ -449,8 +440,6 @@ let join_ctxs (loop_id : LoopId.id) (fixed_ids : ids_sets) (ctx0 : eval_ctx) in let module S : MatchJoinState = struct - (* The context is only used to lookup module data: we can pick whichever we want *) - let ctx = ctx let loop_id = loop_id let nabs = nabs end in @@ -466,9 +455,9 @@ let join_ctxs (loop_id : LoopId.id) (fixed_ids : ids_sets) (ctx0 : eval_ctx) (lazy ("join_prefixes: BDummys:\n\n- fixed_ids:\n" ^ "\n" ^ show_ids_sets fixed_ids ^ "\n\n- value0:\n" - ^ env_elem_to_string ctx var0 + ^ env_elem_to_string ctx0 var0 ^ "\n\n- value1:\n" - ^ env_elem_to_string ctx var1 + ^ env_elem_to_string ctx1 var1 ^ "\n\n")); (* Two cases: the dummy value is an old value, in which case the bindings @@ -478,7 +467,7 @@ let join_ctxs (loop_id : LoopId.id) (fixed_ids : ids_sets) (ctx0 : eval_ctx) (* Still in the prefix: match the values *) assert (b0 = b1); let b = b0 in - let v = M.match_typed_values ctx v0 v1 in + let v = M.match_typed_values ctx0 ctx1 v0 v1 in let var = EBinding (BDummy b, v) in (* Continue *) var :: join_prefixes env0' env1') @@ -491,9 +480,9 @@ let join_ctxs (loop_id : LoopId.id) (fixed_ids : ids_sets) (ctx0 : eval_ctx) (lazy ("join_prefixes: BVars:\n\n- fixed_ids:\n" ^ "\n" ^ show_ids_sets fixed_ids ^ "\n\n- value0:\n" - ^ env_elem_to_string ctx var0 + ^ env_elem_to_string ctx0 var0 ^ "\n\n- value1:\n" - ^ env_elem_to_string ctx var1 + ^ env_elem_to_string ctx1 var1 ^ "\n\n")); (* Variable bindings *must* be in the prefix and consequently their @@ -501,7 +490,7 @@ let join_ctxs (loop_id : LoopId.id) (fixed_ids : ids_sets) (ctx0 : eval_ctx) assert (b0 = b1); (* Match the values *) let b = b0 in - let v = M.match_typed_values ctx v0 v1 in + let v = M.match_typed_values ctx0 ctx1 v0 v1 in let var = EBinding (BVar b, v) in (* Continue *) var :: join_prefixes env0' env1' @@ -510,8 +499,8 @@ let join_ctxs (loop_id : LoopId.id) (fixed_ids : ids_sets) (ctx0 : eval_ctx) log#ldebug (lazy ("join_prefixes: Abs:\n\n- fixed_ids:\n" ^ "\n" - ^ show_ids_sets fixed_ids ^ "\n\n- abs0:\n" ^ abs_to_string ctx abs0 - ^ "\n\n- abs1:\n" ^ abs_to_string ctx abs1 ^ "\n\n")); + ^ show_ids_sets fixed_ids ^ "\n\n- abs0:\n" ^ abs_to_string ctx0 abs0 + ^ "\n\n- abs1:\n" ^ abs_to_string ctx1 abs1 ^ "\n\n")); (* Same as for the dummy values: there are two cases *) if AbstractionId.Set.mem abs0.abs_id fixed_ids.aids then ( diff --git a/compiler/InterpreterLoopsMatchCtxs.ml b/compiler/InterpreterLoopsMatchCtxs.ml index 2a688fa7..4624a1e9 100644 --- a/compiler/InterpreterLoopsMatchCtxs.ml +++ b/compiler/InterpreterLoopsMatchCtxs.ml @@ -182,13 +182,20 @@ let rec match_types (match_distinct_types : ty -> ty -> ty) | _ -> match_distinct_types ty0 ty1 module MakeMatcher (M : PrimMatcher) : Matcher = struct - let rec match_typed_values (ctx : eval_ctx) (v0 : typed_value) - (v1 : typed_value) : typed_value = - let match_rec = match_typed_values ctx in - let ty = M.match_etys v0.ty v1.ty in + let rec match_typed_values (ctx0 : eval_ctx) (ctx1 : eval_ctx) + (v0 : typed_value) (v1 : typed_value) : typed_value = + let match_rec = match_typed_values ctx0 ctx1 in + let ty = M.match_etys ctx0 ctx1 v0.ty v1.ty in + (* Using ValuesUtils.value_has_borrows on purpose here: we want + to make explicit the fact that, though we have to pick + one of the two contexts (ctx0 here) to call value_has_borrows, + it doesn't matter here. *) + let value_has_borrows = + ValuesUtils.value_has_borrows ctx0.type_ctx.type_infos + in match (v0.value, v1.value) with | VLiteral lv0, VLiteral lv1 -> - if lv0 = lv1 then v1 else M.match_distinct_literals ty lv0 lv1 + if lv0 = lv1 then v1 else M.match_distinct_literals ctx0 ctx1 ty lv0 lv1 | VAdt av0, VAdt av1 -> if av0.variant_id = av1.variant_id then let fields = List.combine av0.field_values av1.field_values in @@ -201,21 +208,29 @@ module MakeMatcher (M : PrimMatcher) : Matcher = struct { value; ty = v1.ty } else ( (* For now, we don't merge ADTs which contain borrows *) - assert (not (value_has_borrows ctx v0.value)); - assert (not (value_has_borrows ctx v1.value)); + assert (not (value_has_borrows v0.value)); + assert (not (value_has_borrows v1.value)); (* Merge *) - M.match_distinct_adts ty av0 av1) + M.match_distinct_adts ctx0 ctx1 ty av0 av1) | VBottom, VBottom -> v0 | VBorrow bc0, VBorrow bc1 -> let bc = match (bc0, bc1) with | VSharedBorrow bid0, VSharedBorrow bid1 -> - let bid = M.match_shared_borrows match_rec ty bid0 bid1 in + let bid = + M.match_shared_borrows ctx0 ctx1 match_rec ty bid0 bid1 + in VSharedBorrow bid | VMutBorrow (bid0, bv0), VMutBorrow (bid1, bv1) -> let bv = match_rec bv0 bv1 in - assert (not (value_has_borrows ctx bv.value)); - let bid, bv = M.match_mut_borrows ty bid0 bv0 bid1 bv1 bv in + + assert ( + not + (ValuesUtils.value_has_borrows ctx0.type_ctx.type_infos + bv.value)); + let bid, bv = + M.match_mut_borrows ctx0 ctx1 ty bid0 bv0 bid1 bv1 bv + in VMutBorrow (bid, bv) | VReservedMutBorrow _, _ | _, VReservedMutBorrow _ @@ -235,11 +250,11 @@ module MakeMatcher (M : PrimMatcher) : Matcher = struct match (lc0, lc1) with | VSharedLoan (ids0, sv0), VSharedLoan (ids1, sv1) -> let sv = match_rec sv0 sv1 in - assert (not (value_has_borrows ctx sv.value)); - let ids, sv = M.match_shared_loans ty ids0 ids1 sv in + assert (not (value_has_borrows sv.value)); + let ids, sv = M.match_shared_loans ctx0 ctx1 ty ids0 ids1 sv in VSharedLoan (ids, sv) | VMutLoan id0, VMutLoan id1 -> - let id = M.match_mut_loans ty id0 id1 in + let id = M.match_mut_loans ctx0 ctx1 ty id0 id1 in VMutLoan id | VSharedLoan _, VMutLoan _ | VMutLoan _, VSharedLoan _ -> raise (Failure "Unreachable") @@ -248,10 +263,10 @@ module MakeMatcher (M : PrimMatcher) : Matcher = struct | VSymbolic sv0, VSymbolic sv1 -> (* For now, we force all the symbolic values containing borrows to be eagerly expanded, and we don't support nested borrows *) - assert (not (value_has_borrows ctx v0.value)); - assert (not (value_has_borrows ctx v1.value)); + assert (not (value_has_borrows v0.value)); + assert (not (value_has_borrows v1.value)); (* Match *) - let sv = M.match_symbolic_values sv0 sv1 in + let sv = M.match_symbolic_values ctx0 ctx1 sv0 sv1 in { v1 with value = VSymbolic sv } | VLoan lc, _ -> ( match lc with @@ -261,31 +276,39 @@ module MakeMatcher (M : PrimMatcher) : Matcher = struct match lc with | VSharedLoan (ids, _) -> raise (ValueMatchFailure (LoansInRight ids)) | VMutLoan id -> raise (ValueMatchFailure (LoanInRight id))) - | VSymbolic sv, _ -> M.match_symbolic_with_other true sv v1 - | _, VSymbolic sv -> M.match_symbolic_with_other false sv v0 - | VBottom, _ -> M.match_bottom_with_other true v1 - | _, VBottom -> M.match_bottom_with_other false v0 + | VSymbolic sv, _ -> M.match_symbolic_with_other ctx0 ctx1 true sv v1 + | _, VSymbolic sv -> M.match_symbolic_with_other ctx0 ctx1 false sv v0 + | VBottom, _ -> M.match_bottom_with_other ctx0 ctx1 true v1 + | _, VBottom -> M.match_bottom_with_other ctx0 ctx1 false v0 | _ -> log#ldebug (lazy ("Unexpected match case:\n- value0: " - ^ typed_value_to_string ctx v0 + ^ typed_value_to_string ctx0 v0 ^ "\n- value1: " - ^ typed_value_to_string ctx v1)); + ^ typed_value_to_string ctx1 v1)); raise (Failure "Unexpected match case") - and match_typed_avalues (ctx : eval_ctx) (v0 : typed_avalue) - (v1 : typed_avalue) : typed_avalue = + and match_typed_avalues (ctx0 : eval_ctx) (ctx1 : eval_ctx) + (v0 : typed_avalue) (v1 : typed_avalue) : typed_avalue = log#ldebug (lazy ("match_typed_avalues:\n- value0: " - ^ typed_avalue_to_string ctx v0 + ^ typed_avalue_to_string ctx0 v0 ^ "\n- value1: " - ^ typed_avalue_to_string ctx v1)); + ^ typed_avalue_to_string ctx1 v1)); + + (* Using ValuesUtils.value_has_borrows on purpose here: we want + to make explicit the fact that, though we have to pick + one of the two contexts (ctx0 here) to call value_has_borrows, + it doesn't matter here. *) + let value_has_borrows = + ValuesUtils.value_has_borrows ctx0.type_ctx.type_infos + in - let match_rec = match_typed_values ctx in - let match_arec = match_typed_avalues ctx in - let ty = M.match_rtys v0.ty v1.ty in + let match_rec = match_typed_values ctx0 ctx1 in + let match_arec = match_typed_avalues ctx0 ctx1 in + let ty = M.match_rtys ctx0 ctx1 v0.ty v1.ty in match (v0.value, v1.value) with | AAdt av0, AAdt av1 -> if av0.variant_id = av1.variant_id then @@ -298,7 +321,7 @@ module MakeMatcher (M : PrimMatcher) : Matcher = struct in { value; ty } else (* Merge *) - M.match_distinct_aadts v0.ty av0 v1.ty av1 ty + M.match_distinct_aadts ctx0 ctx1 v0.ty av0 v1.ty av1 ty | ABottom, ABottom -> mk_abottom ty | AIgnored, AIgnored -> mk_aignored ty | ABorrow bc0, ABorrow bc1 -> ( @@ -306,7 +329,7 @@ module MakeMatcher (M : PrimMatcher) : Matcher = struct match (bc0, bc1) with | ASharedBorrow bid0, ASharedBorrow bid1 -> log#ldebug (lazy "match_typed_avalues: shared borrows"); - M.match_ashared_borrows v0.ty bid0 v1.ty bid1 ty + M.match_ashared_borrows ctx0 ctx1 v0.ty bid0 v1.ty bid1 ty | AMutBorrow (bid0, av0), AMutBorrow (bid1, av1) -> log#ldebug (lazy "match_typed_avalues: mut borrows"); log#ldebug @@ -315,7 +338,7 @@ module MakeMatcher (M : PrimMatcher) : Matcher = struct let av = match_arec av0 av1 in log#ldebug (lazy "match_typed_avalues: mut borrows: matched children values"); - M.match_amut_borrows v0.ty bid0 av0 v1.ty bid1 av1 ty av + M.match_amut_borrows ctx0 ctx1 v0.ty bid0 av0 v1.ty bid1 av1 ty av | AIgnoredMutBorrow _, AIgnoredMutBorrow _ -> (* The abstractions are destructured: we shouldn't get there *) raise (Failure "Unexpected") @@ -348,8 +371,9 @@ module MakeMatcher (M : PrimMatcher) : Matcher = struct log#ldebug (lazy "match_typed_avalues: shared loans"); let sv = match_rec sv0 sv1 in let av = match_arec av0 av1 in - assert (not (value_has_borrows ctx sv.value)); - M.match_ashared_loans v0.ty ids0 sv0 av0 v1.ty ids1 sv1 av1 ty sv av + assert (not (value_has_borrows sv.value)); + M.match_ashared_loans ctx0 ctx1 v0.ty ids0 sv0 av0 v1.ty ids1 sv1 + av1 ty sv av | AMutLoan (id0, av0), AMutLoan (id1, av1) -> log#ldebug (lazy "match_typed_avalues: mut loans"); log#ldebug @@ -357,7 +381,7 @@ module MakeMatcher (M : PrimMatcher) : Matcher = struct let av = match_arec av0 av1 in log#ldebug (lazy "match_typed_avalues: mut loans: matched children values"); - M.match_amut_loans v0.ty id0 av0 v1.ty id1 av1 ty av + M.match_amut_loans ctx0 ctx1 v0.ty id0 av0 v1.ty id1 av1 ty av | AIgnoredMutLoan _, AIgnoredMutLoan _ | AIgnoredSharedLoan _, AIgnoredSharedLoan _ -> (* Those should have been filtered when destructuring the abstractions - @@ -368,7 +392,7 @@ module MakeMatcher (M : PrimMatcher) : Matcher = struct (* For now, we force all the symbolic values containing borrows to be eagerly expanded, and we don't support nested borrows *) raise (Failure "Unreachable") - | _ -> M.match_avalues v0 v1 + | _ -> M.match_avalues ctx0 ctx1 v0 v1 end module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct @@ -377,31 +401,31 @@ module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct let push_absl (absl : abs list) : unit = List.iter push_abs absl - let match_etys ty0 ty1 = + let match_etys _ _ ty0 ty1 = assert (ty0 = ty1); ty0 - let match_rtys ty0 ty1 = + let match_rtys _ _ ty0 ty1 = (* The types must be equal - in effect, this forbids to match symbolic values containing borrows *) assert (ty0 = ty1); ty0 - let match_distinct_literals (ty : ety) (_ : literal) (_ : literal) : - typed_value = + let match_distinct_literals (_ : eval_ctx) (_ : eval_ctx) (ty : ety) + (_ : literal) (_ : literal) : typed_value = mk_fresh_symbolic_typed_value_from_no_regions_ty ty - let match_distinct_adts (ty : ety) (adt0 : adt_value) (adt1 : adt_value) : - typed_value = + let match_distinct_adts (ctx0 : eval_ctx) (ctx1 : eval_ctx) (ty : ety) + (adt0 : adt_value) (adt1 : adt_value) : typed_value = (* Check that the ADTs don't contain borrows - this is redundant with checks performed by the caller, but we prefer to be safe with regards to future updates *) - let check_no_borrows (v : typed_value) = - assert (not (value_has_borrows S.ctx v.value)) + let check_no_borrows ctx (v : typed_value) = + assert (not (value_has_borrows ctx v.value)) in - List.iter check_no_borrows adt0.field_values; - List.iter check_no_borrows adt1.field_values; + List.iter (check_no_borrows ctx0) adt0.field_values; + List.iter (check_no_borrows ctx1) adt1.field_values; (* Check if there are loans: we request to end them *) let check_loans (left : bool) (fields : typed_value list) : unit = @@ -417,11 +441,17 @@ module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct check_loans true adt0.field_values; check_loans false adt1.field_values; - (* No borrows, no loans: we can introduce a symbolic value *) - mk_fresh_symbolic_typed_value_from_no_regions_ty ty + (* If there is a bottom in one of the two values, return bottom: *) + if + bottom_in_adt_value ctx0.ended_regions adt0 + || bottom_in_adt_value ctx1.ended_regions adt1 + then mk_bottom ty + else + (* No borrows, no loans, no bottoms: we can introduce a symbolic value *) + mk_fresh_symbolic_typed_value_from_no_regions_ty ty - let match_shared_borrows _ (ty : ety) (bid0 : borrow_id) (bid1 : borrow_id) : - borrow_id = + let match_shared_borrows (_ : eval_ctx) (_ : eval_ctx) _ (ty : ety) + (bid0 : borrow_id) (bid1 : borrow_id) : borrow_id = if bid0 = bid1 then bid0 else (* We replace bid0 and bid1 with a fresh borrow id, and introduce @@ -472,9 +502,9 @@ module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct (* Return the new borrow *) bid2 - let match_mut_borrows (ty : ety) (bid0 : borrow_id) (bv0 : typed_value) - (bid1 : borrow_id) (bv1 : typed_value) (bv : typed_value) : - borrow_id * typed_value = + let match_mut_borrows (ctx0 : eval_ctx) (_ : eval_ctx) (ty : ety) + (bid0 : borrow_id) (bv0 : typed_value) (bid1 : borrow_id) + (bv1 : typed_value) (bv : typed_value) : borrow_id * typed_value = if bid0 = bid1 then ( (* If the merged value is not the same as the original value, we introduce an abstraction: @@ -523,7 +553,8 @@ module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct do so, we won't introduce reborrows like above: the forward loop function will update [v], while the backward loop function will return nothing. *) - assert (not (value_has_borrows S.ctx bv.value)); + assert ( + not (ValuesUtils.value_has_borrows ctx0.type_ctx.type_infos bv.value)); if bv0 = bv1 then ( assert (bv0 = bv); @@ -617,8 +648,9 @@ module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct (* Return the new borrow *) (bid2, sv) - let match_shared_loans (_ : ety) (ids0 : loan_id_set) (ids1 : loan_id_set) - (sv : typed_value) : loan_id_set * typed_value = + let match_shared_loans (_ : eval_ctx) (_ : eval_ctx) (_ : ety) + (ids0 : loan_id_set) (ids1 : loan_id_set) (sv : typed_value) : + loan_id_set * typed_value = (* Check if the ids are the same - Rem.: we forbid the sets of loans to be different. However, if we dive inside data-structures (by using a shared borrow) the shared values might themselves contain @@ -639,15 +671,16 @@ module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct (* Return *) (ids, sv) - let match_mut_loans (_ : ety) (id0 : loan_id) (id1 : loan_id) : loan_id = + let match_mut_loans (_ : eval_ctx) (_ : eval_ctx) (_ : ety) (id0 : loan_id) + (id1 : loan_id) : loan_id = if id0 = id1 then id0 else (* We forbid this case for now: if we get there, we force to end both borrows *) raise (ValueMatchFailure (LoanInLeft id0)) - let match_symbolic_values (sv0 : symbolic_value) (sv1 : symbolic_value) : - symbolic_value = + let match_symbolic_values (ctx0 : eval_ctx) (_ : eval_ctx) + (sv0 : symbolic_value) (sv1 : symbolic_value) : symbolic_value = let id0 = sv0.sv_id in let id1 = sv1.sv_id in if id0 = id1 then ( @@ -658,19 +691,20 @@ module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct else ( (* The caller should have checked that the symbolic values don't contain borrows *) - assert (not (ty_has_borrows S.ctx.type_ctx.type_infos sv0.sv_ty)); + assert (not (ty_has_borrows ctx0.type_ctx.type_infos sv0.sv_ty)); (* We simply introduce a fresh symbolic value *) mk_fresh_symbolic_value sv0.sv_ty) - let match_symbolic_with_other (left : bool) (sv : symbolic_value) - (v : typed_value) : typed_value = + let match_symbolic_with_other (ctx0 : eval_ctx) (_ : eval_ctx) (left : bool) + (sv : symbolic_value) (v : typed_value) : typed_value = (* Check that: - there are no borrows in the symbolic value - there are no borrows in the "regular" value If there are loans in the regular value, raise an exception. *) - assert (not (ty_has_borrows S.ctx.type_ctx.type_infos sv.sv_ty)); - assert (not (value_has_borrows S.ctx v.value)); + let type_infos = ctx0.type_ctx.type_infos in + assert (not (ty_has_borrows type_infos sv.sv_ty)); + assert (not (ValuesUtils.value_has_borrows type_infos v.value)); let value_is_left = not left in (match InterpreterBorrowsCore.get_first_loan_in_value v with | None -> () @@ -683,7 +717,8 @@ module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct (* Return a fresh symbolic value *) mk_fresh_symbolic_typed_value sv.sv_ty - let match_bottom_with_other (left : bool) (v : typed_value) : typed_value = + let match_bottom_with_other (ctx0 : eval_ctx) (ctx1 : eval_ctx) (left : bool) + (v : typed_value) : typed_value = (* If there are outer loans in the non-bottom value, raise an exception. Otherwise, convert it to an abstraction and return [Bottom]. *) @@ -693,7 +728,9 @@ module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct InterpreterBorrowsCore.get_first_outer_loan_or_borrow_in_value with_borrows v with - | Some (BorrowContent _) -> raise (Failure "Unreachable") + | Some (BorrowContent _) -> + (* Can't get there: we only ask for outer *loans* *) + raise (Failure "Unreachable") | Some (LoanContent lc) -> ( match lc with | VSharedLoan (ids, _) -> @@ -703,13 +740,16 @@ module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct if value_is_left then raise (ValueMatchFailure (LoanInLeft id)) else raise (ValueMatchFailure (LoanInRight id))) | None -> + (* *) + (* Convert the value to an abstraction *) let abs_kind : abs_kind = Loop (S.loop_id, None, LoopSynthInput) in let can_end = true in let destructure_shared_values = true in + let ctx = if value_is_left then ctx0 else ctx1 in let absl = convert_value_to_abstractions abs_kind can_end - destructure_shared_values S.ctx v + destructure_shared_values ctx v in push_absl absl; (* Return [Bottom] *) @@ -718,12 +758,136 @@ module MakeJoinMatcher (S : MatchJoinState) : PrimMatcher = struct (* As explained in comments: we don't use the join matcher to join avalues, only concrete values *) - let match_distinct_aadts _ _ _ _ _ = raise (Failure "Unreachable") - let match_ashared_borrows _ _ _ _ = raise (Failure "Unreachable") - let match_amut_borrows _ _ _ _ _ _ _ _ = raise (Failure "Unreachable") - let match_ashared_loans _ _ _ _ _ _ _ _ _ _ _ = raise (Failure "Unreachable") - let match_amut_loans _ _ _ _ _ _ _ _ = raise (Failure "Unreachable") - let match_avalues _ _ = raise (Failure "Unreachable") + let match_distinct_aadts _ _ _ _ _ _ _ = raise (Failure "Unreachable") + let match_ashared_borrows _ _ _ _ _ _ = raise (Failure "Unreachable") + let match_amut_borrows _ _ _ _ _ _ _ _ _ _ = raise (Failure "Unreachable") + + let match_ashared_loans _ _ _ _ _ _ _ _ _ _ _ _ _ = + raise (Failure "Unreachable") + + let match_amut_loans _ _ _ _ _ _ _ _ _ _ = raise (Failure "Unreachable") + let match_avalues _ _ _ _ = raise (Failure "Unreachable") +end + +(* Very annoying: functors only take modules as inputs... *) +module type MatchMoveState = sig + (** The current loop *) + val loop_id : LoopId.id + + (** The moved values *) + val nvalues : typed_value list ref +end + +(* We use this matcher to move values in environment. + + To be more precise, we use this to update the target environment + (typically, the environment we have when we reach a continue statement) + by moving values into anonymous variables when the matched value + coming from the source environment (typically, a loop fixed-point) + is a bottom. + + Importantly, put aside the case where the source value is bottom + and the target value is not bottom, we always return the target value. + + Also note that the role of this matcher is simply to perform a reorganization: + the resulting environment will be matched again with the source. + This means that it is ok if we are not sure if the source environment + indeed matches the resulting target environment: it will be re-checked later. +*) +module MakeMoveMatcher (S : MatchMoveState) : PrimMatcher = struct + (** Small utility *) + let push_moved_value (v : typed_value) : unit = S.nvalues := v :: !S.nvalues + + let match_etys _ _ ty0 ty1 = + assert (ty0 = ty1); + ty0 + + let match_rtys _ _ ty0 ty1 = + (* The types must be equal - in effect, this forbids to match symbolic + values containing borrows *) + assert (ty0 = ty1); + ty0 + + let match_distinct_literals (_ : eval_ctx) (_ : eval_ctx) (ty : ety) + (_ : literal) (l : literal) : typed_value = + { value = VLiteral l; ty } + + let match_distinct_adts (_ : eval_ctx) (_ : eval_ctx) (ty : ety) + (_ : adt_value) (adt1 : adt_value) : typed_value = + (* Note that if there was a bottom inside the ADT on the left, + the value on the left should have been simplified to bottom. *) + { ty; value = VAdt adt1 } + + let match_shared_borrows (_ : eval_ctx) (_ : eval_ctx) _ (_ : ety) + (_ : borrow_id) (bid1 : borrow_id) : borrow_id = + (* There can't be bottoms in shared values *) + bid1 + + let match_mut_borrows (_ : eval_ctx) (_ : eval_ctx) (_ : ety) (_ : borrow_id) + (_ : typed_value) (bid1 : borrow_id) (bv1 : typed_value) (_ : typed_value) + : borrow_id * typed_value = + (* There can't be bottoms in borrowed values *) + (bid1, bv1) + + let match_shared_loans (_ : eval_ctx) (_ : eval_ctx) (_ : ety) + (_ : loan_id_set) (ids1 : loan_id_set) (sv : typed_value) : + loan_id_set * typed_value = + (* There can't be bottoms in shared loans *) + (ids1, sv) + + let match_mut_loans (_ : eval_ctx) (_ : eval_ctx) (_ : ety) (_ : loan_id) + (id1 : loan_id) : loan_id = + id1 + + let match_symbolic_values (_ : eval_ctx) (_ : eval_ctx) (_ : symbolic_value) + (sv1 : symbolic_value) : symbolic_value = + sv1 + + let match_symbolic_with_other (_ : eval_ctx) (_ : eval_ctx) (left : bool) + (sv : symbolic_value) (v : typed_value) : typed_value = + if left then v else mk_typed_value_from_symbolic_value sv + + let match_bottom_with_other (_ : eval_ctx) (_ : eval_ctx) (left : bool) + (v : typed_value) : typed_value = + let with_borrows = false in + if left then ( + (* The bottom is on the left *) + (* Small sanity check *) + match + InterpreterBorrowsCore.get_first_outer_loan_or_borrow_in_value + with_borrows v + with + | Some (BorrowContent _) -> + (* Can't get there: we only ask for outer *loans* *) + raise (Failure "Unreachable") + | Some (LoanContent _) -> + (* We should have ended all the outer loans *) + raise (Failure "Unexpected outer loan") + | None -> + (* Move the value - note that we shouldn't get there if we + were not allowed to move the value in the first place. *) + push_moved_value v; + (* Return [Bottom] *) + mk_bottom v.ty) + else + (* If we get there it means the source environment (e.g., the + fixed-point) has a non-bottom value, while the target environment + (e.g., the environment we have when we reach the continue) + has bottom: we shouldn't get there. *) + raise (Failure "Unreachable") + + (* As explained in comments: we don't use the join matcher to join avalues, + only concrete values *) + + let match_distinct_aadts _ _ _ _ _ _ _ = raise (Failure "Unreachable") + let match_ashared_borrows _ _ _ _ _ _ = raise (Failure "Unreachable") + let match_amut_borrows _ _ _ _ _ _ _ _ _ _ = raise (Failure "Unreachable") + + let match_ashared_loans _ _ _ _ _ _ _ _ _ _ _ _ _ = + raise (Failure "Unreachable") + + let match_amut_loans _ _ _ _ _ _ _ _ _ _ = raise (Failure "Unreachable") + let match_avalues _ _ _ _ = raise (Failure "Unreachable") end module MakeCheckEquivMatcher (S : MatchCheckEquivState) : CheckEquivMatcher = @@ -813,10 +977,10 @@ struct let match_aids = GetSetAid.match_es "match_aids: " S.aid_map (** *) - let match_etys ty0 ty1 = + let match_etys (_ : eval_ctx) (_ : eval_ctx) ty0 ty1 = if ty0 <> ty1 then raise (Distinct "match_etys") else ty0 - let match_rtys ty0 ty1 = + let match_rtys (_ : eval_ctx) (_ : eval_ctx) ty0 ty1 = let match_distinct_types _ _ = raise (Distinct "match_rtys") in let match_regions r0 r1 = match (r0, r1) with @@ -828,15 +992,15 @@ struct in match_types match_distinct_types match_regions ty0 ty1 - let match_distinct_literals (ty : ety) (_ : literal) (_ : literal) : - typed_value = + let match_distinct_literals (_ : eval_ctx) (_ : eval_ctx) (ty : ety) + (_ : literal) (_ : literal) : typed_value = mk_fresh_symbolic_typed_value_from_no_regions_ty ty - let match_distinct_adts (_ty : ety) (_adt0 : adt_value) (_adt1 : adt_value) : - typed_value = + let match_distinct_adts (_ : eval_ctx) (_ : eval_ctx) (_ty : ety) + (_adt0 : adt_value) (_adt1 : adt_value) : typed_value = raise (Distinct "match_distinct_adts") - let match_shared_borrows + let match_shared_borrows (ctx0 : eval_ctx) (ctx1 : eval_ctx) (match_typed_values : typed_value -> typed_value -> typed_value) (_ty : ety) (bid0 : borrow_id) (bid1 : borrow_id) : borrow_id = log#ldebug @@ -857,31 +1021,33 @@ struct (lazy ("MakeCheckEquivMatcher: match_shared_borrows: looked up values:" ^ "sv0: " - ^ typed_value_to_string S.ctx v0 + ^ typed_value_to_string ctx0 v0 ^ ", sv1: " - ^ typed_value_to_string S.ctx v1)); + ^ typed_value_to_string ctx1 v1)); let _ = match_typed_values v0 v1 in () in bid - let match_mut_borrows (_ty : ety) (bid0 : borrow_id) (_bv0 : typed_value) - (bid1 : borrow_id) (_bv1 : typed_value) (bv : typed_value) : - borrow_id * typed_value = + let match_mut_borrows (_ : eval_ctx) (_ : eval_ctx) (_ty : ety) + (bid0 : borrow_id) (_bv0 : typed_value) (bid1 : borrow_id) + (_bv1 : typed_value) (bv : typed_value) : borrow_id * typed_value = let bid = match_borrow_id bid0 bid1 in (bid, bv) - let match_shared_loans (_ : ety) (ids0 : loan_id_set) (ids1 : loan_id_set) - (sv : typed_value) : loan_id_set * typed_value = + let match_shared_loans (_ : eval_ctx) (_ : eval_ctx) (_ : ety) + (ids0 : loan_id_set) (ids1 : loan_id_set) (sv : typed_value) : + loan_id_set * typed_value = let ids = match_loan_ids ids0 ids1 in (ids, sv) - let match_mut_loans (_ : ety) (bid0 : loan_id) (bid1 : loan_id) : loan_id = + let match_mut_loans (_ : eval_ctx) (_ : eval_ctx) (_ : ety) (bid0 : loan_id) + (bid1 : loan_id) : loan_id = match_loan_id bid0 bid1 - let match_symbolic_values (sv0 : symbolic_value) (sv1 : symbolic_value) : - symbolic_value = + let match_symbolic_values (ctx0 : eval_ctx) (ctx1 : eval_ctx) + (sv0 : symbolic_value) (sv1 : symbolic_value) : symbolic_value = let id0 = sv0.sv_id in let id1 = sv1.sv_id in @@ -899,7 +1065,7 @@ struct let sv_id = GetSetSid.match_e "match_symbolic_values: ids: " S.sid_map id0 id1 in - let sv_ty = match_rtys sv0.sv_ty sv1.sv_ty in + let sv_ty = match_rtys ctx0 ctx1 sv0.sv_ty sv1.sv_ty in let sv = { sv_id; sv_ty } in sv else ( @@ -917,8 +1083,8 @@ struct we want *) sv0) - let match_symbolic_with_other (left : bool) (sv : symbolic_value) - (v : typed_value) : typed_value = + let match_symbolic_with_other (_ : eval_ctx) (_ : eval_ctx) (left : bool) + (sv : symbolic_value) (v : typed_value) : typed_value = if S.check_equiv then raise (Distinct "match_symbolic_with_other") else ( assert left; @@ -931,52 +1097,64 @@ struct (* Return - the returned value is not used, so we can return whatever we want *) v) - let match_bottom_with_other (left : bool) (v : typed_value) : typed_value = + let match_bottom_with_other (ctx0 : eval_ctx) (ctx1 : eval_ctx) (left : bool) + (v : typed_value) : typed_value = (* It can happen that some variables get initialized in some branches and not in some others, which causes problems when matching. *) (* TODO: the returned value is not used, while it should: in generality it should be ok to match a fixed-point with the environment we get at a continue, where the fixed point contains some bottom values. *) - if left && not (value_has_loans_or_borrows S.ctx v.value) then - mk_bottom v.ty - else raise (Distinct "match_bottom_with_other") + let value_is_left = not left in + let ctx = if value_is_left then ctx0 else ctx1 in + if left && not (value_has_loans_or_borrows ctx v.value) then mk_bottom v.ty + else + raise + (Distinct + ("match_bottom_with_other:\n- bottom value is in left environment: " + ^ Print.bool_to_string left ^ "\n- value to match with bottom:\n" + ^ show_typed_value v)) - let match_distinct_aadts _ _ _ _ _ = raise (Distinct "match_distinct_adts") + let match_distinct_aadts _ _ _ _ _ _ _ = + raise (Distinct "match_distinct_adts") - let match_ashared_borrows _ty0 bid0 _ty1 bid1 ty = + let match_ashared_borrows (_ : eval_ctx) (_ : eval_ctx) _ty0 bid0 _ty1 bid1 ty + = let bid = match_borrow_id bid0 bid1 in let value = ABorrow (ASharedBorrow bid) in { value; ty } - let match_amut_borrows _ty0 bid0 _av0 _ty1 bid1 _av1 ty av = + let match_amut_borrows (_ : eval_ctx) (_ : eval_ctx) _ty0 bid0 _av0 _ty1 bid1 + _av1 ty av = let bid = match_borrow_id bid0 bid1 in let value = ABorrow (AMutBorrow (bid, av)) in { value; ty } - let match_ashared_loans _ty0 ids0 _v0 _av0 _ty1 ids1 _v1 _av1 ty v av = + let match_ashared_loans (_ : eval_ctx) (_ : eval_ctx) _ty0 ids0 _v0 _av0 _ty1 + ids1 _v1 _av1 ty v av = let bids = match_loan_ids ids0 ids1 in let value = ALoan (ASharedLoan (bids, v, av)) in { value; ty } - let match_amut_loans _ty0 id0 _av0 _ty1 id1 _av1 ty av = + let match_amut_loans (ctx0 : eval_ctx) (ctx1 : eval_ctx) _ty0 id0 _av0 _ty1 + id1 _av1 ty av = log#ldebug (lazy ("MakeCheckEquivMatcher:match_amut_loans:" ^ "\n- id0: " ^ BorrowId.to_string id0 ^ "\n- id1: " ^ BorrowId.to_string id1 - ^ "\n- ty: " ^ ty_to_string S.ctx ty ^ "\n- av: " - ^ typed_avalue_to_string S.ctx av)); + ^ "\n- ty: " ^ ty_to_string ctx0 ty ^ "\n- av: " + ^ typed_avalue_to_string ctx1 av)); let id = match_loan_id id0 id1 in let value = ALoan (AMutLoan (id, av)) in { value; ty } - let match_avalues v0 v1 = + let match_avalues (ctx0 : eval_ctx) (ctx1 : eval_ctx) v0 v1 = log#ldebug (lazy ("avalues don't match:\n- v0: " - ^ typed_avalue_to_string S.ctx v0 + ^ typed_avalue_to_string ctx0 v0 ^ "\n- v1: " - ^ typed_avalue_to_string S.ctx v1)); + ^ typed_avalue_to_string ctx1 v1)); raise (Distinct "match_avalues") end @@ -1033,7 +1211,6 @@ let match_ctxs (check_equiv : bool) (fixed_ids : ids_sets) let module S : MatchCheckEquivState = struct let check_equiv = check_equiv - let ctx = ctx0 let rid_map = rid_map let blid_map = blid_map let borrow_id_map = borrow_id_map @@ -1060,14 +1237,6 @@ let match_ctxs (check_equiv : bool) (fixed_ids : ids_sets) && SymbolicValueId.Set.subset sids fixed_ids.sids in - (* We need to pick a context for some functions like [match_typed_values]: - the context is only used to lookup module data, so we can pick whichever - we want. - TODO: this is not very clean. Maybe we should just carry the relevant data - (i.e.e, not the whole context) around. - *) - let ctx = ctx0 in - (* Rem.: this function raises exceptions of type [Distinct] *) let match_abstractions (abs0 : abs) (abs1 : abs) : unit = let { @@ -1107,7 +1276,7 @@ let match_ctxs (check_equiv : bool) (fixed_ids : ids_sets) log#ldebug (lazy "match_abstractions: matching values"); let _ = List.map - (fun (v0, v1) -> M.match_typed_avalues ctx v0 v1) + (fun (v0, v1) -> M.match_typed_avalues ctx0 ctx1 v0 v1) (List.combine avalues0 avalues1) in log#ldebug (lazy "match_abstractions: values matched OK"); @@ -1146,12 +1315,12 @@ let match_ctxs (check_equiv : bool) (fixed_ids : ids_sets) assert ((not S.check_equiv) || ids_are_fixed ids)); (* We still match the values - allows to compute mappings (which are the identity actually) *) - let _ = M.match_typed_values ctx v0 v1 in + let _ = M.match_typed_values ctx0 ctx1 v0 v1 in match_envs env0' env1' | EBinding (BVar b0, v0) :: env0', EBinding (BVar b1, v1) :: env1' -> assert (b0 = b1); (* Match the values *) - let _ = M.match_typed_values ctx v0 v1 in + let _ = M.match_typed_values ctx0 ctx1 v0 v1 in (* Continue *) match_envs env0' env1' | EAbs abs0 :: env0', EAbs abs1 :: env1' -> @@ -1246,7 +1415,7 @@ let match_ctx_with_target (config : config) (loop_id : LoopId.id) log#ldebug (lazy - ("match_ctx_with_target:\n" ^ "\n- fixed_ids: " + ("cf_reorganize_join_tgt: match_ctx_with_target:\n" ^ "\n- fixed_ids: " ^ show_ids_sets fixed_ids ^ "\n" ^ "\n- filt_src_ctx: " ^ env_to_string src_ctx filt_src_env ^ "\n- filt_tgt_ctx: " @@ -1260,19 +1429,9 @@ let match_ctx_with_target (config : config) (loop_id : LoopId.id) let filt_tgt_env = List.filter filter filt_tgt_env in (* Match the values to check if there are loans to eliminate *) - - (* We need to pick a context for some functions like [match_typed_values]: - the context is only used to lookup module data, so we can pick whichever - we want. - TODO: this is not very clean. Maybe we should just carry this data around. - *) - let ctx = tgt_ctx in - let nabs = ref [] in let module S : MatchJoinState = struct - (* The context is only used to lookup module data: we can pick whichever we want *) - let ctx = ctx let loop_id = loop_id let nabs = nabs end in @@ -1285,16 +1444,80 @@ let match_ctx_with_target (config : config) (loop_id : LoopId.id) match (var0, var1) with | EBinding (BDummy b0, v0), EBinding (BDummy b1, v1) -> assert (b0 = b1); - let _ = M.match_typed_values ctx v0 v1 in + let _ = M.match_typed_values src_ctx tgt_ctx v0 v1 in () | EBinding (BVar b0, v0), EBinding (BVar b1, v1) -> assert (b0 = b1); - let _ = M.match_typed_values ctx v0 v1 in + let _ = M.match_typed_values src_ctx tgt_ctx v0 v1 in () | _ -> raise (Failure "Unexpected")) (List.combine filt_src_env filt_tgt_env) in (* No exception was thrown: continue *) + log#ldebug + (lazy + ("cf_reorganize_join_tgt: done with borrows/loans:\n" + ^ "\n- fixed_ids: " ^ show_ids_sets fixed_ids ^ "\n" + ^ "\n- filt_src_ctx: " + ^ env_to_string src_ctx filt_src_env + ^ "\n- filt_tgt_ctx: " + ^ env_to_string tgt_ctx filt_tgt_env)); + + (* We are done with the borrows/loans: now make sure we move all + the values which are bottom in the src environment (i.e., the + fixed-point environment) *) + (* First compute the map from binder to new value for the target + environment *) + let nvalues = ref [] in + let module S : MatchMoveState = struct + let loop_id = loop_id + let nvalues = nvalues + end in + let module MM = MakeMoveMatcher (S) in + let module M = MakeMatcher (MM) in + let var_to_new_val = + List.map + (fun (var0, var1) -> + match (var0, var1) with + | EBinding (BDummy b0, v0), EBinding ((BDummy b1 as var1), v1) -> + assert (b0 = b1); + let v = M.match_typed_values src_ctx tgt_ctx v0 v1 in + (var1, v) + | EBinding (BVar b0, v0), EBinding ((BVar b1 as var1), v1) -> + assert (b0 = b1); + let v = M.match_typed_values src_ctx tgt_ctx v0 v1 in + (var1, v) + | _ -> raise (Failure "Unexpected")) + (List.combine filt_src_env filt_tgt_env) + in + let var_to_new_val = BinderMap.of_list var_to_new_val in + + (* Update the target environment to take into account the moved values *) + let tgt_ctx = + (* Update the bindings *) + let tgt_env = + List.map + (fun b -> + match b with + | EBinding (bv, _) -> ( + match BinderMap.find_opt bv var_to_new_val with + | None -> b + | Some nv -> EBinding (bv, nv)) + | _ -> b) + tgt_ctx.env + in + (* Insert the moved values *) + let tgt_ctx = { tgt_ctx with env = tgt_env } in + ctx_push_fresh_dummy_vars tgt_ctx (List.rev !nvalues) + in + + log#ldebug + (lazy + ("cf_reorganize_join_tgt: done with borrows/loans and moves:\n" + ^ "\n- fixed_ids: " ^ show_ids_sets fixed_ids ^ "\n" ^ "\n- src_ctx: " + ^ eval_ctx_to_string src_ctx ^ "\n- tgt_ctx: " + ^ eval_ctx_to_string tgt_ctx)); + cf tgt_ctx with ValueMatchFailure e -> (* Exception: end the corresponding borrows, and continue *) @@ -1308,7 +1531,7 @@ let match_ctx_with_target (config : config) (loop_id : LoopId.id) comp cc cf_reorganize_join_tgt cf tgt_ctx in - (* Introduce the "identity" abstractions for the loop reentry. + (* Introduce the "identity" abstractions for the loop re-entry. Match the target context with the source context so as to compute how to map the borrows from the target context (i.e., the fixed point context) @@ -1363,9 +1586,9 @@ let match_ctx_with_target (config : config) (loop_id : LoopId.id) (* Debug *) log#ldebug (lazy - ("match_ctx_with_target: cf_introduce_loop_fp_abs:" ^ "\n\n- tgt_ctx: " - ^ eval_ctx_to_string tgt_ctx ^ "\n\n- src_ctx: " - ^ eval_ctx_to_string src_ctx ^ "\n\n- filt_tgt_ctx: " + ("match_ctx_with_target: cf_introduce_loop_fp_abs:" ^ "\n\n- src_ctx: " + ^ eval_ctx_to_string src_ctx ^ "\n\n- tgt_ctx: " + ^ eval_ctx_to_string tgt_ctx ^ "\n\n- filt_tgt_ctx: " ^ eval_ctx_to_string_no_filter filt_tgt_ctx ^ "\n\n- filt_src_ctx: " ^ eval_ctx_to_string_no_filter filt_src_ctx @@ -1568,8 +1791,8 @@ let match_ctx_with_target (config : config) (loop_id : LoopId.id) log#ldebug (lazy - ("match_ctx_with_target:cf_introduce_loop_fp_abs:\n- result ctx:\n" - ^ eval_ctx_to_string tgt_ctx)); + ("match_ctx_with_target: cf_introduce_loop_fp_abs: done:\n\ + - result ctx:\n" ^ eval_ctx_to_string tgt_ctx)); (* Sanity check *) if !Config.sanity_checks then diff --git a/compiler/InterpreterUtils.ml b/compiler/InterpreterUtils.ml index a1a06ee5..0817b111 100644 --- a/compiler/InterpreterUtils.ml +++ b/compiler/InterpreterUtils.ml @@ -236,28 +236,38 @@ let symbolic_value_has_ended_regions (ended_regions : RegionId.Set.t) let regions = ty_regions s.sv_ty in not (RegionId.Set.disjoint regions ended_regions) +let bottom_in_value_visitor (ended_regions : RegionId.Set.t) = + object + inherit [_] iter_typed_value + method! visit_VBottom _ = raise Found + + method! visit_symbolic_value _ s = + if symbolic_value_has_ended_regions ended_regions s then raise Found + else () + end + (** Check if a {!type:Values.value} contains [⊥]. Note that this function is very general: it also checks wether symbolic values contain already ended regions. *) let bottom_in_value (ended_regions : RegionId.Set.t) (v : typed_value) : bool = - let obj = - object - inherit [_] iter_typed_value - method! visit_VBottom _ = raise Found - - method! visit_symbolic_value _ s = - if symbolic_value_has_ended_regions ended_regions s then raise Found - else () - end - in + let obj = bottom_in_value_visitor ended_regions in (* We use exceptions *) try obj#visit_typed_value () v; false with Found -> true +let bottom_in_adt_value (ended_regions : RegionId.Set.t) (v : adt_value) : bool + = + let obj = bottom_in_value_visitor ended_regions in + (* We use exceptions *) + try + obj#visit_adt_value () v; + false + with Found -> true + let value_has_ret_symbolic_value_with_borrow_under_mut (ctx : eval_ctx) (v : typed_value) : bool = let obj = @@ -8,11 +8,11 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1703290921, - "narHash": "sha256-Jbf7JETi3XHLV19pDz8AT/Gyu8PpEfZhxO7T4W94uws=", + "lastModified": 1706179002, + "narHash": "sha256-sVAG73/MMnGOFdjUvEyEt3BD2gC6H1VhIQBX3VB7H6A=", "owner": "aeneasverif", "repo": "charon", - "rev": "f91d9d16520f0615047ccdf98b654cf47a10b0ce", + "rev": "9a4ac0c8c88c6778da31177f69b0f93bac66a88b", "type": "github" }, "original": { @@ -82,11 +82,11 @@ "systems": "systems_3" }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", "owner": "numtide", "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", "type": "github" }, "original": { @@ -131,11 +131,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1703180293, - "narHash": "sha256-zQPEPf1Q3Z4Wt86Bef9czyKfff8r8vr2LEsfR5qxoaU=", + "lastModified": 1706129113, + "narHash": "sha256-7YW9RkxDfVQFej2Lw4equuAFb5lEWwsNxW/G+fft768=", "owner": "fstarlang", "repo": "fstar", - "rev": "0806a005a879f256ff5af6736fbea4d45ea6f6ca", + "rev": "1be61a27b7413c4e35c1f9affcc6979e8c9a43d6", "type": "github" }, "original": { @@ -164,11 +164,11 @@ ] }, "locked": { - "lastModified": 1703047078, - "narHash": "sha256-LbEoFtOMFB1LVAV4O4WvOvKNjT5QTQo44mkwbzTaA2A=", + "lastModified": 1705864452, + "narHash": "sha256-vjW9bxQ8gm5c0b316NOfjqXaWDLGDCGCnXd6HcvIV+k=", "owner": "hacl-star", "repo": "hacl-star", - "rev": "1e571f77e1752449d48fe7361787cc7d01f93a49", + "rev": "73e719274a8372122994919ae2722a3b1be2bb32", "type": "github" }, "original": { @@ -194,11 +194,11 @@ ] }, "locked": { - "lastModified": 1703207646, - "narHash": "sha256-ZM7WeH5Inwottbxefjn0Acw3z6Q/iarkqldbTWt/2lQ=", + "lastModified": 1706145524, + "narHash": "sha256-gVS1+zqmQa2ghxbPgHG98QmpTqvTB9JM7G9pbe2rLbM=", "owner": "hacl-star", "repo": "hacl-nix", - "rev": "31e836f69da3cddbc1d3324de40b4901a69de320", + "rev": "757aa30e65f111714797d8ba37b38cc0f03aa6b2", "type": "github" }, "original": { @@ -223,11 +223,11 @@ ] }, "locked": { - "lastModified": 1702906344, - "narHash": "sha256-bfg18GolyW8/LcmUKh/bwryMjSQCR6GaGVuKmJIdBwQ=", + "lastModified": 1705542599, + "narHash": "sha256-wNtuRRvMzRzBE2xKreNSM9uJecDHFUXyug1+O9t+eyQ=", "owner": "fstarlang", "repo": "karamel", - "rev": "67b19d9a05f6578aec0b640fcb6e432ff18daa71", + "rev": "fdf6a10aa22f9b1b3effffeeb270229447b5bb9b", "type": "github" }, "original": { @@ -265,11 +265,11 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1703256773, - "narHash": "sha256-HuiHOhvfNVaJAOgpSMpUp24YcYxuRWMt7X77bT+sNAg=", + "lastModified": 1706176580, + "narHash": "sha256-GPvacgrLp/LGt1YU8P40dNnJBCMs376kB7SZAo6MV88=", "owner": "leanprover", "repo": "lean4", - "rev": "7c38649527c85116345df831254985afa2680dd0", + "rev": "1f4359cc80d9942d6ee651017cc17dcd62da6595", "type": "github" }, "original": { @@ -318,11 +318,11 @@ "nixpkgs": "nixpkgs_7" }, "locked": { - "lastModified": 1703256773, - "narHash": "sha256-HuiHOhvfNVaJAOgpSMpUp24YcYxuRWMt7X77bT+sNAg=", + "lastModified": 1706176580, + "narHash": "sha256-GPvacgrLp/LGt1YU8P40dNnJBCMs376kB7SZAo6MV88=", "owner": "leanprover", "repo": "lean4", - "rev": "7c38649527c85116345df831254985afa2680dd0", + "rev": "1f4359cc80d9942d6ee651017cc17dcd62da6595", "type": "github" }, "original": { diff --git a/tests/coq/misc/Loops.v b/tests/coq/misc/Loops.v index af920d41..8260db02 100644 --- a/tests/coq/misc/Loops.v +++ b/tests/coq/misc/Loops.v @@ -70,8 +70,31 @@ Definition sum_with_shared_borrows (n : nat) (max : u32) : result u32 := sum_with_shared_borrows_loop n max 0%u32 0%u32 . +(** [loops::sum_array]: loop 0: + Source: 'src/loops.rs', lines 50:0-58:1 *) +Fixpoint sum_array_loop + (N : usize) (n : nat) (a : array u32 N) (i : usize) (s : u32) : result u32 := + match n with + | O => Fail_ OutOfFuel + | S n1 => + if i s< N + then ( + i1 <- array_index_usize u32 N a i; + s1 <- u32_add s i1; + i2 <- usize_add i 1%usize; + sum_array_loop N n1 a i2 s1) + else Return s + end +. + +(** [loops::sum_array]: + Source: 'src/loops.rs', lines 50:0-50:52 *) +Definition sum_array (N : usize) (n : nat) (a : array u32 N) : result u32 := + sum_array_loop N n a 0%usize 0%u32 +. + (** [loops::clear]: loop 0: - Source: 'src/loops.rs', lines 52:0-58:1 *) + Source: 'src/loops.rs', lines 62:0-68:1 *) Fixpoint clear_loop (n : nat) (v : alloc_vec_Vec u32) (i : usize) : result (alloc_vec_Vec u32) := match n with @@ -92,14 +115,14 @@ Fixpoint clear_loop . (** [loops::clear]: - Source: 'src/loops.rs', lines 52:0-52:30 *) + Source: 'src/loops.rs', lines 62:0-62:30 *) Definition clear (n : nat) (v : alloc_vec_Vec u32) : result (alloc_vec_Vec u32) := clear_loop n v 0%usize . (** [loops::List] - Source: 'src/loops.rs', lines 60:0-60:16 *) + Source: 'src/loops.rs', lines 70:0-70:16 *) Inductive List_t (T : Type) := | List_Cons : T -> List_t T -> List_t T | List_Nil : List_t T @@ -109,7 +132,7 @@ Arguments List_Cons { _ }. Arguments List_Nil { _ }. (** [loops::list_mem]: loop 0: - Source: 'src/loops.rs', lines 66:0-75:1 *) + Source: 'src/loops.rs', lines 76:0-85:1 *) Fixpoint list_mem_loop (n : nat) (x : u32) (ls : List_t u32) : result bool := match n with | O => Fail_ OutOfFuel @@ -122,13 +145,13 @@ Fixpoint list_mem_loop (n : nat) (x : u32) (ls : List_t u32) : result bool := . (** [loops::list_mem]: - Source: 'src/loops.rs', lines 66:0-66:52 *) + Source: 'src/loops.rs', lines 76:0-76:52 *) Definition list_mem (n : nat) (x : u32) (ls : List_t u32) : result bool := list_mem_loop n x ls . (** [loops::list_nth_mut_loop]: loop 0: - Source: 'src/loops.rs', lines 78:0-88:1 *) + Source: 'src/loops.rs', lines 88:0-98:1 *) Fixpoint list_nth_mut_loop_loop (T : Type) (n : nat) (ls : List_t T) (i : u32) : result (T * (T -> result (List_t T))) @@ -155,7 +178,7 @@ Fixpoint list_nth_mut_loop_loop . (** [loops::list_nth_mut_loop]: - Source: 'src/loops.rs', lines 78:0-78:71 *) + Source: 'src/loops.rs', lines 88:0-88:71 *) Definition list_nth_mut_loop (T : Type) (n : nat) (ls : List_t T) (i : u32) : result (T * (T -> result (List_t T))) @@ -164,7 +187,7 @@ Definition list_nth_mut_loop . (** [loops::list_nth_shared_loop]: loop 0: - Source: 'src/loops.rs', lines 91:0-101:1 *) + Source: 'src/loops.rs', lines 101:0-111:1 *) Fixpoint list_nth_shared_loop_loop (T : Type) (n : nat) (ls : List_t T) (i : u32) : result T := match n with @@ -181,14 +204,14 @@ Fixpoint list_nth_shared_loop_loop . (** [loops::list_nth_shared_loop]: - Source: 'src/loops.rs', lines 91:0-91:66 *) + Source: 'src/loops.rs', lines 101:0-101:66 *) Definition list_nth_shared_loop (T : Type) (n : nat) (ls : List_t T) (i : u32) : result T := list_nth_shared_loop_loop T n ls i . (** [loops::get_elem_mut]: loop 0: - Source: 'src/loops.rs', lines 103:0-117:1 *) + Source: 'src/loops.rs', lines 113:0-127:1 *) Fixpoint get_elem_mut_loop (n : nat) (x : usize) (ls : List_t usize) : result (usize * (usize -> result (List_t usize))) @@ -214,7 +237,7 @@ Fixpoint get_elem_mut_loop . (** [loops::get_elem_mut]: - Source: 'src/loops.rs', lines 103:0-103:73 *) + Source: 'src/loops.rs', lines 113:0-113:73 *) Definition get_elem_mut (n : nat) (slots : alloc_vec_Vec (List_t usize)) (x : usize) : result (usize * (usize -> result (alloc_vec_Vec (List_t usize)))) @@ -230,7 +253,7 @@ Definition get_elem_mut . (** [loops::get_elem_shared]: loop 0: - Source: 'src/loops.rs', lines 119:0-133:1 *) + Source: 'src/loops.rs', lines 129:0-143:1 *) Fixpoint get_elem_shared_loop (n : nat) (x : usize) (ls : List_t usize) : result usize := match n with @@ -245,7 +268,7 @@ Fixpoint get_elem_shared_loop . (** [loops::get_elem_shared]: - Source: 'src/loops.rs', lines 119:0-119:68 *) + Source: 'src/loops.rs', lines 129:0-129:68 *) Definition get_elem_shared (n : nat) (slots : alloc_vec_Vec (List_t usize)) (x : usize) : result usize @@ -257,7 +280,7 @@ Definition get_elem_shared . (** [loops::id_mut]: - Source: 'src/loops.rs', lines 135:0-135:50 *) + Source: 'src/loops.rs', lines 145:0-145:50 *) Definition id_mut (T : Type) (ls : List_t T) : result ((List_t T) * (List_t T -> result (List_t T))) @@ -266,13 +289,13 @@ Definition id_mut . (** [loops::id_shared]: - Source: 'src/loops.rs', lines 139:0-139:45 *) + Source: 'src/loops.rs', lines 149:0-149:45 *) Definition id_shared (T : Type) (ls : List_t T) : result (List_t T) := Return ls . (** [loops::list_nth_mut_loop_with_id]: loop 0: - Source: 'src/loops.rs', lines 144:0-155:1 *) + Source: 'src/loops.rs', lines 154:0-165:1 *) Fixpoint list_nth_mut_loop_with_id_loop (T : Type) (n : nat) (i : u32) (ls : List_t T) : result (T * (T -> result (List_t T))) @@ -299,7 +322,7 @@ Fixpoint list_nth_mut_loop_with_id_loop . (** [loops::list_nth_mut_loop_with_id]: - Source: 'src/loops.rs', lines 144:0-144:75 *) + Source: 'src/loops.rs', lines 154:0-154:75 *) Definition list_nth_mut_loop_with_id (T : Type) (n : nat) (ls : List_t T) (i : u32) : result (T * (T -> result (List_t T))) @@ -313,7 +336,7 @@ Definition list_nth_mut_loop_with_id . (** [loops::list_nth_shared_loop_with_id]: loop 0: - Source: 'src/loops.rs', lines 158:0-169:1 *) + Source: 'src/loops.rs', lines 168:0-179:1 *) Fixpoint list_nth_shared_loop_with_id_loop (T : Type) (n : nat) (i : u32) (ls : List_t T) : result T := match n with @@ -331,14 +354,14 @@ Fixpoint list_nth_shared_loop_with_id_loop . (** [loops::list_nth_shared_loop_with_id]: - Source: 'src/loops.rs', lines 158:0-158:70 *) + Source: 'src/loops.rs', lines 168:0-168:70 *) Definition list_nth_shared_loop_with_id (T : Type) (n : nat) (ls : List_t T) (i : u32) : result T := ls1 <- id_shared T ls; list_nth_shared_loop_with_id_loop T n i ls1 . (** [loops::list_nth_mut_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 174:0-195:1 *) + Source: 'src/loops.rs', lines 184:0-205:1 *) Fixpoint list_nth_mut_loop_pair_loop (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * (T -> result (List_t T)) * (T -> result (List_t T))) @@ -372,7 +395,7 @@ Fixpoint list_nth_mut_loop_pair_loop . (** [loops::list_nth_mut_loop_pair]: - Source: 'src/loops.rs', lines 174:0-178:27 *) + Source: 'src/loops.rs', lines 184:0-188:27 *) Definition list_nth_mut_loop_pair (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * (T -> result (List_t T)) * (T -> result (List_t T))) @@ -383,7 +406,7 @@ Definition list_nth_mut_loop_pair . (** [loops::list_nth_shared_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 198:0-219:1 *) + Source: 'src/loops.rs', lines 208:0-229:1 *) Fixpoint list_nth_shared_loop_pair_loop (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -407,7 +430,7 @@ Fixpoint list_nth_shared_loop_pair_loop . (** [loops::list_nth_shared_loop_pair]: - Source: 'src/loops.rs', lines 198:0-202:19 *) + Source: 'src/loops.rs', lines 208:0-212:19 *) Definition list_nth_shared_loop_pair (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -416,7 +439,7 @@ Definition list_nth_shared_loop_pair . (** [loops::list_nth_mut_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 223:0-238:1 *) + Source: 'src/loops.rs', lines 233:0-248:1 *) Fixpoint list_nth_mut_loop_pair_merge_loop (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * ((T * T) -> result ((List_t T) * (List_t T)))) @@ -453,7 +476,7 @@ Fixpoint list_nth_mut_loop_pair_merge_loop . (** [loops::list_nth_mut_loop_pair_merge]: - Source: 'src/loops.rs', lines 223:0-227:27 *) + Source: 'src/loops.rs', lines 233:0-237:27 *) Definition list_nth_mut_loop_pair_merge (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * ((T * T) -> result ((List_t T) * (List_t T)))) @@ -464,7 +487,7 @@ Definition list_nth_mut_loop_pair_merge . (** [loops::list_nth_shared_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 241:0-256:1 *) + Source: 'src/loops.rs', lines 251:0-266:1 *) Fixpoint list_nth_shared_loop_pair_merge_loop (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -489,7 +512,7 @@ Fixpoint list_nth_shared_loop_pair_merge_loop . (** [loops::list_nth_shared_loop_pair_merge]: - Source: 'src/loops.rs', lines 241:0-245:19 *) + Source: 'src/loops.rs', lines 251:0-255:19 *) Definition list_nth_shared_loop_pair_merge (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result (T * T) @@ -498,7 +521,7 @@ Definition list_nth_shared_loop_pair_merge . (** [loops::list_nth_mut_shared_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 259:0-274:1 *) + Source: 'src/loops.rs', lines 269:0-284:1 *) Fixpoint list_nth_mut_shared_loop_pair_loop (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * (T -> result (List_t T))) @@ -529,7 +552,7 @@ Fixpoint list_nth_mut_shared_loop_pair_loop . (** [loops::list_nth_mut_shared_loop_pair]: - Source: 'src/loops.rs', lines 259:0-263:23 *) + Source: 'src/loops.rs', lines 269:0-273:23 *) Definition list_nth_mut_shared_loop_pair (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * (T -> result (List_t T))) @@ -540,7 +563,7 @@ Definition list_nth_mut_shared_loop_pair . (** [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 278:0-293:1 *) + Source: 'src/loops.rs', lines 288:0-303:1 *) Fixpoint list_nth_mut_shared_loop_pair_merge_loop (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * (T -> result (List_t T))) @@ -571,7 +594,7 @@ Fixpoint list_nth_mut_shared_loop_pair_merge_loop . (** [loops::list_nth_mut_shared_loop_pair_merge]: - Source: 'src/loops.rs', lines 278:0-282:23 *) + Source: 'src/loops.rs', lines 288:0-292:23 *) Definition list_nth_mut_shared_loop_pair_merge (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * (T -> result (List_t T))) @@ -582,7 +605,7 @@ Definition list_nth_mut_shared_loop_pair_merge . (** [loops::list_nth_shared_mut_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 297:0-312:1 *) + Source: 'src/loops.rs', lines 307:0-322:1 *) Fixpoint list_nth_shared_mut_loop_pair_loop (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * (T -> result (List_t T))) @@ -613,7 +636,7 @@ Fixpoint list_nth_shared_mut_loop_pair_loop . (** [loops::list_nth_shared_mut_loop_pair]: - Source: 'src/loops.rs', lines 297:0-301:23 *) + Source: 'src/loops.rs', lines 307:0-311:23 *) Definition list_nth_shared_mut_loop_pair (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * (T -> result (List_t T))) @@ -624,7 +647,7 @@ Definition list_nth_shared_mut_loop_pair . (** [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 316:0-331:1 *) + Source: 'src/loops.rs', lines 326:0-341:1 *) Fixpoint list_nth_shared_mut_loop_pair_merge_loop (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * (T -> result (List_t T))) @@ -655,7 +678,7 @@ Fixpoint list_nth_shared_mut_loop_pair_merge_loop . (** [loops::list_nth_shared_mut_loop_pair_merge]: - Source: 'src/loops.rs', lines 316:0-320:23 *) + Source: 'src/loops.rs', lines 326:0-330:23 *) Definition list_nth_shared_mut_loop_pair_merge (T : Type) (n : nat) (ls0 : List_t T) (ls1 : List_t T) (i : u32) : result ((T * T) * (T -> result (List_t T))) diff --git a/tests/coq/traits/Traits.v b/tests/coq/traits/Traits.v index 7abf2021..4d0beae2 100644 --- a/tests/coq/traits/Traits.v +++ b/tests/coq/traits/Traits.v @@ -402,17 +402,8 @@ Arguments mkChildTrait_t { _ }. Arguments ChildTrait_tChildTrait_t_ParentTrait0SelfInst { _ }. Arguments ChildTrait_tChildTrait_t_ParentTrait1SelfInst { _ }. -(** [traits::test_parent_trait0]: - Source: 'src/traits.rs', lines 208:0-208:57 *) -Definition test_parent_trait0 - (T : Type) (parentTrait0TInst : ParentTrait0_t T) (x : T) : - result parentTrait0TInst.(ParentTrait0_tParentTrait0_t_W) - := - parentTrait0TInst.(ParentTrait0_t_get_w) x -. - (** [traits::test_child_trait1]: - Source: 'src/traits.rs', lines 213:0-213:56 *) + Source: 'src/traits.rs', lines 209:0-209:56 *) Definition test_child_trait1 (T : Type) (childTraitTInst : ChildTrait_t T) (x : T) : result string := childTraitTInst.(ChildTrait_tChildTrait_t_ParentTrait0SelfInst).(ParentTrait0_t_get_name) @@ -420,7 +411,7 @@ Definition test_child_trait1 . (** [traits::test_child_trait2]: - Source: 'src/traits.rs', lines 217:0-217:54 *) + Source: 'src/traits.rs', lines 213:0-213:54 *) Definition test_child_trait2 (T : Type) (childTraitTInst : ChildTrait_t T) (x : T) : result @@ -431,7 +422,7 @@ Definition test_child_trait2 . (** [traits::order1]: - Source: 'src/traits.rs', lines 223:0-223:59 *) + Source: 'src/traits.rs', lines 219:0-219:59 *) Definition order1 (T U : Type) (parentTrait0TInst : ParentTrait0_t T) (parentTrait0UInst : ParentTrait0_t U) : @@ -441,7 +432,7 @@ Definition order1 . (** Trait declaration: [traits::ChildTrait1] - Source: 'src/traits.rs', lines 226:0-226:35 *) + Source: 'src/traits.rs', lines 222:0-222:35 *) Record ChildTrait1_t (Self : Type) := mkChildTrait1_t { ChildTrait1_tChildTrait1_t_ParentTrait1SelfInst : ParentTrait1_t Self; }. @@ -450,19 +441,19 @@ Arguments mkChildTrait1_t { _ }. Arguments ChildTrait1_tChildTrait1_t_ParentTrait1SelfInst { _ }. (** Trait implementation: [traits::{usize#9}] - Source: 'src/traits.rs', lines 228:0-228:27 *) + Source: 'src/traits.rs', lines 224:0-224:27 *) Definition traits_ParentTrait1UsizeInst : ParentTrait1_t usize := mkParentTrait1_t. (** Trait implementation: [traits::{usize#10}] - Source: 'src/traits.rs', lines 229:0-229:26 *) + Source: 'src/traits.rs', lines 225:0-225:26 *) Definition traits_ChildTrait1UsizeInst : ChildTrait1_t usize := {| ChildTrait1_tChildTrait1_t_ParentTrait1SelfInst := traits_ParentTrait1UsizeInst; |}. (** Trait declaration: [traits::Iterator] - Source: 'src/traits.rs', lines 233:0-233:18 *) + Source: 'src/traits.rs', lines 229:0-229:18 *) Record Iterator_t (Self : Type) := mkIterator_t { Iterator_tIterator_t_Item : Type; }. @@ -471,7 +462,7 @@ Arguments mkIterator_t { _ }. Arguments Iterator_tIterator_t_Item { _ }. (** Trait declaration: [traits::IntoIterator] - Source: 'src/traits.rs', lines 237:0-237:22 *) + Source: 'src/traits.rs', lines 233:0-233:22 *) Record IntoIterator_t (Self : Type) := mkIntoIterator_t { IntoIterator_tIntoIterator_t_Item : Type; IntoIterator_tIntoIterator_t_IntoIter : Type; @@ -488,13 +479,13 @@ Arguments IntoIterator_tIntoIterator_t_IntoIter_clause_0 { _ }. Arguments IntoIterator_t_into_iter { _ }. (** Trait declaration: [traits::FromResidual] - Source: 'src/traits.rs', lines 254:0-254:21 *) + Source: 'src/traits.rs', lines 250:0-250:21 *) Record FromResidual_t (Self T : Type) := mkFromResidual_t{}. Arguments mkFromResidual_t { _ _ }. (** Trait declaration: [traits::Try] - Source: 'src/traits.rs', lines 250:0-250:48 *) + Source: 'src/traits.rs', lines 246:0-246:48 *) Record Try_t (Self : Type) := mkTry_t { Try_tTry_t_Residual : Type; Try_tTry_t_FromResidualSelftraitsTrySelfResidualInst : FromResidual_t Self @@ -506,7 +497,7 @@ Arguments Try_tTry_t_Residual { _ }. Arguments Try_tTry_t_FromResidualSelftraitsTrySelfResidualInst { _ }. (** Trait declaration: [traits::WithTarget] - Source: 'src/traits.rs', lines 256:0-256:20 *) + Source: 'src/traits.rs', lines 252:0-252:20 *) Record WithTarget_t (Self : Type) := mkWithTarget_t { WithTarget_tWithTarget_t_Target : Type; }. @@ -515,7 +506,7 @@ Arguments mkWithTarget_t { _ }. Arguments WithTarget_tWithTarget_t_Target { _ }. (** Trait declaration: [traits::ParentTrait2] - Source: 'src/traits.rs', lines 260:0-260:22 *) + Source: 'src/traits.rs', lines 256:0-256:22 *) Record ParentTrait2_t (Self : Type) := mkParentTrait2_t { ParentTrait2_tParentTrait2_t_U : Type; ParentTrait2_tParentTrait2_t_U_clause_0 : WithTarget_t @@ -527,7 +518,7 @@ Arguments ParentTrait2_tParentTrait2_t_U { _ }. Arguments ParentTrait2_tParentTrait2_t_U_clause_0 { _ }. (** Trait declaration: [traits::ChildTrait2] - Source: 'src/traits.rs', lines 264:0-264:35 *) + Source: 'src/traits.rs', lines 260:0-260:35 *) Record ChildTrait2_t (Self : Type) := mkChildTrait2_t { ChildTrait2_tChildTrait2_t_ParentTrait2SelfInst : ParentTrait2_t Self; ChildTrait2_t_convert : @@ -541,25 +532,25 @@ Arguments ChildTrait2_tChildTrait2_t_ParentTrait2SelfInst { _ }. Arguments ChildTrait2_t_convert { _ }. (** Trait implementation: [traits::{u32#11}] - Source: 'src/traits.rs', lines 268:0-268:23 *) + Source: 'src/traits.rs', lines 264:0-264:23 *) Definition traits_WithTargetU32Inst : WithTarget_t u32 := {| WithTarget_tWithTarget_t_Target := u32; |}. (** Trait implementation: [traits::{u32#12}] - Source: 'src/traits.rs', lines 272:0-272:25 *) + Source: 'src/traits.rs', lines 268:0-268:25 *) Definition traits_ParentTrait2U32Inst : ParentTrait2_t u32 := {| ParentTrait2_tParentTrait2_t_U := u32; ParentTrait2_tParentTrait2_t_U_clause_0 := traits_WithTargetU32Inst; |}. (** [traits::{u32#13}::convert]: - Source: 'src/traits.rs', lines 277:4-277:29 *) + Source: 'src/traits.rs', lines 273:4-273:29 *) Definition u32_convert (x : u32) : result u32 := Return x. (** Trait implementation: [traits::{u32#13}] - Source: 'src/traits.rs', lines 276:0-276:24 *) + Source: 'src/traits.rs', lines 272:0-272:24 *) Definition traits_ChildTrait2U32Inst : ChildTrait2_t u32 := {| ChildTrait2_tChildTrait2_t_ParentTrait2SelfInst := traits_ParentTrait2U32Inst; @@ -567,7 +558,7 @@ Definition traits_ChildTrait2U32Inst : ChildTrait2_t u32 := {| |}. (** Trait declaration: [traits::CFnOnce] - Source: 'src/traits.rs', lines 290:0-290:23 *) + Source: 'src/traits.rs', lines 286:0-286:23 *) Record CFnOnce_t (Self Args : Type) := mkCFnOnce_t { CFnOnce_tCFnOnce_t_Output : Type; CFnOnce_t_call_once : Self -> Args -> result CFnOnce_tCFnOnce_t_Output; @@ -578,7 +569,7 @@ Arguments CFnOnce_tCFnOnce_t_Output { _ _ }. Arguments CFnOnce_t_call_once { _ _ }. (** Trait declaration: [traits::CFnMut] - Source: 'src/traits.rs', lines 296:0-296:37 *) + Source: 'src/traits.rs', lines 292:0-292:37 *) Record CFnMut_t (Self Args : Type) := mkCFnMut_t { CFnMut_tCFnMut_t_CFnOnceSelfArgsInst : CFnOnce_t Self Args; CFnMut_t_call_mut : Self -> Args -> result @@ -591,7 +582,7 @@ Arguments CFnMut_tCFnMut_t_CFnOnceSelfArgsInst { _ _ }. Arguments CFnMut_t_call_mut { _ _ }. (** Trait declaration: [traits::CFn] - Source: 'src/traits.rs', lines 300:0-300:33 *) + Source: 'src/traits.rs', lines 296:0-296:33 *) Record CFn_t (Self Args : Type) := mkCFn_t { CFn_tCFn_t_CFnMutSelfArgsInst : CFnMut_t Self Args; CFn_t_call : Self -> Args -> result @@ -603,7 +594,7 @@ Arguments CFn_tCFn_t_CFnMutSelfArgsInst { _ _ }. Arguments CFn_t_call { _ _ }. (** Trait declaration: [traits::GetTrait] - Source: 'src/traits.rs', lines 304:0-304:18 *) + Source: 'src/traits.rs', lines 300:0-300:18 *) Record GetTrait_t (Self : Type) := mkGetTrait_t { GetTrait_tGetTrait_t_W : Type; GetTrait_t_get_w : Self -> result GetTrait_tGetTrait_t_W; @@ -614,7 +605,7 @@ Arguments GetTrait_tGetTrait_t_W { _ }. Arguments GetTrait_t_get_w { _ }. (** [traits::test_get_trait]: - Source: 'src/traits.rs', lines 309:0-309:49 *) + Source: 'src/traits.rs', lines 305:0-305:49 *) Definition test_get_trait (T : Type) (getTraitTInst : GetTrait_t T) (x : T) : result getTraitTInst.(GetTrait_tGetTrait_t_W) diff --git a/tests/fstar-split/misc/Loops.Clauses.Template.fst b/tests/fstar-split/misc/Loops.Clauses.Template.fst index 6be351c6..244761d3 100644 --- a/tests/fstar-split/misc/Loops.Clauses.Template.fst +++ b/tests/fstar-split/misc/Loops.Clauses.Template.fst @@ -24,106 +24,113 @@ let sum_with_shared_borrows_loop_decreases (max : u32) (i : u32) (s : u32) : nat = admit () +(** [loops::sum_array]: decreases clause + Source: 'src/loops.rs', lines 50:0-58:1 *) +unfold +let sum_array_loop_decreases (n : usize) (a : array u32 n) (i : usize) + (s : u32) : nat = + admit () + (** [loops::clear]: decreases clause - Source: 'src/loops.rs', lines 52:0-58:1 *) + Source: 'src/loops.rs', lines 62:0-68:1 *) unfold let clear_loop_decreases (v : alloc_vec_Vec u32) (i : usize) : nat = admit () (** [loops::list_mem]: decreases clause - Source: 'src/loops.rs', lines 66:0-75:1 *) + Source: 'src/loops.rs', lines 76:0-85:1 *) unfold let list_mem_loop_decreases (x : u32) (ls : list_t u32) : nat = admit () (** [loops::list_nth_mut_loop]: decreases clause - Source: 'src/loops.rs', lines 78:0-88:1 *) + Source: 'src/loops.rs', lines 88:0-98:1 *) unfold let list_nth_mut_loop_loop_decreases (t : Type0) (ls : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_shared_loop]: decreases clause - Source: 'src/loops.rs', lines 91:0-101:1 *) + Source: 'src/loops.rs', lines 101:0-111:1 *) unfold let list_nth_shared_loop_loop_decreases (t : Type0) (ls : list_t t) (i : u32) : nat = admit () (** [loops::get_elem_mut]: decreases clause - Source: 'src/loops.rs', lines 103:0-117:1 *) + Source: 'src/loops.rs', lines 113:0-127:1 *) unfold let get_elem_mut_loop_decreases (x : usize) (ls : list_t usize) : nat = admit () (** [loops::get_elem_shared]: decreases clause - Source: 'src/loops.rs', lines 119:0-133:1 *) + Source: 'src/loops.rs', lines 129:0-143:1 *) unfold let get_elem_shared_loop_decreases (x : usize) (ls : list_t usize) : nat = admit () (** [loops::list_nth_mut_loop_with_id]: decreases clause - Source: 'src/loops.rs', lines 144:0-155:1 *) + Source: 'src/loops.rs', lines 154:0-165:1 *) unfold let list_nth_mut_loop_with_id_loop_decreases (t : Type0) (i : u32) (ls : list_t t) : nat = admit () (** [loops::list_nth_shared_loop_with_id]: decreases clause - Source: 'src/loops.rs', lines 158:0-169:1 *) + Source: 'src/loops.rs', lines 168:0-179:1 *) unfold let list_nth_shared_loop_with_id_loop_decreases (t : Type0) (i : u32) (ls : list_t t) : nat = admit () (** [loops::list_nth_mut_loop_pair]: decreases clause - Source: 'src/loops.rs', lines 174:0-195:1 *) + Source: 'src/loops.rs', lines 184:0-205:1 *) unfold let list_nth_mut_loop_pair_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_shared_loop_pair]: decreases clause - Source: 'src/loops.rs', lines 198:0-219:1 *) + Source: 'src/loops.rs', lines 208:0-229:1 *) unfold let list_nth_shared_loop_pair_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_mut_loop_pair_merge]: decreases clause - Source: 'src/loops.rs', lines 223:0-238:1 *) + Source: 'src/loops.rs', lines 233:0-248:1 *) unfold let list_nth_mut_loop_pair_merge_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_shared_loop_pair_merge]: decreases clause - Source: 'src/loops.rs', lines 241:0-256:1 *) + Source: 'src/loops.rs', lines 251:0-266:1 *) unfold let list_nth_shared_loop_pair_merge_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_mut_shared_loop_pair]: decreases clause - Source: 'src/loops.rs', lines 259:0-274:1 *) + Source: 'src/loops.rs', lines 269:0-284:1 *) unfold let list_nth_mut_shared_loop_pair_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_mut_shared_loop_pair_merge]: decreases clause - Source: 'src/loops.rs', lines 278:0-293:1 *) + Source: 'src/loops.rs', lines 288:0-303:1 *) unfold let list_nth_mut_shared_loop_pair_merge_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_shared_mut_loop_pair]: decreases clause - Source: 'src/loops.rs', lines 297:0-312:1 *) + Source: 'src/loops.rs', lines 307:0-322:1 *) unfold let list_nth_shared_mut_loop_pair_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_shared_mut_loop_pair_merge]: decreases clause - Source: 'src/loops.rs', lines 316:0-331:1 *) + Source: 'src/loops.rs', lines 326:0-341:1 *) unfold let list_nth_shared_mut_loop_pair_merge_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = diff --git a/tests/fstar-split/misc/Loops.Clauses.fst b/tests/fstar-split/misc/Loops.Clauses.fst index 75194437..13f5513d 100644 --- a/tests/fstar-split/misc/Loops.Clauses.fst +++ b/tests/fstar-split/misc/Loops.Clauses.fst @@ -19,6 +19,11 @@ unfold let sum_with_shared_borrows_loop_decreases (max : u32) (i : u32) (s : u32) : nat = if max >= i then max - i else 0 +(** [loops::sum_array]: decreases clause *) +unfold +let sum_array_loop_decreases (n : usize) (_ : array u32 n) (i : usize) (_ : u32) : nat = + if n >= i then n - i else 0 + (** [loops::clear]: decreases clause *) unfold let clear_loop_decreases (v : alloc_vec_Vec u32) (i : usize) : nat = if i <= List.Tot.length v then List.Tot.length v - i else 0 diff --git a/tests/fstar-split/misc/Loops.Funs.fst b/tests/fstar-split/misc/Loops.Funs.fst index 3168fddb..01d66726 100644 --- a/tests/fstar-split/misc/Loops.Funs.fst +++ b/tests/fstar-split/misc/Loops.Funs.fst @@ -58,9 +58,28 @@ let rec sum_with_shared_borrows_loop let sum_with_shared_borrows (max : u32) : result u32 = sum_with_shared_borrows_loop max 0 0 +(** [loops::sum_array]: loop 0: forward function + Source: 'src/loops.rs', lines 50:0-58:1 *) +let rec sum_array_loop + (n : usize) (a : array u32 n) (i : usize) (s : u32) : + Tot (result u32) (decreases (sum_array_loop_decreases n a i s)) + = + if i < n + then + let* i1 = array_index_usize u32 n a i in + let* s1 = u32_add s i1 in + let* i2 = usize_add i 1 in + sum_array_loop n a i2 s1 + else Return s + +(** [loops::sum_array]: forward function + Source: 'src/loops.rs', lines 50:0-50:52 *) +let sum_array (n : usize) (a : array u32 n) : result u32 = + sum_array_loop n a 0 0 + (** [loops::clear]: loop 0: merged forward/backward function (there is a single backward function, and the forward function returns ()) - Source: 'src/loops.rs', lines 52:0-58:1 *) + Source: 'src/loops.rs', lines 62:0-68:1 *) let rec clear_loop (v : alloc_vec_Vec u32) (i : usize) : Tot (result (alloc_vec_Vec u32)) (decreases (clear_loop_decreases v i)) @@ -77,12 +96,12 @@ let rec clear_loop (** [loops::clear]: merged forward/backward function (there is a single backward function, and the forward function returns ()) - Source: 'src/loops.rs', lines 52:0-52:30 *) + Source: 'src/loops.rs', lines 62:0-62:30 *) let clear (v : alloc_vec_Vec u32) : result (alloc_vec_Vec u32) = clear_loop v 0 (** [loops::list_mem]: loop 0: forward function - Source: 'src/loops.rs', lines 66:0-75:1 *) + Source: 'src/loops.rs', lines 76:0-85:1 *) let rec list_mem_loop (x : u32) (ls : list_t u32) : Tot (result bool) (decreases (list_mem_loop_decreases x ls)) @@ -93,12 +112,12 @@ let rec list_mem_loop end (** [loops::list_mem]: forward function - Source: 'src/loops.rs', lines 66:0-66:52 *) + Source: 'src/loops.rs', lines 76:0-76:52 *) let list_mem (x : u32) (ls : list_t u32) : result bool = list_mem_loop x ls (** [loops::list_nth_mut_loop]: loop 0: forward function - Source: 'src/loops.rs', lines 78:0-88:1 *) + Source: 'src/loops.rs', lines 88:0-98:1 *) let rec list_nth_mut_loop_loop (t : Type0) (ls : list_t t) (i : u32) : Tot (result t) (decreases (list_nth_mut_loop_loop_decreases t ls i)) @@ -112,12 +131,12 @@ let rec list_nth_mut_loop_loop end (** [loops::list_nth_mut_loop]: forward function - Source: 'src/loops.rs', lines 78:0-78:71 *) + Source: 'src/loops.rs', lines 88:0-88:71 *) let list_nth_mut_loop (t : Type0) (ls : list_t t) (i : u32) : result t = list_nth_mut_loop_loop t ls i (** [loops::list_nth_mut_loop]: loop 0: backward function 0 - Source: 'src/loops.rs', lines 78:0-88:1 *) + Source: 'src/loops.rs', lines 88:0-98:1 *) let rec list_nth_mut_loop_loop_back (t : Type0) (ls : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) (decreases (list_nth_mut_loop_loop_decreases t ls i)) @@ -134,13 +153,13 @@ let rec list_nth_mut_loop_loop_back end (** [loops::list_nth_mut_loop]: backward function 0 - Source: 'src/loops.rs', lines 78:0-78:71 *) + Source: 'src/loops.rs', lines 88:0-88:71 *) let list_nth_mut_loop_back (t : Type0) (ls : list_t t) (i : u32) (ret : t) : result (list_t t) = list_nth_mut_loop_loop_back t ls i ret (** [loops::list_nth_shared_loop]: loop 0: forward function - Source: 'src/loops.rs', lines 91:0-101:1 *) + Source: 'src/loops.rs', lines 101:0-111:1 *) let rec list_nth_shared_loop_loop (t : Type0) (ls : list_t t) (i : u32) : Tot (result t) (decreases (list_nth_shared_loop_loop_decreases t ls i)) @@ -154,12 +173,12 @@ let rec list_nth_shared_loop_loop end (** [loops::list_nth_shared_loop]: forward function - Source: 'src/loops.rs', lines 91:0-91:66 *) + Source: 'src/loops.rs', lines 101:0-101:66 *) let list_nth_shared_loop (t : Type0) (ls : list_t t) (i : u32) : result t = list_nth_shared_loop_loop t ls i (** [loops::get_elem_mut]: loop 0: forward function - Source: 'src/loops.rs', lines 103:0-117:1 *) + Source: 'src/loops.rs', lines 113:0-127:1 *) let rec get_elem_mut_loop (x : usize) (ls : list_t usize) : Tot (result usize) (decreases (get_elem_mut_loop_decreases x ls)) @@ -170,7 +189,7 @@ let rec get_elem_mut_loop end (** [loops::get_elem_mut]: forward function - Source: 'src/loops.rs', lines 103:0-103:73 *) + Source: 'src/loops.rs', lines 113:0-113:73 *) let get_elem_mut (slots : alloc_vec_Vec (list_t usize)) (x : usize) : result usize = let* l = @@ -179,7 +198,7 @@ let get_elem_mut get_elem_mut_loop x l (** [loops::get_elem_mut]: loop 0: backward function 0 - Source: 'src/loops.rs', lines 103:0-117:1 *) + Source: 'src/loops.rs', lines 113:0-127:1 *) let rec get_elem_mut_loop_back (x : usize) (ls : list_t usize) (ret : usize) : Tot (result (list_t usize)) (decreases (get_elem_mut_loop_decreases x ls)) @@ -193,7 +212,7 @@ let rec get_elem_mut_loop_back end (** [loops::get_elem_mut]: backward function 0 - Source: 'src/loops.rs', lines 103:0-103:73 *) + Source: 'src/loops.rs', lines 113:0-113:73 *) let get_elem_mut_back (slots : alloc_vec_Vec (list_t usize)) (x : usize) (ret : usize) : result (alloc_vec_Vec (list_t usize)) @@ -206,7 +225,7 @@ let get_elem_mut_back (core_slice_index_SliceIndexUsizeSliceTInst (list_t usize)) slots 0 l1 (** [loops::get_elem_shared]: loop 0: forward function - Source: 'src/loops.rs', lines 119:0-133:1 *) + Source: 'src/loops.rs', lines 129:0-143:1 *) let rec get_elem_shared_loop (x : usize) (ls : list_t usize) : Tot (result usize) (decreases (get_elem_shared_loop_decreases x ls)) @@ -217,7 +236,7 @@ let rec get_elem_shared_loop end (** [loops::get_elem_shared]: forward function - Source: 'src/loops.rs', lines 119:0-119:68 *) + Source: 'src/loops.rs', lines 129:0-129:68 *) let get_elem_shared (slots : alloc_vec_Vec (list_t usize)) (x : usize) : result usize = let* l = @@ -226,23 +245,23 @@ let get_elem_shared get_elem_shared_loop x l (** [loops::id_mut]: forward function - Source: 'src/loops.rs', lines 135:0-135:50 *) + Source: 'src/loops.rs', lines 145:0-145:50 *) let id_mut (t : Type0) (ls : list_t t) : result (list_t t) = Return ls (** [loops::id_mut]: backward function 0 - Source: 'src/loops.rs', lines 135:0-135:50 *) + Source: 'src/loops.rs', lines 145:0-145:50 *) let id_mut_back (t : Type0) (ls : list_t t) (ret : list_t t) : result (list_t t) = Return ret (** [loops::id_shared]: forward function - Source: 'src/loops.rs', lines 139:0-139:45 *) + Source: 'src/loops.rs', lines 149:0-149:45 *) let id_shared (t : Type0) (ls : list_t t) : result (list_t t) = Return ls (** [loops::list_nth_mut_loop_with_id]: loop 0: forward function - Source: 'src/loops.rs', lines 144:0-155:1 *) + Source: 'src/loops.rs', lines 154:0-165:1 *) let rec list_nth_mut_loop_with_id_loop (t : Type0) (i : u32) (ls : list_t t) : Tot (result t) (decreases (list_nth_mut_loop_with_id_loop_decreases t i ls)) @@ -256,13 +275,13 @@ let rec list_nth_mut_loop_with_id_loop end (** [loops::list_nth_mut_loop_with_id]: forward function - Source: 'src/loops.rs', lines 144:0-144:75 *) + Source: 'src/loops.rs', lines 154:0-154:75 *) let list_nth_mut_loop_with_id (t : Type0) (ls : list_t t) (i : u32) : result t = let* ls1 = id_mut t ls in list_nth_mut_loop_with_id_loop t i ls1 (** [loops::list_nth_mut_loop_with_id]: loop 0: backward function 0 - Source: 'src/loops.rs', lines 144:0-155:1 *) + Source: 'src/loops.rs', lines 154:0-165:1 *) let rec list_nth_mut_loop_with_id_loop_back (t : Type0) (i : u32) (ls : list_t t) (ret : t) : Tot (result (list_t t)) @@ -280,7 +299,7 @@ let rec list_nth_mut_loop_with_id_loop_back end (** [loops::list_nth_mut_loop_with_id]: backward function 0 - Source: 'src/loops.rs', lines 144:0-144:75 *) + Source: 'src/loops.rs', lines 154:0-154:75 *) let list_nth_mut_loop_with_id_back (t : Type0) (ls : list_t t) (i : u32) (ret : t) : result (list_t t) = let* ls1 = id_mut t ls in @@ -288,7 +307,7 @@ let list_nth_mut_loop_with_id_back id_mut_back t ls l (** [loops::list_nth_shared_loop_with_id]: loop 0: forward function - Source: 'src/loops.rs', lines 158:0-169:1 *) + Source: 'src/loops.rs', lines 168:0-179:1 *) let rec list_nth_shared_loop_with_id_loop (t : Type0) (i : u32) (ls : list_t t) : Tot (result t) @@ -303,13 +322,13 @@ let rec list_nth_shared_loop_with_id_loop end (** [loops::list_nth_shared_loop_with_id]: forward function - Source: 'src/loops.rs', lines 158:0-158:70 *) + Source: 'src/loops.rs', lines 168:0-168:70 *) let list_nth_shared_loop_with_id (t : Type0) (ls : list_t t) (i : u32) : result t = let* ls1 = id_shared t ls in list_nth_shared_loop_with_id_loop t i ls1 (** [loops::list_nth_mut_loop_pair]: loop 0: forward function - Source: 'src/loops.rs', lines 174:0-195:1 *) + Source: 'src/loops.rs', lines 184:0-205:1 *) let rec list_nth_mut_loop_pair_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -328,13 +347,13 @@ let rec list_nth_mut_loop_pair_loop end (** [loops::list_nth_mut_loop_pair]: forward function - Source: 'src/loops.rs', lines 174:0-178:27 *) + Source: 'src/loops.rs', lines 184:0-188:27 *) let list_nth_mut_loop_pair (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_mut_loop_pair_loop t ls0 ls1 i (** [loops::list_nth_mut_loop_pair]: loop 0: backward function 0 - Source: 'src/loops.rs', lines 174:0-195:1 *) + Source: 'src/loops.rs', lines 184:0-205:1 *) let rec list_nth_mut_loop_pair_loop_back'a (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -356,7 +375,7 @@ let rec list_nth_mut_loop_pair_loop_back'a end (** [loops::list_nth_mut_loop_pair]: backward function 0 - Source: 'src/loops.rs', lines 174:0-178:27 *) + Source: 'src/loops.rs', lines 184:0-188:27 *) let list_nth_mut_loop_pair_back'a (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) @@ -364,7 +383,7 @@ let list_nth_mut_loop_pair_back'a list_nth_mut_loop_pair_loop_back'a t ls0 ls1 i ret (** [loops::list_nth_mut_loop_pair]: loop 0: backward function 1 - Source: 'src/loops.rs', lines 174:0-195:1 *) + Source: 'src/loops.rs', lines 184:0-205:1 *) let rec list_nth_mut_loop_pair_loop_back'b (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -386,7 +405,7 @@ let rec list_nth_mut_loop_pair_loop_back'b end (** [loops::list_nth_mut_loop_pair]: backward function 1 - Source: 'src/loops.rs', lines 174:0-178:27 *) + Source: 'src/loops.rs', lines 184:0-188:27 *) let list_nth_mut_loop_pair_back'b (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) @@ -394,7 +413,7 @@ let list_nth_mut_loop_pair_back'b list_nth_mut_loop_pair_loop_back'b t ls0 ls1 i ret (** [loops::list_nth_shared_loop_pair]: loop 0: forward function - Source: 'src/loops.rs', lines 198:0-219:1 *) + Source: 'src/loops.rs', lines 208:0-229:1 *) let rec list_nth_shared_loop_pair_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -413,13 +432,13 @@ let rec list_nth_shared_loop_pair_loop end (** [loops::list_nth_shared_loop_pair]: forward function - Source: 'src/loops.rs', lines 198:0-202:19 *) + Source: 'src/loops.rs', lines 208:0-212:19 *) let list_nth_shared_loop_pair (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_shared_loop_pair_loop t ls0 ls1 i (** [loops::list_nth_mut_loop_pair_merge]: loop 0: forward function - Source: 'src/loops.rs', lines 223:0-238:1 *) + Source: 'src/loops.rs', lines 233:0-248:1 *) let rec list_nth_mut_loop_pair_merge_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -439,13 +458,13 @@ let rec list_nth_mut_loop_pair_merge_loop end (** [loops::list_nth_mut_loop_pair_merge]: forward function - Source: 'src/loops.rs', lines 223:0-227:27 *) + Source: 'src/loops.rs', lines 233:0-237:27 *) let list_nth_mut_loop_pair_merge (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_mut_loop_pair_merge_loop t ls0 ls1 i (** [loops::list_nth_mut_loop_pair_merge]: loop 0: backward function 0 - Source: 'src/loops.rs', lines 223:0-238:1 *) + Source: 'src/loops.rs', lines 233:0-248:1 *) let rec list_nth_mut_loop_pair_merge_loop_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : (t & t)) : Tot (result ((list_t t) & (list_t t))) @@ -468,7 +487,7 @@ let rec list_nth_mut_loop_pair_merge_loop_back end (** [loops::list_nth_mut_loop_pair_merge]: backward function 0 - Source: 'src/loops.rs', lines 223:0-227:27 *) + Source: 'src/loops.rs', lines 233:0-237:27 *) let list_nth_mut_loop_pair_merge_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : (t & t)) : result ((list_t t) & (list_t t)) @@ -476,7 +495,7 @@ let list_nth_mut_loop_pair_merge_back list_nth_mut_loop_pair_merge_loop_back t ls0 ls1 i ret (** [loops::list_nth_shared_loop_pair_merge]: loop 0: forward function - Source: 'src/loops.rs', lines 241:0-256:1 *) + Source: 'src/loops.rs', lines 251:0-266:1 *) let rec list_nth_shared_loop_pair_merge_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -497,13 +516,13 @@ let rec list_nth_shared_loop_pair_merge_loop end (** [loops::list_nth_shared_loop_pair_merge]: forward function - Source: 'src/loops.rs', lines 241:0-245:19 *) + Source: 'src/loops.rs', lines 251:0-255:19 *) let list_nth_shared_loop_pair_merge (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_shared_loop_pair_merge_loop t ls0 ls1 i (** [loops::list_nth_mut_shared_loop_pair]: loop 0: forward function - Source: 'src/loops.rs', lines 259:0-274:1 *) + Source: 'src/loops.rs', lines 269:0-284:1 *) let rec list_nth_mut_shared_loop_pair_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -524,13 +543,13 @@ let rec list_nth_mut_shared_loop_pair_loop end (** [loops::list_nth_mut_shared_loop_pair]: forward function - Source: 'src/loops.rs', lines 259:0-263:23 *) + Source: 'src/loops.rs', lines 269:0-273:23 *) let list_nth_mut_shared_loop_pair (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_mut_shared_loop_pair_loop t ls0 ls1 i (** [loops::list_nth_mut_shared_loop_pair]: loop 0: backward function 0 - Source: 'src/loops.rs', lines 259:0-274:1 *) + Source: 'src/loops.rs', lines 269:0-284:1 *) let rec list_nth_mut_shared_loop_pair_loop_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -552,7 +571,7 @@ let rec list_nth_mut_shared_loop_pair_loop_back end (** [loops::list_nth_mut_shared_loop_pair]: backward function 0 - Source: 'src/loops.rs', lines 259:0-263:23 *) + Source: 'src/loops.rs', lines 269:0-273:23 *) let list_nth_mut_shared_loop_pair_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) @@ -560,7 +579,7 @@ let list_nth_mut_shared_loop_pair_back list_nth_mut_shared_loop_pair_loop_back t ls0 ls1 i ret (** [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: forward function - Source: 'src/loops.rs', lines 278:0-293:1 *) + Source: 'src/loops.rs', lines 288:0-303:1 *) let rec list_nth_mut_shared_loop_pair_merge_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -581,13 +600,13 @@ let rec list_nth_mut_shared_loop_pair_merge_loop end (** [loops::list_nth_mut_shared_loop_pair_merge]: forward function - Source: 'src/loops.rs', lines 278:0-282:23 *) + Source: 'src/loops.rs', lines 288:0-292:23 *) let list_nth_mut_shared_loop_pair_merge (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_mut_shared_loop_pair_merge_loop t ls0 ls1 i (** [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: backward function 0 - Source: 'src/loops.rs', lines 278:0-293:1 *) + Source: 'src/loops.rs', lines 288:0-303:1 *) let rec list_nth_mut_shared_loop_pair_merge_loop_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -610,7 +629,7 @@ let rec list_nth_mut_shared_loop_pair_merge_loop_back end (** [loops::list_nth_mut_shared_loop_pair_merge]: backward function 0 - Source: 'src/loops.rs', lines 278:0-282:23 *) + Source: 'src/loops.rs', lines 288:0-292:23 *) let list_nth_mut_shared_loop_pair_merge_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) @@ -618,7 +637,7 @@ let list_nth_mut_shared_loop_pair_merge_back list_nth_mut_shared_loop_pair_merge_loop_back t ls0 ls1 i ret (** [loops::list_nth_shared_mut_loop_pair]: loop 0: forward function - Source: 'src/loops.rs', lines 297:0-312:1 *) + Source: 'src/loops.rs', lines 307:0-322:1 *) let rec list_nth_shared_mut_loop_pair_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -639,13 +658,13 @@ let rec list_nth_shared_mut_loop_pair_loop end (** [loops::list_nth_shared_mut_loop_pair]: forward function - Source: 'src/loops.rs', lines 297:0-301:23 *) + Source: 'src/loops.rs', lines 307:0-311:23 *) let list_nth_shared_mut_loop_pair (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_shared_mut_loop_pair_loop t ls0 ls1 i (** [loops::list_nth_shared_mut_loop_pair]: loop 0: backward function 1 - Source: 'src/loops.rs', lines 297:0-312:1 *) + Source: 'src/loops.rs', lines 307:0-322:1 *) let rec list_nth_shared_mut_loop_pair_loop_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -667,7 +686,7 @@ let rec list_nth_shared_mut_loop_pair_loop_back end (** [loops::list_nth_shared_mut_loop_pair]: backward function 1 - Source: 'src/loops.rs', lines 297:0-301:23 *) + Source: 'src/loops.rs', lines 307:0-311:23 *) let list_nth_shared_mut_loop_pair_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) @@ -675,7 +694,7 @@ let list_nth_shared_mut_loop_pair_back list_nth_shared_mut_loop_pair_loop_back t ls0 ls1 i ret (** [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: forward function - Source: 'src/loops.rs', lines 316:0-331:1 *) + Source: 'src/loops.rs', lines 326:0-341:1 *) let rec list_nth_shared_mut_loop_pair_merge_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -696,13 +715,13 @@ let rec list_nth_shared_mut_loop_pair_merge_loop end (** [loops::list_nth_shared_mut_loop_pair_merge]: forward function - Source: 'src/loops.rs', lines 316:0-320:23 *) + Source: 'src/loops.rs', lines 326:0-330:23 *) let list_nth_shared_mut_loop_pair_merge (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_shared_mut_loop_pair_merge_loop t ls0 ls1 i (** [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: backward function 0 - Source: 'src/loops.rs', lines 316:0-331:1 *) + Source: 'src/loops.rs', lines 326:0-341:1 *) let rec list_nth_shared_mut_loop_pair_merge_loop_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : Tot (result (list_t t)) @@ -725,7 +744,7 @@ let rec list_nth_shared_mut_loop_pair_merge_loop_back end (** [loops::list_nth_shared_mut_loop_pair_merge]: backward function 0 - Source: 'src/loops.rs', lines 316:0-320:23 *) + Source: 'src/loops.rs', lines 326:0-330:23 *) let list_nth_shared_mut_loop_pair_merge_back (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) (ret : t) : result (list_t t) diff --git a/tests/fstar-split/misc/Loops.Types.fst b/tests/fstar-split/misc/Loops.Types.fst index 8aa38290..29f56e1b 100644 --- a/tests/fstar-split/misc/Loops.Types.fst +++ b/tests/fstar-split/misc/Loops.Types.fst @@ -6,7 +6,7 @@ open Primitives #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" (** [loops::List] - Source: 'src/loops.rs', lines 60:0-60:16 *) + Source: 'src/loops.rs', lines 70:0-70:16 *) type list_t (t : Type0) = | List_Cons : t -> list_t t -> list_t t | List_Nil : list_t t diff --git a/tests/fstar-split/traits/Traits.fst b/tests/fstar-split/traits/Traits.fst index d3847590..a815406f 100644 --- a/tests/fstar-split/traits/Traits.fst +++ b/tests/fstar-split/traits/Traits.fst @@ -326,22 +326,14 @@ noeq type childTrait_t (self : Type0) = { parentTrait1SelfInst : parentTrait1_t self; } -(** [traits::test_parent_trait0]: forward function - Source: 'src/traits.rs', lines 208:0-208:57 *) -let test_parent_trait0 - (t : Type0) (parentTrait0TInst : parentTrait0_t t) (x : t) : - result parentTrait0TInst.tW - = - parentTrait0TInst.get_w x - (** [traits::test_child_trait1]: forward function - Source: 'src/traits.rs', lines 213:0-213:56 *) + Source: 'src/traits.rs', lines 209:0-209:56 *) let test_child_trait1 (t : Type0) (childTraitTInst : childTrait_t t) (x : t) : result string = childTraitTInst.parentTrait0SelfInst.get_name x (** [traits::test_child_trait2]: forward function - Source: 'src/traits.rs', lines 217:0-217:54 *) + Source: 'src/traits.rs', lines 213:0-213:54 *) let test_child_trait2 (t : Type0) (childTraitTInst : childTrait_t t) (x : t) : result childTraitTInst.parentTrait0SelfInst.tW @@ -349,7 +341,7 @@ let test_child_trait2 childTraitTInst.parentTrait0SelfInst.get_w x (** [traits::order1]: forward function - Source: 'src/traits.rs', lines 223:0-223:59 *) + Source: 'src/traits.rs', lines 219:0-219:59 *) let order1 (t u : Type0) (parentTrait0TInst : parentTrait0_t t) (parentTrait0UInst : parentTrait0_t u) : @@ -358,27 +350,27 @@ let order1 Return () (** Trait declaration: [traits::ChildTrait1] - Source: 'src/traits.rs', lines 226:0-226:35 *) + Source: 'src/traits.rs', lines 222:0-222:35 *) noeq type childTrait1_t (self : Type0) = { parentTrait1SelfInst : parentTrait1_t self; } (** Trait implementation: [traits::{usize#9}] - Source: 'src/traits.rs', lines 228:0-228:27 *) + Source: 'src/traits.rs', lines 224:0-224:27 *) let traits_ParentTrait1UsizeInst : parentTrait1_t usize = () (** Trait implementation: [traits::{usize#10}] - Source: 'src/traits.rs', lines 229:0-229:26 *) + Source: 'src/traits.rs', lines 225:0-225:26 *) let traits_ChildTrait1UsizeInst : childTrait1_t usize = { parentTrait1SelfInst = traits_ParentTrait1UsizeInst; } (** Trait declaration: [traits::Iterator] - Source: 'src/traits.rs', lines 233:0-233:18 *) + Source: 'src/traits.rs', lines 229:0-229:18 *) noeq type iterator_t (self : Type0) = { tItem : Type0; } (** Trait declaration: [traits::IntoIterator] - Source: 'src/traits.rs', lines 237:0-237:22 *) + Source: 'src/traits.rs', lines 233:0-233:22 *) noeq type intoIterator_t (self : Type0) = { tItem : Type0; tIntoIter : Type0; @@ -387,29 +379,29 @@ noeq type intoIterator_t (self : Type0) = { } (** Trait declaration: [traits::FromResidual] - Source: 'src/traits.rs', lines 254:0-254:21 *) + Source: 'src/traits.rs', lines 250:0-250:21 *) type fromResidual_t (self t : Type0) = unit (** Trait declaration: [traits::Try] - Source: 'src/traits.rs', lines 250:0-250:48 *) + Source: 'src/traits.rs', lines 246:0-246:48 *) noeq type try_t (self : Type0) = { tResidual : Type0; fromResidualSelftraitsTrySelfResidualInst : fromResidual_t self tResidual; } (** Trait declaration: [traits::WithTarget] - Source: 'src/traits.rs', lines 256:0-256:20 *) + Source: 'src/traits.rs', lines 252:0-252:20 *) noeq type withTarget_t (self : Type0) = { tTarget : Type0; } (** Trait declaration: [traits::ParentTrait2] - Source: 'src/traits.rs', lines 260:0-260:22 *) + Source: 'src/traits.rs', lines 256:0-256:22 *) noeq type parentTrait2_t (self : Type0) = { tU : Type0; tU_clause_0 : withTarget_t tU; } (** Trait declaration: [traits::ChildTrait2] - Source: 'src/traits.rs', lines 264:0-264:35 *) + Source: 'src/traits.rs', lines 260:0-260:35 *) noeq type childTrait2_t (self : Type0) = { parentTrait2SelfInst : parentTrait2_t self; convert : parentTrait2SelfInst.tU -> result @@ -417,37 +409,37 @@ noeq type childTrait2_t (self : Type0) = { } (** Trait implementation: [traits::{u32#11}] - Source: 'src/traits.rs', lines 268:0-268:23 *) + Source: 'src/traits.rs', lines 264:0-264:23 *) let traits_WithTargetU32Inst : withTarget_t u32 = { tTarget = u32; } (** Trait implementation: [traits::{u32#12}] - Source: 'src/traits.rs', lines 272:0-272:25 *) + Source: 'src/traits.rs', lines 268:0-268:25 *) let traits_ParentTrait2U32Inst : parentTrait2_t u32 = { tU = u32; tU_clause_0 = traits_WithTargetU32Inst; } (** [traits::{u32#13}::convert]: forward function - Source: 'src/traits.rs', lines 277:4-277:29 *) + Source: 'src/traits.rs', lines 273:4-273:29 *) let u32_convert (x : u32) : result u32 = Return x (** Trait implementation: [traits::{u32#13}] - Source: 'src/traits.rs', lines 276:0-276:24 *) + Source: 'src/traits.rs', lines 272:0-272:24 *) let traits_ChildTrait2U32Inst : childTrait2_t u32 = { parentTrait2SelfInst = traits_ParentTrait2U32Inst; convert = u32_convert; } (** Trait declaration: [traits::CFnOnce] - Source: 'src/traits.rs', lines 290:0-290:23 *) + Source: 'src/traits.rs', lines 286:0-286:23 *) noeq type cFnOnce_t (self args : Type0) = { tOutput : Type0; call_once : self -> args -> result tOutput; } (** Trait declaration: [traits::CFnMut] - Source: 'src/traits.rs', lines 296:0-296:37 *) + Source: 'src/traits.rs', lines 292:0-292:37 *) noeq type cFnMut_t (self args : Type0) = { cFnOnceSelfArgsInst : cFnOnce_t self args; call_mut : self -> args -> result cFnOnceSelfArgsInst.tOutput; @@ -455,19 +447,19 @@ noeq type cFnMut_t (self args : Type0) = { } (** Trait declaration: [traits::CFn] - Source: 'src/traits.rs', lines 300:0-300:33 *) + Source: 'src/traits.rs', lines 296:0-296:33 *) noeq type cFn_t (self args : Type0) = { cFnMutSelfArgsInst : cFnMut_t self args; call : self -> args -> result cFnMutSelfArgsInst.cFnOnceSelfArgsInst.tOutput; } (** Trait declaration: [traits::GetTrait] - Source: 'src/traits.rs', lines 304:0-304:18 *) + Source: 'src/traits.rs', lines 300:0-300:18 *) noeq type getTrait_t (self : Type0) = { tW : Type0; get_w : self -> result tW; } (** [traits::test_get_trait]: forward function - Source: 'src/traits.rs', lines 309:0-309:49 *) + Source: 'src/traits.rs', lines 305:0-305:49 *) let test_get_trait (t : Type0) (getTraitTInst : getTrait_t t) (x : t) : result getTraitTInst.tW diff --git a/tests/fstar/misc/Loops.Clauses.Template.fst b/tests/fstar/misc/Loops.Clauses.Template.fst index 6be351c6..244761d3 100644 --- a/tests/fstar/misc/Loops.Clauses.Template.fst +++ b/tests/fstar/misc/Loops.Clauses.Template.fst @@ -24,106 +24,113 @@ let sum_with_shared_borrows_loop_decreases (max : u32) (i : u32) (s : u32) : nat = admit () +(** [loops::sum_array]: decreases clause + Source: 'src/loops.rs', lines 50:0-58:1 *) +unfold +let sum_array_loop_decreases (n : usize) (a : array u32 n) (i : usize) + (s : u32) : nat = + admit () + (** [loops::clear]: decreases clause - Source: 'src/loops.rs', lines 52:0-58:1 *) + Source: 'src/loops.rs', lines 62:0-68:1 *) unfold let clear_loop_decreases (v : alloc_vec_Vec u32) (i : usize) : nat = admit () (** [loops::list_mem]: decreases clause - Source: 'src/loops.rs', lines 66:0-75:1 *) + Source: 'src/loops.rs', lines 76:0-85:1 *) unfold let list_mem_loop_decreases (x : u32) (ls : list_t u32) : nat = admit () (** [loops::list_nth_mut_loop]: decreases clause - Source: 'src/loops.rs', lines 78:0-88:1 *) + Source: 'src/loops.rs', lines 88:0-98:1 *) unfold let list_nth_mut_loop_loop_decreases (t : Type0) (ls : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_shared_loop]: decreases clause - Source: 'src/loops.rs', lines 91:0-101:1 *) + Source: 'src/loops.rs', lines 101:0-111:1 *) unfold let list_nth_shared_loop_loop_decreases (t : Type0) (ls : list_t t) (i : u32) : nat = admit () (** [loops::get_elem_mut]: decreases clause - Source: 'src/loops.rs', lines 103:0-117:1 *) + Source: 'src/loops.rs', lines 113:0-127:1 *) unfold let get_elem_mut_loop_decreases (x : usize) (ls : list_t usize) : nat = admit () (** [loops::get_elem_shared]: decreases clause - Source: 'src/loops.rs', lines 119:0-133:1 *) + Source: 'src/loops.rs', lines 129:0-143:1 *) unfold let get_elem_shared_loop_decreases (x : usize) (ls : list_t usize) : nat = admit () (** [loops::list_nth_mut_loop_with_id]: decreases clause - Source: 'src/loops.rs', lines 144:0-155:1 *) + Source: 'src/loops.rs', lines 154:0-165:1 *) unfold let list_nth_mut_loop_with_id_loop_decreases (t : Type0) (i : u32) (ls : list_t t) : nat = admit () (** [loops::list_nth_shared_loop_with_id]: decreases clause - Source: 'src/loops.rs', lines 158:0-169:1 *) + Source: 'src/loops.rs', lines 168:0-179:1 *) unfold let list_nth_shared_loop_with_id_loop_decreases (t : Type0) (i : u32) (ls : list_t t) : nat = admit () (** [loops::list_nth_mut_loop_pair]: decreases clause - Source: 'src/loops.rs', lines 174:0-195:1 *) + Source: 'src/loops.rs', lines 184:0-205:1 *) unfold let list_nth_mut_loop_pair_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_shared_loop_pair]: decreases clause - Source: 'src/loops.rs', lines 198:0-219:1 *) + Source: 'src/loops.rs', lines 208:0-229:1 *) unfold let list_nth_shared_loop_pair_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_mut_loop_pair_merge]: decreases clause - Source: 'src/loops.rs', lines 223:0-238:1 *) + Source: 'src/loops.rs', lines 233:0-248:1 *) unfold let list_nth_mut_loop_pair_merge_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_shared_loop_pair_merge]: decreases clause - Source: 'src/loops.rs', lines 241:0-256:1 *) + Source: 'src/loops.rs', lines 251:0-266:1 *) unfold let list_nth_shared_loop_pair_merge_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_mut_shared_loop_pair]: decreases clause - Source: 'src/loops.rs', lines 259:0-274:1 *) + Source: 'src/loops.rs', lines 269:0-284:1 *) unfold let list_nth_mut_shared_loop_pair_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_mut_shared_loop_pair_merge]: decreases clause - Source: 'src/loops.rs', lines 278:0-293:1 *) + Source: 'src/loops.rs', lines 288:0-303:1 *) unfold let list_nth_mut_shared_loop_pair_merge_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_shared_mut_loop_pair]: decreases clause - Source: 'src/loops.rs', lines 297:0-312:1 *) + Source: 'src/loops.rs', lines 307:0-322:1 *) unfold let list_nth_shared_mut_loop_pair_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = admit () (** [loops::list_nth_shared_mut_loop_pair_merge]: decreases clause - Source: 'src/loops.rs', lines 316:0-331:1 *) + Source: 'src/loops.rs', lines 326:0-341:1 *) unfold let list_nth_shared_mut_loop_pair_merge_loop_decreases (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : nat = diff --git a/tests/fstar/misc/Loops.Clauses.fst b/tests/fstar/misc/Loops.Clauses.fst index 75194437..13f5513d 100644 --- a/tests/fstar/misc/Loops.Clauses.fst +++ b/tests/fstar/misc/Loops.Clauses.fst @@ -19,6 +19,11 @@ unfold let sum_with_shared_borrows_loop_decreases (max : u32) (i : u32) (s : u32) : nat = if max >= i then max - i else 0 +(** [loops::sum_array]: decreases clause *) +unfold +let sum_array_loop_decreases (n : usize) (_ : array u32 n) (i : usize) (_ : u32) : nat = + if n >= i then n - i else 0 + (** [loops::clear]: decreases clause *) unfold let clear_loop_decreases (v : alloc_vec_Vec u32) (i : usize) : nat = if i <= List.Tot.length v then List.Tot.length v - i else 0 diff --git a/tests/fstar/misc/Loops.Funs.fst b/tests/fstar/misc/Loops.Funs.fst index 88389300..209c48cd 100644 --- a/tests/fstar/misc/Loops.Funs.fst +++ b/tests/fstar/misc/Loops.Funs.fst @@ -58,8 +58,27 @@ let rec sum_with_shared_borrows_loop let sum_with_shared_borrows (max : u32) : result u32 = sum_with_shared_borrows_loop max 0 0 +(** [loops::sum_array]: loop 0: + Source: 'src/loops.rs', lines 50:0-58:1 *) +let rec sum_array_loop + (n : usize) (a : array u32 n) (i : usize) (s : u32) : + Tot (result u32) (decreases (sum_array_loop_decreases n a i s)) + = + if i < n + then + let* i1 = array_index_usize u32 n a i in + let* s1 = u32_add s i1 in + let* i2 = usize_add i 1 in + sum_array_loop n a i2 s1 + else Return s + +(** [loops::sum_array]: + Source: 'src/loops.rs', lines 50:0-50:52 *) +let sum_array (n : usize) (a : array u32 n) : result u32 = + sum_array_loop n a 0 0 + (** [loops::clear]: loop 0: - Source: 'src/loops.rs', lines 52:0-58:1 *) + Source: 'src/loops.rs', lines 62:0-68:1 *) let rec clear_loop (v : alloc_vec_Vec u32) (i : usize) : Tot (result (alloc_vec_Vec u32)) (decreases (clear_loop_decreases v i)) @@ -76,12 +95,12 @@ let rec clear_loop else Return v (** [loops::clear]: - Source: 'src/loops.rs', lines 52:0-52:30 *) + Source: 'src/loops.rs', lines 62:0-62:30 *) let clear (v : alloc_vec_Vec u32) : result (alloc_vec_Vec u32) = clear_loop v 0 (** [loops::list_mem]: loop 0: - Source: 'src/loops.rs', lines 66:0-75:1 *) + Source: 'src/loops.rs', lines 76:0-85:1 *) let rec list_mem_loop (x : u32) (ls : list_t u32) : Tot (result bool) (decreases (list_mem_loop_decreases x ls)) @@ -92,12 +111,12 @@ let rec list_mem_loop end (** [loops::list_mem]: - Source: 'src/loops.rs', lines 66:0-66:52 *) + Source: 'src/loops.rs', lines 76:0-76:52 *) let list_mem (x : u32) (ls : list_t u32) : result bool = list_mem_loop x ls (** [loops::list_nth_mut_loop]: loop 0: - Source: 'src/loops.rs', lines 78:0-88:1 *) + Source: 'src/loops.rs', lines 88:0-98:1 *) let rec list_nth_mut_loop_loop (t : Type0) (ls : list_t t) (i : u32) : Tot (result (t & (t -> result (list_t t)))) @@ -116,7 +135,7 @@ let rec list_nth_mut_loop_loop end (** [loops::list_nth_mut_loop]: - Source: 'src/loops.rs', lines 78:0-78:71 *) + Source: 'src/loops.rs', lines 88:0-88:71 *) let list_nth_mut_loop (t : Type0) (ls : list_t t) (i : u32) : result (t & (t -> result (list_t t))) @@ -124,7 +143,7 @@ let list_nth_mut_loop let* (x, back) = list_nth_mut_loop_loop t ls i in Return (x, back) (** [loops::list_nth_shared_loop]: loop 0: - Source: 'src/loops.rs', lines 91:0-101:1 *) + Source: 'src/loops.rs', lines 101:0-111:1 *) let rec list_nth_shared_loop_loop (t : Type0) (ls : list_t t) (i : u32) : Tot (result t) (decreases (list_nth_shared_loop_loop_decreases t ls i)) @@ -138,12 +157,12 @@ let rec list_nth_shared_loop_loop end (** [loops::list_nth_shared_loop]: - Source: 'src/loops.rs', lines 91:0-91:66 *) + Source: 'src/loops.rs', lines 101:0-101:66 *) let list_nth_shared_loop (t : Type0) (ls : list_t t) (i : u32) : result t = list_nth_shared_loop_loop t ls i (** [loops::get_elem_mut]: loop 0: - Source: 'src/loops.rs', lines 103:0-117:1 *) + Source: 'src/loops.rs', lines 113:0-127:1 *) let rec get_elem_mut_loop (x : usize) (ls : list_t usize) : Tot (result (usize & (usize -> result (list_t usize)))) @@ -161,7 +180,7 @@ let rec get_elem_mut_loop end (** [loops::get_elem_mut]: - Source: 'src/loops.rs', lines 103:0-103:73 *) + Source: 'src/loops.rs', lines 113:0-113:73 *) let get_elem_mut (slots : alloc_vec_Vec (list_t usize)) (x : usize) : result (usize & (usize -> result (alloc_vec_Vec (list_t usize)))) @@ -174,7 +193,7 @@ let get_elem_mut Return (i, back1) (** [loops::get_elem_shared]: loop 0: - Source: 'src/loops.rs', lines 119:0-133:1 *) + Source: 'src/loops.rs', lines 129:0-143:1 *) let rec get_elem_shared_loop (x : usize) (ls : list_t usize) : Tot (result usize) (decreases (get_elem_shared_loop_decreases x ls)) @@ -185,7 +204,7 @@ let rec get_elem_shared_loop end (** [loops::get_elem_shared]: - Source: 'src/loops.rs', lines 119:0-119:68 *) + Source: 'src/loops.rs', lines 129:0-129:68 *) let get_elem_shared (slots : alloc_vec_Vec (list_t usize)) (x : usize) : result usize = let* l = @@ -194,7 +213,7 @@ let get_elem_shared get_elem_shared_loop x l (** [loops::id_mut]: - Source: 'src/loops.rs', lines 135:0-135:50 *) + Source: 'src/loops.rs', lines 145:0-145:50 *) let id_mut (t : Type0) (ls : list_t t) : result ((list_t t) & (list_t t -> result (list_t t))) @@ -202,12 +221,12 @@ let id_mut Return (ls, Return) (** [loops::id_shared]: - Source: 'src/loops.rs', lines 139:0-139:45 *) + Source: 'src/loops.rs', lines 149:0-149:45 *) let id_shared (t : Type0) (ls : list_t t) : result (list_t t) = Return ls (** [loops::list_nth_mut_loop_with_id]: loop 0: - Source: 'src/loops.rs', lines 144:0-155:1 *) + Source: 'src/loops.rs', lines 154:0-165:1 *) let rec list_nth_mut_loop_with_id_loop (t : Type0) (i : u32) (ls : list_t t) : Tot (result (t & (t -> result (list_t t)))) @@ -226,7 +245,7 @@ let rec list_nth_mut_loop_with_id_loop end (** [loops::list_nth_mut_loop_with_id]: - Source: 'src/loops.rs', lines 144:0-144:75 *) + Source: 'src/loops.rs', lines 154:0-154:75 *) let list_nth_mut_loop_with_id (t : Type0) (ls : list_t t) (i : u32) : result (t & (t -> result (list_t t))) @@ -237,7 +256,7 @@ let list_nth_mut_loop_with_id Return (x, back1) (** [loops::list_nth_shared_loop_with_id]: loop 0: - Source: 'src/loops.rs', lines 158:0-169:1 *) + Source: 'src/loops.rs', lines 168:0-179:1 *) let rec list_nth_shared_loop_with_id_loop (t : Type0) (i : u32) (ls : list_t t) : Tot (result t) @@ -252,13 +271,13 @@ let rec list_nth_shared_loop_with_id_loop end (** [loops::list_nth_shared_loop_with_id]: - Source: 'src/loops.rs', lines 158:0-158:70 *) + Source: 'src/loops.rs', lines 168:0-168:70 *) let list_nth_shared_loop_with_id (t : Type0) (ls : list_t t) (i : u32) : result t = let* ls1 = id_shared t ls in list_nth_shared_loop_with_id_loop t i ls1 (** [loops::list_nth_mut_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 174:0-195:1 *) + Source: 'src/loops.rs', lines 184:0-205:1 *) let rec list_nth_mut_loop_pair_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result ((t & t) & (t -> result (list_t t)) & (t -> result (list_t t)))) @@ -288,7 +307,7 @@ let rec list_nth_mut_loop_pair_loop end (** [loops::list_nth_mut_loop_pair]: - Source: 'src/loops.rs', lines 174:0-178:27 *) + Source: 'src/loops.rs', lines 184:0-188:27 *) let list_nth_mut_loop_pair (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result ((t & t) & (t -> result (list_t t)) & (t -> result (list_t t))) @@ -297,7 +316,7 @@ let list_nth_mut_loop_pair Return (p, back_'a, back_'b) (** [loops::list_nth_shared_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 198:0-219:1 *) + Source: 'src/loops.rs', lines 208:0-229:1 *) let rec list_nth_shared_loop_pair_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -316,13 +335,13 @@ let rec list_nth_shared_loop_pair_loop end (** [loops::list_nth_shared_loop_pair]: - Source: 'src/loops.rs', lines 198:0-202:19 *) + Source: 'src/loops.rs', lines 208:0-212:19 *) let list_nth_shared_loop_pair (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_shared_loop_pair_loop t ls0 ls1 i (** [loops::list_nth_mut_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 223:0-238:1 *) + Source: 'src/loops.rs', lines 233:0-248:1 *) let rec list_nth_mut_loop_pair_merge_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result ((t & t) & ((t & t) -> result ((list_t t) & (list_t t))))) @@ -352,7 +371,7 @@ let rec list_nth_mut_loop_pair_merge_loop end (** [loops::list_nth_mut_loop_pair_merge]: - Source: 'src/loops.rs', lines 223:0-227:27 *) + Source: 'src/loops.rs', lines 233:0-237:27 *) let list_nth_mut_loop_pair_merge (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result ((t & t) & ((t & t) -> result ((list_t t) & (list_t t)))) @@ -361,7 +380,7 @@ let list_nth_mut_loop_pair_merge Return (p, back_'a) (** [loops::list_nth_shared_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 241:0-256:1 *) + Source: 'src/loops.rs', lines 251:0-266:1 *) let rec list_nth_shared_loop_pair_merge_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result (t & t)) @@ -382,13 +401,13 @@ let rec list_nth_shared_loop_pair_merge_loop end (** [loops::list_nth_shared_loop_pair_merge]: - Source: 'src/loops.rs', lines 241:0-245:19 *) + Source: 'src/loops.rs', lines 251:0-255:19 *) let list_nth_shared_loop_pair_merge (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result (t & t) = list_nth_shared_loop_pair_merge_loop t ls0 ls1 i (** [loops::list_nth_mut_shared_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 259:0-274:1 *) + Source: 'src/loops.rs', lines 269:0-284:1 *) let rec list_nth_mut_shared_loop_pair_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result ((t & t) & (t -> result (list_t t)))) @@ -414,7 +433,7 @@ let rec list_nth_mut_shared_loop_pair_loop end (** [loops::list_nth_mut_shared_loop_pair]: - Source: 'src/loops.rs', lines 259:0-263:23 *) + Source: 'src/loops.rs', lines 269:0-273:23 *) let list_nth_mut_shared_loop_pair (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result ((t & t) & (t -> result (list_t t))) @@ -423,7 +442,7 @@ let list_nth_mut_shared_loop_pair Return (p, back_'a) (** [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 278:0-293:1 *) + Source: 'src/loops.rs', lines 288:0-303:1 *) let rec list_nth_mut_shared_loop_pair_merge_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result ((t & t) & (t -> result (list_t t)))) @@ -450,7 +469,7 @@ let rec list_nth_mut_shared_loop_pair_merge_loop end (** [loops::list_nth_mut_shared_loop_pair_merge]: - Source: 'src/loops.rs', lines 278:0-282:23 *) + Source: 'src/loops.rs', lines 288:0-292:23 *) let list_nth_mut_shared_loop_pair_merge (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result ((t & t) & (t -> result (list_t t))) @@ -459,7 +478,7 @@ let list_nth_mut_shared_loop_pair_merge Return (p, back_'a) (** [loops::list_nth_shared_mut_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 297:0-312:1 *) + Source: 'src/loops.rs', lines 307:0-322:1 *) let rec list_nth_shared_mut_loop_pair_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result ((t & t) & (t -> result (list_t t)))) @@ -485,7 +504,7 @@ let rec list_nth_shared_mut_loop_pair_loop end (** [loops::list_nth_shared_mut_loop_pair]: - Source: 'src/loops.rs', lines 297:0-301:23 *) + Source: 'src/loops.rs', lines 307:0-311:23 *) let list_nth_shared_mut_loop_pair (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result ((t & t) & (t -> result (list_t t))) @@ -494,7 +513,7 @@ let list_nth_shared_mut_loop_pair Return (p, back_'b) (** [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 316:0-331:1 *) + Source: 'src/loops.rs', lines 326:0-341:1 *) let rec list_nth_shared_mut_loop_pair_merge_loop (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : Tot (result ((t & t) & (t -> result (list_t t)))) @@ -521,7 +540,7 @@ let rec list_nth_shared_mut_loop_pair_merge_loop end (** [loops::list_nth_shared_mut_loop_pair_merge]: - Source: 'src/loops.rs', lines 316:0-320:23 *) + Source: 'src/loops.rs', lines 326:0-330:23 *) let list_nth_shared_mut_loop_pair_merge (t : Type0) (ls0 : list_t t) (ls1 : list_t t) (i : u32) : result ((t & t) & (t -> result (list_t t))) diff --git a/tests/fstar/misc/Loops.Types.fst b/tests/fstar/misc/Loops.Types.fst index 8aa38290..29f56e1b 100644 --- a/tests/fstar/misc/Loops.Types.fst +++ b/tests/fstar/misc/Loops.Types.fst @@ -6,7 +6,7 @@ open Primitives #set-options "--z3rlimit 50 --fuel 1 --ifuel 1" (** [loops::List] - Source: 'src/loops.rs', lines 60:0-60:16 *) + Source: 'src/loops.rs', lines 70:0-70:16 *) type list_t (t : Type0) = | List_Cons : t -> list_t t -> list_t t | List_Nil : list_t t diff --git a/tests/fstar/traits/Traits.fst b/tests/fstar/traits/Traits.fst index cb9c1654..0760de2e 100644 --- a/tests/fstar/traits/Traits.fst +++ b/tests/fstar/traits/Traits.fst @@ -325,22 +325,14 @@ noeq type childTrait_t (self : Type0) = { parentTrait1SelfInst : parentTrait1_t self; } -(** [traits::test_parent_trait0]: - Source: 'src/traits.rs', lines 208:0-208:57 *) -let test_parent_trait0 - (t : Type0) (parentTrait0TInst : parentTrait0_t t) (x : t) : - result parentTrait0TInst.tW - = - parentTrait0TInst.get_w x - (** [traits::test_child_trait1]: - Source: 'src/traits.rs', lines 213:0-213:56 *) + Source: 'src/traits.rs', lines 209:0-209:56 *) let test_child_trait1 (t : Type0) (childTraitTInst : childTrait_t t) (x : t) : result string = childTraitTInst.parentTrait0SelfInst.get_name x (** [traits::test_child_trait2]: - Source: 'src/traits.rs', lines 217:0-217:54 *) + Source: 'src/traits.rs', lines 213:0-213:54 *) let test_child_trait2 (t : Type0) (childTraitTInst : childTrait_t t) (x : t) : result childTraitTInst.parentTrait0SelfInst.tW @@ -348,7 +340,7 @@ let test_child_trait2 childTraitTInst.parentTrait0SelfInst.get_w x (** [traits::order1]: - Source: 'src/traits.rs', lines 223:0-223:59 *) + Source: 'src/traits.rs', lines 219:0-219:59 *) let order1 (t u : Type0) (parentTrait0TInst : parentTrait0_t t) (parentTrait0UInst : parentTrait0_t u) : @@ -357,27 +349,27 @@ let order1 Return () (** Trait declaration: [traits::ChildTrait1] - Source: 'src/traits.rs', lines 226:0-226:35 *) + Source: 'src/traits.rs', lines 222:0-222:35 *) noeq type childTrait1_t (self : Type0) = { parentTrait1SelfInst : parentTrait1_t self; } (** Trait implementation: [traits::{usize#9}] - Source: 'src/traits.rs', lines 228:0-228:27 *) + Source: 'src/traits.rs', lines 224:0-224:27 *) let traits_ParentTrait1UsizeInst : parentTrait1_t usize = () (** Trait implementation: [traits::{usize#10}] - Source: 'src/traits.rs', lines 229:0-229:26 *) + Source: 'src/traits.rs', lines 225:0-225:26 *) let traits_ChildTrait1UsizeInst : childTrait1_t usize = { parentTrait1SelfInst = traits_ParentTrait1UsizeInst; } (** Trait declaration: [traits::Iterator] - Source: 'src/traits.rs', lines 233:0-233:18 *) + Source: 'src/traits.rs', lines 229:0-229:18 *) noeq type iterator_t (self : Type0) = { tItem : Type0; } (** Trait declaration: [traits::IntoIterator] - Source: 'src/traits.rs', lines 237:0-237:22 *) + Source: 'src/traits.rs', lines 233:0-233:22 *) noeq type intoIterator_t (self : Type0) = { tItem : Type0; tIntoIter : Type0; @@ -386,29 +378,29 @@ noeq type intoIterator_t (self : Type0) = { } (** Trait declaration: [traits::FromResidual] - Source: 'src/traits.rs', lines 254:0-254:21 *) + Source: 'src/traits.rs', lines 250:0-250:21 *) type fromResidual_t (self t : Type0) = unit (** Trait declaration: [traits::Try] - Source: 'src/traits.rs', lines 250:0-250:48 *) + Source: 'src/traits.rs', lines 246:0-246:48 *) noeq type try_t (self : Type0) = { tResidual : Type0; fromResidualSelftraitsTrySelfResidualInst : fromResidual_t self tResidual; } (** Trait declaration: [traits::WithTarget] - Source: 'src/traits.rs', lines 256:0-256:20 *) + Source: 'src/traits.rs', lines 252:0-252:20 *) noeq type withTarget_t (self : Type0) = { tTarget : Type0; } (** Trait declaration: [traits::ParentTrait2] - Source: 'src/traits.rs', lines 260:0-260:22 *) + Source: 'src/traits.rs', lines 256:0-256:22 *) noeq type parentTrait2_t (self : Type0) = { tU : Type0; tU_clause_0 : withTarget_t tU; } (** Trait declaration: [traits::ChildTrait2] - Source: 'src/traits.rs', lines 264:0-264:35 *) + Source: 'src/traits.rs', lines 260:0-260:35 *) noeq type childTrait2_t (self : Type0) = { parentTrait2SelfInst : parentTrait2_t self; convert : parentTrait2SelfInst.tU -> result @@ -416,56 +408,56 @@ noeq type childTrait2_t (self : Type0) = { } (** Trait implementation: [traits::{u32#11}] - Source: 'src/traits.rs', lines 268:0-268:23 *) + Source: 'src/traits.rs', lines 264:0-264:23 *) let traits_WithTargetU32Inst : withTarget_t u32 = { tTarget = u32; } (** Trait implementation: [traits::{u32#12}] - Source: 'src/traits.rs', lines 272:0-272:25 *) + Source: 'src/traits.rs', lines 268:0-268:25 *) let traits_ParentTrait2U32Inst : parentTrait2_t u32 = { tU = u32; tU_clause_0 = traits_WithTargetU32Inst; } (** [traits::{u32#13}::convert]: - Source: 'src/traits.rs', lines 277:4-277:29 *) + Source: 'src/traits.rs', lines 273:4-273:29 *) let u32_convert (x : u32) : result u32 = Return x (** Trait implementation: [traits::{u32#13}] - Source: 'src/traits.rs', lines 276:0-276:24 *) + Source: 'src/traits.rs', lines 272:0-272:24 *) let traits_ChildTrait2U32Inst : childTrait2_t u32 = { parentTrait2SelfInst = traits_ParentTrait2U32Inst; convert = u32_convert; } (** Trait declaration: [traits::CFnOnce] - Source: 'src/traits.rs', lines 290:0-290:23 *) + Source: 'src/traits.rs', lines 286:0-286:23 *) noeq type cFnOnce_t (self args : Type0) = { tOutput : Type0; call_once : self -> args -> result tOutput; } (** Trait declaration: [traits::CFnMut] - Source: 'src/traits.rs', lines 296:0-296:37 *) + Source: 'src/traits.rs', lines 292:0-292:37 *) noeq type cFnMut_t (self args : Type0) = { cFnOnceSelfArgsInst : cFnOnce_t self args; call_mut : self -> args -> result (cFnOnceSelfArgsInst.tOutput & self); } (** Trait declaration: [traits::CFn] - Source: 'src/traits.rs', lines 300:0-300:33 *) + Source: 'src/traits.rs', lines 296:0-296:33 *) noeq type cFn_t (self args : Type0) = { cFnMutSelfArgsInst : cFnMut_t self args; call : self -> args -> result cFnMutSelfArgsInst.cFnOnceSelfArgsInst.tOutput; } (** Trait declaration: [traits::GetTrait] - Source: 'src/traits.rs', lines 304:0-304:18 *) + Source: 'src/traits.rs', lines 300:0-300:18 *) noeq type getTrait_t (self : Type0) = { tW : Type0; get_w : self -> result tW; } (** [traits::test_get_trait]: - Source: 'src/traits.rs', lines 309:0-309:49 *) + Source: 'src/traits.rs', lines 305:0-305:49 *) let test_get_trait (t : Type0) (getTraitTInst : getTrait_t t) (x : t) : result getTraitTInst.tW diff --git a/tests/lean/Loops.lean b/tests/lean/Loops.lean index fbb4616f..f8e1a8cc 100644 --- a/tests/lean/Loops.lean +++ b/tests/lean/Loops.lean @@ -54,8 +54,26 @@ divergent def sum_with_shared_borrows_loop def sum_with_shared_borrows (max : U32) : Result U32 := sum_with_shared_borrows_loop max 0#u32 0#u32 +/- [loops::sum_array]: loop 0: + Source: 'src/loops.rs', lines 50:0-58:1 -/ +divergent def sum_array_loop + (N : Usize) (a : Array U32 N) (i : Usize) (s : U32) : Result U32 := + if i < N + then + do + let i1 ← Array.index_usize U32 N a i + let s1 ← s + i1 + let i2 ← i + 1#usize + sum_array_loop N a i2 s1 + else Result.ret s + +/- [loops::sum_array]: + Source: 'src/loops.rs', lines 50:0-50:52 -/ +def sum_array (N : Usize) (a : Array U32 N) : Result U32 := + sum_array_loop N a 0#usize 0#u32 + /- [loops::clear]: loop 0: - Source: 'src/loops.rs', lines 52:0-58:1 -/ + Source: 'src/loops.rs', lines 62:0-68:1 -/ divergent def clear_loop (v : alloc.vec.Vec U32) (i : Usize) : Result (alloc.vec.Vec U32) := let i1 := alloc.vec.Vec.len U32 v @@ -71,18 +89,18 @@ divergent def clear_loop else Result.ret v /- [loops::clear]: - Source: 'src/loops.rs', lines 52:0-52:30 -/ + Source: 'src/loops.rs', lines 62:0-62:30 -/ def clear (v : alloc.vec.Vec U32) : Result (alloc.vec.Vec U32) := clear_loop v 0#usize /- [loops::List] - Source: 'src/loops.rs', lines 60:0-60:16 -/ + Source: 'src/loops.rs', lines 70:0-70:16 -/ inductive List (T : Type) := | Cons : T → List T → List T | Nil : List T /- [loops::list_mem]: loop 0: - Source: 'src/loops.rs', lines 66:0-75:1 -/ + Source: 'src/loops.rs', lines 76:0-85:1 -/ divergent def list_mem_loop (x : U32) (ls : List U32) : Result Bool := match ls with | List.Cons y tl => if y = x @@ -91,12 +109,12 @@ divergent def list_mem_loop (x : U32) (ls : List U32) : Result Bool := | List.Nil => Result.ret false /- [loops::list_mem]: - Source: 'src/loops.rs', lines 66:0-66:52 -/ + Source: 'src/loops.rs', lines 76:0-76:52 -/ def list_mem (x : U32) (ls : List U32) : Result Bool := list_mem_loop x ls /- [loops::list_nth_mut_loop]: loop 0: - Source: 'src/loops.rs', lines 78:0-88:1 -/ + Source: 'src/loops.rs', lines 88:0-98:1 -/ divergent def list_nth_mut_loop_loop (T : Type) (ls : List T) (i : U32) : Result (T × (T → Result (List T))) := match ls with @@ -117,7 +135,7 @@ divergent def list_nth_mut_loop_loop | List.Nil => Result.fail .panic /- [loops::list_nth_mut_loop]: - Source: 'src/loops.rs', lines 78:0-78:71 -/ + Source: 'src/loops.rs', lines 88:0-88:71 -/ def list_nth_mut_loop (T : Type) (ls : List T) (i : U32) : Result (T × (T → Result (List T))) := do @@ -125,7 +143,7 @@ def list_nth_mut_loop Result.ret (t, back) /- [loops::list_nth_shared_loop]: loop 0: - Source: 'src/loops.rs', lines 91:0-101:1 -/ + Source: 'src/loops.rs', lines 101:0-111:1 -/ divergent def list_nth_shared_loop_loop (T : Type) (ls : List T) (i : U32) : Result T := match ls with @@ -138,12 +156,12 @@ divergent def list_nth_shared_loop_loop | List.Nil => Result.fail .panic /- [loops::list_nth_shared_loop]: - Source: 'src/loops.rs', lines 91:0-91:66 -/ + Source: 'src/loops.rs', lines 101:0-101:66 -/ def list_nth_shared_loop (T : Type) (ls : List T) (i : U32) : Result T := list_nth_shared_loop_loop T ls i /- [loops::get_elem_mut]: loop 0: - Source: 'src/loops.rs', lines 103:0-117:1 -/ + Source: 'src/loops.rs', lines 113:0-127:1 -/ divergent def get_elem_mut_loop (x : Usize) (ls : List Usize) : Result (Usize × (Usize → Result (List Usize))) @@ -165,7 +183,7 @@ divergent def get_elem_mut_loop | List.Nil => Result.fail .panic /- [loops::get_elem_mut]: - Source: 'src/loops.rs', lines 103:0-103:73 -/ + Source: 'src/loops.rs', lines 113:0-113:73 -/ def get_elem_mut (slots : alloc.vec.Vec (List Usize)) (x : Usize) : Result (Usize × (Usize → Result (alloc.vec.Vec (List Usize)))) @@ -181,7 +199,7 @@ def get_elem_mut Result.ret (i, back1) /- [loops::get_elem_shared]: loop 0: - Source: 'src/loops.rs', lines 119:0-133:1 -/ + Source: 'src/loops.rs', lines 129:0-143:1 -/ divergent def get_elem_shared_loop (x : Usize) (ls : List Usize) : Result Usize := match ls with @@ -191,7 +209,7 @@ divergent def get_elem_shared_loop | List.Nil => Result.fail .panic /- [loops::get_elem_shared]: - Source: 'src/loops.rs', lines 119:0-119:68 -/ + Source: 'src/loops.rs', lines 129:0-129:68 -/ def get_elem_shared (slots : alloc.vec.Vec (List Usize)) (x : Usize) : Result Usize := do @@ -201,7 +219,7 @@ def get_elem_shared get_elem_shared_loop x l /- [loops::id_mut]: - Source: 'src/loops.rs', lines 135:0-135:50 -/ + Source: 'src/loops.rs', lines 145:0-145:50 -/ def id_mut (T : Type) (ls : List T) : Result ((List T) × (List T → Result (List T))) @@ -209,12 +227,12 @@ def id_mut Result.ret (ls, Result.ret) /- [loops::id_shared]: - Source: 'src/loops.rs', lines 139:0-139:45 -/ + Source: 'src/loops.rs', lines 149:0-149:45 -/ def id_shared (T : Type) (ls : List T) : Result (List T) := Result.ret ls /- [loops::list_nth_mut_loop_with_id]: loop 0: - Source: 'src/loops.rs', lines 144:0-155:1 -/ + Source: 'src/loops.rs', lines 154:0-165:1 -/ divergent def list_nth_mut_loop_with_id_loop (T : Type) (i : U32) (ls : List T) : Result (T × (T → Result (List T))) := match ls with @@ -235,7 +253,7 @@ divergent def list_nth_mut_loop_with_id_loop | List.Nil => Result.fail .panic /- [loops::list_nth_mut_loop_with_id]: - Source: 'src/loops.rs', lines 144:0-144:75 -/ + Source: 'src/loops.rs', lines 154:0-154:75 -/ def list_nth_mut_loop_with_id (T : Type) (ls : List T) (i : U32) : Result (T × (T → Result (List T))) := do @@ -247,7 +265,7 @@ def list_nth_mut_loop_with_id Result.ret (t, back1) /- [loops::list_nth_shared_loop_with_id]: loop 0: - Source: 'src/loops.rs', lines 158:0-169:1 -/ + Source: 'src/loops.rs', lines 168:0-179:1 -/ divergent def list_nth_shared_loop_with_id_loop (T : Type) (i : U32) (ls : List T) : Result T := match ls with @@ -260,7 +278,7 @@ divergent def list_nth_shared_loop_with_id_loop | List.Nil => Result.fail .panic /- [loops::list_nth_shared_loop_with_id]: - Source: 'src/loops.rs', lines 158:0-158:70 -/ + Source: 'src/loops.rs', lines 168:0-168:70 -/ def list_nth_shared_loop_with_id (T : Type) (ls : List T) (i : U32) : Result T := do @@ -268,7 +286,7 @@ def list_nth_shared_loop_with_id list_nth_shared_loop_with_id_loop T i ls1 /- [loops::list_nth_mut_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 174:0-195:1 -/ + Source: 'src/loops.rs', lines 184:0-205:1 -/ divergent def list_nth_mut_loop_pair_loop (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × (T → Result (List T)) × (T → Result (List T))) @@ -299,7 +317,7 @@ divergent def list_nth_mut_loop_pair_loop | List.Nil => Result.fail .panic /- [loops::list_nth_mut_loop_pair]: - Source: 'src/loops.rs', lines 174:0-178:27 -/ + Source: 'src/loops.rs', lines 184:0-188:27 -/ def list_nth_mut_loop_pair (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × (T → Result (List T)) × (T → Result (List T))) @@ -309,7 +327,7 @@ def list_nth_mut_loop_pair Result.ret (p, back_'a, back_'b) /- [loops::list_nth_shared_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 198:0-219:1 -/ + Source: 'src/loops.rs', lines 208:0-229:1 -/ divergent def list_nth_shared_loop_pair_loop (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := match ls0 with @@ -325,13 +343,13 @@ divergent def list_nth_shared_loop_pair_loop | List.Nil => Result.fail .panic /- [loops::list_nth_shared_loop_pair]: - Source: 'src/loops.rs', lines 198:0-202:19 -/ + Source: 'src/loops.rs', lines 208:0-212:19 -/ def list_nth_shared_loop_pair (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := list_nth_shared_loop_pair_loop T ls0 ls1 i /- [loops::list_nth_mut_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 223:0-238:1 -/ + Source: 'src/loops.rs', lines 233:0-248:1 -/ divergent def list_nth_mut_loop_pair_merge_loop (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × ((T × T) → Result ((List T) × (List T)))) @@ -361,7 +379,7 @@ divergent def list_nth_mut_loop_pair_merge_loop | List.Nil => Result.fail .panic /- [loops::list_nth_mut_loop_pair_merge]: - Source: 'src/loops.rs', lines 223:0-227:27 -/ + Source: 'src/loops.rs', lines 233:0-237:27 -/ def list_nth_mut_loop_pair_merge (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × ((T × T) → Result ((List T) × (List T)))) @@ -371,7 +389,7 @@ def list_nth_mut_loop_pair_merge Result.ret (p, back_'a) /- [loops::list_nth_shared_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 241:0-256:1 -/ + Source: 'src/loops.rs', lines 251:0-266:1 -/ divergent def list_nth_shared_loop_pair_merge_loop (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := match ls0 with @@ -388,13 +406,13 @@ divergent def list_nth_shared_loop_pair_merge_loop | List.Nil => Result.fail .panic /- [loops::list_nth_shared_loop_pair_merge]: - Source: 'src/loops.rs', lines 241:0-245:19 -/ + Source: 'src/loops.rs', lines 251:0-255:19 -/ def list_nth_shared_loop_pair_merge (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result (T × T) := list_nth_shared_loop_pair_merge_loop T ls0 ls1 i /- [loops::list_nth_mut_shared_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 259:0-274:1 -/ + Source: 'src/loops.rs', lines 269:0-284:1 -/ divergent def list_nth_mut_shared_loop_pair_loop (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × (T → Result (List T))) @@ -420,7 +438,7 @@ divergent def list_nth_mut_shared_loop_pair_loop | List.Nil => Result.fail .panic /- [loops::list_nth_mut_shared_loop_pair]: - Source: 'src/loops.rs', lines 259:0-263:23 -/ + Source: 'src/loops.rs', lines 269:0-273:23 -/ def list_nth_mut_shared_loop_pair (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × (T → Result (List T))) @@ -430,7 +448,7 @@ def list_nth_mut_shared_loop_pair Result.ret (p, back_'a) /- [loops::list_nth_mut_shared_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 278:0-293:1 -/ + Source: 'src/loops.rs', lines 288:0-303:1 -/ divergent def list_nth_mut_shared_loop_pair_merge_loop (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × (T → Result (List T))) @@ -457,7 +475,7 @@ divergent def list_nth_mut_shared_loop_pair_merge_loop | List.Nil => Result.fail .panic /- [loops::list_nth_mut_shared_loop_pair_merge]: - Source: 'src/loops.rs', lines 278:0-282:23 -/ + Source: 'src/loops.rs', lines 288:0-292:23 -/ def list_nth_mut_shared_loop_pair_merge (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × (T → Result (List T))) @@ -467,7 +485,7 @@ def list_nth_mut_shared_loop_pair_merge Result.ret (p, back_'a) /- [loops::list_nth_shared_mut_loop_pair]: loop 0: - Source: 'src/loops.rs', lines 297:0-312:1 -/ + Source: 'src/loops.rs', lines 307:0-322:1 -/ divergent def list_nth_shared_mut_loop_pair_loop (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × (T → Result (List T))) @@ -493,7 +511,7 @@ divergent def list_nth_shared_mut_loop_pair_loop | List.Nil => Result.fail .panic /- [loops::list_nth_shared_mut_loop_pair]: - Source: 'src/loops.rs', lines 297:0-301:23 -/ + Source: 'src/loops.rs', lines 307:0-311:23 -/ def list_nth_shared_mut_loop_pair (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × (T → Result (List T))) @@ -503,7 +521,7 @@ def list_nth_shared_mut_loop_pair Result.ret (p, back_'b) /- [loops::list_nth_shared_mut_loop_pair_merge]: loop 0: - Source: 'src/loops.rs', lines 316:0-331:1 -/ + Source: 'src/loops.rs', lines 326:0-341:1 -/ divergent def list_nth_shared_mut_loop_pair_merge_loop (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × (T → Result (List T))) @@ -530,7 +548,7 @@ divergent def list_nth_shared_mut_loop_pair_merge_loop | List.Nil => Result.fail .panic /- [loops::list_nth_shared_mut_loop_pair_merge]: - Source: 'src/loops.rs', lines 316:0-320:23 -/ + Source: 'src/loops.rs', lines 326:0-330:23 -/ def list_nth_shared_mut_loop_pair_merge (T : Type) (ls0 : List T) (ls1 : List T) (i : U32) : Result ((T × T) × (T → Result (List T))) diff --git a/tests/lean/Traits.lean b/tests/lean/Traits.lean index 35f9e5bf..d32aba86 100644 --- a/tests/lean/Traits.lean +++ b/tests/lean/Traits.lean @@ -338,22 +338,14 @@ structure ChildTrait (Self : Type) where ParentTrait0SelfInst : ParentTrait0 Self ParentTrait1SelfInst : ParentTrait1 Self -/- [traits::test_parent_trait0]: - Source: 'src/traits.rs', lines 208:0-208:57 -/ -def test_parent_trait0 - (T : Type) (ParentTrait0TInst : ParentTrait0 T) (x : T) : - Result ParentTrait0TInst.W - := - ParentTrait0TInst.get_w x - /- [traits::test_child_trait1]: - Source: 'src/traits.rs', lines 213:0-213:56 -/ + Source: 'src/traits.rs', lines 209:0-209:56 -/ def test_child_trait1 (T : Type) (ChildTraitTInst : ChildTrait T) (x : T) : Result String := ChildTraitTInst.ParentTrait0SelfInst.get_name x /- [traits::test_child_trait2]: - Source: 'src/traits.rs', lines 217:0-217:54 -/ + Source: 'src/traits.rs', lines 213:0-213:54 -/ def test_child_trait2 (T : Type) (ChildTraitTInst : ChildTrait T) (x : T) : Result ChildTraitTInst.ParentTrait0SelfInst.W @@ -361,7 +353,7 @@ def test_child_trait2 ChildTraitTInst.ParentTrait0SelfInst.get_w x /- [traits::order1]: - Source: 'src/traits.rs', lines 223:0-223:59 -/ + Source: 'src/traits.rs', lines 219:0-219:59 -/ def order1 (T U : Type) (ParentTrait0TInst : ParentTrait0 T) (ParentTrait0UInst : ParentTrait0 U) : @@ -370,28 +362,28 @@ def order1 Result.ret () /- Trait declaration: [traits::ChildTrait1] - Source: 'src/traits.rs', lines 226:0-226:35 -/ + Source: 'src/traits.rs', lines 222:0-222:35 -/ structure ChildTrait1 (Self : Type) where ParentTrait1SelfInst : ParentTrait1 Self /- Trait implementation: [traits::{usize#9}] - Source: 'src/traits.rs', lines 228:0-228:27 -/ + Source: 'src/traits.rs', lines 224:0-224:27 -/ def traits.ParentTrait1UsizeInst : ParentTrait1 Usize := { } /- Trait implementation: [traits::{usize#10}] - Source: 'src/traits.rs', lines 229:0-229:26 -/ + Source: 'src/traits.rs', lines 225:0-225:26 -/ def traits.ChildTrait1UsizeInst : ChildTrait1 Usize := { ParentTrait1SelfInst := traits.ParentTrait1UsizeInst } /- Trait declaration: [traits::Iterator] - Source: 'src/traits.rs', lines 233:0-233:18 -/ + Source: 'src/traits.rs', lines 229:0-229:18 -/ structure Iterator (Self : Type) where Item : Type /- Trait declaration: [traits::IntoIterator] - Source: 'src/traits.rs', lines 237:0-237:22 -/ + Source: 'src/traits.rs', lines 233:0-233:22 -/ structure IntoIterator (Self : Type) where Item : Type IntoIter : Type @@ -399,84 +391,84 @@ structure IntoIterator (Self : Type) where into_iter : Self → Result IntoIter /- Trait declaration: [traits::FromResidual] - Source: 'src/traits.rs', lines 254:0-254:21 -/ + Source: 'src/traits.rs', lines 250:0-250:21 -/ structure FromResidual (Self T : Type) where /- Trait declaration: [traits::Try] - Source: 'src/traits.rs', lines 250:0-250:48 -/ + Source: 'src/traits.rs', lines 246:0-246:48 -/ structure Try (Self : Type) where Residual : Type FromResidualSelftraitsTrySelfResidualInst : FromResidual Self Residual /- Trait declaration: [traits::WithTarget] - Source: 'src/traits.rs', lines 256:0-256:20 -/ + Source: 'src/traits.rs', lines 252:0-252:20 -/ structure WithTarget (Self : Type) where Target : Type /- Trait declaration: [traits::ParentTrait2] - Source: 'src/traits.rs', lines 260:0-260:22 -/ + Source: 'src/traits.rs', lines 256:0-256:22 -/ structure ParentTrait2 (Self : Type) where U : Type U_clause_0 : WithTarget U /- Trait declaration: [traits::ChildTrait2] - Source: 'src/traits.rs', lines 264:0-264:35 -/ + Source: 'src/traits.rs', lines 260:0-260:35 -/ structure ChildTrait2 (Self : Type) where ParentTrait2SelfInst : ParentTrait2 Self convert : ParentTrait2SelfInst.U → Result ParentTrait2SelfInst.U_clause_0.Target /- Trait implementation: [traits::{u32#11}] - Source: 'src/traits.rs', lines 268:0-268:23 -/ + Source: 'src/traits.rs', lines 264:0-264:23 -/ def traits.WithTargetU32Inst : WithTarget U32 := { Target := U32 } /- Trait implementation: [traits::{u32#12}] - Source: 'src/traits.rs', lines 272:0-272:25 -/ + Source: 'src/traits.rs', lines 268:0-268:25 -/ def traits.ParentTrait2U32Inst : ParentTrait2 U32 := { U := U32 U_clause_0 := traits.WithTargetU32Inst } /- [traits::{u32#13}::convert]: - Source: 'src/traits.rs', lines 277:4-277:29 -/ + Source: 'src/traits.rs', lines 273:4-273:29 -/ def U32.convert (x : U32) : Result U32 := Result.ret x /- Trait implementation: [traits::{u32#13}] - Source: 'src/traits.rs', lines 276:0-276:24 -/ + Source: 'src/traits.rs', lines 272:0-272:24 -/ def traits.ChildTrait2U32Inst : ChildTrait2 U32 := { ParentTrait2SelfInst := traits.ParentTrait2U32Inst convert := U32.convert } /- Trait declaration: [traits::CFnOnce] - Source: 'src/traits.rs', lines 290:0-290:23 -/ + Source: 'src/traits.rs', lines 286:0-286:23 -/ structure CFnOnce (Self Args : Type) where Output : Type call_once : Self → Args → Result Output /- Trait declaration: [traits::CFnMut] - Source: 'src/traits.rs', lines 296:0-296:37 -/ + Source: 'src/traits.rs', lines 292:0-292:37 -/ structure CFnMut (Self Args : Type) where CFnOnceSelfArgsInst : CFnOnce Self Args call_mut : Self → Args → Result (CFnOnceSelfArgsInst.Output × Self) /- Trait declaration: [traits::CFn] - Source: 'src/traits.rs', lines 300:0-300:33 -/ + Source: 'src/traits.rs', lines 296:0-296:33 -/ structure CFn (Self Args : Type) where CFnMutSelfArgsInst : CFnMut Self Args call : Self → Args → Result CFnMutSelfArgsInst.CFnOnceSelfArgsInst.Output /- Trait declaration: [traits::GetTrait] - Source: 'src/traits.rs', lines 304:0-304:18 -/ + Source: 'src/traits.rs', lines 300:0-300:18 -/ structure GetTrait (Self : Type) where W : Type get_w : Self → Result W /- [traits::test_get_trait]: - Source: 'src/traits.rs', lines 309:0-309:49 -/ + Source: 'src/traits.rs', lines 305:0-305:49 -/ def test_get_trait (T : Type) (GetTraitTInst : GetTrait T) (x : T) : Result GetTraitTInst.W := GetTraitTInst.get_w x |