diff options
author | Björn Gustavsson <[email protected]> | 2012-01-10 08:31:15 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2012-01-24 16:18:08 +0100 |
commit | 64ccd8c9b7a782ca777ca4649dbb1f4a1ef00bce (patch) | |
tree | a2a78c9027718de0f9976b1a174785a21b8fe06b /lib/stdlib/test/ets_SUITE.erl | |
parent | e71de38e077199d7d36cf5e3e6017cdd12dff1ba (diff) | |
download | otp-64ccd8c9b7a782ca777ca4649dbb1f4a1ef00bce.tar.gz otp-64ccd8c9b7a782ca777ca4649dbb1f4a1ef00bce.tar.bz2 otp-64ccd8c9b7a782ca777ca4649dbb1f4a1ef00bce.zip |
beam_load.c: Allow stubs for BIFs
We want to be able to write type specifications for BIFs in the same
way as for any other function. Currently, the type for BIFs need
to be described in erl_bif_types.
To avoid extending the compiler and Dialyzer with special directives
for providing specifications for BIFs, we have decided to let the
loader accept a local definition for a function which exists as a
BIF. As an example, here is how a stub for lists:reverse/2 can be
defined:
-export([reverse/2]).
-spec reverse([term()], term()) -> [term()].
reverse(_, _) ->
erlang:nif_error(undef).
Essentially, the loader will discard the local definition of reverse/2.
Other functions in the same module must *not* do local calls to a BIF
stub. If a local call to a BIF is found, the loader will refuse to load
the module. That is, the following call is not allowed:
reverse(List) ->
reverse(List, []).
but the following is:
reverse(List) ->
?MODULE:reverse(List, []).
A few words about the implementation.
It turns out to be too complicated to actually discard the BIF
stubs. Although it would be possibly with some jiggery pokery in
ops.tab, the code would be difficult to maintain and it could slow
down loading of modules that don't define BIFs (which are almost
all modules).
Therefore, the stub functions are kept in the loaded code, but
their names in the func_info instruction are invalidated so that
module_info(functions) can filter them out.
Diffstat (limited to 'lib/stdlib/test/ets_SUITE.erl')
0 files changed, 0 insertions, 0 deletions