[erlang-patches] Promote compiler option 'inline_list_funcs'
Anthony Ramine
n.oxyde@REDACTED
Sat Nov 3 19:02:56 CET 2012
The compiler option inline_list_funcs has been present in Erlang/OTP
since at least release R9B0. It enables the inlining of the most used
list manipulation functions of the stdlib's lists module.
This couple of commits fix some wrong warnings triggered by the option
if the result of the inlined function is not actually used and mention
it in the documentation.
https://github.com/nox/otp/compare/promote-inline_list_funcs
https://github.com/nox/otp/compare/promote-inline_list_funcs.patch
Regards,
The following changes since commit d5733bc3e34449affde2594d85b905c8ab440d42:
Merge branch 'egil/ensure-erl_crash.dump/OTP-10422' into maint
(2012-10-24 14:20:26 +0200)
are available in the git repository at:
https://github.com/nox/otp promote-inline_list_funcs
for you to fetch changes up to 6ac8429cbe1072af6d615f668523237a2d040ed0:
Document compiler option 'inline_list_funcs' (2012-11-03 18:55:07 +0100)
----------------------------------------------------------------
Anthony Ramine (2):
Silence some wrong warnings triggered by inline_list_funcs
Document compiler option 'inline_list_funcs'
lib/compiler/doc/src/compile.xml | 26 ++++++++++++++++++++++++++
lib/compiler/src/sys_core_fold.erl | 20 ++++++++++++++------
2 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/lib/compiler/doc/src/compile.xml b/lib/compiler/doc/src/compile.xml
index 27d750f..e9375d6 100644
--- a/lib/compiler/doc/src/compile.xml
+++ b/lib/compiler/doc/src/compile.xml
@@ -816,6 +816,32 @@ pi() -> 3.1416.
</section>
<section>
+ <title>Inlining of list functions</title>
+ <p>The compiler can also inline a variety of list manipulation functions
+ from the stdlib's lists module.</p>
+
+ <p>This feature must be explicitely enabled with a compiler option or a
+ <c>-compile()</c> attribute in the source module.</p>
+
+ <p>To enable inlining of list functions, use the <c>inline_list_funcs</c>
+ option.</p>
+
+ <p>The following functions are inlined:</p>
+ <list type="bulleted">
+ <item><seealso marker="stdlib:lists#all/1">lists:all/1</seealso></item>
+ <item><seealso marker="stdlib:lists#any/1">lists:any/1</seealso></item>
+ <item><seealso
marker="stdlib:lists#foreach/2">lists:foreach/2</seealso></item>
+ <item><seealso marker="stdlib:lists#map/2">lists:map/2</seealso></item>
+ <item><seealso
marker="stdlib:lists#flatmap/2">lists:flatmap/2</seealso></item>
+ <item><seealso
marker="stdlib:lists#filter/1">lists:filter/2</seealso></item>
+ <item><seealso
marker="stdlib:lists#foldl/3">lists:foldl/3</seealso></item>
+ <item><seealso
marker="stdlib:lists#foldr/3">lists:foldr/3</seealso></item>
+ <item><seealso
marker="stdlib:lists#mapfoldl/3">lists:mapfoldl/3</seealso></item>
+ <item><seealso
marker="stdlib:lists#mapfoldr/3">lists:mapfoldr/3</seealso></item>
+ </list>
+ </section>
+
+ <section>
<title>Parse Transformations</title>
<p>Parse transformations are used when a programmer wants to use
diff --git a/lib/compiler/src/sys_core_fold.erl
b/lib/compiler/src/sys_core_fold.erl
index 18fba79..17397be 100644
--- a/lib/compiler/src/sys_core_fold.erl
+++ b/lib/compiler/src/sys_core_fold.erl
@@ -756,6 +756,7 @@ call_1(#c_call{anno=Anno}, lists, map, [Arg1,Arg2], Sub) ->
op=F,
args=[X]},
body=#c_cons{hd=H,
+ anno=[compiler_generated],
tl=#c_apply{anno=Anno,
op=Loop,
args=[Xs]}}}},
@@ -780,7 +781,7 @@ call_1(#c_call{anno=Anno}, lists, flatmap,
[Arg1,Arg2], Sub) ->
C1 = #c_clause{pats=[#c_cons{hd=X, tl=Xs}], guard=#c_literal{val=true},
body=#c_let{vars=[H],
arg=#c_apply{anno=Anno, op=F, args=[X]},
- body=#c_call{anno=Anno,
+ body=#c_call{anno=[compiler_generated|Anno],
module=#c_literal{val=erlang},
name=#c_literal{val='++'},
args=[H,
@@ -807,7 +808,7 @@ call_1(#c_call{anno=Anno}, lists, filter,
[Arg1,Arg2], Sub) ->
B = #c_var{name='B'},
Err1 = #c_tuple{es=[#c_literal{val='case_clause'}, X]},
CC1 = #c_clause{pats=[#c_literal{val=true}], guard=#c_literal{val=true},
- body=#c_cons{hd=X, tl=Xs}},
+ body=#c_cons{anno=[compiler_generated], hd=X, tl=Xs}},
CC2 = #c_clause{pats=[#c_literal{val=false}], guard=#c_literal{val=true},
body=Xs},
CC3 = #c_clause{pats=[X], guard=#c_literal{val=true},
@@ -901,7 +902,10 @@ call_1(#c_call{anno=Anno}, lists, mapfoldl,
[Arg1,Arg2,Arg3], Sub) ->
op=Loop,
args=[Xs, Avar]},
#c_tuple{es=[Xs, Avar]},
- #c_tuple{es=[#c_cons{hd=X, tl=Xs}, Avar]})
+ #c_tuple{anno=[compiler_generated],
+ es=[#c_cons{anno=[compiler_generated],
+ hd=X, tl=Xs},
+ Avar]})
%%% Multiple-value version
%%% #c_let{vars=[Xs,A],
%%% %% The tuple here will be optimised
@@ -912,7 +916,8 @@ call_1(#c_call{anno=Anno}, lists, mapfoldl,
[Arg1,Arg2,Arg3], Sub) ->
)},
C2 = #c_clause{pats=[#c_literal{val=[]}], guard=#c_literal{val=true},
%%% Tuple passing version
- body=#c_tuple{es=[#c_literal{val=[]}, Avar]}},
+ body=#c_tuple{anno=[compiler_generated],
+ es=[#c_literal{val=[]}, Avar]}},
%%% Multiple-value version
%%% body=#c_values{es=[#c_literal{val=[]}, A]}},
Err = #c_tuple{es=[#c_literal{val='function_clause'}, Xs]},
@@ -955,7 +960,9 @@ call_1(#c_call{anno=Anno}, lists, mapfoldr,
[Arg1,Arg2,Arg3], Sub) ->
#c_tuple{es=[Xs, Avar]},
Match(#c_apply{anno=Anno, op=F, args=[X, Avar]},
#c_tuple{es=[X, Avar]},
- #c_tuple{es=[#c_cons{hd=X, tl=Xs}, Avar]}))
+ #c_tuple{anno=[compiler_generated],
+ es=[#c_cons{anno=[compiler_generated],
+ hd=X, tl=Xs}, Avar]}))
%%% Multiple-value version
%%% body=#c_let{vars=[Xs,A],
%%% %% The tuple will be optimised away
@@ -967,7 +974,8 @@ call_1(#c_call{anno=Anno}, lists, mapfoldr,
[Arg1,Arg2,Arg3], Sub) ->
},
C2 = #c_clause{pats=[#c_literal{val=[]}], guard=#c_literal{val=true},
%%% Tuple passing version
- body=#c_tuple{es=[#c_literal{val=[]}, Avar]}},
+ body=#c_tuple{anno=[compiler_generated],
+ es=[#c_literal{val=[]}, Avar]}},
%%% Multiple-value version
%%% body=#c_values{es=[#c_literal{val=[]}, A]}},
Err = #c_tuple{es=[#c_literal{val='function_clause'}, Xs]},
--
Anthony Ramine
More information about the erlang-patches
mailing list