Skip to content

Commit

Permalink
Remove adaptRuntimeTypeValueToNativeType option
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 702815226
  • Loading branch information
l46kok authored and copybara-github committed Dec 9, 2024
1 parent 46aeb6b commit fa370d6
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 48 deletions.
11 changes: 0 additions & 11 deletions common/src/main/java/dev/cel/common/CelOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ public enum ProtoUnsetFieldOptions {

public abstract ProtoUnsetFieldOptions fromProtoUnsetFieldOption();

public abstract boolean adaptRuntimeTypeValueToNativeType();

public abstract boolean enableStringConversion();

public abstract boolean enableStringConcatenation();
Expand Down Expand Up @@ -210,7 +208,6 @@ public static Builder newBuilder() {
.enableCelValue(false)
.comprehensionMaxIterations(-1)
.unwrapWellKnownTypesOnFunctionDispatch(true)
.adaptRuntimeTypeValueToNativeType(true)
.fromProtoUnsetFieldOption(ProtoUnsetFieldOptions.BIND_DEFAULT)
.enableStringConversion(true)
.enableStringConcatenation(true)
Expand Down Expand Up @@ -523,14 +520,6 @@ public abstract static class Builder {
*/
public abstract Builder fromProtoUnsetFieldOption(ProtoUnsetFieldOptions value);

/**
* If enabled, result of the type function call `type(foo)` will be evaluated as a native-type
* equivalent {@code CelType} instead of the protobuf type equivalent from {value.proto}.
*
* <p>This is a temporary flag for migration purposes, and will be removed in the near future.
*/
public abstract Builder adaptRuntimeTypeValueToNativeType(boolean value);

/**
* Enables string() overloads for the runtime. This option exists to maintain parity with
* cel-cpp interpreter options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ public void newValue_createProtoMessage_fieldsPopulated() {
@Test
public void newValue_createProtoMessage_unsignedLongFieldsPopulated() {
ProtoMessageValueProvider protoMessageValueProvider =
ProtoMessageValueProvider.newInstance(
DYNAMIC_PROTO, CelOptions.current().enableUnsignedLongs(true).build());
ProtoMessageValueProvider.newInstance(DYNAMIC_PROTO, CelOptions.current().build());

ProtoMessageValue protoMessageValue =
(ProtoMessageValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class ProtoMessageValueTest {

private static final ProtoCelValueConverter PROTO_CEL_VALUE_CONVERTER =
ProtoCelValueConverter.newInstance(
CelOptions.current().enableUnsignedLongs(true).build(),
CelOptions.current().build(),
DefaultDescriptorPool.INSTANCE,
DynamicProto.create(DefaultMessageFactory.INSTANCE));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ private static TypeRegistry newDefaultTypeRegistry() {
private static final CelOptions OPTIONS =
CelOptions.current()
.enableTimestampEpoch(true)
.enableUnsignedLongs(true)
.adaptRuntimeTypeValueToNativeType(true)
.enableHeterogeneousNumericComparisons(true)
.enableProtoDifferencerEquality(true)
.enableOptionalSyntax(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public void least_unsignedLongResult_withSignedLongType_success(String expr, lon
+ " '3'}")
public void least_unsignedLongResult_withUnsignedLongType_success(
String expr, String expectedResult) throws Exception {
CelOptions celOptions = CelOptions.current().enableUnsignedLongs(true).build();
CelOptions celOptions = CelOptions.current().build();
CelCompiler celCompiler =
CelCompilerFactory.standardCelCompilerBuilder()
.setOptions(celOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ private enum ConstantTestCases {

private static CelBuilder newCelBuilder() {
return CelFactory.standardCelBuilder()
.setOptions(
CelOptions.current()
.enableUnsignedLongs(true)
.enableTimestampEpoch(true)
.adaptRuntimeTypeValueToNativeType(true)
.build())
.setOptions(CelOptions.current().enableTimestampEpoch(true).build())
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.setContainer("cel.expr.conformance.proto3")
.addMessageTypes(TestAllTypes.getDescriptor())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@

@RunWith(TestParameterInjector.class)
public final class CelSetsExtensionsTest {
private static final CelOptions CEL_OPTIONS =
CelOptions.current().enableUnsignedLongs(true).build();
private static final CelOptions CEL_OPTIONS = CelOptions.current().build();
private static final CelCompiler COMPILER =
CelCompilerFactory.standardCelCompilerBuilder()
.addMessageTypes(TestAllTypes.getDescriptor())
Expand Down
1 change: 1 addition & 0 deletions runtime/src/main/java/dev/cel/runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ java_library(
"//common/internal:default_message_factory",
"//common/internal:dynamic_proto",
"//common/internal:proto_message_factory",
"//common/types",
"//common/types:cel_types",
"//common/types:type_providers",
"@cel_spec//proto/cel/expr:expr_java_proto",
Expand Down
19 changes: 5 additions & 14 deletions runtime/src/main/java/dev/cel/runtime/DefaultInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static com.google.common.base.Preconditions.checkNotNull;

import dev.cel.expr.Value;
import com.google.auto.value.AutoValue;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
Expand All @@ -40,6 +39,7 @@
import dev.cel.common.ast.CelReference;
import dev.cel.common.types.CelKind;
import dev.cel.common.types.CelType;
import dev.cel.common.types.TypeType;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -260,10 +260,7 @@ private IntermediateResult resolveIdent(ExecutionFrame frame, CelExpr expr, Stri
// Check whether the type exists in the type check map as a 'type'.
Optional<CelType> checkedType = ast.getType(expr.id());
if (checkedType.isPresent() && checkedType.get().kind() == CelKind.TYPE) {
Object typeValue =
celOptions.adaptRuntimeTypeValueToNativeType()
? CelTypeResolver.adaptType(checkedType.get())
: typeProvider.adaptType(checkedType.get());
TypeType typeValue = CelTypeResolver.adaptType(checkedType.get());
return IntermediateResult.create(typeValue);
}

Expand Down Expand Up @@ -643,15 +640,9 @@ private IntermediateResult evalType(ExecutionFrame frame, CelCall callExpr)
.setLocation(metadata, typeExprArg.id())
.build());

Object typeValue;
if (celOptions.adaptRuntimeTypeValueToNativeType()) {
CelType checkedTypeValue = CelTypeResolver.adaptType(checkedType);
typeValue = CelTypeResolver.resolveObjectType(argResult.value(), checkedTypeValue);
} else {
Value checkedTypeValue = typeProvider.adaptType(checkedType);
typeValue = typeProvider.resolveObjectType(argResult.value(), checkedTypeValue);
}
return IntermediateResult.create(typeValue);
CelType checkedTypeValue = CelTypeResolver.adaptType(checkedType);
return IntermediateResult.create(
CelTypeResolver.resolveObjectType(argResult.value(), checkedTypeValue));
}

private IntermediateResult evalOptionalOr(ExecutionFrame frame, CelCall callExpr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public class CelTypeResolverTest {

private static final Cel CEL =
CelFactory.standardCelBuilder()
.setOptions(
CelOptions.current()
.enableTimestampEpoch(true)
.adaptRuntimeTypeValueToNativeType(true)
.build())
.setOptions(CelOptions.current().enableTimestampEpoch(true).build())
.setTypeProvider(PROTO_MESSAGE_TYPE_PROVIDER)
.addCompilerLibraries(CelOptionalLibrary.INSTANCE)
.addRuntimeLibraries(CelOptionalLibrary.INSTANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ public final class RuntimeEqualityTest {
.enableProtoDifferencerEquality(true)
.build();
private static final CelOptions UNSIGNED_LONGS =
CelOptions.newBuilder().disableCelStandardEquality(false).enableUnsignedLongs(true).build();
CelOptions.newBuilder().disableCelStandardEquality(false).build();
private static final CelOptions PROTO_EQUALITY_UNSIGNED_LONGS =
CelOptions.newBuilder()
.disableCelStandardEquality(false)
.enableProtoDifferencerEquality(true)
.enableUnsignedLongs(true)
.build();

private static final RuntimeEquality RUNTIME_EQUALITY =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ private static CelOptions.Builder newBaseOptions() {

/** Test options to supply for interpreter tests. */
protected enum InterpreterTestOption {
ADAPT_TYPE_VALUE(newBaseOptions().adaptRuntimeTypeValueToNativeType(true).build(), true),
CEL_TYPE(newBaseOptions().build(), true),
PROTO_TYPE(newBaseOptions().build(), false),
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public abstract class CelBaselineTestCase extends BaselineTestCase {
protected static final CelOptions TEST_OPTIONS =
CelOptions.current()
.enableTimestampEpoch(true)
.enableUnsignedLongs(true)
.enableHeterogeneousNumericComparisons(true)
.enableOptionalSyntax(true)
.comprehensionMaxIterations(1_000)
Expand Down

0 comments on commit fa370d6

Please sign in to comment.