aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar mjhalupka <mjhalupka@google.com>2018-06-27 13:50:17 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-27 13:51:49 -0700
commitf095fe0229600d5e63405595022a4751421e3189 (patch)
tree362e9cdb325db527e1d53e73e30600548bfb5bca /src/main
parent90e2b4b5e745fe2de9ca82bc8163c198e5be8ca9 (diff)
Add Interners for CcToolchainFeatures$ActionConfig, Feature, and
FeatureConfiguration. PiperOrigin-RevId: 202363333
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java83
1 files changed, 75 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
index 5becc5aa3a..60d2c1113f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeatures.java
@@ -25,9 +25,11 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Interner;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
+import com.google.devtools.build.lib.concurrent.BlazeInterners;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.Expandable;
import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.SingleVariables;
@@ -684,6 +686,8 @@ public class CcToolchainFeatures implements Serializable {
@AutoCodec
@VisibleForSerialization
static class Feature implements Serializable, CrosstoolSelectable {
+ private static final Interner<Feature> FEATURE_INTERNER = BlazeInterners.newWeakInterner();
+
private final String name;
private final ImmutableList<FlagSet> flagSets;
private final ImmutableList<EnvSet> envSets;
@@ -717,9 +721,7 @@ public class CcToolchainFeatures implements Serializable {
this.provides = ImmutableList.copyOf(feature.getProvidesList());
}
- @AutoCodec.Instantiator
- @VisibleForSerialization
- Feature(
+ private Feature(
String name,
ImmutableList<FlagSet> flagSets,
ImmutableList<EnvSet> envSets,
@@ -736,6 +738,20 @@ public class CcToolchainFeatures implements Serializable {
this.provides = provides;
}
+ @AutoCodec.Instantiator
+ @VisibleForSerialization
+ static Feature createFeatureForSerialization(
+ String name,
+ ImmutableList<FlagSet> flagSets,
+ ImmutableList<EnvSet> envSets,
+ boolean enabled,
+ ImmutableList<ImmutableSet<String>> requires,
+ ImmutableList<String> implies,
+ ImmutableList<String> provides) {
+ return FEATURE_INTERNER.intern(
+ new Feature(name, flagSets, envSets, enabled, requires, implies, provides));
+ }
+
@Override
public String getName() {
return name;
@@ -881,6 +897,9 @@ public class CcToolchainFeatures implements Serializable {
+ "to the configured action. Thus, you must not specify action lists in an "
+ "action_config's flag set.";
+ private static final Interner<ActionConfig> ACTION_CONFIG_INTERNER =
+ BlazeInterners.newWeakInterner();
+
private final String configName;
private final String actionName;
private final ImmutableList<Tool> tools;
@@ -922,9 +941,7 @@ public class CcToolchainFeatures implements Serializable {
this.implies = ImmutableList.copyOf(actionConfig.getImpliesList());
}
- @AutoCodec.Instantiator
- @VisibleForSerialization
- ActionConfig(
+ private ActionConfig(
String configName,
String actionName,
ImmutableList<Tool> tools,
@@ -939,6 +956,19 @@ public class CcToolchainFeatures implements Serializable {
this.implies = implies;
}
+ @AutoCodec.Instantiator
+ @VisibleForSerialization
+ static ActionConfig createForSerialization(
+ String configName,
+ String actionName,
+ ImmutableList<Tool> tools,
+ ImmutableList<FlagSet> flagSets,
+ boolean enabled,
+ ImmutableList<String> implies) {
+ return ACTION_CONFIG_INTERNER.intern(
+ new ActionConfig(configName, actionName, tools, flagSets, enabled, implies));
+ }
+
@Override
public String getName() {
return configName;
@@ -991,6 +1021,29 @@ public class CcToolchainFeatures implements Serializable {
public ImmutableList<String> getImplies() {
return implies;
}
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof ActionConfig)) {
+ return false;
+ }
+ ActionConfig that = (ActionConfig) other;
+
+ return Objects.equals(configName, that.configName)
+ && Objects.equals(actionName, that.actionName)
+ && enabled == that.enabled
+ && Iterables.elementsEqual(tools, that.tools)
+ && Iterables.elementsEqual(flagSets, that.flagSets)
+ && Iterables.elementsEqual(implies, that.implies);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(configName, actionName, enabled, tools, flagSets, implies);
+ }
}
/** A description of how artifacts of a certain type are named. */
@@ -1055,6 +1108,9 @@ public class CcToolchainFeatures implements Serializable {
@Immutable
@AutoCodec
public static class FeatureConfiguration implements FeatureConfigurationApi {
+ private static final Interner<FeatureConfiguration> FEATURE_CONFIGURATION_INTERNER =
+ BlazeInterners.newWeakInterner();
+
private final ImmutableSet<String> enabledFeatureNames;
private final ImmutableList<Feature> enabledFeatures;
private final ImmutableSet<String> enabledActionConfigActionNames;
@@ -1066,13 +1122,23 @@ public class CcToolchainFeatures implements Serializable {
* used when creation of the real {@link FeatureConfiguration} failed, the rule error was
* reported, but the analysis continues to collect more rule errors.
*/
- public static final FeatureConfiguration EMPTY = new FeatureConfiguration();
+ public static final FeatureConfiguration EMPTY =
+ FEATURE_CONFIGURATION_INTERNER.intern(new FeatureConfiguration());
protected FeatureConfiguration() {
this(ImmutableList.of(), ImmutableSet.of(), ImmutableMap.of());
}
@AutoCodec.Instantiator
+ static FeatureConfiguration createForSerialization(
+ ImmutableList<Feature> enabledFeatures,
+ ImmutableSet<String> enabledActionConfigActionNames,
+ ImmutableMap<String, ActionConfig> actionConfigByActionName) {
+ return FEATURE_CONFIGURATION_INTERNER.intern(
+ new FeatureConfiguration(
+ enabledFeatures, enabledActionConfigActionNames, actionConfigByActionName));
+ }
+
FeatureConfiguration(
ImmutableList<Feature> enabledFeatures,
ImmutableSet<String> enabledActionConfigActionNames,
@@ -1179,10 +1245,11 @@ public class CcToolchainFeatures implements Serializable {
}
if (object instanceof FeatureConfiguration) {
FeatureConfiguration that = (FeatureConfiguration) object;
+ // Only compare actionConfigByActionName, enabledActionConfigActionnames and enabledFeatures
+ // because enabledFeatureNames is based on the list of Features.
return Objects.equals(actionConfigByActionName, that.actionConfigByActionName)
&& Iterables.elementsEqual(
enabledActionConfigActionNames, that.enabledActionConfigActionNames)
- && Iterables.elementsEqual(enabledFeatureNames, that.enabledFeatureNames)
&& Iterables.elementsEqual(enabledFeatures, that.enabledFeatures);
}
return false;