Skip to content

Commit 701946b

Browse files
jckingcopybara-github
authored andcommitted
Update unknown FunctionResultSet to only hold function names
PiperOrigin-RevId: 985415836
1 parent 14fad34 commit 701946b

6 files changed

Lines changed: 25 additions & 35 deletions

File tree

base/BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ cc_library(
120120
hdrs = [
121121
"function_result.h",
122122
],
123-
deps = [":function_descriptor"],
123+
deps = [
124+
":function_descriptor",
125+
"@com_google_absl//absl/base:core_headers",
126+
"@com_google_absl//absl/strings:string_view",
127+
],
124128
)
125129

126130
cc_library(

base/function_result.h

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
#define THIRD_PARTY_CEL_CPP_BASE_FUNCTION_RESULT_H_
1717

1818
#include <cstdint>
19+
#include <string>
1920
#include <utility>
2021

22+
#include "absl/base/attributes.h"
23+
#include "absl/strings/string_view.h"
2124
#include "base/function_descriptor.h"
2225

2326
namespace cel {
@@ -32,37 +35,29 @@ class FunctionResult final {
3235
FunctionResult& operator=(const FunctionResult&) = default;
3336
FunctionResult& operator=(FunctionResult&&) = default;
3437

35-
FunctionResult(FunctionDescriptor descriptor, int64_t expr_id)
36-
: descriptor_(std::move(descriptor)), expr_id_(expr_id) {}
38+
explicit FunctionResult(std::string_view name) : name_(name) {}
3739

38-
// The descriptor of the called function that return Unknown.
39-
const FunctionDescriptor& descriptor() const { return descriptor_; }
40-
41-
// The id of the |Expr| that triggered the function call step. Provided
42-
// informationally -- if two different |Expr|s generate the same unknown call,
43-
// they will be treated as the same unknown function result.
44-
int64_t call_expr_id() const { return expr_id_; }
40+
absl::string_view name() const ABSL_ATTRIBUTE_LIFETIME_BOUND { return name_; }
4541

4642
// Equality operator provided for testing. Compatible with set less-than
4743
// comparator.
4844
// Compares descriptor then arguments elementwise.
4945
bool IsEqualTo(const FunctionResult& other) const {
50-
return descriptor() == other.descriptor();
46+
return name() == other.name();
5147
}
5248

5349
// TODO(uncreated-issue/5): re-implement argument capture
5450

5551
private:
56-
FunctionDescriptor descriptor_;
57-
int64_t expr_id_;
52+
std::string name_;
5853
};
5954

6055
inline bool operator==(const FunctionResult& lhs, const FunctionResult& rhs) {
6156
return lhs.IsEqualTo(rhs);
6257
}
6358

6459
inline bool operator<(const FunctionResult& lhs, const FunctionResult& rhs) {
65-
return lhs.descriptor() < rhs.descriptor();
60+
return lhs.name() < rhs.name();
6661
}
6762

6863
} // namespace cel

eval/eval/attribute_utility.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ UnknownValue AttributeUtility::CreateUnknownSet(
219219
const cel::FunctionDescriptor& fn_descriptor, int64_t expr_id,
220220
absl::Span<const cel::Value> args) const {
221221
return cel::common_internal::MakeUnknownValue(
222-
cel::Unknown(FunctionResultSet(FunctionResult(fn_descriptor, expr_id))));
222+
cel::Unknown(FunctionResultSet(FunctionResult(fn_descriptor.name()))));
223223
}
224224

225225
void AttributeUtility::Add(Accumulator& a, const cel::UnknownValue& v) const {

eval/public/unknown_function_result_set_test.cc

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ CelFunctionDescriptor kTwoInt("TwoInt", false,
3838
CelFunctionDescriptor kOneInt("OneInt", false, {CelValue::Type::kInt64});
3939

4040
TEST(UnknownFunctionResult, Equals) {
41-
UnknownFunctionResult call1(kTwoInt, /*expr_id=*/0);
41+
UnknownFunctionResult call1(kTwoInt.name());
4242

43-
UnknownFunctionResult call2(kTwoInt, /*expr_id=*/0);
43+
UnknownFunctionResult call2(kTwoInt.name());
4444

4545
EXPECT_TRUE(call1.IsEqualTo(call2));
4646

47-
UnknownFunctionResult call3(kOneInt, /*expr_id=*/0);
47+
UnknownFunctionResult call3(kOneInt.name());
4848

49-
UnknownFunctionResult call4(kOneInt, /*expr_id=*/0);
49+
UnknownFunctionResult call4(kOneInt.name());
5050

5151
EXPECT_TRUE(call3.IsEqualTo(call4));
5252

@@ -57,25 +57,16 @@ TEST(UnknownFunctionResult, Equals) {
5757
}
5858

5959
TEST(UnknownFunctionResult, InequalDescriptor) {
60-
UnknownFunctionResult call1(kTwoInt, /*expr_id=*/0);
60+
UnknownFunctionResult call1(kTwoInt.name());
6161

62-
UnknownFunctionResult call2(kOneInt, /*expr_id=*/0);
62+
UnknownFunctionResult call2(kOneInt.name());
6363

6464
EXPECT_FALSE(call1.IsEqualTo(call2));
6565

66-
CelFunctionDescriptor one_uint("OneInt", false, {CelValue::Type::kUint64});
67-
68-
UnknownFunctionResult call3(kOneInt, /*expr_id=*/0);
69-
70-
UnknownFunctionResult call4(one_uint, /*expr_id=*/0);
71-
72-
EXPECT_FALSE(call3.IsEqualTo(call4));
73-
74-
UnknownFunctionResultSet call_set({call1, call3, call4});
75-
EXPECT_EQ(call_set.size(), 3);
66+
UnknownFunctionResultSet call_set({call1, call2});
67+
EXPECT_EQ(call_set.size(), 2);
7668
auto it = call_set.begin();
77-
EXPECT_EQ(*it++, call3);
78-
EXPECT_EQ(*it++, call4);
69+
EXPECT_EQ(*it++, call2);
7970
EXPECT_EQ(*it++, call1);
8071
}
8172

eval/public/unknown_set_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using ::testing::UnorderedElementsAre;
2222

2323
UnknownFunctionResultSet MakeFunctionResult(Arena* arena, int64_t id) {
2424
CelFunctionDescriptor desc("OneInt", false, {CelValue::Type::kInt64});
25-
return UnknownFunctionResultSet(UnknownFunctionResult(desc, /*expr_id=*/0));
25+
return UnknownFunctionResultSet(UnknownFunctionResult(desc.name()));
2626
}
2727

2828
UnknownAttributeSet MakeAttribute(Arena* arena, int64_t id) {

eval/tests/unknowns_end_to_end_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class UnknownsTest : public testing::Test {
133133

134134
MATCHER_P(FunctionCallIs, fn_name, "") {
135135
const cel::FunctionResult& result = arg;
136-
return result.descriptor().name() == fn_name;
136+
return result.name() == fn_name;
137137
}
138138

139139
MATCHER_P(AttributeIs, attr, "") {

0 commit comments

Comments
 (0)