Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use zip generators #9123

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/dialyzer/src/dialyzer_contracts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ locate_invalid_elems([Contract], SuccType) ->

ProblematicArgs =
[erl_types:t_is_none(erl_types:t_inf(Cont, Succ)) andalso
(not erl_types:t_is_none(Cont))
|| {Cont, Succ} <- lists:zip(CArgs, SArgs)],
(not erl_types:t_is_none(Cont)) ||
Cont <- CArgs && Succ <- SArgs],

ProblematicRange =
erl_types:t_is_impossible(erl_types:t_inf(CRange, SRange))
Expand Down
13 changes: 6 additions & 7 deletions lib/dialyzer/src/dialyzer_dataflow.erl
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ handle_apply(Tree, Map, State) ->
NewArgs = t_inf_lists(ArgTypes, t_fun_args(OpType1)),
case any_none(NewArgs) of
true ->
EnumNewArgs = lists:zip(lists:seq(1, length(NewArgs)),
NewArgs),
EnumNewArgs = lists:enumerate(NewArgs),
ArgNs = [Arg ||
{Arg, Type} <- EnumNewArgs, t_is_none(Type)],
Msg = {fun_app_args,
Expand Down Expand Up @@ -545,7 +544,7 @@ handle_apply_or_call([{TypeOfApply, {Fun, Sig, Contr, LocalRet}}|Left],
NewAccArgTypes =
case FailedConj of
true -> AccArgTypes;
false -> [t_sup(X, Y) || {X, Y} <- lists:zip(NewArgTypes, AccArgTypes)]
false -> [t_sup(X, Y) || X <- NewArgTypes && Y <- AccArgTypes]
end,
TotalRet =
case t_is_none(LocalRet) andalso t_is_unit(RetWithoutLocal) of
Expand Down Expand Up @@ -642,8 +641,8 @@ get_apply_fail_msg(Fun, Args, ArgTypes, NewArgTypes,
dialyzer_contracts:contract_to_string(C)};
none -> {false, none}
end,
EnumArgTypes = lists:zip(lists:seq(1, length(NewArgTypes)), NewArgTypes),
ArgNs = [Arg || {Arg, Type} <- EnumArgTypes, t_is_none(Type)],
ArgNs = [Arg || Arg <- lists:seq(1, length(NewArgTypes)) &&
jhogberg marked this conversation as resolved.
Show resolved Hide resolved
Type <- NewArgTypes, t_is_none(Type)],
case state__lookup_name(Fun, State) of
{M, F, _A} ->
{call, [M, F, ArgStrings,
Expand Down Expand Up @@ -1162,7 +1161,7 @@ opaque_clauses(Clauses, ClauseTypes, #state{module=Module}=State) ->
[erl_types:t_is_opaque(Type, Module),
format_type(Type, State)]},
clause_error_warning(Msg, false, Clause)
end || {Clause, Type} <- lists:zip(Clauses, ClauseTypes),
end || Clause <- Clauses && Type <- ClauseTypes,
not erl_types:t_is_impossible(Type),
not erl_types:t_is_any(Type)]
else
Expand Down Expand Up @@ -3249,7 +3248,7 @@ forward_args(Fun, ArgTypes, #state{work = Work, fun_tab = FunTab} = State) ->
{ArgTypes, OldOut0, false};
{ok, {OldArgTypes0, OldOut0}} ->
NewArgTypes0 = [t_sup(X, Y) ||
{X, Y} <- lists:zip(ArgTypes, OldArgTypes0)],
X <- ArgTypes && Y <- OldArgTypes0],
{NewArgTypes0, OldOut0,
t_is_equal(t_product(NewArgTypes0), t_product(OldArgTypes0))}
end,
Expand Down
2 changes: 1 addition & 1 deletion lib/dialyzer/src/dialyzer_dep.erl
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ merge_outs([#output{type = single, content = S1}|Left],
merge_outs(Left, output(set__union(S1, S2)));
merge_outs([#output{type = list, content = L1}|Left],
#output{type = list, content = L2}) ->
NewList = [merge_outs([X, Y]) || {X, Y} <- lists:zip(L1, L2)],
NewList = [merge_outs([X, Y]) || X <- L1 && Y <- L2],
merge_outs(Left, output(NewList));
merge_outs([], Res) ->
Res.
Expand Down
24 changes: 8 additions & 16 deletions lib/dialyzer/src/dialyzer_iplt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -402,26 +402,18 @@ compute_new_md5_1(Entries, InitDiffs, ModuleToPathLookup) ->
ExistingHashes = [Md5 || {_Module, Md5} <- Entries],
Files = [maps:get(Module, ModuleToPathLookup) || Module <- Modules],
NewHashes = dialyzer_utils:p_map(fun compute_md5_from_file/1, Files),
Diffs =
lists:zipwith3(
fun (Module, BeforeHash, AfterHash) ->
case BeforeHash of
AfterHash ->
none;
_ ->
{differ, Module}
end
end,
Modules,
ExistingHashes,
NewHashes),
Diffs1 = InitDiffs ++ lists:filter(fun ({differ,_}) -> true; (none) -> false end, Diffs),
case Diffs1 of
Diffs = InitDiffs ++
[{differ, Module} ||
Module <- Modules &&
BeforeHash <- ExistingHashes &&
AfterHash <- NewHashes,
BeforeHash =/= AfterHash],
case Diffs of
[] ->
ok;
_ ->
ModuleHashes = lists:zip(Modules, NewHashes),
{differ, lists:keysort(1, ModuleHashes), Diffs1}
{differ, lists:sort(ModuleHashes), Diffs}
end.

-spec implementation_module_paths() -> module_file_path_lookup().
Expand Down
15 changes: 7 additions & 8 deletions lib/dialyzer/src/dialyzer_typesig.erl
Original file line number Diff line number Diff line change
Expand Up @@ -818,13 +818,13 @@ get_plt_constr(MFA, Dst, ArgVars, State) ->
end, ArgVars), GenArgs};
{value, {PltRetType, PltArgTypes}} ->
%% Need to combine the contract with the success typing.
{?mk_fun_var(
fun(Map) ->
ArgTypes = lookup_type_list(ArgVars, Map),
{?mk_fun_var(
fun(Map) ->
ArgTypes = lookup_type_list(ArgVars, Map),
CRet = get_contract_return(C, ArgTypes),
t_inf(CRet, PltRetType)
end, ArgVars),
[t_inf(X, Y) || {X, Y} <- lists:zip(GenArgs, PltArgTypes)]}
t_inf(CRet, PltRetType)
end, ArgVars),
[t_inf(X, Y) || X <- GenArgs && Y <- PltArgTypes]}
end,
state__store_conj_lists([Dst|ArgVars], sub, [RetType|ArgCs], State)
end.
Expand Down Expand Up @@ -2640,8 +2640,7 @@ state__store_funs(Vars0, Funs0, #state{fun_map = Map} = State) ->
debug_make_name_map(Vars0, Funs0),
Vars = mk_var_list(Vars0),
Funs = mk_var_list(Funs0),
NewMap = lists:foldl(fun({Var, Fun}, MP) -> maps:put(Fun, Var, MP) end,
Map, lists:zip(Vars, Funs)),
NewMap = maps:merge(Map, #{Fun => Var || Var <- Vars && Fun <- Funs}),
State#state{fun_map = NewMap}.

state__get_rec_var(Fun, #state{fun_map = Map}) ->
Expand Down
31 changes: 11 additions & 20 deletions lib/dialyzer/src/erl_types.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2227,10 +2227,8 @@ t_sup_aux(T1, T2) ->

-spec t_sup_lists([erl_type()], [erl_type()]) -> [erl_type()].

t_sup_lists([T1|Left1], [T2|Left2]) ->
[t_sup(T1, T2)|t_sup_lists(Left1, Left2)];
t_sup_lists([], []) ->
[].
t_sup_lists(Ts1, Ts2) ->
[t_sup(T1, T2) || T1 <- Ts1 && T2 <- Ts2].

%% Adds the new nominal `Sup` into the set of nominals `Ns0`. Note that it does
%% not handle structurals; the caller is expected to normalize the result
Expand Down Expand Up @@ -2715,10 +2713,8 @@ t_inf_aux(#c{}, #c{}) ->

-spec t_inf_lists([erl_type()], [erl_type()]) -> [erl_type()].

t_inf_lists([T1 | Left1], [T2 | Left2]) ->
[t_inf(T1, T2) | t_inf_lists(Left1, Left2)];
t_inf_lists([], []) ->
[].
t_inf_lists(Ts1, Ts2) ->
[t_inf(T1, T2) || T1 <- Ts1 && T2 <- Ts2].

%% Infimum of lists with strictness.
%% If any element is the ?none type, the value 'bottom' is returned.
Expand Down Expand Up @@ -3344,14 +3340,7 @@ t_subtract_aux(T1, T2) ->
-spec t_subtract_lists([erl_type()], [erl_type()]) -> [erl_type()].

t_subtract_lists(L1, L2) ->
t_subtract_lists(L1, L2, []).

-spec t_subtract_lists([erl_type()], [erl_type()], [erl_type()]) -> [erl_type()].

t_subtract_lists([T1|Left1], [T2|Left2], Acc) ->
t_subtract_lists(Left1, Left2, [t_subtract(T1, T2)|Acc]);
t_subtract_lists([], [], Acc) ->
lists:reverse(Acc).
[t_subtract(T1, T2) || T1 <- L1 && T2 <- L2].

-spec subtract_union([erl_type(),...], [erl_type(),...]) -> erl_type().

Expand Down Expand Up @@ -3398,10 +3387,12 @@ sns_cartesian_1(A, []) ->
%% should contain a single element that is not none. That element
%% will replace the element in the corresponding position in the
%% first list.
replace_nontrivial_element([T1|Left1], [?none|Left2]) ->
[T1|replace_nontrivial_element(Left1, Left2)];
replace_nontrivial_element([_|Left1], [T2|_]) ->
[T2|Left1].

replace_nontrivial_element(Left, Right) ->
[case T2 of
?none -> T1;
_ -> T2
end || T1 <- Left && T2 <- Right].

subtract_bin(?bitstr(U1, B1), ?bitstr(U1, B1)) ->
?none;
Expand Down
Loading