aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dialyzer/src')
-rw-r--r--lib/dialyzer/src/dialyzer_analysis_callgraph.erl15
-rw-r--r--lib/dialyzer/src/dialyzer_behaviours.erl19
-rw-r--r--lib/dialyzer/src/dialyzer_cl.erl54
-rw-r--r--lib/dialyzer/src/dialyzer_codeserver.erl2
-rw-r--r--lib/dialyzer/src/dialyzer_contracts.erl139
-rw-r--r--lib/dialyzer/src/dialyzer_dataflow.erl146
-rw-r--r--lib/dialyzer/src/dialyzer_gui.erl17
-rw-r--r--lib/dialyzer/src/dialyzer_typesig.erl3
8 files changed, 282 insertions, 113 deletions
diff --git a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl
index 62153fa176..458f3a4c81 100644
--- a/lib/dialyzer/src/dialyzer_analysis_callgraph.erl
+++ b/lib/dialyzer/src/dialyzer_analysis_callgraph.erl
@@ -2,7 +2,7 @@
%%--------------------------------------------------------------------
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2006-2010. All Rights Reserved.
+%% Copyright Ericsson AB 2006-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -359,8 +359,17 @@ store_core(Mod, Core, NoWarn, Callgraph, CServer) ->
store_code_and_build_callgraph(Mod, LabeledCore, Callgraph, CServer3, NoWarn).
abs_get_nowarn(Abs, M) ->
- [{M, F, A}
- || {attribute, _, compile, {nowarn_unused_function, {F, A}}} <- Abs].
+ Opts = lists:flatten([C || {attribute, _, compile, C} <- Abs]),
+ Warn = erl_lint:bool_option(warn_unused_function, nowarn_unused_function,
+ true, Opts),
+ case Warn of
+ false ->
+ [{M, F, A} || {function, _, F, A, _} <- Abs]; % all functions
+ true ->
+ [{M, F, A} ||
+ {nowarn_unused_function, FAs} <- Opts,
+ {F, A} <- lists:flatten([FAs])]
+ end.
get_exported_types_from_core(Core) ->
Attrs = cerl:module_attrs(Core),
diff --git a/lib/dialyzer/src/dialyzer_behaviours.erl b/lib/dialyzer/src/dialyzer_behaviours.erl
index 56eb46d78a..e89c08df7d 100644
--- a/lib/dialyzer/src/dialyzer_behaviours.erl
+++ b/lib/dialyzer/src/dialyzer_behaviours.erl
@@ -2,7 +2,7 @@
%%-----------------------------------------------------------------------
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -144,15 +144,20 @@ check_all_callbacks(Module, Behaviour, [Cb|Rest],
'error' -> Acc1;
{ok, {{File, Line}, Contract}} ->
Acc10 = Acc1,
- SpecReturnType = dialyzer_contracts:get_contract_return(Contract),
- SpecArgTypes = dialyzer_contracts:get_contract_args(Contract),
+ SpecReturnType0 = dialyzer_contracts:get_contract_return(Contract),
+ SpecArgTypes0 = dialyzer_contracts:get_contract_args(Contract),
+ SpecReturnType = erl_types:subst_all_vars_to_any(SpecReturnType0),
+ SpecArgTypes =
+ [erl_types:subst_all_vars_to_any(ArgT0) || ArgT0 <- SpecArgTypes0],
Acc11 =
case erl_types:t_is_subtype(SpecReturnType, CbReturnType) of
true -> Acc10;
- false -> [{callback_spec_type_mismatch,
- [File, Line, Behaviour, Function, Arity,
- erl_types:t_to_string(SpecReturnType, Records),
- erl_types:t_to_string(CbReturnType, Records)]}|Acc10]
+ false ->
+ ExtraType = erl_types:t_subtract(SpecReturnType, CbReturnType),
+ [{callback_spec_type_mismatch,
+ [File, Line, Behaviour, Function, Arity,
+ erl_types:t_to_string(ExtraType, Records),
+ erl_types:t_to_string(CbReturnType, Records)]}|Acc10]
end,
Acc12 =
case erl_types:any_none(
diff --git a/lib/dialyzer/src/dialyzer_cl.erl b/lib/dialyzer/src/dialyzer_cl.erl
index e638e2fff2..04a0db890f 100644
--- a/lib/dialyzer/src/dialyzer_cl.erl
+++ b/lib/dialyzer/src/dialyzer_cl.erl
@@ -29,10 +29,6 @@
-module(dialyzer_cl).
-%% Avoid warning for local function error/1 clashing with autoimported BIF.
--compile({no_auto_import,[error/1]}).
-%% Avoid warning for local function error/2 clashing with autoimported BIF.
--compile({no_auto_import,[error/2]}).
-export([start/1]).
-include("dialyzer.hrl").
@@ -88,7 +84,7 @@ init_opts_for_build(Opts) ->
Plts ->
Msg = io_lib:format("Could not build multiple PLT files: ~s\n",
[format_plts(Plts)]),
- error(Msg)
+ cl_error(Msg)
end;
false -> Opts#options{init_plts = []}
end.
@@ -110,7 +106,7 @@ init_opts_for_add(Opts) ->
Plts ->
Msg = io_lib:format("Could not add to multiple PLT files: ~s\n",
[format_plts(Plts)]),
- error(Msg)
+ cl_error(Msg)
end;
false ->
case Opts#options.init_plts =:= [] of
@@ -134,11 +130,12 @@ check_plt_aux([_] = Plt, Opts) ->
report_check(Opts2),
plt_common(Opts2, [], []);
check_plt_aux([Plt|Plts], Opts) ->
- Opts1 = Opts#options{init_plts = [Plt]},
- Opts2 = init_opts_for_check(Opts1),
- report_check(Opts2),
- plt_common(Opts2, [], []),
- check_plt_aux(Plts, Opts).
+ case check_plt_aux([Plt], Opts) of
+ {?RET_NOTHING_SUSPICIOUS, []} -> check_plt_aux(Plts, Opts);
+ {?RET_DISCREPANCIES, Warns} ->
+ {_RET, MoreWarns} = check_plt_aux(Plts, Opts),
+ {?RET_DISCREPANCIES, Warns ++ MoreWarns}
+ end.
init_opts_for_check(Opts) ->
InitPlt =
@@ -175,7 +172,7 @@ init_opts_for_remove(Opts) ->
Plts ->
Msg = io_lib:format("Could not remove from multiple PLT files: ~s\n",
[format_plts(Plts)]),
- error(Msg)
+ cl_error(Msg)
end;
false ->
case Opts#options.init_plts =:= [] of
@@ -193,7 +190,7 @@ plt_common(#options{init_plts = [InitPlt]} = Opts, RemoveFiles, AddFiles) ->
none -> ok;
OutPlt ->
{ok, Binary} = file:read_file(InitPlt),
- file:write_file(OutPlt, Binary)
+ ok = file:write_file(OutPlt, Binary)
end,
case Opts#options.report_mode of
quiet -> ok;
@@ -221,19 +218,19 @@ plt_common(#options{init_plts = [InitPlt]} = Opts, RemoveFiles, AddFiles) ->
{error, no_such_file} ->
Msg = io_lib:format("Could not find the PLT: ~s\n~s",
[InitPlt, default_plt_error_msg()]),
- error(Msg);
+ cl_error(Msg);
{error, not_valid} ->
Msg = io_lib:format("The file: ~s is not a valid PLT file\n~s",
[InitPlt, default_plt_error_msg()]),
- error(Msg);
+ cl_error(Msg);
{error, read_error} ->
Msg = io_lib:format("Could not read the PLT: ~s\n~s",
[InitPlt, default_plt_error_msg()]),
- error(Msg);
+ cl_error(Msg);
{error, {no_file_to_remove, F}} ->
Msg = io_lib:format("Could not remove the file ~s from the PLT: ~s\n",
[F, InitPlt]),
- error(Msg)
+ cl_error(Msg)
end.
default_plt_error_msg() ->
@@ -426,7 +423,7 @@ assert_writable(PltFile) ->
true -> ok;
false ->
Msg = io_lib:format(" The PLT file ~s is not writable", [PltFile]),
- error(Msg)
+ cl_error(Msg)
end.
check_if_writable(PltFile) ->
@@ -525,10 +522,7 @@ native_compile(Mods) ->
end.
hc(Mod) ->
- case code:ensure_loaded(Mod) of
- {module, Mod} -> ok;
- {error, sticky_directory} -> ok
- end,
+ {module, Mod} = code:ensure_loaded(Mod),
case code:is_module_native(Mod) of
true -> ok;
false ->
@@ -553,7 +547,7 @@ init_output(State0, #options{output_file = OutFile,
{error, Reason} ->
Msg = io_lib:format("Could not open output file ~p, Reason: ~p\n",
[OutFile, Reason]),
- error(State, lists:flatten(Msg))
+ cl_error(State, lists:flatten(Msg))
end
end.
@@ -599,10 +593,10 @@ cl_loop(State, LogCache) ->
cl_loop(NewState, LogCache);
{'EXIT', BackendPid, {error, Reason}} ->
Msg = failed_anal_msg(Reason, LogCache),
- error(State, Msg);
+ cl_error(State, Msg);
{'EXIT', BackendPid, Reason} when Reason =/= 'normal' ->
Msg = failed_anal_msg(io_lib:format("~P", [Reason, 12]), LogCache),
- error(State, Msg);
+ cl_error(State, Msg);
_Other ->
%% io:format("Received ~p\n", [_Other]),
cl_loop(State, LogCache)
@@ -611,7 +605,7 @@ cl_loop(State, LogCache) ->
-spec failed_anal_msg(string(), [_]) -> nonempty_string().
failed_anal_msg(Reason, LogCache) ->
- Msg = "Analysis failed with error: " ++ Reason ++ "\n",
+ Msg = "Analysis failed with error:\n" ++ Reason ++ "\n",
case LogCache =:= [] of
true -> Msg;
false ->
@@ -635,14 +629,14 @@ store_warnings(#cl_state{stored_warnings = StoredWarnings} = St, Warnings) ->
store_unknown_behaviours(#cl_state{unknown_behaviours = Behs} = St, Beh) ->
St#cl_state{unknown_behaviours = Beh ++ Behs}.
--spec error(string()) -> no_return().
+-spec cl_error(string()) -> no_return().
-error(Msg) ->
+cl_error(Msg) ->
throw({dialyzer_error, Msg}).
--spec error(#cl_state{}, string()) -> no_return().
+-spec cl_error(#cl_state{}, string()) -> no_return().
-error(State, Msg) ->
+cl_error(State, Msg) ->
case State#cl_state.output of
standard_io -> ok;
Outfile -> io:format(Outfile, "\n~s\n", [Msg])
diff --git a/lib/dialyzer/src/dialyzer_codeserver.erl b/lib/dialyzer/src/dialyzer_codeserver.erl
index c34a9f0b7d..13ca65e4dd 100644
--- a/lib/dialyzer/src/dialyzer_codeserver.erl
+++ b/lib/dialyzer/src/dialyzer_codeserver.erl
@@ -2,7 +2,7 @@
%%-----------------------------------------------------------------------
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2006-2010. All Rights Reserved.
+%% Copyright Ericsson AB 2006-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
diff --git a/lib/dialyzer/src/dialyzer_contracts.erl b/lib/dialyzer/src/dialyzer_contracts.erl
index 3469d70a4d..2b78b736ab 100644
--- a/lib/dialyzer/src/dialyzer_contracts.erl
+++ b/lib/dialyzer/src/dialyzer_contracts.erl
@@ -2,7 +2,7 @@
%%-----------------------------------------------------------------------
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2007-2010. All Rights Reserved.
+%% Copyright Ericsson AB 2007-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -256,7 +256,7 @@ check_extraneous([C|Cs], SuccType) ->
check_extraneous_1(Contract, SuccType) ->
CRngs = erl_types:t_elements(erl_types:t_fun_range(Contract)),
STRng = erl_types:t_fun_range(SuccType),
- %% io:format("CR = ~p\nSR = ~p\n", [CRngs, STRng]),
+ ?debug("CR = ~p\nSR = ~p\n", [CRngs, STRng]),
case [CR || CR <- CRngs, erl_types:t_is_none(erl_types:t_inf(CR, STRng, opaque))] of
[] -> ok;
CRs -> {error, {extra_range, erl_types:t_sup(CRs), STRng}}
@@ -352,28 +352,37 @@ insert_constraints([], Dict) -> Dict.
store_tmp_contract(MFA, FileLine, TypeSpec, SpecDict, RecordsDict) ->
%% io:format("contract from form: ~p\n", [TypeSpec]),
- TmpContract = contract_from_form(TypeSpec, RecordsDict),
+ TmpContract = contract_from_form(TypeSpec, RecordsDict, FileLine),
%% io:format("contract: ~p\n", [Contract]),
dict:store(MFA, {FileLine, TmpContract}, SpecDict).
-contract_from_form(Forms, RecDict) ->
- {CFuns, Forms1} = contract_from_form(Forms, RecDict, [], []),
+contract_from_form(Forms, RecDict, FileLine) ->
+ {CFuns, Forms1} = contract_from_form(Forms, RecDict, FileLine, [], []),
#tmp_contract{contract_funs = CFuns, forms = Forms1}.
contract_from_form([{type, _, 'fun', [_, _]} = Form | Left], RecDict,
- TypeAcc, FormAcc) ->
+ FileLine, TypeAcc, FormAcc) ->
TypeFun =
fun(ExpTypes, AllRecords) ->
- Type = erl_types:t_from_form(Form, RecDict),
+ Type =
+ try
+ erl_types:t_from_form(Form, RecDict)
+ catch
+ throw:{error, Msg} ->
+ {File, Line} = FileLine,
+ NewMsg = io_lib:format("~s:~p: ~s", [filename:basename(File),
+ Line, Msg]),
+ throw({error, NewMsg})
+ end,
NewType = erl_types:t_solve_remote(Type, ExpTypes, AllRecords),
{NewType, []}
end,
NewTypeAcc = [TypeFun | TypeAcc],
NewFormAcc = [{Form, []} | FormAcc],
- contract_from_form(Left, RecDict, NewTypeAcc, NewFormAcc);
+ contract_from_form(Left, RecDict, FileLine, NewTypeAcc, NewFormAcc);
contract_from_form([{type, _L1, bounded_fun,
[{type, _L2, 'fun', [_, _]} = Form, Constr]}| Left],
- RecDict, TypeAcc, FormAcc) ->
+ RecDict, FileLine, TypeAcc, FormAcc) ->
TypeFun =
fun(ExpTypes, AllRecords) ->
Constr1 = [constraint_from_form(C, RecDict, ExpTypes, AllRecords)
@@ -385,8 +394,8 @@ contract_from_form([{type, _L1, bounded_fun,
end,
NewTypeAcc = [TypeFun | TypeAcc],
NewFormAcc = [{Form, Constr} | FormAcc],
- contract_from_form(Left, RecDict, NewTypeAcc, NewFormAcc);
-contract_from_form([], _RecDict, TypeAcc, FormAcc) ->
+ contract_from_form(Left, RecDict, FileLine, NewTypeAcc, NewFormAcc);
+contract_from_form([], _RecDict, _FileLine, TypeAcc, FormAcc) ->
{lists:reverse(TypeAcc), lists:reverse(FormAcc)}.
constraint_from_form({type, _, constraint, [{atom, _, is_subtype},
@@ -444,7 +453,21 @@ get_invalid_contract_warnings_funs([{MFA, {FileLine, Contract}}|Left],
{error, invalid_contract} ->
[invalid_contract_warning(MFA, FileLine, Sig, RecDict)|Acc];
{error, {extra_range, ExtraRanges, STRange}} ->
- [extra_range_warning(MFA, FileLine, ExtraRanges, STRange)|Acc];
+ Warn =
+ case t_from_forms_without_remote(Contract#contract.forms,
+ RecDict) of
+ {ok, NoRemoteType} ->
+ CRet = erl_types:t_fun_range(NoRemoteType),
+ erl_types:t_is_subtype(ExtraRanges, CRet);
+ unsupported ->
+ true
+ end,
+ case Warn of
+ true ->
+ [extra_range_warning(MFA, FileLine, ExtraRanges, STRange)|Acc];
+ false ->
+ Acc
+ end;
{error, Msg} ->
[{?WARN_CONTRACT_SYNTAX, FileLine, Msg}|Acc];
ok ->
@@ -507,26 +530,92 @@ picky_contract_check(CSig0, Sig0, MFA, FileLine, Contract, RecDict, Acc) ->
extra_contract_warning({M, F, A}, FileLine, Contract, CSig, Sig, RecDict) ->
SigString = lists:flatten(dialyzer_utils:format_sig(Sig, RecDict)),
ContractString0 = lists:flatten(dialyzer_utils:format_sig(CSig, RecDict)),
- case SigString =:= ContractString0 of
+ %% The only difference is in record fields containing 'undefined' or not.
+ IsUndefRecordFieldsRelated = SigString =:= ContractString0,
+ {IsRemoteTypesRelated, SubtypeRelation} =
+ is_remote_types_related(Contract, CSig, Sig, RecDict),
+ case IsUndefRecordFieldsRelated orelse IsRemoteTypesRelated of
true ->
- %% The only difference is in record fields containing 'undefined' or not.
no_warning;
false ->
ContractString = contract_to_string(Contract),
{Tag, Msg} =
- case erl_types:t_is_subtype(CSig, Sig) of
- true ->
+ case SubtypeRelation of
+ contract_is_subtype ->
{?WARN_CONTRACT_SUBTYPE,
{contract_subtype, [M, F, A, ContractString, SigString]}};
- false ->
- case erl_types:t_is_subtype(Sig, CSig) of
- true ->
- {?WARN_CONTRACT_SUPERTYPE,
- {contract_supertype, [M, F, A, ContractString, SigString]}};
- false ->
- {?WARN_CONTRACT_NOT_EQUAL,
- {contract_diff, [M, F, A, ContractString, SigString]}}
- end
+ contract_is_supertype ->
+ {?WARN_CONTRACT_SUPERTYPE,
+ {contract_supertype, [M, F, A, ContractString, SigString]}};
+ neither ->
+ {?WARN_CONTRACT_NOT_EQUAL,
+ {contract_diff, [M, F, A, ContractString, SigString]}}
end,
{warning, {Tag, FileLine, Msg}}
end.
+
+is_remote_types_related(Contract, CSig, Sig, RecDict) ->
+ case erl_types:t_is_subtype(CSig, Sig) of
+ true ->
+ {false, contract_is_subtype};
+ false ->
+ case erl_types:t_is_subtype(Sig, CSig) of
+ true ->
+ case t_from_forms_without_remote(Contract#contract.forms, RecDict) of
+ {ok, NoRemoteTypeSig} ->
+ case blame_remote(CSig, NoRemoteTypeSig, Sig) of
+ true ->
+ {true, neither};
+ false ->
+ {false, contract_is_supertype}
+ end;
+ unsupported ->
+ {false, contract_is_supertype}
+ end;
+ false ->
+ {false, neither}
+ end
+ end.
+
+t_from_forms_without_remote([{FType, []}], RecDict) ->
+ Type0 = erl_types:t_from_form(FType, RecDict),
+ Map =
+ fun(Type) ->
+ case erl_types:t_is_remote(Type) of
+ true -> erl_types:t_none();
+ false -> Type
+ end
+ end,
+ {ok, erl_types:t_map(Map, Type0)};
+t_from_forms_without_remote([{_FType, _Constrs}], _RecDict) ->
+ %% 'When' constraints
+ unsupported;
+t_from_forms_without_remote(_Forms, _RecDict) ->
+ %% Lots of forms
+ unsupported.
+
+blame_remote(ContractSig, NoRemoteContractSig, Sig) ->
+ CArgs = erl_types:t_fun_args(ContractSig),
+ CRange = erl_types:t_fun_range(ContractSig),
+ NRArgs = erl_types:t_fun_args(NoRemoteContractSig),
+ NRRange = erl_types:t_fun_range(NoRemoteContractSig),
+ SArgs = erl_types:t_fun_args(Sig),
+ SRange = erl_types:t_fun_range(Sig),
+ blame_remote_list([CRange|CArgs], [NRRange|NRArgs], [SRange|SArgs]).
+
+blame_remote_list([], [], []) ->
+ true;
+blame_remote_list([CArg|CArgs], [NRArg|NRArgs], [SArg|SArgs]) ->
+ case erl_types:t_is_equal(CArg, NRArg) of
+ true ->
+ case not erl_types:t_is_equal(CArg, SArg) of
+ true -> false;
+ false -> blame_remote_list(CArgs, NRArgs, SArgs)
+ end;
+ false ->
+ case erl_types:t_is_subtype(SArg, NRArg)
+ andalso not erl_types:t_is_subtype(NRArg, SArg) of
+ true -> false;
+ false -> blame_remote_list(CArgs, NRArgs, SArgs)
+ end
+ end.
diff --git a/lib/dialyzer/src/dialyzer_dataflow.erl b/lib/dialyzer/src/dialyzer_dataflow.erl
index d74c04385b..6008dba080 100644
--- a/lib/dialyzer/src/dialyzer_dataflow.erl
+++ b/lib/dialyzer/src/dialyzer_dataflow.erl
@@ -101,6 +101,12 @@
behaviour_api_dict = [] ::
dialyzer_behaviours:behaviour_api_dict()}).
+-record(map, {dict = dict:new() :: dict(),
+ subst = dict:new() :: dict(),
+ modified = [] :: [Key :: term()],
+ modified_stack = [] :: [{[Key :: term()],reference()}],
+ ref = undefined :: reference() | undefined}).
+
%% Exported Types
-opaque state() :: #state{}.
@@ -1058,12 +1064,13 @@ handle_case(Tree, Map, #state{callgraph = Callgraph} = State) ->
RaceListSize + 1, State1);
false -> State1
end,
+ Map2 = join_maps_begin(Map1),
{MapList, State3, Type} =
handle_clauses(Clauses, Arg, ArgType, ArgType, State2,
- [], Map1, [], []),
- Map2 = join_maps(MapList, Map1),
+ [], Map2, [], []),
+ Map3 = join_maps_end(MapList, Map2),
debug_pp_map(Map2),
- {State3, Map2, Type}
+ {State3, Map3, Type}
end.
%%----------------------------------------
@@ -1640,14 +1647,15 @@ bind_pat_vars([Pat|PatLeft], [Type|TypeLeft], Acc, Map, State, Rev) ->
false ->
SubTuples = t_tuple_subtypes(Tuple),
%% Need to call the top function to get the try-catch wrapper
+ MapJ = join_maps_begin(Map),
Results =
case Rev of
true ->
[bind_pat_vars_reverse(Es, t_tuple_args(SubTuple), [],
- Map, State)
+ MapJ, State)
|| SubTuple <- SubTuples];
false ->
- [bind_pat_vars(Es, t_tuple_args(SubTuple), [], Map, State)
+ [bind_pat_vars(Es, t_tuple_args(SubTuple), [], MapJ, State)
|| SubTuple <- SubTuples]
end,
case lists:keyfind(opaque, 2, Results) of
@@ -1661,7 +1669,7 @@ bind_pat_vars([Pat|PatLeft], [Type|TypeLeft], Acc, Map, State, Rev) ->
false -> bind_error([Pat], Tuple, t_none(), bind)
end;
Maps ->
- Map1 = join_maps(Maps, Map),
+ Map1 = join_maps_end(Maps, MapJ),
TupleType = t_sup([t_tuple(EsTypes)
|| {M, EsTypes} <- Results, M =/= error]),
{Map1, TupleType}
@@ -2308,27 +2316,29 @@ handle_guard_and(Guard, Map, Env, Eval, State) ->
end
end;
neg ->
+ MapJ = join_maps_begin(Map),
{Map1, Type1} =
- try bind_guard(Arg1, Map, Env, neg, State)
- catch throw:{fail, _} -> bind_guard(Arg2, Map, Env, pos, State)
+ try bind_guard(Arg1, MapJ, Env, neg, State)
+ catch throw:{fail, _} -> bind_guard(Arg2, MapJ, Env, pos, State)
end,
{Map2, Type2} =
- try bind_guard(Arg2, Map, Env, neg, State)
- catch throw:{fail, _} -> bind_guard(Arg1, Map, Env, pos, State)
+ try bind_guard(Arg2, MapJ, Env, neg, State)
+ catch throw:{fail, _} -> bind_guard(Arg1, MapJ, Env, pos, State)
end,
case t_is_atom(false, Type1) orelse t_is_atom(false, Type2) of
- true -> {join_maps([Map1, Map2], Map), t_atom(false)};
+ true -> {join_maps_end([Map1, Map2], MapJ), t_atom(false)};
false -> signal_guard_fail(Eval, Guard, [Type1, Type2], State)
end;
dont_know ->
- {Map1, Type1} = bind_guard(Arg1, Map, Env, dont_know, State),
- {Map2, Type2} = bind_guard(Arg2, Map, Env, dont_know, State),
+ MapJ = join_maps_begin(Map),
+ {Map1, Type1} = bind_guard(Arg1, MapJ, Env, dont_know, State),
+ {Map2, Type2} = bind_guard(Arg2, MapJ, Env, dont_know, State),
Bool1 = t_inf(Type1, t_boolean()),
Bool2 = t_inf(Type2, t_boolean()),
case t_is_none(Bool1) orelse t_is_none(Bool2) of
true -> throw({fatal_fail, none});
false ->
- NewMap = join_maps([Map1, Map2], Map),
+ NewMap = join_maps_end([Map1, Map2], MapJ),
NewType =
case {t_atom_vals(Bool1), t_atom_vals(Bool2)} of
{['true'] , ['true'] } -> t_atom(true);
@@ -2344,20 +2354,21 @@ handle_guard_or(Guard, Map, Env, Eval, State) ->
[Arg1, Arg2] = cerl:call_args(Guard),
case Eval of
pos ->
+ MapJ = join_maps_begin(Map),
{Map1, Bool1} =
- try bind_guard(Arg1, Map, Env, pos, State)
+ try bind_guard(Arg1, MapJ, Env, pos, State)
catch
- throw:{fail,_} -> bind_guard(Arg1, Map, Env, dont_know, State)
+ throw:{fail,_} -> bind_guard(Arg1, MapJ, Env, dont_know, State)
end,
{Map2, Bool2} =
- try bind_guard(Arg2, Map, Env, pos, State)
+ try bind_guard(Arg2, MapJ, Env, pos, State)
catch
- throw:{fail,_} -> bind_guard(Arg2, Map, Env, dont_know, State)
+ throw:{fail,_} -> bind_guard(Arg2, MapJ, Env, dont_know, State)
end,
case ((t_is_atom(true, Bool1) andalso t_is_boolean(Bool2))
orelse
(t_is_atom(true, Bool2) andalso t_is_boolean(Bool1))) of
- true -> {join_maps([Map1, Map2], Map), t_atom(true)};
+ true -> {join_maps_end([Map1, Map2], MapJ), t_atom(true)};
false -> signal_guard_fail(Eval, Guard, [Bool1, Bool2], State)
end;
neg ->
@@ -2372,14 +2383,15 @@ handle_guard_or(Guard, Map, Env, Eval, State) ->
end
end;
dont_know ->
- {Map1, Type1} = bind_guard(Arg1, Map, Env, dont_know, State),
- {Map2, Type2} = bind_guard(Arg2, Map, Env, dont_know, State),
+ MapJ = join_maps_begin(Map),
+ {Map1, Type1} = bind_guard(Arg1, MapJ, Env, dont_know, State),
+ {Map2, Type2} = bind_guard(Arg2, MapJ, Env, dont_know, State),
Bool1 = t_inf(Type1, t_boolean()),
Bool2 = t_inf(Type2, t_boolean()),
case t_is_none(Bool1) orelse t_is_none(Bool2) of
true -> throw({fatal_fail, none});
false ->
- NewMap = join_maps([Map1, Map2], Map),
+ NewMap = join_maps_end([Map1, Map2], MapJ),
NewType =
case {t_atom_vals(Bool1), t_atom_vals(Bool2)} of
{['false'], ['false']} -> t_atom(false);
@@ -2493,8 +2505,9 @@ mk_guard_msg(Eval, F, Args, ArgTypes, State) ->
end
end.
-bind_guard_case_clauses(Arg, Clauses, Map, Env, Eval, State) ->
+bind_guard_case_clauses(Arg, Clauses, Map0, Env, Eval, State) ->
Clauses1 = filter_fail_clauses(Clauses),
+ Map = join_maps_begin(Map0),
{GenMap, GenArgType} = bind_guard(Arg, Map, Env, dont_know, State),
bind_guard_case_clauses(GenArgType, GenMap, Arg, Clauses1, Map, Env, Eval,
t_none(), [], State).
@@ -2594,7 +2607,7 @@ bind_guard_case_clauses(_GenArgType, _GenMap, _ArgExpr, [], Map, _Env, _Eval,
AccType, AccMaps, _State) ->
case t_is_none(AccType) of
true -> throw({fail, none});
- false -> {join_maps(AccMaps, Map), AccType}
+ false -> {join_maps_end(AccMaps, Map), AccType}
end.
%%% ===========================================================================
@@ -2604,11 +2617,34 @@ bind_guard_case_clauses(_GenArgType, _GenMap, _ArgExpr, [], Map, _Env, _Eval,
%%% ===========================================================================
map__new() ->
- {dict:new(), dict:new()}.
+ #map{}.
+
+%% join_maps_begin pushes 'modified' to the stack; join_maps pops
+%% 'modified' from the stack.
+
+join_maps_begin(#map{modified = M, modified_stack = S, ref = Ref} = Map) ->
+ Map#map{ref = make_ref(), modified = [], modified_stack = [{M,Ref} | S]}.
+
+join_maps_end(Maps, MapOut) ->
+ #map{ref = Ref, modified_stack = [{M1,R1} | S]} = MapOut,
+ true = lists:all(fun(M) -> M#map.ref =:= Ref end, Maps), % sanity
+ Keys0 = lists:usort(lists:append([M#map.modified || M <- Maps])),
+ #map{dict = Dict, subst = Subst} = MapOut,
+ Keys = [Key ||
+ Key <- Keys0,
+ dict:is_key(Key, Dict) orelse dict:is_key(Key, Subst)],
+ Out = case Maps of
+ [] -> join_maps(Maps, MapOut);
+ _ -> join_maps(Keys, Maps, MapOut)
+ end,
+ debug_join_check(Maps, MapOut, Out),
+ Out#map{ref = R1,
+ modified = Out#map.modified ++ M1, % duplicates possible
+ modified_stack = S}.
join_maps(Maps, MapOut) ->
- {Map, Subst} = MapOut,
- Keys = ordsets:from_list(dict:fetch_keys(Map) ++ dict:fetch_keys(Subst)),
+ #map{dict = Dict, subst = Subst} = MapOut,
+ Keys = ordsets:from_list(dict:fetch_keys(Dict) ++ dict:fetch_keys(Subst)),
join_maps(Keys, Maps, MapOut).
join_maps([Key|Left], Maps, MapOut) ->
@@ -2631,6 +2667,17 @@ join_maps_one_key([Map|Left], Key, AccType) ->
join_maps_one_key([], _Key, AccType) ->
AccType.
+-ifdef(DEBUG).
+debug_join_check(Maps, MapOut, Out) ->
+ #map{dict = Dict, subst = Subst} = Out,
+ #map{dict = Dict2, subst = Subst2} = join_maps(Maps, MapOut),
+ F = fun(D) -> lists:keysort(1, dict:to_list(D)) end,
+ [throw({bug, join_maps}) ||
+ F(Dict) =/= F(Dict2) orelse F(Subst) =/= F(Subst2)].
+-else.
+debug_join_check(_Maps, _MapOut, _Out) -> ok.
+-endif.
+
enter_type_lists([Key|KeyTail], [Val|ValTail], Map) ->
Map1 = enter_type(Key, Val, Map),
enter_type_lists(KeyTail, ValTail, Map1);
@@ -2643,20 +2690,21 @@ enter_type_list([{Key, Val}|Left], Map) ->
enter_type_list([], Map) ->
Map.
-enter_type(Key, Val, {Map, Subst} = MS) ->
+enter_type(Key, Val, MS) ->
case cerl:is_literal(Key) of
true -> MS;
false ->
case cerl:is_c_values(Key) of
true ->
- Keys = cerl:values_es(Key),
+ Keys = cerl:values_es(Key),
case t_is_any(Val) orelse t_is_none(Val) of
true ->
enter_type_lists(Keys, [Val || _ <- Keys], MS);
false ->
- enter_type_lists(cerl:values_es(Key), t_to_tlist(Val), MS)
+ enter_type_lists(Keys, t_to_tlist(Val), MS)
end;
false ->
+ #map{dict = Dict, subst = Subst} = MS,
KeyLabel = get_label(Key),
case dict:find(KeyLabel, Subst) of
{ok, NewKey} ->
@@ -2664,21 +2712,25 @@ enter_type(Key, Val, {Map, Subst} = MS) ->
enter_type(NewKey, Val, MS);
error ->
?debug("Entering ~p :: ~s\n", [KeyLabel, t_to_string(Val)]),
- case dict:find(KeyLabel, Map) of
+ case dict:find(KeyLabel, Dict) of
{ok, Val} -> MS;
- {ok, _OldVal} -> {dict:store(KeyLabel, Val, Map), Subst};
- error -> {dict:store(KeyLabel, Val, Map), Subst}
+ {ok, _OldVal} -> store_map(KeyLabel, Val, MS);
+ error -> store_map(KeyLabel, Val, MS)
end
end
end
end.
-enter_subst(Key, Val, {Map, Subst} = MS) ->
+store_map(Key, Val, #map{dict = Dict, ref = undefined} = Map) ->
+ Map#map{dict = dict:store(Key, Val, Dict)};
+store_map(Key, Val, #map{dict = Dict, modified = Mod} = Map) ->
+ Map#map{dict = dict:store(Key, Val, Dict), modified = [Key | Mod]}.
+
+enter_subst(Key, Val, #map{subst = Subst} = MS) ->
KeyLabel = get_label(Key),
case cerl:is_literal(Val) of
true ->
- NewMap = dict:store(KeyLabel, literal_type(Val), Map),
- {NewMap, Subst};
+ store_map(KeyLabel, literal_type(Val), MS);
false ->
case cerl:is_c_var(Val) of
false -> MS;
@@ -2691,25 +2743,29 @@ enter_subst(Key, Val, {Map, Subst} = MS) ->
if KeyLabel =:= ValLabel -> MS;
true ->
?debug("Subst: storing ~p = ~p\n", [KeyLabel, ValLabel]),
- NewSubst = dict:store(KeyLabel, ValLabel, Subst),
- {Map, NewSubst}
+ store_subst(KeyLabel, ValLabel, MS)
end
end
end
end.
-lookup_type(Key, {Map, Subst}) ->
- lookup(Key, Map, Subst, t_none()).
+store_subst(Key, Val, #map{subst = S, ref = undefined} = Map) ->
+ Map#map{subst = dict:store(Key, Val, S)};
+store_subst(Key, Val, #map{subst = S, modified = Mod} = Map) ->
+ Map#map{subst = dict:store(Key, Val, S), modified = [Key | Mod]}.
+
+lookup_type(Key, #map{dict = Dict, subst = Subst}) ->
+ lookup(Key, Dict, Subst, t_none()).
-lookup(Key, Map, Subst, AnyNone) ->
+lookup(Key, Dict, Subst, AnyNone) ->
case cerl:is_literal(Key) of
true -> literal_type(Key);
false ->
Label = get_label(Key),
case dict:find(Label, Subst) of
- {ok, NewKey} -> lookup(NewKey, Map, Subst, AnyNone);
+ {ok, NewKey} -> lookup(NewKey, Dict, Subst, AnyNone);
error ->
- case dict:find(Label, Map) of
+ case dict:find(Label, Dict) of
{ok, Val} -> Val;
error -> AnyNone
end
@@ -2744,8 +2800,8 @@ mark_as_fresh([], Map) ->
Map.
-ifdef(DEBUG).
-debug_pp_map(Map = {Map0, _Subst}) ->
- Keys = dict:fetch_keys(Map0),
+debug_pp_map(#map{dict = Dict}=Map) ->
+ Keys = dict:fetch_keys(Dict),
io:format("Map:\n", []),
lists:foreach(fun (Key) ->
io:format("\t~w :: ~s\n",
diff --git a/lib/dialyzer/src/dialyzer_gui.erl b/lib/dialyzer/src/dialyzer_gui.erl
index ccd80a4835..f60194e01f 100644
--- a/lib/dialyzer/src/dialyzer_gui.erl
+++ b/lib/dialyzer/src/dialyzer_gui.erl
@@ -28,6 +28,23 @@
%%%-----------------------------------------------------------------------
-module(dialyzer_gui).
+-compile([{nowarn_deprecated_function,{gs,button,2}},
+ {nowarn_deprecated_function,{gs,config,2}},
+ {nowarn_deprecated_function,{gs,destroy,1}},
+ {nowarn_deprecated_function,{gs,editor,2}},
+ {nowarn_deprecated_function,{gs,entry,2}},
+ {nowarn_deprecated_function,{gs,frame,2}},
+ {nowarn_deprecated_function,{gs,label,2}},
+ {nowarn_deprecated_function,{gs,listbox,2}},
+ {nowarn_deprecated_function,{gs,menu,2}},
+ {nowarn_deprecated_function,{gs,menubar,2}},
+ {nowarn_deprecated_function,{gs,menubutton,2}},
+ {nowarn_deprecated_function,{gs,menuitem,2}},
+ {nowarn_deprecated_function,{gs,radiobutton,2}},
+ {nowarn_deprecated_function,{gs,read,2}},
+ {nowarn_deprecated_function,{gs,start,0}},
+ {nowarn_deprecated_function,{gs,stop,0}},
+ {nowarn_deprecated_function,{gs,window,2}}]).
-export([start/1]).
diff --git a/lib/dialyzer/src/dialyzer_typesig.erl b/lib/dialyzer/src/dialyzer_typesig.erl
index 92868b6878..4268814859 100644
--- a/lib/dialyzer/src/dialyzer_typesig.erl
+++ b/lib/dialyzer/src/dialyzer_typesig.erl
@@ -2046,8 +2046,7 @@ lookup_type(Key, Map) ->
%% case cerl:is_literal(Key) of
%% true -> t_from_term(cerl:concrete(Key));
%% false ->
- Subst = t_subst(Key, Map),
- t_sup(Subst, Subst).
+ t_subst(Key, Map).
%% end.
mk_var(Var) ->