Skip to content

Commit

Permalink
Apply SkyKeyInterner to remaining SkyKeys using Blaze.weakInterner
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 517166151
Change-Id: I57e0bcfe6b30664aac8625b505d8a8c473bf846f
  • Loading branch information
yuyue730 authored and copybara-github committed Mar 16, 2023
1 parent db167a7 commit 1a5c316
Show file tree
Hide file tree
Showing 20 changed files with 129 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@

package com.google.devtools.build.lib.bazel.bzlmod;

import com.google.common.collect.Interner;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.skyframe.AbstractSkyKey;
import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;

/** The result of {@link BzlmodRepoRuleFunction}, holding a repository rule instance. */
Expand Down Expand Up @@ -63,7 +62,7 @@ public Rule getRule() {
/** Argument for the SkyKey to request a BzlmodRepoRuleValue. */
@AutoCodec
public static class Key extends AbstractSkyKey<RepositoryName> {
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();

private Key(RepositoryName arg) {
super(arg);
Expand All @@ -79,5 +78,10 @@ static Key create(RepositoryName arg) {
public SkyFunctionName functionName() {
return BZLMOD_REPO_RULE;
}

@Override
public SkyKeyInterner<Key> getSkyKeyInterner() {
return interner;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import com.google.auto.value.AutoValue;
import com.google.auto.value.extension.memoized.Memoized;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Interner;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.skyframe.SkyFunctions;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.skyframe.SkyFunctionName;
Expand Down Expand Up @@ -85,7 +83,7 @@ public static Key key(ModuleKey moduleKey, @Nullable ModuleOverride override) {
@AutoCodec
@AutoValue
abstract static class Key implements SkyKey {
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();

abstract ModuleKey getModuleKey();

Expand All @@ -105,5 +103,10 @@ public SkyFunctionName functionName() {
@Memoized
@Override
public abstract int hashCode();

@Override
public SkyKeyInterner<Key> getSkyKeyInterner() {
return interner;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Interner;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.packages.Package;
import com.google.devtools.build.lib.skyframe.SkyFunctions;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.skyframe.AbstractSkyKey;
import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;

/** The result of evaluating a single module extension (see {@link SingleExtensionEvalFunction}). */
Expand Down Expand Up @@ -57,7 +56,7 @@ public static Key key(ModuleExtensionId id) {

@AutoCodec
static class Key extends AbstractSkyKey<ModuleExtensionId> {
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();

protected Key(ModuleExtensionId arg) {
super(arg);
Expand All @@ -72,5 +71,10 @@ static Key create(ModuleExtensionId arg) {
public SkyFunctionName functionName() {
return SkyFunctions.SINGLE_EXTENSION_EVAL;
}

@Override
public SkyKeyInterner<Key> getSkyKeyInterner() {
return interner;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Interner;
import com.google.devtools.build.lib.cmdline.RepositoryMapping;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.skyframe.SkyFunctions;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.skyframe.AbstractSkyKey;
import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;

/** The result of {@link SingleExtensionUsagesFunction}. */
Expand Down Expand Up @@ -59,7 +58,7 @@ public static Key key(ModuleExtensionId id) {

@AutoCodec
static class Key extends AbstractSkyKey<ModuleExtensionId> {
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();

protected Key(ModuleExtensionId arg) {
super(arg);
Expand All @@ -74,5 +73,10 @@ static Key create(ModuleExtensionId arg) {
public SkyFunctionName functionName() {
return SkyFunctions.SINGLE_EXTENSION_USAGES;
}

@Override
public SkyKeyInterner<Key> getSkyKeyInterner() {
return interner;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
package com.google.devtools.build.lib.io;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Interner;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.skyframe.AbstractSkyKey;
Expand All @@ -39,7 +37,7 @@ public static SkyKey key(ImmutableList<RootedPath> cycle) {
@AutoCodec.VisibleForSerialization
@AutoCodec
static class Key extends AbstractSkyKey.WithCachedHashCode<ImmutableList<RootedPath>> {
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();

private Key(ImmutableList<RootedPath> arg) {
super(arg);
Expand All @@ -55,6 +53,11 @@ static Key create(ImmutableList<RootedPath> arg) {
public SkyFunctionName functionName() {
return NAME;
}

@Override
public SkyKeyInterner<Key> getSkyKeyInterner() {
return interner;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
package com.google.devtools.build.lib.io;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Interner;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.skyframe.AbstractSkyKey;
Expand All @@ -40,7 +38,7 @@ public static SkyKey key(ImmutableList<RootedPath> cycle) {
@AutoCodec.VisibleForSerialization
@AutoCodec
static class Key extends AbstractSkyKey.WithCachedHashCode<ImmutableList<RootedPath>> {
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();

private Key(ImmutableList<RootedPath> arg) {
super(arg);
Expand All @@ -56,6 +54,11 @@ static Key create(ImmutableList<RootedPath> arg) {
public SkyFunctionName functionName() {
return NAME;
}

@Override
public SkyKeyInterner<Key> getSkyKeyInterner() {
return interner;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
// limitations under the License.
package com.google.devtools.build.lib.rules.cpp;

import com.google.common.collect.Interner;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.vfs.Path;
Expand Down Expand Up @@ -42,7 +40,7 @@ public class CcSkyframeFdoSupportValue implements SkyValue {
@Immutable
@AutoCodec
public static class Key implements SkyKey {
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();

private final PathFragment fdoZipPath;

Expand Down Expand Up @@ -82,6 +80,11 @@ public int hashCode() {
public SkyFunctionName functionName() {
return SKYFUNCTION;
}

@Override
public SkyKeyInterner<Key> getSkyKeyInterner() {
return interner;
}
}

/** Path of the profile file passed to {@code --fdo_optimize} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Interner;
import com.google.common.collect.LinkedHashMultimap;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.packages.AdvertisedProviderSet;
import com.google.devtools.build.lib.packages.Aspect;
import com.google.devtools.build.lib.packages.AspectDefinition;
Expand Down Expand Up @@ -75,7 +73,7 @@ public class GenQueryDirectPackageProviderFactory implements GenQueryPackageProv
*/
@AutoCodec
static class Key extends AbstractSkyKey.WithCachedHashCode<ImmutableList<Label>> {
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();

private Key(ImmutableList<Label> arg) {
super(ImmutableList.sortedCopyOf(arg));
Expand All @@ -96,6 +94,11 @@ public SkyFunctionName functionName() {
public boolean supportsPartialReevaluation() {
return true;
}

@Override
public SkyKeyInterner<Key> getSkyKeyInterner() {
return interner;
}
}

private static class Value implements SkyValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Interner;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.skyframe.DirectoryListingValue;
import com.google.devtools.build.lib.skyframe.SkyFunctions;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
Expand Down Expand Up @@ -166,7 +164,7 @@ public static Key key(RepositoryName repository) {
@AutoCodec.VisibleForSerialization
@AutoCodec
public static class Key extends AbstractSkyKey<RepositoryName> {
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();

private Key(RepositoryName arg) {
super(arg);
Expand All @@ -182,6 +180,11 @@ static Key create(RepositoryName arg) {
public SkyFunctionName functionName() {
return SkyFunctions.REPOSITORY_DIRECTORY;
}

@Override
public SkyKeyInterner<Key> getSkyKeyInterner() {
return interner;
}
}

public static Builder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package com.google.devtools.build.lib.rules.repository;

import com.google.common.collect.Interner;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.skyframe.SkyFunctions;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
Expand All @@ -34,7 +32,7 @@ public class ResolvedFileValue implements SkyValue {
@Immutable
@AutoCodec
public static class ResolvedFileKey implements SkyKey {
private static final Interner<ResolvedFileKey> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<ResolvedFileKey> interner = SkyKey.newInterner();

private final RootedPath path;

Expand Down Expand Up @@ -73,6 +71,11 @@ public boolean equals(Object obj) {
public int hashCode() {
return path.hashCode();
}

@Override
public SkyKeyInterner<ResolvedFileKey> getSkyKeyInterner() {
return interner;
}
}

public static SkyKey key(RootedPath path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
package com.google.devtools.build.lib.skyframe;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Interner;
import com.google.devtools.build.lib.bugreport.BugReport;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.skyframe.AbstractSkyKey;
import com.google.devtools.build.skyframe.SkyFunction;
Expand Down Expand Up @@ -55,7 +53,7 @@ public static Key key(String variable) {
@AutoCodec.VisibleForSerialization
@AutoCodec
static class Key extends AbstractSkyKey<String> {
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();

private Key(String arg) {
super(arg);
Expand All @@ -71,6 +69,11 @@ static Key create(String arg) {
public SkyFunctionName functionName() {
return SkyFunctions.ACTION_ENVIRONMENT_VARIABLE;
}

@Override
public SkyKeyInterner<Key> getSkyKeyInterner() {
return interner;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@

import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.collect.Interner;
import com.google.devtools.build.lib.actions.ActionLookupKey;
import com.google.devtools.build.lib.actions.ActionLookupValue;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
import com.google.devtools.build.skyframe.AbstractSkyKey;
import com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;

/**
Expand All @@ -49,7 +48,7 @@ public static Key key(Artifact artifact) {
@AutoCodec.VisibleForSerialization
@AutoCodec
static class Key extends AbstractSkyKey<ActionLookupKey> {
private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();

private Key(ActionLookupKey arg) {
super(arg);
Expand All @@ -65,5 +64,10 @@ static Key create(ActionLookupKey arg) {
public SkyFunctionName functionName() {
return SkyFunctions.ACTION_LOOKUP_CONFLICT_FINDING;
}

@Override
public SkyKeyInterner<Key> getSkyKeyInterner() {
return interner;
}
}
}
Loading

0 comments on commit 1a5c316

Please sign in to comment.