Revert "[CodeView] Provide a common interface for type collections."

This is a squash of ~5 reverts of, well, pretty much everything
I did today.  Something is seriously broken with lit on Windows
right now, and as a result assertions that fire in tests are
triggering failures.  I've been breaking non-Windows bots all
day which has seriously confused me because all my tests have
been passing, and after running lit with -a to view the output
even on successful runs, I find out that the tool is crashing
and yet lit is still reporting it as a success!

At this point I don't even know where to start, so rather than
leave the tree broken for who knows how long, I will get this
back to green, and then once lit is fixed on Windows, hopefully
hopefully fix the remaining set of problems for real.

llvm-svn: 303409
diff --git a/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp b/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
index 0ca24c7..9ff37e9 100644
--- a/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
+++ b/llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
@@ -11,12 +11,14 @@
 
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
-#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
+#include "llvm/DebugInfo/CodeView/RandomAccessTypeVisitor.h"
+#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
 #include "llvm/DebugInfo/CodeView/TypeRecordMapping.h"
 #include "llvm/DebugInfo/CodeView/TypeSerializer.h"
 #include "llvm/DebugInfo/CodeView/TypeServerHandler.h"
 #include "llvm/DebugInfo/CodeView/TypeTableBuilder.h"
+#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
 #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
 #include "llvm/DebugInfo/PDB/Native/RawTypes.h"
 #include "llvm/Support/Allocator.h"
@@ -128,16 +130,20 @@
 
   void SetUp() override {
     TestState = llvm::make_unique<PerTestState>();
+
+    TestState->Pipeline.addCallbackToPipeline(TestState->Deserializer);
+    TestState->Pipeline.addCallbackToPipeline(TestState->Callbacks);
   }
 
   void TearDown() override { TestState.reset(); }
 
 protected:
-  bool ValidateDatabaseRecord(LazyRandomTypeCollection &Types, uint32_t Index) {
+  bool ValidateDatabaseRecord(const RandomAccessTypeVisitor &Visitor,
+                              uint32_t Index) {
     TypeIndex TI = TypeIndex::fromArrayIndex(Index);
-    if (!Types.contains(TI))
+    if (!Visitor.database().contains(TI))
       return false;
-    if (GlobalState->TypeVector[Index] != Types.getType(TI))
+    if (GlobalState->TypeVector[Index] != Visitor.database().getTypeRecord(TI))
       return false;
     return true;
   }
@@ -178,6 +184,8 @@
   struct PerTestState {
     FixedStreamArray<TypeIndexOffset> Offsets;
 
+    TypeVisitorCallbackPipeline Pipeline;
+    TypeDeserializer Deserializer;
     MockCallbacks Callbacks;
   };
 
@@ -210,22 +218,21 @@
 
 TEST_F(RandomAccessVisitorTest, MultipleVisits) {
   TestState->Offsets = createPartialOffsets(GlobalState->Stream, {0, 8});
-  LazyRandomTypeCollection Types(GlobalState->TypeArray,
-                                 GlobalState->TypeVector.size(),
-                                 TestState->Offsets);
+  RandomAccessTypeVisitor Visitor(GlobalState->TypeArray,
+                                  GlobalState->TypeVector.size(),
+                                  TestState->Offsets);
 
   std::vector<uint32_t> IndicesToVisit = {5, 5, 5};
 
   for (uint32_t I : IndicesToVisit) {
     TypeIndex TI = TypeIndex::fromArrayIndex(I);
-    CVType T = Types.getType(TI);
-    EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks));
+    EXPECT_NO_ERROR(Visitor.visitTypeIndex(TI, TestState->Pipeline));
   }
 
   // [0,8) should be present
-  EXPECT_EQ(8u, Types.size());
+  EXPECT_EQ(8u, Visitor.database().size());
   for (uint32_t I = 0; I < 8; ++I)
-    EXPECT_TRUE(ValidateDatabaseRecord(Types, I));
+    EXPECT_TRUE(ValidateDatabaseRecord(Visitor, I));
 
   // 5, 5, 5
   EXPECT_EQ(3u, TestState->Callbacks.count());
@@ -241,19 +248,19 @@
 
   std::vector<uint32_t> IndicesToVisit = {7, 4, 2};
 
-  LazyRandomTypeCollection Types(GlobalState->TypeArray,
-                                 GlobalState->TypeVector.size(),
-                                 TestState->Offsets);
+  RandomAccessTypeVisitor Visitor(GlobalState->TypeArray,
+                                  GlobalState->TypeVector.size(),
+                                  TestState->Offsets);
+
   for (uint32_t I : IndicesToVisit) {
     TypeIndex TI = TypeIndex::fromArrayIndex(I);
-    CVType T = Types.getType(TI);
-    EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks));
+    EXPECT_NO_ERROR(Visitor.visitTypeIndex(TI, TestState->Pipeline));
   }
 
   // [0, 7]
-  EXPECT_EQ(8u, Types.size());
+  EXPECT_EQ(8u, Visitor.database().size());
   for (uint32_t I = 0; I < 8; ++I)
-    EXPECT_TRUE(ValidateDatabaseRecord(Types, I));
+    EXPECT_TRUE(ValidateDatabaseRecord(Visitor, I));
 
   // 2, 4, 7
   EXPECT_EQ(3u, TestState->Callbacks.count());
@@ -269,19 +276,19 @@
 
   std::vector<uint32_t> IndicesToVisit = {2, 4, 7};
 
-  LazyRandomTypeCollection Types(GlobalState->TypeArray,
-                                 GlobalState->TypeVector.size(),
-                                 TestState->Offsets);
+  RandomAccessTypeVisitor Visitor(GlobalState->TypeArray,
+                                  GlobalState->TypeVector.size(),
+                                  TestState->Offsets);
+
   for (uint32_t I : IndicesToVisit) {
     TypeIndex TI = TypeIndex::fromArrayIndex(I);
-    CVType T = Types.getType(TI);
-    EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks));
+    EXPECT_NO_ERROR(Visitor.visitTypeIndex(TI, TestState->Pipeline));
   }
 
   // [0, 7]
-  EXPECT_EQ(8u, Types.size());
+  EXPECT_EQ(8u, Visitor.database().size());
   for (uint32_t I = 0; I < 8; ++I)
-    EXPECT_TRUE(ValidateDatabaseRecord(Types, I));
+    EXPECT_TRUE(ValidateDatabaseRecord(Visitor, I));
 
   // 2, 4, 7
   EXPECT_EQ(3u, TestState->Callbacks.count());
@@ -298,20 +305,19 @@
 
   std::vector<uint32_t> IndicesToVisit = {0, 1, 2};
 
-  LazyRandomTypeCollection Types(GlobalState->TypeArray,
-                                 GlobalState->TypeVector.size(),
-                                 TestState->Offsets);
+  RandomAccessTypeVisitor Visitor(GlobalState->TypeArray,
+                                  GlobalState->TypeVector.size(),
+                                  TestState->Offsets);
 
   for (uint32_t I : IndicesToVisit) {
     TypeIndex TI = TypeIndex::fromArrayIndex(I);
-    CVType T = Types.getType(TI);
-    EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks));
+    EXPECT_NO_ERROR(Visitor.visitTypeIndex(TI, TestState->Pipeline));
   }
 
   // [0, 8) should be visited.
-  EXPECT_EQ(8u, Types.size());
+  EXPECT_EQ(8u, Visitor.database().size());
   for (uint32_t I = 0; I < 8; ++I)
-    EXPECT_TRUE(ValidateDatabaseRecord(Types, I));
+    EXPECT_TRUE(ValidateDatabaseRecord(Visitor, I));
 
   // [0, 2]
   EXPECT_EQ(3u, TestState->Callbacks.count());
@@ -327,20 +333,19 @@
 
   std::vector<uint32_t> IndicesToVisit = {5, 7};
 
-  LazyRandomTypeCollection Types(GlobalState->TypeArray,
-                                 GlobalState->TypeVector.size(),
-                                 TestState->Offsets);
+  RandomAccessTypeVisitor Visitor(GlobalState->TypeArray,
+                                  GlobalState->TypeVector.size(),
+                                  TestState->Offsets);
 
   for (uint32_t I : IndicesToVisit) {
     TypeIndex TI = TypeIndex::fromArrayIndex(I);
-    CVType T = Types.getType(TI);
-    EXPECT_NO_ERROR(codeview::visitTypeRecord(T, TI, TestState->Callbacks));
+    EXPECT_NO_ERROR(Visitor.visitTypeIndex(TI, TestState->Pipeline));
   }
 
   // [4, 9)
-  EXPECT_EQ(5u, Types.size());
+  EXPECT_EQ(5u, Visitor.database().size());
   for (uint32_t I = 4; I < 9; ++I)
-    EXPECT_TRUE(ValidateDatabaseRecord(Types, I));
+    EXPECT_TRUE(ValidateDatabaseRecord(Visitor, I));
 
   // 5, 7
   EXPECT_EQ(2u, TestState->Callbacks.count());