Skip to content

Horus compilation failure on OTP 29 when compiling a standalone function #39

Description

@krot3232

What does not work?

While converting a simple anonymous function into a standalone function using horus:to_standalone_fun, Horus crashes with horus_ex:compilation_failure.

The generated BEAM assembly appears to be valid and contains only a single exported function (run/0), but the compilation fails inside beam_a:module/2 with a function_clause exception.

Error:

(node1@server1.local)3> horus:to_standalone_fun(fun()->ok end).
** exception error: {horus_ex,compilation_failure,
                     #{error =>
                        {error,
                         [{[],
                           [{none,compile,
                             {crash,beam_a,function_clause,
                              [{beam_a,module,
                                [{'horus__erl_eval__-expr/6-fun-7-__9018232',
                                  [{run,0},{module_info,0},{module_info,1}],
                                  [],
                                  [{function,run,...},{function,...},{...}],
                                  7},
                                 [binary,from_asm,binary,warnings_as_errors,return_errors,
                                  return_warnings|...]],
                                [{file,"beam_a.erl"},{line,36}]},
                               {compile,'-select_passes/2-anonymous-0-',3,
                                [{file,"compile.erl"},{line,1636}]},
                               {compile,fold_comp,4,[{file,"compile.erl"},{line,1334}]},
                               {compile,internal_comp,5,[{file,"compile.erl"},{line,1309}]},
                               {compile,'-internal_fun/2-anonymous-0-',2,
                                [{file,[...]},{line,...}]},
                               {compile,'-do_compile/2-anonymous-0-',1,
                                [{file,...},{...}]}]}}]}],
                         []},
                       asm =>
                        {'horus__erl_eval__-expr/6-fun-7-__9018232',
                         [{run,0},{module_info,0},{module_info,1}],
                         [],
                         [{function,run,0,2,
                           [{label,1},
                            {line,[{location,[],1}]},
                            {func_info,
                             {atom,'horus__erl_eval__-expr/6-fun-7-__9018232'},
                             {atom,run},
                             0},
                            {label,2},
                            {move,{atom,ok},{x,0}},
                            return]},
                          {function,module_info,0,4,
                           [{label,3},
                            {line,[]},
                            {func_info,
                             {atom,'horus__erl_eval__-expr/6-fun-7-__9018232'},
                             {atom,module_info},
                             0},
                            {label,4},
                            {move,
                             {atom,'horus__erl_eval__-expr/6-fun-7-__9018232'},
                             {x,0}},
                            {call_ext_only,1,{extfunc,erlang,get_module_info,1}}]},
                          {function,module_info,1,6,
                           [{label,5},
                            {line,[]},
                            {func_info,
                             {atom,'horus__erl_eval__-expr/6-fun-7-__9018232'},
                             {atom,module_info},
                             1},
                            {label,6},
                            {move,{x,0},{x,1}},
                            {move,
                             {atom,'horus__erl_eval__-expr/6-fun-7-__9018232'},
                             {x,0}},
                            {call_ext_only,2,{extfunc,erlang,get_module_info,...}}]}],
                         7}}}
     in function  horus:handle_compilation_error/2 (/root/my_app/_build/default/lib/horus/src/horus.erl:807)
     in call from horus:to_standalone_fun3/2 (/root/my_app/_build/default/lib/horus/src/horus.erl:510)
     in call from horus:to_standalone_fun2/2 (/root/my_app/_build/default/lib/horus/src/horus.erl:427)
     in call from horus:to_standalone_fun/2 (/root/my_app/_build/default/lib/horus/src/horus.erl:381)

Environment
Horus: 0.4.0
Erlang/OTP: 29.0.2
Rebar3: 3.27.0+build.5573.ref97b6ffcb on Erlang/OTP 29 Erts 17.0.2
OS: Debian GNU/Linux 12

Expected behavior

horus:to_standalone_fun should successfully generate a standalone function and return a callable Horus fun.
Compilation fails with:

horus_ex:compilation_failure

caused by:

beam_a:function_clause

during the internal BEAM assembly compilation phase.

How to reproduce

horus:to_standalone_fun(fun()->ok end).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions