From e83a8d89f33a3a643a9fc0c10c331ff083b76d5b Mon Sep 17 00:00:00 2001 From: Justin King Date: Wed, 23 Sep 2026 08:40:31 -0700 Subject: [PATCH] Update unknown `FunctionResultSet` to only hold function names PiperOrigin-RevId: 986782397 --- base/BUILD | 6 ++++- base/function_result.h | 21 ++++++--------- eval/eval/attribute_utility.cc | 2 +- .../unknown_function_result_set_test.cc | 27 +++++++------------ eval/public/unknown_set_test.cc | 2 +- eval/tests/unknowns_end_to_end_test.cc | 2 +- 6 files changed, 25 insertions(+), 35 deletions(-) diff --git a/base/BUILD b/base/BUILD index 8c2a32671..600889182 100644 --- a/base/BUILD +++ b/base/BUILD @@ -120,7 +120,11 @@ cc_library( hdrs = [ "function_result.h", ], - deps = [":function_descriptor"], + deps = [ + ":function_descriptor", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/strings:string_view", + ], ) cc_library( diff --git a/base/function_result.h b/base/function_result.h index 977ceeb90..b511dd744 100644 --- a/base/function_result.h +++ b/base/function_result.h @@ -16,8 +16,11 @@ #define THIRD_PARTY_CEL_CPP_BASE_FUNCTION_RESULT_H_ #include +#include #include +#include "absl/base/attributes.h" +#include "absl/strings/string_view.h" #include "base/function_descriptor.h" namespace cel { @@ -32,29 +35,21 @@ class FunctionResult final { FunctionResult& operator=(const FunctionResult&) = default; FunctionResult& operator=(FunctionResult&&) = default; - FunctionResult(FunctionDescriptor descriptor, int64_t expr_id) - : descriptor_(std::move(descriptor)), expr_id_(expr_id) {} + explicit FunctionResult(std::string_view name) : name_(name) {} - // The descriptor of the called function that return Unknown. - const FunctionDescriptor& descriptor() const { return descriptor_; } - - // The id of the |Expr| that triggered the function call step. Provided - // informationally -- if two different |Expr|s generate the same unknown call, - // they will be treated as the same unknown function result. - int64_t call_expr_id() const { return expr_id_; } + absl::string_view name() const ABSL_ATTRIBUTE_LIFETIME_BOUND { return name_; } // Equality operator provided for testing. Compatible with set less-than // comparator. // Compares descriptor then arguments elementwise. bool IsEqualTo(const FunctionResult& other) const { - return descriptor() == other.descriptor(); + return name() == other.name(); } // TODO(uncreated-issue/5): re-implement argument capture private: - FunctionDescriptor descriptor_; - int64_t expr_id_; + std::string name_; }; inline bool operator==(const FunctionResult& lhs, const FunctionResult& rhs) { @@ -62,7 +57,7 @@ inline bool operator==(const FunctionResult& lhs, const FunctionResult& rhs) { } inline bool operator<(const FunctionResult& lhs, const FunctionResult& rhs) { - return lhs.descriptor() < rhs.descriptor(); + return lhs.name() < rhs.name(); } } // namespace cel diff --git a/eval/eval/attribute_utility.cc b/eval/eval/attribute_utility.cc index cea676efd..274deb78c 100644 --- a/eval/eval/attribute_utility.cc +++ b/eval/eval/attribute_utility.cc @@ -219,7 +219,7 @@ UnknownValue AttributeUtility::CreateUnknownSet( const cel::FunctionDescriptor& fn_descriptor, int64_t expr_id, absl::Span args) const { return cel::common_internal::MakeUnknownValue( - cel::Unknown(FunctionResultSet(FunctionResult(fn_descriptor, expr_id)))); + cel::Unknown(FunctionResultSet(FunctionResult(fn_descriptor.name())))); } void AttributeUtility::Add(Accumulator& a, const cel::UnknownValue& v) const { diff --git a/eval/public/unknown_function_result_set_test.cc b/eval/public/unknown_function_result_set_test.cc index 745b5b9ff..b629f12fe 100644 --- a/eval/public/unknown_function_result_set_test.cc +++ b/eval/public/unknown_function_result_set_test.cc @@ -38,15 +38,15 @@ CelFunctionDescriptor kTwoInt("TwoInt", false, CelFunctionDescriptor kOneInt("OneInt", false, {CelValue::Type::kInt64}); TEST(UnknownFunctionResult, Equals) { - UnknownFunctionResult call1(kTwoInt, /*expr_id=*/0); + UnknownFunctionResult call1(kTwoInt.name()); - UnknownFunctionResult call2(kTwoInt, /*expr_id=*/0); + UnknownFunctionResult call2(kTwoInt.name()); EXPECT_TRUE(call1.IsEqualTo(call2)); - UnknownFunctionResult call3(kOneInt, /*expr_id=*/0); + UnknownFunctionResult call3(kOneInt.name()); - UnknownFunctionResult call4(kOneInt, /*expr_id=*/0); + UnknownFunctionResult call4(kOneInt.name()); EXPECT_TRUE(call3.IsEqualTo(call4)); @@ -57,25 +57,16 @@ TEST(UnknownFunctionResult, Equals) { } TEST(UnknownFunctionResult, InequalDescriptor) { - UnknownFunctionResult call1(kTwoInt, /*expr_id=*/0); + UnknownFunctionResult call1(kTwoInt.name()); - UnknownFunctionResult call2(kOneInt, /*expr_id=*/0); + UnknownFunctionResult call2(kOneInt.name()); EXPECT_FALSE(call1.IsEqualTo(call2)); - CelFunctionDescriptor one_uint("OneInt", false, {CelValue::Type::kUint64}); - - UnknownFunctionResult call3(kOneInt, /*expr_id=*/0); - - UnknownFunctionResult call4(one_uint, /*expr_id=*/0); - - EXPECT_FALSE(call3.IsEqualTo(call4)); - - UnknownFunctionResultSet call_set({call1, call3, call4}); - EXPECT_EQ(call_set.size(), 3); + UnknownFunctionResultSet call_set({call1, call2}); + EXPECT_EQ(call_set.size(), 2); auto it = call_set.begin(); - EXPECT_EQ(*it++, call3); - EXPECT_EQ(*it++, call4); + EXPECT_EQ(*it++, call2); EXPECT_EQ(*it++, call1); } diff --git a/eval/public/unknown_set_test.cc b/eval/public/unknown_set_test.cc index 3a0d151a5..c15030c00 100644 --- a/eval/public/unknown_set_test.cc +++ b/eval/public/unknown_set_test.cc @@ -22,7 +22,7 @@ using ::testing::UnorderedElementsAre; UnknownFunctionResultSet MakeFunctionResult(Arena* arena, int64_t id) { CelFunctionDescriptor desc("OneInt", false, {CelValue::Type::kInt64}); - return UnknownFunctionResultSet(UnknownFunctionResult(desc, /*expr_id=*/0)); + return UnknownFunctionResultSet(UnknownFunctionResult(desc.name())); } UnknownAttributeSet MakeAttribute(Arena* arena, int64_t id) { diff --git a/eval/tests/unknowns_end_to_end_test.cc b/eval/tests/unknowns_end_to_end_test.cc index 71ffe652c..b8132e42f 100644 --- a/eval/tests/unknowns_end_to_end_test.cc +++ b/eval/tests/unknowns_end_to_end_test.cc @@ -133,7 +133,7 @@ class UnknownsTest : public testing::Test { MATCHER_P(FunctionCallIs, fn_name, "") { const cel::FunctionResult& result = arg; - return result.descriptor().name() == fn_name; + return result.name() == fn_name; } MATCHER_P(AttributeIs, attr, "") {