8

Is it possible to tell the OCaml compiler to inline a function, instead of hoping that its optimization process will do so itself?

Kevin Ji
  • 10,479
  • 4
  • 40
  • 63

1 Answers1

19

You can both add an attribute to always inline a function

let f x = x [@@inline always]
(* which is equivalent to *)
let f x = x [@@inline]

or force a specific call to be inlined with another attribute

let a = (f[@inlined]) 1

If you want to check inlining decisions made by flambda, you can use the inlining-report flag.

Kevin Ji
  • 10,479
  • 4
  • 40
  • 63
octachron
  • 17,178
  • 2
  • 16
  • 23