Commit Graph

24 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Alastair Robertson
03429f3da9 TypeGraph: Remove NodeTracker from the TypeGraph class
The TypeGraph class should only be responsible for storing Type nodes.
Traversing the graph and tracking which nodes have been visited should
not be included there.

Passes now take a NodeTrackerHolder as an input parameter, which
provides access to a zeroed-out NodeTracker.
2023-08-24 15:01:45 +01:00
Jake Hillion
5071519e45 oil v2 2023-08-23 15:59:53 +01:00
Alastair Robertson
373dbe8f6c TypeGraph: Add option to record enumerator names 2023-08-17 15:47:23 +01:00
Jake Hillion
a2f7462a5d DrgnParser: store type of template param value 2023-08-17 15:40:34 +01:00
Alastair Robertson
ff31971bd3 Printer: Use NodeIds for stable IDs when printing graphs
This removes Printer's legacy behaviour of generating an ID for each
node as it gets printed. This old method meant that if new nodes were
added to or removed from a graph, every ID after the new/removed node
would change.

Now IDs are stable so it is easier to follow specific nodes through
multiple transformation passes in CodeGen.
2023-08-16 12:19:14 +01:00
Alastair Robertson
6fbb60826f
EnforceCompatibility: Stub out void pointers
CodeGen v1 does not record anything for pointers to incomplete types.
Not even the address, as is done for other pointers.

Introduce a new Primitive type "Incomplete". This behaves identically to
"Void", but allows us to tell whether a type was defined as void or if
it ended up like that because of incomplete DWARF information.
2023-07-31 14:28:05 +01:00
Alastair Robertson
bc895dc9cc DrgnParser: Always stub function pointers
This makes CodeGen v2 behave the same as CodeGen v1, and there doesn't
seem much point in following function pointers either.
2023-07-26 11:30:01 +01:00
Alastair Robertson
94f8c1db49 DrgnParserTest: Split into reusable components 2023-07-11 13:52:39 +01:00
Alastair Robertson
e1b16a3d7e TypeGraph: Switch from pointers to references
References must always have a value, so are semantically clearer than
pointers for variables which must always be set.

No functional changes.
2023-07-06 17:24:33 +01:00
Alastair Robertson
e86ebb7aff TypeGraph: Support bitfields
- Change member and parent offsets to work in bits, not bytes
- Printer still displays offsets in bytes, with decimals when using
  bitfields
- AddPadding: Don't pad bitfields
- CodeGen: Emit code for bitfields
2023-07-05 13:23:23 +01:00
Alastair Robertson
4bfa932b9b DrgnParser: Handle enum values in template params
We want to use the fully qualified name for scoped enums to keep the C++
compiler happy. When a parameter expects an enum value, we must supply
an enum value and not its underlying integer value.

Before:
  isset_bitset<1, 0>

After:
  isset_bitset<1, apache::thrift::detail::IssetBitsetOption::Unpacked>
2023-06-26 15:13:21 +01:00
Alastair Robertson
6dce2d1c33 Printer: Improvements for displaying large type graphs
- Don't truncate output above 30k characters
- Include enough padding at the begining of lines to account for large
  node IDs
2023-06-23 15:55:42 +01:00
Alastair Robertson
bd919ae4e4 TypeGraph: Add core code
This code mostly works, but is obviously not complete. This commit just
adds the code and tests, but does not enable it in OID or OIL.
2023-05-30 13:27:23 +01:00