Skip to content

Commit c58997c

Browse files
l46kokcopybara-github
authored andcommitted
Add plumbing for executor, async evaluation option. Define program API contracts
PiperOrigin-RevId: 975218617
1 parent a2353b3 commit c58997c

22 files changed

Lines changed: 1701 additions & 9 deletions

.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ build --java_language_version=11
1616
common --javacopt=-Xlint:-options
1717

1818
# Remove flag once https://github.com/google/cel-spec/issues/508 and rules_jvm_external is fixed.
19-
common --incompatible_autoload_externally=proto_library,cc_proto_library,java_proto_library,java_test
19+
common --incompatible_autoload_externally=proto_library,cc_proto_library,java_proto_library,java_test,java_import
2020

2121
# Limit repository cache size by not caching extracted repository contents
2222
build --repo_contents_cache=

publish/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ COMMON_TARGETS = [
2929
# keep sorted
3030
RUNTIME_TARGETS = [
3131
"//runtime/src/main/java/dev/cel/runtime",
32+
"//runtime/src/main/java/dev/cel/runtime:async_call",
33+
"//runtime/src/main/java/dev/cel/runtime:async_drain_strategy",
34+
"//runtime/src/main/java/dev/cel/runtime:async_observer",
35+
"//runtime/src/main/java/dev/cel/runtime:async_options",
3236
"//runtime/src/main/java/dev/cel/runtime:base",
3337
"//runtime/src/main/java/dev/cel/runtime:interpreter",
3438
"//runtime/src/main/java/dev/cel/runtime:late_function_binding",

runtime/BUILD.bazel

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ package(
99
java_library(
1010
name = "runtime",
1111
exports = [
12+
":async_call",
13+
":async_drain_strategy",
14+
":async_observer",
15+
":async_options",
1216
":descriptor_message_provider",
1317
":evaluation_exception",
1418
":function_overload",
@@ -340,6 +344,11 @@ java_library(
340344
exports = ["//runtime/src/main/java/dev/cel/runtime:function_overload"],
341345
)
342346

347+
cel_android_library(
348+
name = "function_overload_android",
349+
exports = ["//runtime/src/main/java/dev/cel/runtime:function_overload_android"],
350+
)
351+
343352
java_library(
344353
name = "descriptor_message_provider",
345354
visibility = ["//:internal"],
@@ -379,3 +388,43 @@ cel_android_library(
379388
name = "partial_vars_android",
380389
exports = ["//runtime/src/main/java/dev/cel/runtime:partial_vars_android"],
381390
)
391+
392+
java_library(
393+
name = "async_call",
394+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_call"],
395+
)
396+
397+
cel_android_library(
398+
name = "async_call_android",
399+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_call_android"],
400+
)
401+
402+
java_library(
403+
name = "async_drain_strategy",
404+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_drain_strategy"],
405+
)
406+
407+
cel_android_library(
408+
name = "async_drain_strategy_android",
409+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_drain_strategy_android"],
410+
)
411+
412+
java_library(
413+
name = "async_observer",
414+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_observer"],
415+
)
416+
417+
cel_android_library(
418+
name = "async_observer_android",
419+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_observer_android"],
420+
)
421+
422+
java_library(
423+
name = "async_options",
424+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_options"],
425+
)
426+
427+
cel_android_library(
428+
name = "async_options_android",
429+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_options_android"],
430+
)

runtime/src/main/java/dev/cel/runtime/BUILD.bazel

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ cel_android_library(
784784
java_library(
785785
name = "function_overload",
786786
srcs = [
787+
"CelAsyncFunctionOverload.java",
787788
"CelFunctionOverload.java",
788789
"OptimizedFunctionOverload.java",
789790
],
@@ -800,9 +801,12 @@ java_library(
800801
cel_android_library(
801802
name = "function_overload_android",
802803
srcs = [
804+
"CelAsyncFunctionOverload.java",
803805
"CelFunctionOverload.java",
804806
"OptimizedFunctionOverload.java",
805807
],
808+
tags = [
809+
],
806810
deps = [
807811
":evaluation_exception",
808812
":unknown_attributes_android",
@@ -817,6 +821,7 @@ java_library(
817821
tags = [
818822
],
819823
deps = [
824+
":async_options",
820825
":descriptor_type_resolver",
821826
":dispatcher",
822827
":evaluation_exception",
@@ -867,6 +872,7 @@ java_library(
867872
tags = [
868873
],
869874
deps = [
875+
":async_options",
870876
":descriptor_message_provider",
871877
":descriptor_type_resolver",
872878
":dispatcher",
@@ -922,6 +928,7 @@ java_library(
922928
],
923929
deps = [
924930
":activation",
931+
":async_options",
925932
":evaluation_exception",
926933
":evaluation_listener",
927934
":function_binding",
@@ -946,6 +953,7 @@ java_library(
946953
"@maven//:com_google_errorprone_error_prone_annotations",
947954
"@maven//:com_google_guava_guava",
948955
"@maven//:com_google_protobuf_protobuf_java",
956+
"@maven//:org_jspecify_jspecify",
949957
],
950958
)
951959

@@ -1277,17 +1285,134 @@ cel_android_library(
12771285
],
12781286
)
12791287

1288+
java_library(
1289+
name = "async_call",
1290+
srcs = ["CelAsyncCall.java"],
1291+
tags = [
1292+
],
1293+
deps = [
1294+
"@maven//:com_google_code_findbugs_annotations",
1295+
"@maven//:com_google_errorprone_error_prone_annotations",
1296+
"@maven//:com_google_guava_guava",
1297+
],
1298+
)
1299+
1300+
cel_android_library(
1301+
name = "async_call_android",
1302+
srcs = ["CelAsyncCall.java"],
1303+
tags = [
1304+
],
1305+
deps = [
1306+
"@maven//:com_google_code_findbugs_annotations",
1307+
"@maven//:com_google_errorprone_error_prone_annotations",
1308+
"@maven_android//:com_google_guava_guava",
1309+
],
1310+
)
1311+
1312+
java_library(
1313+
name = "async_drain_strategy",
1314+
srcs = [
1315+
"CelAsyncDrainAction.java",
1316+
"CelAsyncDrainStrategy.java",
1317+
],
1318+
tags = [
1319+
],
1320+
deps = [
1321+
":async_call",
1322+
"//:auto_value",
1323+
"@maven//:com_google_errorprone_error_prone_annotations",
1324+
"@maven//:com_google_guava_guava",
1325+
],
1326+
)
1327+
1328+
cel_android_library(
1329+
name = "async_drain_strategy_android",
1330+
srcs = [
1331+
"CelAsyncDrainAction.java",
1332+
"CelAsyncDrainStrategy.java",
1333+
],
1334+
tags = [
1335+
],
1336+
deps = [
1337+
":async_call_android",
1338+
"//:auto_value",
1339+
"@maven//:com_google_errorprone_error_prone_annotations",
1340+
"@maven_android//:com_google_guava_guava",
1341+
],
1342+
)
1343+
1344+
java_library(
1345+
name = "async_observer",
1346+
srcs = ["CelAsyncObserver.java"],
1347+
tags = [
1348+
],
1349+
deps = [
1350+
":async_call",
1351+
"@maven//:com_google_code_findbugs_annotations",
1352+
"@maven//:com_google_errorprone_error_prone_annotations",
1353+
"@maven//:org_jspecify_jspecify",
1354+
],
1355+
)
1356+
1357+
cel_android_library(
1358+
name = "async_observer_android",
1359+
srcs = ["CelAsyncObserver.java"],
1360+
tags = [
1361+
],
1362+
deps = [
1363+
":async_call_android",
1364+
"@maven//:com_google_code_findbugs_annotations",
1365+
"@maven//:com_google_errorprone_error_prone_annotations",
1366+
"@maven//:org_jspecify_jspecify",
1367+
],
1368+
)
1369+
1370+
java_library(
1371+
name = "async_options",
1372+
srcs = ["CelAsyncEvaluationOptions.java"],
1373+
tags = [
1374+
],
1375+
deps = [
1376+
":async_drain_strategy",
1377+
":async_observer",
1378+
"//:auto_value",
1379+
"@maven//:com_google_code_findbugs_annotations",
1380+
"@maven//:com_google_errorprone_error_prone_annotations",
1381+
"@maven//:org_jspecify_jspecify",
1382+
],
1383+
)
1384+
1385+
cel_android_library(
1386+
name = "async_options_android",
1387+
srcs = ["CelAsyncEvaluationOptions.java"],
1388+
tags = [
1389+
],
1390+
deps = [
1391+
":async_drain_strategy_android",
1392+
":async_observer_android",
1393+
"//:auto_value",
1394+
"@maven//:com_google_code_findbugs_annotations",
1395+
"@maven//:com_google_errorprone_error_prone_annotations",
1396+
"@maven//:org_jspecify_jspecify",
1397+
],
1398+
)
1399+
12801400
java_library(
12811401
name = "program",
12821402
srcs = ["Program.java"],
12831403
tags = [
12841404
],
12851405
deps = [
1406+
":activation",
12861407
":evaluation_exception",
12871408
":function_resolver",
1409+
":interpretable",
12881410
":partial_vars",
12891411
":variable_resolver",
1412+
"//common/annotations",
12901413
"@maven//:com_google_errorprone_error_prone_annotations",
1414+
"@maven//:com_google_guava_guava",
1415+
"@maven//:org_jspecify_jspecify",
12911416
],
12921417
)
12931418

@@ -1297,11 +1422,16 @@ cel_android_library(
12971422
tags = [
12981423
],
12991424
deps = [
1425+
":activation_android",
13001426
":evaluation_exception",
13011427
":function_resolver_android",
1428+
":interpretable_android",
13021429
":partial_vars_android",
13031430
":variable_resolver",
1431+
"//common/annotations",
13041432
"@maven//:com_google_errorprone_error_prone_annotations",
1433+
"@maven//:org_jspecify_jspecify",
1434+
"@maven_android//:com_google_guava_guava",
13051435
],
13061436
)
13071437

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2026 Google LLC
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+
// https://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+
15+
package dev.cel.runtime;
16+
17+
import com.google.common.collect.ImmutableList;
18+
import javax.annotation.concurrent.ThreadSafe;
19+
import java.time.Duration;
20+
21+
/** Describes a pending or completed asynchronous function call. */
22+
@ThreadSafe
23+
public interface CelAsyncCall {
24+
25+
/** Returns the unique incremental tracking ID assigned to this call. */
26+
long callId();
27+
28+
/** Returns the AST expression node ID where the call is located. */
29+
long exprId();
30+
31+
/** Returns the name of the function being invoked. */
32+
String functionName();
33+
34+
/** Returns the specific overload ID being invoked. */
35+
String overloadId();
36+
37+
/** Returns the arguments passed to the function call. */
38+
ImmutableList<Object> arguments();
39+
40+
/** Returns the elapsed duration of the async function execution. */
41+
Duration elapsedDuration();
42+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2026 Google LLC
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+
// https://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+
15+
package dev.cel.runtime;
16+
17+
import static com.google.common.base.Preconditions.checkArgument;
18+
import static com.google.common.base.Preconditions.checkNotNull;
19+
20+
import com.google.auto.value.AutoValue;
21+
import com.google.errorprone.annotations.Immutable;
22+
import java.time.Duration;
23+
24+
/** Dictates what asynchronous evaluation should do after inspecting completions. */
25+
@AutoValue
26+
@Immutable
27+
public abstract class CelAsyncDrainAction {
28+
29+
CelAsyncDrainAction() {}
30+
31+
/** Indicates that the AST should be re-evaluated immediately. */
32+
public abstract boolean shouldReevaluate();
33+
34+
/**
35+
* Indicates how long the evaluator should wait for additional completions before deciding to
36+
* re-evaluate. A duration of ZERO with reevaluate=false means wait indefinitely for the next
37+
* completion.
38+
*/
39+
public abstract Duration waitDuration();
40+
41+
public static CelAsyncDrainAction waitDuration(Duration duration) {
42+
checkNotNull(duration);
43+
checkArgument(!duration.isNegative(), "duration must not be negative");
44+
if (duration.isZero()) {
45+
return reevaluate();
46+
}
47+
return new AutoValue_CelAsyncDrainAction(false, duration);
48+
}
49+
50+
public static CelAsyncDrainAction reevaluate() {
51+
return new AutoValue_CelAsyncDrainAction(true, Duration.ZERO);
52+
}
53+
54+
public static CelAsyncDrainAction waitForMore() {
55+
return new AutoValue_CelAsyncDrainAction(false, Duration.ZERO);
56+
}
57+
}

0 commit comments

Comments
 (0)