Skip to content

Commit 41b0078

Browse files
authored
Add [@inline ready] attribute and remove [@inline hint] (not [@inlined hint]) (#351)
1 parent 2484f48 commit 41b0078

File tree

74 files changed

+1932
-1444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1932
-1444
lines changed

middle_end/closure/closure.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,8 @@ let bind_params { backend; mutable_vars; _ } loc fdesc params args funct body =
785785
(* Check if a lambda term is ``pure'',
786786
that is without side-effects *and* not containing function definitions *)
787787

788-
let warning_if_forced_inline ~loc ~attribute warning =
789-
if attribute = Always_inline then
788+
let warning_if_forced_inlined ~loc ~attribute warning =
789+
if attribute = Always_inlined then
790790
Location.prerr_warning (Debuginfo.Scoped_location.to_location loc)
791791
(Warnings.Inlining_impossible warning)
792792

@@ -800,17 +800,17 @@ let fail_if_probe ~probe msg =
800800

801801
let direct_apply env fundesc ufunct uargs ~probe ~loc ~attribute =
802802
match fundesc.fun_inline, attribute with
803-
| _, Never_inline
803+
| _, Never_inlined
804804
| None, _ ->
805805
let dbg = Debuginfo.from_location loc in
806-
warning_if_forced_inline ~loc ~attribute
806+
warning_if_forced_inlined ~loc ~attribute
807807
"Function information unavailable";
808808
if not fundesc.fun_closed then begin
809809
fail_if_probe ~probe "Not closed"
810810
end;
811811
begin match probe, attribute with
812812
| None, _ -> ()
813-
| Some _, Never_inline -> ()
813+
| Some _, Never_inlined -> ()
814814
| Some _, _ ->
815815
fail_if_probe ~probe "Erroneously marked to be inlined"
816816
end;
@@ -993,7 +993,7 @@ let rec close ({ backend; fenv; cenv ; mutable_vars } as env) lam =
993993
ap_func=(Lvar funct_var);
994994
ap_args=internal_args;
995995
ap_tailcall=Default_tailcall;
996-
ap_inlined=Default_inline;
996+
ap_inlined=Default_inlined;
997997
ap_specialised=Default_specialise;
998998
ap_probe=None;
999999
};
@@ -1004,7 +1004,7 @@ let rec close ({ backend; fenv; cenv ; mutable_vars } as env) lam =
10041004
iter first_args
10051005
(Ulet (Immutable, Pgenval, VP.create funct_var, ufunct, new_fun))
10061006
in
1007-
warning_if_forced_inline ~loc ~attribute "Partial application";
1007+
warning_if_forced_inlined ~loc ~attribute "Partial application";
10081008
fail_if_probe ~probe "Partial application";
10091009
(new_fun, approx)
10101010

@@ -1015,7 +1015,7 @@ let rec close ({ backend; fenv; cenv ; mutable_vars } as env) lam =
10151015
let first_args = List.map (fun (id, _) -> Uvar id) first_args in
10161016
let rem_args = List.map (fun (id, _) -> Uvar id) rem_args in
10171017
let dbg = Debuginfo.from_location loc in
1018-
warning_if_forced_inline ~loc ~attribute "Over-application";
1018+
warning_if_forced_inlined ~loc ~attribute "Over-application";
10191019
fail_if_probe ~probe "Over-application";
10201020
let body =
10211021
Ugeneric_apply(direct_apply env ~loc ~attribute
@@ -1031,7 +1031,7 @@ let rec close ({ backend; fenv; cenv ; mutable_vars } as env) lam =
10311031
result, Value_unknown
10321032
| ((ufunct, _), uargs) ->
10331033
let dbg = Debuginfo.from_location loc in
1034-
warning_if_forced_inline ~loc ~attribute "Unknown function";
1034+
warning_if_forced_inlined ~loc ~attribute "Unknown function";
10351035
fail_if_probe ~probe "Unknown function";
10361036
(Ugeneric_apply(ufunct, uargs, dbg), Value_unknown)
10371037
end
@@ -1126,7 +1126,7 @@ let rec close ({ backend; fenv; cenv ; mutable_vars } as env) lam =
11261126
ap_func=funct;
11271127
ap_args=[arg];
11281128
ap_tailcall=Default_tailcall;
1129-
ap_inlined=Default_inline;
1129+
ap_inlined=Default_inlined;
11301130
ap_specialised=Default_specialise;
11311131
ap_probe=None;
11321132
})
@@ -1374,7 +1374,7 @@ and close_functions { backend; fenv; cenv; mutable_vars } fun_defs =
13741374
in
13751375
let magic_scale_constant = 8. in
13761376
int_of_float (inline_threshold *. magic_scale_constant) + n
1377-
| Always_inline | Hint_inline -> max_int
1377+
| Always_inline | Available_inline -> max_int
13781378
| Never_inline -> min_int
13791379
| Unroll _ -> assert false
13801380
in

middle_end/flambda/augment_specialised_args.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ module Make (T : S) = struct
468468
spec_args_bound_in_the_wrapper;
469469
kind = Direct (Closure_id.wrap new_fun_var);
470470
dbg = Debuginfo.none;
471-
inline = Default_inline;
471+
inlined = Default_inlined;
472472
specialise = Default_specialise;
473473
probe = None;
474474
}

middle_end/flambda/closure_conversion.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ let tupled_function_call_stub original_params unboxed_version ~closure_bound_var
8585
redundancy here (func is also unboxed_version) *)
8686
kind = Direct (Closure_id.wrap unboxed_version);
8787
dbg = Debuginfo.none;
88-
inline = Default_inline;
88+
inlined = Default_inlined;
8989
specialise = Default_specialise;
9090
probe = None;
9191
})
@@ -240,7 +240,7 @@ let rec close t env (lam : Lambda.lambda) : Flambda.t =
240240
args;
241241
kind = Indirect;
242242
dbg = Debuginfo.from_location ap_loc;
243-
inline = ap_inlined;
243+
inlined = ap_inlined;
244244
specialise = ap_specialised;
245245
probe = ap_probe;
246246
})))
@@ -425,7 +425,7 @@ let rec close t env (lam : Lambda.lambda) : Flambda.t =
425425
application attributes to functions applied with the application
426426
operators. *)
427427
ap_tailcall = Default_tailcall;
428-
ap_inlined = Default_inline;
428+
ap_inlined = Default_inlined;
429429
ap_specialised = Default_specialise;
430430
ap_probe = None;
431431
}

middle_end/flambda/flambda.ml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type apply = {
3030
args : Variable.t list;
3131
kind : call_kind;
3232
dbg : Debuginfo.t;
33-
inline : Lambda.inline_attribute;
33+
inlined : Lambda.inlined_attribute;
3434
specialise : Lambda.specialise_attribute;
3535
probe : Lambda.probe;
3636
}
@@ -192,26 +192,26 @@ let rec lam ppf (flam : t) =
192192
match flam with
193193
| Var (id) ->
194194
Variable.print ppf id
195-
| Apply({func; args; kind; inline; probe; dbg}) ->
195+
| Apply({func; args; kind; inlined; probe; dbg}) ->
196196
let direct ppf () =
197197
match kind with
198198
| Indirect -> ()
199199
| Direct closure_id -> fprintf ppf "*[%a]" Closure_id.print closure_id
200200
in
201-
let inline ppf () =
202-
match inline with
203-
| Always_inline -> fprintf ppf "<always>"
204-
| Never_inline -> fprintf ppf "<never>"
205-
| Hint_inline -> fprintf ppf "<hint>"
201+
let inlined ppf () =
202+
match inlined with
203+
| Always_inlined -> fprintf ppf "<always>"
204+
| Never_inlined -> fprintf ppf "<never>"
205+
| Hint_inlined -> fprintf ppf "<hint>"
206206
| Unroll i -> fprintf ppf "<unroll %i>" i
207-
| Default_inline -> ()
207+
| Default_inlined -> ()
208208
in
209209
let probe ppf () =
210210
match probe with
211211
| None -> ()
212212
| Some {name} -> fprintf ppf "<probe %s>" name
213213
in
214-
fprintf ppf "@[<2>(apply%a%a%a<%s>@ %a%a)@]" direct () inline () probe ()
214+
fprintf ppf "@[<2>(apply%a%a%a<%s>@ %a%a)@]" direct () inlined () probe ()
215215
(Debuginfo.to_string dbg)
216216
Variable.print func Variable.print_list args
217217
| Assign { being_assigned; new_value; } ->
@@ -381,7 +381,8 @@ and print_function_declaration ppf var (f : function_declaration) =
381381
in
382382
let inline =
383383
match f.inline with
384-
| Always_inline | Hint_inline -> " *inline*"
384+
| Always_inline -> " *inline*"
385+
| Available_inline -> " *inline_available*"
385386
| Never_inline -> " *never_inline*"
386387
| Unroll _ -> " *unroll*"
387388
| Default_inline -> ""
@@ -1030,11 +1031,11 @@ let create_function_declaration ~params ~body ~stub ~dbg
10301031
begin match stub, inline with
10311032
| true, (Never_inline | Default_inline)
10321033
| false, (Never_inline | Default_inline
1033-
| Always_inline | Hint_inline | Unroll _) -> ()
1034-
| true, (Always_inline | Hint_inline | Unroll _) ->
1034+
| Always_inline | Available_inline | Unroll _) -> ()
1035+
| true, (Always_inline | Available_inline | Unroll _) ->
10351036
Misc.fatal_errorf
10361037
"Stubs may not be annotated as [Always_inline], \
1037-
[Hint_inline] or [Unroll]: %a"
1038+
[Available_inline] or [Unroll]: %a"
10381039
print body
10391040
end;
10401041
begin match stub, specialise with

middle_end/flambda/flambda.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type apply = {
3838
args : Variable.t list;
3939
kind : call_kind;
4040
dbg : Debuginfo.t;
41-
inline : Lambda.inline_attribute;
41+
inlined : Lambda.inlined_attribute;
4242
(** Instructions from the source code as to whether the callee should
4343
be inlined. *)
4444
specialise : Lambda.specialise_attribute;

middle_end/flambda/flambda_invariants.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let ignore_set_of_closures_origin (_ : Set_of_closures_origin.t) = ()
4949
let ignore_closure_id (_ : Closure_id.t) = ()
5050
let ignore_var_within_closure (_ : Var_within_closure.t) = ()
5151
let ignore_tag (_ : Tag.t) = ()
52-
let ignore_inline_attribute (_ : Lambda.inline_attribute) = ()
52+
let ignore_inlined_attribute (_ : Lambda.inlined_attribute) = ()
5353
let ignore_specialise_attribute (_ : Lambda.specialise_attribute) = ()
5454
let ignore_probe (_ : Lambda.probe) = ()
5555
let ignore_value_kind (_ : Lambda.value_kind) = ()
@@ -186,12 +186,12 @@ let variable_and_symbol_invariants (program : Flambda.program) =
186186
loop (add_binding_occurrence env var) handler
187187
(* Everything else: *)
188188
| Var var -> check_variable_is_bound env var
189-
| Apply { func; args; kind; dbg; inline; specialise; probe } ->
189+
| Apply { func; args; kind; dbg; inlined; specialise; probe } ->
190190
check_variable_is_bound env func;
191191
check_variables_are_bound env args;
192192
ignore_call_kind kind;
193193
ignore_debuginfo dbg;
194-
ignore_inline_attribute inline;
194+
ignore_inlined_attribute inlined;
195195
ignore_specialise_attribute specialise;
196196
ignore_probe probe
197197
| Assign { being_assigned; new_value; } ->

middle_end/flambda/flambda_middle_end.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ let lambda_to_flambda ~ppf_dump ~prefixname ~backend ~size ~filename
167167
loop flam
168168
in
169169
let flam = back_end flam in
170-
(* Check that there aren't any unused "always inline" attributes. *)
170+
(* Check that there aren't any unused "always inlined" attributes. *)
171171
Flambda_iterators.iter_apply_on_program flam ~f:(fun apply ->
172-
match apply.inline with
173-
| Default_inline | Never_inline | Hint_inline -> ()
174-
| Always_inline ->
172+
match apply.inlined with
173+
| Default_inlined | Never_inlined | Hint_inlined -> ()
174+
| Always_inlined ->
175175
(* CR-someday mshinwell: consider a different error message if
176176
this triggers as a result of the propagation of a user's
177177
attribute into the second part of an over application

middle_end/flambda/flambda_utils.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ let toplevel_substitution sb tree =
249249
| Assign { being_assigned; new_value; } ->
250250
let new_value = sb new_value in
251251
Assign { being_assigned; new_value; }
252-
| Apply { func; args; kind; dbg; inline; specialise; probe; } ->
252+
| Apply { func; args; kind; dbg; inlined; specialise; probe; } ->
253253
let func = sb func in
254254
let args = List.map sb args in
255-
Apply { func; args; kind; dbg; inline; specialise; probe; }
255+
Apply { func; args; kind; dbg; inlined; specialise; probe; }
256256
| If_then_else (cond, e1, e2) ->
257257
let cond = sb cond in
258258
If_then_else (cond, e1, e2)
@@ -696,14 +696,14 @@ let substitute_read_symbol_field_for_variables
696696
bind_from_value @@
697697
bind_to_value @@
698698
Flambda.For { bound_var; from_value; to_value; direction; body }
699-
| Apply { func; args; kind; dbg; inline; specialise; probe } ->
699+
| Apply { func; args; kind; dbg; inlined; specialise; probe } ->
700700
let func, bind_func = make_var_subst func in
701701
let args, bind_args =
702702
List.split (List.map make_var_subst args)
703703
in
704704
bind_func @@
705705
List.fold_right (fun f expr -> f expr) bind_args @@
706-
Flambda.Apply { func; args; kind; dbg; inline; specialise; probe }
706+
Flambda.Apply { func; args; kind; dbg; inlined; specialise; probe }
707707
| Send { kind; meth; obj; args; dbg } ->
708708
let meth, bind_meth = make_var_subst meth in
709709
let obj, bind_obj = make_var_subst obj in

middle_end/flambda/inline_and_simplify.ml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ and simplify_set_of_closures original_env r
673673
and simplify_apply env r ~(apply : Flambda.apply) : Flambda.t * R.t =
674674
let {
675675
Flambda. func = lhs_of_application; args; kind = _; dbg;
676-
inline = inline_requested; specialise = specialise_requested;
676+
inlined = inlined_requested; specialise = specialise_requested;
677677
probe = probe_requested;
678678
} = apply in
679679
let dbg = E.add_inlined_debuginfo env ~dbg in
@@ -760,16 +760,16 @@ and simplify_apply env r ~(apply : Flambda.apply) : Flambda.t * R.t =
760760
simplify_full_application env r ~function_decls
761761
~lhs_of_application ~closure_id_being_applied ~function_decl
762762
~value_set_of_closures ~args ~args_approxs ~dbg
763-
~inline_requested ~specialise_requested ~probe_requested
763+
~inlined_requested ~specialise_requested ~probe_requested
764764
else if nargs > arity then
765765
simplify_over_application env r ~args ~args_approxs
766766
~function_decls ~lhs_of_application ~closure_id_being_applied
767-
~function_decl ~value_set_of_closures ~dbg ~inline_requested
767+
~function_decl ~value_set_of_closures ~dbg ~inlined_requested
768768
~specialise_requested
769769
else if nargs > 0 && nargs < arity then
770770
simplify_partial_application env r ~lhs_of_application
771771
~closure_id_being_applied ~function_decl ~args ~dbg
772-
~inline_requested ~specialise_requested
772+
~inlined_requested ~specialise_requested
773773
else
774774
Misc.fatal_errorf "Function with arity %d when simplifying \
775775
application expression: %a"
@@ -778,24 +778,25 @@ and simplify_apply env r ~(apply : Flambda.apply) : Flambda.t * R.t =
778778
wrap result, r
779779
| Wrong -> (* Insufficient approximation information to simplify. *)
780780
Apply ({ func = lhs_of_application; args; kind = Indirect; dbg;
781-
inline = inline_requested; specialise = specialise_requested;
781+
inlined = inlined_requested;
782+
specialise = specialise_requested;
782783
probe = probe_requested;
783784
}),
784785
ret r (A.value_unknown Other)))
785786

786787
and simplify_full_application env r ~function_decls ~lhs_of_application
787788
~closure_id_being_applied ~function_decl ~value_set_of_closures ~args
788-
~args_approxs ~dbg ~inline_requested ~specialise_requested
789+
~args_approxs ~dbg ~inlined_requested ~specialise_requested
789790
~probe_requested
790791
=
791792
Inlining_decision.for_call_site ~env ~r ~function_decls
792793
~lhs_of_application ~closure_id_being_applied ~function_decl
793794
~value_set_of_closures ~args ~args_approxs ~dbg ~simplify
794-
~inline_requested ~specialise_requested ~probe_requested
795+
~inlined_requested ~specialise_requested ~probe_requested
795796

796797
and simplify_partial_application env r ~lhs_of_application
797798
~closure_id_being_applied ~function_decl ~args ~dbg
798-
~inline_requested ~specialise_requested
799+
~inlined_requested ~specialise_requested
799800
=
800801
let arity = A.function_arity function_decl in
801802
assert (arity > List.length args);
@@ -805,16 +806,16 @@ and simplify_partial_application env r ~lhs_of_application
805806
(* CR-someday mshinwell: Pierre noted that we might like a function to be
806807
inlined when applied to its first set of arguments, e.g. for some kind
807808
of type class like thing. *)
808-
begin match (inline_requested : Lambda.inline_attribute) with
809-
| Always_inline | Never_inline ->
809+
begin match (inlined_requested : Lambda.inlined_attribute) with
810+
| Always_inlined | Never_inlined ->
810811
Location.prerr_warning (Debuginfo.to_location dbg)
811812
(Warnings.Inlining_impossible "[@inlined] attributes may not be used \
812813
on partial applications")
813814
| Unroll _ ->
814815
Location.prerr_warning (Debuginfo.to_location dbg)
815816
(Warnings.Inlining_impossible "[@unrolled] attributes may not be used \
816817
on partial applications")
817-
| Hint_inline | Default_inline -> ()
818+
| Hint_inlined | Default_inlined -> ()
818819
end;
819820
begin match (specialise_requested : Lambda.specialise_attribute) with
820821
| Always_specialise | Never_specialise ->
@@ -837,7 +838,7 @@ and simplify_partial_application env r ~lhs_of_application
837838
args = Parameter.List.vars freshened_params;
838839
kind = Direct closure_id_being_applied;
839840
dbg;
840-
inline = Default_inline;
841+
inlined = Default_inlined;
841842
specialise = Default_specialise;
842843
probe = None;
843844
}
@@ -862,7 +863,7 @@ and simplify_partial_application env r ~lhs_of_application
862863

863864
and simplify_over_application env r ~args ~args_approxs ~function_decls
864865
~lhs_of_application ~closure_id_being_applied ~function_decl
865-
~value_set_of_closures ~dbg ~inline_requested ~specialise_requested
866+
~value_set_of_closures ~dbg ~inlined_requested ~specialise_requested
866867
=
867868
let arity = A.function_arity function_decl in
868869
assert (arity < List.length args);
@@ -877,13 +878,13 @@ and simplify_over_application env r ~args ~args_approxs ~function_decls
877878
simplify_full_application env r ~function_decls ~lhs_of_application
878879
~closure_id_being_applied ~function_decl ~value_set_of_closures
879880
~args:full_app_args ~args_approxs:full_app_approxs ~dbg
880-
~inline_requested ~specialise_requested ~probe_requested:None
881+
~inlined_requested ~specialise_requested ~probe_requested:None
881882
in
882883
let func_var = Variable.create Internal_variable_names.full_apply in
883884
let expr : Flambda.t =
884885
Flambda.create_let func_var (Expr expr)
885886
(Apply { func = func_var; args = remaining_args; kind = Indirect; dbg;
886-
inline = inline_requested; specialise = specialise_requested;
887+
inlined = inlined_requested; specialise = specialise_requested;
887888
probe = None})
888889
in
889890
let expr = Lift_code.lift_lets_expr expr ~toplevel:true in

middle_end/flambda/inline_and_simplify_aux.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ let keep_body_check ~is_classic_mode ~recursive =
543543
match fun_decl.inline with
544544
| Default_inline -> can_inline_non_rec_function fun_decl
545545
| Unroll factor -> factor > 0
546-
| Always_inline | Hint_inline -> true
546+
| Always_inline | Available_inline -> true
547547
| Never_inline -> false
548548
end
549549
end

0 commit comments

Comments
 (0)