[erlang-questions] Pmods, packages, Unicode source code and column numbers in compiler - what will happen in R16?

Richard Carlsson <>
Wed Oct 17 13:27:27 CEST 2012

On 2012-10-17 13:01 , Loïc Hoguin wrote:
>> For the record, the bad part about making a representation like this
>> public is that it takes implementation details that happened to make
>> sense for the underlying platform at the time (BEAM), and makes it
>> impossible to change them later on. In this case, such implementation
>> details are that the tuple contains exactly the module name followed by
>> the hidden parameters, in order. No additional fields can be added in
>> future versions. Also, the calling convention becomes fixed so that the
>> module tuple itself must always be passed as the last parameter.
> Now what if the tuple call support was removed and was simply replaced
> in the parse transform by code similar to the following?
> if is_tuple(Var) -> M = element(1, Var), M:fun();
>     true -> Var:fun()
> end

The above code is not equivalent with the calling convention for 
parameterised modules. You need to do something like this:

   Mod:Func(A1, ... AN)


   if is_tuple(Mod), tuple_size(Mod) > 0 ->
          (element(1, Mod))(A1, ... AN, Mod)
      true ->
          Mod:Func(A1, ... AN)

Apart from that, your point that it would still work is correct, but the 
low level implementation in BEAM also caches the last looked up module 
name, so that you don't have to do the full atom -> module mapping each 
time you get to the same call point. Our original use case was pluggable 
implementations of various things in the middle of passes in the HiPE 
compiler, so performance was definitely an issue.


More information about the erlang-questions mailing list