I have found that if an atom occurs in a literal that can be fully known to the compiler (e.g., a map), then the atom does not appear in the atoms
section of the beam file.
Example:
-module(test).
-export[test/0].
test() ->
Example = #{
foo => bar
},
erlang:display(Example).
Snippet of generated byte code:
{function, test, 0, 2}.
{label,1}.
{line,[{location,"test.erl",5}]}.
{func_info,{atom,test},{atom,test},0}.
{label,2}.
{move,{literal,#{foo => bar}},{x,0}}.
{line,[{location,"test.erl",9}]}.
{call_ext_only,1,{extfunc,erlang,display,1}}.
Erlang shell:
1> c(test).
{ok,test}
2> {ok, Bin} = file:read_file("test.beam").
{ok,<<70,79,82,49,0,0,2,56,66,69,65,77,65,116,85,56,0,0,
0,52,0,0,0,5,4,116,101,...>>}
3> beam_lib:chunks(Bin, [atoms]).
{ok,{test,[{atoms,[{1,test},
{2,erlang},
{3,display},
{4,module_info},
{5,get_module_info}]}]}}
4> test:test().
#{foo=>bar}
true
Feature or bug?
(I am trying to use the atoms section of a BEAM file to find recursive dependencies from a root node, using the occurrences of atoms to widen the potential list of dependent BEAM files, as a dependent module may occur as an atom, so I would call it an oversight, at least for my purposes.)