Allow SkyValues to be marked not "comparable". Such values are not compared for the purpose of change pruning.

--
MOS_MIGRATED_REVID=108203369
diff --git a/src/main/java/com/google/devtools/build/skyframe/ValueWithMetadata.java b/src/main/java/com/google/devtools/build/skyframe/ValueWithMetadata.java
index 6eab026..b702433 100644
--- a/src/main/java/com/google/devtools/build/skyframe/ValueWithMetadata.java
+++ b/src/main/java/com/google/devtools/build/skyframe/ValueWithMetadata.java
@@ -60,7 +60,7 @@
     if (errorInfo == null) {
       return transitiveEvents.isEmpty()
           ? value
-          : new ValueWithEvents(value, transitiveEvents);
+          : ValueWithEvents.createValueWithEvents(value, transitiveEvents);
     }
     return new ErrorInfoValue(errorInfo, value, transitiveEvents);
   }
@@ -75,15 +75,24 @@
   public abstract NestedSet<TaggedEvents> getTransitiveEvents();
 
   /** Implementation of {@link ValueWithMetadata} for the value case. */
-  public static final class ValueWithEvents extends ValueWithMetadata {
+  public static class ValueWithEvents extends ValueWithMetadata {
 
     private final NestedSet<TaggedEvents> transitiveEvents;
 
-    public ValueWithEvents(SkyValue value, NestedSet<TaggedEvents> transitiveEvents) {
+    private ValueWithEvents(SkyValue value, NestedSet<TaggedEvents> transitiveEvents) {
       super(Preconditions.checkNotNull(value));
       this.transitiveEvents = Preconditions.checkNotNull(transitiveEvents);
     }
 
+    public static ValueWithEvents createValueWithEvents(SkyValue value,
+            NestedSet<TaggedEvents> transitiveEvents) {
+      if (value instanceof NotComparableSkyValue) {
+        return new NotComparableValueWithEvents(value, transitiveEvents);
+      } else {
+        return new ValueWithEvents(value, transitiveEvents);
+      }
+    }
+
     @Nullable
     @Override
     ErrorInfo getErrorInfo() { return null; }
@@ -124,8 +133,21 @@
     public String toString() { return value.toString(); }
   }
 
-  /** Implementation of {@link ValueWithMetadata} for the error case. */
-  private static final class ErrorInfoValue extends ValueWithMetadata {
+  private static final class NotComparableValueWithEvents extends ValueWithEvents
+          implements NotComparableSkyValue {
+    private NotComparableValueWithEvents(SkyValue value,
+            NestedSet<TaggedEvents> transitiveEvents) {
+      super(value, transitiveEvents);
+    }
+  }
+
+  /**
+   * Implementation of {@link ValueWithMetadata} for the error case.
+   *
+   * ErorInfo does not override equals(), so it may as well be marked NotComparableSkyValue.
+   */
+  private static final class ErrorInfoValue extends ValueWithMetadata
+          implements NotComparableSkyValue {
 
     private final ErrorInfo errorInfo;
     private final NestedSet<TaggedEvents> transitiveEvents;
@@ -198,7 +220,7 @@
     if (value instanceof ValueWithMetadata) {
       return (ValueWithMetadata) value;
     }
-    return new ValueWithEvents(value, NO_EVENTS);
+    return ValueWithEvents.createValueWithEvents(value, NO_EVENTS);
   }
 
   @Nullable