Skip to content

Commit 3b7f706

Browse files
Merge pull request #120 from google/cpp-sync
Latest sync from google3
2 parents bb03a5f + f3b9b46 commit 3b7f706

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1938
-813
lines changed

common/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ cc_test(
196196
"//internal:types",
197197
"//internal:value_internal",
198198
"//testutil:util",
199+
"@com_google_absl//absl/meta:type_traits",
199200
"@com_google_absl//absl/strings",
200201
"@com_google_googleapis//google/rpc:status_cc_proto",
201202
"@com_google_googleapis//google/type:money_cc_proto",
@@ -218,6 +219,7 @@ cc_library(
218219
"//internal:list_impl",
219220
"//internal:map_impl",
220221
"//internal:types",
222+
"@com_google_absl//absl/meta:type_traits",
221223
],
222224
)
223225

common/converters.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <memory>
77

8+
#include "absl/meta/type_traits.h"
89
#include "common/parent_ref.h"
910
#include "common/value.h"
1011
#include "internal/list_impl.h"
@@ -53,7 +54,7 @@ template <Value::Kind ValueKind, typename T>
5354
Value ValueFromList(T&& value) {
5455
static_assert(!std::is_pointer<T>::value, "use ValueForList");
5556
return Value::MakeList<
56-
internal::ListWrapper<ValueKind, internal::remove_cvref_t<T>>>(
57+
internal::ListWrapper<ValueKind, absl::remove_cvref_t<T>>>(
5758
std::forward<T>(value));
5859
}
5960

@@ -92,7 +93,7 @@ template <Value::Kind KeyKind, Value::Kind ValueKind, typename T>
9293
Value ValueFromMap(T&& value) {
9394
static_assert(!std::is_pointer<T>::value, "use ValueForList");
9495
return Value::MakeMap<
95-
internal::MapWrapper<KeyKind, ValueKind, internal::remove_cvref_t<T>>>(
96+
internal::MapWrapper<KeyKind, ValueKind, absl::remove_cvref_t<T>>>(
9697
std::forward<T>(value));
9798
}
9899

common/escaping.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ inline std::tuple<std::string, absl::string_view, std::string> unescape_char(
241241
}
242242

243243
if (value < 0x80 || !encode) {
244-
char tmp[2] = {(char)value, '\0'};
244+
char tmp[2] = {static_cast<char>(value), '\0'};
245245
return std::make_tuple(std::string(tmp), s, "");
246246
} else {
247247
char tmp[5];
@@ -294,7 +294,7 @@ absl::optional<std::string> unescape(const std::string& s, bool is_bytes) {
294294
}
295295
value = value.substr(1, n - 2);
296296
// If there is nothing to escape, then return.
297-
if (is_raw_literal || (value.find('\\') == std::string::npos)) {
297+
if (is_raw_literal || (!absl::StrContains(value, '\\'))) {
298298
return value;
299299
}
300300

common/value.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ namespace api {
2020
namespace expr {
2121
namespace common {
2222

23-
using ::google::api::expr::internal::NotFoundError;
24-
2523
namespace {
2624

2725
static constexpr const Value::Kind kIndexToKind[] = {

common/value_test.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "google/type/money.pb.h"
1111
#include "gmock/gmock.h"
1212
#include "gtest/gtest.h"
13+
#include "absl/meta/type_traits.h"
1314
#include "absl/strings/str_cat.h"
1415
#include "common/custom_object.h"
1516
#include "internal/status_util.h"
@@ -709,15 +710,15 @@ class ValueVisitTest : public ::testing::Test {
709710
710711
template <typename H>
711712
void TestGetPtrVisitor() {
712-
using T = remove_reference_t<decltype(*inst_of<H&>())>;
713+
using T = absl::remove_reference_t<decltype(*inst_of<H&>())>;
713714
ExpectSameType<const T*, GetPtrVisitorType<H, T>>();
714715
// Return by const ref.
715716
ExpectSameType<const T&, GetVisitorType<H, const T&, T>>();
716717
}
717718
718719
template <typename H, typename U>
719720
void TestGetVisitor() {
720-
using T = remove_reference_t<decltype(*inst_of<H&>())>;
721+
using T = absl::remove_reference_t<decltype(*inst_of<H&>())>;
721722
// Return by optional.
722723
ExpectSameType<absl::optional<U>,
723724
GetVisitorType<H, absl::optional<U>, T>>();
@@ -727,7 +728,7 @@ class ValueVisitTest : public ::testing::Test {
727728
728729
template <typename H>
729730
void TestValueAdapter() {
730-
using T = remove_reference_t<decltype(*inst_of<H&>())>;
731+
using T = absl::remove_reference_t<decltype(*inst_of<H&>())>;
731732
ExpectSameType<T&, ValueAdapterType<H&>>();
732733
ExpectSameType<const T&, ValueAdapterType<const H&>>();
733734
}

conformance/BUILD

Lines changed: 43 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ALL_TESTS = [
1818
"@com_google_cel_spec//tests/simple:testdata/logic.textproto",
1919
"@com_google_cel_spec//tests/simple:testdata/macros.textproto",
2020
"@com_google_cel_spec//tests/simple:testdata/namespace.textproto",
21+
"@com_google_cel_spec//tests/simple:testdata/parse.textproto",
2122
"@com_google_cel_spec//tests/simple:testdata/plumbing.textproto",
2223
"@com_google_cel_spec//tests/simple:testdata/proto2.textproto",
2324
"@com_google_cel_spec//tests/simple:testdata/proto3.textproto",
@@ -26,27 +27,6 @@ ALL_TESTS = [
2627
"@com_google_cel_spec//tests/simple:testdata/unknowns.textproto",
2728
]
2829

29-
DASHBOARD_TESTS = [
30-
"@com_google_cel_spec//tests/simple:testdata/basic.textproto",
31-
"@com_google_cel_spec//tests/simple:testdata/comparisons.textproto",
32-
"@com_google_cel_spec//tests/simple:testdata/conversions.textproto",
33-
"@com_google_cel_spec//tests/simple:testdata/dynamic.textproto",
34-
"@com_google_cel_spec//tests/simple:testdata/enums.textproto",
35-
"@com_google_cel_spec//tests/simple:testdata/fields.textproto",
36-
"@com_google_cel_spec//tests/simple:testdata/fp_math.textproto",
37-
"@com_google_cel_spec//tests/simple:testdata/integer_math.textproto",
38-
"@com_google_cel_spec//tests/simple:testdata/lists.textproto",
39-
"@com_google_cel_spec//tests/simple:testdata/logic.textproto",
40-
"@com_google_cel_spec//tests/simple:testdata/macros.textproto",
41-
"@com_google_cel_spec//tests/simple:testdata/namespace.textproto",
42-
"@com_google_cel_spec//tests/simple:testdata/proto2.textproto",
43-
"@com_google_cel_spec//tests/simple:testdata/proto3.textproto",
44-
"@com_google_cel_spec//tests/simple:testdata/plumbing.textproto",
45-
"@com_google_cel_spec//tests/simple:testdata/string.textproto",
46-
"@com_google_cel_spec//tests/simple:testdata/timestamps.textproto",
47-
"@com_google_cel_spec//tests/simple:testdata/unknowns.textproto",
48-
]
49-
5030
cc_binary(
5131
name = "server",
5232
testonly = 1,
@@ -81,71 +61,54 @@ cc_binary(
8161
"--server=\"$(location :server) " + arg + "\"",
8262
"--skip_check",
8363
"--pipe",
84-
# TODO(issues/93): Inconsistent Duration.getMilliseconds() behavior.
64+
65+
# Tests which require spec changes.
66+
# TODO(issues/93): Deprecate Duration.getMilliseconds.
8567
"--skip_test=timestamps/duration_converters/get_milliseconds",
86-
# TODO(issues/94): Missing timestamp conversion functions (type / string)
87-
"--skip_test=timestamps/timestamp_conversions/toType_timestamp,toString_timestamp",
88-
"--skip_test=timestamps/duration_conversions/toType_duration,toString_duration",
8968
# TODO(issues/81): Conversion functions for int(), uint() which can be
9069
# uncommented when the spec changes to truncation rather than rounding.
9170
"--skip_test=conversions/int/double_nearest,double_nearest_neg,double_half_away_neg,double_half_away_pos",
9271
"--skip_test=conversions/uint/double_nearest,double_nearest_int,double_half_away",
93-
# TODO(issues/96): Well-known type conversion support.
94-
"--skip_test=proto2/literal_wellknown",
95-
"--skip_test=proto3/literal_wellknown",
96-
"--skip_test=proto2/empty_field/wkt",
97-
"--skip_test=proto3/empty_field/wkt",
98-
# Requires container support
99-
"--skip_test=namespace/namespace/self_eval_container_lookup_unchecked",
72+
# TODO(issues/110): Tune parse limits to mirror those for proto deserialization and C++ safety limits.
73+
"--skip_test=parse/nest/list_index,message_literal,funcall,list_literal,map_literal;repeat/conditional,add_sub,mul_div,select,index,map_literal,message_literal",
74+
75+
# Broken test cases which should be supported.
76+
# TODO(issues/111): Byte literal decoding of invalid UTF-8 results in incorrect bytes output.
10077
"--skip_test=basic/self_eval_nonzeroish/self_eval_bytes_invalid_utf8",
101-
# Requires heteregenous equality spec clarification
102-
"--skip_test=comparisons/in_list_literal/elem_in_mixed_type_list_error",
103-
"--skip_test=comparisons/in_map_literal/key_in_mixed_key_type_map_error",
104-
"--skip_test=fields/in/singleton",
105-
# Requires qualified bindings error message relaxation
106-
"--skip_test=fields/qualified_identifier_resolution/qualified_identifier_resolution_unchecked",
107-
"--skip_test=string/size/one_unicode,unicode",
10878
"--skip_test=string/bytes_concat/left_unit",
109-
# TODO(issues/85): The exists one macro should not short-circuit false.
110-
"--skip_test=macros/exists_one/list_no_shortcircuit",
111-
# TODO(issues/86): Map macro may produce incorrect results on error.
112-
"--skip_test=macros/map/list_error",
113-
# TODO(issues/97): Parse-only qualified variable lookup "x.y" wtih binding "x.y" or "y" within container "x" fails
114-
"--skip_test=namespace/qualified/self_eval_qualified_lookup",
115-
"--skip_test=namespace/namespace/self_eval_container_lookup",
116-
"--skip_test=fields/qualified_identifier_resolution/qualified_ident",
117-
"--skip_test=fields/qualified_identifier_resolution/map_field_select",
118-
"--skip_test=fields/qualified_identifier_resolution/ident_with_longest_prefix_check",
119-
# New conformance tests awaiting synchronization.
79+
# TODO(issues/112): Unbound functions result in empty eval response.
12080
"--skip_test=basic/functions/unbound",
12181
"--skip_test=basic/functions/unbound_is_runtime_error",
82+
# TODO(issues/113): Aggregate values must logically AND element equality results.
12283
"--skip_test=comparisons/eq_literal/not_eq_list_false_vs_types",
12384
"--skip_test=comparisons/eq_literal/not_eq_map_false_vs_types",
124-
"--skip_test=dynamic/int32",
125-
"--skip_test=dynamic/int64",
126-
"--skip_test=dynamic/uint32",
127-
"--skip_test=dynamic/uint64",
128-
"--skip_test=dynamic/float",
129-
"--skip_test=dynamic/double",
130-
"--skip_test=dynamic/string",
131-
"--skip_test=dynamic/bytes",
132-
"--skip_test=dynamic/bool",
133-
"--skip_test=dynamic/list",
134-
"--skip_test=dynamic/struct",
135-
"--skip_test=dynamic/value_null",
136-
"--skip_test=dynamic/value_number",
137-
"--skip_test=dynamic/value_string",
138-
"--skip_test=dynamic/value_bool",
139-
"--skip_test=dynamic/value_struct",
140-
"--skip_test=dynamic/value_list",
141-
"--skip_test=dynamic/any",
142-
"--skip_test=dynamic/complex",
143-
"--skip_test=enums/legacy_proto2",
144-
"--skip_test=enums/legacy_proto3",
85+
# TODO(issues/114): Ensure the 'in' operator is a logical OR of element equality results.
86+
"--skip_test=comparisons/in_list_literal/elem_in_mixed_type_list_error",
87+
"--skip_test=comparisons/in_map_literal/key_in_mixed_key_type_map_error",
88+
# TODO(issues/115): The 'in' operator fails with maps containing boolean keys.
89+
"--skip_test=fields/in/singleton",
90+
# TODO(issues/97): Parse-only qualified variable lookup "x.y" wtih binding "x.y" or "y" within container "x" fails
91+
"--skip_test=fields/qualified_identifier_resolution/qualified_ident,map_field_select,ident_with_longest_prefix_check,qualified_identifier_resolution_unchecked",
92+
"--skip_test=namespace/qualified/self_eval_qualified_lookup",
93+
"--skip_test=namespace/namespace/self_eval_container_lookup,self_eval_container_lookup_unchecked",
94+
# TODO(issues/116): Debug why dynamic/list/var fails to JSON parse correctly.
95+
"--skip_test=dynamic/list/var",
96+
# TODO(issues/109): Ensure that unset wrapper fields return 'null' rather than the default value of the wrapper.
97+
"--skip_test=dynamic/int32/field_read_proto2_unset,field_read_proto3_unset;uint32/field_read_proto2_unset;uint64/field_read_proto2_unset;float/field_read_proto2_unset,field_read_proto3_unset;double/field_read_proto2_unset,field_read_proto3_unset",
98+
"--skip_test=proto2/empty_field/wkt",
99+
"--skip_test=proto3/empty_field/wkt",
100+
# TODO(issues/117): Integer overflow on enum assignments should error.
101+
"--skip_test=enums/legacy_proto2/select_big,select_neg,assign_standalone_int_too_big,assign_standalone_int_too_neg",
102+
"--skip_test=enums/legacy_proto3/assign_standalone_int_too_big,assign_standalone_int_too_neg",
103+
# TODO(issues/118): Duration and timestamp range errors should result in evaluation errors.
104+
"--skip_test=timestamps/timestamp_range",
105+
106+
# Future features for CEL 1.0
107+
# TODO(issues/119): Strong typing support for enums, specified but not implemented.
145108
"--skip_test=enums/strong_proto2",
146109
"--skip_test=enums/strong_proto3",
147-
"--skip_test=timestamps/timestamp_range",
148-
"--skip_test=timestamps/duration_range",
110+
# Bad tests, temporarily disable.
111+
"--skip_test=dynamic/float/field_assign_proto2_range,field_assign_proto3_range",
149112
] + ["$(location " + test + ")" for test in ALL_TESTS],
150113
data = [
151114
":server",
@@ -165,12 +128,17 @@ sh_test(
165128
"$(location @com_google_cel_spec//tests/simple:simple_test)",
166129
"--server=$(location :server)",
167130
"--skip_check",
131+
# TODO(issues/116): Debug why dynamic/list/var fails to JSON parse correctly.
132+
"--skip_test=dynamic/list/var",
133+
# TODO(issues/119): Strong typing support for enums, specified but not implemented.
134+
"--skip_test=enums/strong_proto2",
135+
"--skip_test=enums/strong_proto3",
168136
"--pipe",
169-
] + ["$(location " + test + ")" for test in DASHBOARD_TESTS],
137+
] + ["$(location " + test + ")" for test in ALL_TESTS],
170138
data = [
171139
":server",
172140
"@com_google_cel_spec//tests/simple:simple_test",
173-
] + DASHBOARD_TESTS,
141+
] + ALL_TESTS,
174142
visibility = [
175143
"//:__subpackages__",
176144
"//third_party/cel:__pkg__",

conformance/server.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#include <iostream>
2-
1+
#include "google/api/expr/v1alpha1/conformance_service.pb.h"
32
#include "google/api/expr/v1alpha1/syntax.pb.h"
43
#include "google/api/expr/v1alpha1/checked.pb.h"
5-
#include "google/api/expr/v1alpha1/conformance_service.pb.h"
64
#include "google/api/expr/v1alpha1/eval.pb.h"
75
#include "google/api/expr/v1alpha1/syntax.pb.h"
86
#include "google/api/expr/v1alpha1/value.pb.h"
@@ -151,6 +149,7 @@ int RunServer(bool optimize) {
151149
google::protobuf::Arena arena;
152150
InterpreterOptions options;
153151
options.enable_qualified_type_identifiers = true;
152+
options.enable_string_size_as_unicode_codepoints = true;
154153

155154
if (optimize) {
156155
std::cerr << "Enabling optimizations" << std::endl;
@@ -169,7 +168,8 @@ int RunServer(bool optimize) {
169168
NestedEnum_descriptor());
170169
type_registry->Register(google::api::expr::test::v1::proto3::TestAllTypes::
171170
NestedEnum_descriptor());
172-
auto register_status = RegisterBuiltinFunctions(builder->GetRegistry());
171+
auto register_status =
172+
RegisterBuiltinFunctions(builder->GetRegistry(), options);
173173
if (!register_status.ok()) {
174174
std::cerr << "Failed to initialize: " << register_status.ToString()
175175
<< std::endl;
@@ -181,7 +181,7 @@ int RunServer(bool optimize) {
181181
// Implementation of a simple pipe protocol:
182182
// INPUT LINE 1: parse/check/eval
183183
// INPUT LINE 2: JSON of the corresponding request protobuf
184-
// OUTPUT LINE 1: JSON of the coressponding response protobuf
184+
// OUTPUT LINE 1: JSON of the corresponding response protobuf
185185
while (true) {
186186
std::string cmd, input, output;
187187
std::getline(std::cin, cmd);

eval/eval/BUILD

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,10 @@ cc_library(
173173
deps = [
174174
":evaluator_core",
175175
":expression_step_base",
176-
"//eval/public:activation",
177-
"//eval/public:cel_value",
178176
"//eval/public/containers:container_backed_list_impl",
177+
"@com_google_absl//absl/status",
179178
"@com_google_absl//absl/status:statusor",
180-
"@com_google_absl//absl/strings",
181179
"@com_google_absl//absl/types:span",
182-
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto",
183180
],
184181
)
185182

eval/eval/attribute_utility_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace runtime {
1515

1616
using google::api::expr::v1alpha1::Expr;
1717
using testing::Eq;
18-
using testing::IsNull;
1918
using testing::NotNull;
2019
using testing::SizeIs;
2120
using testing::UnorderedPointwise;

eval/eval/comprehension_step.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ absl::Status ComprehensionFinish::Evaluate(ExecutionFrame* frame) const {
209209

210210
class ListKeysStep : public ExpressionStepBase {
211211
public:
212-
ListKeysStep(int64_t expr_id) : ExpressionStepBase(expr_id, false) {}
212+
explicit ListKeysStep(int64_t expr_id) : ExpressionStepBase(expr_id, false) {}
213213
absl::Status Evaluate(ExecutionFrame* frame) const override;
214214

215215
private:

0 commit comments

Comments
 (0)