[erlang-bugs] Parameterized modules aren't correct treated by HiPE

Sergey S <>
Fri Feb 13 23:20:32 CET 2009


Hello.

While playing with parameterized modules, I found that they aren't
completely supported by HiPE. It was expressed that my HiPE compiled
server involving parameterized modules crashed, when I started it.
Details are below.

I know that parameterized modules we have in R12B5 is an experimental
feature, but if it's going to be an official part of the language this
bug report may be helpful to make it more stable than it is now.

I've just written a sample to be used as a demonstration of this issue.

Here is shell session, illustrating how to reproduce it in three
steps. The same steps without involving HiPE don't lead to crash:

% --------------------------------------------------------------
Erlang (BEAM) emulator version 5.6.5 [source] [smp:2]
[async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.6.5  (abort with ^G)
1> c(srv, [native]), c(req).
{ok,req}
2> srv:start().
<0.53.0>
3> srv ! doit.

=ERROR REPORT==== 13-Feb-2009::23:08:52 ===
Error in process <0.53.0> with exit value:
{badarg,[{srv,handler,1},{srv,loop,1},{io,format,2}]}

doit
% --------------------------------------------------------------

And two modules you need to repeat above steps:

% -srv.erl-------------------------------------------------
-module(srv).
-export([start/0]).

start() ->
    spawn(fun() -> register(?MODULE, self()), loop(fun handler/1) end).

handler(Req) ->
    io:format("# ~p~n", [Req:get_time()]).

loop(Handler) ->
    receive
	doit ->
	    Handler(req:new(time())),
	    loop(Handler);
	stop ->
	    ok
    end.
% --------------------------------------------------

% -req.erl-------------------------------------------------
-module(req, [Time]).
-export([get_time/0]).

get_time() -> Time.
% --------------------------------------------------

Actually this is more or less how Mochiweb passes its request data
(socket, headers etc) to internal funcions through a callback one. It
seems that Mochiweb has been using parameterized modules to hide
request representation from an user since its first versions. So it
becomes impossible to compile such a http-handler using HiPE :(

--
Sergey



More information about the erlang-bugs mailing list