From d260a79416a9ace99357d81747c3677fced43319 Mon Sep 17 00:00:00 2001 From: Gabriel Scherer Date: Sun, 12 Apr 2020 15:28:13 +0200 Subject: [refactoring] gives tailcall attributes a more standard structure We want to start allowing more information in the payload of [@tailcall] attributes (currently no payload is supported), for example we could consider using [@tailcall false] to ask the code generator to disable a tail call. A first required step in this direction is to use a custom datatype to represent the tail-call attribute, instead of a boolean. This is consistent with the other application-site attributes (inline_attribute, specialise_attribute, local_attribute), so it makes the code more regular -- but the change itself is boilerplate-y. --- middle_end/closure/closure.ml | 29 +++++++++++++++++------------ middle_end/flambda/closure_conversion.ml | 8 ++++---- 2 files changed, 21 insertions(+), 16 deletions(-) (limited to 'middle_end') diff --git a/middle_end/closure/closure.ml b/middle_end/closure/closure.ml index 700ec9c405..a51768216c 100644 --- a/middle_end/closure/closure.ml +++ b/middle_end/closure/closure.ml @@ -940,12 +940,14 @@ let rec close ({ backend; fenv; cenv ; mutable_vars } as env) lam = kind = Curried; return = Pgenval; params = List.map (fun v -> v, Pgenval) final_args; - body = Lapply{ap_should_be_tailcall=false; - ap_loc=loc; - ap_func=(Lvar funct_var); - ap_args=internal_args; - ap_inlined=Default_inline; - ap_specialised=Default_specialise}; + body = Lapply{ + ap_loc=loc; + ap_func=(Lvar funct_var); + ap_args=internal_args; + ap_tailcall=Default_tailcall; + ap_inlined=Default_inline; + ap_specialised=Default_specialise; + }; loc; attr = default_function_attribute}) in @@ -1066,12 +1068,15 @@ let rec close ({ backend; fenv; cenv ; mutable_vars } as env) lam = close env arg | Lprim(Pdirapply,[funct;arg], loc) | Lprim(Prevapply,[arg;funct], loc) -> - close env (Lapply{ap_should_be_tailcall=false; - ap_loc=loc; - ap_func=funct; - ap_args=[arg]; - ap_inlined=Default_inline; - ap_specialised=Default_specialise}) + close env + (Lapply{ + ap_loc=loc; + ap_func=funct; + ap_args=[arg]; + ap_tailcall=Default_tailcall; + ap_inlined=Default_inline; + ap_specialised=Default_specialise; + }) | Lprim(Pgetglobal id, [], loc) -> let dbg = Debuginfo.from_location loc in check_constant_result (getglobal dbg id) diff --git a/middle_end/flambda/closure_conversion.ml b/middle_end/flambda/closure_conversion.ml index b47fb80c10..8c731a9faa 100644 --- a/middle_end/flambda/closure_conversion.ml +++ b/middle_end/flambda/closure_conversion.ml @@ -225,8 +225,8 @@ let rec close t env (lam : Lambda.lambda) : Flambda.t = in Flambda.create_let set_of_closures_var set_of_closures (name_expr (Project_closure (project_closure)) ~name) - | Lapply { ap_func; ap_args; ap_loc; ap_should_be_tailcall = _; - ap_inlined; ap_specialised; } -> + | Lapply { ap_func; ap_args; ap_loc; + ap_tailcall = _; ap_inlined; ap_specialised; } -> Lift_code.lifting_helper (close_list t env ap_args) ~evaluation_order:`Right_to_left ~name:Names.apply_arg @@ -418,10 +418,10 @@ let rec close t env (lam : Lambda.lambda) : Flambda.t = { ap_func = funct; ap_args = [arg]; ap_loc = loc; - ap_should_be_tailcall = false; (* CR-someday lwhite: it would be nice to be able to give - inlined attributes to functions applied with the application + application attributes to functions applied with the application operators. *) + ap_tailcall = Default_tailcall; ap_inlined = Default_inline; ap_specialised = Default_specialise; } -- cgit v1.2.1