Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force OCaml to inline a function?

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

like image 941
kevinji Avatar asked Jan 26 '19 19:01

kevinji


People also ask

How do you force an inline function?

Inline function and classes: If you need to explicitly declare inline function in the class then just declare the function inside the class and define it outside the class using inline keyword.

How do you inline a method?

Press ⌥⌘N (macOS), or Ctrl+Alt+N (Windows/Linux), to inline a method.

How do you declare inline?

DATA - Inline Declaration - ABAP Keyword Documentation. A declaration expression with the declaration operator DATA declares a variable var used as an operand in the current writing position. The declared variable is visible statically in the program from the location DATA(var) and is valid in the current context.

How inline function is executed?

An inline function is one for which the compiler copies the code from the function definition directly into the code of the calling function rather than creating a separate set of instructions in memory. This eliminates call-linkage overhead and can expose significant optimization opportunities.


1 Answers

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.

like image 192
octachron Avatar answered Sep 30 '22 03:09

octachron