tbv2: account for duplicate types when emitting name providers

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.
This commit is contained in:
Jake Hillion 2023-12-20 15:51:42 +00:00 committed by Jake Hillion
parent 5a2ca8b059
commit 6d898bed95

View File

@ -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();