Skip to content

Stricter complex arity + fix tupled functions #2

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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
make fmt
  • Loading branch information
chambart committed May 12, 2023
commit 915eb7665b5f26498e7e70c8939649d9ed355d18
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ val is_empty : t -> bool

val same_number : t -> t -> bool

val arity : t -> [>] Flambda_arity.t
val arity : t -> [> ] Flambda_arity.t

val check_no_duplicates : t -> unit

Expand Down
16 changes: 5 additions & 11 deletions middle_end/flambda2/from_lambda/lambda_to_flambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,14 @@ module Env : sig
val register_unboxed_product :
t ->
unboxed_product:Ident.t ->
before_unarization:
[`Complex] Flambda_arity.Component_for_creation.t ->
before_unarization:[`Complex] Flambda_arity.Component_for_creation.t ->
fields:(Ident.t * Flambda_kind.With_subkind.t) list ->
t

val get_unboxed_product_fields :
t ->
Ident.t ->
([`Complex] Flambda_arity.Component_for_creation.t
* Ident.t list)
option
([`Complex] Flambda_arity.Component_for_creation.t * Ident.t list) option

type add_continuation_result = private
{ body_env : t;
Expand Down Expand Up @@ -1345,15 +1342,13 @@ type cps_continuation =
| Non_tail of non_tail_continuation

let apply_cps_cont_simple k ?(dbg = Debuginfo.none) acc env ccenv simples
(arity_component :
[`Complex] Flambda_arity.Component_for_creation.t) =
(arity_component : [`Complex] Flambda_arity.Component_for_creation.t) =
match k with
| Tail k -> apply_cont_with_extra_args acc env ccenv ~dbg k None simples
| Non_tail k -> k acc env ccenv simples arity_component

let apply_cps_cont k ?dbg acc env ccenv id
(arity_component :
[`Complex] Flambda_arity.Component_for_creation.t) =
(arity_component : [`Complex] Flambda_arity.Component_for_creation.t) =
apply_cps_cont_simple k ?dbg acc env ccenv [IR.Var id] arity_component

let maybe_insert_let_cont result_var_name layout k acc env ccenv body =
Expand Down Expand Up @@ -2058,8 +2053,7 @@ and cps_non_tail_list :
(* Always evaluate right-to-left. *)
cps_non_tail_list_core acc env ccenv lams
(fun acc env ccenv ids
(arity :
[`Complex] Flambda_arity.Component_for_creation.t list) ->
(arity : [`Complex] Flambda_arity.Component_for_creation.t list) ->
k acc env ccenv (List.rev ids) (List.rev arity))
k_exn

Expand Down
4 changes: 1 addition & 3 deletions middle_end/flambda2/kinds/flambda_arity.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ module Component = struct
| Unboxed_product ts -> List.concat_map unarize ts

let component : [`Unarized] t -> Flambda_kind.With_subkind.t =
fun t ->
match t with
| Singleton kind -> kind
fun t -> match t with Singleton kind -> kind
end

type 'uc t = 'uc Component.t list
Expand Down
6 changes: 4 additions & 2 deletions middle_end/flambda2/kinds/flambda_arity.mli
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ val unarize : [`Complex] t -> Flambda_kind.With_subkind.t list
val unarized_components : [`Unarized] t -> Flambda_kind.With_subkind.t list

(** Like [unarize] but returns one list per parameter. *)
val unarize_per_parameter : [`Complex] t -> Flambda_kind.With_subkind.t list list
val unarize_per_parameter :
[`Complex] t -> Flambda_kind.With_subkind.t list list

(** Like [unarize] but returns a value of type [t]. *)
val unarize_t : [`Complex] t -> [`Unarized] t
Expand All @@ -92,4 +93,5 @@ val from_lambda_list : Lambda.layout list -> [`Complex] t

(** Remove the first portion of an arity to correspond to a partial
application. *)
val partially_apply : [`Complex] t -> num_non_unarized_params_provided:int -> [`Complex] t
val partially_apply :
[`Complex] t -> num_non_unarized_params_provided:int -> [`Complex] t
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 @@ -459,13 +459,11 @@ let is_default_arity (a : [`Unarized] Flambda_arity.t) =

let complex_arity (a : [`Complex] Flambda_arity.t) : Fexpr.arity =
(* CR mshinwell: add unboxed arities to Fexpr *)
Flambda_arity.unarize a
|> List.map kind_with_subkind
Flambda_arity.unarize a |> List.map kind_with_subkind

let arity (a : [`Unarized] Flambda_arity.t) : Fexpr.arity =
(* CR mshinwell: add unboxed arities to Fexpr *)
Flambda_arity.unarized_components a
|> List.map kind_with_subkind
Flambda_arity.unarized_components a |> List.map kind_with_subkind

let arity_opt (a : [`Unarized] Flambda_arity.t) : Fexpr.arity option =
if is_default_arity a then None else Some (arity a)
Expand Down
4 changes: 3 additions & 1 deletion middle_end/flambda2/simplify/expr_builder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,9 @@ let rewrite_fixed_arity_continuation0 uacc cont_or_apply_cont ~use_id arity :
(fun _kind -> Variable.create "param")
(Flambda_arity.unarized_components arity)
in
let params = List.map2 BP.create params (Flambda_arity.unarized_components arity) in
let params =
List.map2 BP.create params (Flambda_arity.unarized_components arity)
in
let args = List.map BP.simple params in
let params = Bound_parameters.create params in
let apply_cont = Apply_cont.create cont ~args ~dbg:Debuginfo.none in
Expand Down
36 changes: 14 additions & 22 deletions middle_end/flambda2/simplify/simplify_apply_expr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ let simplify_direct_full_application ~simplify_expr dacc apply function_type
arg))
denv params args
in
let result_arity = Flambda_arity.unarized_components result_arity in
let result_arity =
Flambda_arity.unarized_components result_arity
in
let denv =
List.fold_left2
(fun denv kind result ->
Expand Down Expand Up @@ -597,12 +599,10 @@ let simplify_direct_partial_application ~simplify_expr dacc apply
Code.create code_id ~params_and_body
~free_names_of_params_and_body:free_names ~newer_version_of:None
~params_arity:(Bound_parameters.arity remaining_params)
~num_trailing_local_params
~result_arity:result_arity
~result_types:Unknown ~contains_no_escaping_local_allocs ~stub:true
~inline:Default_inline ~poll_attribute:Default
~check:Check_attribute.Default_check ~is_a_functor:false ~recursive
~cost_metrics:cost_metrics_of_body
~num_trailing_local_params ~result_arity ~result_types:Unknown
~contains_no_escaping_local_allocs ~stub:true ~inline:Default_inline
~poll_attribute:Default ~check:Check_attribute.Default_check
~is_a_functor:false ~recursive ~cost_metrics:cost_metrics_of_body
~inlining_arguments:(DE.inlining_arguments (DA.denv dacc))
~dbg ~is_tupled:false
~is_my_closure_used:
Expand Down Expand Up @@ -770,8 +770,7 @@ let simplify_direct_function_call ~simplify_expr dacc apply
present on the application expression, so all we can do is check that
the function being overapplied returns kind Value. *)
if not
(Flambda_arity.equal_ignoring_subkinds
result_arity
(Flambda_arity.equal_ignoring_subkinds result_arity
result_arity_of_application)
then
Misc.fatal_errorf
Expand Down Expand Up @@ -807,10 +806,9 @@ let simplify_direct_function_call ~simplify_expr dacc apply
Apply.print apply;
simplify_direct_partial_application ~simplify_expr dacc apply
~callee's_code_id ~callee's_code_metadata ~callee's_function_slot
~param_arity:params_arity ~args_arity
~result_arity:result_arity
~recursive ~down_to_up ~coming_from_indirect
~closure_alloc_mode_from_type ~current_region
~param_arity:params_arity ~args_arity ~result_arity ~recursive
~down_to_up ~coming_from_indirect ~closure_alloc_mode_from_type
~current_region
~num_trailing_local_non_unarized_params:
(Code_metadata.num_trailing_local_params callee's_code_metadata))
else
Expand All @@ -826,9 +824,7 @@ let rebuild_function_call_where_callee's_type_unavailable apply call_kind
|> Simplify_common.update_exn_continuation_extra_args uacc ~exn_cont_use_id
in
let uacc, expr =
EB.rewrite_fixed_arity_apply uacc ~use_id
(Apply.return_arity apply)
apply
EB.rewrite_fixed_arity_apply uacc ~use_id (Apply.return_arity apply) apply
in
after_rebuild expr uacc

Expand Down Expand Up @@ -1009,9 +1005,7 @@ let rebuild_method_call apply ~use_id ~exn_cont_use_id uacc ~after_rebuild =
apply
in
let uacc, expr =
EB.rewrite_fixed_arity_apply uacc ~use_id
(Apply.return_arity apply)
apply
EB.rewrite_fixed_arity_apply uacc ~use_id (Apply.return_arity apply) apply
in
after_rebuild expr uacc

Expand Down Expand Up @@ -1072,9 +1066,7 @@ let rebuild_c_call apply ~use_id ~exn_cont_use_id ~return_arity uacc
let uacc, expr =
match use_id with
| Some use_id ->
EB.rewrite_fixed_arity_apply uacc ~use_id
return_arity
apply
EB.rewrite_fixed_arity_apply uacc ~use_id return_arity apply
| None ->
let uacc =
UA.add_free_names uacc (Apply.free_names apply)
Expand Down
3 changes: 1 addition & 2 deletions middle_end/flambda2/simplify/simplify_set_of_closures.ml
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ let simplify_function_body context ~outer_dacc function_slot_opt
assert (not (DE.at_unit_toplevel (DA.denv dacc)));
match
C.simplify_function_body context dacc body ~return_continuation
~exn_continuation
~return_arity:(Code.result_arity code)
~exn_continuation ~return_arity:(Code.result_arity code)
~implicit_params:
(Bound_parameters.create
[ Bound_parameter.create my_closure
Expand Down
3 changes: 1 addition & 2 deletions middle_end/flambda2/terms/apply_expr.mli
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ val with_continuations : t -> Result_continuation.t -> Exn_continuation.t -> t
val with_exn_continuation : t -> Exn_continuation.t -> t

(** Change the arguments of an application *)
val with_args :
t -> Simple.t list -> args_arity:[`Complex] Flambda_arity.t -> t
val with_args : t -> Simple.t list -> args_arity:[`Complex] Flambda_arity.t -> t

(** Change the call kind of an application. *)
val with_call_kind : t -> Call_kind.t -> t
Expand Down
3 changes: 2 additions & 1 deletion middle_end/flambda2/types/grammar/more_type_creators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ let rec unknown_with_subkind ?(alloc_mode = Alloc_mode.For_types.unknown ())
let bottom_with_subkind kind = bottom (Flambda_kind.With_subkind.kind kind)

let unknown_types_from_arity arity =
List.map (unknown_with_subkind ?alloc_mode:None)
List.map
(unknown_with_subkind ?alloc_mode:None)
(Flambda_arity.unarized_components arity)

let bottom_types_from_arity arity =
Expand Down
3 changes: 2 additions & 1 deletion middle_end/flambda2/types/grammar/more_type_creators.mli
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ val unknown_with_subkind :
Type_grammar.t

(** For each of the kinds in an arity, create an "unknown" type. *)
val unknown_types_from_arity : [`Unarized] Flambda_arity.t -> Type_grammar.t list
val unknown_types_from_arity :
[`Unarized] Flambda_arity.t -> Type_grammar.t list

(** For each of the kinds in an arity, create an "bottom" type. *)
val bottom_types_from_arity : [`Complex] Flambda_arity.t -> Type_grammar.t list