-
Notifications
You must be signed in to change notification settings - Fork 86
Refactor primitive handling in Lambda_to_flambda #1382
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -601,16 +601,40 @@ let close_exn_continuation acc env (exn_continuation : IR.exn_continuation) = | |
Exn_continuation.create ~exn_handler:exn_continuation.exn_handler | ||
~extra_args ) | ||
|
||
let close_raise acc env ~raise_kind ~arg loc exn_continuation = | ||
let acc, exn_cont = close_exn_continuation acc env exn_continuation in | ||
let exn_handler = Exn_continuation.exn_handler exn_cont in | ||
let acc, arg = find_simple acc env arg in | ||
let args = | ||
(* CR mshinwell: Share with [Lambda_to_flambda_primitives_helpers] *) | ||
let extra_args = | ||
List.map | ||
(fun (simple, _kind) -> simple) | ||
(Exn_continuation.extra_args exn_cont) | ||
in | ||
arg :: extra_args | ||
in | ||
let raise_kind = Some (Trap_action.Raise_kind.from_lambda raise_kind) in | ||
let trap_action = Trap_action.Pop { exn_handler; raise_kind } in | ||
let dbg = Debuginfo.from_location loc in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason to do that rather than give |
||
let acc, apply_cont = | ||
Apply_cont_with_acc.create acc ~trap_action exn_handler ~args ~dbg | ||
in | ||
(* Since raising of an exception doesn't terminate, we don't call [k]. *) | ||
Expr_with_acc.create_apply_cont acc apply_cont | ||
|
||
let close_primitive acc env ~let_bound_var named (prim : Lambda.primitive) ~args | ||
loc (exn_continuation : IR.exn_continuation option) ~current_region | ||
(k : Acc.t -> Named.t option -> Expr_with_acc.t) : Expr_with_acc.t = | ||
let orig_exn_continuation = exn_continuation in | ||
let acc, exn_continuation = | ||
match exn_continuation with | ||
| None -> acc, None | ||
| Some exn_continuation -> | ||
let acc, cont = close_exn_continuation acc env exn_continuation in | ||
acc, Some cont | ||
in | ||
let orig_args = args in | ||
let acc, args = find_simples acc env args in | ||
let dbg = Debuginfo.from_location loc in | ||
match prim, args with | ||
|
@@ -642,29 +666,14 @@ let close_primitive acc env ~let_bound_var named (prim : Lambda.primitive) ~args | |
k acc (Some named) | ||
| Praise raise_kind, [_] -> | ||
let exn_continuation = | ||
match exn_continuation with | ||
match orig_exn_continuation with | ||
| None -> | ||
Misc.fatal_errorf "Praise is missing exception continuation: %a" | ||
IR.print_named named | ||
| Some exn_continuation -> exn_continuation | ||
in | ||
let exn_handler = Exn_continuation.exn_handler exn_continuation in | ||
let args = | ||
(* CR mshinwell: Share with [Lambda_to_flambda_primitives_helpers] *) | ||
let extra_args = | ||
List.map | ||
(fun (simple, _kind) -> simple) | ||
(Exn_continuation.extra_args exn_continuation) | ||
in | ||
args @ extra_args | ||
in | ||
let raise_kind = Some (Trap_action.Raise_kind.from_lambda raise_kind) in | ||
let trap_action = Trap_action.Pop { exn_handler; raise_kind } in | ||
let acc, apply_cont = | ||
Apply_cont_with_acc.create acc ~trap_action exn_handler ~args ~dbg | ||
in | ||
(* Since raising of an exception doesn't terminate, we don't call [k]. *) | ||
Expr_with_acc.create_apply_cont acc apply_cont | ||
close_raise acc env ~raise_kind ~arg:(List.hd orig_args) loc | ||
exn_continuation | ||
| (Pmakeblock _ | Pmakefloatblock _ | Pmakearray _), [] -> | ||
(* Special case for liftable empty block or array *) | ||
let acc, sym = | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1430,9 +1430,12 @@ let primitive_result_layout (p : primitive) = | |||||
| Paddfloat _ | Psubfloat _ | Pmulfloat _ | Pdivfloat _ | ||||||
| Pbox_float _ -> layout_float | ||||||
| Punbox_float -> Punboxed_float | ||||||
| Pccall _p -> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should add a case |
||||||
(* CR ncourant: use native_repr *) | ||||||
| Pccall { prim_native_repr_res = _, Untagged_int; _} ->layout_int | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Pccall { prim_native_repr_res = _, Unboxed_float; _} -> layout_float | ||||||
| Pccall { prim_native_repr_res = _, Same_as_ocaml_repr; _} -> | ||||||
layout_any_value | ||||||
| Pccall { prim_native_repr_res = _, Unboxed_integer bi; _} -> | ||||||
layout_boxedint bi | ||||||
| Praise _ -> layout_bottom | ||||||
| Psequor | Psequand | Pnot | ||||||
| Pnegint | Paddint | Psubint | Pmulint | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we already do
let acc, args = find_simples acc env args
inclose_primitive
, I think this might duplicate the definition of the constant corresponding to the argument if it is one.