[compiler-hacking] @inline attribute?
Pierre Chambart
pierre.chambart at ocamlpro.com
Thu Oct 30 16:22:34 GMT 2014
On 30/10/2014 17:01, Anil Madhavapeddy wrote:
> On 30 Oct 2014, at 14:42, Leo White <lpw25 at cam.ac.uk> wrote:
>>> I'm interested in people's thoughts on adding an @inline attribute,
>>> along the lines of GHC's {-# INLINE #-}:
>>>
>>> https://www.haskell.org/ghc/docs/7.0.2/html/users_guide/pragmas.html#inline-noinline-pragma
>>>
>>> It'd be useful to have a way of encouraging the compiler to inline
>>> functions which its own heuristics might discount as too large or
>>> otherwise too expensive.
>> I'd like it to go one step further and give a warning or error if
>> inlining could not be done for some reason (e.g. .cmx file not
>> present). I think this is very much inline with OCaml's philosophy of
>> predictable performance -- rather than just hope that the compiler
>> inlines something I can be certain of it.
> I agree. I would also like the reverse mode: a compiler mode that
> annotates existing source code with @inline attributes where it
> does actually take place, so that the programmer can get a sense
> of where it has happened in existing code.
>
> This might better be supported through Merlin or something, but I
> always liked how ocamlprof rewrote the source code with comments.
>
> Another hopefully simple option that would be handy is a compiler
> flag that flags a missing .cmx as an error for the purposes of
> cross-module inlining in ocamlopt, to prevent silently missing
> inlining opportunities due to build system bugs.
>
> -anil
It may be quite difficult to do something like that in the general case:
let f g x =
g x
If f is inlined in different contexts, in some cases g can be inlined in f
and not in other cases.
--
Pierre
More information about the Cam-compiler-hacking
mailing list