Skip to content

Flambda2 layouts: Fix partial application wrapper result arity #1551

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 2 commits into from
Jul 12, 2023
Merged
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
30 changes: 17 additions & 13 deletions middle_end/flambda2/from_lambda/closure_conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ let close_let_rec acc env ~function_declarations
named ~body

let wrap_partial_application acc env apply_continuation (apply : IR.apply)
approx ~provided ~missing_arity ~first_complex_local_param
approx ~provided ~missing_arity ~result_arity ~first_complex_local_param
~contains_no_escaping_local_allocs =
(* In case of partial application, creates a wrapping function from scratch to
allow inlining and lifting *)
Expand Down Expand Up @@ -2049,7 +2049,8 @@ let wrap_partial_application acc env apply_continuation (apply : IR.apply)
continuation = return_continuation;
exn_continuation;
inlined = Lambda.Default_inlined;
mode = result_mode
mode = result_mode;
return_arity = result_arity
}
(Some approx) ~replace_region:None
in
Expand Down Expand Up @@ -2092,11 +2093,10 @@ let wrap_partial_application acc env apply_continuation (apply : IR.apply)
Flambda_arity.cardinal missing_arity
- first_complex_local_param
})
~params ~return:apply.return_arity ~return_continuation
~exn_continuation ~my_region:apply.region ~body:fbody ~attr
~loc:apply.loc ~free_idents_of_body ~closure_alloc_mode
~first_complex_local_param ~contains_no_escaping_local_allocs
Recursive.Non_recursive ]
~params ~return:result_arity ~return_continuation ~exn_continuation
~my_region:apply.region ~body:fbody ~attr ~loc:apply.loc
~free_idents_of_body ~closure_alloc_mode ~first_complex_local_param
~contains_no_escaping_local_allocs Recursive.Non_recursive ]
in
let body acc env =
let arg = find_simple_from_id env wrapper_id in
Expand Down Expand Up @@ -2213,7 +2213,8 @@ type call_args_split =
| Exact of IR.simple list
| Partial_app of
{ provided : IR.simple list;
missing_arity : Flambda_arity.t
missing_arity : Flambda_arity.t;
result_arity : Flambda_arity.t
}
| Over_app of
{ full : IR.simple list;
Expand All @@ -2230,6 +2231,7 @@ let close_apply acc env (apply : IR.apply) : Expr_with_acc.t =
let metadata = Code_or_metadata.code_metadata code in
Some
( Code_metadata.params_arity metadata,
Code_metadata.result_arity metadata,
Code_metadata.is_tupled metadata,
Code_metadata.first_complex_local_param metadata,
Code_metadata.contains_no_escaping_local_allocs metadata )
Expand All @@ -2246,14 +2248,15 @@ let close_apply acc env (apply : IR.apply) : Expr_with_acc.t =
match code_info with
| None -> close_exact_or_unknown_apply acc env apply None ~replace_region:None
| Some
( arity,
( params_arity,
result_arity,
is_tupled,
first_complex_local_param,
contains_no_escaping_local_allocs ) -> (
let acc, args_with_arities = find_simples_and_arity acc env apply.args in
let args_arity = List.map snd args_with_arities in
let split_args =
let arity = Flambda_arity.to_list arity in
let arity = Flambda_arity.to_list params_arity in
let split args arity =
let rec cut n l =
if n <= 0
Expand All @@ -2274,7 +2277,8 @@ let close_apply acc env (apply : IR.apply) : Expr_with_acc.t =
let _provided_arity, missing_arity = cut args_l arity in
Partial_app
{ provided = args;
missing_arity = Flambda_arity.create missing_arity
missing_arity = Flambda_arity.create missing_arity;
result_arity
}
else
let full, remaining = cut arity_l args in
Expand All @@ -2297,7 +2301,7 @@ let close_apply acc env (apply : IR.apply) : Expr_with_acc.t =
close_exact_or_unknown_apply acc env
{ apply with args; continuation = apply.continuation }
(Some approx) ~replace_region:None
| Partial_app { provided; missing_arity } ->
| Partial_app { provided; missing_arity; result_arity } ->
(match apply.inlined with
| Always_inlined | Unroll _ ->
Location.prerr_warning
Expand All @@ -2307,7 +2311,7 @@ let close_apply acc env (apply : IR.apply) : Expr_with_acc.t =
inlined_attribute_on_partial_application_msg Inlined))
| Never_inlined | Hint_inlined | Default_inlined -> ());
wrap_partial_application acc env apply.continuation apply approx ~provided
~missing_arity ~first_complex_local_param
~missing_arity ~result_arity ~first_complex_local_param
~contains_no_escaping_local_allocs
| Over_app { full; remaining; remaining_arity } ->
let full_args_call apply_continuation ~region acc =
Expand Down