Skip to content

Commit 17ca921

Browse files
l46kokcopybara-github
authored andcommitted
Remove grouped overloads from CelStandardFunctions
PiperOrigin-RevId: 850118838
1 parent 463bee0 commit 17ca921

File tree

5 files changed

+198
-516
lines changed

5 files changed

+198
-516
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,9 @@ java_library(
828828
"//common/types:cel_types",
829829
"//common/values:cel_value_provider",
830830
"//common/values:proto_message_value_provider",
831+
"//runtime/standard:add",
832+
"//runtime/standard:int",
833+
"//runtime/standard:timestamp",
831834
"@maven//:com_google_code_findbugs_annotations",
832835
"@maven//:com_google_errorprone_error_prone_annotations",
833836
"@maven//:com_google_guava_guava",

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
import dev.cel.common.types.CelTypes;
4444
import dev.cel.common.values.CelValueProvider;
4545
import dev.cel.common.values.ProtoMessageValueProvider;
46-
import dev.cel.runtime.CelStandardFunctions.StandardFunction.Overload.Arithmetic;
47-
import dev.cel.runtime.CelStandardFunctions.StandardFunction.Overload.Comparison;
48-
import dev.cel.runtime.CelStandardFunctions.StandardFunction.Overload.Conversions;
46+
import dev.cel.runtime.standard.AddOperator.AddOverload;
47+
import dev.cel.runtime.standard.IntFunction.IntOverload;
48+
import dev.cel.runtime.standard.TimestampFunction.TimestampOverload;
4949
import java.util.Arrays;
5050
import java.util.HashMap;
5151
import java.util.Optional;
@@ -339,7 +339,7 @@ private ImmutableSet<CelFunctionBinding> newStandardFunctionBindings(
339339
(standardFunction, standardOverload) -> {
340340
switch (standardFunction) {
341341
case INT:
342-
if (standardOverload.equals(Conversions.INT64_TO_INT64)) {
342+
if (standardOverload.equals(IntOverload.INT64_TO_INT64)) {
343343
// Note that we require UnsignedLong flag here to avoid ambiguous
344344
// overloads against "uint64_to_int64", because they both use the same
345345
// Java Long class. We skip adding this identity function if the flag is
@@ -350,26 +350,23 @@ private ImmutableSet<CelFunctionBinding> newStandardFunctionBindings(
350350
case TIMESTAMP:
351351
// TODO: Remove this flag guard once the feature has been
352352
// auto-enabled.
353-
if (standardOverload.equals(Conversions.INT64_TO_TIMESTAMP)) {
353+
if (standardOverload.equals(TimestampOverload.INT64_TO_TIMESTAMP)) {
354354
return options.enableTimestampEpoch();
355355
}
356356
break;
357357
case STRING:
358358
return options.enableStringConversion();
359359
case ADD:
360-
Arithmetic arithmetic = (Arithmetic) standardOverload;
361-
if (arithmetic.equals(Arithmetic.ADD_STRING)) {
360+
if (standardOverload.equals(AddOverload.ADD_STRING)) {
362361
return options.enableStringConcatenation();
363362
}
364-
if (arithmetic.equals(Arithmetic.ADD_LIST)) {
363+
if (standardOverload.equals(AddOverload.ADD_LIST)) {
365364
return options.enableListConcatenation();
366365
}
367366
break;
368367
default:
369-
if (standardOverload instanceof Comparison
370-
&& !options.enableHeterogeneousNumericComparisons()) {
371-
Comparison comparison = (Comparison) standardOverload;
372-
return !comparison.isHeterogeneousComparison();
368+
if (!options.enableHeterogeneousNumericComparisons()) {
369+
return !CelStandardFunctions.isHeterogeneousComparison(standardOverload);
373370
}
374371
break;
375372
}

0 commit comments

Comments
 (0)