[clang-tools-extra] Reapply "[clang-doc] Move Info types into arenas (#190054)" (PR #192495)

via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 16 10:44:34 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: Paul Kirth (ilovepi)

<details>
<summary>Changes</summary>

This base patch was reverted to unbreak darwin-x86 bots, but the
issue was in a later patch that was tested together with this base
patch (e.g. they were batched together in the build bot). In that case
this can be relanded.

---
Original PR text:

Info types used to own significant chunks of data. As we move these into
local arenas, these types must be trivially destructible, to avoid
leaking resources when the arena is reset. Unfortunatly, there isn't a
good way to transition all the data types one at a time, since most of
them are tied together in some way. Further, as they're now allocated in
the arenas, they often cannot be treated the same way, and even the
aliases and interfaces put in place to simplify the transition cannot
cover the full range of changes required.

We also use some SFINAE tricks to avoid adding boilerplate for helper
APIs, we'd otherwise have to support

Though it introduces some additional churn, we also try to keep tests
from using arena allocation as much as possible, since this is not
required to test the implementation of the library. As much of the test
code needed to be rewritten anyway, we take the opportunity to
transition now.

We see a large improvement in overall memory use, dropping by 15% over
the previous patches, and taking the total savings down to almost 54%.
Performance numbers stay mostly flat, but merging is vastly improved,
seeing a reduction of 40+% over the previous patch, and a 90% reduction
overall.

| Metric | Baseline | Prev | This | Culm% | Seq% |
| :--- | :--- | :--- | :--- | :--- | :--- |
| Time | 920.5s | 1013.6s | 1014.5s | +10.2% | +0.1% |
| Memory | 86.0G | 47.3G | 39.9G | -53.6% | -15.6% |

| Benchmark | Baseline | Prev | This | Culm% | Seq% |
| :--- | :--- | :--- | :--- | :--- | :--- |
| BM_BitcodeReader_Scale/10 | 67.9us | 69.1us | 73.0us | +7.5% | +5.8% |
| BM_BitcodeReader_Scale/10000 | 70.5ms | 24.5ms | 17.1ms | -75.8% | -30.4% |
| BM_BitcodeReader_Scale/4096 | 23.2ms | 4.5ms | 6.5ms | -71.9% | +45.1% |
| BM_BitcodeReader_Scale/512 | 509.4us | 540.3us | 850.1us | +66.9% | +57.4% |
| BM_BitcodeReader_Scale/64 | 114.8us | 117.3us | 140.6us | +22.5% | +19.9% |
| BM_EmitInfoFunction | 1.6us | 1.6us | 1.8us | +12.9% | +15.0% |
| BM_Index_Insertion/10 | 2.3us | 4.2us | 4.1us | +79.5% | -1.1% |
| BM_Index_Insertion/10000 | 3.1ms | 5.2ms | 5.4ms | +71.1% | +3.7% |
| BM_Index_Insertion/4096 | 1.3ms | 2.1ms | 2.1ms | +64.9% | +2.0% |
| BM_Index_Insertion/512 | 153.6us | 244.7us | 252.9us | +64.7% | +3.3% |
| BM_Index_Insertion/64 | 18.1us | 29.1us | 30.4us | +68.3% | +4.4% |
| BM_JSONGenerator_Scale/10 | 36.8us | 38.3us | 38.1us | +3.5% | -0.4% |
| BM_JSONGenerator_Scale/10000 | 89.6ms | 90.8ms | 84.2ms | -6.0% | -7.2% |
| BM_JSONGenerator_Scale/4096 | 33.7ms | 35.9ms | 32.1ms | -4.7% | -10.5% |
| BM_JSONGenerator_Scale/512 | 1.9ms | 2.0ms | 2.0ms | +3.1% | +0.4% |
| BM_JSONGenerator_Scale/64 | 222.4us | 231.9us | 232.5us | +4.5% | +0.2% |
| BM_Mapper_Scale/10000 | 104.3ms | 104.9ms | 102.1ms | -2.1% | -2.7% |
| BM_Mapper_Scale/4096 | 44.3ms | 44.4ms | 46.5ms | +4.9% | +4.9% |
| BM_Mapper_Scale/512 | 7.6ms | 7.6ms | 7.4ms | -2.1% | -1.8% |
| BM_Mapper_Scale/64 | 3.1ms | 3.0ms | 3.0ms | -1.3% | -0.0% |
| BM_MergeInfos_Scale/10000 | 12.2ms | 1.9ms | 931.2us | -92.4% | -49.8% |
| BM_MergeInfos_Scale/2 | 1.9us | 1.7us | 1.8us | -4.5% | +4.7% |
| BM_MergeInfos_Scale/4096 | 2.8ms | 521.8us | 201.3us | -92.8% | -61.4% |
| BM_MergeInfos_Scale/512 | 68.9us | 34.9us | 19.9us | -71.2% | -43.1% |
| BM_MergeInfos_Scale/64 | 10.3us | 5.8us | 4.1us | -59.8% | -28.4% |
| BM_MergeInfos_Scale/8 | 2.8us | 2.1us | 1.9us | -33.3% | -12.6% |
| BM_SerializeFunctionInfo | 25.5us | 26.0us | 26.2us | +2.4% | +0.8% |

---

Patch is 181.50 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/192495.diff


20 Files Affected:

- (modified) clang-tools-extra/clang-doc/BitcodeReader.cpp (+419-187) 
- (modified) clang-tools-extra/clang-doc/BitcodeReader.h (+20) 
- (modified) clang-tools-extra/clang-doc/JSONGenerator.cpp (+28-17) 
- (modified) clang-tools-extra/clang-doc/MDGenerator.cpp (+4-5) 
- (modified) clang-tools-extra/clang-doc/Mapper.cpp (+3) 
- (modified) clang-tools-extra/clang-doc/Representation.cpp (+12-34) 
- (modified) clang-tools-extra/clang-doc/Representation.h (+59-49) 
- (modified) clang-tools-extra/clang-doc/Serialize.cpp (+133-71) 
- (modified) clang-tools-extra/clang-doc/Serialize.h (+10-8) 
- (modified) clang-tools-extra/clang-doc/YAMLGenerator.cpp (+66-12) 
- (modified) clang-tools-extra/clang-doc/benchmarks/ClangDocBenchmark.cpp (+4-3) 
- (modified) clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp (+72-41) 
- (modified) clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp (+185-89) 
- (modified) clang-tools-extra/unittests/clang-doc/ClangDocTest.h (+22-15) 
- (modified) clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp (+4-2) 
- (modified) clang-tools-extra/unittests/clang-doc/JSONGeneratorTest.cpp (+52-31) 
- (modified) clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp (+48-25) 
- (modified) clang-tools-extra/unittests/clang-doc/MergeTest.cpp (+201-134) 
- (modified) clang-tools-extra/unittests/clang-doc/SerializeTest.cpp (+246-189) 
- (modified) clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp (+71-41) 


``````````diff
diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index b7f4d6aa7ba23..c5e848ae4c28d 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -129,14 +129,15 @@ static llvm::Error decodeRecord(const Record &R, FieldId &Field,
                                  "invalid value for FieldId");
 }
 
-static llvm::Error decodeRecord(const Record &R,
-                                llvm::SmallVectorImpl<Location> &Field,
+static llvm::Error decodeRecord(const Record &R, OwningVec<Location> &Field,
                                 llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
                                    "integer too large to parse");
-  Field.emplace_back(static_cast<int>(R[0]), static_cast<int>(R[1]), Blob,
-                     static_cast<bool>(R[2]));
+
+  Field.push_back(*allocatePtr<Location>(static_cast<int>(R[0]),
+                                         static_cast<int>(R[1]), Blob,
+                                         static_cast<bool>(R[2])));
   return llvm::Error::success();
 }
 
@@ -425,6 +426,99 @@ ClangDocBitcodeReader::parseBlock(unsigned ID, T I, BlockBeginHandler &&BBH,
   }
 }
 
+template <typename T, typename BlockBeginHandler, typename BlockEndHandler>
+llvm::Error ClangDocBitcodeReader::parseBlock(unsigned ID, T I,
+                                              BlockBeginHandler &&BBH,
+                                              BlockEndHandler &&BEH) {
+  return parseBlock(ID, I, std::forward<BlockBeginHandler>(BBH),
+                    std::forward<BlockEndHandler>(BEH),
+                    [&](unsigned Code) { return readRecord(Code, I); });
+}
+
+template <typename ChildType>
+llvm::Expected<bool> ClangDocBitcodeReader::readSubBlockIfMatch(
+    unsigned ID, unsigned TargetID, llvm::SmallVectorImpl<ChildType> &V) {
+  if (ID != TargetID)
+    return false;
+  ChildType Val;
+  if (auto Err = readBlock(ID, &Val))
+    return std::move(Err);
+  V.push_back(std::move(Val));
+  return true;
+}
+
+template <typename T>
+static llvm::Error addReference(T I, Reference &&R, FieldId F);
+
+template <> llvm::Error addReference(VarInfo *I, Reference &&R, FieldId F);
+template <> llvm::Error addReference(TypeInfo *I, Reference &&R, FieldId F);
+template <>
+llvm::Error addReference(FieldTypeInfo *I, Reference &&R, FieldId F);
+template <>
+llvm::Error addReference(MemberTypeInfo *I, Reference &&R, FieldId F);
+template <> llvm::Error addReference(EnumInfo *I, Reference &&R, FieldId F);
+template <> llvm::Error addReference(TypedefInfo *I, Reference &&R, FieldId F);
+template <>
+llvm::Error addReference(NamespaceInfo *I, Reference &&R, FieldId F);
+template <> llvm::Error addReference(FunctionInfo *I, Reference &&R, FieldId F);
+template <> llvm::Error addReference(RecordInfo *I, Reference &&R, FieldId F);
+template <>
+llvm::Error addReference(ConstraintInfo *I, Reference &&R, FieldId F);
+template <>
+llvm::Error addReference(FriendInfo *Friend, Reference &&R, FieldId F);
+
+template <typename InfoT>
+llvm::Expected<bool> ClangDocBitcodeReader::routeReferenceBlock(
+    unsigned ID, llvm::SmallVectorImpl<Reference> &Namespaces, InfoT *I,
+    std::initializer_list<ReferenceMap> Mappings) {
+  if (ID != BI_REFERENCE_BLOCK_ID)
+    return false;
+  Reference R;
+  if (auto Err = readBlock(ID, &R))
+    return std::move(Err);
+
+  for (const auto &Map : Mappings) {
+    if (CurrentReferenceField == Map.Field) {
+      Map.Vec->push_back(std::move(R));
+      return true;
+    }
+  }
+
+  if (CurrentReferenceField == FieldId::F_namespace) {
+    Namespaces.push_back(std::move(R));
+    return true;
+  }
+
+  if (auto Err = addReference(I, std::move(R), CurrentReferenceField))
+    return std::move(Err);
+
+  return true;
+}
+
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, CommentInfo *I);
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, FunctionInfo *I);
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, EnumInfo *I);
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, BaseRecordInfo *I);
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, RecordInfo *I);
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, TemplateInfo *I);
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID,
+                                             TemplateSpecializationInfo *I);
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, VarInfo *I);
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, TypedefInfo *I);
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, NamespaceInfo *I);
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, FriendInfo *I);
+
 template <>
 llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, CommentInfo *I) {
   llvm::SmallVector<CommentInfo> LocalChildren;
@@ -448,25 +542,13 @@ llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, CommentInfo *I) {
         if (!LocalChildren.empty())
           I->Children =
               allocateArray<CommentInfo>(LocalChildren, TransientArena);
-        if (!AttrKeys.empty()) {
-          StringRef *KeysMem =
-              TransientArena.Allocate<StringRef>(AttrKeys.size());
-          std::uninitialized_copy(AttrKeys.begin(), AttrKeys.end(), KeysMem);
-          I->AttrKeys = llvm::ArrayRef<StringRef>(KeysMem, AttrKeys.size());
-        }
-        if (!AttrValues.empty()) {
-          StringRef *ValuesMem =
-              TransientArena.Allocate<StringRef>(AttrValues.size());
-          std::uninitialized_copy(AttrValues.begin(), AttrValues.end(),
-                                  ValuesMem);
-          I->AttrValues =
-              llvm::ArrayRef<StringRef>(ValuesMem, AttrValues.size());
-        }
-        if (!Args.empty()) {
-          StringRef *ArgsMem = TransientArena.Allocate<StringRef>(Args.size());
-          std::uninitialized_copy(Args.begin(), Args.end(), ArgsMem);
-          I->Args = llvm::ArrayRef<StringRef>(ArgsMem, Args.size());
-        }
+        if (!AttrKeys.empty())
+          I->AttrKeys = allocateArray(AttrKeys, TransientArena);
+        if (!AttrValues.empty())
+          I->AttrValues = allocateArray(AttrValues, TransientArena);
+        if (!Args.empty())
+          I->Args = allocateArray(Args, TransientArena);
+
         return llvm::Error::success();
       },
       [&](unsigned BlockOrCode) -> llvm::Error {
@@ -481,6 +563,219 @@ llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, CommentInfo *I) {
       });
 }
 
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, FunctionInfo *I) {
+  llvm::SmallVector<FieldTypeInfo, 4> LocalParams;
+  llvm::SmallVector<Reference> LocalNamespaces;
+
+  return parseBlock(
+      ID, I,
+      [&](unsigned BlockOrCode) -> llvm::Expected<bool> {
+        auto B = readSubBlockIfMatch(BlockOrCode, BI_FIELD_TYPE_BLOCK_ID,
+                                     LocalParams);
+        if (!B)
+          return B.takeError();
+        if (*B)
+          return true;
+        return routeReferenceBlock(BlockOrCode, LocalNamespaces, I);
+      },
+      [&]() -> llvm::Error {
+        I->Params = allocateArray(LocalParams, TransientArena);
+        if (!LocalNamespaces.empty())
+          I->Namespace = allocateArray(LocalNamespaces, TransientArena);
+        return llvm::Error::success();
+      });
+}
+
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, EnumInfo *I) {
+  llvm::SmallVector<EnumValueInfo, 4> LocalMembers;
+  llvm::SmallVector<Reference> LocalNamespaces;
+
+  return parseBlock(
+      ID, I,
+      [&](unsigned BlockOrCode) -> llvm::Expected<bool> {
+        auto B = readSubBlockIfMatch(BlockOrCode, BI_ENUM_VALUE_BLOCK_ID,
+                                     LocalMembers);
+        if (!B)
+          return B.takeError();
+        if (*B)
+          return true;
+        return routeReferenceBlock(BlockOrCode, LocalNamespaces, I);
+      },
+      [&]() -> llvm::Error {
+        I->Members = allocateArray(LocalMembers, TransientArena);
+        if (!LocalNamespaces.empty())
+          I->Namespace = allocateArray(LocalNamespaces, TransientArena);
+        return llvm::Error::success();
+      });
+}
+
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, BaseRecordInfo *I) {
+  // BaseRecordInfo and FriendInfo are over 256 bytes and require a size.
+  llvm::SmallVector<BaseRecordInfo, 4> LocalBases;
+  llvm::SmallVector<FriendInfo, 4> LocalFriends;
+  llvm::SmallVector<MemberTypeInfo> LocalMembers;
+  llvm::SmallVector<Reference> LocalParents;
+  llvm::SmallVector<Reference> LocalVirtualParents;
+
+  return parseBlock(
+      ID, I,
+      [&](unsigned BlockOrCode) -> llvm::Expected<bool> {
+        auto B = readSubBlockIfMatch(BlockOrCode, BI_MEMBER_TYPE_BLOCK_ID,
+                                     LocalMembers);
+        if (!B)
+          return B.takeError();
+        if (*B)
+          return true;
+
+        B = readSubBlockIfMatch(BlockOrCode, BI_BASE_RECORD_BLOCK_ID,
+                                LocalBases);
+        if (!B)
+          return B.takeError();
+        if (*B)
+          return true;
+
+        B = readSubBlockIfMatch(BlockOrCode, BI_FRIEND_BLOCK_ID, LocalFriends);
+        if (!B)
+          return B.takeError();
+        if (*B)
+          return true;
+
+        llvm::SmallVector<Reference> Dummy;
+        return routeReferenceBlock(
+            BlockOrCode, Dummy, I,
+            {{FieldId::F_parent, &LocalParents},
+             {FieldId::F_vparent, &LocalVirtualParents}});
+      },
+      [&]() -> llvm::Error {
+        if (!LocalMembers.empty())
+          I->Members = allocateArray(LocalMembers, TransientArena);
+        if (!LocalParents.empty())
+          I->Parents = allocateArray(LocalParents, TransientArena);
+        if (!LocalVirtualParents.empty())
+          I->VirtualParents =
+              allocateArray(LocalVirtualParents, TransientArena);
+        I->Bases = allocateArray(LocalBases, TransientArena);
+        I->Friends = allocateArray(LocalFriends, TransientArena);
+        return llvm::Error::success();
+      });
+}
+
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, RecordInfo *I) {
+  llvm::SmallVector<BaseRecordInfo, 4> LocalBases;
+  llvm::SmallVector<FriendInfo, 4> LocalFriends;
+  llvm::SmallVector<MemberTypeInfo> LocalMembers;
+  llvm::SmallVector<Reference> LocalParents;
+  llvm::SmallVector<Reference> LocalVirtualParents;
+  llvm::SmallVector<Reference> LocalNamespaces;
+
+  return parseBlock(
+      ID, I,
+      [&](unsigned BlockOrCode) -> llvm::Expected<bool> {
+        auto B = readSubBlockIfMatch(BlockOrCode, BI_MEMBER_TYPE_BLOCK_ID,
+                                     LocalMembers);
+        if (!B)
+          return B.takeError();
+        if (*B)
+          return true;
+
+        B = readSubBlockIfMatch(BlockOrCode, BI_BASE_RECORD_BLOCK_ID,
+                                LocalBases);
+        if (!B)
+          return B.takeError();
+        if (*B)
+          return true;
+
+        B = readSubBlockIfMatch(BlockOrCode, BI_FRIEND_BLOCK_ID, LocalFriends);
+        if (!B)
+          return B.takeError();
+        if (*B)
+          return true;
+
+        return routeReferenceBlock(
+            BlockOrCode, LocalNamespaces, I,
+            {{FieldId::F_parent, &LocalParents},
+             {FieldId::F_vparent, &LocalVirtualParents}});
+      },
+      [&]() -> llvm::Error {
+        if (!LocalMembers.empty())
+          I->Members = allocateArray(LocalMembers, TransientArena);
+        if (!LocalParents.empty())
+          I->Parents = allocateArray(LocalParents, TransientArena);
+        if (!LocalVirtualParents.empty())
+          I->VirtualParents =
+              allocateArray(LocalVirtualParents, TransientArena);
+        if (!LocalNamespaces.empty())
+          I->Namespace = allocateArray(LocalNamespaces, TransientArena);
+        I->Bases = allocateArray(LocalBases, TransientArena);
+        I->Friends = allocateArray(LocalFriends, TransientArena);
+        return llvm::Error::success();
+      });
+}
+
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID, TemplateInfo *I) {
+  llvm::SmallVector<TemplateParamInfo> LocalParams;
+  llvm::SmallVector<ConstraintInfo> LocalConstraints;
+
+  return parseBlock(
+      ID, I,
+      [&](unsigned BlockOrCode) -> llvm::Expected<bool> {
+        auto B = readSubBlockIfMatch(BlockOrCode, BI_TEMPLATE_PARAM_BLOCK_ID,
+                                     LocalParams);
+        if (!B)
+          return B.takeError();
+        if (*B)
+          return true;
+
+        B = readSubBlockIfMatch(BlockOrCode, BI_CONSTRAINT_BLOCK_ID,
+                                LocalConstraints);
+        if (!B)
+          return B.takeError();
+        if (*B)
+          return true;
+
+        return false;
+      },
+      [&]() -> llvm::Error {
+        I->Params = allocateArray(LocalParams, TransientArena);
+        I->Constraints = allocateArray(LocalConstraints, TransientArena);
+        return llvm::Error::success();
+      },
+      [&](unsigned BlockOrCode) -> llvm::Error {
+        return readRecord(BlockOrCode, I);
+      });
+}
+
+template <>
+llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID,
+                                             TemplateSpecializationInfo *I) {
+  llvm::SmallVector<TemplateParamInfo> LocalParams;
+
+  return parseBlock(
+      ID, I,
+      [&](unsigned BlockOrCode) -> llvm::Expected<bool> {
+        auto B = readSubBlockIfMatch(BlockOrCode, BI_TEMPLATE_PARAM_BLOCK_ID,
+                                     LocalParams);
+        if (!B)
+          return B.takeError();
+        if (*B)
+          return true;
+
+        return false;
+      },
+      [&]() -> llvm::Error {
+        I->Params = allocateArray(LocalParams, TransientArena);
+        return llvm::Error::success();
+      },
+      [&](unsigned BlockOrCode) -> llvm::Error {
+        return readRecord(BlockOrCode, I);
+      });
+}
+
 static llvm::Error parseRecord(const Record &R, unsigned ID,
                                llvm::StringRef Blob, Reference *I, FieldId &F) {
   switch (ID) {
@@ -579,51 +874,25 @@ static llvm::Error parseRecord(const Record &R, unsigned ID, StringRef Blob,
                                  "invalid field for Friend");
 }
 
+template <typename, typename = void>
+struct has_description : std::false_type {};
+template <typename T>
+struct has_description<T, std::void_t<decltype(std::declval<T>().Description)>>
+    : std::true_type {};
+
 template <typename T> static llvm::Expected<CommentInfo *> getCommentInfo(T I) {
+  if constexpr (std::is_pointer_v<T>) {
+    using Pointee = std::remove_pointer_t<T>;
+    if constexpr (has_description<Pointee>::value) {
+      auto *NewComment = allocatePtr<CommentInfo>();
+      I->Description.push_back(*NewComment);
+      return NewComment;
+    }
+  }
   return llvm::createStringError(llvm::inconvertibleErrorCode(),
                                  "invalid type cannot contain CommentInfo");
 }
 
-template <> llvm::Expected<CommentInfo *> getCommentInfo(FunctionInfo *I) {
-  return &I->Description.emplace_back();
-}
-
-template <> llvm::Expected<CommentInfo *> getCommentInfo(NamespaceInfo *I) {
-  return &I->Description.emplace_back();
-}
-
-template <> llvm::Expected<CommentInfo *> getCommentInfo(RecordInfo *I) {
-  return &I->Description.emplace_back();
-}
-
-template <> llvm::Expected<CommentInfo *> getCommentInfo(MemberTypeInfo *I) {
-  return &I->Description.emplace_back();
-}
-
-template <> llvm::Expected<CommentInfo *> getCommentInfo(EnumInfo *I) {
-  return &I->Description.emplace_back();
-}
-
-template <> llvm::Expected<CommentInfo *> getCommentInfo(TypedefInfo *I) {
-  return &I->Description.emplace_back();
-}
-
-template <> llvm::Expected<CommentInfo *> getCommentInfo(EnumValueInfo *I) {
-  return &I->Description.emplace_back();
-}
-
-template <> llvm::Expected<CommentInfo *> getCommentInfo(ConceptInfo *I) {
-  return &I->Description.emplace_back();
-}
-
-template <> Expected<CommentInfo *> getCommentInfo(VarInfo *I) {
-  return &I->Description.emplace_back();
-}
-
-template <> Expected<CommentInfo *> getCommentInfo(FriendInfo *I) {
-  return &I->Description.emplace_back();
-}
-
 // When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on
 // the parent block to set it. The template specializations define what to do
 // for each supported parent block.
@@ -633,26 +902,11 @@ static llvm::Error addTypeInfo(T I, TTypeInfo &&TI) {
                                  "invalid type cannot contain TypeInfo");
 }
 
-template <> llvm::Error addTypeInfo(RecordInfo *I, MemberTypeInfo &&T) {
-  I->Members.emplace_back(std::move(T));
-  return llvm::Error::success();
-}
-
-template <> llvm::Error addTypeInfo(BaseRecordInfo *I, MemberTypeInfo &&T) {
-  I->Members.emplace_back(std::move(T));
-  return llvm::Error::success();
-}
-
 template <> llvm::Error addTypeInfo(FunctionInfo *I, TypeInfo &&T) {
   I->ReturnType = std::move(T);
   return llvm::Error::success();
 }
 
-template <> llvm::Error addTypeInfo(FunctionInfo *I, FieldTypeInfo &&T) {
-  I->Params.emplace_back(std::move(T));
-  return llvm::Error::success();
-}
-
 template <> llvm::Error addTypeInfo(FriendInfo *I, TypeInfo &&T) {
   I->ReturnType.emplace(std::move(T));
   return llvm::Error::success();
@@ -681,9 +935,6 @@ static llvm::Error addReference(T I, Reference &&R, FieldId F) {
 
 template <> llvm::Error addReference(VarInfo *I, Reference &&R, FieldId F) {
   switch (F) {
-  case FieldId::F_namespace:
-    I->Namespace.emplace_back(std::move(R));
-    return llvm::Error::success();
   default:
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
                                    "VarInfo cannot contain this Reference");
@@ -727,9 +978,6 @@ llvm::Error addReference(MemberTypeInfo *I, Reference &&R, FieldId F) {
 
 template <> llvm::Error addReference(EnumInfo *I, Reference &&R, FieldId F) {
   switch (F) {
-  case FieldId::F_namespace:
-    I->Namespace.emplace_back(std::move(R));
-    return llvm::Error::success();
   default:
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
                                    "invalid type cannot contain Reference");
@@ -738,9 +986,6 @@ template <> llvm::Error addReference(EnumInfo *I, Reference &&R, FieldId F) {
 
 template <> llvm::Error addReference(TypedefInfo *I, Reference &&R, FieldId F) {
   switch (F) {
-  case FieldId::F_namespace:
-    I->Namespace.emplace_back(std::move(R));
-    return llvm::Error::success();
   default:
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
                                    "invalid type cannot contain Reference");
@@ -750,16 +995,13 @@ template <> llvm::Error addReference(TypedefInfo *I, Reference &&R, FieldId F) {
 template <>
 llvm::Error addReference(NamespaceInfo *I, Reference &&R, FieldId F) {
   switch (F) {
-  case FieldId::F_namespace:
-    I->Namespace.emplace_back(std::move(R));
-    return llvm::Error::success();
-  case FieldId::F_child_namespace: {
-    Reference *NewR = allocatePtr<Reference>(TransientArena, std::move(R));
-    I->Children.Namespaces.push_back(*NewR);
+  case FieldId::F_child_namespace:
+    I->Children.Namespaces.push_back(
+        *allocatePtr<Reference>(TransientArena, std::move(R)));
     return llvm::Error::success();
-  }
   case FieldId::F_child_record:
-    I->Children.Records.emplace_back(std::move(R));
+    I->Children.Records.push_back(
+        *allocatePtr<Reference>(TransientArena, std::move(R)));
     return llvm::Error::success();
   default:
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -770,9 +1012,6 @@ llvm::Error addReference(NamespaceInfo *I, Reference &&R, FieldId F) {
 template <>
 llvm::Error addReference(FunctionInfo *I, Reference &&R, FieldId F) {
   switch (F) {
-  case FieldId::F_namespace:
-    I->Namespace.emplace_back(std::move(R));
-    return llvm::Error::success();
   case FieldId::F_parent:
     I->Parent = std::move(R);
     return llvm::Error::success();
@@ -784,17 +1023,9 @@ llvm::Error addReference(FunctionInfo *I, Reference &&R, FieldId F) {
 
 te...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/192495


More information about the cfe-commits mailing list