Skip to content
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
1 change: 1 addition & 0 deletions PLANNER_MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ CelOptions options = CelOptions.current()
// .enableUnsignedLongs(...)
// .unwrapWellKnownTypesOnFunctionDispatch(...)
// .enableTimestampEpoch(...)
// .enableHeterogeneousNumericComparisons(...)
.build();

CelRuntime runtime = CelRuntimeFactory.plannerRuntimeBuilder()
Expand Down
7 changes: 6 additions & 1 deletion bundle/src/main/java/dev/cel/bundle/CelEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ public abstract class CelEnvironment {
"cel.feature.backtick_escape_syntax",
CelOptions.Builder::enableQuotedIdentifierSyntax,
"cel.feature.cross_type_numeric_comparisons",
CelOptions.Builder::enableHeterogeneousNumericComparisons);
// Always enabled (mirroring cel-go); the name is still accepted for existing configs.
(unused, enabled) ->
checkArgument(
enabled,
"cel.feature.cross_type_numeric_comparisons cannot be disabled. Subset the"
+ " standard library instead."));

/** Environment source in textual format (ex: textproto, YAML). */
public abstract Optional<Source> source();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ public CelEnvironment export(CelCompiler cel) {
private void addOptions(CelEnvironment.Builder envBuilder, CelOptions options) {
// The set of features supported in the exported environment in Go is pretty limited right now.
ImmutableSet.Builder<CelEnvironment.FeatureFlag> featureFlags = ImmutableSet.builder();
if (options.enableHeterogeneousNumericComparisons()) {
featureFlags.add(
CelEnvironment.FeatureFlag.create("cel.feature.cross_type_numeric_comparisons", true));
}
if (options.enableQuotedIdentifierSyntax()) {
featureFlags.add(
CelEnvironment.FeatureFlag.create("cel.feature.backtick_escape_syntax", true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
@RunWith(TestParameterInjector.class)
public class CelEnvironmentExporterTest {

private static final CelOptions CEL_OPTIONS =
CelOptions.current().enableHeterogeneousNumericComparisons(true).build();
private static final CelOptions CEL_OPTIONS = CelOptions.DEFAULT;

@Test
public void extensions_latest() {
Expand Down Expand Up @@ -350,7 +349,6 @@ public void options() {
.maxParseRecursionDepth(10)
.maxParseExpressionNodeCount(500)
.enableQuotedIdentifierSyntax(true)
.enableHeterogeneousNumericComparisons(true)
.populateMacroCalls(true)
.build())
.build();
Expand All @@ -360,7 +358,6 @@ public void options() {
assertThat(celEnvironment.features())
.containsExactly(
CelEnvironment.FeatureFlag.create("cel.feature.backtick_escape_syntax", true),
CelEnvironment.FeatureFlag.create("cel.feature.cross_type_numeric_comparisons", true),
CelEnvironment.FeatureFlag.create("cel.feature.macro_call_tracking", true));
assertThat(celEnvironment.limits())
.containsExactly(
Expand Down
18 changes: 16 additions & 2 deletions bundle/src/test/java/dev/cel/bundle/CelEnvironmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
@RunWith(TestParameterInjector.class)
public class CelEnvironmentTest {

private static final CelOptions CEL_OPTIONS =
CelOptions.current().enableHeterogeneousNumericComparisons(true).build();
private static final CelOptions CEL_OPTIONS = CelOptions.DEFAULT;

@Test
public void newBuilder_defaults() {
Expand Down Expand Up @@ -138,6 +137,21 @@ public void extend_allFeatureFlags() throws Exception {
assertThat(result).isTrue();
}

@Test
public void extend_crossTypeNumericComparisonsDisabled_throws() {
CelEnvironment environment =
CelEnvironment.newBuilder()
.setFeatures(
CelEnvironment.FeatureFlag.create(
"cel.feature.cross_type_numeric_comparisons", false))
.build();
Cel cel = CelFactory.plannerCelBuilder().build();

IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, () -> environment.extend(cel, CEL_OPTIONS));
assertThat(e).hasMessageThat().contains("cannot be disabled");
}

@Test
public void extend_allLimits() throws Exception {
CelEnvironment environment =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
@RunWith(TestParameterInjector.class)
public final class CelEnvironmentYamlParserTest {

private static final CelOptions CEL_OPTIONS =
CelOptions.current().enableHeterogeneousNumericComparisons(true).build();
private static final CelOptions CEL_OPTIONS = CelOptions.DEFAULT;

private static final Cel CEL_WITH_MESSAGE_TYPES =
CelFactory.plannerCelBuilder()
Expand Down
15 changes: 0 additions & 15 deletions bundle/src/test/java/dev/cel/bundle/CelImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ public void compile_withOptionalTypes() throws Exception {
CelFactory.plannerCelBuilder()
.setOptions(
CelOptions.current()
.enableHeterogeneousNumericComparisons(true)
.enableOptionalSyntax(true)
.build())
.addVar("a", OptionalType.create(SimpleType.STRING))
Expand Down Expand Up @@ -834,7 +833,6 @@ public void program_deepTypeResolution() throws Exception {
.addFileTypes(CheckedExpr.getDescriptor().getFile())
// In this test 'ParsedExpr' is defined in syntax.proto, while the descriptor provided
// is defined in checked.proto, which imports syntax.proto.
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.setContainer(CelContainer.ofName(packageName))
.setResultType(StructTypeReference.create(packageName + ".ParsedExpr"))
.build();
Expand All @@ -857,7 +855,6 @@ public void program_deepTypeResolutionForRuntime_success() throws Exception {
CelRuntime celRuntime =
CelRuntimeFactory.plannerRuntimeBuilder()
.addFileTypes(CheckedExpr.getDescriptor().getFile())
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
// CEL-Internal-2
.build();
CelRuntime.Program program = celRuntime.createProgram(ast);
Expand Down Expand Up @@ -912,7 +909,6 @@ public void program_enumTypeDirectResolution() throws Exception {
Cel cel =
plannerCelBuilderWithMacros()
.addFileTypes(StandaloneGlobalEnum.getDescriptor().getFile())
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.setContainer(
CelContainer.ofName("dev.cel.testing.testdata.proto3.StandaloneGlobalEnum"))
.setResultType(SimpleType.BOOL)
Expand All @@ -929,7 +925,6 @@ public void program_enumTypeDirectResolution() throws Exception {
public void program_enumTypeReferenceResolution() throws Exception {
Cel cel =
plannerCelBuilderWithMacros()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.addMessageTypes(Struct.getDescriptor())
.setResultType(StructTypeReference.create("google.protobuf.NullValue"))
.setContainer(CelContainer.ofName("google.protobuf"))
Expand All @@ -945,7 +940,6 @@ public void program_enumTypeReferenceResolution() throws Exception {
public void program_enumTypeTransitiveResolution() throws Exception {
Cel cel =
plannerCelBuilderWithMacros()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.addMessageTypes(Proto2ExtensionScopedMessage.getDescriptor())
.setResultType(StructTypeReference.create("google.protobuf.NullValue"))
.setContainer(CelContainer.ofName("google.protobuf"))
Expand Down Expand Up @@ -1079,7 +1073,6 @@ public void setOptions() throws Exception {
plannerCelBuilderWithMacros()
.setOptions(
CelOptions.current()
.enableHeterogeneousNumericComparisons(true)
.retainRepeatedUnaryOperators(true)
.build())
.build();
Expand Down Expand Up @@ -1850,7 +1843,6 @@ public void program_comprehensionDisabled_throws() throws Exception {
plannerCelBuilderWithMacros()
.setOptions(
CelOptions.current()
.enableHeterogeneousNumericComparisons(true)
.enableComprehension(false)
.build())
.build();
Expand All @@ -1868,7 +1860,6 @@ public void program_regexProgramSizeUnderLimit_success() throws Exception {
plannerCelBuilderWithMacros()
.setOptions(
CelOptions.current()
.enableHeterogeneousNumericComparisons(true)
.maxRegexProgramSize(7)
.build())
.build();
Expand All @@ -1885,7 +1876,6 @@ public void program_regexProgramSizeExceedsLimit_throws() throws Exception {
plannerCelBuilderWithMacros()
.setOptions(
CelOptions.current()
.enableHeterogeneousNumericComparisons(true)
.maxRegexProgramSize(6)
.build())
.build();
Expand Down Expand Up @@ -2103,7 +2093,6 @@ public void eval_withJsonFieldName_runtimeOptionDisabled_throws() throws Excepti
.addMessageTypes(SingleFile.getDescriptor())
.setOptions(
CelOptions.current()
.enableHeterogeneousNumericComparisons(true)
.enableJsonFieldNames(true)
.build())
.build();
Expand All @@ -2112,7 +2101,6 @@ public void eval_withJsonFieldName_runtimeOptionDisabled_throws() throws Excepti
.addMessageTypes(SingleFile.getDescriptor())
.setOptions(
CelOptions.current()
.enableHeterogeneousNumericComparisons(true)
.enableJsonFieldNames(false)
.build())
.build();
Expand All @@ -2134,7 +2122,6 @@ public void compile_withJsonFieldName_astTagged() throws Exception {
.addMessageTypes(SingleFile.getDescriptor())
.setOptions(
CelOptions.current()
.enableHeterogeneousNumericComparisons(true)
.enableJsonFieldNames(true)
.build())
.build();
Expand All @@ -2154,7 +2141,6 @@ public void compile_withJsonFieldName_protoFieldNameComparison_throws() throws E
.addMessageTypes(SingleFile.getDescriptor())
.setOptions(
CelOptions.current()
.enableHeterogeneousNumericComparisons(true)
.enableJsonFieldNames(true)
.build())
.build();
Expand Down Expand Up @@ -2213,7 +2199,6 @@ private static Cel setupEnv(CelBuilder celBuilder) {
.setOptions(
CelOptions.current()
.enableJsonFieldNames(true)
.enableHeterogeneousNumericComparisons(true)
.enableQuotedIdentifierSyntax(true)
.build())
.build();
Expand Down
9 changes: 7 additions & 2 deletions common/src/main/java/dev/cel/common/CelOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ public abstract static class Builder {
* Enable the {@code int64_to_timestamp} overload which creates a timestamp from Unix epoch
* seconds.
*
* <p>Historically used to opt-in to this feature, this option is now enabled by default across
* all runtimes.
* <p>This option is enabled by default in {@link CelOptions#current}.
*
* <p>TODO: Remove this feature once it has been auto-enabled.
*
Expand All @@ -327,7 +326,13 @@ public abstract static class Builder {
* <p>This option is enabled by default in {@link CelOptions#current}.
*
* <p>TODO: Remove this feature once it has been auto-enabled.
*
* @deprecated This option is now enabled by default. If you are passing {@code true}, simply
* remove this method call. If you are passing {@code false} to disable this feature, subset
* the environment instead using {@code dev.cel.checker.CelStandardDeclarations} and {@code
* dev.cel.runtime.CelStandardFunctions}.
*/
@Deprecated
public abstract Builder enableHeterogeneousNumericComparisons(boolean value);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public void celTypeTest() {
public void evaluate_typeOfCustomStruct() throws Exception {
Cel cel =
CelFactory.plannerCelBuilder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.addVar("a", CUSTOM_STRUCT_TYPE)
.setTypeProvider(CUSTOM_STRUCT_TYPE_PROVIDER)
.setValueProvider(CUSTOM_STRUCT_VALUE_PROVIDER)
Expand All @@ -148,7 +147,6 @@ public void evaluate_typeOfCustomStruct() throws Exception {
public void evaluate_usingCustomClass_createNewStruct() throws Exception {
Cel cel =
CelFactory.plannerCelBuilder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.setTypeProvider(CUSTOM_STRUCT_TYPE_PROVIDER)
.setValueProvider(CUSTOM_STRUCT_VALUE_PROVIDER)
.build();
Expand All @@ -163,7 +161,6 @@ public void evaluate_usingCustomClass_createNewStruct() throws Exception {
public void evaluate_usingCustomClass_asVariable() throws Exception {
Cel cel =
CelFactory.plannerCelBuilder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.addVar("a", CUSTOM_STRUCT_TYPE)
.setTypeProvider(CUSTOM_STRUCT_TYPE_PROVIDER)
.setValueProvider(CUSTOM_STRUCT_VALUE_PROVIDER)
Expand All @@ -181,7 +178,6 @@ public void evaluate_usingCustomClass_asVariable() throws Exception {
public void evaluate_usingCustomClass_asVariableSelectField() throws Exception {
Cel cel =
CelFactory.plannerCelBuilder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.addVar("a", CUSTOM_STRUCT_TYPE)
.setTypeProvider(CUSTOM_STRUCT_TYPE_PROVIDER)
.setValueProvider(CUSTOM_STRUCT_VALUE_PROVIDER)
Expand All @@ -196,7 +192,6 @@ public void evaluate_usingCustomClass_asVariableSelectField() throws Exception {
public void evaluate_usingCustomClass_selectField() throws Exception {
Cel cel =
CelFactory.plannerCelBuilder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.setTypeProvider(CUSTOM_STRUCT_TYPE_PROVIDER)
.setValueProvider(CUSTOM_STRUCT_VALUE_PROVIDER)
.build();
Expand All @@ -211,7 +206,6 @@ public void evaluate_usingCustomClass_selectField() throws Exception {
public void evaluate_usingMultipleProviders_selectFieldFromCustomClass() throws Exception {
Cel cel =
CelFactory.plannerCelBuilder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.setTypeProvider(CUSTOM_STRUCT_TYPE_PROVIDER)
.setValueProvider(
CombinedCelValueProvider.combine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public final class ConformanceTest extends Statement {

private static final CelOptions OPTIONS =
CelOptions.current()
.enableHeterogeneousNumericComparisons(true)
.enableProtoDifferencerEquality(true)
.enableOptionalSyntax(true)
.enableQuotedIdentifierSyntax(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public final class CelBindingsExtensionsTest extends CelExtensionTestBase {
protected Cel newCelEnv() {
return runtimeFlavor
.builder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.addCompilerLibraries(CelOptionalLibrary.INSTANCE, CelExtensions.bindings())
.addRuntimeLibraries(CelOptionalLibrary.INSTANCE)
Expand Down Expand Up @@ -102,7 +101,6 @@ public void binding_nonCelNamespace_success(String expr) throws Exception {
Cel customCel =
runtimeFlavor
.builder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.addCompilerLibraries(CelExtensions.bindings())
.addFunctionDeclarations(
CelFunctionDecl.newFunctionDeclaration(
Expand Down Expand Up @@ -144,7 +142,6 @@ public void lazyBinding_bindingVarNeverReferenced() throws Exception {
Cel customCel =
runtimeFlavor
.builder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.setStandardMacros(CelStandardMacro.HAS)
.addMessageTypes(TestAllTypes.getDescriptor())
.addVar("msg", StructTypeReference.create(TestAllTypes.getDescriptor().getFullName()))
Expand Down Expand Up @@ -191,7 +188,6 @@ public void lazyBinding_accuInitEvaluatedOnce() throws Exception {
Cel customCel =
runtimeFlavor
.builder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.addCompilerLibraries(CelExtensions.bindings())
.addFunctionDeclarations(
CelFunctionDecl.newFunctionDeclaration(
Expand Down Expand Up @@ -221,7 +217,6 @@ public void lazyBinding_withNestedBinds() throws Exception {
Cel customCel =
runtimeFlavor
.builder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.addCompilerLibraries(CelExtensions.bindings())
.addFunctionDeclarations(
CelFunctionDecl.newFunctionDeclaration(
Expand Down Expand Up @@ -255,7 +250,6 @@ public void lazyBinding_boundAttributeInComprehension() throws Exception {
Cel customCel =
runtimeFlavor
.builder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.setStandardMacros(CelStandardMacro.MAP)
.addCompilerLibraries(CelExtensions.bindings())
.addFunctionDeclarations(
Expand Down Expand Up @@ -288,7 +282,6 @@ public void lazyBinding_boundAttributeInNestedComprehension() throws Exception {
Cel customCel =
runtimeFlavor
.builder()
.setOptions(CelOptions.current().enableHeterogeneousNumericComparisons(true).build())
.setStandardMacros(CelStandardMacro.EXISTS)
.addCompilerLibraries(CelExtensions.bindings())
.addFunctionDeclarations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public class CelComprehensionsExtensionsTest extends CelExtensionTestBase {

private static final CelOptions CEL_OPTIONS =
CelOptions.current()
.enableHeterogeneousNumericComparisons(true)
// Enable macro call population for unparsing
.populateMacroCalls(true)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@

@RunWith(TestParameterInjector.class)
public class CelEncoderExtensionsTest extends CelExtensionTestBase {
private static final CelOptions CEL_OPTIONS =
CelOptions.current().enableHeterogeneousNumericComparisons(true).build();
private static final CelOptions CEL_OPTIONS = CelOptions.DEFAULT;

@Override
protected Cel newCelEnv() {
Expand Down Expand Up @@ -275,7 +274,8 @@ public void encoders_deprecatedNoArg() throws Exception {
}

@Test
@SuppressWarnings("deprecation") // Test only - verifying deprecated evaluateCanonicalTypesToNativeValues option
@SuppressWarnings(
"deprecation") // Test only - verifying deprecated evaluateCanonicalTypesToNativeValues option
public void encoders_evaluateCanonicalTypesToNativeValuesDisabled_producesAndConsumesByteString()
throws Exception {
CelOptions options = CelOptions.current().evaluateCanonicalTypesToNativeValues(false).build();
Expand Down
Loading
Loading