Skip to content

Commit

Permalink
Add object_ptr type alias
Browse files Browse the repository at this point in the history
Summary:
This diff adds `object_ptr` as an alias because `object::ptr` cannot be used in places where `object` is still an incomplete type (e.g. `native_function`). This makes the code cleaner.

Change is no-op.

Reviewed By: iahs

Differential Revision: D67928744

fbshipit-source-id: 27658cb1fa6619235dc32eac301de8becb16fdae
  • Loading branch information
praihan authored and facebook-github-bot committed Jan 10, 2025
1 parent 76efc2b commit 5d57aea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
8 changes: 3 additions & 5 deletions thrift/compiler/whisker/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ native_function::context::map_like::map_like(maybe_managed_ptr<map>&& m)
: which_(std::move(m)) {}

/* static */ std::optional<native_function::context::array_like>
native_function::context::array_like::try_from(
const maybe_managed_ptr<object>& o) {
native_function::context::array_like::try_from(const object::ptr& o) {
if (o->is_array()) {
return array_like(
maybe_managed_ptr<array>(o, std::addressof(o->as_array())));
Expand Down Expand Up @@ -229,8 +228,7 @@ const object* native_function::context::map_like::lookup_property(
}

/* static */ std::optional<native_function::context::map_like>
native_function::context::map_like::try_from(
const maybe_managed_ptr<object>& o) {
native_function::context::map_like::try_from(const object::ptr& o) {
if (o->is_map()) {
return map_like(maybe_managed_ptr<map>(o, std::addressof(o->as_map())));
}
Expand All @@ -242,7 +240,7 @@ native_function::context::map_like::try_from(
return std::nullopt;
}

maybe_managed_ptr<object> native_function::context::named_argument(
object::ptr native_function::context::named_argument(
std::string_view name, named_argument_presence presence) const {
auto arg = named_args_.find(name);
if (arg == named_args_.end()) {
Expand Down
12 changes: 6 additions & 6 deletions thrift/compiler/whisker/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ struct object_print_options {
*/
template <typename T>
using maybe_managed_ptr = std::shared_ptr<const T>;
using object_ptr = maybe_managed_ptr<object>;

/**
* A native_object is the most powerful type in Whisker. Its properties and
Expand Down Expand Up @@ -351,7 +352,7 @@ class native_function {
* Postconditions:
* - The returned object is non-null.
*/
virtual maybe_managed_ptr<object> invoke(context) = 0;
virtual object_ptr invoke(context) = 0;

/**
* An exception that can be thrown to indicate a fatal error in function
Expand Down Expand Up @@ -430,8 +431,7 @@ class native_function {
* Tries to marshal the provided object into an array-like object, if the
* underlying type matches. Otherwise, returns an empty optional.
*/
static std::optional<array_like> try_from(
const maybe_managed_ptr<object>&);
static std::optional<array_like> try_from(const object_ptr&);

private:
explicit array_like(native_object::array_like::ptr&& arr);
Expand Down Expand Up @@ -465,7 +465,7 @@ class native_function {
* Tries to marshal the provided object into an map-like object, if the
* underlying type matches. Otherwise, returns an empty optional.
*/
static std::optional<map_like> try_from(const maybe_managed_ptr<object>&);
static std::optional<map_like> try_from(const object_ptr&);

private:
explicit map_like(native_object::map_like::ptr&& m);
Expand Down Expand Up @@ -514,7 +514,7 @@ class native_function {
* If the argument is not present and presence is required, then this throws
* an error. Otherwise, returns nullptr.
*/
maybe_managed_ptr<object> named_argument(
object_ptr named_argument(
std::string_view name,
named_argument_presence = named_argument_presence::required) const;

Expand Down Expand Up @@ -689,7 +689,7 @@ class object final : private detail::object_base<object> {
return std::get<T>(*this);
}

using ptr = maybe_managed_ptr<object>;
using ptr = object_ptr;

/**
* Returns a shared_ptr which is an unmanaged reference to the provided
Expand Down

0 comments on commit 5d57aea

Please sign in to comment.