Skip to content

Commit 3cebc1a

Browse files
l46kokcopybara-github
authored andcommitted
Expose planner based runtimes through experimental factories
PiperOrigin-RevId: 875869202
1 parent 941932c commit 3cebc1a

File tree

11 files changed

+166
-36
lines changed

11 files changed

+166
-36
lines changed

bundle/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ java_library(
1313
],
1414
)
1515

16+
java_library(
17+
name = "cel_experimental_factory",
18+
visibility = ["//:internal"],
19+
exports = [
20+
"//bundle/src/main/java/dev/cel/bundle:cel_experimental_factory",
21+
],
22+
)
23+
1624
java_library(
1725
name = "environment",
1826
exports = ["//bundle/src/main/java/dev/cel/bundle:environment"],

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ java_library(
5757
],
5858
)
5959

60+
java_library(
61+
name = "cel_experimental_factory",
62+
srcs = ["CelExperimentalFactory.java"],
63+
tags = [
64+
],
65+
deps = [
66+
":cel",
67+
":cel_impl",
68+
"//checker",
69+
"//common:options",
70+
"//common/annotations",
71+
"//compiler",
72+
"//parser",
73+
"//runtime:runtime_planner_impl",
74+
],
75+
)
76+
6077
java_library(
6178
name = "cel_impl",
6279
srcs = ["CelImpl.java"],
@@ -73,7 +90,6 @@ java_library(
7390
"//common:compiler_common",
7491
"//common:container",
7592
"//common:options",
76-
"//common/annotations",
7793
"//common/internal:env_visitor",
7894
"//common/internal:file_descriptor_converter",
7995
"//common/types:cel_proto_types",
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.bundle;
16+
17+
import dev.cel.checker.CelCheckerLegacyImpl;
18+
import dev.cel.common.CelOptions;
19+
import dev.cel.common.annotations.Beta;
20+
import dev.cel.compiler.CelCompilerImpl;
21+
import dev.cel.parser.CelParserImpl;
22+
import dev.cel.runtime.CelRuntimeImpl;
23+
24+
/**
25+
* Experimental helper class to configure the entire CEL stack in a common interface, backed by the
26+
* new {@code ProgramPlanner} architecture.
27+
*
28+
* <p>All APIs and behaviors surfaced here are subject to change.
29+
*/
30+
@Beta
31+
public final class CelExperimentalFactory {
32+
33+
/**
34+
* Creates a builder for configuring CEL for the parsing, optional type-checking, and evaluation
35+
* of expressions using the Program Planner.
36+
*
37+
* <p>The {@code ProgramPlanner} architecture provides key benefits over the legacy runtime:
38+
*
39+
* <ul>
40+
* <li><b>Performance:</b> Programs can be cached for improving evaluation speed.
41+
* <li><b>Parsed-only expression evaluation:</b> Unlike the traditional stack which required
42+
* supplying type-checked expressions, this architecture handles both parsed-only and
43+
* type-checked expressions.
44+
* </ul>
45+
*/
46+
public static CelBuilder plannerCelBuilder() {
47+
return CelImpl.newBuilder(
48+
CelCompilerImpl.newBuilder(
49+
CelParserImpl.newBuilder(),
50+
CelCheckerLegacyImpl.newBuilder().setStandardEnvironmentEnabled(true)),
51+
CelRuntimeImpl.newBuilder())
52+
// CEL-Internal-2
53+
.setOptions(
54+
CelOptions.current()
55+
.enableHeterogeneousNumericComparisons(true)
56+
.enableTimestampEpoch(true)
57+
.build());
58+
}
59+
60+
private CelExperimentalFactory() {}
61+
}

bundle/src/main/java/dev/cel/bundle/CelImpl.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import dev.cel.common.CelSource;
3939
import dev.cel.common.CelValidationResult;
4040
import dev.cel.common.CelVarDecl;
41-
import dev.cel.common.annotations.Internal;
4241
import dev.cel.common.internal.EnvVisitable;
4342
import dev.cel.common.internal.EnvVisitor;
4443
import dev.cel.common.internal.FileDescriptorSetConverter;
@@ -65,14 +64,9 @@
6564
* Implementation of the synchronous CEL stack.
6665
*
6766
* <p>Note, the underlying {@link CelCompiler} and {@link CelRuntime} values are constructed lazily.
68-
*
69-
* <p>CEL Library Internals. Do Not Use. Consumers should use {@code CelFactory} instead.
70-
*
71-
* <p>TODO: Restrict visibility once factory is introduced
7267
*/
7368
@Immutable
74-
@Internal
75-
public final class CelImpl implements Cel, EnvVisitable {
69+
final class CelImpl implements Cel, EnvVisitable {
7670

7771
// The lazily constructed compiler and runtime values are memoized and guaranteed to be
7872
// constructed only once without side effects, thus making them effectively immutable.
@@ -151,11 +145,8 @@ static CelImpl combine(CelCompiler compiler, CelRuntime runtime) {
151145
* <p>By default, {@link CelOptions#DEFAULT} are enabled, as is the CEL standard environment.
152146
*
153147
* <p>CEL Library Internals. Do Not Use. Consumers should use {@code CelFactory} instead.
154-
*
155-
* <p>TODO: Restrict visibility once factory is introduced
156148
*/
157-
@Internal
158-
public static CelBuilder newBuilder(
149+
static CelBuilder newBuilder(
159150
CelCompilerBuilder compilerBuilder, CelRuntimeBuilder celRuntimeBuilder) {
160151
return new CelImpl.Builder(compilerBuilder, celRuntimeBuilder);
161152
}

extensions/src/test/java/dev/cel/extensions/BUILD.bazel

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ java_library(
1010
deps = [
1111
"//:java_truth",
1212
"//bundle:cel",
13-
"//bundle:cel_impl",
14-
"//checker",
13+
"//bundle:cel_experimental_factory",
1514
"//common:cel_ast",
1615
"//common:compiler_common",
1716
"//common:container",
@@ -32,15 +31,13 @@ java_library(
3231
"//extensions:sets",
3332
"//extensions:sets_function",
3433
"//extensions:strings",
35-
"//parser",
3634
"//parser:macro",
3735
"//parser:unparser",
3836
"//runtime",
3937
"//runtime:function_binding",
4038
"//runtime:interpreter_util",
4139
"//runtime:lite_runtime",
4240
"//runtime:lite_runtime_factory",
43-
"//runtime:runtime_planner_impl",
4441
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
4542
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
4643
"@cel_spec//proto/cel/expr/conformance/test:simple_java_proto",

extensions/src/test/java/dev/cel/extensions/CelOptionalLibraryTest.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
import com.google.testing.junit.testparameterinjector.TestParameters;
2727
import dev.cel.bundle.Cel;
2828
import dev.cel.bundle.CelBuilder;
29+
import dev.cel.bundle.CelExperimentalFactory;
2930
import dev.cel.bundle.CelFactory;
30-
import dev.cel.bundle.CelImpl;
31-
import dev.cel.checker.CelCheckerLegacyImpl;
3231
import dev.cel.common.CelAbstractSyntaxTree;
3332
import dev.cel.common.CelContainer;
3433
import dev.cel.common.CelFunctionDecl;
@@ -46,16 +45,13 @@
4645
import dev.cel.common.values.CelByteString;
4746
import dev.cel.common.values.NullValue;
4847
import dev.cel.compiler.CelCompiler;
49-
import dev.cel.compiler.CelCompilerImpl;
5048
import dev.cel.expr.conformance.proto3.TestAllTypes;
5149
import dev.cel.expr.conformance.proto3.TestAllTypes.NestedMessage;
5250
import dev.cel.parser.CelMacro;
53-
import dev.cel.parser.CelParserImpl;
5451
import dev.cel.parser.CelStandardMacro;
5552
import dev.cel.runtime.CelEvaluationException;
5653
import dev.cel.runtime.CelFunctionBinding;
5754
import dev.cel.runtime.CelRuntime;
58-
import dev.cel.runtime.CelRuntimeImpl;
5955
import dev.cel.runtime.InterpreterUtil;
6056
import java.time.Duration;
6157
import java.time.Instant;
@@ -106,17 +102,6 @@ private enum ConstantTestCases {
106102
}
107103
}
108104

109-
private static CelBuilder plannerCelBuilder() {
110-
// TODO: Replace with factory once available.
111-
return CelImpl.newBuilder(
112-
CelCompilerImpl.newBuilder(
113-
CelParserImpl.newBuilder(),
114-
CelCheckerLegacyImpl.newBuilder().setStandardEnvironmentEnabled(true)),
115-
CelRuntimeImpl.newBuilder())
116-
// CEL-Internal-2
117-
.setOptions(CelOptions.current().build());
118-
}
119-
120105
private CelBuilder newCelBuilder() {
121106
return newCelBuilder(Integer.MAX_VALUE);
122107
}
@@ -126,7 +111,7 @@ private CelBuilder newCelBuilder(int version) {
126111
switch (testMode) {
127112
case PLANNER_PARSE_ONLY:
128113
case PLANNER_CHECKED:
129-
celBuilder = plannerCelBuilder();
114+
celBuilder = CelExperimentalFactory.plannerCelBuilder();
130115
break;
131116
case LEGACY_CHECKED:
132117
celBuilder = CelFactory.standardCelBuilder();

runtime/BUILD.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ java_library(
2929
],
3030
)
3131

32+
java_library(
33+
name = "runtime_experimental_factory",
34+
visibility = ["//:internal"],
35+
exports = [
36+
"//runtime/src/main/java/dev/cel/runtime:runtime_experimental_factory",
37+
],
38+
)
39+
3240
java_library(
3341
name = "runtime_legacy_impl",
3442
visibility = ["//:internal"],

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,19 @@ java_library(
912912
],
913913
)
914914

915+
java_library(
916+
name = "runtime_experimental_factory",
917+
srcs = ["CelRuntimeExperimentalFactory.java"],
918+
tags = [
919+
],
920+
deps = [
921+
":runtime",
922+
":runtime_planner_impl",
923+
"//common:options",
924+
"//common/annotations",
925+
],
926+
)
927+
915928
java_library(
916929
name = "runtime",
917930
srcs = RUNTIME_SOURCES,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 dev.cel.common.CelOptions;
18+
import dev.cel.common.annotations.Beta;
19+
20+
/**
21+
* Experimental helper class to construct new {@code CelRuntime} instances backed by the new {@code
22+
* ProgramPlanner} architecture.
23+
*
24+
* <p>All APIs and behaviors surfaced here are subject to change.
25+
*/
26+
@Beta
27+
public final class CelRuntimeExperimentalFactory {
28+
29+
/**
30+
* Create a new builder for constructing a {@code CelRuntime} instance.
31+
*
32+
* <p>The {@code ProgramPlanner} architecture provides key benefits over the legacy runtime:
33+
*
34+
* <ul>
35+
* <li><b>Performance:</b> Programs can be cached for improving evaluation speed.
36+
* <li><b>Parsed-only expression evaluation:</b> Unlike the traditional legacy runtime, which
37+
* only supported evaluating type-checked expressions, this architecture handles both
38+
* parsed-only and type-checked expressions.
39+
* </ul>
40+
*/
41+
public static CelRuntimeBuilder plannerRuntimeBuilder() {
42+
return CelRuntimeImpl.newBuilder()
43+
// CEL-Internal-2
44+
.setOptions(
45+
CelOptions.current()
46+
.enableTimestampEpoch(true)
47+
.enableHeterogeneousNumericComparisons(true)
48+
.build());
49+
}
50+
51+
private CelRuntimeExperimentalFactory() {}
52+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ java_library(
138138
"//common/types:type_providers",
139139
"//extensions",
140140
"//runtime",
141-
"//runtime:runtime_planner_impl",
141+
"//runtime:runtime_experimental_factory",
142142
"//testing:base_interpreter_test",
143143
"@maven//:com_google_testparameterinjector_test_parameter_injector",
144144
"@maven//:junit_junit",

0 commit comments

Comments
 (0)