object-introspection/types
Jake Hillion a931d2f52f oilgen: migrate to source parsing (#421)
Summary:
oilgen: migrate to source parsing

Using debug information generated from partial source (that is, not the final
binary) has been insufficient to generally generate OIL code.

A particular example is pointers to templates:
```cpp
#include <oi/oi.h>
template <typename T>
struct Foo {
  T t;
};
template <typename T>
struct Bar {
  Foo<T>& f;
};
void foo(const Bar<int>& b) {
  oi::introspect(b);
}
```

The pointer/reference to `Foo<int>` appears in DWARF with
`DW_AT_declaration(true)` because it could be specialised before its usage.
However, with OIL, we are creating an implicit usage site in the
`oi::introspect` call that the compiler is unable to see.

This change reworks OILGen to work from a Clang command line rather than debug
information. We setup and run a compiler on the source, giving us access to an
AST and Semantic Analyser. We then:
- Find the `oi::introspect` template.
- Iterate through each of its callsites for their type.
- Run `ClangTypeParser::parse` on each type.
- Run codegen.
- Compile into an object file.

Having access to the semantic analyser allows us to forcefully complete a type,
as it would be if it was used in the initial code.


Test Plan:
hope

`buck2 run fbcode//mode/opt fbcode//object-introspection/oil/examples/compile-time:compile-time`

Reviewed By: tyroguru

Differential Revision: D51854477

Pulled By: JakeHillion
2023-12-19 11:57:44 -08:00
..
array_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
boost_bimap_type.toml TypeGraph: Update container TOML files to new format 2023-05-26 18:21:59 +01:00
caffe2_blob_type.toml TypeGraph: Update container TOML files to new format 2023-05-26 18:21:59 +01:00
cxx11_list_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
cxx11_string_type.toml tbv2: replace DB template param with Ctx (#409) 2023-11-15 11:52:17 -08:00
deque_list_type.toml types: remove now unused handlers 2023-11-15 14:27:07 +00:00
f14_fast_map.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
f14_fast_set.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
f14_node_map.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
f14_node_set.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
f14_value_map.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
f14_value_set.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
f14_vector_map.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
f14_vector_set.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
fb_string_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
folly_iobuf_queue_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
folly_iobuf_type.toml Add missing namespace to folly::IOBuf container TOML 2023-06-29 11:59:07 +01:00
folly_optional_type.toml TypeGraph: Update container TOML files to new format 2023-05-26 18:21:59 +01:00
folly_small_heap_vector_map.toml TypeGraph: Update container TOML files to new format 2023-05-26 18:21:59 +01:00
list_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
map_seq_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
multi_map_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
multi_set_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
optional_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
pair_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
priority_queue_container_adapter_type.toml types: remove now unused handlers 2023-11-15 14:27:07 +00:00
queue_container_adapter_type.toml types: remove now unused handlers 2023-11-15 14:27:07 +00:00
README.md collapse TreeBuilderV2 features 2023-11-13 19:43:03 +00:00
ref_wrapper_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
repeated_field_type.toml TypeGraph: Update container TOML files to new format 2023-05-26 18:21:59 +01:00
repeated_ptr_field_type.toml TypeGraph: Update container TOML files to new format 2023-05-26 18:21:59 +01:00
seq_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
set_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
shrd_ptr_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
small_vec_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
sorted_vec_set_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
stack_container_adapter_type.toml types: remove now unused handlers 2023-11-15 14:27:07 +00:00
std_map_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
std_unordered_map_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
std_unordered_multimap_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
std_variant.toml types: remove now unused handlers 2023-11-15 14:27:07 +00:00
string_type.toml oilgen: migrate to source parsing (#421) 2023-12-19 11:57:44 -08:00
thrift_isset_type.toml types: remove now unused handlers 2023-11-15 14:27:07 +00:00
try_type.toml Fix JIT CodeGen for Try<> 2023-08-21 19:16:13 +02:00
uniq_ptr_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
unordered_multiset_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
unordered_set_type.toml tbv2: add dynamic context passed through all functions (#410) 2023-11-16 08:03:32 -08:00
weak_ptr_type.toml types: remove now unused handlers 2023-11-15 14:27:07 +00:00

Container Type Definition Format

This document describes the format of the container definition files contained in this directory.

info

  • type_name

    The fully-qualified name of the container type. This is used to match against the names of types contained in an executable's debug information.

  • header

    The name of the C++ header file in which this container is defined.

  • stub_template_params

    The indexes of template parameters which do not represent types stored within this container. These parameters will not be recursed into and measured by OI.

  • underlying_container_index

    Only used for container adapters. Points OI to the template parameter representing the underlying container to be measured.

  • required_features

    A set of feature names such as tree-builder-v2 which must be enabled for this container description to be included. Currently only supported with CodeGen v2 as that's their only use case and an implementation for CodeGen v1 would be untested.

codegen

  • decl

    C++ code for the declaration of a getSizeType function for this container.

  • func

    C++ code for the definition of a getSizeType function for this container.

  • processor.type

    The static type that will be filled in by this particular processor. Multiple processors are allowed and recommended.

  • processor.func

    C++ code for the function body of a function with this signature: void(result::Element& el, std::stack<Inst>& ins, ParsedData d) which is supplied with the data of the paired static type.

  • traversal_func

    C++ code for the function body of a function with this signature: static types::st::Unit<DB> getSizeType(const T& container, ST returnArg) where ST defines the combined static type of each supplied processor.

  • extra

    Any extra C++ code to be included directly. This code is not automatically wrapped in a namespace, so definitions from different container TOML files will collide if they share the same name.

## Changes introduced with TreeBuilder V2

  • decl and func fields are ignored when using -ftree-builder-v2. The TypeHandler is constructed from traversal_func field and processor entries.

Changes introduced with TypeGraph

  • typeName and matcher fields have been merged into the single field type_name.
  • ns namespace definition is no longer required.
  • underlyingContainerIndex renamed to underlying_container_index
  • The options for measuring / stubbing / removing template parameters have been reworked:
    • By default all parameters are now measured. This includes the tail parameters in a variadic template.
    • There is one option to specify template parameters which should not be measured: stub_template_params. The type graph code will automatically determine what type of stubbing to apply to each parameter in this list.

Deprecated Options

  • ctype

    A reference to the enum ContainerTypeEnum in OI's source code. This is no longer required with Tree Builder v2.

  • handler

    C++ code for the definition of a TypeHandler class for this container. Now generated from traversal_func and processor entries.

  • numTemplateParams

    The first numTemplateParams template parameters for this container represent the types for the data we want to process. If this is not set, use all a container's template parameters. All of a container's parameters will still be enumerated and output in CodeGen, regardless of this setting.

  • allocatorIndex

    Index of a template parameter representing an allocator. It will be not be used when CodeGenning this container.

  • replaceTemplateParamIndex

    Indexes of template parameters to be stubbed out, i.e. replaced with dummy structs of a given size. Used for custom hashers and comparers.