Skip to content

Revert "Refactor of simplify-let-cont" #1068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions middle_end/flambda2/compare/compare.ml
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,13 @@ and subst_let_cont env (let_cont_expr : Let_cont_expr.t) =
Let_cont_expr.create_non_recursive cont handler ~body
~free_names_of_body:Unknown)
| Recursive handlers ->
Recursive_let_cont_handlers.pattern_match handlers
~f:(fun ~invariant_params ~body handlers ->
Recursive_let_cont_handlers.pattern_match handlers ~f:(fun ~body handlers ->
let body = subst_expr env body in
let handlers =
Continuation.Map.map_sharing (subst_cont_handler env)
(handlers |> Continuation_handlers.to_map)
in
Let_cont_expr.create_recursive handlers ~invariant_params ~body)
Let_cont_expr.create_recursive handlers ~body)

and subst_cont_handler env cont_handler =
Continuation_handler.pattern_match cont_handler ~f:(fun params ~handler ->
Expand Down Expand Up @@ -1252,15 +1251,15 @@ and let_cont_exprs env (let_cont1 : Let_cont.t) (let_cont2 : Let_cont.t) :
|> Comparison.map ~f:Continuation.Map.of_list
in
Recursive_let_cont_handlers.pattern_match_pair handlers1 handlers2
~f:(fun ~invariant_params ~body1 ~body2 cont_handlers1 cont_handlers2 ->
~f:(fun ~body1 ~body2 cont_handlers1 cont_handlers2 ->
pairs ~f1:exprs ~f2:compare_handler_maps
~subst2:(fun env map ->
Continuation.Map.map_sharing (subst_cont_handler env) map)
env
(body1, cont_handlers1 |> Continuation_handlers.to_map)
(body2, cont_handlers2 |> Continuation_handlers.to_map)
|> Comparison.map ~f:(fun (body, handlers) ->
Let_cont_expr.create_recursive handlers ~invariant_params ~body))
Let_cont_expr.create_recursive handlers ~body))
| _, _ -> Different { approximant = subst_let_cont env let_cont1 }

and cont_handlers env handler1 handler2 =
Expand Down
6 changes: 1 addition & 5 deletions middle_end/flambda2/from_lambda/closure_conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -883,11 +883,7 @@ let close_let_cont acc env ~name ~is_exn_handler ~params
let handlers =
Continuation.Map.singleton name (handler, handler_params, is_exn_handler)
in
(* CR ncourant: If we could somehow detect the syntactically invariant
parameters here, we could be able to improve the results of [Simplify] in
some cases. *)
Let_cont_with_acc.build_recursive acc
~invariant_params:Bound_parameters.empty ~handlers ~body
Let_cont_with_acc.build_recursive acc ~handlers ~body

let close_exact_or_unknown_apply acc env
({ kind;
Expand Down
10 changes: 4 additions & 6 deletions middle_end/flambda2/from_lambda/closure_conversion_aux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -950,23 +950,22 @@ module Let_cont_with_acc = struct
let acc = Acc.remove_continuation_from_free_names cont acc in
acc, expr

let create_recursive acc ~invariant_params handlers ~body
~cost_metrics_of_handlers =
let create_recursive acc handlers ~body ~cost_metrics_of_handlers =
let acc =
Acc.increment_metrics
(Cost_metrics.increase_due_to_let_cont_recursive
~cost_metrics_of_handlers)
acc
in
let expr = Let_cont.create_recursive ~invariant_params handlers ~body in
let expr = Let_cont.create_recursive handlers ~body in
let acc =
Continuation.Map.fold
(fun cont _ acc -> Acc.remove_continuation_from_free_names cont acc)
handlers acc
in
acc, expr

let build_recursive acc ~invariant_params ~handlers ~body =
let build_recursive acc ~handlers ~body =
let handlers_free_names, cost_metrics_of_handlers, acc, handlers =
Continuation.Map.fold
(fun cont (handler, params, is_exn_handler)
Expand All @@ -991,8 +990,7 @@ module Let_cont_with_acc = struct
(Name_occurrences.increase_counts handlers_free_names))
acc
in
create_recursive acc ~invariant_params handlers ~body
~cost_metrics_of_handlers
create_recursive acc handlers ~body ~cost_metrics_of_handlers

let build_non_recursive acc cont ~handler_params ~handler ~body
~is_exn_handler =
Expand Down
1 change: 0 additions & 1 deletion middle_end/flambda2/from_lambda/closure_conversion_aux.mli
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ end
module Let_cont_with_acc : sig
val build_recursive :
Acc.t ->
invariant_params:Bound_parameters.t ->
handlers:
((Acc.t -> Expr_with_acc.t) * Bound_parameters.t * bool)
Continuation.Map.t ->
Expand Down
3 changes: 1 addition & 2 deletions middle_end/flambda2/parser/fexpr_to_flambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,7 @@ let rec expr env (e : Fexpr.expr) : Flambda.Expr.t =
~free_names_of_body:Unknown
| Recursive ->
let handlers = Continuation.Map.singleton name handler in
Flambda.Let_cont.create_recursive ~invariant_params:Bound_parameters.empty
handlers ~body)
Flambda.Let_cont.create_recursive handlers ~body)
| Let_cont _ -> failwith "TODO andwhere"
| Apply_cont ac -> Flambda.Expr.create_apply_cont (apply_cont env ac)
| Switch { scrutinee; cases } ->
Expand Down
6 changes: 2 additions & 4 deletions middle_end/flambda2/parser/flambda_to_fexpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,7 @@ and let_cont_expr env (lc : Flambda.Let_cont_expr.t) =
Fexpr.Let_cont { recursive = Nonrecursive; bindings = [binding]; body })
| Recursive handlers ->
Flambda.Recursive_let_cont_handlers.pattern_match handlers
~f:(fun ~invariant_params:_ ~body handlers ->
(* TODO support them *)
~f:(fun ~body handlers ->
let env =
Continuation.Set.fold
(fun c env ->
Expand Down Expand Up @@ -1025,8 +1024,7 @@ module Iter = struct
let h = Non_recursive_let_cont_handler.handler handler in
let_cont_aux f_c f_s k h body)
| Recursive handlers ->
Recursive_let_cont_handlers.pattern_match handlers
~f:(fun ~invariant_params:_ ~body conts ->
Recursive_let_cont_handlers.pattern_match handlers ~f:(fun ~body conts ->
assert (not (Continuation_handlers.contains_exn_handler conts));
let_cont_rec f_c f_s conts body)

Expand Down
Loading