Merge pull request #13821 from slavapestov/kill-unused-link-entities

Kill unused link entities
diff --git a/include/swift/IRGen/Linking.h b/include/swift/IRGen/Linking.h
index 678ff89..e05b5a1 100644
--- a/include/swift/IRGen/Linking.h
+++ b/include/swift/IRGen/Linking.h
@@ -108,10 +108,6 @@
 #define LINKENTITY_GET_FIELD(value, field) ((value & field##Mask) >> field##Shift)
 
   enum class Kind {
-    /// A function.
-    /// The pointer is a FuncDecl*.
-    Function,
-
     /// A field offset.  The pointer is a VarDecl*.
     FieldOffset,
 
@@ -143,13 +139,6 @@
     /// The pointer is a ProtocolDecl*.
     ProtocolDescriptor,
 
-    /// Some other kind of declaration.
-    /// The pointer is a Decl*.
-    Other,
-
-    /// A reflection metadata descriptor for the superclass of a class.
-    ReflectionSuperclassDescriptor,
-
     /// A SIL function. The pointer is a SILFunction*.
     SILFunction,
 
@@ -249,7 +238,7 @@
   }
 
   static bool isDeclKind(Kind k) {
-    return k <= Kind::ReflectionSuperclassDescriptor;
+    return k <= Kind::ProtocolDescriptor;
   }
   static bool isTypeKind(Kind k) {
     return k >= Kind::ProtocolWitnessTableLazyAccessFunction;
@@ -370,14 +359,6 @@
   LinkEntity() = default;
 
 public:
-  static LinkEntity forNonFunction(ValueDecl *decl) {
-    assert(!isFunction(decl));
-
-    LinkEntity entity;
-    entity.setForDecl(Kind::Other, decl);
-    return entity;
-  }
-
   static LinkEntity forFieldOffset(VarDecl *decl, bool isIndirect) {
     LinkEntity entity;
     entity.Pointer = decl;
@@ -580,13 +561,6 @@
     return entity;
   }
 
-  static LinkEntity
-  forReflectionSuperclassDescriptor(const ClassDecl *decl) {
-    LinkEntity entity;
-    entity.setForDecl(Kind::ReflectionSuperclassDescriptor, decl);
-    return entity;
-  }
-
 
   void mangle(llvm::raw_ostream &out) const;
   void mangle(SmallVectorImpl<char> &buffer) const;
diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp
index 497351a..74fb5ac 100644
--- a/lib/IRGen/GenDecl.cpp
+++ b/lib/IRGen/GenDecl.cpp
@@ -1257,8 +1257,6 @@
   case Kind::ObjCClassRef:
     return SILLinkage::Private;
 
-  case Kind::Function:
-  case Kind::Other:
   case Kind::ObjCClass:
   case Kind::ObjCMetaclass:
   case Kind::SwiftMetaclassStub:
@@ -1309,10 +1307,6 @@
     if (getLinkageAsConformance() == SILLinkage::Shared)
       return SILLinkage::Shared;
     return SILLinkage::Private;
-  case Kind::ReflectionSuperclassDescriptor:
-    if (getDeclLinkage(getDecl()) == FormalLinkage::PublicNonUnique)
-      return SILLinkage::Shared;
-    return SILLinkage::Private;
   }
   llvm_unreachable("bad link entity kind");
 }
@@ -1363,8 +1357,6 @@
   case Kind::ValueWitness:
   case Kind::TypeMetadataAccessFunction:
   case Kind::TypeMetadataLazyCacheVariable:
-  case Kind::Function:
-  case Kind::Other:
   case Kind::FieldOffset:
   case Kind::ProtocolWitnessTableAccessFunction:
   case Kind::ProtocolWitnessTableLazyAccessFunction:
@@ -1378,7 +1370,6 @@
   case Kind::ReflectionBuiltinDescriptor:
   case Kind::ReflectionFieldDescriptor:
   case Kind::ReflectionAssociatedTypeDescriptor:
-  case Kind::ReflectionSuperclassDescriptor:
     llvm_unreachable("Relative reference to unsupported link entity");
   }
   llvm_unreachable("bad link entity kind");
diff --git a/lib/IRGen/IRGenMangler.h b/lib/IRGen/IRGenMangler.h
index e6a031c..4617ea4 100644
--- a/lib/IRGen/IRGenMangler.h
+++ b/lib/IRGen/IRGenMangler.h
@@ -149,10 +149,6 @@
     return mangleConformanceSymbol(Type(), C, "MA");
   }
 
-  std::string mangleReflectionSuperclassDescriptor(const ClassDecl *Decl) {
-    return mangleNominalTypeSymbol(Decl, "MC");
-  }
-
   std::string mangleOutlinedCopyFunction(const GenericTypeDecl *Decl) {
     beginMangling();
     appendAnyGenericType(Decl);
diff --git a/lib/IRGen/Linking.cpp b/lib/IRGen/Linking.cpp
index fbe8201..a3fef9e 100644
--- a/lib/IRGen/Linking.cpp
+++ b/lib/IRGen/Linking.cpp
@@ -17,11 +17,7 @@
 #include "swift/IRGen/Linking.h"
 #include "IRGenMangler.h"
 #include "IRGenModule.h"
-#include "swift/ClangImporter/ClangImporter.h"
 #include "swift/SIL/SILGlobalVariable.h"
-#include "clang/AST/Attr.h"
-#include "clang/AST/Decl.h"
-#include "clang/AST/DeclObjC.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
@@ -50,14 +46,6 @@
   mangle(stream);
 }
 
-/// Use the Clang importer to mangle a Clang declaration.
-static void mangleClangDecl(raw_ostream &buffer,
-                            const clang::NamedDecl *clangDecl,
-                            ASTContext &ctx) {
-  auto *importer = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
-  importer->getMangledName(buffer, clangDecl);
-}
-
 /// Mangle this entity into the given stream.
 void LinkEntity::mangle(raw_ostream &buffer) const {
   std::string Result = mangleAsString();
@@ -141,46 +129,6 @@
                   getProtocolConformance(), assocConf.first, assocConf.second);
     }
 
-    case Kind::Function:
-      // As a special case, functions can have manually mangled names.
-      if (auto AsmA = getDecl()->getAttrs().getAttribute<SILGenNameAttr>())
-        if (!AsmA->Name.empty())
-          return AsmA->Name;
-
-      // Otherwise, fall through into the 'other decl' case.
-      LLVM_FALLTHROUGH;
-
-    case Kind::Other:
-      // As a special case, Clang functions and globals don't get mangled at all.
-      if (auto clangDecl = getDecl()->getClangDecl()) {
-        if (auto namedClangDecl = dyn_cast<clang::DeclaratorDecl>(clangDecl)) {
-          if (auto asmLabel = namedClangDecl->getAttr<clang::AsmLabelAttr>()) {
-            std::string Name(1, '\01');
-            Name.append(asmLabel->getLabel());
-            return Name;
-          }
-          if (namedClangDecl->hasAttr<clang::OverloadableAttr>()) {
-            // FIXME: When we can import C++, use Clang's mangler all the time.
-            std::string storage;
-            llvm::raw_string_ostream SS(storage);
-            mangleClangDecl(SS, namedClangDecl, getDecl()->getASTContext());
-            return SS.str();
-          }
-          return namedClangDecl->getName();
-        }
-      }
-
-      if (auto type = dyn_cast<NominalTypeDecl>(getDecl())) {
-        return mangler.mangleNominalType(type);
-      }
-      if (auto ctor = dyn_cast<ConstructorDecl>(getDecl())) {
-        // FIXME: Hack. LinkInfo should be able to refer to the allocating
-        // constructor rather than inferring it here.
-        return mangler.mangleConstructorEntity(ctor, /*isAllocating=*/true,
-                                               /*isCurried=*/false);
-      }
-      return mangler.mangleEntity(getDecl(), /*isCurried=*/false);
-
       // An Objective-C class reference reference. The symbol is private, so
       // the mangling is unimportant; it should just be readable in LLVM IR.
     case Kind::ObjCClassRef: {
@@ -221,9 +169,6 @@
     case Kind::ReflectionAssociatedTypeDescriptor:
       return mangler.mangleReflectionAssociatedTypeDescriptor(
                                                       getProtocolConformance());
-    case Kind::ReflectionSuperclassDescriptor:
-      return mangler.mangleReflectionSuperclassDescriptor(
-                                                    cast<ClassDecl>(getDecl()));
   }
   llvm_unreachable("bad entity kind!");
 }