Implement the rdeps predicate directly for RBuildFilesVisitor. PiperOrigin-RevId: 234722492
diff --git a/src/main/java/com/google/devtools/build/lib/query2/ParallelSkyQueryUtils.java b/src/main/java/com/google/devtools/build/lib/query2/ParallelSkyQueryUtils.java index a9a0aca..1f5e55a 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/ParallelSkyQueryUtils.java +++ b/src/main/java/com/google/devtools/build/lib/query2/ParallelSkyQueryUtils.java
@@ -31,7 +31,6 @@ import com.google.devtools.build.lib.query2.engine.QueryExpressionContext; import com.google.devtools.build.lib.query2.engine.QueryUtil; import com.google.devtools.build.lib.query2.engine.QueryUtil.AggregateAllCallback; -import com.google.devtools.build.lib.skyframe.SkyFunctions; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.skyframe.SkyKey; import java.util.Collection; @@ -172,14 +171,7 @@ /*visitUniquifier=*/ env.createSkyKeyUniquifier(), /*resultUniquifier=*/ env.createSkyKeyUniquifier(), context, - callback, - /*rdepFilter=*/ rdep -> - // Packages may depend on the existence of subpackages, but these edges aren't - // relevant to rbuildfiles. They may also depend on files transitively through - // globs, but these cannot be included in load statements and so we don't traverse - // through these either. - !rdep.functionName().equals(SkyFunctions.PACKAGE_LOOKUP) - && !rdep.functionName().equals(SkyFunctions.GLOB)); + callback); visitor.visitAndWaitForCompletion(env.getFileStateKeysForFileFragments(fileIdentifiers)); }
diff --git a/src/main/java/com/google/devtools/build/lib/query2/RBuildFilesVisitor.java b/src/main/java/com/google/devtools/build/lib/query2/RBuildFilesVisitor.java index 7f89545..ec4bb59 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/RBuildFilesVisitor.java +++ b/src/main/java/com/google/devtools/build/lib/query2/RBuildFilesVisitor.java
@@ -26,7 +26,6 @@ import com.google.devtools.build.skyframe.SkyKey; import java.util.Collection; import java.util.Set; -import java.util.function.Function; /** A helper class that computes 'rbuildfiles(<blah>)' via BFS. */ public class RBuildFilesVisitor extends AbstractSkyKeyParallelVisitor<Target> { @@ -39,17 +38,15 @@ private static final SkyKey EXTERNAL_PACKAGE_KEY = PackageValue.key(LabelConstants.EXTERNAL_PACKAGE_IDENTIFIER); private final SkyQueryEnvironment env; - private final Uniquifier<SkyKey> resultUniquifier; private final QueryExpressionContext<Target> context; - private final Function<SkyKey, Boolean> rdepFilter; + protected final Uniquifier<SkyKey> resultUniquifier; public RBuildFilesVisitor( SkyQueryEnvironment env, Uniquifier<SkyKey> visitUniquifier, Uniquifier<SkyKey> resultUniquifier, QueryExpressionContext<Target> context, - Callback<Target> callback, - Function<SkyKey, Boolean> rdepFilter) { + Callback<Target> callback) { super( visitUniquifier, callback, @@ -58,7 +55,6 @@ this.env = env; this.resultUniquifier = resultUniquifier; this.context = context; - this.rdepFilter = rdepFilter; } @Override @@ -76,8 +72,8 @@ if (rdep.equals(EXTERNAL_PACKAGE_KEY)) { keysToVisitNext.add(rdep); } - } else if (rdepFilter.apply(rdep)) { - keysToVisitNext.add(rdep); + } else { + processNonPackageRdepAndDetermineVisitations(rdep, keysToVisitNext, keysToUseForResult); } } return new Visit(keysToUseForResult, keysToVisitNext); @@ -95,4 +91,17 @@ protected Iterable<SkyKey> preprocessInitialVisit(Iterable<SkyKey> keys) { return keys; } + + protected void processNonPackageRdepAndDetermineVisitations( + SkyKey rdep, Set<SkyKey> keysToVisitNext, Set<SkyKey> keysToUseForResult) + throws QueryException { + // Packages may depend on the existence of subpackages, but these edges aren't + // relevant to rbuildfiles. They may also depend on files transitively through + // globs, but these cannot be included in load statements and so we don't traverse + // through these either. + if (!rdep.functionName().equals(SkyFunctions.PACKAGE_LOOKUP) + && !rdep.functionName().equals(SkyFunctions.GLOB)) { + keysToVisitNext.add(rdep); + } + } }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java index 0741eb0..f5c5f8c 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java
@@ -133,9 +133,10 @@ return Key.create(pkgIdentifier); } + /** {@link SkyKey} for {@link PackageLookupValue} computation. */ @AutoCodec.VisibleForSerialization @AutoCodec - static class Key extends AbstractSkyKey<PackageIdentifier> { + public static class Key extends AbstractSkyKey<PackageIdentifier> { private static final Interner<Key> interner = BlazeInterners.newWeakInterner(); private Key(PackageIdentifier arg) {