[erlang-questions] Inlining in Erlang

Matthias Lang matthias@REDACTED
Thu Feb 19 22:32:32 CET 2015


Hi,

On 18. February 2015, zxq9 wrote:

> 1. A function wrapper around the value:
>
>   some_value() -> 7.
>
> The function call involved will be optimized away by the compiler, but this
...
> This sucks for various reasons and achieves the same effect as #1 in any case
> (after compilation *literally* the same effect,

Going off on a tangent: getting the compiler to act as you describe
requires non-default options:

  | Inlining is never default; it must be explicitly enabled with a
  | compiler option or a -compile() attribute in the source module.
  |
  | To enable inlining, either use the inline option to let the compiler
  | decide which functions to inline or {inline,[{Name,Arity},...]} to
  | have the compiler inline all calls to the given functions. If the
  | option is given inside a compile directive in an Erlang module,
  | {Name,Arity} may be written as Name/Arity.
  |
  | http://www.erlang.org/doc/man/compile.html#file-1

I think HiPE, which isn't on by default, inlines by default. But
I haven't checked.

(I checked that the regular compiler doesn't inline by compiling to
assembler, i.e. the 'S' option, and inspecting the code. I didn't
check the beam loader, but I don't think it inlines things; if it does
then that is surprising.)

Matthias



More information about the erlang-questions mailing list