Skip to content

Commit f4c6978

Browse files
l46kokcopybara-github
authored andcommitted
Promote planner runtime builders to the main factories
PiperOrigin-RevId: 904040881
1 parent 61a01d8 commit f4c6978

59 files changed

Lines changed: 1058 additions & 451 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bundle/BUILD.bazel

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ 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-
2416
java_library(
2517
name = "environment",
2618
exports = ["//bundle/src/main/java/dev/cel/bundle:environment"],

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ java_library(
3535
"@cel_spec//proto/cel/expr:checked_java_proto",
3636
"@maven//:com_google_code_findbugs_annotations",
3737
"@maven//:com_google_errorprone_error_prone_annotations",
38-
"@maven//:com_google_guava_guava",
3938
"@maven//:com_google_protobuf_protobuf_java",
4039
],
4140
)
@@ -54,22 +53,6 @@ java_library(
5453
"//compiler:compiler_builder",
5554
"//parser",
5655
"//runtime",
57-
],
58-
)
59-
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",
7356
"//runtime:runtime_planner_impl",
7457
],
7558
)
@@ -117,7 +100,6 @@ java_library(
117100
tags = [
118101
],
119102
deps = [
120-
":cel_factory",
121103
":environment_exception",
122104
":required_fields_checker",
123105
"//:auto_value",
@@ -190,7 +172,6 @@ java_library(
190172
"//common:options",
191173
"//common/internal:env_visitor",
192174
"//common/types:cel_proto_types",
193-
"//common/types:cel_types",
194175
"//common/types:type_providers",
195176
"//compiler:compiler_builder",
196177
"//extensions",

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ public interface CelBuilder {
165165
@CanIgnoreReturnValue
166166
CelBuilder addFunctionBindings(Iterable<CelFunctionBinding> bindings);
167167

168+
/** Adds bindings for functions that are allowed to be late-bound (resolved at execution time). */
169+
@CanIgnoreReturnValue
170+
CelBuilder addLateBoundFunctions(String... lateBoundFunctionNames);
171+
172+
/** Adds bindings for functions that are allowed to be late-bound (resolved at execution time). */
173+
@CanIgnoreReturnValue
174+
CelBuilder addLateBoundFunctions(Iterable<String> lateBoundFunctionNames);
175+
168176
/** Set the expected {@code resultType} for the type-checked expression. */
169177
@CanIgnoreReturnValue
170178
CelBuilder setResultType(CelType resultType);

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

Lines changed: 0 additions & 57 deletions
This file was deleted.

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import dev.cel.compiler.CelCompilerImpl;
2121
import dev.cel.parser.CelParserImpl;
2222
import dev.cel.runtime.CelRuntime;
23+
import dev.cel.runtime.CelRuntimeImpl;
2324
import dev.cel.runtime.CelRuntimeLegacyImpl;
2425

2526
/** Helper class to configure the entire CEL stack in a common interface. */
@@ -44,6 +45,30 @@ public static CelBuilder standardCelBuilder() {
4445
.setStandardEnvironmentEnabled(true);
4546
}
4647

48+
/**
49+
* Creates a builder for configuring CEL for the parsing, optional type-checking, and evaluation
50+
* of expressions using the Program Planner.
51+
*
52+
* <p>The {@code ProgramPlanner} architecture provides key benefits over the {@link
53+
* #standardCelBuilder()}:
54+
*
55+
* <ul>
56+
* <li><b>Performance:</b> Programs can be cached for improving evaluation speed.
57+
* <li><b>Parsed-only expression evaluation:</b> Unlike the traditional stack which required
58+
* supplying type-checked expressions, this architecture handles both parsed-only and
59+
* type-checked expressions.
60+
* </ul>
61+
*/
62+
public static CelBuilder plannerCelBuilder() {
63+
return CelImpl.newBuilder(
64+
CelCompilerImpl.newBuilder(
65+
CelParserImpl.newBuilder(),
66+
CelCheckerLegacyImpl.newBuilder().setStandardEnvironmentEnabled(true)),
67+
CelRuntimeImpl.newBuilder())
68+
// CEL-Internal-2
69+
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build());
70+
}
71+
4772
/** Combines a prebuilt {@link CelCompiler} and {@link CelRuntime} into {@link Cel}. */
4873
public static Cel combine(CelCompiler celCompiler, CelRuntime celRuntime) {
4974
return CelImpl.combine(celCompiler, celRuntime);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,18 @@ public CelBuilder addFunctionBindings(Iterable<dev.cel.runtime.CelFunctionBindin
281281
return this;
282282
}
283283

284+
@Override
285+
public CelBuilder addLateBoundFunctions(String... lateBoundFunctionNames) {
286+
runtimeBuilder.addLateBoundFunctions(lateBoundFunctionNames);
287+
return this;
288+
}
289+
290+
@Override
291+
public CelBuilder addLateBoundFunctions(Iterable<String> lateBoundFunctionNames) {
292+
runtimeBuilder.addLateBoundFunctions(lateBoundFunctionNames);
293+
return this;
294+
}
295+
284296
@Override
285297
public CelBuilder setResultType(CelType resultType) {
286298
checkNotNull(resultType);

common/src/main/java/dev/cel/common/values/CelValueConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected Object normalizePrimitive(Object value) {
117117
}
118118

119119
/** Adapts a {@link CelValue} to a plain old Java Object. */
120-
private static Object unwrap(CelValue celValue) {
120+
private Object unwrap(CelValue celValue) {
121121
Preconditions.checkNotNull(celValue);
122122

123123
if (celValue instanceof OptionalValue) {
@@ -126,7 +126,7 @@ private static Object unwrap(CelValue celValue) {
126126
return Optional.empty();
127127
}
128128

129-
return Optional.of(optionalValue.value());
129+
return Optional.of(maybeUnwrap(optionalValue.value()));
130130
}
131131

132132
if (celValue instanceof ErrorValue) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ java_library(
122122
":extension_library",
123123
"//checker:checker_builder",
124124
"//common:compiler_common",
125-
"//common:options",
126125
"//common/ast",
127126
"//common/exceptions:numeric_overflow",
128127
"//common/internal:comparison_functions",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ java_library(
1010
deps = [
1111
"//:java_truth",
1212
"//bundle:cel",
13-
"//bundle:cel_experimental_factory",
1413
"//common:cel_ast",
1514
"//common:cel_exception",
1615
"//common:compiler_common",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
* planner runtime, along with parsed-only and checked expression evaluations for the planner.
3030
*/
3131
abstract class CelExtensionTestBase {
32-
@TestParameter public CelRuntimeFlavor runtimeFlavor;
33-
@TestParameter public boolean isParseOnly;
32+
@TestParameter CelRuntimeFlavor runtimeFlavor;
33+
@TestParameter boolean isParseOnly;
3434

3535
@Before
3636
public void setUpBase() {

0 commit comments

Comments
 (0)