Skip to content

Commit

Permalink
Temporarily remove new proto bindings
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 596669466
  • Loading branch information
jcking authored and copybara-github committed Jan 8, 2024
1 parent bc483ec commit bbe9066
Show file tree
Hide file tree
Showing 50 changed files with 1 addition and 20,581 deletions.
117 changes: 0 additions & 117 deletions conformance/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ cc_binary(
testonly = 1,
srcs = [
"server.cc",
"value_conversion.cc",
"value_conversion.h",
],
deps = [
"//base:data",
Expand All @@ -60,7 +58,6 @@ cc_binary(
"//eval/public:cel_options",
"//eval/public:cel_value",
"//eval/public:transform_utility",
"//extensions/protobuf:data",
"//extensions/protobuf:enum_adapter",
"//extensions/protobuf:memory_manager",
"//extensions/protobuf:runtime_adapter",
Expand Down Expand Up @@ -138,112 +135,6 @@ cc_binary(
]
]

[
sh_test(
name = "simple" + "".join([arg.replace("--", "_") for arg in args]),
srcs = ["@com_google_cel_spec//tests:conftest.sh"],
args = [
"$(location @com_google_cel_spec//tests/simple:simple_test)",
"--server=\"$(location :server) " + " ".join(args) + "\"",
"--skip_check",
"--pipe",
"--pipe_pings",

# Tests which require spec changes.
# TODO(issues/93): Deprecate Duration.getMilliseconds.
"--skip_test=timestamps/duration_converters/get_milliseconds",

# Broken test cases which should be supported.
# TODO(issues/112): Unbound functions result in empty eval response.
"--skip_test=basic/functions/unbound",
"--skip_test=basic/functions/unbound_is_runtime_error",

# TODO(issues/97): Parse-only qualified variable lookup "x.y" wtih binding "x.y" or "y" within container "x" fails
"--skip_test=fields/qualified_identifier_resolution/qualified_ident,map_field_select,ident_with_longest_prefix_check,qualified_identifier_resolution_unchecked",
"--skip_test=namespace/qualified/self_eval_qualified_lookup",
"--skip_test=namespace/namespace/self_eval_container_lookup,self_eval_container_lookup_unchecked",
# TODO(issues/117): Integer overflow on enum assignments should error.
"--skip_test=enums/legacy_proto2/select_big,select_neg",

# Skip until fixed.
"--skip_test=wrappers/field_mask/to_json",
"--skip_test=fields/qualified_identifier_resolution/map_value_repeat_key_heterogeneous",

# Future features for CEL 1.0
# TODO(issues/119): Strong typing support for enums, specified but not implemented.
"--skip_test=enums/strong_proto2",
"--skip_test=enums/strong_proto3",

# TODO(uncreated-issue/62): edge cases modern type provider handles differently.
# Nested Any comparsions when unpacking fails.
# Hard to express in pure CEL, maybe need to update conformance.
"--skip_test=comparisons/eq_wrapper/" + ",".join([
"eq_proto2_any_unpack_bytewise_fallback_not_equal",
"eq_proto3_any_unpack_bytewise_fallback_not_equal",
]),
"--skip_test=comparisons/ne_literal/" + ",".join([
"ne_proto2_any_unpack_bytewise_fallback",
"ne_proto3_any_unpack_bytewise_fallback",
]),
# float overflows
"--skip_test=dynamic/float/" + ",".join([
"field_assign_proto2_subnorm",
"field_assign_proto3_subnorm#01",
"field_assign_proto2_round_to_zero",
"field_assign_proto3_round_to_zero",
"field_assign_proto2_range",
"field_assign_proto3_range",
]),
# JSON types
"--skip_test=dynamic/struct/" + ",".join([
"var",
"field_assign_proto2_bad",
"field_read_proto2",
"field_assign_proto3_bad",
"field_read_proto3",
]),
"--skip_test=dynamic/value_struct/" + ",".join([
"var",
"field_read_proto2",
"field_read_proto3",
]),
"--skip_test=dynamic/any/var",
"--skip_test=dynamic/complex/any_list_map",
# Strong vs weak enum typing
"--skip_test=enums/legacy_proto2/" + ",".join([
"select_default",
"select",
"field_type",
]),
"--skip_test=enums/legacy_proto3/" + ",".join([
"select_default",
"select",
"field_type",
"select_big",
"select_neg",
"field_type",
]),
"--skip_test=proto2/literal_singular/float",
"--skip_test=proto3/literal_singular/float",
] + ["$(location " + test + ")" for test in ALL_TESTS],
data = [
":server",
"@com_google_cel_spec//tests/simple:simple_test",
] + ALL_TESTS,
)
for args in [
[
"--modern",
"--arena",
],
[
"--modern",
"--arena",
"--opt",
],
]
]

[
sh_test(
name = "simple_dashboard" + "".join([arg.replace("--", "_") for arg in args]),
Expand All @@ -269,13 +160,5 @@ cc_binary(
)
for args in [
[],
[
"--modern",
"--arena",
],
[
"--modern",
"--noarena",
],
]
]
182 changes: 1 addition & 181 deletions conformance/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,21 @@
#include "absl/status/statusor.h"
#include "absl/strings/escaping.h"
#include "absl/strings/string_view.h"
#include "base/memory.h"
#include "base/value.h"
#include "base/values/error_value.h"
#include "conformance/value_conversion.h"
#include "eval/public/activation.h"
#include "eval/public/builtin_func_registrar.h"
#include "eval/public/cel_expr_builder_factory.h"
#include "eval/public/cel_expression.h"
#include "eval/public/cel_options.h"
#include "eval/public/cel_value.h"
#include "eval/public/transform_utility.h"
#include "extensions/protobuf/enum_adapter.h"
#include "extensions/protobuf/memory_manager.h"
#include "extensions/protobuf/runtime_adapter.h"
#include "extensions/protobuf/type_provider.h"
#include "internal/status_macros.h"
#include "parser/parser.h"
#include "runtime/activation.h"
#include "runtime/constant_folding.h"
#include "runtime/managed_value_factory.h"
#include "runtime/runtime.h"
#include "runtime/runtime_options.h"
#include "runtime/standard_runtime_builder_factory.h"
#include "proto/test/v1/proto2/test_all_types.pb.h"
#include "proto/test/v1/proto3/test_all_types.pb.h"
#include "google/protobuf/arena.h"
#include "google/protobuf/message.h"


using ::cel::CreateStandardRuntimeBuilder;
using ::cel::Handle;
using ::cel::MemoryManager;
using ::cel::Runtime;
using ::cel::RuntimeOptions;
using ::cel::Value;
using ::cel::conformance_internal::FromConformanceValue;
using ::cel::conformance_internal::ToConformanceValue;
using ::cel::extensions::ProtobufRuntimeAdapter;
using ::cel::extensions::ProtoMemoryManager;
using ::cel::extensions::ProtoMemoryManagerRef;
using ::cel::extensions::RegisterProtobufEnum;
using ::google::protobuf::Arena;

ABSL_FLAG(bool, opt, false, "Enable optimizations (constant folding)");
Expand Down Expand Up @@ -246,156 +220,6 @@ class LegacyConformanceServiceImpl : public ConformanceServiceInterface {
std::unique_ptr<CelExpressionBuilder> builder_;
};

class ModernConformanceServiceImpl : public ConformanceServiceInterface {
public:
static absl::StatusOr<std::unique_ptr<ModernConformanceServiceImpl>> Create(
bool optimize, bool use_arena) {
google::protobuf::LinkMessageReflection<
google::api::expr::test::v1::proto3::TestAllTypes>();
google::protobuf::LinkMessageReflection<
google::api::expr::test::v1::proto2::TestAllTypes>();
google::protobuf::LinkMessageReflection<
google::api::expr::test::v1::proto3::NestedTestAllTypes>();
google::protobuf::LinkMessageReflection<
google::api::expr::test::v1::proto2::NestedTestAllTypes>();

RuntimeOptions options;
options.enable_qualified_type_identifiers = true;
options.enable_timestamp_duration_overflow_errors = true;
options.enable_heterogeneous_equality = true;
options.enable_empty_wrapper_null_unboxing = true;

return absl::WrapUnique(
new ModernConformanceServiceImpl(options, use_arena, optimize));
}

absl::StatusOr<std::unique_ptr<const cel::Runtime>> Setup(
absl::string_view container) {
RuntimeOptions options(options_);
options.container = std::string(container);
CEL_ASSIGN_OR_RETURN(auto builder, CreateStandardRuntimeBuilder(options));

if (enable_optimizations_) {
CEL_RETURN_IF_ERROR(cel::extensions::EnableConstantFolding(
builder, constant_memory_manager_));
}

auto& type_registry = builder.type_registry();
// Use linked pbs in the
type_registry.AddTypeProvider(
std::make_unique<cel::extensions::ProtoTypeProvider>());
CEL_RETURN_IF_ERROR(RegisterProtobufEnum(
type_registry,
google::api::expr::test::v1::proto2::GlobalEnum_descriptor()));
CEL_RETURN_IF_ERROR(RegisterProtobufEnum(
type_registry,
google::api::expr::test::v1::proto3::GlobalEnum_descriptor()));
CEL_RETURN_IF_ERROR(RegisterProtobufEnum(
type_registry, google::api::expr::test::v1::proto2::TestAllTypes::
NestedEnum_descriptor()));
CEL_RETURN_IF_ERROR(RegisterProtobufEnum(
type_registry, google::api::expr::test::v1::proto3::TestAllTypes::
NestedEnum_descriptor()));

return std::move(builder).Build();
}

void Parse(const conformance::v1alpha1::ParseRequest& request,
conformance::v1alpha1::ParseResponse& response) override {
LegacyParse(request, response);
}

void Check(const conformance::v1alpha1::CheckRequest& request,
conformance::v1alpha1::CheckResponse& response) override {
auto issue = response.add_issues();
issue->set_message("Check is not supported");
issue->set_code(google::rpc::Code::UNIMPLEMENTED);
}

absl::Status Eval(const conformance::v1alpha1::EvalRequest& request,
conformance::v1alpha1::EvalResponse& response) override {
google::api::expr::v1alpha1::Expr expr = ExtractExpr(request);
google::protobuf::Arena arena;
auto proto_memory_manager = ProtoMemoryManagerRef(&arena);
cel::MemoryManagerRef memory_manager =
(use_arena_ ? proto_memory_manager
: cel::MemoryManagerRef::ReferenceCounting());

auto runtime_status = Setup(request.container());
if (!runtime_status.ok()) {
return absl::InternalError(runtime_status.status().ToString());
}
std::unique_ptr<const cel::Runtime> runtime =
std::move(runtime_status).value();

auto program_status = ProtobufRuntimeAdapter::CreateProgram(*runtime, expr);
if (!program_status.ok()) {
return absl::InternalError(program_status.status().ToString());
}
std::unique_ptr<cel::TraceableProgram> program =
std::move(program_status).value();
cel::ManagedValueFactory value_factory(program->GetTypeProvider(),
memory_manager);
cel::Activation activation;

for (const auto& pair : request.bindings()) {
google::api::expr::v1alpha1::Value import_value;
(import_value).MergeFrom(pair.second.value());
auto import_status =
FromConformanceValue(value_factory.get(), import_value);
if (!import_status.ok()) {
return absl::InternalError(import_status.status().ToString());
}

activation.InsertOrAssignValue(pair.first,
std::move(import_status).value());
}

auto eval_status = program->Evaluate(activation, value_factory.get());
if (!eval_status.ok()) {
*response.mutable_result()
->mutable_error()
->add_errors()
->mutable_message() = eval_status.status().ToString();
return absl::OkStatus();
}

Handle<cel::Value> result = eval_status.value();
if (result->Is<cel::ErrorValue>()) {
const absl::Status& error = result->As<cel::ErrorValue>().NativeValue();
*response.mutable_result()
->mutable_error()
->add_errors()
->mutable_message() = std::string(error.message());
} else {
auto export_status = ToConformanceValue(value_factory.get(), result);
if (!export_status.ok()) {
return absl::InternalError(export_status.status().ToString());
}
auto* result_value = response.mutable_result()->mutable_value();
(*result_value).MergeFrom(*export_status);
}
return absl::OkStatus();
}

private:
explicit ModernConformanceServiceImpl(const RuntimeOptions& options,
bool use_arena,
bool enable_optimizations)
: options_(options),
use_arena_(use_arena),
enable_optimizations_(enable_optimizations),
constant_memory_manager_(
use_arena_ ? ProtoMemoryManagerRef(&constant_arena_)
: cel::MemoryManagerRef::ReferenceCounting()) {}

RuntimeOptions options_;
bool use_arena_;
bool enable_optimizations_;
Arena constant_arena_;
cel::MemoryManagerRef constant_memory_manager_;
};

class PipeCodec {
public:
PipeCodec() = default;
Expand All @@ -420,11 +244,7 @@ class PipeCodec {

int RunServer(bool optimize, bool modern, bool arena) {
absl::StatusOr<std::unique_ptr<ConformanceServiceInterface>> service_or;
if (modern) {
service_or = ModernConformanceServiceImpl::Create(optimize, arena);
} else {
service_or = LegacyConformanceServiceImpl::Create(optimize);
}
service_or = LegacyConformanceServiceImpl::Create(optimize);

if (!service_or.ok()) {
std::cerr << "failed to create conformance service " << service_or.status()
Expand Down
Loading

0 comments on commit bbe9066

Please # to comment.