blob: 488dea237fa02e7b08a54e67795f42c842e35a5c [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.skyframe;
15
Nathan Harmatae9552872015-04-01 21:53:06 +000016import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
Googler407d3932019-05-16 15:13:59 -070017import com.google.devtools.build.lib.supplier.InterruptibleSupplier;
18import com.google.devtools.build.lib.supplier.MemoizingInterruptibleSupplier;
shreyax26e72802018-03-26 09:04:48 -070019import com.google.errorprone.annotations.CanIgnoreReturnValue;
janakr3fd40542017-04-07 20:43:42 +000020import java.util.Collection;
Nathan Harmatac7e974a2015-10-02 22:07:35 +000021import java.util.Map;
Nathan Harmata3b47b1f2016-07-26 18:41:41 +000022import javax.annotation.Nullable;
Nathan Harmatac7e974a2015-10-02 22:07:35 +000023
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010024/**
25 * Interface between a single version of the graph and the evaluator. Supports mutation of that
26 * single version of the graph.
Janak Ramakrishnan3c0adb22016-08-15 21:54:55 +000027 *
28 * <p>Certain graph implementations can throw {@link InterruptedException} when trying to retrieve
29 * node entries. Such exceptions should not be caught locally -- they should be allowed to propagate
30 * up.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010031 */
Nathan Harmatae9552872015-04-01 21:53:06 +000032@ThreadSafe
Janak Ramakrishnancc7712f2016-07-08 17:38:27 +000033interface EvaluableGraph extends QueryableGraph, DeletableGraph {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010034 /**
Janak Ramakrishnan3c0adb22016-08-15 21:54:55 +000035 * Like {@link QueryableGraph#getBatch}, except it creates a new node for each key not already
36 * present in the graph. Thus, the returned map will have an entry for each key in {@code keys}.
Nathan Harmata3b47b1f2016-07-26 18:41:41 +000037 *
38 * @param requestor if non-{@code null}, the node on behalf of which the given {@code keys} are
39 * being requested.
40 * @param reason the reason the nodes are being requested.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010041 */
Janak Ramakrishnan3c0adb22016-08-15 21:54:55 +000042 Map<SkyKey, ? extends NodeEntry> createIfAbsentBatch(
43 @Nullable SkyKey requestor, Reason reason, Iterable<SkyKey> keys) throws InterruptedException;
janakr3fd40542017-04-07 20:43:42 +000044
45 /**
shreyax26e72802018-03-26 09:04:48 -070046 * Like {@link QueryableGraph#getBatchAsync}, except it creates a new node for each key not
47 * already present in the graph. Thus, the returned map will have an entry for each key in {@code
48 * keys}.
49 *
50 * @param requestor if non-{@code null}, the node on behalf of which the given {@code keys} are
51 * being requested.
52 * @param reason the reason the nodes are being requested.
53 */
54 @CanIgnoreReturnValue
55 default InterruptibleSupplier<Map<SkyKey, ? extends NodeEntry>> createIfAbsentBatchAsync(
56 @Nullable SkyKey requestor, Reason reason, Iterable<SkyKey> keys) {
Googler407d3932019-05-16 15:13:59 -070057 return MemoizingInterruptibleSupplier.of(() -> createIfAbsentBatch(requestor, reason, keys));
shreyax26e72802018-03-26 09:04:48 -070058 }
59
60 /**
janakr3fd40542017-04-07 20:43:42 +000061 * Optional optimization: graph may use internal knowledge to filter out keys in {@code deps} that
62 * have not been recomputed since the last computation of {@code parent}. When determining if
63 * {@code parent} needs to be re-evaluated, this may be used to avoid unnecessary graph accesses.
64 *
65 * <p>Returns deps that may have new values since the node of {@code parent} was last computed,
66 * and therefore which may force re-evaluation of the node of {@code parent}.
67 */
68 DepsReport analyzeDepsDoneness(SkyKey parent, Collection<SkyKey> deps)
69 throws InterruptedException;
70
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010071}