From 03518150c522b1633afebd204d36e5c3b501e968 Mon Sep 17 00:00:00 2001 From: Jonathan Haslam Date: Mon, 15 Apr 2024 08:22:29 -0700 Subject: [PATCH] Make folly::Optional TBv2 compliant (#490) Summary: The container implementation for `folly::Optional` currently lacks TBv2 support. This change is a skilfully crafted cut-n-paste of the `std::optional` TBv2 implementation. Reviewed By: ajor Differential Revision: D56139280 --- types/folly_optional_type.toml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/types/folly_optional_type.toml b/types/folly_optional_type.toml index e3b6e5a..9df4ece 100644 --- a/types/folly_optional_type.toml +++ b/types/folly_optional_type.toml @@ -29,3 +29,31 @@ void getSizeType(const %1%& container, size_t& returnArg) { } } """ + +traversal_func = """ +if (container.has_value()) { + return returnArg.template delegate<1>([&ctx, &container](auto ret) { + return OIInternal::getSizeType(ctx, *container, ret); + }); +} else { + return returnArg.template delegate<0>(std::identity()); +} +""" + +[[codegen.processor]] +type = "types::st::Sum, typename TypeHandler::type>" +func = """ +static constexpr auto elementField = make_field("el"); + +auto sum = std::get(d.val); + +el.container_stats = result::Element::ContainerStats { + .capacity = 1, + .length = sum.index, +}; + +if (sum.index == 1) { + el.exclusive_size -= sizeof(T0); + stack_ins(elementField); +} +"""