[erlang-questions] Abstract code in .beam files

Robert Virding rvirding@REDACTED
Wed Sep 23 17:51:45 CEST 2015

LFE compiles to Core not to Erlang AST. I have a hack for dialyzer which
allows it to get the Core erlang it uses from an LFE source file, This
works but it means that the the LFE compiler can't add the Erlang AST which
dialyzer uses to the .beam file. It is a bit hacky but it works. The
dialyzer interface code is not very cleanly written but IIRC it assumes
that one source file results in one module. I have now extended the LFE
compiler so you can compile multiple modules in one source file.
(interesting for flavors and structs)

My thought was that if I can hack the compiler so it puts the Core erlang
AST in the .beam file instead of the Erlang AST then I could extend my
dialyzer hack to even work with the .beam file. However that would mean
hacking the Erlang compiler to handle a new option which I don't really
want to do. It's a pretty easy hack but there are limits.

Anyway that was my idea. I see I will have to wait until the Erlang
compiler is fixed to do this. And dialyzer.


On 21 September 2015 at 14:46, José Valim <jose.valim@REDACTED>

> Robert, the .beam file is made of a bunch of chunks. The abstract code is
> stored in a chunk named "Abst", where it is versioned and
> term_to_binary'ed. Literally:
>     erlang:term_to_binary({raw_abstract_v1, AST})
> You can't/shouldn't store the core format here but you can create as many
> chunks as you want in the BEAM file. We actually do this in Elixir to store
> the documentation. At EUC, I talked to Björn Gustavsson about officially
> supporting a core chunk. Here is what we agreed on to the best of my memory:
> 1. We will have a new chunk named "Core" (they are all four letters)
> 2. The core AST will be versioned as well (raw_core_v1) and
> term_to_binary'ed, like this: erlang:term_to_binary({raw_core_v1, CoreAST})
> I also talked to Kostis so dialyzer starts reading the core information
> from it too.  Let me know if you go ahead with this so we can sync before I
> eventually send a PR to OTP and dialyzer.
> *José Valim*
> www.plataformatec.com.br
> Skype: jv.ptec
> Founder and Director of R&D
> On Mon, Sep 21, 2015 at 2:14 PM, Robert Virding <rvirding@REDACTED>
> wrote:
>> When you compile a file with debug_info then the Erlang AST of the file
>> is included in the .beam file. Does anyone know if the actual structure
>> which is put in the file is checked for format? Can I put anything in
>> there, for example the core code?
>> Robert
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150923/e18796d6/attachment.htm>

More information about the erlang-questions mailing list