compiler optimisation of constant expressions

Andreas Schultz andreas.schultz@REDACTED
Thu Sep 16 11:15:15 CEST 2021


I've stumbled upon a statement in  EPP-0045 that made me wonder:

There is no run-time penality for defining `FUNCTION_STRING`
yourself, as the compiler will turn either definition of
`FUNCTION_STRING` into a literal string during compilation.
Historical note: `MODULE_STRING` was added as an optimization in OTP
R7B, because at the time the compiler did not optimize constant
expressions as well as it does now.

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).

What I would have expected is this:

test() ->

Has the optimization been lost or was it never implemented or am I doing
something wrong?


Andreas Schultz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the erlang-questions mailing list