Skip to content

Commit 84021cb

Browse files
jckingcopybara-github
authored andcommitted
Begin getting rid of cel::MemoryManager
PiperOrigin-RevId: 993982182
1 parent f28da96 commit 84021cb

7 files changed

Lines changed: 44 additions & 105 deletions

File tree

‎common/BUILD‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ cc_library(
506506
":allocator",
507507
"//internal:to_address",
508508
"@com_google_absl//absl/base:core_headers",
509-
"@com_google_absl//absl/base:no_destructor",
510509
"@com_google_absl//absl/base:nullability",
511510
"@com_google_absl//absl/log:absl_check",
512511
"@com_google_absl//absl/numeric:bits",

‎common/memory.cc‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
#include <new>
2020
#include <ostream>
2121

22-
#include "absl/base/no_destructor.h"
2322
#include "absl/log/absl_check.h"
2423
#include "absl/numeric/bits.h"
25-
#include "google/protobuf/arena.h"
2624

2725
namespace cel {
2826

@@ -73,11 +71,4 @@ bool ReferenceCountingMemoryManager::Deallocate(void* ptr, size_t size,
7371
return true;
7472
}
7573

76-
MemoryManager MemoryManager::Unmanaged() {
77-
// A static singleton arena, using `absl::NoDestructor` to avoid warnings
78-
// related static variables without trivial destructors.
79-
static absl::NoDestructor<google::protobuf::Arena> arena;
80-
return MemoryManager::Pooling(&*arena);
81-
}
82-
8374
} // namespace cel

‎common/memory.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,6 @@ class PoolingMemoryManager final {
152152
// resources.
153153
class MemoryManager final {
154154
public:
155-
// Returns a `MemoryManager` which utilizes an arena but never frees its
156-
// memory. It is effectively a memory leak and should only be used for limited
157-
// use cases, such as initializing singletons which live for the life of the
158-
// program.
159-
static MemoryManager Unmanaged();
160-
161-
// Returns a `MemoryManager` which utilizes reference counting.
162-
ABSL_MUST_USE_RESULT static MemoryManager ReferenceCounting() {
163-
return MemoryManager(nullptr);
164-
}
165-
166155
// Returns a `MemoryManager` which utilizes an arena.
167156
ABSL_MUST_USE_RESULT static MemoryManager Pooling(
168157
google::protobuf::Arena* absl_nonnull arena) {

‎eval/public/BUILD‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ cc_library(
9696
"//common:native_type",
9797
"//eval/internal:errors",
9898
"//eval/public/structs:legacy_type_info_apis",
99-
"//extensions/protobuf:memory_manager",
10099
"//internal:casts",
101100
"//internal:status_macros",
102101
"//internal:utf8",

‎eval/public/cel_value.cc‎

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
#include "absl/strings/str_join.h"
1515
#include "absl/strings/string_view.h"
1616
#include "absl/types/optional.h"
17-
#include "common/memory.h"
1817
#include "eval/internal/errors.h"
1918
#include "eval/public/structs/legacy_type_info_apis.h"
20-
#include "extensions/protobuf/memory_manager.h"
2119
#include "google/protobuf/arena.h"
2220

2321
namespace google::api::expr::runtime {
@@ -286,23 +284,6 @@ CelValue CelValue::CreateList() { return CreateList(EmptyCelList::Get()); }
286284

287285
CelValue CelValue::CreateMap() { return CreateMap(EmptyCelMap::Get()); }
288286

289-
CelValue CreateErrorValue(cel::MemoryManagerRef manager,
290-
absl::string_view message,
291-
absl::StatusCode error_code) {
292-
// TODO(uncreated-issue/1): assume arena-style allocator while migrating to new
293-
// value type.
294-
Arena* arena = cel::extensions::ProtoMemoryManagerArena(manager);
295-
return CreateErrorValue(arena, message, error_code);
296-
}
297-
298-
CelValue CreateErrorValue(cel::MemoryManagerRef manager,
299-
const absl::Status& status) {
300-
// TODO(uncreated-issue/1): assume arena-style allocator while migrating to new
301-
// value type.
302-
Arena* arena = cel::extensions::ProtoMemoryManagerArena(manager);
303-
return CreateErrorValue(arena, status);
304-
}
305-
306287
CelValue CreateErrorValue(Arena* arena, absl::string_view message,
307288
absl::StatusCode error_code) {
308289
CelError* error = Arena::Create<CelError>(arena, error_code, message);
@@ -314,12 +295,6 @@ CelValue CreateErrorValue(Arena* arena, const absl::Status& status) {
314295
return CelValue::CreateError(error);
315296
}
316297

317-
CelValue CreateNoMatchingOverloadError(cel::MemoryManagerRef manager,
318-
absl::string_view fn) {
319-
return CelValue::CreateError(interop::CreateNoMatchingOverloadError(
320-
cel::extensions::ProtoMemoryManagerArena(manager), fn));
321-
}
322-
323298
CelValue CreateNoMatchingOverloadError(google::protobuf::Arena* arena,
324299
absl::string_view fn) {
325300
return CelValue::CreateError(
@@ -333,22 +308,10 @@ bool CheckNoMatchingOverloadError(CelValue value) {
333308
cel::runtime_internal::kErrNoMatchingOverload);
334309
}
335310

336-
CelValue CreateNoSuchFieldError(cel::MemoryManagerRef manager,
337-
absl::string_view field) {
338-
return CelValue::CreateError(interop::CreateNoSuchFieldError(
339-
cel::extensions::ProtoMemoryManagerArena(manager), field));
340-
}
341-
342311
CelValue CreateNoSuchFieldError(google::protobuf::Arena* arena, absl::string_view field) {
343312
return CelValue::CreateError(interop::CreateNoSuchFieldError(arena, field));
344313
}
345314

346-
CelValue CreateNoSuchKeyError(cel::MemoryManagerRef manager,
347-
absl::string_view key) {
348-
return CelValue::CreateError(interop::CreateNoSuchKeyError(
349-
cel::extensions::ProtoMemoryManagerArena(manager), key));
350-
}
351-
352315
CelValue CreateNoSuchKeyError(google::protobuf::Arena* arena, absl::string_view key) {
353316
return CelValue::CreateError(interop::CreateNoSuchKeyError(arena, key));
354317
}
@@ -365,15 +328,6 @@ CelValue CreateMissingAttributeError(google::protobuf::Arena* arena,
365328
interop::CreateMissingAttributeError(arena, missing_attribute_path));
366329
}
367330

368-
CelValue CreateMissingAttributeError(cel::MemoryManagerRef manager,
369-
absl::string_view missing_attribute_path) {
370-
// TODO(uncreated-issue/1): assume arena-style allocator while migrating
371-
// to new value type.
372-
return CelValue::CreateError(interop::CreateMissingAttributeError(
373-
cel::extensions::ProtoMemoryManagerArena(manager),
374-
missing_attribute_path));
375-
}
376-
377331
bool IsMissingAttributeError(const CelValue& value) {
378332
const CelError* error;
379333
if (!value.GetValue(&error)) return false;
@@ -385,12 +339,6 @@ bool IsMissingAttributeError(const CelValue& value) {
385339
return false;
386340
}
387341

388-
CelValue CreateUnknownFunctionResultError(cel::MemoryManagerRef manager,
389-
absl::string_view help_message) {
390-
return CelValue::CreateError(interop::CreateUnknownFunctionResultError(
391-
cel::extensions::ProtoMemoryManagerArena(manager), help_message));
392-
}
393-
394342
CelValue CreateUnknownFunctionResultError(google::protobuf::Arena* arena,
395343
absl::string_view help_message) {
396344
return CelValue::CreateError(

‎eval/public/cel_value.h‎

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -653,70 +653,84 @@ class CelMap {
653653
// Utility method that generates CelValue containing CelError.
654654
// message an error message
655655
// error_code error code
656-
CelValue CreateErrorValue(
657-
cel::MemoryManagerRef manager ABSL_ATTRIBUTE_LIFETIME_BOUND,
658-
absl::string_view message,
659-
absl::StatusCode error_code = absl::StatusCode::kUnknown);
660656
CelValue CreateErrorValue(
661657
google::protobuf::Arena* arena, absl::string_view message,
662658
absl::StatusCode error_code = absl::StatusCode::kUnknown);
663-
664-
// Utility method for generating a CelValue from an absl::Status.
665-
CelValue CreateErrorValue(cel::MemoryManagerRef manager
666-
ABSL_ATTRIBUTE_LIFETIME_BOUND,
667-
const absl::Status& status);
659+
ABSL_DEPRECATE_AND_INLINE()
660+
inline CelValue CreateErrorValue(
661+
cel::MemoryManagerRef manager ABSL_ATTRIBUTE_LIFETIME_BOUND,
662+
absl::string_view message,
663+
absl::StatusCode error_code = absl::StatusCode::kUnknown) {
664+
return CreateErrorValue(manager.arena(), message, error_code);
665+
}
668666

669667
// Utility method for generating a CelValue from an absl::Status.
670668
CelValue CreateErrorValue(google::protobuf::Arena* arena, const absl::Status& status);
669+
ABSL_DEPRECATE_AND_INLINE()
670+
inline CelValue CreateErrorValue(cel::MemoryManagerRef manager
671+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
672+
const absl::Status& status) {
673+
return CreateErrorValue(manager.arena(), status);
674+
}
671675

672676
// Create an error for failed overload resolution, optionally including the name
673677
// of the function.
674-
CelValue CreateNoMatchingOverloadError(cel::MemoryManagerRef manager
675-
ABSL_ATTRIBUTE_LIFETIME_BOUND,
676-
absl::string_view fn = "");
677-
ABSL_DEPRECATED("Prefer using the generic MemoryManager overload")
678678
CelValue CreateNoMatchingOverloadError(google::protobuf::Arena* arena,
679679
absl::string_view fn = "");
680+
ABSL_DEPRECATE_AND_INLINE()
681+
inline CelValue CreateNoMatchingOverloadError(cel::MemoryManagerRef manager
682+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
683+
absl::string_view fn = "") {
684+
return CreateNoMatchingOverloadError(manager.arena(), fn);
685+
}
680686
bool CheckNoMatchingOverloadError(CelValue value);
681687

682-
CelValue CreateNoSuchFieldError(cel::MemoryManagerRef manager
683-
ABSL_ATTRIBUTE_LIFETIME_BOUND,
684-
absl::string_view field = "");
685-
ABSL_DEPRECATED("Prefer using the generic MemoryManager overload")
686688
CelValue CreateNoSuchFieldError(google::protobuf::Arena* arena,
687689
absl::string_view field = "");
690+
ABSL_DEPRECATE_AND_INLINE()
691+
inline CelValue CreateNoSuchFieldError(cel::MemoryManagerRef manager
692+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
693+
absl::string_view field = "") {
694+
return CreateNoSuchFieldError(manager.arena(), field);
695+
}
688696

689-
CelValue CreateNoSuchKeyError(cel::MemoryManagerRef manager
690-
ABSL_ATTRIBUTE_LIFETIME_BOUND,
691-
absl::string_view key);
692-
ABSL_DEPRECATED("Prefer using the generic MemoryManager overload")
693697
CelValue CreateNoSuchKeyError(google::protobuf::Arena* arena, absl::string_view key);
698+
ABSL_DEPRECATE_AND_INLINE()
699+
inline CelValue CreateNoSuchKeyError(cel::MemoryManagerRef manager
700+
ABSL_ATTRIBUTE_LIFETIME_BOUND,
701+
absl::string_view key) {
702+
return CreateNoSuchKeyError(manager.arena(), key);
703+
}
694704

695705
bool CheckNoSuchKeyError(CelValue value);
696706

697707
// Returns an error indicating that evaluation has accessed an attribute whose
698708
// value is undefined. For example, this may represent a field in a proto
699709
// message bound to the activation whose value can't be determined by the
700710
// hosting application.
701-
CelValue CreateMissingAttributeError(cel::MemoryManagerRef manager
702-
ABSL_ATTRIBUTE_LIFETIME_BOUND,
703-
absl::string_view missing_attribute_path);
704-
ABSL_DEPRECATED("Prefer using the generic MemoryManager overload")
705711
CelValue CreateMissingAttributeError(google::protobuf::Arena* arena,
706712
absl::string_view missing_attribute_path);
713+
ABSL_DEPRECATE_AND_INLINE()
714+
inline CelValue CreateMissingAttributeError(
715+
cel::MemoryManagerRef manager ABSL_ATTRIBUTE_LIFETIME_BOUND,
716+
absl::string_view missing_attribute_path) {
717+
return CreateMissingAttributeError(manager.arena(), missing_attribute_path);
718+
}
707719

708720
ABSL_CONST_INIT extern const absl::string_view kPayloadUrlMissingAttributePath;
709721
bool IsMissingAttributeError(const CelValue& value);
710722

711723
// Returns error indicating the result of the function is unknown. This is used
712724
// as a signal to create an unknown set if unknown function handling is opted
713725
// into.
714-
CelValue CreateUnknownFunctionResultError(cel::MemoryManagerRef manager
715-
ABSL_ATTRIBUTE_LIFETIME_BOUND,
716-
absl::string_view help_message);
717-
ABSL_DEPRECATED("Prefer using the generic MemoryManager overload")
718726
CelValue CreateUnknownFunctionResultError(google::protobuf::Arena* arena,
719727
absl::string_view help_message);
728+
ABSL_DEPRECATE_AND_INLINE()
729+
inline CelValue CreateUnknownFunctionResultError(
730+
cel::MemoryManagerRef manager ABSL_ATTRIBUTE_LIFETIME_BOUND,
731+
absl::string_view help_message) {
732+
return CreateUnknownFunctionResultError(manager.arena(), help_message);
733+
}
720734

721735
// Returns true if this is unknown value error indicating that evaluation
722736
// called an extension function whose value is unknown for the given args.

‎extensions/protobuf/memory_manager.cc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ namespace cel {
2323
namespace extensions {
2424

2525
MemoryManagerRef ProtoMemoryManager(google::protobuf::Arena* arena) {
26-
return arena != nullptr ? MemoryManagerRef::Pooling(arena)
27-
: MemoryManagerRef::ReferenceCounting();
26+
return MemoryManagerRef::Pooling(arena);
2827
}
2928

3029
google::protobuf::Arena* absl_nullable ProtoMemoryManagerArena(

0 commit comments

Comments
 (0)