Commit Graph

214 Commits

Author SHA1 Message Date
Jake Hillion
a9afb25248 tbv2: update tuple test
This test is a bit odd, but this change adds the full set of size/member checks
for the hierarchy for TreeBuilder v2 and enables it.

Closes #304

Test Plan:
- CI
2024-01-11 13:39:19 +00:00
Thierry Treyer
d232a5d2fb Add namespaces to integration tests' "typeName"
Some integration tests have not been updated since drgn started
reporting type names with all their namespaces, and were failing.
2024-01-11 14:13:51 +01:00
Thierry Treyer
cf8fe64d5d Enable test arrays_member_int0 2024-01-10 19:13:41 +01:00
Jake Hillion
cbeafba9bb tbv2: fix type names for std::optional
Type names of optional elements were accidentally left as todo. Update
`std::optional` to use `make_field` and correctly name its elements.

Test Plan:
- CI
- Updated the integration tests to test the names.
2024-01-09 15:09:24 +00:00
Jake Hillion
db93feb180 incomplete: name type in compiler errors
Summary:

We have a good type representation in the Type Graph of an incomplete type and
the underlying type that represents. However, this incomplete type still ends
up in the generated code as `void` which loses information. For example, a
container that can't contain void may fail to compile because it was
initialised with `void` but really its because the type it was supposed to be
initialised with (say, `Foo`) had incomplete debug information.

This change identifies that a type is incomplete in the output by generating it
as an incomplete type `struct Incomplete<struct Foo>`. This allows us to name
the type correctly in the TreeBuilder output and filter for incomplete types,
as well as getting appropriate compiler errors if it mustn't be incomplete.

Test Plan:
- CI
- Added a unit test to namegen.
- Enabled and added an extra pointers_incomplete test.

This change is tricky to test because it isn't really user visible. The types
still use their `inputName` which is unchanged in any successful output - this
change is used so the compiler fails with a more detailed error.
2024-01-09 15:08:25 +00:00
Jake Hillion
71e734b120 tbv2: calculate total memory footprint
Add the option to calculate total size (inclusive size) by wrapping the
existing iterator. This change provides a new iterator, `SizedIterator`, which
wraps an existing iterator and adds a new field `size` to the output element.

This is achieved with a two pass algorithm on the existing iterator:
1. Gather metadata for each element. This includes the total size up until that
   element and the range of elements that should be included in the size.
2. Return the result from the underlying iterator with the additional
   field.

This algorithm is `O(N)` time on the number of elements in the iterator and
`O(N)` time, storing 16 bytes per element. This isn't super expensive but is a
lot more than the current algorithm which requires close to constant space.
Because of this I've implemented it as a wrapper on the iterator rather than on
by default, though it is now on in every one of our integration test cases.

Test plan:
- Added to the integration tests for full coverage.
2024-01-04 09:21:35 +00:00
Jake Hillion
6c90103278 circleci: clean up codegen v1 runs
Remove the CodeGen v1 sections of the CI config because both OID and OIL use
CodeGen v2.

We were missing running any test that wasn't `Oi{d,l}Integration.*` before.
This now runs the unit tests again and requires a minor fix to one unit test.

Test plan:
- CI
2024-01-03 17:29:59 +00:00
Alastair Robertson
2060a0491e CodeGen v2: Enable independent running without CodeGen v1
Create DrgnExporter to translate Type Graph "Type" nodes into drgn_type
structs, suitable for use in OICache and TreeBuilder.
2023-12-15 14:57:24 +00:00
Alastair Robertson
a0164e5cc7 TypeGraph: Make Class types use fully qualified names as their input names
This will ensure we continue to get fully qualified names in
user-visible output when we switch to CodeGen v2.
2023-12-15 14:45:01 +00:00
Alastair Robertson
688d483c0c TypeGraph: Fix handling for classes which inherit from containers
We previously moved container identification later in CodeGen in order
to preserve information for AlignmentCalc.

However, Flattener needs to know if a class is a container in order to
apply its special handling for this case.

This new approach moves container identification in front of Flattener,
but has Container own a type node, representing its layout. This
underlying type node can be used for calculating a container's
alignment in a later pass.
2023-12-14 18:02:45 +00:00
Alastair Robertson
aa87c3f2d1 NameGen: Override inputName for anonymous members 2023-12-14 17:42:48 +00:00
Thierry Treyer
d79b55cfd2 Update integration tests 2023-12-13 11:59:21 +00:00
Alastair Robertson
7cc7aa8882 CodeGen: Remove Incomplete members from Classes
They must not appear in the final generated code as we'd end up with
invalid types with void members, e.g.:
  struct Foo {
    int a;
    void myIncompleteMember;
    int c;
  };

Removing them from the type graph early also ensures that padding is
calculated correctly.
2023-12-12 18:50:15 +00:00
Alastair Robertson
6b780add4a Integration Tests: Fix thrift_unions tests
With a recent Thrift update, we now must also define a destructor for
this type.
2023-12-12 18:33:52 +00:00
Jake Hillion
e9d8df0ca4 oil: add support for std::list
Summary:

Remove the now useless `handler` and adds the `traversal_func` and `processor`
entries for `std::list`. This type is a bit weird as most of our sequential
containers don't have any overhead on storing the element. I went for the same
approach we take for maps where we have a shared `[]` element covering the map
overhead and below that a `key` & `value`. As we only have a single element
under it which doesn't have a logical name I went for `*`.

Closes #315.

Test Plan:
- CI
- Copied the relevant `std::vector` tests and updated the existing one.
2023-11-15 14:14:02 +00: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
Alastair Robertson
c207972af6 TypeGraph: Calculate alignment before identifying containers
Not all containers have 8-byte alignment, so if we want to avoid lots of
manual logic for calculating container alignment on a case-by-case
basis, we must calculate alignment from the member variables before the
Class nodes have been replaced by Container nodes.
2023-11-06 13:16:30 +00:00
Alastair Robertson
2c5fb5d845 TypeGraph: Stop identifying containers in DrgnParser
Leave it to the new mutator pass IdentifyContainers to replace Class
nodes with Container nodes where appropriate.

This will allow us to run passes over the type graph before identifying
containers, and therefore before we have lost information about the
internal details of the container (e.g. alignment of member variables).
2023-11-06 11:45:57 +00:00
Alastair Robertson
98008f9054 TypeGraph: Add IdentifyContainers mutator pass 2023-11-06 11:28:00 +00:00
Alastair Robertson
81ae075a68 DrgnParserTest: Replace testContains with testGlob
It now uses '*' as a wildcard character for more powerful matching of
type graphs.
2023-11-06 11:05:09 +00:00
Jake Hillion
315a5cde6c integration: move pid back to end 2023-11-02 18:27:27 +00:00
Alastair Robertson
e7581ad915 TopoSorter: Only allow certain params to be incomplete
For the containers which are allowed to be declared with incomplete
types, it is only the contained types which are allowed to be
incomplete. Other template parameters (e.g. allocators) must always be
defined before use.
2023-10-25 17:01:44 +01:00
Jake Hillion
f7bb1e75ad tbv2: fix exclusive size of elements in containers 2023-10-16 19:18:42 +01:00
Jake Hillion
e867178ebd capture_keys: include data in type path 2023-10-11 16:32:35 -07:00
Jake Hillion
4c6f232766 containers: add required features (#374)
Summary:
Adds the option for required features to container definitions. These cause the container not to be passed to `DrgnParser` if that feature is not enabled during code generation. The thrift isset type does not currently work with `tree-builder-v2` and only provides benefit with `capture-thrift-isset`. This change makes sure the container is ignored if it won't be useful, allowing code generation under `tree-builder-v2`.


Test Plan: - CI

Differential Revision: D49960512

Pulled By: JakeHillion
2023-10-09 17:50:39 -04:00
Thierry Treyer
593a1412d8 Fix exclusive_size for F14NodeMap 2023-10-09 10:41:34 -06:00
Thierry Treyer
7b5baca3b0 Fix exclusive_size for F14FastMap 2023-10-09 10:41:34 -06:00
Thierry Treyer
9ce7bd5fad Fix exclusive_size for F14VectorMap 2023-10-09 10:41:34 -06:00
Thierry Treyer
2d3709da65 Fix exclusive_size for F14ValueMap 2023-10-09 10:41:34 -06:00
Thierry Treyer
37b25bb278 Fix exclusive_size for F14NodeSet 2023-10-09 10:41:34 -06:00
Thierry Treyer
7836134343 Fix exclusive_size for F14VectorSet 2023-10-09 10:41:34 -06:00
Thierry Treyer
cc12264847 Fix exclusive_size for F14FastSet 2023-10-09 10:41:34 -06:00
Thierry Treyer
76adc64723 Fix exclusive_size for F14ValueSet 2023-10-09 10:41:34 -06:00
Thierry Treyer
f4a1bd3d99 Remove Primitive::Kind::Incomplete 2023-10-04 11:23:28 -06:00
Thierry Treyer
3065dd14e9 Maintain type/name of Incomplete type 2023-10-04 11:23:28 -06: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
Alastair Robertson
35d45c2b4f folly::sorted_vector_map: Add key-capture support 2023-09-29 11:21:41 -07:00
Alastair Robertson
fb66f3ea05 CaptureKeys: Add test for capturing object pointers 2023-09-28 19:42:49 -07:00
Alastair Robertson
5572e294f7 CaptureKeys: Add support for std::map and std::unordered_map 2023-09-28 19:42:49 -07:00
Alastair Robertson
3446339358 TypeGraph: Add KeyCapture pass 2023-09-28 19:42:49 -07:00
Alastair Robertson
0ae08addc9 TypeGraph: Add CaptureKeys node 2023-09-28 19:42:49 -07:00
Jake Hillion
edb7bf5f3f Implement Container V2 for folly::sorted_vector_set 2023-09-27 19:06:20 -07:00
Jake Hillion
8bad704d9c Implement Container V2 for fbstring 2023-09-27 18:16:36 -07:00
Alastair Robertson
bd826f9794 CodeGen: Store list of ContainerInfos in unique_ptrs for reference stability
Lots of places rely on reference stability of ContainerInfo objects
(CodeGen's deduplication, Container nodes' containerInfo_ member).

In the key capture work, we need to be able to append to this list,
which would invalidate references before this change.
2023-09-22 17:10:56 +01:00
Jake Hillion
5632738d97 make StubbedPointer an explicit C++ type 2023-09-22 11:49:50 +01:00
Jake Hillion
c766d7b572 codegen: generate enums as enum class 2023-09-20 18:13:45 +01:00
Alastair Robertson
a509354624 DrgnParser: Options should default to false
We only want to do the extra work if it's explicitly requested.

chaseRawPointers is already explicitly requested whenever it's needed
and readEnumValues currently isn't needed at all.
2023-09-19 18:32:37 +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
Thierry Treyer
331c47705c Implement Container V2 for folly::small_vector 2023-09-08 16:34:34 +02:00