implements PR031
This commit is contained in:
+52
-2
@@ -134,10 +134,12 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
}
|
||||
moduleVisibilityValidator.validate(ReadOnlyList.wrap(modules), diagnostics);
|
||||
markModulesWithLinkingErrors(diagnostics, moduleKeyByFile, failedModuleKeys);
|
||||
final var moduleDependencyGraph = buildModuleDependencyGraph(parsedSourceFiles);
|
||||
|
||||
final var compiledSourceFiles = new ArrayList<CompiledSourceFile>(parsedSourceFiles.size());
|
||||
for (final var parsedSource : parsedSourceFiles) {
|
||||
if (failedModuleKeys.contains(parsedSource.moduleKey())) {
|
||||
final var blockedModuleKeys = blockedModulesByDependency(failedModuleKeys, moduleDependencyGraph);
|
||||
if (blockedModuleKeys.contains(parsedSource.moduleKey())) {
|
||||
continue;
|
||||
}
|
||||
final var compileErrorBaseline = diagnostics.errorCount();
|
||||
@@ -153,8 +155,9 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
compiledSourceFiles.add(new CompiledSourceFile(parsedSource.moduleKey(), irBackendFile));
|
||||
}
|
||||
|
||||
final var blockedModuleKeys = blockedModulesByDependency(failedModuleKeys, moduleDependencyGraph);
|
||||
for (final var compiledSource : compiledSourceFiles) {
|
||||
if (failedModuleKeys.contains(compiledSource.moduleKey())) {
|
||||
if (blockedModuleKeys.contains(compiledSource.moduleKey())) {
|
||||
continue;
|
||||
}
|
||||
irBackendAggregator.merge(compiledSource.irBackendFile());
|
||||
@@ -306,10 +309,57 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Set<String>> buildModuleDependencyGraph(
|
||||
final ArrayList<ParsedSourceFile> parsedSourceFiles) {
|
||||
final Map<String, Set<String>> dependenciesByModule = new HashMap<>();
|
||||
for (final var parsedSource : parsedSourceFiles) {
|
||||
final var moduleDependencies = dependenciesByModule.computeIfAbsent(
|
||||
parsedSource.moduleKey(),
|
||||
ignored -> new HashSet<>());
|
||||
for (final var importDecl : parsedSource.ast().imports()) {
|
||||
final var moduleRef = importDecl.moduleRef();
|
||||
moduleDependencies.add(moduleKey(moduleRef.project(), moduleRef.pathSegments()));
|
||||
}
|
||||
}
|
||||
return dependenciesByModule;
|
||||
}
|
||||
|
||||
private Set<String> blockedModulesByDependency(
|
||||
final Set<String> failedModuleKeys,
|
||||
final Map<String, Set<String>> dependenciesByModule) {
|
||||
final Map<String, Set<String>> dependentsByModule = new HashMap<>();
|
||||
for (final var entry : dependenciesByModule.entrySet()) {
|
||||
final var importer = entry.getKey();
|
||||
for (final var dependency : entry.getValue()) {
|
||||
dependentsByModule.computeIfAbsent(dependency, ignored -> new HashSet<>()).add(importer);
|
||||
}
|
||||
}
|
||||
|
||||
final var blocked = new HashSet<String>(failedModuleKeys);
|
||||
final var pending = new ArrayDeque<String>(failedModuleKeys);
|
||||
while (!pending.isEmpty()) {
|
||||
final var failedOrBlocked = pending.removeFirst();
|
||||
final var dependents = dependentsByModule.getOrDefault(failedOrBlocked, Set.of());
|
||||
for (final var dependent : dependents) {
|
||||
if (!blocked.add(dependent)) {
|
||||
continue;
|
||||
}
|
||||
pending.addLast(dependent);
|
||||
}
|
||||
}
|
||||
return blocked;
|
||||
}
|
||||
|
||||
private String moduleKey(final PbsModuleVisibilityValidator.ModuleCoordinates coordinates) {
|
||||
return coordinates.project() + ":" + String.join("/", coordinates.pathSegments().asList());
|
||||
}
|
||||
|
||||
private String moduleKey(
|
||||
final String project,
|
||||
final ReadOnlyList<String> pathSegments) {
|
||||
return project + ":" + String.join("/", pathSegments.asList());
|
||||
}
|
||||
|
||||
private static final class MutableModuleUnit {
|
||||
private final ArrayList<PbsModuleVisibilityValidator.SourceFile> sources = new ArrayList<>();
|
||||
private final ArrayList<PbsModuleVisibilityValidator.BarrelFile> barrels = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user