Commit Graph

17 Commits

Author SHA1 Message Date
Jonathan Haslam
1ba742b433 Keep template parameters for pass-through types (#486)
Summary:

Implement the pass-through feature in ClangTypeParser (keeping template parameters for specified types0.

Reviewed By: JakeHillion

Differential Revision: D53815662
2024-02-15 12:04:41 -08:00
Jon Haslam
bfafe2eeae
stub types in OIL via config (#484) 2024-02-14 15:23:35 +00:00
Jake Hillion
55989a9156 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 13:26:25 -08:00
Jake Hillion
3871d92abb collapse TreeBuilderV2 features
Summary:

Currently there are two features between CodeGen v2 (TypeGraph) and TreeBuilder
v2. These are TypedDataSegment and TreeBuilderTypeChecking. Each of these
features currently has a full set of tests run in the CI and each have specific
exclusions.

Collapse these features into TreeBuilder v2. This allows for significantly
simplified testing as any OIL tests run under TreeBuilder v2 and any OID tests
run under TreeBuilder v1.

The reasoning behind this is I no longer intend to partially roll out this
feature. Full TreeBuilder v2 applies different conditions to containers than
the intermediate states, and writing these only to have them never deployed is
a waste of time.

Test Plan:
- it builds
- CI
2023-11-13 19:43:03 +00:00
Jake Hillion
393f8aab42 clang-format: disable bin packing
Bin packing often makes code hard to read. Disable it entirely.

Test plan:
- CI
2023-11-13 18:19:53 +00:00
Jake Hillion
217f675e30 oilgen: accept multiple config files (#379)
Summary:

Extend the multiple config files system to OILGen, the piece it was originally designed for. This allows for specifying additional configs which say which keys of maps to capture.

Reviewed By: ajor

Differential Revision: D50105138
2023-10-11 16:25:13 -07:00
Jake Hillion
37991140da support 0 to many config files (#371)
Summary:
Previously OID/OIL required exactly one configuration file. This change makes it so you can supply 0 or more configuration files. 0 is useful if you have pre-generated the cache or use some sort of remote generation system. 1 is useful for the common case, where you have a configuration file that describes your entire source and use just that. More are useful if you have supplemental bits of config you wish to apply/override - see the changes to the integration test framework where we do exactly this.


Test Plan:
This isn't super well tested. It works for the test cases which add features via the config or enable `codegen.ignore`.

- CI

Reviewed By: ajor

Differential Revision: D49758032

Pulled By: JakeHillion
2023-10-02 14:06:39 -06:00
Jake Hillion
929a2e68f8 oilgen: avoid demangling empty symbols 2023-09-19 20:27:10 +01:00
Jake Hillion
78b1a6c840 oilgen: hash linkage names in output path 2023-09-18 17:26:21 +01:00
Jake Hillion
a6d74a20a6 Update to clang/llvm 15 (#342)
Summary:

Update to clang-15 compiler and libraries as clang-12 is ancient.

The changes to oilgen are necessary because the new internal toolchain is being more picky about linking PIC to PIC. In certain modes we build with PIC, but try to link a non-PIC oilgen artifact. Add the ability to build the oilgen artifacts with PIC which sorts this.

Reviewed By: ttreyer

Differential Revision: D46220858
2023-09-14 06:02:32 -07:00
Jake Hillion
a9cffbe22d Compile Time OIL for OIL v2
Summary:
Update `OIGenerator` and out BUCK stuff for compile time OIL with OIL v2. Main things:
- Switch `OIGenerator` from the `getObjectSize` call to the new `introspect` call.
- Switch from looking at template parameters to looking at function parameters, as this was exposing a bug in our elfutils/drgn and this way it's the same as OID.
- Migrate `OIGenerator` to CodeGen v2 and update CodeGen v2 to accept a linkage name.
- Update the compile time example to be the same as the JIT example, using the new interface and the JSON exporter.
- Clean up the `ObjectIntrospection.h` header.

Differential Revision: D48687728

fbshipit-source-id: 2c3c041fd1b6499c5e02eb5e2082a977bfa529d7
2023-08-30 04:28:02 -07:00
Jake Hillion
d7cfcca30d move all internal logic to oi::detail namespace 2023-07-26 18:01:38 +01:00
Alastair Robertson
45c3697f6b TypeGraph: Add Prune pass
This lets us remove fields from types when they are no longer needed,
speeding up later passes.

A secondary benefit of pruning unused types means that we sometimes
remove types for which we can't generate correct C++ code. This can
allow us to CodeGen for complex types which reference these broken types
without actually requiring them (e.g. as template parameters).

Add a new feature flag "prune-type-graph" to control this pass. It makes
sense to prune most of the time, but for testing CodeGen functionality
on a wider range of types, it will be useful to have the option to not
prune.
2023-07-26 16:56:34 +01:00
Jake Hillion
6aead62652 static types: place in own header for testing 2023-06-30 12:54:02 +01:00
Alastair Robertson
cdb70e8008 Fix warnings in core code 2023-05-23 10:36:42 +01:00
Jake Hillion
b32f723844 resources: manage headers properly
Previously we had an `R"(` string in `OITraceCode.cpp` which allowed us
to include the file as a string. Instead, keep `OITraceCode.cpp` a fully
formed C++ file and utilise the build system to turn it into a string.
This will be used for more header files that are needed both as valid
headers and as strings for JIT compilation in the Typed TreeBuilder
work.
2023-05-18 16:04:13 +02:00
Jon Haslam
d4891e98d4
move src directory to oi (#134) 2023-04-26 16:20:53 +01:00