Skip to content

Commit bebd2dd

Browse files
jnthntatumcopybara-github
authored andcommitted
Mock default enabling recursive planning for identifying compatibility issues.
Do not merge. PiperOrigin-RevId: 623213699
1 parent ea6e21c commit bebd2dd

File tree

82 files changed

+6518
-946
lines changed

Some content is hidden

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

82 files changed

+6518
-946
lines changed

common/value.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,12 @@ bool Value::IsZeroValue() const {
270270
}
271271

272272
std::ostream& operator<<(std::ostream& out, const Value& value) {
273-
value.AssertIsValid();
274273
return absl::visit(
275274
[&out](const auto& alternative) -> std::ostream& {
276275
if constexpr (std::is_same_v<
277276
absl::remove_cvref_t<decltype(alternative)>,
278277
absl::monostate>) {
279-
// In optimized builds, we do nothing. In debug builds we cannot
280-
// reach here.
281-
return out;
278+
return out << "default ctor Value";
282279
} else {
283280
return out << alternative;
284281
}
@@ -513,15 +510,12 @@ bool ValueView::IsZeroValue() const {
513510
}
514511

515512
std::ostream& operator<<(std::ostream& out, ValueView value) {
516-
value.AssertIsValid();
517513
return absl::visit(
518514
[&out](auto alternative) -> std::ostream& {
519515
if constexpr (std::is_same_v<
520516
absl::remove_cvref_t<decltype(alternative)>,
521517
absl::monostate>) {
522-
// In optimized builds, we do nothing. In debug builds we cannot
523-
// reach here.
524-
return out;
518+
return out << "default ctor ValueView";
525519
} else {
526520
return out << alternative;
527521
}

common/value.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class Value final {
8484
: variant_((other.AssertIsValid(), other.variant_)) {}
8585

8686
Value& operator=(const Value& other) {
87+
if (this == std::addressof(other)) {
88+
return *this;
89+
}
8790
other.AssertIsValid();
8891
ABSL_DCHECK(this != std::addressof(other))
8992
<< "Value should not be copied to itself";

common/value_test.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ TEST(Value, GetTypeName) {
4444
EXPECT_DEBUG_DEATH(static_cast<void>(moved_from_value.GetTypeName()), _);
4545
}
4646

47-
TEST(Value, DebugStringDebugDeath) {
47+
TEST(Value, DebugStringUinitializedValue) {
4848
Value moved_from_value = BoolValue(true);
4949
Value value = std::move(moved_from_value);
5050
IS_INITIALIZED(moved_from_value);
5151
static_cast<void>(value);
5252
std::ostringstream out;
53-
EXPECT_DEBUG_DEATH(static_cast<void>(out << moved_from_value), _);
53+
out << moved_from_value;
54+
EXPECT_EQ(out.str(), "default ctor Value");
5455
}
5556

5657
TEST(Value, NativeValueIdDebugDeath) {

common/value_testing.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828

2929
namespace cel {
3030

31-
void PrintTo(const Value& value, std::ostream* os) {
32-
*os << value.DebugString() << "\n";
33-
}
31+
void PrintTo(const Value& value, std::ostream* os) { *os << value << "\n"; }
3432

3533
namespace test {
3634
namespace {

conformance/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ cc_binary(
167167
for args in [
168168
[],
169169
["--opt"],
170+
["--recursive"],
170171
]
171172
]
172173

@@ -236,6 +237,11 @@ cc_binary(
236237
"--arena",
237238
"--opt",
238239
],
240+
[
241+
"--modern",
242+
"--arena",
243+
"--recursive",
244+
],
239245
]
240246
]
241247

conformance/server.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ ABSL_FLAG(
7878
ABSL_FLAG(bool, arena, false,
7979
"Use arena memory manager (default: global heap ref-counted). Only "
8080
"affects the modern implementation");
81+
ABSL_FLAG(bool, recursive, false,
82+
"Enable recursive plans. Depth limited to slightly more than the "
83+
"default nesting limit.");
8184

8285
namespace google::api::expr::runtime {
8386

@@ -163,6 +166,10 @@ class LegacyConformanceServiceImpl : public ConformanceServiceInterface {
163166
options.constant_arena = constant_arena;
164167
}
165168

169+
if (absl::GetFlag(FLAGS_recursive)) {
170+
options.max_recursion_depth = 48;
171+
}
172+
166173
std::unique_ptr<CelExpressionBuilder> builder =
167174
CreateCelExpressionBuilder(options);
168175
auto type_registry = builder->GetTypeRegistry();
@@ -284,6 +291,9 @@ class ModernConformanceServiceImpl : public ConformanceServiceInterface {
284291
options.enable_timestamp_duration_overflow_errors = true;
285292
options.enable_heterogeneous_equality = true;
286293
options.enable_empty_wrapper_null_unboxing = true;
294+
if (absl::GetFlag(FLAGS_recursive)) {
295+
options.max_recursion_depth = 48;
296+
}
287297

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

eval/compiler/BUILD

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ cc_library(
2828
"//base:ast",
2929
"//base/ast_internal:ast_impl",
3030
"//base/ast_internal:expr",
31+
"//common:native_type",
3132
"//common:value",
33+
"//eval/eval:direct_expression_step",
3234
"//eval/eval:evaluator_core",
35+
"//eval/eval:trace_step",
36+
"//internal:casts",
3337
"//runtime:runtime_options",
3438
"//runtime/internal:issue_collector",
3539
"@com_google_absl//absl/algorithm:container",
@@ -40,6 +44,7 @@ cc_library(
4044
"@com_google_absl//absl/memory",
4145
"@com_google_absl//absl/status",
4246
"@com_google_absl//absl/status:statusor",
47+
"@com_google_absl//absl/types:optional",
4348
"@com_google_absl//absl/types:variant",
4449
],
4550
)
@@ -51,10 +56,14 @@ cc_test(
5156
":flat_expr_builder_extensions",
5257
":resolver",
5358
"//base/ast_internal:expr",
59+
"//common:casting",
5460
"//common:memory",
61+
"//common:native_type",
5562
"//common:value",
5663
"//eval/eval:const_value_step",
64+
"//eval/eval:direct_expression_step",
5765
"//eval/eval:evaluator_core",
66+
"//eval/eval:function_step",
5867
"//internal:status_macros",
5968
"//internal:testing",
6069
"//runtime:function_registry",
@@ -83,13 +92,16 @@ cc_library(
8392
"//base/ast_internal:ast_impl",
8493
"//base/ast_internal:expr",
8594
"//common:memory",
95+
"//common:type",
8696
"//common:value",
97+
"//eval/eval:attribute_trail",
8798
"//eval/eval:comprehension_step",
8899
"//eval/eval:const_value_step",
89100
"//eval/eval:container_access_step",
90101
"//eval/eval:create_list_step",
91102
"//eval/eval:create_map_step",
92103
"//eval/eval:create_struct_step",
104+
"//eval/eval:direct_expression_step",
93105
"//eval/eval:evaluator_core",
94106
"//eval/eval:function_step",
95107
"//eval/eval:ident_step",
@@ -99,6 +111,7 @@ cc_library(
99111
"//eval/eval:select_step",
100112
"//eval/eval:shadowable_value_step",
101113
"//eval/eval:ternary_step",
114+
"//eval/eval:trace_step",
102115
"//eval/public:ast_traverse_native",
103116
"//eval/public:ast_visitor_native",
104117
"//eval/public:cel_type_registry",
@@ -108,6 +121,7 @@ cc_library(
108121
"//runtime:runtime_issue",
109122
"//runtime:runtime_options",
110123
"//runtime:type_registry",
124+
"//runtime/internal:convert_constant",
111125
"//runtime/internal:issue_collector",
112126
"@com_google_absl//absl/algorithm:container",
113127
"@com_google_absl//absl/base:core_headers",
@@ -119,6 +133,7 @@ cc_library(
119133
"@com_google_absl//absl/status",
120134
"@com_google_absl//absl/status:statusor",
121135
"@com_google_absl//absl/strings",
136+
"@com_google_absl//absl/types:optional",
122137
"@com_google_absl//absl/types:span",
123138
"@com_google_absl//absl/types:variant",
124139
],
@@ -201,6 +216,7 @@ cc_test(
201216
"//internal:status_macros",
202217
"//internal:testing",
203218
"//parser",
219+
"//runtime",
204220
"//runtime:runtime_options",
205221
"@com_google_absl//absl/status",
206222
"@com_google_absl//absl/strings",
@@ -220,7 +236,9 @@ cc_library(
220236
deps = [
221237
":flat_expr_builder",
222238
"//base:ast",
239+
"//common:native_type",
223240
"//eval/eval:cel_expression_flat_impl",
241+
"//eval/eval:direct_expression_step",
224242
"//eval/eval:evaluator_core",
225243
"//eval/public:cel_expression",
226244
"//extensions/protobuf:ast_converters",
@@ -243,15 +261,32 @@ cc_test(
243261
],
244262
deps = [
245263
":cel_expression_builder_flat_impl",
264+
":constant_folding",
265+
":regex_precompilation_optimization",
266+
"//eval/eval:cel_expression_flat_impl",
246267
"//eval/public:activation",
247268
"//eval/public:builtin_func_registrar",
269+
"//eval/public:cel_expression",
270+
"//eval/public:cel_function",
271+
"//eval/public:cel_value",
272+
"//eval/public:portable_cel_function_adapter",
273+
"//eval/public/containers:container_backed_map_impl",
274+
"//eval/public/structs:cel_proto_wrapper",
275+
"//eval/public/structs:protobuf_descriptor_type_provider",
248276
"//eval/public/testing:matchers",
277+
"//extensions:bindings_ext",
278+
"//extensions/protobuf:memory_manager",
279+
"//internal:status_macros",
249280
"//internal:testing",
250281
"//parser",
282+
"//parser:macro",
251283
"//runtime:runtime_options",
284+
"@com_google_absl//absl/algorithm:container",
252285
"@com_google_absl//absl/status",
286+
"@com_google_cel_spec//proto/test/v1/proto3:test_all_types_cc_proto",
253287
"@com_google_googleapis//google/api/expr/v1alpha1:checked_cc_proto",
254288
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto",
289+
"@com_google_protobuf//:protobuf",
255290
],
256291
)
257292

@@ -274,6 +309,7 @@ cc_library(
274309
"//common:memory",
275310
"//common:value",
276311
"//eval/eval:const_value_step",
312+
"//eval/eval:direct_expression_step",
277313
"//eval/eval:evaluator_core",
278314
"//internal:status_macros",
279315
"//runtime:activation",
@@ -462,14 +498,17 @@ cc_library(
462498
"//common:native_type",
463499
"//common:value",
464500
"//eval/eval:compiler_constant_step",
501+
"//eval/eval:direct_expression_step",
465502
"//eval/eval:evaluator_core",
466503
"//eval/eval:regex_match_step",
467504
"//internal:casts",
468505
"//internal:status_macros",
506+
"@com_google_absl//absl/base:nullability",
469507
"@com_google_absl//absl/container:flat_hash_map",
470508
"@com_google_absl//absl/status",
471509
"@com_google_absl//absl/strings",
472510
"@com_google_absl//absl/types:optional",
511+
"@com_googlesource_code_re2//:re2",
473512
],
474513
)
475514

@@ -485,16 +524,18 @@ cc_test(
485524
"//base/ast_internal:ast_impl",
486525
"//base/ast_internal:expr",
487526
"//common:memory",
488-
"//common:type",
489527
"//common:value",
490-
"//eval/eval:cel_expression_flat_impl",
491528
"//eval/eval:evaluator_core",
529+
"//eval/public:activation",
492530
"//eval/public:builtin_func_registrar",
531+
"//eval/public:cel_expression",
493532
"//eval/public:cel_options",
533+
"//eval/public:cel_value",
494534
"//internal:testing",
495535
"//parser",
496536
"//runtime:runtime_issue",
497537
"//runtime/internal:issue_collector",
538+
"@com_google_absl//absl/status",
498539
"@com_google_googleapis//google/api/expr/v1alpha1:checked_cc_proto",
499540
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto",
500541
"@com_google_protobuf//:protobuf",

eval/compiler/cel_expression_builder_flat_impl.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
#include "absl/status/status.h"
2828
#include "absl/status/statusor.h"
2929
#include "base/ast.h"
30+
#include "common/native_type.h"
3031
#include "eval/eval/cel_expression_flat_impl.h"
32+
#include "eval/eval/direct_expression_step.h"
3133
#include "eval/eval/evaluator_core.h"
3234
#include "eval/public/cel_expression.h"
3335
#include "extensions/protobuf/ast_converters.h"
@@ -94,6 +96,14 @@ CelExpressionBuilderFlatImpl::CreateExpressionImpl(
9496
warnings->push_back(issue.ToStatus());
9597
}
9698
}
99+
if (flat_expr_builder_.options().max_recursion_depth != 0 &&
100+
impl.path().size() > 0 &&
101+
// mainline expression is exactly one recursive step.
102+
impl.subexpressions().front().size() == 1 &&
103+
impl.path().front()->GetNativeTypeId() ==
104+
cel::NativeTypeId::For<WrappedDirectStep>()) {
105+
return CelExpressionRecursiveImpl::Create(std::move(impl));
106+
}
97107

98108
return std::make_unique<CelExpressionFlatImpl>(std::move(impl));
99109
}

0 commit comments

Comments
 (0)