Skip to content

Commit

Permalink
Suggested clean ups and simplifications
Browse files Browse the repository at this point in the history
Note that the checks before calling make_refill/4 are not necessary.
  • Loading branch information
bjorng committed Nov 5, 2024
1 parent 05edbd8 commit 4be6278
Showing 1 changed file with 47 additions and 38 deletions.
85 changes: 47 additions & 38 deletions lib/compiler/src/v3_core.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,7 @@ lc_tq1(Line, E, [#igen{anno=#a{anno=GA}=GAnno,
AccClauseNoGuards = if
AccGuard =:= [] ->
nomatch;
element(1,NomatchMode) =:= skip ->
NomatchMode =:= skip ->
nomatch;
true ->
make_clause([compiler_generated|LA],
Expand Down Expand Up @@ -1688,27 +1688,31 @@ zip_tq(Line, E, #izip{anno=#a{anno=GA}=GAnno,
%% Generate the name for the letrec.
F = #c_var{anno=LA,name={Name,NumGenerators}},

%% Generate the clauses for the letrec.
%% Generate the clauses for the letrec. First, the accumulating
%% clause.
Sc = #iapply{anno=GAnno,op=F,args=TailVars},
{Lc,Lps,St4} = lc_tq(Line, E, Qs, Sc, St3),

AccClause = make_clause(LA, AccPats, AccGuard, Lps++[Lc]),
%% If all generators are strict, no skipping is possible.
AccClauseNoGuards = case NomatchTotal of
strict -> nomatch;
_ -> make_clause([skip_clause,compiler_generated|LA],
SkipPats, [], [Sc])
end,
TailClause = make_clause(LA, TailPats, [], [Mc]),
RefillClause =
case all(fun(X) -> X =:= nomatch end, RefillPats0) of
true ->
%% There are no map generators.
[nomatch];
false ->
make_refill(RefillPats0, 0, RefillAs, {TailVars, LA, [], Sc})

%% Generate the skip clause unless all generators are strict, in
%% which case no skipping is possible.
AccClauseNoGuards =
case NomatchTotal of
strict ->
nomatch;
_ ->
make_clause([skip_clause,compiler_generated|LA],
SkipPats, [], [Sc])
end,
Cs0 = [AccClause, AccClauseNoGuards, TailClause]++RefillClause,

%% Generate the clause testing for empty generators.
TailClause = make_clause(LA, TailPats, [], [Mc]),

%% Generate refill clauses for map generators.
RefillClauses = make_refill(RefillPats0, 0, RefillAs, {TailVars, LA, [], Sc}),

%% Gather clauses.
Cs0 = [AccClause, AccClauseNoGuards, TailClause | RefillClauses],
Cs = [C || C <- Cs0, C =/= nomatch],

Fc = bad_generators(FcVars, hd(Args), lc, bad_generators),
Expand Down Expand Up @@ -1851,32 +1855,38 @@ bzip_tq1(Line, E, #izip{anno=#a{anno=_GA}=GAnno,
%% Generate the name for the letrec.
F = #c_var{anno=LA,name={Name,Arity}},

%% Generate the clauses for the letrec.
%% Generate the clauses for the letrec. First, the accumulating
%% clause.
BinAccVar = last(CallVars),
Sc = #iapply{anno=GAnno,op=F,args=TailVars++[BinAccVar]},
{Bc,Bps,St4} = bc_tq1(Line, E, Qs, BinAccVar, St3),
Body = Bps++[#iset{var=hd(CallVars), arg=Bc}, Sc],
AccClause = make_clause(LA, AccPats++[Mc], AccGuard, Body),
%% If all generators are strict, no skipping is possible.
AccClauseNoGuards = case NomatchTotal of
strict -> nomatch;
_ -> make_clause([skip_clause,compiler_generated|LA],
SkipPats++[Mc], [], [Sc])
end,
TailClause = make_clause(LA, TailPats++[Mc], [], [Mc]),
RefillClause =
case all(fun(X) -> X =:= nomatch end, RefillPats0) of
true ->
%% There are no map generators.
[nomatch];
false ->
make_refill(RefillPats0, 0, RefillAs, {TailVars, LA, [Mc], Sc})

%% Generate the skip clause unless all generators are strict, in
%% which case no skipping is possible.
AccClauseNoGuards =
case NomatchTotal of
strict ->
nomatch;
_ ->
make_clause([skip_clause,compiler_generated|LA],
SkipPats++[Mc], [], [Sc])
end,
Cs0 = [AccClause, AccClauseNoGuards, TailClause]++RefillClause,

%% Generate the clause testing for empty generators.
TailClause = make_clause(LA, TailPats++[Mc], [], [Mc]),

%% Generate refill clauses for map generators.
RefillClauses = make_refill(RefillPats0, 0, RefillAs, {TailVars, LA, [Mc], Sc}),

%% Gather clauses.
Cs0 = [AccClause, AccClauseNoGuards, TailClause | RefillClauses],
Cs = [C || C <- Cs0, C =/= nomatch],

Fc = bad_generators(FcVars, hd(Args), bc, bad_generators),
Fun = #ifun{anno=GAnno,id=[],vars=CallVars,clauses=Cs,fc=Fc},

%% Inlining would disable the size calculation optimization for
%% bs_init_writable.
{#iletrec{anno=LAnno#a{anno=[list_comprehension,no_inline|LA]},
Expand Down Expand Up @@ -2020,10 +2030,10 @@ preprocess_zip_generators([], Zip) ->
Zip.

get_nomatch_total(NomatchModes) ->
case lists:all(fun(X) -> X =:= skip end, NomatchModes) of
case all(fun(X) -> X =:= skip end, NomatchModes) of
true -> skip;
false ->
case lists:any(fun(X) -> X =:= skip end, NomatchModes) of
case any(fun(X) -> X =:= skip end, NomatchModes) of
true -> mixed;
false -> strict
end
Expand Down Expand Up @@ -2732,7 +2742,6 @@ bad_generator(Ps, Generator, Arg) ->
L = [#c_literal{val=bad_generator}, Generator],
bad_generator_common(L, Ps, Arg).


bad_generators(Ps, Arg, bc, ErrorType) ->
T1 = #c_tuple{es=droplast(Ps)},
L = [#c_literal{val=ErrorType}, T1],
Expand Down Expand Up @@ -4430,7 +4439,7 @@ is_simple(_) -> false.

-spec is_simple_list([cerl:cerl()]) -> boolean().

is_simple_list(Es) -> lists:all(fun is_simple/1, Es).
is_simple_list(Es) -> all(fun is_simple/1, Es).

insert_nif_start([VF={V,F=#c_fun{body=Body}}|Funs]) ->
case Body of
Expand Down

0 comments on commit 4be6278

Please sign in to comment.