Skip to content

Commit

Permalink
Get rid of the module map altogether
Browse files Browse the repository at this point in the history
It is rarely used and can always be calculated on the fly when it is
needed. It should have never been a part of the PLT in the first place.
  • Loading branch information
mpitid committed Jul 19, 2011
1 parent d1d7ec4 commit 2075a4b
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/purity_plt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

-export_type([plt/0]).

-define(VERSION, "0.4").
-define(VERSION, "0.5").

-ifdef(TEST).
-include("purity_plt_tests.hrl").
Expand All @@ -48,7 +48,6 @@

-record(plt, {version = ?VERSION :: string(),
checksums = [] :: [file_checksum()],
modules = dict:new() :: dict(),
table = dict:new() :: dict(),
cache = [] :: [{term(), dict()}]}).

Expand All @@ -69,7 +68,6 @@ new() ->
-spec new(dict(), files()) -> plt().
new(Table, Filenames) ->
#plt{table = Table,
modules = module_dependencies(Table),
checksums = compute_checksums(absolute(Filenames))}.

-spec table(plt(), options()) -> dict().
Expand Down Expand Up @@ -209,7 +207,9 @@ compute_checksum(Filename) ->
%% @doc Provided a list of files, return a list of modules which depend
%% on them and should be re-analysed.
-spec dependent_modules(plt(), files()) -> [module()].
dependent_modules(#plt{modules = Ms}, Filenames) ->

dependent_modules(#plt{table = T}, Filenames) ->
Ms = ?utils:module_rmap(T),
uflatten([reachable(module(F), Ms) || F <- Filenames]).


Expand Down Expand Up @@ -247,9 +247,7 @@ update(Plt, Options, {Filenames, T, R}) ->
{K, C} <- keep_consistent(C0, Tn)],
Cn = assoc_store(cache_key(Options), Rn, C1),

{ok, Plt#plt{table = Tn, cache = Cn,
modules = module_dependencies(Tn),
checksums = CS}}
{ok, Plt#plt{table = Tn, cache = Cn, checksums = CS}}
end.

update_checksums(CS1, CS2) ->
Expand Down Expand Up @@ -318,11 +316,6 @@ relevant(_) ->
false.


%% @doc Reverse lookup table for inter-module dependencies, i.e.
%% each key maps to the list of modules which depend on it.
module_dependencies(T) ->
?utils:module_rmap(T).

reachable(Module, Map) ->
case dict_fetch(Module, Map, []) of
[] -> [Module];
Expand Down Expand Up @@ -362,22 +355,21 @@ assoc_store(Key, Value, [H|T]) ->
[H|assoc_store(Key, Value, T)].


-spec export(plt()) -> {string(), [{_,_}], [{_,_}], [{_,_}], [{_,_}]}.
-spec export(plt()) -> {string(), [{_,_}], [{_,_}], [{_,_}]}.

%% @doc Export a PLT into a simple deterministic structure, useful
%% for debugging.
export(#plt{table = T, cache = C, checksums = CS, modules = Ms, version = V}) ->
export(#plt{table = T, cache = C, checksums = CS, version = V}) ->
{V, lists:keysort(2, [{md5hex(MD5), F} || {F, MD5} <- CS]),
lists:sort(dict:to_list(T)),
lists:sort([{K, lists:sort(dict:to_list(R))} || {K, R} <- C]),
lists:sort(dict:to_list(Ms))}.
lists:sort([{K, lists:sort(dict:to_list(R))} || {K, R} <- C])}.


%% @doc Export a PLT as plain text.
-spec export_text(plt()) -> [iolist()].

export_text(Plt) ->
{Vsn, CS, T, R, M} = export(Plt),
{Vsn, CS, T, R} = export(Plt),
P1 = fun (F) -> io_lib:format(F ++ "~n", []) end,
%% Converting to binary is necessary for large PLTs as character
%% lists are very wasteful with regard to memory.
Expand All @@ -386,8 +378,7 @@ export_text(Plt) ->
[ P2("PLT ~s", [Vsn]),
P1("FILES"), print(P2, "~s: ~s", CS),
P1("TABLE"), PL(T),
[[P2("RES ~p", [K]), PL(V)] || {K, V} <- R],
P1("MOD"), print(P2, "~p: ~w", M) ].
[[P2("RESULTS ~p", [K]), PL(V)] || {K, V} <- R] ].


print(Print, Fmt, Items) ->
Expand Down

0 comments on commit 2075a4b

Please sign in to comment.