[erlang-patches] [erlang-bugs] Compiler crash with 'inline_list_funcs' and "fun Fun/Arity" notation
Anthony Ramine
n.oxyde@REDACTED
Wed Jun 26 14:52:23 CEST 2013
Will amend.
--
Anthony Ramine
Le 26 juin 2013 à 14:43, Björn Gustavsson a écrit :
> Thanks! Looks good. I have only two slight comments:
>
> If find the first sentence in the commit message confusing:
>
> "Local fun references look like plain old variables in the Core Erlang
> AST and should not be treated as such."
>
> I would suggest "but" instead of "and":
>
> "Local fun references look like plain old variables in the Core Erlang
> AST, but should not be treated as such."
>
> The test cases tests that the compiler does not crash and that
> the code can be loaded, but it does not test that the code actually
> works. I suggest that you rewrite it to something like this:
>
> ?MODULE() ->
> F = fun bar/1,
> G = lists:last([(fun (X) when F =:= X -> X end)]),
> F = G(F),
> ok.
>
> bar(X) ->
> X.
>
> /Bjorn
>
>
>
> On Sat, May 18, 2013 at 6:22 PM, Anthony Ramine <n.oxyde@REDACTED> wrote:
> Hello,
>
> This patch fixes the bug by forbidding inlining of variables which values are local fun references outside of application contexts.
>
> git fetch https://github.com/nox/otp.git fix-fname-inlining
>
> https://github.com/nox/otp/compare/erlang:maint...fix-fname-inlining
> https://github.com/nox/otp/compare/erlang:maint...fix-fname-inlining.patch
>
> Regards,
>
> --
> Anthony Ramine
>
> Le 17 mai 2013 à 20:06, Anthony Ramine a écrit :
>
> > Hello,
> >
> > Shorter test case, showing the problem comes from the inline itself and not inline_list_funcs:
> >
> > -module(test).
> > -compile(inline).
> > -export([foo/0]).
> >
> > foo() ->
> > F = fun bar/1,
> > fun (X) when X =:= F -> X end.
> >
> > bar(X) -> X.
> >
> > If you run the core_lint pass, you can see where the problem comes from:
> >
> > $ erlc +clint test.erl
> > test: illegal guard expression in foo/0
> >
> > The inliner inlines `when 'erlang':'=:='(X, F)` to `'erlang':'=:='(X, 'bar'/1)` but local fun references can't appear in guards.
> >
> > I'll try to make a patch.
> >
> > Regards,
> >
> > --
> > Anthony Ramine
> >
> > Le 17 mai 2013 à 10:55, Masatake Daimon a écrit :
> >
> >> Hello,
> >>
> >> Compiling the following module makes the compiler crash. I'm using
> >> R16B.
> >>
> >> ===== test.erl =====
> >> -module(test).
> >> -compile(inline).
> >> -compile(inline_list_funcs).
> >> -export([foo/0]).
> >>
> >> foo() ->
> >> lists:map(fun bar/1, [1]).
> >>
> >> bar(X) -> X.
> >>
> >> ===== the crash ====
> >> % erlc test.erl
> >> test: function '-foo/0-lists^map/1-0-'/1+15:
> >> Internal consistency check failed - please report this bug.
> >> Instruction: {move,{x,0},{yy,0}}
> >> Error: {invalid_store,{yy,0},term}:
> >>
> >>
> >> Note that the problem disappears with any of these changes:
> >>
> >> * Commenting out "-compile(inline)."
> >> * Commenting out "-compile(inline_list_funcs)."
> >> * Changing the definition of foo/0 to:
> >> foo() ->
> >> lists:map(fun bar/1, []). % [] instead of [1]
> >> * Changing the definition of foo/0 to:
> >> foo() ->
> >> lists:map(fun (A) -> bar(A) end, [1]).
> >>
> >> Regards,
> >> --
> >> 大門 正岳 <daimon@REDACTED>
> >> _______________________________________________
> >> erlang-bugs mailing list
> >> erlang-bugs@REDACTED
> >> http://erlang.org/mailman/listinfo/erlang-bugs
> >
>
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs
>
>
>
> --
> Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-patches
mailing list