Skip to content

Commit

Permalink
Replace NullEvaluationProgressReceiver with default methods
Browse files Browse the repository at this point in the history
Removes unnecessary clutter.

RELNOTES: None.
PiperOrigin-RevId: 361458286
  • Loading branch information
anakanemison authored and copybara-github committed Mar 8, 2021
1 parent 1a48161 commit 7242b0e
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
import javax.annotation.Nullable;

/**
* Listener for executed actions and built artifacts. We use a listener so that we have an
* accurate set of successfully run actions and built artifacts, even if the build is interrupted.
* Listener for executed actions and built artifacts. We use a listener so that we have an accurate
* set of successfully run actions and built artifacts, even if the build is interrupted.
*/
public final class ExecutionProgressReceiver
extends EvaluationProgressReceiver.NullEvaluationProgressReceiver
implements SkyframeActionExecutor.ProgressSupplier,
SkyframeActionExecutor.ActionCompletedReceiver {
SkyframeActionExecutor.ActionCompletedReceiver,
EvaluationProgressReceiver {
private static final ThreadLocal<NumberFormat> PROGRESS_MESSAGE_NUMBER_FORMATTER =
ThreadLocal.withInitial(
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,8 +1058,7 @@ public ActionKeyContext getActionKeyContext() {
return skyframeExecutor.getActionKeyContext();
}

private final class ActionLookupValueProgressReceiver
extends EvaluationProgressReceiver.NullEvaluationProgressReceiver {
private final class ActionLookupValueProgressReceiver implements EvaluationProgressReceiver {
private final AtomicInteger actionLookupValueCount = new AtomicInteger();
private final AtomicInteger actionCount = new AtomicInteger();
private final AtomicInteger configuredTargetCount = new AtomicInteger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3005,9 +3005,8 @@ public PrepareAnalysisPhaseValue prepareAnalysisPhase(
return prepareAnalysisPhaseValue;
}

/** A progress received to track analysis invalidation and update progress messages. */
protected class SkyframeProgressReceiver
extends EvaluationProgressReceiver.NullEvaluationProgressReceiver {
/** A progress receiver to track analysis invalidation and update progress messages. */
protected class SkyframeProgressReceiver implements EvaluationProgressReceiver {
/**
* This flag is needed in order to avoid invalidating legacy data when we clear the analysis
* cache because of --discard_analysis_cache flag. For that case we want to keep the legacy data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.skyframe.trimming.TrimmedConfigurationCache;
import com.google.devtools.build.skyframe.ErrorInfo;
import com.google.devtools.build.skyframe.EvaluationProgressReceiver.EvaluationState;
import com.google.devtools.build.skyframe.EvaluationProgressReceiver.EvaluationSuccessState;
import com.google.devtools.build.skyframe.EvaluationProgressReceiver.InvalidationState;
import com.google.devtools.build.skyframe.EvaluationProgressReceiver.NullEvaluationProgressReceiver;
import com.google.devtools.build.skyframe.EvaluationProgressReceiver;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import java.util.function.Supplier;
Expand All @@ -32,7 +29,7 @@
* Skyframe progress receiver which keeps a {@link TrimmedConfigurationCache} in sync with Skyframe
* invalidations and revalidations.
*/
public final class TrimmedConfigurationProgressReceiver extends NullEvaluationProgressReceiver {
public final class TrimmedConfigurationProgressReceiver implements EvaluationProgressReceiver {

private final TrimmedConfigurationCache<SkyKey, Label, BuildOptions.OptionsDiffForReconstruction>
cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private BuildDriver makeFreshDriver() {
InMemoryMemoizingEvaluator.SUPPLIER.create(
makeFreshSkyFunctions(),
preinjectedDifferencer,
new EvaluationProgressReceiver.NullEvaluationProgressReceiver(),
EvaluationProgressReceiver.NULL,
GraphInconsistencyReceiver.THROWING,
InMemoryMemoizingEvaluator.DEFAULT_STORED_EVENT_FILTER,
new MemoizingEvaluator.EmittedEventState(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
/** Receiver for various stages of the lifetime of a skyframe node evaluation. */
@ThreadSafety.ThreadSafe
public interface EvaluationProgressReceiver {
/**
* New state of the value entry after evaluation.
*/

/** A no-op {@link EvaluationProgressReceiver}. */
EvaluationProgressReceiver NULL = new EvaluationProgressReceiver() {};

/** New state of the value entry after evaluation. */
enum EvaluationState {
/** The value was successfully re-evaluated. */
BUILT,
Expand Down Expand Up @@ -50,19 +52,15 @@ public Supplier<EvaluationSuccessState> supplier() {
}
}

/**
* New state of the value entry after invalidation.
*/
/** New state of the value entry after invalidation. */
enum InvalidationState {
/** The value is dirty, although it might get re-validated again. */
DIRTY,
/** The value is dirty and got deleted, cannot get re-validated again. */
DELETED,
}

/**
* Overall state of the node while it is being evaluated.
*/
/** Overall state of the node while it is being evaluated. */
enum NodeState {
/** The node is undergoing a dirtiness check and may be re-validated. */
CHECK_DIRTY,
Expand All @@ -84,25 +82,25 @@ enum NodeState {
* <p>If {@code state} is {@link InvalidationState#DIRTY}, should only be called after a
* successful {@link ThinNodeEntry#markDirty} call: a call that returns a non-null value.
*/
void invalidated(SkyKey skyKey, InvalidationState state);
default void invalidated(SkyKey skyKey, InvalidationState state) {}

/**
* Notifies that {@code skyKey} is about to get queued for evaluation.
*
* <p>Note that we don't guarantee that it actually got enqueued or will, only that if
* everything "goes well" (e.g. no interrupts happen) it will.
* <p>Note that we don't guarantee that it actually got enqueued or will, only that if everything
* "goes well" (e.g. no interrupts happen) it will.
*
* <p>This guarantee is intentionally vague to encourage writing robust implementations.
*/
void enqueueing(SkyKey skyKey);
default void enqueueing(SkyKey skyKey) {}

/**
* Notifies that the node for {@code skyKey} is about to enter the given {@code nodeState}.
*
* <p>Notably, this includes {@link SkyFunction#compute} calls due to Skyframe restarts, but also
* dirtiness checking and node completion.
*/
void stateStarting(SkyKey skyKey, NodeState nodeState);
default void stateStarting(SkyKey skyKey, NodeState nodeState) {}

/**
* Notifies that the node for {@code skyKey} is about to complete the given {@code nodeState}.
Expand All @@ -112,7 +110,7 @@ enum NodeState {
* <p>{@code elapsedTimeNanos} is either the elapsed time in the {@code nodeState} or -1 if the
* timing was not recorded.
*/
void stateEnding(SkyKey skyKey, NodeState nodeState, long elapsedTimeNanos);
default void stateEnding(SkyKey skyKey, NodeState nodeState, long elapsedTimeNanos) {}

/**
* Notifies that the node for {@code skyKey} has been evaluated, or found to not need
Expand All @@ -128,37 +126,10 @@ enum NodeState {
* value or error (i.e., {@code EvaluationState.BUILT} if and only if at least one of newValue
* and newError is non-null)
*/
void evaluated(
default void evaluated(
SkyKey skyKey,
@Nullable SkyValue newValue,
@Nullable ErrorInfo newError,
Supplier<EvaluationSuccessState> evaluationSuccessState,
EvaluationState state);

/** An {@link EvaluationProgressReceiver} that does nothing. */
class NullEvaluationProgressReceiver implements EvaluationProgressReceiver {
@Override
public void invalidated(SkyKey skyKey, InvalidationState state) {
}

@Override
public void enqueueing(SkyKey skyKey) {
}

@Override
public void stateStarting(SkyKey skyKey, NodeState nodeState) {
}

@Override
public void stateEnding(SkyKey skyKey, NodeState nodeState, long elapsedTimeNanos) {
}

@Override
public void evaluated(
SkyKey skyKey,
@Nullable SkyValue newValue,
@Nullable ErrorInfo newError,
Supplier<EvaluationSuccessState> evaluationSuccessState,
EvaluationState state) {}
}
EvaluationState state) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ private void invalidateOutputArtifact(Artifact output) {
}

private static final class RecordingEvaluationProgressReceiver
extends EvaluationProgressReceiver.NullEvaluationProgressReceiver {
implements EvaluationProgressReceiver {
Set<SkyKey> invalidations;
Set<SkyKey> evaluations;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public final void createExecutor() throws Exception {
}

private static final class TrackingEvaluationProgressReceiver
extends EvaluationProgressReceiver.NullEvaluationProgressReceiver {
implements EvaluationProgressReceiver {

public static final class InvalidatedKey {
public final SkyKey skyKey;
Expand Down
Loading

0 comments on commit 7242b0e

Please sign in to comment.