// Copyright 2017 The Bazel Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.skyframe; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.Interner; import com.google.devtools.build.lib.concurrent.BlazeInterners; /** * Container for a pending operation on the reverse deps set. We use subclasses to save 8 bytes of * memory instead of keeping a field in this class, and we store {@link Op#CHECK} or {@link Op#ADD} * operations as the bare {@link SkyKey} in order to save the wrapper object in that case. * *
When a list of {@link KeyToConsolidate} operations is processed, each operation is performed
* in order. Operations on a done or freshly evaluating node entry are straightforward: they apply
* to the entry's reverse deps. Operations on a re-evaluating node entry have a double meaning: they
* will eventually be applied to the node entry's existing reverse deps, just as for a done node
* entry, but they are also used to track the entries that declared/redeclared a reverse dep on this
* entry during this evaluation (and will thus need to be signaled when this entry finishes
* evaluating).
*/
public abstract class KeyToConsolidate {
enum Op {
/**
* Assert that the reverse dep is already present in the set of reverse deps. If the entry is
* re-evaluating, add this reverse dep to the set of reverse deps to signal when this entry is
* done.
*/
CHECK,
/**
* Add the reverse dep to the set of reverse deps and assert it was not already present. If the
* entry is re-evaluating, add this reverse dep to the set of reverse deps to signal when this
* entry is done.
*/
ADD,
/**
* Remove the reverse dep from the set of reverse deps and assert it was present. If the entry
* is re-evaluating, also remove the reverse dep from the set of reverse deps to signal when
* this entry is done, and assert that it was present.
*/
REMOVE,
/**
* The same as {@link #REMOVE}, except that if the entry is re-evaluating, we assert that the
* set of reverse deps to signal did not contain this reverse dep.
*/
REMOVE_OLD
}
/** The operation {@link ReverseDepsUtility} should store bare in pending reverse dep ops. */
public enum OpToStoreBare {
ADD(Op.ADD),
CHECK(Op.CHECK);
private final Op op;
OpToStoreBare(Op op) {
this.op = op;
}
}
private static final Interner