Skip to content

Commit

Permalink
Prevent the compiler from hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Dec 19, 2022
1 parent 48be617 commit 539d17b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/compiler/src/beam_ssa_type.erl
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,16 @@ sig_function_1(Id, StMap, State0, FuncDb) ->
WlChanged = wl_changed(Wl0, State#sig_st.wl),
#{ Id := #func_info{succ_types=SuccTypes0}=Entry0 } = FuncDb,

if
SuccTypes0 =:= SuccTypes ->
case SuccTypes of
[] ->
%% Can never succeed. (Handling this case explicitly is necessary
%% for correctness in rare circumstances to prevent osciallation.)
{false, WlChanged, State, FuncDb};
SuccTypes0 ->
%% No change from last time.
{false, WlChanged, State, FuncDb};
SuccTypes0 =/= SuccTypes ->
_ ->
%% Success types were refined. Continue iterating.
Entry = Entry0#func_info{succ_types=SuccTypes},
{true, WlChanged, State, FuncDb#{ Id := Entry }}
end.
Expand Down
10 changes: 10 additions & 0 deletions lib/compiler/test/compilation_SUITE_data/infinite_loop.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ mutually_recursive(X) ->
%% This LC will be implemented as mutually recursive functions.
%% Analyzing them would cause an infinite loop.
[0 || _ <- [], <<_>> <= X].

%% GH-6578. The type optimization pass would oscillate between no success
%% types and [any()] -> bitstring().

gh_6578(X) ->
<<
0
|| (+(is_alive())) <
[gh_6578(gh_6578(0))|| X] andalso ok
>>.

0 comments on commit 539d17b

Please sign in to comment.