Skip to content

Commit

Permalink
tbv2: account for duplicate types when emitting name providers
Browse files Browse the repository at this point in the history
ClangTypeParser has emitted a duplicate type for `std::allocatr<int8_t>`.
Rather than fixing this, add the same check the compiler will do for the
duplicate templates that `addNames` emits. That is, `template<>
NameProvider<Foo>` will collide if `Foo` is used twice. We can do this by
adding a set of these strings for now. If this shows up regularly it will
likely make sense to deduplicate the type graph with a deduplication pass.

Test plan:
- Fixes the issue in prod. This change is quite logical.
  • Loading branch information
JakeHillion committed Dec 20, 2023
1 parent 5a2ca8b commit 6d898be
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions oi/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,13 @@ template <typename T>
struct NameProvider {};
)";

// TODO: stop types being duplicated at this point and remove this check
std::unordered_set<std::string_view> emittedTypes;
for (const Type& t : typeGraph.finalTypes) {
if (dynamic_cast<const Typedef*>(&t))
continue;
if (!emittedTypes.emplace(t.name()).second)
continue;

code += "template <> struct NameProvider<";
code += t.name();
Expand Down

0 comments on commit 6d898be

Please sign in to comment.