Skip to content

Commit 84f3e3f

Browse files
sonmarchoRyan Lahfa
authored andcommitted
Merge branch 'main' into proving-with-lean
2 parents f2cabe5 + 80dbc55 commit 84f3e3f

File tree

11 files changed

+126
-192
lines changed

11 files changed

+126
-192
lines changed

charon-pin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# This is the commit from https://github.com/AeneasVerif/charon that should be used with this version of aeneas.
2-
13502d2f3bd477ee86acafe5974016dc7707db83
2+
79355ca1a90eccd7e3c3ded0fe3d1473a91f20ac

compiler/Assumed.ml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,6 @@ let raw_assumed_fun_infos : raw_assumed_fun_info list =
240240
false,
241241
"alloc::boxed::Box::new",
242242
Some [ true; false ] );
243-
(* BoxFree shouldn't be used *)
244-
( BoxFree,
245-
Sig.box_free_sig,
246-
false,
247-
"alloc::boxed::Box::free",
248-
Some [ true; false ] );
249243
(* Array Index *)
250244
( ArrayIndexShared,
251245
Sig.array_index_sig false,

compiler/FunsAnalysis.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,15 @@ let analyze_module (m : crate) (funs_map : fun_decl FunDeclId.Map.t)
104104

105105
method! visit_rvalue _env rv =
106106
match rv with
107-
| Use _ | RvRef _ | Global _ | Discriminant _ | Aggregate _ | Len _
108-
-> ()
107+
| Use _
108+
| RvRef _
109+
| Global _
110+
| Discriminant _
111+
| Aggregate _
112+
| Len _
113+
| NullaryOp _
114+
| RawPtr _
115+
| ShallowInitBox _ -> ()
109116
| UnaryOp (uop, _) -> can_fail := unop_can_fail uop || !can_fail
110117
| BinaryOp (bop, _, _) ->
111118
can_fail := binop_can_fail bop || !can_fail

compiler/InterpreterExpressions.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,9 @@ let eval_rvalue_not_global (config : config) (span : Meta.span)
862862
AST"
863863
| Global _ -> craise __FILE__ __LINE__ span "Unreachable"
864864
| Len _ -> craise __FILE__ __LINE__ span "Unhandled Len"
865+
| _ ->
866+
craise __FILE__ __LINE__ span
867+
("Unsupported operation: " ^ Print.EvalCtx.rvalue_to_string ctx rvalue)
865868

866869
let eval_fake_read (config : config) (span : Meta.span) (p : place) : cm_fun =
867870
fun ctx ->

compiler/InterpreterStatements.ml

Lines changed: 88 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -281,28 +281,20 @@ let push_frame (ctx : eval_ctx) : eval_ctx = ctx_push_frame ctx
281281
let 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

307299
let 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 *)
477430
let 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
@@ -952,18 +892,22 @@ and eval_statement_raw (config : config) (st : statement) : stl_cm_fun =
952892
| Global _ -> craise __FILE__ __LINE__ st.span "Unreachable"
953893
| Len _ ->
954894
craise __FILE__ __LINE__ st.span "Len is not handled yet"
895+
| ShallowInitBox _ ->
896+
craise __FILE__ __LINE__ st.span "ShallowInitBox"
955897
| Use _
956898
| RvRef (_, (BShared | BMut | BTwoPhaseMut | BShallow))
957-
| UnaryOp _ | BinaryOp _ | Discriminant _ | Aggregate _ ->
899+
| NullaryOp _
900+
| UnaryOp _
901+
| BinaryOp _
902+
| Discriminant _
903+
| Aggregate _
904+
| RawPtr _ ->
905+
let p = S.mk_mplace st.span p ctx in
958906
let rp = rvalue_get_place rvalue in
959907
let rp =
960-
match rp with
961-
| Some rp -> Some (S.mk_mplace st.span rp ctx)
962-
| None -> None
908+
Option.map (fun rp -> S.mk_mplace st.span rp ctx) rp
963909
in
964-
S.synthesize_assignment ctx
965-
(S.mk_mplace st.span p ctx)
966-
rv rp
910+
S.synthesize_assignment ctx p rv rp
967911
in
968912
let ctx, cc =
969913
comp cc (assign_to_place config st.span rv p ctx)
@@ -1548,45 +1492,22 @@ and eval_assumed_function_call_symbolic (config : config) (span : Meta.span)
15481492
generics.types)
15491493
span;
15501494

1551-
(* There are two cases (and this is extremely annoying):
1552-
- the function is not box_free
1553-
- the function is box_free
1554-
See {!eval_box_free}
1555-
*)
1556-
match fid with
1557-
| BoxFree ->
1558-
(* Degenerate case: box_free - note that this is not really a function
1559-
* call: no need to call a "synthesize_..." function *)
1560-
let ctx, cc = eval_box_free config span generics args dest ctx in
1561-
([ (ctx, Unit) ], cc_singleton __FILE__ __LINE__ span cc)
1562-
| _ ->
1563-
(* "Normal" case: not box_free *)
1564-
(* In symbolic mode, the behaviour of a function call is completely defined
1565-
* by the signature of the function: we thus simply generate correctly
1566-
* instantiated signatures, and delegate the work to an auxiliary function *)
1567-
let sg, regions_hierarchy, inst_sig =
1568-
match fid with
1569-
| BoxFree ->
1570-
(* Should have been treated above *)
1571-
craise __FILE__ __LINE__ span "Unreachable"
1572-
| _ ->
1573-
let regions_hierarchy =
1574-
LlbcAstUtils.FunIdMap.find (FAssumed fid)
1575-
ctx.fun_ctx.regions_hierarchies
1576-
in
1577-
(* There shouldn't be any reference to Self *)
1578-
let tr_self = UnknownTrait __FUNCTION__ in
1579-
let sg = Assumed.get_assumed_fun_sig fid in
1580-
let inst_sg =
1581-
instantiate_fun_sig span ctx generics tr_self sg regions_hierarchy
1582-
in
1583-
(sg, regions_hierarchy, inst_sg)
1584-
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
15851507

1586-
(* Evaluate the function call *)
1587-
eval_function_call_symbolic_from_inst_sig config span
1588-
(FunId (FAssumed fid)) sg regions_hierarchy inst_sig generics None args
1589-
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
15901511

15911512
(** Evaluate a statement seen as a function body *)
15921513
and eval_function_body (config : config) (body : statement) : stl_cm_fun =

compiler/InterpreterUtils.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,14 @@ let rvalue_get_place (rv : rvalue) : place option =
293293
match rv with
294294
| Use (Copy p | Move p) -> Some p
295295
| Use (Constant _) -> None
296-
| Len (p, _, _) | RvRef (p, _) -> Some p
297-
| UnaryOp _ | BinaryOp _ | Global _ | Discriminant _ | Aggregate _ -> None
296+
| Len (p, _, _) | RvRef (p, _) | RawPtr (p, _) -> Some p
297+
| NullaryOp _
298+
| UnaryOp _
299+
| BinaryOp _
300+
| Global _
301+
| Discriminant _
302+
| Aggregate _ -> None
303+
| ShallowInitBox _ -> failwith "ShallowInitBox"
298304

299305
(** See {!ValuesUtils.symbolic_value_has_borrows} *)
300306
let symbolic_value_has_borrows (ctx : eval_ctx) (sv : symbolic_value) : bool =

compiler/Print.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ module EvalCtx = struct
613613
let env = eval_ctx_to_fmt_env ctx in
614614
operand_to_string env op
615615

616+
let rvalue_to_string (ctx : eval_ctx) (rval : rvalue) : string =
617+
let env = eval_ctx_to_fmt_env ctx in
618+
rvalue_to_string env rval
619+
616620
let call_to_string (ctx : eval_ctx) (call : call) : string =
617621
let env = eval_ctx_to_fmt_env ctx in
618622
call_to_string env "" call

compiler/PrintPure.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ let fun_suffix (lp_id : LoopId.id option) : string =
491491
let llbc_assumed_fun_id_to_string (fid : A.assumed_fun_id) : string =
492492
match fid with
493493
| BoxNew -> "alloc::boxed::Box::new"
494-
| BoxFree -> "alloc::alloc::box_free"
495494
| ArrayIndexShared -> "@ArrayIndexShared"
496495
| ArrayIndexMut -> "@ArrayIndexMut"
497496
| ArrayToSliceShared -> "@ArrayToSliceShared"

compiler/PureMicroPasses.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,10 +1587,6 @@ let eliminate_box_functions (_ctx : trans_ctx) (def : fun_decl) : fun_decl =
15871587
| BoxNew ->
15881588
let arg, args = Collections.List.pop args in
15891589
mk_apps def.item_meta.span arg args
1590-
| BoxFree ->
1591-
sanity_check __FILE__ __LINE__ (args = [])
1592-
def.item_meta.span;
1593-
mk_unit_rvalue
15941590
| SliceIndexShared
15951591
| SliceIndexMut
15961592
| ArrayIndexShared

0 commit comments

Comments
 (0)