From edb7bf5f3f9ff604da34b072ee8f9055390c546e Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Wed, 27 Sep 2023 18:51:47 -0700 Subject: [PATCH] Implement Container V2 for folly::sorted_vector_set --- test/integration/sorted_vector_set.toml | 14 +++++++-- types/sorted_vec_set_type.toml | 38 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/test/integration/sorted_vector_set.toml b/test/integration/sorted_vector_set.toml index f8e15c0..8e37abd 100644 --- a/test/integration/sorted_vector_set.toml +++ b/test/integration/sorted_vector_set.toml @@ -5,7 +5,6 @@ definitions = ''' [cases] [cases.no_ints] - oil_skip = 'not implemented for treebuilder v2' # https://github.com/facebookexperimental/object-introspection/issues/320 param_types = ["const sorted_vector_set&"] setup = "return {};" expect_json = '''[{ @@ -21,9 +20,14 @@ definitions = ''' "capacity": 0, "elementStaticSize": 4 }]}]''' + expect_json_v2 = '''[{ + "staticSize": 24, + "exclusiveSize": 24, + "length": 0, + "capacity": 0 + }]''' [cases.some_ints] - oil_skip = 'not implemented for treebuilder v2' # https://github.com/facebookexperimental/object-introspection/issues/320 param_types = ["const sorted_vector_set&"] setup = ''' sorted_vector_set is; @@ -49,3 +53,9 @@ definitions = ''' "elementStaticSize": 4 }]}] ''' + expect_json_v2 = '''[{ + "staticSize": 24, + "exclusiveSize": 28, + "length": 3, + "capacity": 4 + }]''' diff --git a/types/sorted_vec_set_type.toml b/types/sorted_vec_set_type.toml index 2bfe95d..bc44219 100644 --- a/types/sorted_vec_set_type.toml +++ b/types/sorted_vec_set_type.toml @@ -47,3 +47,41 @@ struct TypeHandler> { } }; """ + +traversal_func = ''' +auto tail = returnArg.write((uintptr_t)&container) + .write(container.capacity()) + .write(container.size()); + +for (const auto& el : container) { + tail = tail.delegate([&el](auto ret) { + return OIInternal::getSizeType(el, ret); + }); +} + +return tail.finish(); +''' + +[[codegen.processor]] +type = "types::st::VarInt" +func = "el.pointer = std::get(d.val).value;" + +[[codegen.processor]] +type = "types::st::VarInt" +func = ''' +el.container_stats.emplace(result::Element::ContainerStats{ .capacity = std::get(d.val).value }); +''' + +[[codegen.processor]] +type = "types::st::List::type>" +func = """ +static constexpr auto childField = make_field("[]"); + +auto list = std::get(d.val); +el.container_stats->length = list.length; +el.exclusive_size += (el.container_stats->capacity - el.container_stats->length) * sizeof(T0); + +for (size_t i = 0; i < list.length; i++) + stack_ins(childField); +""" +