Skip to content

Commit e917d00

Browse files
committed
Prevent infinite DAG growth
In some circumstances where files repeatedly get updated, such as when a .xrl file re-generates a .erl file on each compile run, the DAG analysis would repeatedly re-add edges for this file's dependencies (such as include files) to the DAG. Since the digraph module de-dupes vertices but not edges (duplicate edges is a valid use case), we add an explicit check for edge presence before re-adding them. This should properly prevent unexpected growth of DAG files. From manual testing, we get stability when going from a fresh DAG, but if it already had many dupes, the file size may jump around a bit regardless.
1 parent 4594b00 commit e917d00

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

apps/rebar/src/rebar_compiler_dag.erl

+10-1
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,21 @@ finalise_populate_sources_(G, InDirs, [{Status, {deps, Source, AbsIncls}}|Acc])
149149
{_, _Src, Path, _Label} <- [digraph:edge(G, Edge)],
150150
not lists:member(Path, AbsIncls)],
151151
%% Add the rest
152-
[digraph:add_edge(G, Source, Incl) || Incl <- AbsIncls],
152+
RemainingEdges = [digraph:edge(G, E) || E <- digraph:out_edges(G, Source),
153+
AbsIncls =/= []],
154+
[digraph:add_edge(G, Source, Incl) || Incl <- AbsIncls,
155+
not in_edges(Source, Incl, RemainingEdges)],
153156
%% mark the digraph dirty when there is any change in
154157
%% dependencies, for any application in the project
155158
mark_dirty(G),
156159
finalise_populate_sources_(G, InDirs, Acc).
157160

161+
%% @private look if two vertices `V1' and `V2' exist in an unsorted set
162+
%% of DAG edges (in expanded format).
163+
in_edges(_, _, []) -> false;
164+
in_edges(V1, V2, [{_, V1, V2, []}|_]) -> true;
165+
in_edges(V1, V2, [_|T]) -> in_edges(V1, V2, T).
166+
158167
%% @doc this function scans all the source files found and looks into
159168
%% all the `InDirs' for deps (other source files, or files that aren't source
160169
%% but still returned by the compiler module) that are related

0 commit comments

Comments
 (0)