RE: compiler optimisation of constant expressions
Сергей Прохоров <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAMZozm40G7m1+tNAWAGE4E8L6e++R-TMFbYBzidHUh1Nco41sQ@mail.gmail.com> |
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?