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

Mikael Pettersson <>
Fri Feb 20 10:24:16 CET 2009


Sergey S writes:
 > 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 :(

This has now been fixed and the fix will be included in R13B.
Below you'll find the patch fixing this for R12B-5.

/Mikael

--- otp_src_R12B-5/lib/hipe/rtl/hipe_rtl_primops.erl.~1~	2008-06-10 14:47:40.000000000 +0200
+++ otp_src_R12B-5/lib/hipe/rtl/hipe_rtl_primops.erl	2009-02-20 09:22:18.000000000 +0100
@@ -896,6 +896,19 @@ gen_enter_apply(Args=[_M,_F,_AppArgs]) -
 %%
 
 gen_apply_N(Dst, Arity, [M,F|CallArgs], Cont, Fail) ->
+  MM = hipe_rtl:mk_new_var(),
+  NotModuleLbl = hipe_rtl:mk_new_label(),
+  NotModuleLblName = hipe_rtl:label_name(NotModuleLbl),
+  Tuple = M,
+  TupleInfo = [],
+  Index = hipe_rtl:mk_imm(1),
+  IndexInfo = 1,
+  [hipe_tagscheme:element(MM, Index, Tuple, NotModuleLblName, TupleInfo, IndexInfo),
+   gen_apply_N_common(Dst, Arity+1, MM, F, CallArgs++[M], Cont, Fail),
+   NotModuleLbl,
+   gen_apply_N_common(Dst, Arity, M, F, CallArgs, Cont, Fail)].
+
+gen_apply_N_common(Dst, Arity, M, F, CallArgs, Cont, Fail) ->
   CallLabel = hipe_rtl:mk_new_label(),
   CodeAddress = hipe_rtl:mk_new_reg(),
   [hipe_rtl:mk_call([CodeAddress], find_na_or_make_stub,



More information about the erlang-bugs mailing list