29
29
-include("hipe_icode_type.hrl").
30
30
-include("../flow/cfg.hrl").
32
-type(args_fun() :: fun((mfa(), cfg()) -> [erl_type()])).
33
-type(call_fun() :: fun((mfa(), [_]) -> erl_type())).
34
-type(final_fun() :: fun((mfa(), [_]) -> 'ok')).
35
-type(data() :: {mfa(), args_fun(), call_fun(), final_fun()}).
32
-type args_fun() :: fun((mfa(), cfg()) -> [erl_type()]).
33
-type call_fun() :: fun((mfa(), [_]) -> erl_type()).
34
-type final_fun() :: fun((mfa(), [_]) -> 'ok').
35
-type data() :: {mfa(), args_fun(), call_fun(), final_fun()}.
37
37
%-define(DO_HIPE_ICODE_TYPE_TEST, false).
97
97
%% The main exported function
98
98
%%-----------------------------------------------------------------------
100
-spec(cfg/4 :: (cfg(), mfa(), comp_options(), #comp_servers{}) -> cfg()).
100
-spec cfg(cfg(), mfa(), comp_options(), #comp_servers{}) -> cfg().
102
102
cfg(Cfg, MFA, Options, Servers) ->
103
103
case proplists:get_bool(concurrent_comp, Options) of
150
150
FinalFun = fun(_,_) -> ok end,
151
151
{MFA,ArgsFun,CallFun,FinalFun}.
153
%debug_make_data(Cfg, {_M,_F,A}=MFA) ->
155
% case hipe_icode_cfg:is_closure(Cfg) of
156
% true -> hipe_icode_cfg:closure_arity(Cfg);
159
% Args = lists:duplicate(NoArgs,t_any()),
160
% ArgsFun = fun(MFA,_Cfg) -> io:format("Start:~p~n",[MFA]),Args end,
161
% CallFun = fun(MFA,Types) -> io:format("Call With:~p~nTo:~p~n",[Types,MFA]), t_any() end,
162
% FinalFun = fun(MFA,Type) -> io:format("ResType:~p~nFor:~p~n",[Type,MFA]),ok end,
163
% {MFA,ArgsFun,CallFun,FinalFun}.
153
%%debug_make_data(Cfg, {_M,_F,A}=MFA) ->
155
%% case hipe_icode_cfg:is_closure(Cfg) of
156
%% true -> hipe_icode_cfg:closure_arity(Cfg);
159
%% Args = lists:duplicate(NoArgs,t_any()),
160
%% ArgsFun = fun(MFA,_Cfg) -> io:format("Start:~p~n",[MFA]),Args end,
161
%% CallFun = fun(MFA,Types) -> io:format("Call With:~p~nTo:~p~n",[Types,MFA]), t_any() end,
162
%% FinalFun = fun(MFA,Type) -> io:format("ResType:~p~nFor:~p~n",[Type,MFA]),ok end,
163
%% {MFA,ArgsFun,CallFun,FinalFun}.
166
166
%% _________________________________________________________________
183
183
catch throw:no_input -> ok % No need to do anything since we have no input
186
-spec(safe_analyse/2 :: (cfg(), data()) -> #state{}).
186
-spec safe_analyse(cfg(), data()) -> #state{}.
188
188
safe_analyse(Cfg, {MFA,_,_,_}=Data) ->
189
189
State = new_state(Cfg, Data),
2083
2083
make_annotation(X, Info) ->
2084
2084
{type_anno, safe_lookup(X, Info), fun erl_types:t_to_string/1}.
2086
-spec(unannotate_cfg/1 :: (cfg()) -> cfg()).
2086
-spec unannotate_cfg(cfg()) -> cfg().
2088
2088
unannotate_cfg(Cfg) ->
2089
2089
NewCfg = unannotate_params(Cfg),
2209
2209
%% Icode Coordinator Callbacks
2210
2210
%%=====================================================================
2212
-spec(replace_nones/1 :: ([erl_type()] | erl_type()) -> [erl_type()]).
2212
-spec replace_nones([erl_type()] | erl_type()) -> [erl_type()].
2214
2214
replace_nones(Types) when is_list(Types) ->
2215
2215
[replace_none(T) || T <- Types];
2216
2216
replace_nones(Type) ->
2217
2217
[replace_none(Type)].
2219
-spec(replace_none/1 :: (erl_type()) -> erl_type()).
2219
-spec replace_none(erl_type()) -> erl_type().
2221
2221
replace_none(Type) ->
2222
2222
case erl_types:t_is_none(Type) of
2229
-spec(update__info/2 :: ([erl_type()], [erl_type()]) -> {bool(), [erl_type()]}).
2229
-spec update__info([erl_type()], [erl_type()]) -> {bool(), [erl_type()]}.
2231
2231
update__info(NewTypes, OldTypes) ->
2238
2238
Change = lists:zipwith(EqFun, ResTypes, OldTypes),
2239
2239
{lists:all(fun(X) -> X end, Change), ResTypes}.
2241
-spec(new__info/1 :: ([erl_type()]) -> [erl_type()]).
2241
-spec new__info([erl_type()]) -> [erl_type()].
2243
2243
new__info(NewTypes) ->
2244
2244
[erl_types:t_limit(T, ?TYPE_DEPTH) || T <- NewTypes].
2246
-spec(return__info/1 :: (erl_type()) -> erl_type()).
2246
-spec return__info(erl_type()) -> erl_type().
2248
2248
return__info(Types) ->
2251
-spec(return_none/0 :: () -> [erl_type(),...]).
2251
-spec return_none() -> [erl_type(),...].
2253
2253
return_none() ->
2254
2254
[erl_types:t_none()].
2256
-spec(return_none_args/2 :: (cfg(), mfa()) -> [erl_type()]).
2256
-spec return_none_args(cfg(), mfa()) -> [erl_type()].
2258
2258
return_none_args(Cfg, {_M,_F,A}) ->
2264
2264
lists:duplicate(NoArgs, erl_types:t_none()).
2266
-spec(return_any_args/2 :: (cfg(), mfa()) -> [erl_type()]).
2266
-spec return_any_args(cfg(), mfa()) -> [erl_type()].
2268
2268
return_any_args(Cfg, {_M,_F,A}) ->