Skip to content

Commit 085030c

Browse files
l46kokcopybara-github
authored andcommitted
Split Program into its own interface
PiperOrigin-RevId: 825748112
1 parent c0dbe7e commit 085030c

File tree

8 files changed

+124
-27
lines changed

8 files changed

+124
-27
lines changed

runtime/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,14 @@ cel_android_library(
244244
visibility = ["//:internal"],
245245
exports = ["//runtime/src/main/java/dev/cel/runtime:internal_function_binder_andriod"],
246246
)
247+
248+
java_library(
249+
name = "program",
250+
visibility = ["//:internal"],
251+
exports = ["//runtime/src/main/java/dev/cel/runtime:program"],
252+
)
253+
254+
cel_android_library(
255+
name = "program_android",
256+
exports = ["//runtime/src/main/java/dev/cel/runtime:program_android"],
257+
)

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

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ LITE_RUNTIME_SOURCES = [
4141

4242
# keep sorted
4343
LITE_RUNTIME_IMPL_SOURCES = [
44-
"LiteProgramImpl.java",
4544
"LiteRuntimeImpl.java",
4645
]
4746

47+
# keep sorted
48+
LITE_PROGRAM_IMPL_SOURCES = [
49+
"LiteProgramImpl.java",
50+
]
51+
4852
# keep sorted
4953
FUNCTION_BINDING_SOURCES = [
5054
"CelFunctionBinding.java",
@@ -853,6 +857,7 @@ java_library(
853857
"//common/types:cel_types",
854858
"//common/values:cel_value_provider",
855859
"//common/values:proto_message_value_provider",
860+
"//runtime:program",
856861
"@maven//:com_google_code_findbugs_annotations",
857862
"@maven//:com_google_errorprone_error_prone_annotations",
858863
"@maven//:com_google_guava_guava",
@@ -869,12 +874,12 @@ java_library(
869874
deps = [
870875
":evaluation_exception",
871876
":function_binding",
872-
":function_resolver",
873877
"//:auto_value",
874878
"//common:cel_ast",
875879
"//common:options",
876880
"//common/annotations",
877881
"//common/values:cel_value_provider",
882+
"//runtime:program",
878883
"//runtime/standard:standard_function",
879884
"@maven//:com_google_code_findbugs_annotations",
880885
"@maven//:com_google_errorprone_error_prone_annotations",
@@ -896,6 +901,7 @@ java_library(
896901
":function_resolver",
897902
":interpretable",
898903
":interpreter",
904+
":lite_program_impl",
899905
":lite_runtime",
900906
":runtime_equality",
901907
":runtime_helpers",
@@ -904,13 +910,47 @@ java_library(
904910
"//common:cel_ast",
905911
"//common:options",
906912
"//common/values:cel_value_provider",
913+
"//runtime:program",
907914
"//runtime/standard:standard_function",
908915
"@maven//:com_google_code_findbugs_annotations",
909-
"@maven//:com_google_errorprone_error_prone_annotations",
910916
"@maven//:com_google_guava_guava",
911917
],
912918
)
913919

920+
java_library(
921+
name = "lite_program_impl",
922+
srcs = LITE_PROGRAM_IMPL_SOURCES,
923+
tags = [
924+
],
925+
deps = [
926+
":activation",
927+
":evaluation_exception",
928+
":function_resolver",
929+
":interpretable",
930+
":lite_runtime",
931+
":program",
932+
"//:auto_value",
933+
"@maven//:com_google_errorprone_error_prone_annotations",
934+
],
935+
)
936+
937+
cel_android_library(
938+
name = "lite_program_impl_android",
939+
srcs = LITE_PROGRAM_IMPL_SOURCES,
940+
tags = [
941+
],
942+
deps = [
943+
":activation_android",
944+
":evaluation_exception",
945+
":function_resolver_android",
946+
":interpretable_android",
947+
":lite_runtime_android",
948+
":program_android",
949+
"//:auto_value",
950+
"@maven//:com_google_errorprone_error_prone_annotations",
951+
],
952+
)
953+
914954
cel_android_library(
915955
name = "lite_runtime_impl_android",
916956
srcs = LITE_RUNTIME_IMPL_SOURCES,
@@ -925,7 +965,9 @@ cel_android_library(
925965
":function_resolver_android",
926966
":interpretable_android",
927967
":interpreter_android",
968+
":lite_program_impl_android",
928969
":lite_runtime_android",
970+
":program_android",
929971
":runtime_equality_android",
930972
":runtime_helpers_android",
931973
":type_resolver_android",
@@ -1128,6 +1170,7 @@ cel_android_library(
11281170
":evaluation_exception",
11291171
":function_binding_android",
11301172
":function_resolver_android",
1173+
":program_android",
11311174
"//:auto_value",
11321175
"//common:cel_ast_android",
11331176
"//common:options",
@@ -1195,6 +1238,33 @@ cel_android_library(
11951238
],
11961239
)
11971240

1241+
java_library(
1242+
name = "program",
1243+
srcs = ["Program.java"],
1244+
tags = [
1245+
],
1246+
deps = [
1247+
":evaluation_exception",
1248+
":function_resolver",
1249+
"@maven//:com_google_errorprone_error_prone_annotations",
1250+
],
1251+
)
1252+
1253+
cel_android_library(
1254+
name = "program_android",
1255+
srcs = ["Program.java"],
1256+
tags = [
1257+
],
1258+
deps = [
1259+
":evaluation_exception",
1260+
":function_overload_android",
1261+
":function_resolver_android",
1262+
":resolved_overload_internal_android",
1263+
"//:auto_value",
1264+
"@maven//:com_google_errorprone_error_prone_annotations",
1265+
],
1266+
)
1267+
11981268
java_library(
11991269
name = "internal_function_binder",
12001270
srcs = ["InternalFunctionBinder.java"],

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414

1515
package dev.cel.runtime;
1616

17-
import com.google.errorprone.annotations.Immutable;
1817
import javax.annotation.concurrent.ThreadSafe;
1918
import dev.cel.common.CelAbstractSyntaxTree;
2019
import dev.cel.common.annotations.Beta;
21-
import java.util.Map;
2220

2321
/**
2422
* CelLiteRuntime creates executable {@link Program} instances from {@link CelAbstractSyntaxTree}
@@ -34,22 +32,4 @@ public interface CelLiteRuntime {
3432
Program createProgram(CelAbstractSyntaxTree ast) throws CelEvaluationException;
3533

3634
CelLiteRuntimeBuilder toRuntimeBuilder();
37-
38-
/** Creates an evaluable {@code Program} instance which is thread-safe and immutable. */
39-
@Immutable
40-
interface Program {
41-
42-
/** Evaluate the expression without any variables. */
43-
Object eval() throws CelEvaluationException;
44-
45-
/** Evaluate the expression using a {@code mapValue} as the source of input variables. */
46-
Object eval(Map<String, ?> mapValue) throws CelEvaluationException;
47-
48-
/**
49-
* Evaluate a compiled program with {@code mapValue} and late-bound functions {@code
50-
* lateBoundFunctionResolver}.
51-
*/
52-
Object eval(Map<String, ?> mapValue, CelFunctionResolver lateBoundFunctionResolver)
53-
throws CelEvaluationException;
54-
}
5535
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface CelRuntime {
3737

3838
/** Creates an evaluable {@code Program} instance which is thread-safe and immutable. */
3939
@Immutable
40-
interface Program extends CelLiteRuntime.Program {
40+
interface Program extends dev.cel.runtime.Program {
4141

4242
/** Evaluate the expression using {@code message} fields as the source of input variables. */
4343
Object eval(Message message) throws CelEvaluationException;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
@Immutable
2222
@AutoValue
23-
abstract class LiteProgramImpl implements CelLiteRuntime.Program {
23+
abstract class LiteProgramImpl implements Program {
2424

2525
abstract Interpretable interpretable();
2626

@@ -40,7 +40,7 @@ public Object eval(Map<String, ?> mapValue, CelFunctionResolver lateBoundFunctio
4040
return interpretable().eval(Activation.copyOf(mapValue), lateBoundFunctionResolver);
4141
}
4242

43-
static CelLiteRuntime.Program plan(Interpretable interpretable) {
43+
static Program plan(Interpretable interpretable) {
4444
return new AutoValue_LiteProgramImpl(interpretable);
4545
}
4646
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2025 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.errorprone.annotations.Immutable;
18+
import java.util.Map;
19+
20+
/** Creates an evaluable {@code Program} instance which is thread-safe and immutable. */
21+
@Immutable
22+
public interface Program {
23+
24+
/** Evaluate the expression without any variables. */
25+
Object eval() throws CelEvaluationException;
26+
27+
/** Evaluate the expression using a {@code mapValue} as the source of input variables. */
28+
Object eval(Map<String, ?> mapValue) throws CelEvaluationException;
29+
30+
/**
31+
* Evaluate a compiled program with {@code mapValue} and late-bound functions {@code
32+
* lateBoundFunctionResolver}.
33+
*/
34+
Object eval(Map<String, ?> mapValue, CelFunctionResolver lateBoundFunctionResolver)
35+
throws CelEvaluationException;
36+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ cel_android_local_test(
156156
"//runtime:lite_runtime_impl_android",
157157
"//runtime:standard_functions_android",
158158
"//runtime:unknown_attributes_android",
159+
"//runtime/src/main/java/dev/cel/runtime:program_android",
159160
"//runtime/standard:equals_android",
160161
"//runtime/standard:int_android",
161162
"//testing/protos:test_all_types_cel_java_proto2_lite",

runtime/src/test/java/dev/cel/runtime/CelLiteRuntimeAndroidTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import dev.cel.expr.conformance.proto3.TestAllTypesCelLiteDescriptor;
4848
import dev.cel.extensions.CelLiteExtensions;
4949
import dev.cel.extensions.SetsFunction;
50-
import dev.cel.runtime.CelLiteRuntime.Program;
5150
import dev.cel.runtime.standard.EqualsOperator;
5251
import dev.cel.runtime.standard.IntFunction;
5352
import dev.cel.runtime.standard.IntFunction.IntOverload;

0 commit comments

Comments
 (0)