Speed up finding dependency cycles am: 9793b0a5e0

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1689305

Change-Id: I28b57ccfe40e04e446d8ff4c721752ff1a69aae9
This commit is contained in:
Colin Cross 2021-04-29 00:13:51 +00:00 committed by Automerger Merge Worker
commit 010f5bbd8d

View file

@ -2081,6 +2081,11 @@ func parallelVisit(modules []*moduleInfo, order visitOrderer, limit int,
// modules to the modules that would have been unblocked when that module finished, i.e
// the reverse of the visitOrderer.
// In order to reduce duplicated work, once a module has been checked and determined
// not to be part of a cycle add it and everything that depends on it to the checked
// map.
checked := make(map[*moduleInfo]struct{})
var check func(module, end *moduleInfo) []*moduleInfo
check = func(module, end *moduleInfo) []*moduleInfo {
if module.waitingCount == -1 {
@ -2092,6 +2097,10 @@ func parallelVisit(modules []*moduleInfo, order visitOrderer, limit int,
return []*moduleInfo{module}
}
if _, alreadyChecked := checked[module]; alreadyChecked {
return nil
}
for _, dep := range order.propagate(module) {
cycle := check(dep, end)
if cycle != nil {
@ -2105,6 +2114,7 @@ func parallelVisit(modules []*moduleInfo, order visitOrderer, limit int,
}
}
checked[module] = struct{}{}
return nil
}