Skip to content
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

Add [@inline ready] attribute and remove [@inline hint] (not [@inlined hint]) #351

Merged
merged 5 commits into from
Oct 28, 2021
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
Next Next commit
Use inline available not inline ready
  • Loading branch information
mshinwell committed Oct 28, 2021
commit a5e4fa7e2483e3aaedb2a9cf5915dc5cca5a79d0
2 changes: 1 addition & 1 deletion middle_end/closure/closure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ and close_functions { backend; fenv; cenv; mutable_vars } fun_defs =
in
let magic_scale_constant = 8. in
int_of_float (inline_threshold *. magic_scale_constant) + n
| Always_inline | Ready_inline -> max_int
| Always_inline | Available_inline -> max_int
| Never_inline -> min_int
| Unroll _ -> assert false
in
Expand Down
6 changes: 3 additions & 3 deletions middle_end/flambda/flambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ and print_function_declaration ppf var (f : function_declaration) =
let inline =
match f.inline with
| Always_inline -> " *inline*"
| Ready_inline -> " *inline_ready*"
| Available_inline -> " *inline_available*"
| Never_inline -> " *never_inline*"
| Unroll _ -> " *unroll*"
| Default_inline -> ""
Expand Down Expand Up @@ -1031,8 +1031,8 @@ let create_function_declaration ~params ~body ~stub ~dbg
begin match stub, inline with
| true, (Never_inline | Default_inline)
| false, (Never_inline | Default_inline
| Always_inline | Ready_inline | Unroll _) -> ()
| true, (Always_inline | Ready_inline | Unroll _) ->
| Always_inline | Available_inline | Unroll _) -> ()
| true, (Always_inline | Available_inline | Unroll _) ->
Misc.fatal_errorf
"Stubs may not be annotated as [Always_inline], \
[Hint_inline] or [Unroll]: %a"
mshinwell marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion middle_end/flambda/inline_and_simplify_aux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ let keep_body_check ~is_classic_mode ~recursive =
match fun_decl.inline with
| Default_inline -> can_inline_non_rec_function fun_decl
| Unroll factor -> factor > 0
| Always_inline | Ready_inline -> true
| Always_inline | Available_inline -> true
| Never_inline -> false
end
end
Expand Down
2 changes: 1 addition & 1 deletion middle_end/flambda/inlining_decision.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let inline env r ~lhs_of_application
| Default_inlined ->
match function_body.inline with
| Always_inline -> Always_inlined
| Ready_inline | Default_inline -> Default_inlined
| Available_inline | Default_inline -> Default_inlined
| Never_inline -> Never_inlined
| Unroll n -> Unroll n
in
Expand Down
2 changes: 1 addition & 1 deletion middle_end/flambda/simple_value_approx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ let print_function_declaration ppf var (f : function_declaration) =
let inline =
match b.inline with
| Always_inline -> " *inline*"
| Ready_inline -> " *inline_ready*"
| Available_inline -> " *inline_available*"
| Never_inline -> " *never_inline*"
| Unroll _ -> " *unroll*"
| Default_inline -> ""
Expand Down
2 changes: 1 addition & 1 deletion middle_end/flambda2/from_lambda/lambda_conversions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let inline_attribute (attr : L.inline_attribute) : Inline_attribute.t =
match attr with
| Always_inline -> Always_inline
| Never_inline -> Never_inline
| Ready_inline -> Ready_inline
| Available_inline -> Available_inline
| Unroll i -> Unroll i
| Default_inline -> Default_inline

Expand Down
2 changes: 1 addition & 1 deletion middle_end/flambda2/parser/fexpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ type function_arities =

type inline_attribute = Inline_attribute.t =
| Always_inline
| Ready_inline
| Available_inline
| Never_inline
| Unroll of int
| Default_inline
Expand Down
2 changes: 1 addition & 1 deletion middle_end/flambda2/parser/flambda_lex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let keyword_table =
"andwhere", KWD_ANDWHERE;
"apply", KWD_APPLY;
"asr", KWD_ASR;
"available", KWD_AVAILABLE;
"Block", KWD_BLOCK;
"boxed", KWD_BOXED;
"ccall", KWD_CCALL;
Expand Down Expand Up @@ -76,7 +77,6 @@ let keyword_table =
"notrace", KWD_NOTRACE;
"pop", KWD_POP;
"push", KWD_PUSH;
"ready", KWD_READY;
"rec", KWD_REC;
"rec_info", KWD_REC_INFO;
"regular", KWD_REGULAR;
Expand Down
2 changes: 1 addition & 1 deletion middle_end/flambda2/parser/flambda_lex.mll
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let keyword_table =
"andwhere", KWD_ANDWHERE;
"apply", KWD_APPLY;
"asr", KWD_ASR;
"available", KWD_AVAILABLE;
"Block", KWD_BLOCK;
"boxed", KWD_BOXED;
"ccall", KWD_CCALL;
Expand Down Expand Up @@ -76,7 +77,6 @@ let keyword_table =
"notrace", KWD_NOTRACE;
"pop", KWD_POP;
"push", KWD_PUSH;
"ready", KWD_READY;
"rec", KWD_REC;
"rec_info", KWD_REC_INFO;
"regular", KWD_REGULAR;
Expand Down
110 changes: 55 additions & 55 deletions middle_end/flambda2/parser/flambda_parser.ml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion middle_end/flambda2/parser/flambda_parser.mli
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ type token =
| KWD_REGULAR
| KWD_REC_INFO
| KWD_REC
| KWD_READY
| KWD_PUSH
| KWD_POP
| KWD_NOTRACE
Expand Down Expand Up @@ -124,6 +123,7 @@ type token =
| KWD_CCALL
| KWD_BOXED
| KWD_BLOCK
| KWD_AVAILABLE
| KWD_ASR
| KWD_APPLY
| KWD_ANDWHERE
Expand Down
4 changes: 2 additions & 2 deletions middle_end/flambda2/parser/flambda_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ let make_boxed_const_int (i, m) : static_data =
%token KWD_ANDWHERE [@symbol "andwhere"]
%token KWD_APPLY [@symbol "apply"]
%token KWD_ASR [@symbol "asr"]
%token KWD_AVAILABLE [@symbol "available"]
%token KWD_BLOCK [@symbol "Block"]
%token KWD_BOXED [@symbol "boxed"]
%token KWD_CCALL [@symbol "ccall"]
Expand Down Expand Up @@ -153,7 +154,6 @@ let make_boxed_const_int (i, m) : static_data =
%token KWD_NOTRACE [@symbol "notrace"]
%token KWD_POP [@symbol "pop"]
%token KWD_PUSH [@symbol "push"]
%token KWD_READY [@symbol "ready"]
%token KWD_REC [@symbol "rec"]
%token KWD_REC_INFO [@symbol "rec_info"]
%token KWD_REGULAR [@symbol "regular"]
Expand Down Expand Up @@ -684,7 +684,7 @@ call_kind:

inline:
| KWD_INLINE LPAREN KWD_ALWAYS RPAREN { Always_inline }
| KWD_INLINE LPAREN KWD_READY RPAREN { Ready_inline }
| KWD_INLINE LPAREN KWD_AVAILABLE RPAREN { Available_inline }
| KWD_INLINE LPAREN KWD_NEVER RPAREN { Never_inline }
| KWD_UNROLL LPAREN; i = plain_int; RPAREN { Inline_attribute.Unroll i }
| KWD_INLINE LPAREN KWD_DEFAULT RPAREN { Default_inline }
Expand Down
2 changes: 1 addition & 1 deletion middle_end/flambda2/parser/print_fexpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ let inline_attribute ~space ppf (i : Inline_attribute.t) =
let str =
match i with
| Always_inline -> Some "inline(always)"
| Ready_inline -> Some "inline(hint)"
| Available_inline -> Some "inline(hint)"
| Never_inline -> Some "inline(never)"
| Unroll i -> Some (Format.sprintf "unroll(%d)" i)
| Default_inline -> None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let make_decision ~inlining_arguments:args ~inline ~stub ~cost_metrics:metrics
examining call sites. *)
match (inline : Inline_attribute.t) with
| Never_inline -> Never_inline_attribute
| Ready_inline | Always_inline -> Attribute_inline
| Available_inline | Always_inline -> Attribute_inline
| Default_inline | Unroll _ ->
if stub
then Stub
Expand Down
4 changes: 2 additions & 2 deletions middle_end/flambda2/terms/code0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ let create ~print_function_params_and_body code_id
~cost_metrics ~inlining_arguments ~dbg ~is_tupled ~inlining_decision =
begin
match stub, inline with
| true, (Ready_inline | Never_inline | Default_inline)
| true, (Available_inline | Never_inline | Default_inline)
| ( false,
(Never_inline | Default_inline | Always_inline | Ready_inline | Unroll _)
(Never_inline | Default_inline | Always_inline | Available_inline | Unroll _)
) ->
()
| true, (Always_inline | Unroll _) ->
Expand Down
10 changes: 5 additions & 5 deletions middle_end/flambda2/terms/inline_attribute.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

type t =
| Always_inline
| Ready_inline
| Available_inline
| Never_inline
| Unroll of int
| Default_inline
Expand All @@ -27,24 +27,24 @@ let [@ocamlformat "disable"] print ppf t =
let fprintf = Format.fprintf in
match t with
| Always_inline -> fprintf ppf "Always_inline"
| Ready_inline -> fprintf ppf "Ready_inline"
| Available_inline -> fprintf ppf "Available_inline"
| Never_inline -> fprintf ppf "Never_inline"
| Unroll n -> fprintf ppf "@[(Unroll %d)@]" n
| Default_inline -> fprintf ppf "Default_inline"

let equal t1 t2 =
match t1, t2 with
| Always_inline, Always_inline
| Ready_inline, Ready_inline
| Available_inline, Available_inline
| Never_inline, Never_inline
| Default_inline, Default_inline ->
true
| Unroll n1, Unroll n2 -> n1 = n2
| (Always_inline | Ready_inline | Never_inline | Unroll _ | Default_inline), _
| (Always_inline | Available_inline | Never_inline | Unroll _ | Default_inline), _
->
false

let is_default t =
match t with
| Default_inline -> true
| Always_inline | Ready_inline | Never_inline | Unroll _ -> false
| Always_inline | Available_inline | Never_inline | Unroll _ -> false
2 changes: 1 addition & 1 deletion middle_end/flambda2/terms/inline_attribute.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

type t =
| Always_inline
| Ready_inline
| Available_inline
| Never_inline
| Unroll of int
| Default_inline
Expand Down
6 changes: 3 additions & 3 deletions ocaml/lambda/lambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ type tailcall_attribute =
type inline_attribute =
| Always_inline (* [@inline] or [@inline always] *)
| Never_inline (* [@inline never] *)
| Ready_inline (* [@inline ready] *)
| Available_inline (* [@inline available] *)
| Unroll of int (* [@unroll x] *)
| Default_inline (* no [@inline] attribute *)

Expand All @@ -250,14 +250,14 @@ let equal_inline_attribute (x : inline_attribute) (y : inline_attribute) =
match x, y with
| Always_inline, Always_inline
| Never_inline, Never_inline
| Ready_inline, Ready_inline
| Available_inline, Available_inline
| Default_inline, Default_inline
->
true
| Unroll u, Unroll v ->
u = v
| (Always_inline | Never_inline
| Ready_inline | Unroll _ | Default_inline), _ ->
| Available_inline | Unroll _ | Default_inline), _ ->
false

let equal_inlined_attribute (x : inlined_attribute) (y : inlined_attribute) =
Expand Down
2 changes: 1 addition & 1 deletion ocaml/lambda/lambda.mli
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ type tailcall_attribute =
type inline_attribute =
| Always_inline (* [@inline] or [@inline always] *)
| Never_inline (* [@inline never] *)
| Ready_inline (* [@inline ready] *)
| Available_inline (* [@inline available] *)
| Unroll of int (* [@unroll x] *)
| Default_inline (* no [@inline] attribute *)

Expand Down
2 changes: 1 addition & 1 deletion ocaml/lambda/printlambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ let function_attribute ppf { inline; specialise; local; is_a_functor; stub } =
begin match inline with
| Default_inline -> ()
| Always_inline -> fprintf ppf "always_inline@ "
| Ready_inline -> fprintf ppf "ready_inline@ "
| Available_inline -> fprintf ppf "available_inline@ "
| Never_inline -> fprintf ppf "never_inline@ "
| Unroll i -> fprintf ppf "unroll(%i)@ " i
end;
Expand Down
2 changes: 1 addition & 1 deletion ocaml/lambda/simplif.ml
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ let simplify_local_functions lam =
let enabled = function
| {local = Always_local; _}
| {local = Default_local;
inline = (Never_inline | Default_inline | Ready_inline); _}
inline = (Never_inline | Default_inline | Available_inline); _}
-> true
| {local = Default_local;
inline = (Always_inline | Unroll _); _}
Expand Down
8 changes: 4 additions & 4 deletions ocaml/lambda/translattribute.ml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ let parse_inline_attribute attr : inline_attribute =
[
"never", Never_inline;
"always", Always_inline;
"ready", Ready_inline;
"available", Available_inline;
]
payload

Expand Down Expand Up @@ -211,7 +211,7 @@ let get_local_attribute l =

let check_local_inline loc attr =
match attr.local, attr.inline with
| Always_local, (Always_inline | Ready_inline | Unroll _) ->
| Always_local, (Always_inline | Available_inline | Unroll _) ->
Location.prerr_warning loc
(Warnings.Duplicated_attribute "local/inline")
| _ ->
Expand All @@ -223,14 +223,14 @@ let add_inline_attribute expr loc attributes =
| Lfunction({ attr = { stub = false } as attr } as funct), inline ->
begin match attr.inline with
| Default_inline -> ()
| Always_inline | Ready_inline | Never_inline | Unroll _ ->
| Always_inline | Available_inline | Never_inline | Unroll _ ->
Location.prerr_warning loc
(Warnings.Duplicated_attribute "inline")
end;
let attr = { attr with inline } in
check_local_inline loc attr;
Lfunction { funct with attr = attr }
| expr, (Always_inline | Ready_inline | Never_inline | Unroll _) ->
| expr, (Always_inline | Available_inline | Never_inline | Unroll _) ->
Location.prerr_warning loc
(Warnings.Misplaced_attribute "inline");
expr
Expand Down
2 changes: 1 addition & 1 deletion ocaml/middle_end/closure/closure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ and close_functions { backend; fenv; cenv; mutable_vars } fun_defs =
in
let magic_scale_constant = 8. in
int_of_float (inline_threshold *. magic_scale_constant) + n
| Always_inline | Ready_inline -> max_int
| Always_inline | Available_inline -> max_int
| Never_inline -> min_int
| Unroll _ -> assert false
in
Expand Down
6 changes: 3 additions & 3 deletions ocaml/middle_end/flambda/flambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ and print_function_declaration ppf var (f : function_declaration) =
let inline =
match f.inline with
| Always_inline -> " *inline*"
| Ready_inline -> " *inline_ready*"
| Available_inline -> " *inline_available*"
| Never_inline -> " *never_inline*"
| Unroll _ -> " *unroll*"
| Default_inline -> ""
Expand Down Expand Up @@ -1031,8 +1031,8 @@ let create_function_declaration ~params ~body ~stub ~dbg
begin match stub, inline with
| true, (Never_inline | Default_inline)
| false, (Never_inline | Default_inline
| Always_inline | Ready_inline | Unroll _) -> ()
| true, (Always_inline | Ready_inline | Unroll _) ->
| Always_inline | Available_inline | Unroll _) -> ()
| true, (Always_inline | Available_inline | Unroll _) ->
Misc.fatal_errorf
"Stubs may not be annotated as [Always_inline], \
[Hint_inline] or [Unroll]: %a"
Expand Down
2 changes: 1 addition & 1 deletion ocaml/middle_end/flambda/inline_and_simplify_aux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ let keep_body_check ~is_classic_mode ~recursive =
match fun_decl.inline with
| Default_inline -> can_inline_non_rec_function fun_decl
| Unroll factor -> factor > 0
| Always_inline | Ready_inline -> true
| Always_inline | Available_inline -> true
| Never_inline -> false
end
end
Expand Down
2 changes: 1 addition & 1 deletion ocaml/middle_end/flambda/inlining_decision.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let inline env r ~lhs_of_application
| Default_inlined ->
match function_body.inline with
| Always_inline -> Always_inlined
| Ready_inline | Default_inline -> Default_inlined
| Available_inline | Default_inline -> Default_inlined
| Never_inline -> Never_inlined
| Unroll n -> Unroll n
in
Expand Down
2 changes: 1 addition & 1 deletion ocaml/middle_end/flambda/simple_value_approx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ let print_function_declaration ppf var (f : function_declaration) =
let inline =
match b.inline with
| Always_inline -> " *inline*"
| Ready_inline -> " *inline_ready*"
| Available_inline -> " *inline_available*"
| Never_inline -> " *never_inline*"
| Unroll _ -> " *unroll*"
| Default_inline -> ""
Expand Down
8 changes: 4 additions & 4 deletions ocaml/testsuite/tests/warnings/w47_inline.compilers.reference
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ File "w47_inline.ml", line 15, characters 23-29:
15 | let d = (fun x -> x) [@inline malformed attribute] (* rejected *)
^^^^^^
Warning 47 [attribute-payload]: illegal payload for attribute 'inline'.
It must be either 'never', 'always', 'ready' or empty
It must be either 'never', 'always', 'available' or empty
File "w47_inline.ml", line 16, characters 23-29:
16 | let e = (fun x -> x) [@inline malformed_attribute] (* rejected *)
^^^^^^
Warning 47 [attribute-payload]: illegal payload for attribute 'inline'.
It must be either 'never', 'always', 'ready' or empty
It must be either 'never', 'always', 'available' or empty
File "w47_inline.ml", line 17, characters 23-29:
17 | let f = (fun x -> x) [@inline : malformed_attribute] (* rejected *)
^^^^^^
Warning 47 [attribute-payload]: illegal payload for attribute 'inline'.
It must be either 'never', 'always', 'ready' or empty
It must be either 'never', 'always', 'available' or empty
File "w47_inline.ml", line 18, characters 23-29:
18 | let g = (fun x -> x) [@inline ? malformed_attribute] (* rejected *)
^^^^^^
Warning 47 [attribute-payload]: illegal payload for attribute 'inline'.
It must be either 'never', 'always', 'ready' or empty
It must be either 'never', 'always', 'available' or empty
File "w47_inline.ml", line 23, characters 15-22:
23 | let k x = (a [@inlined malformed]) x (* rejected *)
^^^^^^^
Expand Down