Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 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. |
| 14 | package com.google.devtools.build.skyframe; |
| 15 | |
Nathan Harmata | e955287 | 2015-04-01 21:53:06 +0000 | [diff] [blame] | 16 | import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; |
Googler | 407d393 | 2019-05-16 15:13:59 -0700 | [diff] [blame] | 17 | import com.google.devtools.build.lib.supplier.InterruptibleSupplier; |
| 18 | import com.google.devtools.build.lib.supplier.MemoizingInterruptibleSupplier; |
shreyax | 26e7280 | 2018-03-26 09:04:48 -0700 | [diff] [blame] | 19 | import com.google.errorprone.annotations.CanIgnoreReturnValue; |
janakr | 3fd4054 | 2017-04-07 20:43:42 +0000 | [diff] [blame] | 20 | import java.util.Collection; |
Nathan Harmata | c7e974a | 2015-10-02 22:07:35 +0000 | [diff] [blame] | 21 | import java.util.Map; |
Nathan Harmata | 3b47b1f | 2016-07-26 18:41:41 +0000 | [diff] [blame] | 22 | import javax.annotation.Nullable; |
Nathan Harmata | c7e974a | 2015-10-02 22:07:35 +0000 | [diff] [blame] | 23 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 24 | /** |
| 25 | * Interface between a single version of the graph and the evaluator. Supports mutation of that |
| 26 | * single version of the graph. |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 27 | * |
| 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 31 | */ |
Nathan Harmata | e955287 | 2015-04-01 21:53:06 +0000 | [diff] [blame] | 32 | @ThreadSafe |
Janak Ramakrishnan | cc7712f | 2016-07-08 17:38:27 +0000 | [diff] [blame] | 33 | interface EvaluableGraph extends QueryableGraph, DeletableGraph { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 34 | /** |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 35 | * 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 Harmata | 3b47b1f | 2016-07-26 18:41:41 +0000 | [diff] [blame] | 37 | * |
| 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 41 | */ |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 42 | Map<SkyKey, ? extends NodeEntry> createIfAbsentBatch( |
| 43 | @Nullable SkyKey requestor, Reason reason, Iterable<SkyKey> keys) throws InterruptedException; |
janakr | 3fd4054 | 2017-04-07 20:43:42 +0000 | [diff] [blame] | 44 | |
| 45 | /** |
shreyax | 26e7280 | 2018-03-26 09:04:48 -0700 | [diff] [blame] | 46 | * 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) { |
Googler | 407d393 | 2019-05-16 15:13:59 -0700 | [diff] [blame] | 57 | return MemoizingInterruptibleSupplier.of(() -> createIfAbsentBatch(requestor, reason, keys)); |
shreyax | 26e7280 | 2018-03-26 09:04:48 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /** |
janakr | 3fd4054 | 2017-04-07 20:43:42 +0000 | [diff] [blame] | 61 | * 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 Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 71 | } |