[compiler-hacking] @inline attribute?

Jeremy Yallop yallop at gmail.com
Thu Oct 30 14:37:25 GMT 2014


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.

For example, ctypes can generate a large function, "foreign", which
I'd like inlined and then further reduced.  The generated function
immediately matches its arguments, its arguments are usually manifest
values, and the continuations of the match are usually simple values,
so inlining the function will usually resolve in smaller and more
efficient code:

  (* definition of "foreign" in generated code *)
  let foreign x y = match x, y with
   | "x", Function (Int, Returning Int) ->
      fun v -> primitive v
   | (* lots more match cases *)

  (* call to foreign *)
  let f = foreign "x" (Function (Int, Returning Int))

It'd be nice if the above code compiled down to the equivalent of this:

  let f = fun v -> primitive v

There are a few steps besides inlining needed to accomplish this, but
it seems likely that a way to guide the inliner is likely to be
useful, both for the current compiler and once Pierre's new inliner is
complete.


More information about the Cam-compiler-hacking mailing list