From f928756b2b7f26b90d962cc038d4ba68619c1bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 13 Feb 2012 09:45:22 +0100 Subject: compiler: Teach the inliner to preserve on_load functions The inliner was ignorant of on_load functions and would discard them (unless they were exported or referenced). Noticed-by: Yiannis Tsiouris --- lib/compiler/src/cerl_inline.erl | 24 +++++++++++++++++++++- lib/compiler/test/compilation_SUITE.erl | 1 + .../test/compilation_SUITE_data/on_load_inline.erl | 23 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 lib/compiler/test/compilation_SUITE_data/on_load_inline.erl diff --git a/lib/compiler/src/cerl_inline.erl b/lib/compiler/src/cerl_inline.erl index c15103999f..589685d72d 100644 --- a/lib/compiler/src/cerl_inline.erl +++ b/lib/compiler/src/cerl_inline.erl @@ -1262,8 +1262,9 @@ i_receive_1(E, Cs, T, B, S) -> i_module(E, Ctxt, Ren, Env, S) -> %% Cf. `i_letrec'. Note that we pass a dummy constant value for the %% "body" parameter. + Exps = i_module_exports(E), {Es, _, Xs1, S1} = i_letrec(module_defs(E), void(), - module_exports(E), Ctxt, Ren, Env, S), + Exps, Ctxt, Ren, Env, S), %% Sanity check: case Es of [] -> @@ -1276,6 +1277,27 @@ i_module(E, Ctxt, Ren, Env, S) -> E1 = update_c_module(E, module_name(E), Xs1, module_attrs(E), Es), {E1, count_size(weight(module), S1)}. +i_module_exports(E) -> + %% If a function is named in an `on_load' attribute, we will + %% pretend that it is exported to ensure that it will not be removed. + Exps = module_exports(E), + Attrs = module_attrs(E), + case i_module_on_load(Attrs) of + none -> + Exps; + [{_,_}=FA] -> + ordsets:add_element(c_var(FA), Exps) + end. + +i_module_on_load([{Key,Val}|T]) -> + case concrete(Key) of + on_load -> + concrete(Val); + _ -> + i_module_on_load(T) + end; +i_module_on_load([]) -> none. + %% Binary-syntax expressions are too complicated to do anything %% interesting with here - that is beyond the scope of this program; %% also, their construction could have side effects, so even in effect diff --git a/lib/compiler/test/compilation_SUITE.erl b/lib/compiler/test/compilation_SUITE.erl index 664582a3a8..408fd5ed53 100644 --- a/lib/compiler/test/compilation_SUITE.erl +++ b/lib/compiler/test/compilation_SUITE.erl @@ -159,6 +159,7 @@ split({int, N}, <>) -> ?comp(convopts). ?comp(otp_7202). ?comp(on_load). +?comp(on_load_inline). beam_compiler_7(doc) -> "Code snippet submitted from Ulf Wiger which fails in R3 Beam."; diff --git a/lib/compiler/test/compilation_SUITE_data/on_load_inline.erl b/lib/compiler/test/compilation_SUITE_data/on_load_inline.erl new file mode 100644 index 0000000000..322843b61e --- /dev/null +++ b/lib/compiler/test/compilation_SUITE_data/on_load_inline.erl @@ -0,0 +1,23 @@ +-module(on_load_inline). +-export([?MODULE/0]). +-on_load(on_load/0). +-compile(inline). + +?MODULE() -> + [{pid,Pid}] = ets:lookup(on_load_executed, pid), + exit(Pid, kill), + ok. + +on_load() -> + Parent = self(), + spawn(fun() -> + T = ets:new(on_load_executed, [named_table]), + ets:insert(T, {pid,self()}), + Parent ! done, + receive + wait_forever -> ok + end + end), + receive + done -> ok + end. -- cgit v1.2.3 From 6c2e966d4fccf7ec60795a3293492862f76aba5c Mon Sep 17 00:00:00 2001 From: Gustav Simonsson Date: Mon, 13 Feb 2012 10:39:05 +0100 Subject: Fix to integer and sequence definitions Enable re-use of integer definitions in subsequent definitions and added clauses to check greatest common range for sequence definitions --- lib/asn1/src/asn1ct_check.erl | 3 +++ lib/asn1/src/asn1ct_gen_per.erl | 4 ++++ lib/asn1/src/asn1ct_gen_per_rt2ct.erl | 4 ++++ lib/asn1/test/asn1_SUITE.erl.src | 25 +++++++++++++++++++++++-- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl index e318477234..105fc02819 100644 --- a/lib/asn1/src/asn1ct_check.erl +++ b/lib/asn1/src/asn1ct_check.erl @@ -5253,6 +5253,9 @@ check_int(S,[{'NamedNumber',Id,Num}|T],Acc) when is_integer(Num) -> check_int(S,[{'NamedNumber',Id,{identifier,_,Name}}|T],Acc) -> Val = dbget_ex(S,S#state.mname,Name), check_int(S,[{'NamedNumber',Id,Val#valuedef.value}|T],Acc); +check_int(S,[{'NamedNumber',Id,{'Externalvaluereference',_,Mod,Name}}|T],Acc) -> + Val = dbget_ex(S,Mod,Name), + check_int(S,[{'NamedNumber',Id,Val#valuedef.value}|T],Acc); check_int(_S,[],Acc) -> lists:keysort(2,Acc). diff --git a/lib/asn1/src/asn1ct_gen_per.erl b/lib/asn1/src/asn1ct_gen_per.erl index b90a0adf81..8fd7a69a19 100644 --- a/lib/asn1/src/asn1ct_gen_per.erl +++ b/lib/asn1/src/asn1ct_gen_per.erl @@ -358,6 +358,10 @@ greatest_common_range2({_,Int},VR={_Lb,_Ub}) when is_integer(Int) -> greatest_common_range2({_,L},{Lb,Ub}) when is_list(L) -> Min = least_Lb([Lb|L]), Max = greatest_Ub([Ub|L]), + [{'ValueRange',{Min,Max}}]; +greatest_common_range2({Lb1,Ub1},{Lb2,Ub2}) -> + Min = least_Lb([Lb1,Lb2]), + Max = greatest_Ub([Ub1,Ub2]), [{'ValueRange',{Min,Max}}]. mk_vr([{Type,I}]) when is_atom(Type), is_integer(I) -> diff --git a/lib/asn1/src/asn1ct_gen_per_rt2ct.erl b/lib/asn1/src/asn1ct_gen_per_rt2ct.erl index 1a0a0e211d..fb9613c18d 100644 --- a/lib/asn1/src/asn1ct_gen_per_rt2ct.erl +++ b/lib/asn1/src/asn1ct_gen_per_rt2ct.erl @@ -704,6 +704,10 @@ greatest_common_range([{_,Int}],VR=[{_,{_Lb,_Ub}}]) when is_integer(Int) -> greatest_common_range([{_,L}],[{_,{Lb,Ub}}]) when is_list(L) -> Min = least_Lb([Lb|L]), Max = greatest_Ub([Ub|L]), + [{'ValueRange',{Min,Max}}]; +greatest_common_range([{_,{Lb1,Ub1}}],[{_,{Lb2,Ub2}}]) -> + Min = least_Lb([Lb1,Lb2]), + Max = greatest_Ub([Ub1,Ub2]), [{'ValueRange',{Min,Max}}]. diff --git a/lib/asn1/test/asn1_SUITE.erl.src b/lib/asn1/test/asn1_SUITE.erl.src index 124ee2d2bb..dd24feeda9 100644 --- a/lib/asn1/test/asn1_SUITE.erl.src +++ b/lib/asn1/test/asn1_SUITE.erl.src @@ -96,7 +96,8 @@ all() -> [{group,compile},parse,default_per,default_ber,default_per_opt,per, testSSLspecs, testNortel,test_undecoded_rest, test_inline, testTcapsystem, testNBAPsystem, test_compile_options,testDoubleEllipses, test_modified_x420, - testX420, test_x691,ticket_6143, testExtensionAdditionGroup + testX420, test_x691,ticket_6143, testExtensionAdditionGroup, + test_OTP_9688 ] ++ common() ++ particular(). groups() -> @@ -2369,4 +2370,24 @@ test_modules() -> "LDAP" ]. - +test_OTP_9688(_Config) -> + Asn1Mod = "OTP-9688.asn1", + Files = [Asn1Mod, "OTP-9688.asn1db", "OTP-9688.beam", "OTP-9688.erl", "OTP-9688.hrl"], + Data = + " +OTP-9688 DEFINITIONS ::= BEGIN + + foo INTEGER ::= 1 + bar INTEGER ::= 42 + + Baz ::= INTEGER {x-y-z1(foo), x-y-z2(bar)} + Qux ::= SEQUENCE {flerpInfo SEQUENCE {x INTEGER (-10 | -9 | (0..4))} OPTIONAL} + +END +", + file:write_file(Asn1Mod, Data), + %% Does it compile with changes to asn1ct_check and asn1ct_gen_per_rt2ct? + %% (see ticket) + ok = asn1ct:compile(Asn1Mod), + [file:delete(File) || File <- Files], + ok. \ No newline at end of file -- cgit v1.2.3 From da3d4c3bc803a8697c2e35c95d05417ac39ad497 Mon Sep 17 00:00:00 2001 From: Gustav Simonsson Date: Tue, 14 Feb 2012 17:47:27 +0100 Subject: Change test to use CT Config PrivDir --- lib/asn1/test/asn1_SUITE.erl.src | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/asn1/test/asn1_SUITE.erl.src b/lib/asn1/test/asn1_SUITE.erl.src index dd24feeda9..3f51b125ec 100644 --- a/lib/asn1/test/asn1_SUITE.erl.src +++ b/lib/asn1/test/asn1_SUITE.erl.src @@ -2370,11 +2370,11 @@ test_modules() -> "LDAP" ]. -test_OTP_9688(_Config) -> +test_OTP_9688(Config) -> Asn1Mod = "OTP-9688.asn1", - Files = [Asn1Mod, "OTP-9688.asn1db", "OTP-9688.beam", "OTP-9688.erl", "OTP-9688.hrl"], - Data = - " + %%DataDir = ?config(data_dir,Config), + PrivDir = ?config(priv_dir,Config), + Data = " OTP-9688 DEFINITIONS ::= BEGIN foo INTEGER ::= 1 @@ -2385,9 +2385,8 @@ OTP-9688 DEFINITIONS ::= BEGIN END ", - file:write_file(Asn1Mod, Data), + File = filename:join(PrivDir,Asn1Mod), + ok = file:write_file(File, Data), %% Does it compile with changes to asn1ct_check and asn1ct_gen_per_rt2ct? %% (see ticket) - ok = asn1ct:compile(Asn1Mod), - [file:delete(File) || File <- Files], - ok. \ No newline at end of file + ok = asn1ct:compile(File, [{outdir, PrivDir}]). -- cgit v1.2.3 From 102c34e414f573081a93ca49162dd78cf91949b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 16 Feb 2012 15:22:19 +0100 Subject: Update primary bootstrap --- bootstrap/lib/compiler/ebin/cerl_inline.beam | Bin 37300 -> 37572 bytes bootstrap/lib/stdlib/ebin/gen_fsm.beam | Bin 14940 -> 14940 bytes bootstrap/lib/stdlib/ebin/gen_server.beam | Bin 16904 -> 16904 bytes bootstrap/lib/stdlib/ebin/otp_internal.beam | Bin 7052 -> 7160 bytes 4 files changed, 0 insertions(+), 0 deletions(-) diff --git a/bootstrap/lib/compiler/ebin/cerl_inline.beam b/bootstrap/lib/compiler/ebin/cerl_inline.beam index b640e22ce6..eed98ecd2c 100644 Binary files a/bootstrap/lib/compiler/ebin/cerl_inline.beam and b/bootstrap/lib/compiler/ebin/cerl_inline.beam differ diff --git a/bootstrap/lib/stdlib/ebin/gen_fsm.beam b/bootstrap/lib/stdlib/ebin/gen_fsm.beam index f763cab747..99410275e2 100644 Binary files a/bootstrap/lib/stdlib/ebin/gen_fsm.beam and b/bootstrap/lib/stdlib/ebin/gen_fsm.beam differ diff --git a/bootstrap/lib/stdlib/ebin/gen_server.beam b/bootstrap/lib/stdlib/ebin/gen_server.beam index fe4e109508..7698131678 100644 Binary files a/bootstrap/lib/stdlib/ebin/gen_server.beam and b/bootstrap/lib/stdlib/ebin/gen_server.beam differ diff --git a/bootstrap/lib/stdlib/ebin/otp_internal.beam b/bootstrap/lib/stdlib/ebin/otp_internal.beam index 636a7a24d5..1a9a55dc24 100644 Binary files a/bootstrap/lib/stdlib/ebin/otp_internal.beam and b/bootstrap/lib/stdlib/ebin/otp_internal.beam differ -- cgit v1.2.3