From ecaf7de57b73f7b9f583d83abd7ada37c382e3ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 1 Oct 2024 15:32:30 +0200 Subject: [PATCH 1/7] compiler: Use zip generators --- lib/compiler/src/beam_core_to_ssa.erl | 5 ++--- lib/compiler/src/beam_ssa_bc_size.erl | 21 +++++++++++---------- lib/compiler/src/beam_ssa_pp.erl | 5 ++--- lib/compiler/src/beam_ssa_pre_codegen.erl | 9 ++++----- lib/compiler/src/beam_ssa_type.erl | 20 ++++++++------------ lib/compiler/src/v3_core.erl | 13 +++++-------- 6 files changed, 32 insertions(+), 41 deletions(-) diff --git a/lib/compiler/src/beam_core_to_ssa.erl b/lib/compiler/src/beam_core_to_ssa.erl index fd6399b73285..d6beeb7bb440 100644 --- a/lib/compiler/src/beam_core_to_ssa.erl +++ b/lib/compiler/src/beam_core_to_ssa.erl @@ -67,8 +67,7 @@ map/2,mapfoldl/3,member/2, keyfind/3,keysort/2,last/1, partition/2,reverse/1,reverse/2, - sort/1,sort/2,splitwith/2, - zip/2]). + sort/1,sort/2,splitwith/2]). -import(ordsets, [add_element/2,del_element/2,intersection/2, subtract/2,union/2,union/1]). @@ -321,7 +320,7 @@ expr(#c_let{vars=Cvs,arg=Ca,body=Cb}, Sub0, St0) -> %% Break known multiple values into separate sets. Sets = case Ka of #ivalues{args=Kas} -> - [#iset{vars=[V],arg=Val} || {V,Val} <:- zip(Kps, Kas)]; + [#iset{vars=[V],arg=Val} || V <- Kps && Val <- Kas]; _Other -> [#iset{vars=Kps,arg=Ka}] end, diff --git a/lib/compiler/src/beam_ssa_bc_size.erl b/lib/compiler/src/beam_ssa_bc_size.erl index 2045f6f46163..66bff27df674 100644 --- a/lib/compiler/src/beam_ssa_bc_size.erl +++ b/lib/compiler/src/beam_ssa_bc_size.erl @@ -140,7 +140,7 @@ call_size_func(#b_set{op=call,args=[Name|Args],dst=Dst}, Bs) -> StMap = map_get(st_map, Bs), case StMap of #{Name := #opt_st{ssa=Linear,args=Params}} -> - NewBs0 = setup_call_bs(Params, Args, Bs, #{}), + NewBs0 = setup_call_bs(Params, Args, Bs), case any(fun({writable,_}) -> true; (_) -> false end, maps:values(NewBs0)) of @@ -206,15 +206,16 @@ capture_generator_1(Dst, [_|T], Bs) -> capture_generator_1(_, [], Bs) -> Bs. -setup_call_bs([V|Vs], [A0|As], OldBs, NewBs) -> - A = case get_value(A0, OldBs) of - #b_literal{}=Lit -> {arg,Lit}; - {writable,#b_literal{val=0}}=Wr -> Wr; - {arg,_}=Arg -> Arg; - _ -> any - end, - setup_call_bs(Vs, As, OldBs, NewBs#{V => A}); -setup_call_bs([], [], #{}, NewBs) -> NewBs. +setup_call_bs(Vs, As, Bs) -> + #{V => setup_call_binding(A, Bs) || V <- Vs && A <- As}. + +setup_call_binding(A, Bs) -> + case get_value(A, Bs) of + #b_literal{}=Lit -> {arg,Lit}; + {writable,#b_literal{val=0}}=Wr -> Wr; + {arg,_}=Arg -> Arg; + _ -> any + end. calc_size([{L,#b_blk{is=Is,last=Last}}|Blks], Map0) -> case maps:take(L, Map0) of diff --git a/lib/compiler/src/beam_ssa_pp.erl b/lib/compiler/src/beam_ssa_pp.erl index 30667f39e71c..c1a9c54e20fe 100644 --- a/lib/compiler/src/beam_ssa_pp.erl +++ b/lib/compiler/src/beam_ssa_pp.erl @@ -266,9 +266,8 @@ format_instr_anno(#{arg_types:=Ts}=Anno0, FuncAnno, Args) -> Iota = lists:seq(0, length(Args) - 1), Formatted0 = [[format_arg(Arg, FuncAnno), " => ", - format_type(map_get(Idx, Ts), - Break)] - || {Idx, Arg} <:- lists:zip(Iota, Args), is_map_key(Idx, Ts)], + format_type(map_get(Idx, Ts), Break)] || + Idx <- Iota && Arg <- Args, is_map_key(Idx, Ts)], Formatted = lists:join(Break, Formatted0), [io_lib:format(" %% Argument types:~s~ts\n", diff --git a/lib/compiler/src/beam_ssa_pre_codegen.erl b/lib/compiler/src/beam_ssa_pre_codegen.erl index 6da00829dc43..94c3bac7bd6c 100644 --- a/lib/compiler/src/beam_ssa_pre_codegen.erl +++ b/lib/compiler/src/beam_ssa_pre_codegen.erl @@ -1564,11 +1564,10 @@ recv_fix_common_1([V|Vs], [Rm|Rms], Msg, Blocks0) -> recv_fix_common_1(Vs, Rms, Msg, Blocks); recv_fix_common_1([], [], _Msg, Blocks) -> Blocks. -fix_exit_phi_args([V|Vs], [Rm|Rms], Exit, Blocks) -> - Path = beam_ssa:rpo([Rm], Blocks), - Preds = exit_predecessors(Path, Exit, Blocks), - [{V,Pred} || Pred <- Preds] ++ fix_exit_phi_args(Vs, Rms, Exit, Blocks); -fix_exit_phi_args([], [], _, _) -> []. +fix_exit_phi_args(Vs, Rms, Exit, Blocks) -> + [{V,Pred} || + V <- Vs && Rm <- Rms, + Pred <- exit_predecessors(beam_ssa:rpo([Rm], Blocks), Exit, Blocks)]. exit_predecessors([L|Ls], Exit, Blocks) -> Blk = map_get(L, Blocks), diff --git a/lib/compiler/src/beam_ssa_type.erl b/lib/compiler/src/beam_ssa_type.erl index 9aaf7ef8afec..de4533f7a2d6 100644 --- a/lib/compiler/src/beam_ssa_type.erl +++ b/lib/compiler/src/beam_ssa_type.erl @@ -92,7 +92,7 @@ opt_start_1([Id | Ids], ArgDb, StMap0, FuncDb0, MetaCache) -> #{ Id := ArgTypes } -> #opt_st{ssa=Linear0,args=Args} = St0 = map_get(Id, StMap0), - Ts = maps:from_list(zip(Args, ArgTypes)), + Ts = #{Arg => Type || Arg <- Args && Type <- ArgTypes}, {Linear, FuncDb} = opt_function(Linear0, Args, Id, Ts, FuncDb0, MetaCache), St = St0#opt_st{ssa=Linear}, @@ -202,7 +202,7 @@ sig_function_1(Id, StMap, State0, FuncDb) -> #opt_st{ssa=Linear,args=Args} = map_get(Id, StMap), {ArgTypes, State1} = sig_commit_args(Id, State0), - Ts = maps:from_list(zip(Args, ArgTypes)), + Ts = #{Arg => Type || Arg <- Args && Type <- ArgTypes}, FakeCall = #b_set{op=call,args=[#b_remote{mod=#b_literal{val=unknown}, name=#b_literal{val=unknown}, @@ -427,7 +427,7 @@ opt_continue(Linear0, Args, Anno, FuncDb) when FuncDb =/= #{} -> %% This is a local function and we're guaranteed to have visited %% every call site at least once, so we know that the parameter %% types are at least as narrow as the join of all argument types. - Ts = join_arg_types(Args, ArgTypes, #{}), + Ts = join_arg_types(Args, ArgTypes), opt_function(Linear0, Args, Id, Ts, FuncDb); #{ Id := #func_info{exported=true} } -> %% We can't infer the parameter types of exported functions, but @@ -443,11 +443,9 @@ opt_continue(Linear0, Args, Anno, _FuncDb) -> {Linear, _} = opt_function(Linear0, Args, Id, Ts, #{}), {Linear, #{}}. -join_arg_types([Arg | Args], [TypeMap | TMs], Ts) -> - Type = beam_types:join(maps:values(TypeMap)), - join_arg_types(Args, TMs, Ts#{ Arg => Type }); -join_arg_types([], [], Ts) -> - Ts. +join_arg_types(Args, TypeMaps) -> + #{Arg => beam_types:join(maps:values(TypeMap)) || + Arg <- Args && TypeMap <- TypeMaps}. %% %% Optimizes a function based on the type information inferred by signatures/2 @@ -2992,10 +2990,8 @@ subtract_types([{#b_var{}=V, T0}|Vs], Ts) -> subtract_types([], Ts) -> Ts. -parallel_join([A | As], [B | Bs]) -> - [beam_types:join(A, B) | parallel_join(As, Bs)]; -parallel_join([], []) -> - []. +parallel_join(As, Bs) -> + [beam_types:join(A, B) || A <- As && B <- Bs]. gcd(A, B) -> case A rem B of diff --git a/lib/compiler/src/v3_core.erl b/lib/compiler/src/v3_core.erl index ba5d3902512a..950e82d1a1d4 100644 --- a/lib/compiler/src/v3_core.erl +++ b/lib/compiler/src/v3_core.erl @@ -1991,19 +1991,16 @@ preprocess_quals(Line, [{zip,Anno,Gens}|Qs], St, Acc) -> Zip2 = Zip1#izip{skip_pats=[case NomatchMode of skip -> NomatchPat; _ -> AccPat - end || - {NomatchMode, NomatchPat, AccPat} <:- - lists:zip3(Zip1#izip.nomatch_total, - Zip1#izip.nomatch_pats, - Zip1#izip.acc_pats)], + end || NomatchMode <- Zip1#izip.nomatch_total && + NomatchPat <- Zip1#izip.nomatch_pats && + AccPat <:-Zip1#izip.acc_pats], tail_pats=[case {NomatchMode,AccPat} of {skip,_} -> AccPat; {_,#ibinary{}} -> AccPat#ibinary{segments=[]}; {_,_} -> AccPat end || - {NomatchMode, AccPat} <:- - lists:zip(Zip1#izip.nomatch_total, - Zip1#izip.tail_pats)], + NomatchMode <- Zip1#izip.nomatch_total && + AccPat <- Zip1#izip.tail_pats], nomatch_total=get_nomatch_total(Zip1#izip.nomatch_total)}, preprocess_quals(Line, Qs, St1, [Zip2|Acc]); preprocess_quals(Line, [Q|Qs0], St0, Acc) -> From b71d244fe2ed22c6250002fd12c1d87e7e81607e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 4 Oct 2024 13:17:28 +0200 Subject: [PATCH 2/7] yecc: Use zip generators --- lib/parsetools/src/yecc.erl | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/parsetools/src/yecc.erl b/lib/parsetools/src/yecc.erl index 59267f108b5d..2c08a5954a75 100644 --- a/lib/parsetools/src/yecc.erl +++ b/lib/parsetools/src/yecc.erl @@ -2339,9 +2339,10 @@ find_identical_shift_states(StateActions) -> %% states so that they can be used from other states. Some space is %% saved. find_partial_shift_states(StateActionsL, StateReprs) -> - L = [{State, Actions} || {{State,Actions}, {State,State}} <- - lists:zip(StateActionsL, StateReprs), - shift_actions_only(Actions)], + L = [{State, Actions} || + {State,Actions} <- StateActionsL && + {State,State} <- StateReprs, + shift_actions_only(Actions)], StateActions = sofs:family(L, [{state,[action]}]), StateAction = sofs:family_to_relation(StateActions), @@ -2366,10 +2367,9 @@ find_partial_shift_states(StateActionsL, StateReprs) -> PartDataL = [#part_data{name = Nm, eq_state = EqS, actions = P, n_actions = length(P), states = ordsets:from_list(S)} || - {{Nm,P}, {Nm,S}, {Nm,EqS}} <- - lists:zip3(PartNameL, - sofs:to_external(PartInStates), - sofs:to_external(PartStates))], + {Nm,P} <- PartNameL && + {Nm,S} <- sofs:to_external(PartInStates) && + {Nm,EqS} <- sofs:to_external(PartStates)], true = length(PartDataL) =:= length(PartNameL), Ps = select_parts(PartDataL), @@ -2392,9 +2392,9 @@ find_partial_shift_states(StateActionsL, StateReprs) -> R = [{S, {Actions,jump_none}} || {S,Actions} <- sofs:to_external(NJS)] ++ - [{S, {Actions--Part, {Tag,ToS,Part}}} || - {{S,Actions}, {S,Part,{Tag,ToS}}} <- - lists:zip(sofs:to_external(JS), J)], + [{S, {Actions--Part, {Tag,ToS,Part}}} || + {S,Actions} <- sofs:to_external(JS) && + {S,Part,{Tag,ToS}} <- J], true = length(StateActionsL) =:= length(R), lists:keysort(1, R). @@ -2450,8 +2450,8 @@ collect_some_state_info(StateActions, StateReprs) -> true <- [RO], Repr =/= State], #state_info{reduce_only = RO, state_repr = Repr, comment = C} end} || - {{State, LaActions}, {State, Repr}} <- - lists:zip(StateActions, StateReprs)], + {State, LaActions} <- StateActions && + {State, Repr} <- StateReprs], list_to_tuple(L). conflict_error(Conflict, St0) -> @@ -2731,9 +2731,9 @@ output_actions(St0, StateJumps, StateInfo) -> Sel = [{S,true} || S <- ordsets:to_list(Y2CS)] ++ [{S,false} || S <- ordsets:to_list(NY2CS)], - SelS = [{State,Called} || - {{State,_JActions}, {State,Called}} <- - lists:zip(StateJumps, lists:keysort(1, Sel))], + SelS = [{State,Called} || + {State,_JActions} <- StateJumps && + {State,Called} <- lists:keysort(1, Sel)], St05 = output_nowarn(St0, yeccpars2, '', 7), St10 = foldl(fun({State, Called}, St_0) -> {State, #state_info{state_repr = IState}} = From 9fa8f96f1015fd023ef0f232f9b6d5b2d9a5d35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 6 Nov 2024 06:53:58 +0100 Subject: [PATCH 3/7] stdlib: Use zip generators While at it, use lists:enumerate/2 to eliminate a usage of lists:zip/2. --- lib/stdlib/src/beam_lib.erl | 2 +- lib/stdlib/src/qlc_pt.erl | 8 ++++---- lib/stdlib/src/rand.erl | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/stdlib/src/beam_lib.erl b/lib/stdlib/src/beam_lib.erl index 3da89a4f085e..4acae18ac76a 100644 --- a/lib/stdlib/src/beam_lib.erl +++ b/lib/stdlib/src/beam_lib.erl @@ -1278,7 +1278,7 @@ extract_literals(Chunk0) -> Literals = [binary_to_term(Term) || <> <:= Literals1], NumLiterals = length(Literals), %Sanity check. - lists:zip(lists:seq(0, NumLiterals - 1), Literals). + lists:enumerate(0, Literals). %%% Utils. diff --git a/lib/stdlib/src/qlc_pt.erl b/lib/stdlib/src/qlc_pt.erl index 29a233a9ed74..eae3655c4510 100644 --- a/lib/stdlib/src/qlc_pt.erl +++ b/lib/stdlib/src/qlc_pt.erl @@ -1796,7 +1796,7 @@ frames_to_columns(Fs, PatternVars, DerefFun, SelectorFun, Imp, CompOp) -> BF = fun(_Op, Value) -> is_bindable(Value) end, Fun = fun({_PatN, PatVar, PatSizes, Vars}, Frames) -> [unify('=:=', pat_tuple(Sz, Vars), PatVar, Frame, BF, Imp) || - {Sz, Frame} <- lists:zip(PatSizes, Frames)] + Sz <- PatSizes && Frame <- Frames] end, NFs = lists:foldl(Fun, Fs, SizesVarsL), [frames2cols(NFs, PatN, PatSizes, Vars, DerefFun, SelectorFun, CompOp) || @@ -1805,8 +1805,8 @@ frames_to_columns(Fs, PatternVars, DerefFun, SelectorFun, Imp, CompOp) -> frames2cols(Fs, PatN, PatSizes, Vars, DerefFun, SelectorFun, CompOp) -> Rs = [ begin RL = [{{PatN,Col},cons2tuple(element(2, Const))} || - {V, Col} <- lists:zip(lists:sublist(Vars, PatSz), - lists:seq(1, PatSz)), + V <- lists:sublist(Vars, PatSz) && + Col <- lists:seq(1, PatSz), %% Do not handle the case where several %% values compare equal, e.g. "X =:= 1 %% andalso X == 1.0". Looking up both @@ -1826,7 +1826,7 @@ frames2cols(Fs, PatN, PatSizes, Vars, DerefFun, SelectorFun, CompOp) -> tl(Consts = DerefFun(V, F)) =:= [], (Const = (SelectorFun(F))(hd(Consts))) =/= no], sofs:relation(RL) % possibly empty - end || {F,PatSz} <- lists:zip(Fs, PatSizes)], + end || F <- Fs && PatSz <- PatSizes], Ss = sofs:from_sets(Rs), %% D: columns occurring in every frame (path). D = sofs:intersection(sofs:projection(fun(S) -> sofs:projection(1, S) end, diff --git a/lib/stdlib/src/rand.erl b/lib/stdlib/src/rand.erl index cddc3a1fedbd..c4e4981ca2ab 100644 --- a/lib/stdlib/src/rand.erl +++ b/lib/stdlib/src/rand.erl @@ -1761,8 +1761,7 @@ exs1024_jump({L, RL}, AS, JL, J, N, TN) -> {_, NS} = exs1024_next({L, RL}), case ?MASK(1, J) of 1 -> - AS2 = lists:zipwith(fun(X, Y) -> X bxor Y end, - AS, L ++ lists:reverse(RL)), + AS2 = [X bxor Y || X <- AS && Y <- L ++ lists:reverse(RL)], exs1024_jump(NS, AS2, JL, J bsr 1, N-1, TN-1); 0 -> exs1024_jump(NS, AS, JL, J bsr 1, N-1, TN-1) From 10bd381eee37acd89f630d85fa801edd898b8606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 4 Oct 2024 14:29:48 +0200 Subject: [PATCH 4/7] asn1: Use zip generators --- lib/asn1/src/asn1ct_check.erl | 7 ++++--- lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl | 11 ++++++----- lib/asn1/src/asn1ct_constructed_per.erl | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl index 772b417c6386..dd7c4a1a3a92 100644 --- a/lib/asn1/src/asn1ct_check.erl +++ b/lib/asn1/src/asn1ct_check.erl @@ -2294,9 +2294,10 @@ use_maps(#state{options=Opts}) -> lists:member(maps, Opts). create_map_value(Components, ListOfVals) -> - Zipped = lists:zip(Components, ListOfVals), - #{Name => V || {#'ComponentType'{name=Name},V} <- Zipped, - V =/= asn1_NOVALUE}. + #{Name => V || + #'ComponentType'{name=Name} <- Components && + V <- ListOfVals, + V =/= asn1_NOVALUE}. normalize_seq_or_set(SorS, S, [{#seqtag{val=Cname},V}|Vs], diff --git a/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl b/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl index 5c7ffc3556bd..efb29f231f3f 100644 --- a/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl +++ b/lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl @@ -171,9 +171,9 @@ enc_match_input(#gen{pack=record}, ValName, CompList) -> enc_match_input(#gen{pack=map}, ValName, CompList) -> Len = length(CompList), Vars = [lists:concat(["Cindex",N]) || N <- lists:seq(1, Len)], - Zipped = lists:zip(CompList, Vars), M = [[{asis,Name},":=",Var] || - {#'ComponentType'{prop=mandatory,name=Name},Var} <- Zipped], + #'ComponentType'{prop=mandatory,name=Name} <- CompList && + Var <- Vars], case M of [] -> ok; @@ -181,7 +181,8 @@ enc_match_input(#gen{pack=map}, ValName, CompList) -> emit(["#{",lists:join(",", M),"} = ",ValName,com,nl]) end, Os0 = [{Name,Var} || - {#'ComponentType'{prop=Prop,name=Name},Var} <- Zipped, + #'ComponentType'{prop=Prop,name=Name} <- CompList && + Var <- Vars, Prop =/= mandatory], F = fun({Name,Var}) -> [Var," = case ",ValName," of\n" @@ -316,8 +317,8 @@ dec_external(#gen{pack=map}, _RecordName) -> Vars = asn1ct_name:all(term), Names = ['direct-reference','indirect-reference', 'data-value-descriptor',encoding], - Zipped = lists:zip(Names, Vars), - MapInit = lists:join(",", [["'",N,"'=>",{var,V}] || {N,V} <- Zipped]), + MapInit = lists:join(",", [["'",N,"'=>",{var,V}] || + N <- Names && V <- Vars]), emit(["OldFormat = #{",MapInit,"}",com,nl, "ASN11994Format =",nl, {call,ext,transform_to_EXTERNAL1994_maps, diff --git a/lib/asn1/src/asn1ct_constructed_per.erl b/lib/asn1/src/asn1ct_constructed_per.erl index b57277b17090..c79e7f6d4c51 100644 --- a/lib/asn1/src/asn1ct_constructed_per.erl +++ b/lib/asn1/src/asn1ct_constructed_per.erl @@ -455,8 +455,8 @@ dec_external(#gen{pack=map}, _Typename) -> Vars = asn1ct_name:all(term), Names = ['direct-reference','indirect-reference', 'data-value-descriptor',encoding], - Zipped = lists:zip(Names, Vars), - MapInit = lists:join(",", [["'",N,"'=>",{var,V}] || {N,V} <- Zipped]), + MapInit = lists:join(",", [["'",N,"'=>",{var,V}] || + N <- Names && V <- Vars]), emit(["OldFormat = #{",MapInit,"}",com,nl, "ASN11994Format =",nl, {call,ext,transform_to_EXTERNAL1994_maps, From 5daedc660b8ae21186290ae77ea0e7667ec47a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Sat, 12 Oct 2024 07:19:20 +0200 Subject: [PATCH 5/7] tools: Use zip generators --- lib/tools/src/lcnt.erl | 2 +- lib/tools/src/tprof.erl | 34 +++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/tools/src/lcnt.erl b/lib/tools/src/lcnt.erl index 3f443d0c5788..840e7621ecde 100644 --- a/lib/tools/src/lcnt.erl +++ b/lib/tools/src/lcnt.erl @@ -959,7 +959,7 @@ summate_stats([S|Ss], #stats{ tries = Tries, colls = Colls, time = Time, nt = Nt summate_histogram(Tup,undefined) when is_tuple(Tup) -> Tup; summate_histogram(undefined,Tup) when is_tuple(Tup) -> Tup; summate_histogram(Hs1,Hs2) -> - list_to_tuple([ A + B || {A,B} <- lists:zip(tuple_to_list(Hs1),tuple_to_list(Hs2))]). + list_to_tuple([A + B || A <- tuple_to_list(Hs1) && B <- tuple_to_list(Hs2)]). %% manipulators filter_locks_type(Locks, undefined) -> Locks; diff --git a/lib/tools/src/tprof.erl b/lib/tools/src/tprof.erl index 6ba8c9895fac..8e2b20cfbfce 100644 --- a/lib/tools/src/tprof.erl +++ b/lib/tools/src/tprof.erl @@ -1123,12 +1123,14 @@ format_impl(Device, {Type, Total, Inspected}) -> format_each(Device, Type, Total, Inspected). format_each(Device, call_count, _Total, Inspected) -> - {Widths, Lines} = lists:foldl( - fun ({Mod, {F, A}, Calls, _Value, _VPC, Percent}, {Widths, Ln}) -> - Line = [lists:flatten(io_lib:format("~tw:~tw/~w", [Mod, F, A])), - integer_to_list(Calls), float_to_list(Percent, [{decimals, 2}])], - NewWidths = [erlang:max(Old, New) || {Old, New} <- lists:zip([string:length(L) || L <- Line], Widths)], - {NewWidths, [Line | Ln]} + {Widths, Lines} = + lists:foldl( + fun ({Mod, {F, A}, Calls, _Value, _VPC, Percent}, {Widths, Ln}) -> + Line = [lists:flatten(io_lib:format("~tw:~tw/~w", [Mod, F, A])), + integer_to_list(Calls), float_to_list(Percent, [{decimals, 2}])], + NewWidths = [max(Old, New) || + Old <- [string:length(L) || L <- Line] && New <- Widths], + {NewWidths, [Line | Ln]} end, {[0, 5, 5], []}, Inspected), %% figure out formatting line @@ -1146,15 +1148,17 @@ format_labelled(Device, Label, Total, Inspected) -> %% The width of the value is either total or label ValueWidth = erlang:max(length(Label), length(integer_to_list(Total))), - {Widths, Lines} = lists:foldl( - fun ({Mod, {F, A}, Calls, Value, VPC, Percent}, {Widths, Ln}) -> - Line = [lists:flatten(io_lib:format("~tw:~tw/~w", [Mod, F, A])), - integer_to_list(Calls), integer_to_list(Value), - float_to_list(VPC, [{decimals, 2}]), - float_to_list(Percent, [{decimals, 2}])], - NewWidths = [erlang:max(Old, New) || {Old, New} <- lists:zip([string:length(L) || L <- Line], Widths)], - {NewWidths, [Line | Ln]} - end, {[0, 5, ValueWidth, 8, 5], []}, Inspected), + {Widths, Lines} = + lists:foldl( + fun ({Mod, {F, A}, Calls, Value, VPC, Percent}, {Widths, Ln}) -> + Line = [lists:flatten(io_lib:format("~tw:~tw/~w", [Mod, F, A])), + integer_to_list(Calls), integer_to_list(Value), + float_to_list(VPC, [{decimals, 2}]), + float_to_list(Percent, [{decimals, 2}])], + NewWidths = [max(Old, New) || + Old <- [string:length(L) || L <- Line] && New <- Widths], + {NewWidths, [Line | Ln]} + end, {[0, 5, ValueWidth, 8, 5], []}, Inspected), %% figure out formatting line Fmt = lists:flatten(io_lib:format("~~.~wts ~~~ws ~~~wts ~~~ws [~~~ws]~~n", Widths)), From adb99ea394f88b4521479f569f2b9002f846dc37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 6 Nov 2024 07:03:12 +0100 Subject: [PATCH 6/7] crypto: Use zip generators --- lib/crypto/src/crypto.erl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/crypto/src/crypto.erl b/lib/crypto/src/crypto.erl index b53e15b78a0d..385f5f9df27a 100644 --- a/lib/crypto/src/crypto.erl +++ b/lib/crypto/src/crypto.erl @@ -2804,9 +2804,8 @@ generate_key(rsa, {ModulusSize, PublicExponent}, undefined) -> [rsa,{ModulusSize,PublicExponent}]); {Private, OldPrivate} when Private == OldPrivate -> {lists:sublist(Private,2), Private}; - {_Private, _OldPrivate} -> - Where = lists:map(fun({A,B}) -> A == B end, - lists:zip(_Private, _OldPrivate)), + {Private, OldPrivate} -> + Where = [A == B || A <- Private && B <- OldPrivate], erlang:error({new_old_differ,Where}, [rsa,{ModulusSize,PublicExponent}]); Private -> From 141328946a4f026e1c6f37268a91cc99925e1597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 6 Nov 2024 07:12:31 +0100 Subject: [PATCH 7/7] runtime_tools: Use zip generators --- lib/runtime_tools/src/scheduler.erl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/runtime_tools/src/scheduler.erl b/lib/runtime_tools/src/scheduler.erl index 52905036de86..f8f62f6ebfe7 100644 --- a/lib/runtime_tools/src/scheduler.erl +++ b/lib/runtime_tools/src/scheduler.erl @@ -243,10 +243,8 @@ enabled during the entire interval between the two samples. Sample1 :: sched_sample(), Sample2 :: sched_sample(). utilization({Stats, Ts0}, {Stats, Ts1}) -> - Diffs = lists:map(fun({{Tag, I, A0, T0}, {Tag, I, A1, T1}}) -> - {Tag, I, (A1 - A0), (T1 - T0)} - end, - lists:zip(Ts0,Ts1)), + Diffs = [{Tag, I, (A1 - A0), (T1 - T0)} || + {Tag, I, A0, T0} <- Ts0 && {Tag, I, A1, T1} <- Ts1], {Lst0, {A, T, N}} = lists:foldl(fun({Tag, I, Adiff, Tdiff}, {Lst, Acc}) -> R = safe_div(Adiff, Tdiff),