[compiler-hacking] @inline attribute?

Jeremy Yallop yallop at gmail.com
Thu Oct 30 17:09:35 GMT 2014


On 30 October 2014 14:42, Leo White <lpw25 at cam.ac.uk> wrote:
>> 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

Ha.

> OCaml's philosophy of
> predictable performance -- rather than just hope that the compiler
> inlines something I can be certain of it.

Agreed: it'd be useful to have a diagnostic, in the same vein as Simon
Cruanes' @tailcall implementation
(https://github.com/ocaml/ocaml/pull/111).

It also seems that it'd be useful to have @inline at both definition
and call sites.  GHC supports both, via different mechanisms: the
INLINE pragma for definitions and the special function
`GHC.Exts.inline` for calls:

   {-# INLINE foo #-}
   foo x y = x + y

   bar x = inline foo 2 3

In OCaml we might as well use attributes in both cases.


More information about the Cam-compiler-hacking mailing list