Skip to content

Commit

Permalink
Change behavior of `SkyFunctionEnvironment#PREFETCH_AND_RETAIN_OLD_DE…
Browse files Browse the repository at this point in the history
…PS` to retain the `NodeEntry` objects rather than merely the `SkyValue` objects.

`SkyFunctionEnvironment#PREFETCH_AND_RETAIN_OLD_DEPS` was recently introduced in commit `84e3bb2`. See that commit's message for more details. tl;dr - You shouldn't know or care about this at all unless you have a private fork of Bazel.

PiperOrigin-RevId: 347641704
  • Loading branch information
haxorz authored and copybara-github committed Dec 15, 2020
1 parent 4a5af6b commit d07bd14
Showing 1 changed file with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ class SkyFunctionEnvironment extends AbstractSkyFunctionEnvironment {
@Nullable private final Map<SkyKey, ValueWithMetadata> bubbleErrorInfo;

/**
* The current values of the direct deps this node had at the previous version.
* The current entries of the direct deps this node had at the previous version.
*
* <p>Used only when {@link #PREFETCH_AND_RETAIN_OLD_DEPS} is {@code true}.
* <p>Used only when {@link #PREFETCH_AND_RETAIN_OLD_DEPS} is {@code true}, and used only for the
* values stored in the entries; do not do any NodeEntry operations on these.
*/
private ImmutableMap<SkyKey, SkyValue> oldDepsValues = ImmutableMap.of();
private ImmutableMap<SkyKey, ? extends NodeEntry> oldDepsEntries = ImmutableMap.of();

/**
* The values previously declared as dependencies.
Expand Down Expand Up @@ -225,17 +226,8 @@ private ImmutableMap<SkyKey, SkyValue> batchPrefetch(
evaluatorContext.getGraph().prefetchDeps(request);
} else if (PREFETCH_AND_RETAIN_OLD_DEPS) {
// TODO(b/175215425): Make PREFETCH_AND_RETAIN_OLD_DEPS the only behavior.
ImmutableMap.Builder<SkyKey, SkyValue> oldDepValuesBuilder =
ImmutableMap.builderWithExpectedSize(oldDeps.size());
Map<SkyKey, ? extends NodeEntry> map =
evaluatorContext.getBatchValues(requestor, Reason.PREFETCH, oldDeps);
for (Entry<SkyKey, ? extends NodeEntry> entry : map.entrySet()) {
SkyValue valueMaybeWithMetadata = entry.getValue().getValueMaybeWithMetadata();
if (valueMaybeWithMetadata != null) {
oldDepValuesBuilder.put(entry.getKey(), valueMaybeWithMetadata);
}
}
this.oldDepsValues = oldDepValuesBuilder.build();
this.oldDepsEntries =
ImmutableMap.copyOf(evaluatorContext.getBatchValues(requestor, Reason.PREFETCH, oldDeps));
}
Map<SkyKey, ? extends NodeEntry> batchMap =
evaluatorContext.getBatchValues(
Expand Down Expand Up @@ -483,7 +475,7 @@ private List<SkyValue> getOrderedValuesFromErrorOrDepsOrGraph(Iterable<? extends
* <li>{@link #bubbleErrorInfo}
* <li>{@link #previouslyRequestedDepsValues}
* <li>{@link #newlyRequestedDepsValues}
* <li>{@link #oldDepsValues}
* <li>{@link #oldDepsEntries}
* <li>{@link #evaluatorContext}'s graph accessing methods
* </ol>
*
Expand Down Expand Up @@ -567,14 +559,14 @@ private Collection<SkyValue> getDepValuesForDoneNodeFromErrorOrDepsOrGraph(
* <li>{@code bubbleErrorInfo}
* <li>{@link #previouslyRequestedDepsValues}
* <li>{@link #newlyRequestedDepsValues}
* <li>{@link #oldDepsValues}
* <li>{@link #oldDepsEntries}
* </ol>
*
* <p>Returns {@code null} if no entries for {@code key} were found in any of those three maps.
* (Note that none of the maps can have {@code null} as a value.)
*/
@Nullable
SkyValue maybeGetValueFromErrorOrDeps(SkyKey key) {
SkyValue maybeGetValueFromErrorOrDeps(SkyKey key) throws InterruptedException {
if (bubbleErrorInfo != null) {
ValueWithMetadata bubbleErrorInfoValue = bubbleErrorInfo.get(key);
if (bubbleErrorInfoValue != null) {
Expand All @@ -589,9 +581,9 @@ SkyValue maybeGetValueFromErrorOrDeps(SkyKey key) {
if (newlyRequestedDepsValue != null) {
return newlyRequestedDepsValue;
}
SkyValue oldDepsValue = oldDepsValues.get(key);
if (oldDepsValue != null) {
return oldDepsValue;
SkyValue oldDepsValueOrNullMarker = getValueOrNullMarker(oldDepsEntries.get(key));
if (oldDepsValueOrNullMarker != NULL_MARKER) {
return oldDepsValueOrNullMarker;
}
return null;
}
Expand Down

0 comments on commit d07bd14

Please sign in to comment.