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

Always-inlined annotated function does not get inlined in OClassic #2355

Open
poechsel opened this issue Mar 13, 2024 · 1 comment
Open

Always-inlined annotated function does not get inlined in OClassic #2355

poechsel opened this issue Mar 13, 2024 · 1 comment

Comments

@poechsel
Copy link
Contributor

The following snippet behaves differently between OClassic and O3:

let[@inline always] loop_impl x =
  let rec loop x = if x then x else loop (not x) in
  loop x
;;

let wrap x = (loop_impl [@inlined always]) x

Works with -O3:

$ ocamlopt.opt -intf-suffix .no-mli -c -impl foo.ml -O3

Warns with -OClassic:

$ ocamlopt.opt -intf-suffix .no-mli -c -impl foo.ml -Oclassic
File "foo.ml", line 6, characters 13-44:
6 | let wrap x = (loop_impl [@inlined always]) x
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Warning 55 [inlining-impossible]: Cannot inline: 
  the optimizer did not know what function was being applied (is it marked [@inline never]?)
  (the full inlining stack was: foo.ml:6,13--44)\

This behavior is confusing: the function is marked as inline always, but does not actually get inlined by OClassic. There's two ways to go about that:

  • Make OClassic inline this function, but this will make OClassic's behavior diverge from the historical closure behavior
  • Do not inline this function, but emit a better warning saying something along the line of "Can't inline in OClassic because the function contained subfunctions"
@lthls
Copy link
Contributor

lthls commented Mar 13, 2024

For reference, Closure produces the following output:

File "foo.ml", line 6, characters 13-44:
6 | let wrap x = (loop_impl [@inlined always]) x
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Warning 55 [inlining-impossible]: Cannot inline: Function information unavailable

We should have enough information in classic mode to emit a better warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants