14
14
package com .google .devtools .build .skyframe ;
15
15
16
16
import com .google .common .annotations .VisibleForTesting ;
17
- import com .google .common .collect .ImmutableSet ;
18
17
import com .google .common .util .concurrent .ListenableFuture ;
19
18
import com .google .devtools .build .lib .util .GroupedList ;
20
19
import java .util .ArrayList ;
@@ -40,11 +39,11 @@ public abstract class AbstractSkyFunctionEnvironment implements SkyFunction.Envi
40
39
@ Nullable private final GroupedList <SkyKey > temporaryDirectDeps ;
41
40
@ Nullable protected List <ListenableFuture <?>> externalDeps ;
42
41
43
- public AbstractSkyFunctionEnvironment (@ Nullable GroupedList <SkyKey > temporaryDirectDeps ) {
42
+ protected AbstractSkyFunctionEnvironment (@ Nullable GroupedList <SkyKey > temporaryDirectDeps ) {
44
43
this .temporaryDirectDeps = temporaryDirectDeps ;
45
44
}
46
45
47
- public AbstractSkyFunctionEnvironment () {
46
+ protected AbstractSkyFunctionEnvironment () {
48
47
this (null );
49
48
}
50
49
@@ -53,31 +52,47 @@ public GroupedList<SkyKey> getTemporaryDirectDeps() {
53
52
return temporaryDirectDeps ;
54
53
}
55
54
56
- /** Implementations should set {@link #valuesMissing} as necessary. */
55
+ /**
56
+ * Gets a single value or exception.
57
+ *
58
+ * <p>Implementations should set {@link #valuesMissing} as necessary.
59
+ */
60
+ protected abstract ValueOrUntypedException getSingleValueOrUntypedException (SkyKey depKey )
61
+ throws InterruptedException ;
62
+
63
+ /**
64
+ * Gets a map of values or exceptions.
65
+ *
66
+ * <p>Implementations should set {@link #valuesMissing} as necessary.
67
+ */
57
68
protected abstract Map <SkyKey , ValueOrUntypedException > getValueOrUntypedExceptions (
58
69
Iterable <? extends SkyKey > depKeys ) throws InterruptedException ;
59
70
60
- /** Implementations should set {@link #valuesMissing} as necessary. */
71
+ /**
72
+ * Gets a list of values or exceptions parallel to the given keys.
73
+ *
74
+ * <p>Implementations should set {@link #valuesMissing} as necessary.
75
+ */
61
76
protected abstract List <ValueOrUntypedException > getOrderedValueOrUntypedExceptions (
62
77
Iterable <? extends SkyKey > depKeys ) throws InterruptedException ;
63
78
64
79
@ Override
65
80
@ Nullable
66
- public SkyValue getValue (SkyKey depKey ) throws InterruptedException {
81
+ public final SkyValue getValue (SkyKey depKey ) throws InterruptedException {
67
82
return getValueOrThrowHelper (depKey , null , null , null , null );
68
83
}
69
84
70
85
@ Override
71
86
@ Nullable
72
- public <E extends Exception > SkyValue getValueOrThrow (SkyKey depKey , Class < E > exceptionClass )
73
- throws E , InterruptedException {
87
+ public final <E extends Exception > SkyValue getValueOrThrow (
88
+ SkyKey depKey , Class < E > exceptionClass ) throws E , InterruptedException {
74
89
SkyFunctionException .validateExceptionType (exceptionClass );
75
90
return getValueOrThrowHelper (depKey , exceptionClass , null , null , null );
76
91
}
77
92
78
93
@ Override
79
94
@ Nullable
80
- public <E1 extends Exception , E2 extends Exception > SkyValue getValueOrThrow (
95
+ public final <E1 extends Exception , E2 extends Exception > SkyValue getValueOrThrow (
81
96
SkyKey depKey , Class <E1 > exceptionClass1 , Class <E2 > exceptionClass2 )
82
97
throws E1 , E2 , InterruptedException {
83
98
SkyFunctionException .validateExceptionType (exceptionClass1 );
@@ -87,7 +102,7 @@ public <E1 extends Exception, E2 extends Exception> SkyValue getValueOrThrow(
87
102
88
103
@ Override
89
104
@ Nullable
90
- public <E1 extends Exception , E2 extends Exception , E3 extends Exception >
105
+ public final <E1 extends Exception , E2 extends Exception , E3 extends Exception >
91
106
SkyValue getValueOrThrow (
92
107
SkyKey depKey ,
93
108
Class <E1 > exceptionClass1 ,
@@ -102,7 +117,8 @@ SkyValue getValueOrThrow(
102
117
103
118
@ Override
104
119
@ Nullable
105
- public <E1 extends Exception , E2 extends Exception , E3 extends Exception , E4 extends Exception >
120
+ public final <
121
+ E1 extends Exception , E2 extends Exception , E3 extends Exception , E4 extends Exception >
106
122
SkyValue getValueOrThrow (
107
123
SkyKey depKey ,
108
124
Class <E1 > exceptionClass1 ,
@@ -127,28 +143,48 @@ SkyValue getValueOrThrowHelper(
127
143
@ Nullable Class <E3 > exceptionClass3 ,
128
144
@ Nullable Class <E4 > exceptionClass4 )
129
145
throws E1 , E2 , E3 , E4 , InterruptedException {
130
- SkyframeIterableResult result = getOrderedValuesAndExceptions (ImmutableSet .of (depKey ));
131
- return result .nextOrThrow (exceptionClass1 , exceptionClass2 , exceptionClass3 , exceptionClass4 );
146
+ ValueOrUntypedException voe = getSingleValueOrUntypedException (depKey );
147
+ SkyValue value = voe .getValue ();
148
+ if (value != null ) {
149
+ return value ;
150
+ }
151
+ Exception e = voe .getException ();
152
+ if (e != null ) {
153
+ if (exceptionClass1 != null && exceptionClass1 .isInstance (e )) {
154
+ throw exceptionClass1 .cast (e );
155
+ }
156
+ if (exceptionClass2 != null && exceptionClass2 .isInstance (e )) {
157
+ throw exceptionClass2 .cast (e );
158
+ }
159
+ if (exceptionClass3 != null && exceptionClass3 .isInstance (e )) {
160
+ throw exceptionClass3 .cast (e );
161
+ }
162
+ if (exceptionClass4 != null && exceptionClass4 .isInstance (e )) {
163
+ throw exceptionClass4 .cast (e );
164
+ }
165
+ }
166
+ valuesMissing = true ;
167
+ return null ;
132
168
}
133
169
134
170
@ Override
135
- public SkyframeLookupResult getValuesAndExceptions (Iterable <? extends SkyKey > depKeys )
171
+ public final SkyframeLookupResult getValuesAndExceptions (Iterable <? extends SkyKey > depKeys )
136
172
throws InterruptedException {
137
173
Map <SkyKey , ValueOrUntypedException > valuesOrExceptions = getValueOrUntypedExceptions (depKeys );
138
174
return new SkyframeLookupResult (() -> valuesMissing = true , valuesOrExceptions ::get );
139
175
}
140
176
141
177
@ Override
142
- public SkyframeIterableResult getOrderedValuesAndExceptions (Iterable <? extends SkyKey > depKeys )
143
- throws InterruptedException {
178
+ public final SkyframeIterableResult getOrderedValuesAndExceptions (
179
+ Iterable <? extends SkyKey > depKeys ) throws InterruptedException {
144
180
List <ValueOrUntypedException > valuesOrExceptions = getOrderedValueOrUntypedExceptions (depKeys );
145
181
Iterator <ValueOrUntypedException > valuesOrExceptionsi = valuesOrExceptions .iterator ();
146
182
return new SkyframeIterableResult (() -> valuesMissing = true , valuesOrExceptionsi );
147
183
}
148
184
149
185
@ Override
150
- public boolean valuesMissing () {
151
- return valuesMissing || ( externalDeps != null ) ;
186
+ public final boolean valuesMissing () {
187
+ return valuesMissing || externalDeps != null ;
152
188
}
153
189
154
190
@ Override
0 commit comments