compiler optimisation of constant expressions

Сергей Прохоров seriy.pr@REDACTED
Thu Sep 16 13:27:48 CEST 2021


Please, have a look at this example:

http://tryerl.seriyps.ru/#id=e8b4

-module(main).
-export([main/0]).

-define(FUNCTION_STRING, atom_to_list(?FUNCTION_NAME) ++ "/" ++
          integer_to_list(?FUNCTION_ARITY)).

main() ->
    ?FUNCTION_STRING.

If you select "compile to: core erlang" or "compile to: static single
assignment" (which are different intermediate representations of Erlang
code on different compilation stages) you may notice that `atom_to_list` as
well as `++` calls are eventually replaced with string literal.

.core:

'main'/0 =
    %% Line 8
    ( fun () ->
 %% Line 9
 [109|[97|[105|[110|[47|[48]]]]]]
      -| [{'function',{'main',0}}] )

.ssa:

%% main.erl:8
%% Counter = 3
function `main`:`main`() {
0:
  ret `"main/0"`
}



Why do you think the beam file still contains `atom_to_list` calls?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210916/344b9dd0/attachment.htm>


More information about the erlang-questions mailing list