Merge pull request #8455 from hughbe/build-support-fix-meanin

Use the directory name, not full directory in SwiftBuildSupport.SWIFT_REPO_NAME
diff --git a/docs/Android.md b/docs/Android.md
index c024088..b9fb5c9 100644
--- a/docs/Android.md
+++ b/docs/Android.md
@@ -118,7 +118,7 @@
     -target armv7-none-linux-androideabi \                                       # Targeting android-armv7.
     -sdk /path/to/android-ndk-r14/platforms/android-21/arch-arm \                # Use the same NDK path and API version as you used to build the stdlib in the previous step.
     -L /path/to/android-ndk-r14/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a \   # Link the Android NDK's libc++ and libgcc.
-    -L /path/to/android-ndk-r14/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9 \
+    -L /path/to/android-ndk-r14/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x \
     hello.swift
 ```
 
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 64887c1..4b55dec 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -2450,6 +2450,10 @@
 }
 
 bool ClassDecl::inheritsSuperclassInitializers(LazyResolver *resolver) {
+  // Get a resolver from the ASTContext if we don't have one already.
+  if (resolver == nullptr)
+    resolver = getASTContext().getLazyResolver();
+
   // Check whether we already have a cached answer.
   switch (static_cast<StoredInheritsSuperclassInits>(
             ClassDeclBits.InheritsSuperclassInits)) {
@@ -2490,8 +2494,10 @@
       return false;
 
     // Resolve this initializer, if needed.
-    if (!ctor->hasInterfaceType())
+    if (!ctor->hasInterfaceType()) {
+      assert(resolver && "Should have a resolver here");
       resolver->resolveDeclSignature(ctor);
+    }
 
     // Ignore any stub implementations.
     if (ctor->hasStubImplementation())
diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp
index e4bd09f..3c97a7f 100644
--- a/lib/IRGen/GenDecl.cpp
+++ b/lib/IRGen/GenDecl.cpp
@@ -1092,10 +1092,38 @@
                                   ForDefinition_t forDefinition) const {
   switch (getKind()) {
   // Most type metadata depend on the formal linkage of their type.
-  case Kind::ValueWitnessTable:
-    return getSILLinkage(getTypeLinkage(getType()), forDefinition);
+  case Kind::ValueWitnessTable: {
+    auto type = getType();
+
+    // Builtin types, (), () -> () and so on are in the runtime.
+    if (!type.getAnyNominal())
+      return getSILLinkage(FormalLinkage::PublicUnique, forDefinition);
+
+    // Imported types.
+    if (getTypeMetadataAccessStrategy(IGM, type) ==
+          MetadataAccessStrategy::NonUniqueAccessor)
+      return SILLinkage::Shared;
+
+    // Everything else is only referenced inside its module.
+    return SILLinkage::Private;
+  }
+
+  case Kind::TypeMetadataLazyCacheVariable: {
+    auto type = getType();
+
+    // Imported types, non-primitive structural types.
+    if (getTypeMetadataAccessStrategy(IGM, type) ==
+          MetadataAccessStrategy::NonUniqueAccessor)
+      return SILLinkage::Shared;
+
+    // Everything else is only referenced inside its module.
+    return SILLinkage::Private;
+  }
 
   case Kind::TypeMetadata:
+    if (isMetadataPattern())
+      return SILLinkage::Private;
+
     switch (getMetadataAddress()) {
     case TypeMetadataAddress::FullMetadata:
       // The full metadata object is private to the containing module.
@@ -1114,7 +1142,6 @@
     return SILLinkage::Shared;
 
   case Kind::TypeMetadataAccessFunction:
-  case Kind::TypeMetadataLazyCacheVariable:
     switch (getTypeMetadataAccessStrategy(IGM, getType())) {
     case MetadataAccessStrategy::PublicUniqueAccessor:
       return getSILLinkage(FormalLinkage::PublicUnique, forDefinition);
diff --git a/lib/Sema/TypeChecker.cpp b/lib/Sema/TypeChecker.cpp
index 160969b..7163f6e 100644
--- a/lib/Sema/TypeChecker.cpp
+++ b/lib/Sema/TypeChecker.cpp
@@ -714,13 +714,14 @@
 
     typeCheckFunctionsAndExternalDecls(TC);
   }
-  MyTC.reset();
 
   // Checking that benefits from having the whole module available.
   if (!(Options & TypeCheckingFlags::DelayWholeModuleChecking)) {
     performWholeModuleTypeChecking(SF);
   }
 
+  MyTC.reset();
+
   // Verify that we've checked types correctly.
   SF.ASTStage = SourceFile::TypeChecked;
 
diff --git a/lib/TBDGen/TBDGen.cpp b/lib/TBDGen/TBDGen.cpp
index 39a9979..b5d9430 100644
--- a/lib/TBDGen/TBDGen.cpp
+++ b/lib/TBDGen/TBDGen.cpp
@@ -37,7 +37,9 @@
   StringSet &Symbols;
 
   void addSymbol(StringRef name) {
-    assert(Symbols.insert(name).second && "already inserted");
+    auto isNewValue = Symbols.insert(name).second;
+    (void)isNewValue;
+    assert(isNewValue && "already inserted");
   }
 
   void visitValueTypeDecl(NominalTypeDecl *NTD) {
@@ -45,11 +47,6 @@
     if (isPrivateDecl(NTD))
       return;
 
-    auto declaredType = NTD->getDeclaredType()->getCanonicalType();
-
-    auto vwt = irgen::LinkEntity::forValueWitnessTable(declaredType);
-    addSymbol(vwt.mangleAsString());
-
     visitNominalTypeDecl(NTD);
   }
 
@@ -105,12 +102,6 @@
     if (isPrivateDecl(CD))
       return;
 
-    auto declaredType = CD->getDeclaredType()->getCanonicalType();
-
-    auto tmlcv =
-        irgen::LinkEntity::forTypeMetadataLazyCacheVariable(declaredType);
-    addSymbol(tmlcv.mangleAsString());
-
     visitNominalTypeDecl(CD);
   }
 
@@ -125,6 +116,9 @@
 
     // There's no relevant information about members of a protocol at individual
     // protocols, each conforming type has to handle them individually.
+
+    // FIXME: Eventually we might allow nominal type members of protocols.
+    // Should just visit that here or at least assert that there aren't any.
   }
 
   void visitVarDecl(VarDecl *VD);
diff --git a/test/IRGen/access_control.sil b/test/IRGen/access_control.sil
index bcb81a9..38a472d 100644
--- a/test/IRGen/access_control.sil
+++ b/test/IRGen/access_control.sil
@@ -4,23 +4,23 @@
 import Swift
 
 public struct PublicStruct { var x: Int }
-// CHECK: @_T014access_control12PublicStructVWV = {{(protected )?}}constant
+// CHECK: @_T014access_control12PublicStructVWV = internal constant
 // CHECK: @_T014access_control12PublicStructVMn = {{(protected )?}}constant
 // CHECK: @_T014access_control12PublicStructVMf = internal constant
 
 internal struct InternalStruct { var x: Int }
-// CHECK: @_T014access_control14InternalStructVWV = hidden constant
+// CHECK: @_T014access_control14InternalStructVWV = internal constant
 // CHECK: @_T014access_control14InternalStructVMn = hidden constant
 // CHECK: @_T014access_control14InternalStructVMf = internal constant
 
 private struct PrivateStruct { var x: Int }
-// CHECK: @_T014access_control13PrivateStruct33_8F630B0A1EEF3ED34B761E3ED76C95A8LLVWV = hidden constant
+// CHECK: @_T014access_control13PrivateStruct33_8F630B0A1EEF3ED34B761E3ED76C95A8LLVWV = internal constant
 // CHECK: @_T014access_control13PrivateStruct33_8F630B0A1EEF3ED34B761E3ED76C95A8LLVMn = hidden constant
 // CHECK: @_T014access_control13PrivateStruct33_8F630B0A1EEF3ED34B761E3ED76C95A8LLVMf = internal constant
 
 func local() {
   struct LocalStruct { var x: Int }
-  // CHECK: @_T014access_control5localyyF11LocalStructL_VWV = hidden constant
+  // CHECK: @_T014access_control5localyyF11LocalStructL_VWV = internal constant
   // CHECK: @_T014access_control5localyyF11LocalStructL_VMn = hidden constant
   // CHECK: @_T014access_control5localyyF11LocalStructL_VMf = internal constant
 }
diff --git a/test/IRGen/dllexport.swift b/test/IRGen/dllexport.swift
index b0ea8e6..416ef22 100644
--- a/test/IRGen/dllexport.swift
+++ b/test/IRGen/dllexport.swift
@@ -27,8 +27,6 @@
 // CHECK-DAG: @_T09dllexport2ciAA1cCv = dllexport global %T9dllexport1cC* null, align 4
 // CHECK-DAG: @_T09dllexport1pMp = dllexport constant %swift.protocol
 // CHECK-DAG: @_T09dllexport1cCMn = dllexport constant
-// CHECK-DAG: @_T09dllexport1cCML = dllexport global %swift.type* null, align 4
-// CHECK-DAG: @_T09dllexport1dCML = dllexport global %swift.type* null, align 4
 // CHECK-DAG: @_T09dllexport1cCN = dllexport alias %swift.type
 // CHECK-DAG: @_T09dllexport1dCN = dllexport alias %swift.type, bitcast ({{.*}})
 // CHECK-DAG-OPT: @_T09dllexport1dC1m33_C57BA610BA35E21738CC992438E660E9LLyyF = dllexport alias void (), void ()* @_swift_dead_method_stub
diff --git a/test/IRGen/enum.sil b/test/IRGen/enum.sil
index ac579588..39cb8c5 100644
--- a/test/IRGen/enum.sil
+++ b/test/IRGen/enum.sil
@@ -122,7 +122,7 @@
 // CHECK:   i32 1, i32 0
 // CHECK: }>
 
-// CHECK: @_T04enum16DynamicSingletonOMP = hidden global <{ {{.*}}, [26 x i8*] }> <{
+// CHECK: @_T04enum16DynamicSingletonOMP = internal global <{ {{.*}}, [26 x i8*] }> <{
 // CHECK:   %swift.type* (%swift.type_pattern*, i8**)* @create_generic_metadata_DynamicSingleton
 // CHECK:   @_T04enum16DynamicSingletonOMn
 // CHECK:   i8* null
@@ -131,7 +131,7 @@
 
 // -- No-payload enums have extra inhabitants in
 //    their value witness table.
-// CHECK: @_T04enum10NoPayloadsOWV = hidden constant [26 x i8*] [
+// CHECK: @_T04enum10NoPayloadsOWV = internal constant [26 x i8*] [
 // -- ...
 // -- size
 // CHECK:   i8* inttoptr ([[WORD:i32|i64]] 1 to i8*),
@@ -149,7 +149,7 @@
 
 // -- Single-payload enums take unused extra inhabitants from their payload
 //    as their own.
-// CHECK: @_T04enum19SinglePayloadNestedOWV = hidden constant [26 x i8*] [
+// CHECK: @_T04enum19SinglePayloadNestedOWV = internal constant [26 x i8*] [
 // -- ...
 // -- size
 // CHECK:   i8* inttoptr ([[WORD]] 1 to i8*),
@@ -166,13 +166,13 @@
 // CHECK: ]
 
 
-// CHECK: @_T04enum20DynamicSinglePayloadOMP = hidden global <{ {{.*}}, [26 x i8*] }> <{
+// CHECK: @_T04enum20DynamicSinglePayloadOMP = internal global <{ {{.*}}, [26 x i8*] }> <{
 // CHECK:   %swift.type* (%swift.type_pattern*, i8**)* @create_generic_metadata_DynamicSinglePayload
 // CHECK:   i8* null
 // CHECK:   i8* bitcast (void (%swift.opaque*, i32, %swift.type*)* @_T04enum20DynamicSinglePayloadOwxs to i8*)
 // CHECK:   i8* bitcast (i32 (%swift.opaque*, %swift.type*)* @_T04enum20DynamicSinglePayloadOwxg to i8*)
 
-// CHECK: @_T04enum18MultiPayloadNestedOWV = hidden constant [26 x i8*] [
+// CHECK: @_T04enum18MultiPayloadNestedOWV = internal constant [26 x i8*] [
 // CHECK:   i8* inttoptr ([[WORD]] 9 to i8*),
 // CHECK:   i8* inttoptr ([[WORD]] 16 to i8*)
 // CHECK: ]
diff --git a/test/IRGen/enum_value_semantics.sil b/test/IRGen/enum_value_semantics.sil
index 6791a92..11156f3 100644
--- a/test/IRGen/enum_value_semantics.sil
+++ b/test/IRGen/enum_value_semantics.sil
@@ -94,7 +94,7 @@
 }
 
 
-// CHECK-LABEL: @_T020enum_value_semantics20SinglePayloadTrivialOWV = hidden constant [26 x i8*] [
+// CHECK-LABEL: @_T020enum_value_semantics20SinglePayloadTrivialOWV = internal constant [26 x i8*] [
 // CHECK:   i8* bitcast (void (i8*, %swift.type*)* @__swift_noop_void_return to i8*),
 // CHECK:   i8* bitcast (i8* (i8*, i8*, %swift.type*)* @__swift_memcpy9_8 to i8*),
 // CHECK:   i8* bitcast (i8* (i8*, %swift.type*)* @__swift_noop_self_return to i8*),
@@ -133,7 +133,7 @@
 // CHECK-SAME: }>
 
 
-// CHECK-LABEL: @_T020enum_value_semantics23SinglePayloadNontrivialOWV = hidden constant [26 x i8*] [
+// CHECK-LABEL: @_T020enum_value_semantics23SinglePayloadNontrivialOWV = internal constant [26 x i8*] [
 // CHECK:   i8* bitcast (void ([24 x i8]*, %swift.type*)* @_T020enum_value_semantics23SinglePayloadNontrivialOwXX to i8*),
 // CHECK:   i8* bitcast (%swift.opaque* ([24 x i8]*, [24 x i8]*, %swift.type*)* @_T020enum_value_semantics23SinglePayloadNontrivialOwCP to i8*),
 // CHECK:   i8* bitcast (i8* (i8*, %swift.type*)* @__swift_noop_self_return to i8*),
@@ -175,7 +175,7 @@
 // CHECK-SAME: }>
 
 
-// CHECK-LABEL: @_T020enum_value_semantics18GenericFixedLayoutOMP = hidden global <{{[{].*\* [}]}}> <{
+// CHECK-LABEL: @_T020enum_value_semantics18GenericFixedLayoutOMP = internal global <{{[{].*\* [}]}}> <{
 // CHECK:   %swift.type* (%swift.type_pattern*, i8**)* @create_generic_metadata_GenericFixedLayout
 // CHECK:   i32 48, i16 1, i16 8,
 // CHECK:   [16 x i8*] zeroinitializer,
diff --git a/test/IRGen/field_type_vectors.sil b/test/IRGen/field_type_vectors.sil
index 6e493ba..9908a8c 100644
--- a/test/IRGen/field_type_vectors.sil
+++ b/test/IRGen/field_type_vectors.sil
@@ -12,7 +12,7 @@
 
 // CHECK-LABEL: @_T018field_type_vectors3BarVMn = hidden constant
 // CHECK:         %swift.type** (%swift.type*)* [[BAR_TYPES_ACCESSOR:@[A-Za-z0-9_]*]]
-// CHECK-LABEL: @_T018field_type_vectors3BarVMP = hidden global
+// CHECK-LABEL: @_T018field_type_vectors3BarVMP = internal global
 // -- There should be 5 words between the address point and the field type
 //    vector slot, with type %swift.type**
 // CHECK:         i64, i64, i64, i64, %swift.type*, %swift.type**
@@ -22,7 +22,7 @@
 
 // CHECK-LABEL: @_T018field_type_vectors3BasVMn = hidden constant
 // CHECK:         %swift.type** (%swift.type*)* [[BAS_TYPES_ACCESSOR:@[A-Za-z0-9_]*]]
-// CHECK-LABEL: @_T018field_type_vectors3BasVMP = hidden global
+// CHECK-LABEL: @_T018field_type_vectors3BasVMP = internal global
 // -- There should be 7 words between the address point and the field type
 //    vector slot, with type %swift.type**
 // CHECK:         i64, i64, i64, i64, i64, %swift.type*, %swift.type*, %swift.type**
@@ -33,7 +33,7 @@
 
 // CHECK-LABEL: @_T018field_type_vectors3ZimCMn = hidden constant
 // CHECK:         %swift.type** (%swift.type*)* [[ZIM_TYPES_ACCESSOR:@[A-Za-z0-9_]*]]
-// CHECK-LABEL: @_T018field_type_vectors3ZimCMP = hidden global
+// CHECK-LABEL: @_T018field_type_vectors3ZimCMP = internal global
 // -- There should be 14 words between the address point and the field type
 //    vector slot, with type %swift.type**
 // CHECK:         i64, %swift.type*, %swift.opaque*, %swift.opaque*, i64, i32, i32, i32, i16, i16, i32, i32, i64, i8*, %swift.type*, %swift.type*, i8*, i64, i64, i64, %swift.type**
@@ -48,7 +48,7 @@
 
 // CHECK-LABEL: @_T018field_type_vectors4ZangCMn = hidden constant
 // CHECK:         %swift.type** (%swift.type*)* [[ZANG_TYPES_ACCESSOR:@[A-Za-z0-9_]*]]
-// CHECK-LABEL: @_T018field_type_vectors4ZangCMP = hidden global
+// CHECK-LABEL: @_T018field_type_vectors4ZangCMP = internal global
 // -- There should be 16 words between the address point and the field type
 //    vector slot, with type %swift.type**
 // CHECK:         i64, %swift.type*, %swift.opaque*, %swift.opaque*, i64, i32, i32, i32, i16, i16, i32, i32, i64, i8*, %swift.type*, %swift.type*, i8*, i64, i64, i64, %swift.type*, i64, %swift.type**
diff --git a/test/IRGen/generic_classes.sil b/test/IRGen/generic_classes.sil
index bcd191e..d5ef36b 100644
--- a/test/IRGen/generic_classes.sil
+++ b/test/IRGen/generic_classes.sil
@@ -27,7 +27,7 @@
 // --       generic parameter count, primary count, witness table counts
 // CHECK:   i32 1, i32 1, i32 0
 // CHECK: }
-// CHECK: @_T015generic_classes11RootGenericCMP = hidden global
+// CHECK: @_T015generic_classes11RootGenericCMP = internal global
 // --       template fill function
 // CHECK:   %swift.type* (%swift.type_pattern*, i8**)* @create_generic_metadata_RootGeneric
 // --       nominal type descriptor
@@ -84,7 +84,7 @@
 // CHECK:   {{.*}}* @_T015generic_classes14RootNonGenericCMn
 // CHECK: }>
 
-// CHECK: @_T015generic_classes015GenericInheritsC0CMP = hidden global
+// CHECK: @_T015generic_classes015GenericInheritsC0CMP = internal global
 // --       template fill function
 // CHECK:   %swift.type* (%swift.type_pattern*, i8**)* @create_generic_metadata_GenericInheritsGeneric
 // --       RootGeneric vtable
diff --git a/test/IRGen/generic_structs.sil b/test/IRGen/generic_structs.sil
index 71182c5..33a52d9 100644
--- a/test/IRGen/generic_structs.sil
+++ b/test/IRGen/generic_structs.sil
@@ -26,7 +26,7 @@
 // --       generic parameter count, primary counts; generic parameter witness counts
 // CHECK:   i32 1, i32 1, i32 0
 // CHECK: }>
-// CHECK: @_T015generic_structs13SingleDynamicVMP = hidden global <{ {{.*}} }> <{
+// CHECK: @_T015generic_structs13SingleDynamicVMP = internal global <{ {{.*}} }> <{
 // -- template header
 // CHECK:   %swift.type* (%swift.type_pattern*, i8**)* @create_generic_metadata_SingleDynamic,
 // CHECK:   i32 240, i16 1, i16 8, [{{[0-9]+}} x i8*] zeroinitializer,
@@ -68,7 +68,7 @@
 // CHECK-SAME: i32 4, i32 2, i32 0
 // CHECK-SAME: }>
 
-// CHECK: @_T015generic_structs23DynamicWithRequirementsVMP = hidden global <{ {{.*}} }> <{
+// CHECK: @_T015generic_structs23DynamicWithRequirementsVMP = internal global <{ {{.*}} }> <{
 // -- field offset vector; generic parameter vector
 // CHECK:   i64 0, i64 0, %swift.type* null, %swift.type* null, i8** null, i8** null,
 // CHECK: }>
diff --git a/test/IRGen/generic_types.swift b/test/IRGen/generic_types.swift
index 38145ba..0bcfc5b 100644
--- a/test/IRGen/generic_types.swift
+++ b/test/IRGen/generic_types.swift
@@ -10,7 +10,7 @@
 // CHECK: [[C:%T13generic_types1CC]] = type
 // CHECK: [[D:%T13generic_types1DC]] = type
 
-// CHECK-LABEL: @_T013generic_types1ACMP = hidden global
+// CHECK-LABEL: @_T013generic_types1ACMP = internal global
 // CHECK:   %swift.type* (%swift.type_pattern*, i8**)* @create_generic_metadata_A,
 // CHECK-native-SAME: i32 160,
 // CHECK-objc-SAME:   i32 344,
@@ -36,7 +36,7 @@
 // CHECK-SAME:   void (%swift.opaque*, [[A]]*)* @_T013generic_types1AC3run{{[_0-9a-zA-Z]*}}F
 // CHECK-SAME:   %T13generic_types1AC* (i64, %T13generic_types1AC*)* @_T013generic_types1ACACyxGSi1y_tcfc
 // CHECK-SAME: }
-// CHECK-LABEL: @_T013generic_types1BCMP = hidden global
+// CHECK-LABEL: @_T013generic_types1BCMP = internal global
 // CHECK-SAME:   %swift.type* (%swift.type_pattern*, i8**)* @create_generic_metadata_B,
 // CHECK-native-SAME: i32 152,
 // CHECK-objc-SAME:   i32 336,
@@ -60,7 +60,7 @@
 // CHECK-SAME:   i32 16,
 // CHECK-SAME:   %swift.type* null
 // CHECK-SAME: }
-// CHECK-LABEL: @_T013generic_types1CCMP = hidden global
+// CHECK-LABEL: @_T013generic_types1CCMP = internal global
 // CHECK-SAME:   void ([[C]]*)* @_T013generic_types1CCfD,
 // CHECK-SAME:   i8** @_T0BoWV,
 // CHECK-SAME:   i64 0,
@@ -71,7 +71,7 @@
 // CHECK-SAME:   i64 1,
 // CHECK-SAME:   void (%swift.opaque*, [[A]]*)* @_T013generic_types1AC3run{{[_0-9a-zA-Z]*}}F
 // CHECK-SAME: }
-// CHECK-LABEL: @_T013generic_types1DCMP = hidden global
+// CHECK-LABEL: @_T013generic_types1DCMP = internal global
 // CHECK-SAME:   void ([[D]]*)* @_T013generic_types1DCfD,
 // CHECK-SAME:   i8** @_T0BoWV,
 // CHECK-SAME:   i64 0,
diff --git a/test/IRGen/indirect_enum.sil b/test/IRGen/indirect_enum.sil
index 63c7617..5976fd3 100644
--- a/test/IRGen/indirect_enum.sil
+++ b/test/IRGen/indirect_enum.sil
@@ -2,8 +2,8 @@
 
 import Swift
 
-// CHECK-64: @_T013indirect_enum5TreeAOWV = hidden constant {{.*}} i8* inttoptr ([[WORD:i64]] 8 to i8*), i8* inttoptr (i64 2162695 to i8*), i8* inttoptr (i64 8 to i8*)
-// CHECK-32: @_T013indirect_enum5TreeAOWV = hidden constant {{.*}} i8* inttoptr ([[WORD:i32]] 4 to i8*), i8* inttoptr (i32 2162691 to i8*), i8* inttoptr (i32 4 to i8*)
+// CHECK-64: @_T013indirect_enum5TreeAOWV = internal constant {{.*}} i8* inttoptr ([[WORD:i64]] 8 to i8*), i8* inttoptr (i64 2162695 to i8*), i8* inttoptr (i64 8 to i8*)
+// CHECK-32: @_T013indirect_enum5TreeAOWV = internal constant {{.*}} i8* inttoptr ([[WORD:i32]] 4 to i8*), i8* inttoptr (i32 2162691 to i8*), i8* inttoptr (i32 4 to i8*)
 
 // CHECK-LABEL: define{{( protected)?}} private %swift.type** @get_field_types_TreeA
 // -- Leaf(T)
diff --git a/test/IRGen/local_types.swift b/test/IRGen/local_types.swift
index 92d21be..5dce78c 100644
--- a/test/IRGen/local_types.swift
+++ b/test/IRGen/local_types.swift
@@ -9,14 +9,14 @@
 import local_types_helper
 
 public func singleFunc() {
-  // CHECK-DAG: @_T011local_types10singleFuncyyF06SingleD6StructL_VWV = hidden constant
+  // CHECK-DAG: @_T011local_types10singleFuncyyF06SingleD6StructL_VWV = internal constant
   struct SingleFuncStruct {
     let i: Int
   }
 }
 
 public let singleClosure: () -> () = {
-  // CHECK-DAG: @_T011local_types13singleClosureyycvfiyycfU_06SingleD6StructL_VWV = hidden constant
+  // CHECK-DAG: @_T011local_types13singleClosureyycvfiyycfU_06SingleD6StructL_VWV = internal constant
   struct SingleClosureStruct {
     let i: Int
   }
@@ -24,7 +24,7 @@
 
 public struct PatternStruct {
   public var singlePattern: Int = ({
-    // CHECK-DAG: @_T011local_types13PatternStructV06singleC0SivfiSiycfU_06SinglecD0L_VWV = hidden constant
+    // CHECK-DAG: @_T011local_types13PatternStructV06singleC0SivfiSiycfU_06SinglecD0L_VWV = internal constant
     struct SinglePatternStruct {
       let i: Int
     }
@@ -33,7 +33,7 @@
 }
 
 public func singleDefaultArgument(i: Int = {
-  // CHECK-DAG: @_T011local_types21singleDefaultArgumentySi1i_tFfA_SiycfU_06SingledE6StructL_VWV = hidden constant
+  // CHECK-DAG: @_T011local_types21singleDefaultArgumentySi1i_tFfA_SiycfU_06SingledE6StructL_VWV = internal constant
   struct SingleDefaultArgumentStruct {
     let i: Int
   }
diff --git a/test/IRGen/struct_layout.sil b/test/IRGen/struct_layout.sil
index a25f432..69be487 100644
--- a/test/IRGen/struct_layout.sil
+++ b/test/IRGen/struct_layout.sil
@@ -9,9 +9,9 @@
 // 64: %T4main14Rdar15410780_CV = type <{ %TSSSg }>
 // 64: %TSSSg = type <{ [24 x i8], [1 x i8] }>
 
-// 64: @_T04main14Rdar15410780_AVWV = hidden constant {{.*}} (i64 257
-// 64: @_T04main14Rdar15410780_BVWV = hidden constant {{.*}} (i64 258
-// 64: @_T04main14Rdar15410780_CVWV = hidden constant {{.*}} (i64 25
+// 64: @_T04main14Rdar15410780_AVWV = internal constant {{.*}} (i64 257
+// 64: @_T04main14Rdar15410780_BVWV = internal constant {{.*}} (i64 258
+// 64: @_T04main14Rdar15410780_CVWV = internal constant {{.*}} (i64 25
 
 
 // 32: %T4main14Rdar15410780_AV = type <{ i2048, %Ts4Int8V }>
@@ -20,9 +20,9 @@
 // 32: %T4main14Rdar15410780_CV = type <{ %TSSSg }>
 // 32: %TSSSg = type <{ [12 x i8], [1 x i8] }>
 
-// 32: @_T04main14Rdar15410780_AVWV = hidden constant {{.*}} (i32 257
-// 32: @_T04main14Rdar15410780_BVWV = hidden constant {{.*}} (i32 258
-// 32: @_T04main14Rdar15410780_CVWV = hidden constant {{.*}} (i32 13
+// 32: @_T04main14Rdar15410780_AVWV = internal constant {{.*}} (i32 257
+// 32: @_T04main14Rdar15410780_BVWV = internal constant {{.*}} (i32 258
+// 32: @_T04main14Rdar15410780_CVWV = internal constant {{.*}} (i32 13
 
 
 // <rdar://problem/15410780>
diff --git a/test/IRGen/type_layout.swift b/test/IRGen/type_layout.swift
index fe847b2..7c6241b 100644
--- a/test/IRGen/type_layout.swift
+++ b/test/IRGen/type_layout.swift
@@ -16,7 +16,7 @@
 @_alignment(4)
 struct CommonLayout { var x,y,z,w: Int8 }
 
-// CHECK:       @_T011type_layout14TypeLayoutTestVMP = hidden global {{.*}} @create_generic_metadata_TypeLayoutTest
+// CHECK:       @_T011type_layout14TypeLayoutTestVMP = internal global {{.*}} @create_generic_metadata_TypeLayoutTest
 // CHECK:       define private %swift.type* @create_generic_metadata_TypeLayoutTest
 struct TypeLayoutTest<T> {
   // -- dynamic layout, projected from metadata
diff --git a/test/IRGen/type_layout_objc.swift b/test/IRGen/type_layout_objc.swift
index 748b586..240a08c 100644
--- a/test/IRGen/type_layout_objc.swift
+++ b/test/IRGen/type_layout_objc.swift
@@ -20,7 +20,7 @@
 @_alignment(4)
 struct CommonLayout { var x,y,z,w: Int8 }
 
-// CHECK:       @_T016type_layout_objc14TypeLayoutTestVMP = hidden global {{.*}} @create_generic_metadata_TypeLayoutTest
+// CHECK:       @_T016type_layout_objc14TypeLayoutTestVMP = internal global {{.*}} @create_generic_metadata_TypeLayoutTest
 // CHECK:       define private %swift.type* @create_generic_metadata_TypeLayoutTest
 struct TypeLayoutTest<T> {
   // -- dynamic layout, projected from metadata
diff --git a/test/IRGen/type_layout_reference_storage.swift b/test/IRGen/type_layout_reference_storage.swift
index 5c7f182..65ede45 100644
--- a/test/IRGen/type_layout_reference_storage.swift
+++ b/test/IRGen/type_layout_reference_storage.swift
@@ -4,7 +4,7 @@
 protocol P: class {}
 protocol Q: class {}
 
-// CHECK: @_T029type_layout_reference_storage26ReferenceStorageTypeLayoutVMP = hidden global {{.*}} @create_generic_metadata_ReferenceStorageTypeLayout
+// CHECK: @_T029type_layout_reference_storage26ReferenceStorageTypeLayoutVMP = internal global {{.*}} @create_generic_metadata_ReferenceStorageTypeLayout
 // CHECK: define private %swift.type* @create_generic_metadata_ReferenceStorageTypeLayout
 struct ReferenceStorageTypeLayout<T> {
   var z: T
diff --git a/test/IRGen/type_layout_reference_storage_objc.swift b/test/IRGen/type_layout_reference_storage_objc.swift
index 1fb59d6..f6db95b 100644
--- a/test/IRGen/type_layout_reference_storage_objc.swift
+++ b/test/IRGen/type_layout_reference_storage_objc.swift
@@ -8,7 +8,7 @@
 @objc protocol Q {}
 protocol NonObjC: class {}
 
-// CHECK: @_T034type_layout_reference_storage_objc26ReferenceStorageTypeLayoutVMP = hidden global {{.*}} @create_generic_metadata_ReferenceStorageTypeLayout
+// CHECK: @_T034type_layout_reference_storage_objc26ReferenceStorageTypeLayoutVMP = internal global {{.*}} @create_generic_metadata_ReferenceStorageTypeLayout
 // CHECK: define private %swift.type* @create_generic_metadata_ReferenceStorageTypeLayout
 struct ReferenceStorageTypeLayout<T> {
   var z: T
diff --git a/test/SourceKit/Indexing/Inputs/index_constructors_other.swift b/test/SourceKit/Indexing/Inputs/index_constructors_other.swift
new file mode 100644
index 0000000..769b64d
--- /dev/null
+++ b/test/SourceKit/Indexing/Inputs/index_constructors_other.swift
@@ -0,0 +1,7 @@
+class DogObject : CatObject {
+  override init() {
+    super.init()
+  }
+}
+
+class CatObject : NSObject {}
diff --git a/test/SourceKit/Indexing/index_constructors.swift b/test/SourceKit/Indexing/index_constructors.swift
new file mode 100644
index 0000000..1791dba
--- /dev/null
+++ b/test/SourceKit/Indexing/index_constructors.swift
@@ -0,0 +1,10 @@
+// RUN: %sourcekitd-test -req=index %s -- %s %S/Inputs/index_constructors_other.swift | %sed_clean > %t.response
+// RUN: diff -u %s.response %t.response
+
+import Foundation
+
+class HorseObject : DogObject {
+  var name: NSString
+
+  @objc public func flip() {}
+}
diff --git a/test/SourceKit/Indexing/index_constructors.swift.response b/test/SourceKit/Indexing/index_constructors.swift.response
new file mode 100644
index 0000000..14391805
--- /dev/null
+++ b/test/SourceKit/Indexing/index_constructors.swift.response
@@ -0,0 +1,58 @@
+{
+  key.hash: <hash>,
+  key.dependencies: [
+    {
+      key.kind: source.lang.swift.import.module.swift,
+      key.name: "Swift",
+      key.filepath: Swift.swiftmodule,
+      key.hash: <hash>,
+      key.is_system: 1
+    }
+  ],
+  key.entities: [
+    {
+      key.kind: source.lang.swift.decl.class,
+      key.name: "HorseObject",
+      key.usr: "s:18index_constructors11HorseObjectC",
+      key.line: 6,
+      key.column: 7,
+      key.related: [
+        {
+          key.kind: source.lang.swift.ref.class,
+          key.name: "DogObject",
+          key.usr: "s:18index_constructors9DogObjectC",
+          key.line: 6,
+          key.column: 21
+        }
+      ],
+      key.entities: [
+        {
+          key.kind: source.lang.swift.ref.class,
+          key.name: "DogObject",
+          key.usr: "s:18index_constructors9DogObjectC",
+          key.line: 6,
+          key.column: 21
+        },
+        {
+          key.kind: source.lang.swift.decl.var.instance,
+          key.name: "name",
+          key.usr: "s:18index_constructors11HorseObjectC4nameXev",
+          key.line: 7,
+          key.column: 7
+        },
+        {
+          key.kind: source.lang.swift.decl.function.method.instance,
+          key.name: "flip()",
+          key.usr: "s:18index_constructors11HorseObjectC4flipyyF",
+          key.line: 9,
+          key.column: 21,
+          key.attributes: [
+            {
+              key.attribute: source.decl.attribute.objc
+            }
+          ]
+        }
+      ]
+    }
+  ]
+}
diff --git a/validation-test/compiler_crashers/28727-objectty-haserror-cannot-have-errortype-wrapped-inside-lvaluetype.swift b/validation-test/compiler_crashers/28727-objectty-haserror-cannot-have-errortype-wrapped-inside-lvaluetype.swift
new file mode 100644
index 0000000..0b01481
--- /dev/null
+++ b/validation-test/compiler_crashers/28727-objectty-haserror-cannot-have-errortype-wrapped-inside-lvaluetype.swift
@@ -0,0 +1,10 @@
+// This source file is part of the Swift.org open source project
+// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+
+// REQUIRES: asserts
+// RUN: not --crash %target-swift-frontend %s -emit-ir
+protocol P}extension P{lazy var f={extension{var f=((self
diff --git a/validation-test/compiler_crashers/28728-d-isbeingvalidated-d-hasvalidsignature.swift b/validation-test/compiler_crashers/28728-d-isbeingvalidated-d-hasvalidsignature.swift
new file mode 100644
index 0000000..57e4115
--- /dev/null
+++ b/validation-test/compiler_crashers/28728-d-isbeingvalidated-d-hasvalidsignature.swift
@@ -0,0 +1,11 @@
+// This source file is part of the Swift.org open source project
+// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
+// Licensed under Apache License v2.0 with Runtime Library Exception
+//
+// See https://swift.org/LICENSE.txt for license information
+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
+
+// REQUIRES: asserts
+// RUN: not --crash %target-swift-frontend %s -emit-ir
+typealias e:a
+struct A:a{}typealias a=A