@@ -281,28 +281,20 @@ let push_frame (ctx : eval_ctx) : eval_ctx = ctx_push_frame ctx
281281let get_assumed_function_return_type (span : Meta.span ) (ctx : eval_ctx )
282282 (fid : assumed_fun_id ) (generics : generic_args ) : ety =
283283 sanity_check __FILE__ __LINE__ (generics.trait_refs = [] ) span;
284- (* [Box::free] has a special treatment *)
285- match fid with
286- | BoxFree ->
287- sanity_check __FILE__ __LINE__ (generics.regions = [] ) span;
288- sanity_check __FILE__ __LINE__ (List. length generics.types = 1 ) span;
289- sanity_check __FILE__ __LINE__ (generics.const_generics = [] ) span;
290- mk_unit_ty
291- | _ ->
292- (* Retrieve the function's signature *)
293- let sg = Assumed. get_assumed_fun_sig fid in
294- (* Instantiate the return type *)
295- (* There shouldn't be any reference to Self *)
296- let tr_self : trait_instance_id = UnknownTrait __FUNCTION__ in
297- let generics = Subst. generic_args_erase_regions generics in
298- let { Subst. r_subst = _; ty_subst; cg_subst; tr_subst; tr_self } =
299- Subst. make_subst_from_generics sg.generics generics tr_self
300- in
301- let ty =
302- Subst. erase_regions_substitute_types ty_subst cg_subst tr_subst tr_self
303- sg.output
304- in
305- AssociatedTypes. ctx_normalize_erase_ty span ctx ty
284+ (* Retrieve the function's signature *)
285+ let sg = Assumed. get_assumed_fun_sig fid in
286+ (* Instantiate the return type *)
287+ (* There shouldn't be any reference to Self *)
288+ let tr_self : trait_instance_id = UnknownTrait __FUNCTION__ in
289+ let generics = Subst. generic_args_erase_regions generics in
290+ let { Subst. r_subst = _; ty_subst; cg_subst; tr_subst; tr_self } =
291+ Subst. make_subst_from_generics sg.generics generics tr_self
292+ in
293+ let ty =
294+ Subst. erase_regions_substitute_types ty_subst cg_subst tr_subst tr_self
295+ sg.output
296+ in
297+ AssociatedTypes. ctx_normalize_erase_ty span ctx ty
306298
307299let move_return_value (config : config ) (span : Meta.span )
308300 (pop_return_value : bool ) (ctx : eval_ctx ) :
@@ -434,45 +426,6 @@ let eval_box_new_concrete (config : config) (span : Meta.span)
434426 comp cc (assign_to_place config span box_v dest ctx)
435427 | _ -> craise __FILE__ __LINE__ span " Inconsistent state"
436428
437- (* * Auxiliary function - see {!eval_assumed_function_call}.
438-
439- [Box::free] is not handled the same way as the other assumed functions:
440- - in the regular case, whenever we need to evaluate an assumed function,
441- we evaluate the operands, push a frame, call a dedicated function
442- to correctly update the variables in the frame (and mimic the execution
443- of a body) and finally pop the frame
444- - in the case of [Box::free]: the value given to this function is often
445- of the form [Box(⊥)] because we can move the value out of the
446- box before freeing the box. It makes it invalid to see box_free as a
447- "regular" function: it is not valid to call a function with arguments
448- which contain [⊥]. For this reason, we execute [Box::free] as drop_value,
449- but this is a bit annoying with regards to the semantics...
450-
451- Followingly this function doesn't behave like the others: it does not expect
452- a stack frame to have been pushed, but rather simply behaves like {!drop_value}.
453- It thus updates the box value (by calling {!drop_value}) and updates
454- the destination (by setting it to [()]).
455- *)
456- let eval_box_free (config : config ) (span : Meta.span ) (generics : generic_args )
457- (args : operand list ) (dest : place ) : cm_fun =
458- fun ctx ->
459- match (generics.regions, generics.types, generics.const_generics, args) with
460- | [] , [ boxed_ty ], [] , [ Move input_box_place ] ->
461- (* Required type checking *)
462- let input_box =
463- InterpreterPaths. read_place span Write input_box_place ctx
464- in
465- (let input_ty = ty_get_box input_box.ty in
466- sanity_check __FILE__ __LINE__ (input_ty = boxed_ty))
467- span;
468-
469- (* Drop the value *)
470- let ctx, cc = drop_value config span input_box_place ctx in
471-
472- (* Update the destination by setting it to [()] *)
473- comp cc (assign_to_place config span mk_unit_value dest ctx)
474- | _ -> craise __FILE__ __LINE__ span " Inconsistent state"
475-
476429(* * Evaluate a non-local function call in concrete mode *)
477430let eval_assumed_function_call_concrete (config : config ) (span : Meta.span )
478431 (fid : assumed_fun_id ) (call : call ) : cm_fun =
@@ -483,72 +436,59 @@ let eval_assumed_function_call_concrete (config : config) (span : Meta.span)
483436 | FnOpMove _ ->
484437 (* Closure case: TODO *)
485438 craise __FILE__ __LINE__ span " Closures are not supported yet"
486- | FnOpRegular func -> (
439+ | FnOpRegular func ->
487440 let generics = func.generics in
488441 (* Sanity check: we don't fully handle the const generic vars environment
489442 in concrete mode yet *)
490443 sanity_check __FILE__ __LINE__ (generics.const_generics = [] ) span;
491- (* There are two cases (and this is extremely annoying):
492- - the function is not box_free
493- - the function is box_free
494- See {!eval_box_free}
495- *)
496- match fid with
497- | BoxFree ->
498- (* Degenerate case: box_free *)
499- eval_box_free config span generics args dest ctx
500- | _ ->
501- (* "Normal" case: not box_free *)
502- (* Evaluate the operands *)
503- (* let ctx, args_vl = eval_operands config ctx args in *)
504- let args_vl, ctx, cc = eval_operands config span args ctx in
505-
506- (* Evaluate the call
507- *
508- * Style note: at some point we used {!comp_transmit} to
509- * transmit the result of {!eval_operands} above down to {!push_vars}
510- * below, without having to introduce an intermediary function call,
511- * but it made it less clear where the computed values came from,
512- * so we reversed the modifications. *)
513- (* Push the stack frame: we initialize the frame with the return variable,
514- and one variable per input argument *)
515- let ctx = push_frame ctx in
516-
517- (* Create and push the return variable *)
518- let ret_vid = VarId. zero in
519- let ret_ty = get_assumed_function_return_type span ctx fid generics in
520- let ret_var = mk_var ret_vid (Some " @return" ) ret_ty in
521- let ctx = push_uninitialized_var span ret_var ctx in
522-
523- (* Create and push the input variables *)
524- let input_vars =
525- VarId. mapi_from1
526- (fun id (v : typed_value ) -> (mk_var id None v.ty, v))
527- args_vl
528- in
529- let ctx = push_vars span input_vars ctx in
530-
531- (* "Execute" the function body. As the functions are assumed, here we call
532- * custom functions to perform the proper manipulations: we don't have
533- * access to a body. *)
534- let ctx, cf_eval_body =
535- match fid with
536- | BoxNew -> eval_box_new_concrete config span generics ctx
537- | BoxFree ->
538- (* Should have been treated above *)
539- craise __FILE__ __LINE__ span " Unreachable"
540- | ArrayIndexShared
541- | ArrayIndexMut
542- | ArrayToSliceShared
543- | ArrayToSliceMut
544- | ArrayRepeat
545- | SliceIndexShared
546- | SliceIndexMut -> craise __FILE__ __LINE__ span " Unimplemented"
547- in
548- let cc = cc_comp cc cf_eval_body in
549444
550- (* Pop the frame *)
551- comp cc (pop_frame_assign config span dest ctx))
445+ (* Evaluate the operands *)
446+ (* let ctx, args_vl = eval_operands config ctx args in *)
447+ let args_vl, ctx, cc = eval_operands config span args ctx in
448+
449+ (* Evaluate the call
450+ *
451+ * Style note: at some point we used {!comp_transmit} to
452+ * transmit the result of {!eval_operands} above down to {!push_vars}
453+ * below, without having to introduce an intermediary function call,
454+ * but it made it less clear where the computed values came from,
455+ * so we reversed the modifications. *)
456+ (* Push the stack frame: we initialize the frame with the return variable,
457+ and one variable per input argument *)
458+ let ctx = push_frame ctx in
459+
460+ (* Create and push the return variable *)
461+ let ret_vid = VarId. zero in
462+ let ret_ty = get_assumed_function_return_type span ctx fid generics in
463+ let ret_var = mk_var ret_vid (Some " @return" ) ret_ty in
464+ let ctx = push_uninitialized_var span ret_var ctx in
465+
466+ (* Create and push the input variables *)
467+ let input_vars =
468+ VarId. mapi_from1
469+ (fun id (v : typed_value ) -> (mk_var id None v.ty, v))
470+ args_vl
471+ in
472+ let ctx = push_vars span input_vars ctx in
473+
474+ (* "Execute" the function body. As the functions are assumed, here we call
475+ * custom functions to perform the proper manipulations: we don't have
476+ * access to a body. *)
477+ let ctx, cf_eval_body =
478+ match fid with
479+ | BoxNew -> eval_box_new_concrete config span generics ctx
480+ | ArrayIndexShared
481+ | ArrayIndexMut
482+ | ArrayToSliceShared
483+ | ArrayToSliceMut
484+ | ArrayRepeat
485+ | SliceIndexShared
486+ | SliceIndexMut -> craise __FILE__ __LINE__ span " Unimplemented"
487+ in
488+ let cc = cc_comp cc cf_eval_body in
489+
490+ (* Pop the frame *)
491+ comp cc (pop_frame_assign config span dest ctx)
552492
553493(* * Helper
554494
@@ -1552,45 +1492,22 @@ and eval_assumed_function_call_symbolic (config : config) (span : Meta.span)
15521492 generics.types)
15531493 span;
15541494
1555- (* There are two cases (and this is extremely annoying):
1556- - the function is not box_free
1557- - the function is box_free
1558- See {!eval_box_free}
1559- *)
1560- match fid with
1561- | BoxFree ->
1562- (* Degenerate case: box_free - note that this is not really a function
1563- * call: no need to call a "synthesize_..." function *)
1564- let ctx, cc = eval_box_free config span generics args dest ctx in
1565- ([ (ctx, Unit ) ], cc_singleton __FILE__ __LINE__ span cc)
1566- | _ ->
1567- (* "Normal" case: not box_free *)
1568- (* In symbolic mode, the behaviour of a function call is completely defined
1569- * by the signature of the function: we thus simply generate correctly
1570- * instantiated signatures, and delegate the work to an auxiliary function *)
1571- let sg, regions_hierarchy, inst_sig =
1572- match fid with
1573- | BoxFree ->
1574- (* Should have been treated above *)
1575- craise __FILE__ __LINE__ span " Unreachable"
1576- | _ ->
1577- let regions_hierarchy =
1578- LlbcAstUtils.FunIdMap. find (FAssumed fid)
1579- ctx.fun_ctx.regions_hierarchies
1580- in
1581- (* There shouldn't be any reference to Self *)
1582- let tr_self = UnknownTrait __FUNCTION__ in
1583- let sg = Assumed. get_assumed_fun_sig fid in
1584- let inst_sg =
1585- instantiate_fun_sig span ctx generics tr_self sg regions_hierarchy
1586- in
1587- (sg, regions_hierarchy, inst_sg)
1588- in
1495+ (* In symbolic mode, the behaviour of a function call is completely defined
1496+ * by the signature of the function: we thus simply generate correctly
1497+ * instantiated signatures, and delegate the work to an auxiliary function *)
1498+ let regions_hierarchy =
1499+ LlbcAstUtils.FunIdMap. find (FAssumed fid) ctx.fun_ctx.regions_hierarchies
1500+ in
1501+ (* There shouldn't be any reference to Self *)
1502+ let tr_self = UnknownTrait __FUNCTION__ in
1503+ let sg = Assumed. get_assumed_fun_sig fid in
1504+ let inst_sig =
1505+ instantiate_fun_sig span ctx generics tr_self sg regions_hierarchy
1506+ in
15891507
1590- (* Evaluate the function call *)
1591- eval_function_call_symbolic_from_inst_sig config span
1592- (FunId (FAssumed fid)) sg regions_hierarchy inst_sig generics None args
1593- dest ctx
1508+ (* Evaluate the function call *)
1509+ eval_function_call_symbolic_from_inst_sig config span (FunId (FAssumed fid))
1510+ sg regions_hierarchy inst_sig generics None args dest ctx
15941511
15951512(* * Evaluate a statement seen as a function body *)
15961513and eval_function_body (config : config ) (body : statement ) : stl_cm_fun =
0 commit comments