compiler optimisation of constant expressions

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


Hi,

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-23.3.4.5 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() ->
    ?FUNCTION_STRING.


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() ->
    "test_mod:test/0".


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

Regards,
Andreas
-- 

Andreas Schultz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210916/c347ab0a/attachment.htm>


More information about the erlang-questions mailing list