Skip to content

Commit 39cc995

Browse files
l46kokcopybara-github
authored andcommitted
Async eval
PiperOrigin-RevId: 974283267
1 parent a2353b3 commit 39cc995

30 files changed

Lines changed: 2978 additions & 32 deletions

runtime/BUILD.bazel

Lines changed: 44 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",
@@ -379,3 +383,43 @@ cel_android_library(
379383
name = "partial_vars_android",
380384
exports = ["//runtime/src/main/java/dev/cel/runtime:partial_vars_android"],
381385
)
386+
387+
java_library(
388+
name = "async_call",
389+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_call"],
390+
)
391+
392+
cel_android_library(
393+
name = "async_call_android",
394+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_call_android"],
395+
)
396+
397+
java_library(
398+
name = "async_drain_strategy",
399+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_drain_strategy"],
400+
)
401+
402+
cel_android_library(
403+
name = "async_drain_strategy_android",
404+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_drain_strategy_android"],
405+
)
406+
407+
java_library(
408+
name = "async_observer",
409+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_observer"],
410+
)
411+
412+
cel_android_library(
413+
name = "async_observer_android",
414+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_observer_android"],
415+
)
416+
417+
java_library(
418+
name = "async_options",
419+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_options"],
420+
)
421+
422+
cel_android_library(
423+
name = "async_options_android",
424+
exports = ["//runtime/src/main/java/dev/cel/runtime:async_options_android"],
425+
)

runtime/src/main/java/dev/cel/runtime/AccumulatedUnknowns.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public final class AccumulatedUnknowns {
3535
private static final int MAX_UNKNOWN_ATTRIBUTE_SIZE = 500_000;
3636
private final Set<Long> exprIds;
3737
private final Set<CelAttribute> attributes;
38+
private final Set<Long> callIds;
3839

3940
Set<Long> exprIds() {
4041
return exprIds;
@@ -44,6 +45,14 @@ Set<CelAttribute> attributes() {
4445
return attributes;
4546
}
4647

48+
public Set<Long> callIds() {
49+
return callIds;
50+
}
51+
52+
public boolean hasCallIds() {
53+
return !callIds.isEmpty();
54+
}
55+
4756
/**
4857
* Evaluates if the right hand side is an accumulated unknown, and if so, merges it into the
4958
* accumulator.
@@ -62,6 +71,7 @@ public AccumulatedUnknowns merge(AccumulatedUnknowns arg) {
6271
enforceMaxAttributeSize(this.attributes, arg.attributes);
6372
this.exprIds.addAll(arg.exprIds);
6473
this.attributes.addAll(arg.attributes);
74+
this.callIds.addAll(arg.callIds);
6575
return this;
6676
}
6777

@@ -73,9 +83,16 @@ static AccumulatedUnknowns create(Collection<Long> ids) {
7383
return create(ids, new ArrayList<>());
7484
}
7585

86+
public static AccumulatedUnknowns createForAsyncCall(long callId) {
87+
HashSet<Long> callIds = new HashSet<>();
88+
callIds.add(callId);
89+
return new AccumulatedUnknowns(new HashSet<>(), new HashSet<>(), callIds);
90+
}
91+
7692
public static AccumulatedUnknowns create(
7793
Collection<Long> exprIds, Collection<CelAttribute> attributes) {
78-
return new AccumulatedUnknowns(new HashSet<>(exprIds), new HashSet<>(attributes));
94+
return new AccumulatedUnknowns(
95+
new HashSet<>(exprIds), new HashSet<>(attributes), new HashSet<>());
7996
}
8097

8198
private static void enforceMaxAttributeSize(
@@ -89,7 +106,12 @@ private static void enforceMaxAttributeSize(
89106
}
90107

91108
private AccumulatedUnknowns(Set<Long> exprIds, Set<CelAttribute> attributes) {
109+
this(exprIds, attributes, new HashSet<>());
110+
}
111+
112+
private AccumulatedUnknowns(Set<Long> exprIds, Set<CelAttribute> attributes, Set<Long> callIds) {
92113
this.exprIds = exprIds;
93114
this.attributes = attributes;
115+
this.callIds = callIds;
94116
}
95117
}

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

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ cel_android_library(
752752
":function_overload_android",
753753
"//common/annotations",
754754
"//common/exceptions:overload_not_found",
755+
"//third_party/java/android_libs/guava_jdk5:concurrent",
755756
"@maven//:com_google_errorprone_error_prone_annotations",
756757
"@maven_android//:com_google_guava_guava",
757758
],
@@ -784,6 +785,7 @@ cel_android_library(
784785
java_library(
785786
name = "function_overload",
786787
srcs = [
788+
"CelAsyncFunctionOverload.java",
787789
"CelFunctionOverload.java",
788790
"OptimizedFunctionOverload.java",
789791
],
@@ -800,12 +802,14 @@ java_library(
800802
cel_android_library(
801803
name = "function_overload_android",
802804
srcs = [
805+
"CelAsyncFunctionOverload.java",
803806
"CelFunctionOverload.java",
804807
"OptimizedFunctionOverload.java",
805808
],
806809
deps = [
807810
":evaluation_exception",
808811
":unknown_attributes_android",
812+
"//third_party/java/android_libs/guava_jdk5:concurrent",
809813
"@maven//:com_google_errorprone_error_prone_annotations",
810814
"@maven_android//:com_google_guava_guava",
811815
],
@@ -817,6 +821,7 @@ java_library(
817821
tags = [
818822
],
819823
deps = [
824+
":async_options",
820825
":descriptor_type_resolver",
821826
":dispatcher",
822827
":evaluation_exception",
@@ -922,6 +927,7 @@ java_library(
922927
],
923928
deps = [
924929
":activation",
930+
":async_options",
925931
":evaluation_exception",
926932
":evaluation_listener",
927933
":function_binding",
@@ -946,6 +952,7 @@ java_library(
946952
"@maven//:com_google_errorprone_error_prone_annotations",
947953
"@maven//:com_google_guava_guava",
948954
"@maven//:com_google_protobuf_protobuf_java",
955+
"@maven//:org_jspecify_jspecify",
949956
],
950957
)
951958

@@ -1277,17 +1284,118 @@ cel_android_library(
12771284
],
12781285
)
12791286

1287+
java_library(
1288+
name = "async_call",
1289+
srcs = ["CelAsyncCall.java"],
1290+
tags = [
1291+
],
1292+
)
1293+
1294+
cel_android_library(
1295+
name = "async_call_android",
1296+
srcs = ["CelAsyncCall.java"],
1297+
tags = [
1298+
],
1299+
)
1300+
1301+
java_library(
1302+
name = "async_drain_strategy",
1303+
srcs = [
1304+
"CelAsyncDrainAction.java",
1305+
"CelAsyncDrainStrategy.java",
1306+
],
1307+
tags = [
1308+
],
1309+
deps = [
1310+
":async_call",
1311+
"//:auto_value",
1312+
"@maven//:com_google_errorprone_error_prone_annotations",
1313+
],
1314+
)
1315+
1316+
cel_android_library(
1317+
name = "async_drain_strategy_android",
1318+
srcs = [
1319+
"CelAsyncDrainAction.java",
1320+
"CelAsyncDrainStrategy.java",
1321+
],
1322+
tags = [
1323+
],
1324+
deps = [
1325+
":async_call_android",
1326+
"//:auto_value",
1327+
"@maven//:com_google_errorprone_error_prone_annotations",
1328+
],
1329+
)
1330+
1331+
java_library(
1332+
name = "async_observer",
1333+
srcs = ["CelAsyncObserver.java"],
1334+
tags = [
1335+
],
1336+
deps = [
1337+
":async_call",
1338+
"@maven//:com_google_errorprone_error_prone_annotations",
1339+
"@maven//:org_jspecify_jspecify",
1340+
],
1341+
)
1342+
1343+
cel_android_library(
1344+
name = "async_observer_android",
1345+
srcs = ["CelAsyncObserver.java"],
1346+
tags = [
1347+
],
1348+
deps = [
1349+
":async_call_android",
1350+
"@maven//:com_google_errorprone_error_prone_annotations",
1351+
"@maven//:org_jspecify_jspecify",
1352+
],
1353+
)
1354+
1355+
java_library(
1356+
name = "async_options",
1357+
srcs = ["CelAsyncEvaluationOptions.java"],
1358+
tags = [
1359+
],
1360+
deps = [
1361+
":async_drain_strategy",
1362+
":async_observer",
1363+
"//:auto_value",
1364+
"@maven//:com_google_errorprone_error_prone_annotations",
1365+
"@maven//:org_jspecify_jspecify",
1366+
],
1367+
)
1368+
1369+
cel_android_library(
1370+
name = "async_options_android",
1371+
srcs = ["CelAsyncEvaluationOptions.java"],
1372+
tags = [
1373+
],
1374+
deps = [
1375+
":async_drain_strategy_android",
1376+
":async_observer_android",
1377+
"//:auto_value",
1378+
"@maven//:com_google_errorprone_error_prone_annotations",
1379+
"@maven//:org_jspecify_jspecify",
1380+
],
1381+
)
1382+
12801383
java_library(
12811384
name = "program",
12821385
srcs = ["Program.java"],
12831386
tags = [
12841387
],
12851388
deps = [
1389+
":activation",
1390+
":async_options",
12861391
":evaluation_exception",
12871392
":function_resolver",
1393+
":interpretable",
12881394
":partial_vars",
12891395
":variable_resolver",
12901396
"@maven//:com_google_errorprone_error_prone_annotations",
1397+
"@maven//:com_google_guava_guava",
1398+
"@maven//:org_jspecify_jspecify",
12911399
],
12921400
)
12931401

@@ -1297,11 +1405,16 @@ cel_android_library(
12971405
tags = [
12981406
],
12991407
deps = [
1408+
":activation_android",
1409+
":async_options_android",
13001410
":evaluation_exception",
13011411
":function_resolver_android",
1412+
":interpretable_android",
13021413
":partial_vars_android",
13031414
":variable_resolver",
1415+
"//third_party/java/android_libs/guava_jdk5:concurrent",
13041416
"@maven//:com_google_errorprone_error_prone_annotations",
1417+
"@maven//:org_jspecify_jspecify",
13051418
],
13061419
)
13071420

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 java.time.Duration;
18+
19+
/** Describes a pending or completed asynchronous function call. */
20+
public interface CelAsyncCall {
21+
22+
/** Returns the unique incremental tracking ID assigned to this call. */
23+
long callId();
24+
25+
/** Returns the AST expression node ID where the call is located. */
26+
long exprId();
27+
28+
/** Returns the name of the function being invoked. */
29+
String functionName();
30+
31+
/** Returns the specific overload ID being invoked. */
32+
String overloadId();
33+
34+
/** Returns the arguments passed to the function call. */
35+
Object[] arguments();
36+
37+
/** Returns the elapsed duration of the async function execution. */
38+
Duration elapsedDuration();
39+
}

0 commit comments

Comments
 (0)