concretizer: add depth calculation

This commit is contained in:
Todd Gamblin 2023-01-02 00:34:32 -08:00
parent c410f3f392
commit 20e698c6b0
No known key found for this signature in database
GPG Key ID: C16729F1AACF66C6
2 changed files with 28 additions and 0 deletions

View File

@ -1106,6 +1106,33 @@ build_priority(Package, 0) :- attr("node", Package), not optimize_for_reuse().
#defined installed_hash/2.
%-----------------------------------------------------------------------------
% Calculate min depth of nodes in the DAG
% We use this to optimize nodes closer to roots with higher precedence.
%-----------------------------------------------------------------------------
#const max_depth = 10.
% roots have depth 0
depth(Package, 0) :- attr("root", Package).
% possible optimization
% adding this to the minimization below doesn't seem to help.
%possible_dependency(Dependent, Package) :- dependency_condition(_, Dependent, Package).
%possible_dependency(Dependent, Package) :-
% dependency_condition(_, Dependent, Virtual), possible_provider(Package, Virtual).
% other nodes' depth is the minimum depth of any dependent plus one.
depth(Package, N+1) :-
N = #min{
D: depends_on(Dependent, Package),
depth(Dependent, D),
0 <= D,
D < max_depth
},
0 <= N,
N <= max_depth,
attr("node", Package).
%-----------------------------------------------------------------
% Optimization to avoid errors
%-----------------------------------------------------------------

View File

@ -26,3 +26,4 @@
#show error/7.
% debug
#show depth/2.