erlang / otp

Erlang/OTP
http://erlang.org
Apache License 2.0
11.36k stars 2.95k forks source link

Sub pass ssa_opt_private_append #8630

Closed manuel-rubio closed 3 months ago

manuel-rubio commented 3 months ago

Describe the bug I'm trying to compile my project (https://github.com/bragful/ephp) using OTP 26.2.5.1 and looks like it's experiencing an issue, first, I compiled and found the error about +0.00 but solving that, it's failing again with this error message:

./rebar3 escriptize
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling ephp
Sub pass ssa_opt_private_append
===> Compiling src/ephp_parser.erl failed
src/ephp_parser.erl:none: internal error in pass beam_ssa_opt:
exception error: no function clause matching beam_ssa_private_append:patch_literal_term([],{hd,self},429)
  in function  beam_ssa_private_append:patch_opargs/6 (beam_ssa_private_append.erl, line 540)
  in call from beam_ssa_private_append:patch_opargs/3 (beam_ssa_private_append.erl, line 534)
  in call from beam_ssa_private_append:patch_appends_is/5 (beam_ssa_private_append.erl, line 488)
  in call from beam_ssa_private_append:patch_appends_f/5 (beam_ssa_private_append.erl, line 469)
  in call from beam_ssa_private_append:'-patch_appends/3-anonymous-2-'/3 (beam_ssa_private_append.erl, line 438)
  in call from maps:fold_1/4 (maps.erl, line 416)
  in call from beam_ssa_private_append:private_append/3 (beam_ssa_private_append.erl, line 72)

make: *** [Makefile:23: ephp] Error 1

To Reproduce Check using these commands:

wget https://raw.githubusercontent.com/bragful/ephp/master/include/ephp.hrl
wget https://raw.githubusercontent.com/bragful/ephp/master/include/ephp_parser.hrl
wget https://raw.githubusercontent.com/bragful/ephp/master/src/ephp_parser.erl
erlc ephp_parser.erl

It should drop this error:

$ erlc ephp_parser.erl
Sub pass ssa_opt_private_append
ephp_parser.erl: internal error in pass beam_ssa_opt:
exception error: no function clause matching beam_ssa_private_append:patch_literal_term([],{hd,self},429)
  in function  beam_ssa_private_append:patch_opargs/6 (beam_ssa_private_append.erl, line 540)
  in call from beam_ssa_private_append:patch_opargs/3 (beam_ssa_private_append.erl, line 534)
  in call from beam_ssa_private_append:patch_appends_is/5 (beam_ssa_private_append.erl, line 488)
  in call from beam_ssa_private_append:patch_appends_f/5 (beam_ssa_private_append.erl, line 469)
  in call from beam_ssa_private_append:'-patch_appends/3-anonymous-2-'/3 (beam_ssa_private_append.erl, line 438)
  in call from maps:fold_1/4 (maps.erl, line 416)
  in call from beam_ssa_private_append:private_append/3 (beam_ssa_private_append.erl, line 72)

Expected behavior Compile ok.

Affected versions I tested with 26.1 and 26.2.5.1, I've also tested 26.0 and it's working fine.

Additional context None.

frej commented 3 months ago

27 and master are not affected.

frej commented 3 months ago

@manuel-rubio : Are you sure about 26.0 working? For me it crashes in the same way as all the other 26.*.

manuel-rubio commented 3 months ago

@frej Yes, in my installed OTP 26 it's working, I'm using 26.0.2.

frej commented 3 months ago

@frej Yes, in my installed OTP 26 it's working, I'm using 26.0.2.

That's strange, I must be doing something wrong when building from the Git tag. I'll double check at work tomorrow. But anyway, I'm pretty sure on what causes the crash and hope to have a fix ready tomorrow. If you compile your module with erlc +no_ssa_opt_private_append ephp_parser.erl you'll bypass the compiler pass which crashes and only miss out a binary optimization that was introduced in 26.0.

frej commented 3 months ago

There is a fix in #8633, thanks for the easy to use reproducing example.

manuel-rubio commented 3 months ago

Thanks for the fix, @frej