compiler optimisation of constant expressions

Björn Gustavsson bjorn@REDACTED
Thu Sep 16 12:18:54 CEST 2021

On Thu, Sep 16, 2021 at 11:15 AM Andreas Schultz
<andreas.schultz@REDACTED> wrote:
> When I tested that on OTP- it turned out that the compiled beam file still contained the atom_to_list and integer_to_list calls, e.g. this code snippet:
> test() ->
> Is contained in the beam file as:
> test() ->
>     "test_mod" ++ ":" ++ atom_to_list(test) ++ "/" ++ integer_to_list(0).

If by "contained in the beam file" you mean the debug info, it has not
been optimized. We intentionally stay as close to the source code as

Later optimization passes will optimize the code. So if I have this module:

-compile([export_all, nowarn_export_all]).

-define(FUNCTION_STRING, atom_to_list(?MODULE) ++ ":" ++
atom_to_list(?FUNCTION_NAME) ++ "/" ++

test() ->

the BEAM code that I'll get if I compile like this:

erlc -S t.erl

will look this this:

{function, test, 0, 2}.


Björn Gustavsson, Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list