[erlang-questions] Accessing 'spec' information at runtime

Eric Merritt ericbmerritt@REDACTED
Tue Mar 8 17:00:29 CET 2011


I think that is an extraordinarily good idea Kenneth. Having that
information be a first class chunk would be useful.

How do record type specs appear. I suspect they are part of the
abstract code for the record.

On Tue, Mar 8, 2011 at 9:48 AM, Kenneth Lundin <kenneth.lundin@REDACTED> wrote:
> The -spec and -type is included in the abstract_code chunk in the beam
> files. If
> they are compiled to contain debug_info (erlc +debug_info my_module.erl).
>
> The appear as attributes and the can be abstracted like this (only the
> -spec(s) in this example):
>
> %% Beam is a string contaning the path to a beam file i.e
> "/home/user/mymodule.beam"
> %% you can for example call it like this from the shell:
> %% m:getspecs(code:which(lists)).
>
> getspecs(Beam)->
>        {ok,{_,[{abstract_code,{_,AC}}]}} =
> beam_lib:chunks(Beam,[abstract_code]),
>    Specs = [Spec|| Spec = {attribute,_,'spec',{FA,_}} <- AC],
>    io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(Specs))]).
>
> Hmm, just thinking. Maybe it would be a good idea to have the -spec
> info available as a separate
> chunk who is always present even without debug_info.
> The -spec info could for example be used for a smarter tab-completion
> of functions in the shell.
> Including argument names and types.
>
> /Kenneth, Erlang/OTP Ericsson
>
> On Tue, Mar 8, 2011 at 3:41 PM, Eric Merritt <ericbmerritt@REDACTED> wrote:
>> Hello All,
>>
>>
>>  I have been doing some digging and it I haven't found anything that
>> indicates that spec information survives compilation. It may in the
>> beam files, but there isn't any documentation to support that
>> assumption in beam_lib. So before I go digging in the source I thought
>> I would ping the list and see if anyone has any ideas on accessing
>> 'speced' type information at run time.
>>
>> Thanks,
>> Eric
>>
>> ________________________________________________________________
>> erlang-questions (at) erlang.org mailing list.
>> See http://www.erlang.org/faq.html
>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>>
>>
>


More information about the erlang-questions mailing list