Skip to content

Switch CelStandardFunctions to use dev.cel.runtime.CelFunctionBinding #592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ java_library(
],
)

java_library(
name = "standard_functions",
exports = [
"//runtime/src/main/java/dev/cel/runtime:standard_functions",
],
)

java_library(
name = "function_binding",
visibility = ["//visibility:public"],
Expand Down
30 changes: 23 additions & 7 deletions runtime/src/main/java/dev/cel/runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ RUNTIME_SOURCES = [
"CelRuntimeFactory.java",
"CelRuntimeLegacyImpl.java",
"CelRuntimeLibrary.java",
"CelStandardFunctions.java",
"CelVariableResolver.java",
"HierarchicalVariableResolver.java",
"UnknownContext.java",
Expand Down Expand Up @@ -247,6 +246,28 @@ java_library(
],
)

java_library(
name = "standard_functions",
srcs = ["CelStandardFunctions.java"],
tags = [
],
deps = [
":function_binding",
":runtime_equality",
":runtime_helpers",
"//common:error_codes",
"//common:options",
"//common:runtime_exception",
"//common/annotations",
"//common/internal:comparison_functions",
"//common/internal:safe_string_formatter",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
],
)

java_library(
name = "function_binding",
srcs = [
Expand Down Expand Up @@ -310,29 +331,24 @@ java_library(
":interpreter",
":proto_message_runtime_equality",
":runtime_equality",
":runtime_helpers",
":runtime_type_provider_legacy",
":unknown_attributes",
"//:auto_value",
"//common",
"//common:error_codes",
"//common:options",
"//common:runtime_exception",
"//common/annotations",
"//common/internal:cel_descriptor_pools",
"//common/internal:comparison_functions",
"//common/internal:default_message_factory",
"//common/internal:dynamic_proto",
"//common/internal:proto_message_factory",
"//common/internal:safe_string_formatter",
"//common/types:cel_types",
"//common/values:cel_value_provider",
"//common/values:proto_message_value_provider",
"//runtime:standard_functions",
"@maven//:com_google_code_findbugs_annotations",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:com_google_protobuf_protobuf_java_util",
"@maven//:org_jspecify_jspecify",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ public CelRuntimeLegacyImpl build() {
DynamicProto dynamicProto = DynamicProto.create(runtimeTypeFactory);
RuntimeEquality runtimeEquality = ProtoMessageRuntimeEquality.create(dynamicProto, options);

ImmutableMap.Builder<String, CelFunctionBinding> functionBindingsBuilder =
ImmutableMap.Builder<String, dev.cel.runtime.CelFunctionBinding> functionBindingsBuilder =
ImmutableMap.builder();
for (CelFunctionBinding standardFunctionBinding :
for (dev.cel.runtime.CelFunctionBinding standardFunctionBinding :
newStandardFunctionBindings(runtimeEquality)) {
functionBindingsBuilder.put(
standardFunctionBinding.getOverloadId(), standardFunctionBinding);
Expand All @@ -257,7 +257,7 @@ public CelRuntimeLegacyImpl build() {
functionBindingsBuilder
.buildOrThrow()
.forEach(
(String overloadId, CelFunctionBinding func) ->
(String overloadId, dev.cel.runtime.CelFunctionBinding func) ->
dispatcher.add(
overloadId, func.getArgTypes(), (args) -> func.getDefinition().apply(args)));

Expand Down Expand Up @@ -288,7 +288,7 @@ public CelRuntimeLegacyImpl build() {
this);
}

private ImmutableSet<CelFunctionBinding> newStandardFunctionBindings(
private ImmutableSet<dev.cel.runtime.CelFunctionBinding> newStandardFunctionBindings(
RuntimeEquality runtimeEquality) {
CelStandardFunctions celStandardFunctions;
if (standardEnvironmentEnabled) {
Expand Down Expand Up @@ -381,6 +381,7 @@ private Builder(Builder builder) {
this.extensionRegistry = builder.extensionRegistry;
this.customTypeFactory = builder.customTypeFactory;
this.standardEnvironmentEnabled = builder.standardEnvironmentEnabled;
this.overriddenStandardFunctions = builder.overriddenStandardFunctions;
this.celValueProvider = builder.celValueProvider;
// The following needs to be deep copied as they are collection builders
this.fileTypes = deepCopy(builder.fileTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import dev.cel.common.annotations.Internal;
import dev.cel.common.internal.ComparisonFunctions;
import dev.cel.common.internal.SafeStringFormatter;
import dev.cel.runtime.CelRuntime.CelFunctionBinding;
import dev.cel.runtime.CelStandardFunctions.StandardFunction.Overload.Arithmetic;
import dev.cel.runtime.CelStandardFunctions.StandardFunction.Overload.BooleanOperator;
import dev.cel.runtime.CelStandardFunctions.StandardFunction.Overload.Comparison;
Expand Down Expand Up @@ -1939,6 +1938,7 @@ public CelStandardFunctions build() {
* Functional interface for filtering standard functions. Returning true in the callback will
* include the function in the environment.
*/
@SuppressWarnings("AndroidJdkLibsChecker") // FunctionalInterface added in 24
@FunctionalInterface
public interface FunctionFilter {
boolean include(StandardFunction standardFunction, StandardOverload standardOverload);
Expand All @@ -1961,6 +1961,7 @@ private FunctionBindingHelper(CelOptions celOptions, RuntimeEquality runtimeEqua
}
}

@SuppressWarnings("AndroidJdkLibsChecker") // FunctionalInterface added in 24
@FunctionalInterface
@Immutable
private interface FunctionBindingCreator {
Expand Down
1 change: 1 addition & 0 deletions runtime/src/test/java/dev/cel/runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ java_library(
"//runtime:proto_message_runtime_helpers",
"//runtime:runtime_equality",
"//runtime:runtime_helpers",
"//runtime:standard_functions",
"//runtime:type_resolver",
"//runtime:unknown_attributes",
"//runtime:unknown_options",
Expand Down