Merge pull request #20207 from atrick/fix-letprop

Fix static initializer analysis, used in LetPropertiesOpt.
diff --git a/benchmark/scripts/run_smoke_bench.py b/benchmark/scripts/run_smoke_bench.py
index 0499345..39edb90 100755
--- a/benchmark/scripts/run_smoke_bench.py
+++ b/benchmark/scripts/run_smoke_bench.py
@@ -63,9 +63,18 @@
     argparser.add_argument(
         'newbuilddir', nargs=1, type=str,
         help='new benchmark build directory')
+    argparser.add_argument(
+        '-check-added', action='store_const',
+        help="Run BenchmarkDoctor's check on newly added benchmarks",
+        const=lambda args: check_added(args), dest='func')
+    argparser.set_defaults(func=test_opt_levels)
     args = argparser.parse_args()
     VERBOSE = args.verbose
 
+    return args.func(args)
+
+
+def test_opt_levels(args):
     for opt_level in args.opt_levels or ['O', 'Osize', 'Onone']:
         log('Testing optimization level -' + opt_level)
         test_opt_level(opt_level, args.oldbuilddir[0], args.newbuilddir[0],
@@ -178,7 +187,33 @@
         sys.stderr.flush()
         return sys.exit(e.returncode)
     else:
-        return output 
+        return output
+
+
+class DriverArgs(object):
+    def __init__(self, tests):
+        self.benchmarks = None
+        self.filters = None
+        self.tests = os.path.join(tests, 'bin')
+        self.optimization = 'O'
+
+
+def check_added(args):
+    from imp import load_source
+    # import Benchmark_Driver  # doesn't work because it misses '.py' extension
+    Benchmark_Driver = load_source(
+        'Benchmark_Driver', os.path.join(os.path.dirname(
+            os.path.abspath(__file__)), 'Benchmark_Driver'))
+    # from Benchmark_Driver import BenchmarkDriver, BenchmarkDoctor
+    BenchmarkDriver = Benchmark_Driver.BenchmarkDriver
+    BenchmarkDoctor = Benchmark_Driver.BenchmarkDoctor
+
+    old = BenchmarkDriver(DriverArgs(args.oldbuilddir[0]))
+    new = BenchmarkDriver(DriverArgs(args.newbuilddir[0]))
+    added = set(new.tests).difference(set(old.tests))
+    new.tests = list(added)
+    doctor = BenchmarkDoctor(args, driver=new)
+    doctor.check()
 
 
 if __name__ == '__main__':
diff --git a/docs/ABI/Mangling.rst b/docs/ABI/Mangling.rst
index e704bbb..49fdd12 100644
--- a/docs/ABI/Mangling.rst
+++ b/docs/ABI/Mangling.rst
@@ -448,6 +448,7 @@
   type ::= 'BB'                              // Builtin.UnsafeValueBuffer
   type ::= 'Bf' NATURAL '_'                  // Builtin.Float<n>
   type ::= 'Bi' NATURAL '_'                  // Builtin.Int<n>
+  type ::= 'BI'                              // Builtin.IntLiteral
   type ::= 'BO'                              // Builtin.UnknownObject
   type ::= 'Bo'                              // Builtin.NativeObject
   type ::= 'Bp'                              // Builtin.RawPointer
diff --git a/docs/LibraryEvolution.rst b/docs/LibraryEvolution.rst
index 430e5c5..22f54f4 100644
--- a/docs/LibraryEvolution.rst
+++ b/docs/LibraryEvolution.rst
@@ -851,7 +851,7 @@
 New requirements can be added to a protocol. However, restrictions around
 existential types mean that adding new associated types or non-type requirements
 involving ``Self`` can break source compatibility. For this reason, the following
-are `binary-compatible source-breaking changes`:
+are `binary-compatible source-breaking changes <binary-compatible source-breaking change>`:
 
 - A new non-type requirement may be added to a protocol, as long as it has an
   unconstrained default implementation in a protocol extension of the
diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h
index 9c3f0b4..2ea5284 100644
--- a/include/swift/AST/ASTContext.h
+++ b/include/swift/AST/ASTContext.h
@@ -612,6 +612,7 @@
   const CanType TheRawPointerType;        /// Builtin.RawPointer
   const CanType TheUnsafeValueBufferType; /// Builtin.UnsafeValueBuffer
   const CanType TheSILTokenType;          /// Builtin.SILToken
+  const CanType TheIntegerLiteralType;    /// Builtin.IntegerLiteralType
   
   const CanType TheIEEE32Type;            /// 32-bit IEEE floating point
   const CanType TheIEEE64Type;            /// 64-bit IEEE floating point
diff --git a/include/swift/AST/Attr.def b/include/swift/AST/Attr.def
index 995444c..533aabd 100644
--- a/include/swift/AST/Attr.def
+++ b/include/swift/AST/Attr.def
@@ -359,9 +359,8 @@
   LongAttribute | RejectByParser | UserInaccessible |
   NotSerialized, 74)
 SIMPLE_DECL_ATTR(_weakLinked, WeakLinked,
-  OnNominalType | OnFunc | OnAccessor | OnVar | OnSubscript | OnConstructor |
-  OnEnumElement |
-  UserInaccessible,
+  OnNominalType | OnAssociatedType | OnFunc | OnAccessor | OnVar |
+  OnSubscript | OnConstructor | OnEnumElement | UserInaccessible,
   75)
 SIMPLE_DECL_ATTR(_frozen, Frozen,
   OnEnum |
diff --git a/include/swift/AST/DiagnosticsParse.def b/include/swift/AST/DiagnosticsParse.def
index 16ef0b3..aa5489f 100644
--- a/include/swift/AST/DiagnosticsParse.def
+++ b/include/swift/AST/DiagnosticsParse.def
@@ -546,6 +546,8 @@
       (StringRef, StringRef, ReferenceOwnership))
 ERROR(sil_integer_literal_not_integer_type,none,
       "integer_literal instruction requires a 'Builtin.Int<n>' type", ())
+ERROR(sil_integer_literal_not_well_formed,none,
+      "integer_literal value not well-formed for type %0", (Type))
 ERROR(sil_float_literal_not_float_type,none,
       "float_literal instruction requires a 'Builtin.FP<n>' type", ())
 ERROR(sil_substitutions_on_non_polymorphic_type,none,
diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def
index 012ee51..f17db23 100644
--- a/include/swift/AST/DiagnosticsSema.def
+++ b/include/swift/AST/DiagnosticsSema.def
@@ -2619,8 +2619,6 @@
 NOTE(found_candidate_type,none,
      "found candidate with type %0", (Type))
 
-ERROR(no_MaxBuiltinIntegerType_found,none,
-   "standard library error: _MaxBuiltinIntegerType is not properly defined", ())
 ERROR(no_MaxBuiltinFloatType_found,none,
    "standard library error: _MaxBuiltinFloatType is not properly defined", ())
 ERROR(integer_literal_overflows_maxwidth, none,
diff --git a/include/swift/AST/Expr.h b/include/swift/AST/Expr.h
index 2743b36..f1c0cb1 100644
--- a/include/swift/AST/Expr.h
+++ b/include/swift/AST/Expr.h
@@ -789,10 +789,12 @@
   static IntegerLiteralExpr *
   createFromUnsigned(ASTContext &C, unsigned value);
 
+  /// Returns the value of the literal, appropriately constructed in the
+  /// target type.
   APInt getValue() const;
-  static APInt getValue(StringRef Text, unsigned BitWidth, bool Negative);
 
-  APInt getRawMagnitude() const;
+  /// Returns the raw value of the literal without any truncation.
+  APInt getRawValue() const;
 
   static bool classof(const Expr *E) {
     return E->getKind() == ExprKind::IntegerLiteral;
diff --git a/include/swift/AST/TypeMatcher.h b/include/swift/AST/TypeMatcher.h
index 26bd7f3..28582a0 100644
--- a/include/swift/AST/TypeMatcher.h
+++ b/include/swift/AST/TypeMatcher.h
@@ -102,6 +102,7 @@
 
     TRIVIAL_CASE(ErrorType)
     TRIVIAL_CASE(BuiltinIntegerType)
+    TRIVIAL_CASE(BuiltinIntegerLiteralType)
     TRIVIAL_CASE(BuiltinFloatType)
     TRIVIAL_CASE(BuiltinRawPointerType)
     TRIVIAL_CASE(BuiltinNativeObjectType)
diff --git a/include/swift/AST/TypeNodes.def b/include/swift/AST/TypeNodes.def
index ba4f042..fd051a7 100644
--- a/include/swift/AST/TypeNodes.def
+++ b/include/swift/AST/TypeNodes.def
@@ -90,7 +90,10 @@
 TYPE(Error, Type)
 UNCHECKED_TYPE(Unresolved, Type)
 ABSTRACT_TYPE(Builtin, Type)
-  BUILTIN_TYPE(BuiltinInteger, BuiltinType)
+  ABSTRACT_TYPE(AnyBuiltinInteger, BuiltinType)
+    BUILTIN_TYPE(BuiltinInteger, AnyBuiltinIntegerType)
+    BUILTIN_TYPE(BuiltinIntegerLiteral, AnyBuiltinIntegerType)
+    TYPE_RANGE(AnyBuiltinInteger, BuiltinInteger, BuiltinIntegerLiteral)
   BUILTIN_TYPE(BuiltinFloat, BuiltinType)
   BUILTIN_TYPE(BuiltinRawPointer, BuiltinType)
   BUILTIN_TYPE(BuiltinNativeObject, BuiltinType)
diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h
index b0a234a..a030883 100644
--- a/include/swift/AST/Types.h
+++ b/include/swift/AST/Types.h
@@ -1346,13 +1346,17 @@
 class BuiltinIntegerWidth {
   /// Tag values for abstract integer sizes.
   enum : unsigned {
-    Least_SpecialValue = ~2U,
-    /// The size of a pointer on the target system.
-    PointerWidth = ~0U,
-    
     /// Inhabitants stolen for use as DenseMap special values.
-    DenseMapEmpty = ~1U,
-    DenseMapTombstone = ~2U,
+    DenseMapEmpty = ~0U,
+    DenseMapTombstone = ~1U,
+
+    /// An arbitrary-precision integer.
+    ArbitraryWidth = ~2U,
+
+    /// The size of a pointer on the target system.
+    PointerWidth = ~3U,
+    
+    Least_SpecialValue = ~3U,
   };
   
   unsigned RawValue;
@@ -1372,6 +1376,10 @@
   static BuiltinIntegerWidth pointer() {
     return BuiltinIntegerWidth(PointerWidth);
   }
+
+  static BuiltinIntegerWidth arbitrary() {
+    return BuiltinIntegerWidth(ArbitraryWidth);
+  }
   
   /// Is this a fixed width?
   bool isFixedWidth() const { return RawValue < Least_SpecialValue; }
@@ -1384,6 +1392,9 @@
   
   /// Is this the abstract target pointer width?
   bool isPointerWidth() const { return RawValue == PointerWidth; }
+
+  /// Is this the abstract arbitrary-width value?
+  bool isArbitraryWidth() const { return RawValue == ArbitraryWidth; }
   
   /// Get the least supported value for the width.
   ///
@@ -1393,6 +1404,8 @@
       return getFixedWidth();
     if (isPointerWidth())
       return 32;
+    if (isArbitraryWidth())
+      return 1;
     llvm_unreachable("impossible width value");
   }
   
@@ -1404,8 +1417,16 @@
       return getFixedWidth();
     if (isPointerWidth())
       return 64;
+    if (isArbitraryWidth())
+      return ~0U;
     llvm_unreachable("impossible width value");
   }
+
+  /// Parse a value of this bit-width.
+  ///
+  /// If the radix is 0, it is autosensed.
+  APInt parse(StringRef text, unsigned radix, bool negate,
+              bool *hadError = nullptr) const;
   
   friend bool operator==(BuiltinIntegerWidth a, BuiltinIntegerWidth b) {
     return a.RawValue == b.RawValue;
@@ -1415,15 +1436,31 @@
   }
 };
 
+/// An abstract base class for the two integer types.
+class AnyBuiltinIntegerType : public BuiltinType {
+protected:
+  AnyBuiltinIntegerType(TypeKind kind, const ASTContext &C)
+    : BuiltinType(kind, C) {}
+
+public:
+  static bool classof(const TypeBase *T) {
+    return T->getKind() >= TypeKind::First_AnyBuiltinIntegerType &&
+           T->getKind() <= TypeKind::Last_AnyBuiltinIntegerType;
+  }
+
+  BuiltinIntegerWidth getWidth() const; // defined inline below
+};
+DEFINE_EMPTY_CAN_TYPE_WRAPPER(AnyBuiltinIntegerType, BuiltinType)
+
 /// The builtin integer types.  These directly correspond
 /// to LLVM IR integer types.  They lack signedness and have an arbitrary
 /// bitwidth.
-class BuiltinIntegerType : public BuiltinType {
+class BuiltinIntegerType : public AnyBuiltinIntegerType {
   friend class ASTContext;
 private:
   BuiltinIntegerWidth Width;
   BuiltinIntegerType(BuiltinIntegerWidth BitWidth, const ASTContext &C)
-    : BuiltinType(TypeKind::BuiltinInteger, C), Width(BitWidth) {}
+    : AnyBuiltinIntegerType(TypeKind::BuiltinInteger, C), Width(BitWidth) {}
   
 public:
   /// Get a builtin integer type.
@@ -1440,7 +1477,8 @@
     return get(BuiltinIntegerWidth::pointer(), C);
   }
   
-  /// Return the bit width of the integer.
+  /// Return the bit width of the integer.  Always returns a non-arbitrary
+  /// width.
   BuiltinIntegerWidth getWidth() const {
     return Width;
   }
@@ -1478,8 +1516,31 @@
     return T->getKind() == TypeKind::BuiltinInteger;
   }
 };
-DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinIntegerType, BuiltinType)
-  
+DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinIntegerType, AnyBuiltinIntegerType)
+
+/// BuiltinIntegerLiteralType - The builtin arbitrary-precision integer type.
+/// Useful for constructing integer literals.
+class BuiltinIntegerLiteralType : public AnyBuiltinIntegerType {
+  friend class ASTContext;
+  BuiltinIntegerLiteralType(const ASTContext &C)
+    : AnyBuiltinIntegerType(TypeKind::BuiltinIntegerLiteral, C) {}
+public:
+  static bool classof(const TypeBase *T) {
+    return T->getKind() == TypeKind::BuiltinIntegerLiteral;
+  }
+
+  BuiltinIntegerWidth getWidth() const = delete;
+};
+DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinIntegerLiteralType, AnyBuiltinIntegerType);
+
+inline BuiltinIntegerWidth AnyBuiltinIntegerType::getWidth() const {
+  if (auto intTy = dyn_cast<BuiltinIntegerType>(this)) {
+    return intTy->getWidth();
+  } else {
+    return BuiltinIntegerWidth::arbitrary();
+  }
+}
+
 class BuiltinFloatType : public BuiltinType {
   friend class ASTContext;
 public:
diff --git a/include/swift/Basic/APIntMap.h b/include/swift/Basic/APIntMap.h
new file mode 100644
index 0000000..3938dfc
--- /dev/null
+++ b/include/swift/Basic/APIntMap.h
@@ -0,0 +1,54 @@
+//===--- APIntMap.h - A map with APInts as the keys -------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// LLVM does not allow arbitrary APInts to be the keys of a DenseMap because
+// APInts are only comparable if they have the same bit-width.  This map
+// implementation assumes that its keys will always be constrained to their
+// minimum width, so it's not a general-purpose structure, but it does work.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SWIFT_BASIC_APINTMAP_H
+#define SWIFT_BASIC_APINTMAP_H
+
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/DenseMap.h"
+#include "swift/Basic/LLVM.h"
+
+namespace swift {
+
+struct WidthPreservingAPIntDenseMapInfo {
+  // For the special values, we use -1 with a bit-width that isn't minimal
+  // for the value, then use a parser that always produces values with
+  // minimal bit-widths so that we don't get a conflict.
+  static inline APInt getEmptyKey() {
+    return APInt::getAllOnesValue(/*bitwidth*/2);
+  }
+  static inline APInt getTombstoneKey() {
+    return APInt::getAllOnesValue(/*bitwidth*/3);
+  }
+
+  static unsigned getHashValue(const APInt &Key) {
+    return static_cast<unsigned>(hash_value(Key));
+  }
+
+  static bool isEqual(const APInt &LHS, const APInt &RHS) {
+    return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
+  }
+};
+
+template <class Value>
+using APIntMap = llvm::DenseMap<APInt, Value, WidthPreservingAPIntDenseMapInfo>;
+
+}
+
+#endif
diff --git a/include/swift/IRGen/Linking.h b/include/swift/IRGen/Linking.h
index 506256d..3bbe48f 100644
--- a/include/swift/IRGen/Linking.h
+++ b/include/swift/IRGen/Linking.h
@@ -919,23 +919,7 @@
   }
 
   /// Determine whether this entity will be weak-imported.
-  bool isWeakImported(ModuleDecl *module) const {
-    if (getKind() == Kind::SILGlobalVariable &&
-        getSILGlobalVariable()->getDecl())
-      return getSILGlobalVariable()->getDecl()->isWeakImported(module);
-
-    if (getKind() == Kind::SILFunction) {
-      if (auto clangOwner = getSILFunction()->getClangNodeOwner())
-        return clangOwner->isWeakImported(module);
-      if (getSILFunction()->isWeakLinked())
-        return getSILFunction()->isAvailableExternally();
-    }
-
-    if (!isDeclKind(getKind()))
-      return false;
-
-    return getDecl()->isWeakImported(module);
-  }
+  bool isWeakImported(ModuleDecl *module) const;
   
   /// Return the source file whose codegen should trigger emission of this
   /// link entity, if one can be identified.
diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td
index 1d0de10..17f9fb6 100644
--- a/include/swift/Option/Options.td
+++ b/include/swift/Option/Options.td
@@ -284,7 +284,7 @@
   Alias<module_name>;
 
 def module_link_name : Separate<["-"], "module-link-name">,
-  Flags<[FrontendOption]>,
+  Flags<[FrontendOption, ParseableInterfaceOption]>,
   HelpText<"Library to link against when using this module">;
 def module_link_name_EQ : Joined<["-"], "module-link-name=">,
   Flags<[FrontendOption]>, Alias<module_link_name>;
diff --git a/include/swift/Parse/Parser.h b/include/swift/Parse/Parser.h
index ab088e5..0546434 100644
--- a/include/swift/Parse/Parser.h
+++ b/include/swift/Parse/Parser.h
@@ -1216,6 +1216,8 @@
   ParserResult<Expr> parseExprStringLiteral();
   ParserResult<Expr> parseExprTypeOf();
 
+  StringRef copyAndStripUnderscores(StringRef text);
+
   ParserStatus parseStringSegments(SmallVectorImpl<Lexer::StringSegment> &Segments,
                                    SmallVectorImpl<Expr*> &Exprs,
                                    Token EntireTok);
diff --git a/include/swift/SIL/SILType.h b/include/swift/SIL/SILType.h
index 2269586..284579d 100644
--- a/include/swift/SIL/SILType.h
+++ b/include/swift/SIL/SILType.h
@@ -516,6 +516,8 @@
   static SILType getRawPointerType(const ASTContext &C);
   /// Get a builtin integer type as a SILType.
   static SILType getBuiltinIntegerType(unsigned bitWidth, const ASTContext &C);
+  /// Get the IntegerLiteral type as a SILType.
+  static SILType getBuiltinIntegerLiteralType(const ASTContext &C);
   /// Get a builtin floating-point type as a SILType.
   static SILType getBuiltinFloatType(BuiltinFloatType::FPKind Kind,
                                      const ASTContext &C);
diff --git a/include/swift/SILOptimizer/PassManager/Passes.def b/include/swift/SILOptimizer/PassManager/Passes.def
index 2258864..f14f51d 100644
--- a/include/swift/SILOptimizer/PassManager/Passes.def
+++ b/include/swift/SILOptimizer/PassManager/Passes.def
@@ -58,6 +58,8 @@
      "Remove dominated access checks with no nested conflict")
 PASS(AccessEnforcementOpts, "access-enforcement-opts",
      "Access Enforcement Optimization")
+PASS(AccessEnforcementReleaseSinking, "access-enforcement-release",
+     "Access Enforcement Release Sinking")
 PASS(AccessEnforcementSelection, "access-enforcement-selection",
      "Access Enforcement Selection")
 PASS(AccessEnforcementWMO, "access-enforcement-wmo",
diff --git a/include/swift/Serialization/ModuleFormat.h b/include/swift/Serialization/ModuleFormat.h
index e23c6ab..38618da 100644
--- a/include/swift/Serialization/ModuleFormat.h
+++ b/include/swift/Serialization/ModuleFormat.h
@@ -52,7 +52,7 @@
 /// describe what change you made. The content of this comment isn't important;
 /// it just ensures a conflict if two people change the module format.
 /// Don't worry about adhering to the 80-column limit for this line.
-const uint16_t SWIFTMODULE_VERSION_MINOR = 455; // Last change: reorder block IDs
+const uint16_t SWIFTMODULE_VERSION_MINOR = 456; // Last change: encode depth in generic param XREFs
 
 using DeclIDField = BCFixed<31>;
 
@@ -1403,7 +1403,8 @@
 
   using XRefGenericParamPathPieceLayout = BCRecordLayout<
     XREF_GENERIC_PARAM_PATH_PIECE,
-    BCVBR<5> // index
+    BCVBR<5>, // depth
+    BCVBR<5>  // index
   >;
 
   using SILGenNameDeclAttrLayout = BCRecordLayout<
diff --git a/include/swift/Strings.h b/include/swift/Strings.h
index ace5f72..eceef8c 100644
--- a/include/swift/Strings.h
+++ b/include/swift/Strings.h
@@ -54,6 +54,9 @@
 constexpr static const char BUILTIN_TYPE_NAME_INT256[] = "Builtin.Int256";
 /// The name of the Builtin type for Int512
 constexpr static const char BUILTIN_TYPE_NAME_INT512[] = "Builtin.Int512";
+/// The name of the Builtin type for IntLiteral
+constexpr static const char BUILTIN_TYPE_NAME_INTLITERAL[] =
+    "Builtin.IntLiteral";
 /// The name of the Builtin type for Float
 constexpr static const char BUILTIN_TYPE_NAME_FLOAT[] = "Builtin.Float";
 /// The name of the Builtin type for NativeObject
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index da9085b..6a5a397 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -511,6 +511,8 @@
                                BuiltinUnsafeValueBufferType(*this)),
     TheSILTokenType(new (*this, AllocationArena::Permanent)
                       SILTokenType(*this)),
+    TheIntegerLiteralType(new (*this, AllocationArena::Permanent)
+                               BuiltinIntegerLiteralType(*this)),
     TheIEEE32Type(new (*this, AllocationArena::Permanent)
                     BuiltinFloatType(BuiltinFloatType::IEEE32,*this)),
     TheIEEE64Type(new (*this, AllocationArena::Permanent)
@@ -3032,6 +3034,7 @@
 
 BuiltinIntegerType *BuiltinIntegerType::get(BuiltinIntegerWidth BitWidth,
                                             const ASTContext &C) {
+  assert(!BitWidth.isArbitraryWidth());
   BuiltinIntegerType *&Result = C.getImpl().IntegerTypes[BitWidth];
   if (Result == nullptr)
     Result = new (C, AllocationArena::Permanent) BuiltinIntegerType(BitWidth,C);
diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp
index 03e3a81..a1cf3c8 100644
--- a/lib/AST/ASTDumper.cpp
+++ b/lib/AST/ASTDumper.cpp
@@ -3193,6 +3193,7 @@
       PrintWithColorRAII(OS, ParenthesisColor) << ')';
     }
 
+    TRIVIAL_TYPE_PRINTER(BuiltinIntegerLiteral, builtin_integer_literal)
     TRIVIAL_TYPE_PRINTER(BuiltinRawPointer, builtin_raw_pointer)
     TRIVIAL_TYPE_PRINTER(BuiltinNativeObject, builtin_native_object)
     TRIVIAL_TYPE_PRINTER(BuiltinBridgeObject, builtin_bridge_object)
diff --git a/lib/AST/ASTMangler.cpp b/lib/AST/ASTMangler.cpp
index 7cb14a3..dcad310 100644
--- a/lib/AST/ASTMangler.cpp
+++ b/lib/AST/ASTMangler.cpp
@@ -717,6 +717,8 @@
         llvm_unreachable("impossible width value");
       return;
     }
+    case TypeKind::BuiltinIntegerLiteral:
+      return appendOperator("BI");
     case TypeKind::BuiltinRawPointer:
       return appendOperator("Bp");
     case TypeKind::BuiltinNativeObject:
diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp
index af3535a..d839e69 100644
--- a/lib/AST/ASTPrinter.cpp
+++ b/lib/AST/ASTPrinter.cpp
@@ -3369,6 +3369,10 @@
     Printer << BUILTIN_TYPE_NAME_UNSAFEVALUEBUFFER;
   }
 
+  void visitBuiltinIntegerLiteralType(BuiltinIntegerLiteralType *T) {
+    Printer << BUILTIN_TYPE_NAME_INTLITERAL;
+  }
+
   void visitBuiltinVectorType(BuiltinVectorType *T) {
     llvm::SmallString<32> UnderlyingStrVec;
     StringRef UnderlyingStr;
diff --git a/lib/AST/ASTVerifier.cpp b/lib/AST/ASTVerifier.cpp
index 2375ced..e289c94 100644
--- a/lib/AST/ASTVerifier.cpp
+++ b/lib/AST/ASTVerifier.cpp
@@ -2039,9 +2039,8 @@
     void verifyChecked(IfExpr *E) {
       PrettyStackTraceExpr debugStack(Ctx, "verifying IfExpr", E);
 
-      auto condTy
-        = E->getCondExpr()->getType()->getAs<BuiltinIntegerType>();
-      if (!condTy || !condTy->isFixedWidth() || condTy->getFixedWidth() != 1) {
+      auto condTy = E->getCondExpr()->getType();
+      if (!condTy->isBuiltinIntegerType(1)) {
         Out << "IfExpr condition is not an i1\n";
         abort();
       }
diff --git a/lib/AST/Builtins.cpp b/lib/AST/Builtins.cpp
index e1cccf0..bf040f0 100644
--- a/lib/AST/Builtins.cpp
+++ b/lib/AST/Builtins.cpp
@@ -93,6 +93,9 @@
   if (Name == "Word")
     return BuiltinIntegerType::getWordType(Context);
 
+  if (Name == "IntLiteral")
+    return Context.TheIntegerLiteralType;
+
   // Handle 'int8' and friends.
   if (Name.substr(0, 3) == "Int") {
     unsigned BitWidth;
@@ -348,7 +351,7 @@
         !CheckOutput->is<BuiltinIntegerType>())
       return nullptr;
     break;
-      
+
   case BuiltinValueKind::UIToFP:
   case BuiltinValueKind::SIToFP:
     if (CheckOutput.isNull() || !CheckInput->is<BuiltinIntegerType>() ||
@@ -1074,16 +1077,20 @@
   return getBuiltinFunction(Id, ArgElts, ResultTy);
 }
 
-static ValueDecl *getCheckedTruncOperation(ASTContext &Context,
-                                                Identifier Id,
-                                                Type InputTy,
-                                                Type OutputTy) {
-  auto InTy = InputTy->getAs<BuiltinIntegerType>();
+static ValueDecl *getCheckedTruncOperation(ASTContext &Context, Identifier Id,
+                                           Type InputTy, Type OutputTy,
+                                           bool AllowLiteral) {
+  auto InTy = InputTy->getAs<AnyBuiltinIntegerType>();
   auto OutTy = OutputTy->getAs<BuiltinIntegerType>();
   if (!InTy || !OutTy)
     return nullptr;
-  if (InTy->getLeastWidth() < OutTy->getGreatestWidth())
+  if (isa<BuiltinIntegerLiteralType>(InTy)) {
+    if (!AllowLiteral)
+      return nullptr;
+  } else if (cast<BuiltinIntegerType>(InTy)->getLeastWidth()
+               < OutTy->getGreatestWidth()) {
     return nullptr;
+  }
 
   Type OverflowBitTy = BuiltinIntegerType::get(1, Context);
   TupleTypeElt ResultElts[] = { Type(OutTy), OverflowBitTy };
@@ -1107,7 +1114,7 @@
 static ValueDecl *getIntToFPWithOverflowOperation(ASTContext &Context,
                                                   Identifier Id, Type InputTy,
                                                   Type OutputTy) {
-  auto InTy = InputTy->getAs<BuiltinIntegerType>();
+  auto InTy = InputTy->getAs<BuiltinIntegerLiteralType>();
   auto OutTy = OutputTy->getAs<BuiltinFloatType>();
   if (!InTy || !OutTy)
     return nullptr;
@@ -1828,12 +1835,15 @@
     if (!Types.empty()) return nullptr;
     return getStaticReportOperation(Context, Id);
 
-  case BuiltinValueKind::UToSCheckedTrunc:
   case BuiltinValueKind::SToSCheckedTrunc:
   case BuiltinValueKind::SToUCheckedTrunc:
+    if (Types.size() != 2) return nullptr;
+    return getCheckedTruncOperation(Context, Id, Types[0], Types[1], true);
+
+  case BuiltinValueKind::UToSCheckedTrunc:
   case BuiltinValueKind::UToUCheckedTrunc:
     if (Types.size() != 2) return nullptr;
-    return getCheckedTruncOperation(Context, Id, Types[0], Types[1]);
+    return getCheckedTruncOperation(Context, Id, Types[0], Types[1], false);
 
   case BuiltinValueKind::SUCheckedConversion:
   case BuiltinValueKind::USCheckedConversion:
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 29e2325..3512da9 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -551,6 +551,12 @@
   if (getAttrs().hasAttribute<WeakLinkedAttr>())
     return true;
 
+  if (auto *accessor = dyn_cast<AccessorDecl>(this))
+    return accessor->getStorage()->isWeakImported(fromModule);
+
+  if (auto *dtor = dyn_cast<DestructorDecl>(this))
+    return cast<ClassDecl>(dtor->getDeclContext())->isWeakImported(fromModule);
+
   // FIXME: Also check availability when containingModule is resilient.
   return false;
 }
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index a1823d8..1a5efc9 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -849,46 +849,81 @@
   return new (C) IntegerLiteralExpr(Text, SourceLoc(), /*implicit*/ true);
 }
 
-/// A wrapper around LLVM::getAsInteger that can be used on Swift interger
-/// literals. It avoids misinterpreting decimal numbers prefixed with 0 as
-/// octal numbers.
-static bool getAsInteger(StringRef Text, llvm::APInt &Value) {
-  // swift encodes octal differently from C
-  bool IsCOctal = Text.size() > 1 && Text[0] == '0' && isdigit(Text[1]);
-  return Text.getAsInteger(IsCOctal ? 10 : 0, Value);
-}
-
-static APInt getIntegerLiteralValue(bool IsNegative, StringRef Text,
-                                    unsigned BitWidth) {
-  llvm::APInt Value(BitWidth, 0);
-  bool Error = getAsInteger(Text, Value);
-  assert(!Error && "Invalid IntegerLiteral formed"); (void)Error;
-  if (IsNegative)
-    Value = -Value;
-  if (Value.getBitWidth() != BitWidth)
-    Value = Value.sextOrTrunc(BitWidth);
-  return Value;
-}
-
-APInt IntegerLiteralExpr::getValue(StringRef Text, unsigned BitWidth, bool Negative) {
-  return getIntegerLiteralValue(Negative, Text, BitWidth);
-}
-
-/// Returns the raw magnitude of the literal text without any truncation.
-APInt IntegerLiteralExpr::getRawMagnitude() const {
-  llvm::APInt Value(64, 0);
-  bool Error = getAsInteger(getDigitsText(), Value);
-  assert(!Error && "Invalid IntegerLiteral formed");
-  (void)Error;
-  return Value;
+APInt IntegerLiteralExpr::getRawValue() const {
+  return BuiltinIntegerWidth::arbitrary().parse(getDigitsText(), /*radix*/0,
+                                                isNegative());
 }
 
 APInt IntegerLiteralExpr::getValue() const {
   assert(!getType().isNull() && "Semantic analysis has not completed");
   assert(!getType()->hasError() && "Should have a valid type");
-  return getIntegerLiteralValue(
-      isNegative(), getDigitsText(),
-      getType()->castTo<BuiltinIntegerType>()->getGreatestWidth());
+  auto width = getType()->castTo<AnyBuiltinIntegerType>()->getWidth();
+  return width.parse(getDigitsText(), /*radix*/ 0, isNegative());
+}
+
+APInt BuiltinIntegerWidth::parse(StringRef text, unsigned radix, bool negate,
+                                 bool *hadError) const {
+  if (hadError) *hadError = false;
+
+  // Parse an unsigned value from the string.
+  APInt value;
+
+  // Swift doesn't treat a leading zero as signifying octal, but
+  // StringRef::getAsInteger does.  Force decimal parsing in this case.
+  if (radix == 0 && text.size() >= 2 && text[0] == '0' && isdigit(text[1]))
+    radix = 10;
+
+  bool error = text.getAsInteger(radix, value);
+  if (error) {
+    if (hadError) *hadError = true;
+    return value;
+  }
+
+  // If we're producing an arbitrary-precision value, we don't need to do
+  // much additional processing.
+  if (isArbitraryWidth()) {
+    // The parser above always produces a non-negative value, so if the sign
+    // bit is set we need to give it some breathing room.
+    if (value.isNegative())
+      value = value.zext(value.getBitWidth() + 1);
+    assert(!value.isNegative());
+
+    // Now we can safely negate.
+    if (negate) {
+      value = -value;
+      assert(value.isNegative() || value.isNullValue());
+    }
+
+    // Truncate down to the minimum number of bits required to express
+    // this value exactly.
+    auto requiredBits = value.getMinSignedBits();
+    if (value.getBitWidth() > requiredBits)
+      value = value.trunc(requiredBits);
+
+  // If we have a fixed-width type (including abstract ones), we need to do
+  // fixed-width transformations, which can overflow.
+  } else {
+    unsigned width = getGreatestWidth();
+
+    // The overflow diagnostics in this case can't be fully correct because
+    // we don't know whether we're supposed to be producing a signed number
+    // or an unsigned one.
+
+    if (hadError && value.getActiveBits() > width)
+      *hadError = true;
+    value = value.zextOrTrunc(width);
+
+    if (negate) {
+      value = -value;
+
+      if (hadError && !value.isNegative())
+        *hadError = true;
+    }
+
+    assert(value.getBitWidth() == width);
+  }
+
+  return value;
 }
 
 static APFloat getFloatLiteralValue(bool IsNegative, StringRef Text,
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index e18b663..9406e42 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -201,6 +201,7 @@
   case TypeKind::Error:
   case TypeKind::Unresolved:
   case TypeKind::BuiltinInteger:
+  case TypeKind::BuiltinIntegerLiteral:
   case TypeKind::BuiltinFloat:
   case TypeKind::BuiltinRawPointer:
   case TypeKind::BuiltinUnsafeValueBuffer:
@@ -4018,6 +4019,7 @@
   case TypeKind::Error:
   case TypeKind::Unresolved:
   case TypeKind::BuiltinInteger:
+  case TypeKind::BuiltinIntegerLiteral:
   case TypeKind::BuiltinFloat:
   case TypeKind::BuiltinRawPointer:
   case TypeKind::BuiltinUnsafeValueBuffer:
diff --git a/lib/Demangling/Demangler.cpp b/lib/Demangling/Demangler.cpp
index 0b808a9..b9df9a5 100644
--- a/lib/Demangling/Demangler.cpp
+++ b/lib/Demangling/Demangler.cpp
@@ -982,6 +982,10 @@
       Ty = createNode(Node::Kind::BuiltinTypeName, name);
       break;
     }
+    case 'I':
+      Ty = createNode(Node::Kind::BuiltinTypeName,
+                      BUILTIN_TYPE_NAME_INTLITERAL);
+      break;
     case 'v': {
       int elts = demangleIndex() - 1;
       if (elts <= 0 || elts > maxTypeSize)
diff --git a/lib/Demangling/Remangler.cpp b/lib/Demangling/Remangler.cpp
index 2f80284..3aa2f09 100644
--- a/lib/Demangling/Remangler.cpp
+++ b/lib/Demangling/Remangler.cpp
@@ -681,6 +681,8 @@
     Buffer << 'p';
   } else if (text == BUILTIN_TYPE_NAME_SILTOKEN) {
     Buffer << 't';
+  } else if (text == BUILTIN_TYPE_NAME_INTLITERAL) {
+    Buffer << 'I';
   } else if (text == BUILTIN_TYPE_NAME_WORD) {
     Buffer << 'w';
   } else if (text.consume_front(BUILTIN_TYPE_NAME_INT)) {
diff --git a/lib/Frontend/ArgsToFrontendOutputsConverter.cpp b/lib/Frontend/ArgsToFrontendOutputsConverter.cpp
index 9eed9b4..c43c64d 100644
--- a/lib/Frontend/ArgsToFrontendOutputsConverter.cpp
+++ b/lib/Frontend/ArgsToFrontendOutputsConverter.cpp
@@ -507,14 +507,16 @@
 
 Optional<std::vector<SupplementaryOutputPaths>>
 SupplementaryOutputPathsComputer::readSupplementaryOutputFileMap() const {
-  if (Arg *A = Args.getLastArg(options::OPT_emit_objc_header_path,
-                               options::OPT_emit_module_path,
-                               options::OPT_emit_module_doc_path,
-                               options::OPT_emit_dependencies_path,
-                               options::OPT_emit_reference_dependencies_path,
-                               options::OPT_serialize_diagnostics_path,
-                               options::OPT_emit_loaded_module_trace_path,
-                               options::OPT_emit_tbd_path)) {
+  if (Arg *A = Args.getLastArg(
+        options::OPT_emit_objc_header_path,
+        options::OPT_emit_module_path,
+        options::OPT_emit_module_doc_path,
+        options::OPT_emit_dependencies_path,
+        options::OPT_emit_reference_dependencies_path,
+        options::OPT_serialize_diagnostics_path,
+        options::OPT_emit_loaded_module_trace_path,
+        options::OPT_emit_parseable_module_interface_path,
+        options::OPT_emit_tbd_path)) {
     Diags.diagnose(SourceLoc(),
                    diag::error_cannot_have_supplementary_outputs,
                    A->getSpelling(), "-supplementary-output-file-map");
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index bfcbd40..e011746 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -159,9 +159,9 @@
 /// Save a copy of any flags marked as ParseableInterfaceOption, if running
 /// in a mode that is going to emit a .swiftinterface file.
 static void SaveParseableInterfaceArgs(ParseableInterfaceOptions &Opts,
+                                       FrontendOptions &FOpts,
                                        ArgList &Args, DiagnosticEngine &Diags) {
-  if (!Args.hasArg(options::OPT_emit_interface_path) &&
-      !Args.hasArg(options::OPT_emit_parseable_module_interface_path))
+  if (!FOpts.InputsAndOutputs.hasParseableInterfaceOutputPath())
     return;
   ArgStringList RenderedArgs;
   for (auto A : Args) {
@@ -1188,13 +1188,14 @@
     return true;
   }
 
-  SaveParseableInterfaceArgs(ParseableInterfaceOpts, ParsedArgs, Diags);
-
   if (ParseFrontendArgs(FrontendOpts, ParsedArgs, Diags,
                         ConfigurationFileBuffers)) {
     return true;
   }
 
+  SaveParseableInterfaceArgs(ParseableInterfaceOpts, FrontendOpts,
+                             ParsedArgs, Diags);
+
   if (ParseLangArgs(LangOpts, ParsedArgs, Diags, FrontendOpts)) {
     return true;
   }
diff --git a/lib/IRGen/CMakeLists.txt b/lib/IRGen/CMakeLists.txt
index 2e97167..b0a59ca 100644
--- a/lib/IRGen/CMakeLists.txt
+++ b/lib/IRGen/CMakeLists.txt
@@ -21,6 +21,7 @@
   GenFunc.cpp
   GenHeap.cpp
   GenInit.cpp
+  GenIntegerLiteral.cpp
   GenKeyPath.cpp
   GenMeta.cpp
   GenObjC.cpp
diff --git a/lib/IRGen/GenBuiltin.cpp b/lib/IRGen/GenBuiltin.cpp
index b9bce4a..8607de9 100644
--- a/lib/IRGen/GenBuiltin.cpp
+++ b/lib/IRGen/GenBuiltin.cpp
@@ -28,6 +28,7 @@
 #include "Explosion.h"
 #include "GenCall.h"
 #include "GenCast.h"
+#include "GenIntegerLiteral.h"
 #include "IRGenFunction.h"
 #include "IRGenModule.h"
 #include "LoadableTypeInfo.h"
@@ -690,10 +691,20 @@
   if (Builtin.ID == BuiltinValueKind::SToSCheckedTrunc ||
       Builtin.ID == BuiltinValueKind::UToUCheckedTrunc ||
       Builtin.ID == BuiltinValueKind::SToUCheckedTrunc) {
+    bool Signed = (Builtin.ID == BuiltinValueKind::SToSCheckedTrunc);
+
+    auto FromType = Builtin.Types[0]->getCanonicalType();
+    auto ToTy = cast<llvm::IntegerType>(
+      IGF.IGM.getStorageTypeForLowered(Builtin.Types[1]->getCanonicalType()));
+
+    // Handle the arbitrary-precision truncate specially.
+    if (isa<BuiltinIntegerLiteralType>(FromType)) {
+      emitIntegerLiteralCheckedTrunc(IGF, args, ToTy, Signed, out);
+      return;
+    }
+
     auto FromTy =
-      IGF.IGM.getStorageTypeForLowered(Builtin.Types[0]->getCanonicalType());
-    auto ToTy =
-      IGF.IGM.getStorageTypeForLowered(Builtin.Types[1]->getCanonicalType());
+      IGF.IGM.getStorageTypeForLowered(FromType);
 
     // Compute the result for SToSCheckedTrunc_IntFrom_IntTo(Arg):
     //   Res = trunc_IntTo(Arg)
@@ -709,7 +720,6 @@
     //   return (Res, OverflowFlag)
     llvm::Value *Arg = args.claimNext();
     llvm::Value *Res = IGF.Builder.CreateTrunc(Arg, ToTy);
-    bool Signed = (Builtin.ID == BuiltinValueKind::SToSCheckedTrunc);
     llvm::Value *Ext = Signed ? IGF.Builder.CreateSExt(Res, FromTy) :
                                 IGF.Builder.CreateZExt(Res, FromTy);
     llvm::Value *OverflowCond = IGF.Builder.CreateICmpEQ(Arg, Ext);
@@ -767,21 +777,12 @@
   // We are currently emitting code for '_convertFromBuiltinIntegerLiteral',
   // which will call the builtin and pass it a non-compile-time-const parameter.
   if (Builtin.ID == BuiltinValueKind::IntToFPWithOverflow) {
-    auto ToTy =
+    assert(Builtin.Types[0]->is<BuiltinIntegerLiteralType>());
+    auto toType =
       IGF.IGM.getStorageTypeForLowered(Builtin.Types[1]->getCanonicalType());
-    llvm::Value *Arg = args.claimNext();
-    unsigned bitSize = Arg->getType()->getScalarSizeInBits();
-    if (bitSize > 64) {
-      // TODO: the integer literal bit size is 2048, but we only have a 64-bit
-      // conversion function available (on all platforms).
-      Arg = IGF.Builder.CreateTrunc(Arg, IGF.IGM.Int64Ty);
-    } else if (bitSize < 64) {
-      // Just for completeness. IntToFPWithOverflow is currently only used to
-      // convert 2048 bit integer literals.
-      Arg = IGF.Builder.CreateSExt(Arg, IGF.IGM.Int64Ty);
-    }
-    llvm::Value *V = IGF.Builder.CreateSIToFP(Arg, ToTy);
-    return out.add(V);
+    auto result = emitIntegerLiteralToFP(IGF, args, toType);
+    out.add(result);
+    return;
   }
 
   if (Builtin.ID == BuiltinValueKind::Once
diff --git a/lib/IRGen/GenClass.cpp b/lib/IRGen/GenClass.cpp
index b30653b..e268a6b 100644
--- a/lib/IRGen/GenClass.cpp
+++ b/lib/IRGen/GenClass.cpp
@@ -993,17 +993,17 @@
   SILType selfType = getSelfType(D);
   auto &classTI = getTypeInfo(selfType).as<ClassTypeInfo>();
 
-  // FIXME: For now, always use the fragile layout when emitting metadata.
+  // Use the fragile layout when emitting metadata.
   auto &fragileLayout =
     classTI.getClassLayout(*this, selfType, /*forBackwardDeployment=*/true);
 
-  // ... but still compute the resilient layout for better test coverage.
+  // The resilient layout tells us what parts of the metadata can be
+  // updated at runtime by the Objective-C metadata update callback.
   auto &resilientLayout =
     classTI.getClassLayout(*this, selfType, /*forBackwardDeployment=*/false);
-  (void) resilientLayout;
 
   // Emit the class metadata.
-  emitClassMetadata(*this, D, fragileLayout);
+  emitClassMetadata(*this, D, fragileLayout, resilientLayout);
 
   IRGen.addClassForEagerInitialization(D);
 
diff --git a/lib/IRGen/GenConstant.cpp b/lib/IRGen/GenConstant.cpp
index d59bad3..27ed4d8 100644
--- a/lib/IRGen/GenConstant.cpp
+++ b/lib/IRGen/GenConstant.cpp
@@ -17,6 +17,7 @@
 #include "llvm/IR/Constants.h"
 
 #include "GenConstant.h"
+#include "GenIntegerLiteral.h"
 #include "GenStruct.h"
 #include "GenTuple.h"
 #include "TypeInfo.h"
@@ -29,19 +30,27 @@
 
 llvm::Constant *irgen::emitConstantInt(IRGenModule &IGM,
                                        IntegerLiteralInst *ILI) {
-  APInt value = ILI->getValue();
   BuiltinIntegerWidth width
-    = ILI->getType().castTo<BuiltinIntegerType>()->getWidth();
+    = ILI->getType().castTo<AnyBuiltinIntegerType>()->getWidth();
+
+  // Handle arbitrary-precision integers.
+  if (width.isArbitraryWidth()) {
+    auto pair = emitConstantIntegerLiteral(IGM, ILI);
+    auto type = IGM.getIntegerLiteralTy();
+    return llvm::ConstantStruct::get(type, { pair.Data, pair.Flags });
+  }
+
+  APInt value = ILI->getValue();
 
   // The value may need truncation if its type had an abstract size.
-  if (!width.isFixedWidth()) {
-    assert(width.isPointerWidth() && "impossible width value");
-
+  if (width.isPointerWidth()) {
     unsigned pointerWidth = IGM.getPointerSize().getValueInBits();
     assert(pointerWidth <= value.getBitWidth()
            && "lost precision at AST/SIL level?!");
     if (pointerWidth < value.getBitWidth())
       value = value.trunc(pointerWidth);
+  } else {
+    assert(width.isFixedWidth() && "impossible width value");
   }
 
   return llvm::ConstantInt::get(IGM.LLVMContext, value);
diff --git a/lib/IRGen/GenEnum.cpp b/lib/IRGen/GenEnum.cpp
index a0da836..03430df 100644
--- a/lib/IRGen/GenEnum.cpp
+++ b/lib/IRGen/GenEnum.cpp
@@ -1077,9 +1077,9 @@
       auto intExpr = cast<IntegerLiteralExpr>(target->getRawValueExpr());
       auto intType = getDiscriminatorType();
 
-      APInt intValue = IntegerLiteralExpr::getValue(intExpr->getDigitsText(),
-                                                    intType->getBitWidth(),
-                                                    intExpr->isNegative());
+      APInt intValue =
+        BuiltinIntegerWidth::fixed(intType->getBitWidth())
+          .parse(intExpr->getDigitsText(), /*radix*/ 0, intExpr->isNegative());
 
       return intValue.getZExtValue();
     }
diff --git a/lib/IRGen/GenIntegerLiteral.cpp b/lib/IRGen/GenIntegerLiteral.cpp
new file mode 100644
index 0000000..0e2d721
--- /dev/null
+++ b/lib/IRGen/GenIntegerLiteral.cpp
@@ -0,0 +1,412 @@
+//===--- GenIntegerLiteral.cpp - IRGen for Builtin.IntegerLiteral ---------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file implements IR generation for Builtin.IntegerLiteral.
+//
+//===----------------------------------------------------------------------===//
+
+#include "GenIntegerLiteral.h"
+
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "swift/ABI/MetadataValues.h"
+#include "Explosion.h"
+#include "ExtraInhabitants.h"
+#include "GenType.h"
+#include "IRGenFunction.h"
+#include "IRGenModule.h"
+#include "LoadableTypeInfo.h"
+#include "ScalarPairTypeInfo.h"
+
+using namespace swift;
+using namespace irgen;
+
+namespace {
+
+/// A TypeInfo implementation for Builtin.IntegerLiteral.
+class IntegerLiteralTypeInfo :
+  public ScalarPairTypeInfo<IntegerLiteralTypeInfo, LoadableTypeInfo> {
+
+public:
+  IntegerLiteralTypeInfo(llvm::StructType *storageType,
+                         Size size, Alignment align, SpareBitVector &&spareBits)
+      : ScalarPairTypeInfo(storageType, size, std::move(spareBits), align,
+                           IsPOD, IsFixedSize) {}
+
+  static Size getFirstElementSize(IRGenModule &IGM) {
+    return IGM.getPointerSize();
+  }
+  static StringRef getFirstElementLabel() {
+    return ".data";
+  }
+  static bool isFirstElementTrivial() {
+    return true;
+  }
+  void emitRetainFirstElement(IRGenFunction &IGF, llvm::Value *fn,
+                              Optional<Atomicity> atomicity = None) const {}
+  void emitReleaseFirstElement(IRGenFunction &IGF, llvm::Value *fn,
+                               Optional<Atomicity> atomicity = None) const {}
+  void emitAssignFirstElement(IRGenFunction &IGF, llvm::Value *fn,
+                              Address fnAddr) const {
+    IGF.Builder.CreateStore(fn, fnAddr);
+  }
+
+  static Size getSecondElementOffset(IRGenModule &IGM) {
+    return IGM.getPointerSize();
+  }
+  static Size getSecondElementSize(IRGenModule &IGM) {
+    return IGM.getPointerSize();
+  }
+  static StringRef getSecondElementLabel() {
+    return ".flags";
+  }
+  bool isSecondElementTrivial() const {
+    return true;
+  }
+  void emitRetainSecondElement(IRGenFunction &IGF, llvm::Value *data,
+                               Optional<Atomicity> atomicity = None) const {}
+  void emitReleaseSecondElement(IRGenFunction &IGF, llvm::Value *data,
+                                Optional<Atomicity> atomicity = None) const {}
+  void emitAssignSecondElement(IRGenFunction &IGF, llvm::Value *context,
+                               Address dataAddr) const {
+    IGF.Builder.CreateStore(context, dataAddr);
+  }
+
+  // The data pointer isn't a heap object, but it is an aligned pointer.
+  bool mayHaveExtraInhabitants(IRGenModule &IGM) const override {
+    return true;
+  }
+  unsigned getFixedExtraInhabitantCount(IRGenModule &IGM) const override {
+    return getHeapObjectExtraInhabitantCount(IGM);
+  }
+  APInt getFixedExtraInhabitantValue(IRGenModule &IGM,
+                                     unsigned bits,
+                                     unsigned index) const override {
+    return getHeapObjectFixedExtraInhabitantValue(IGM, bits, index, 0);
+  }
+  llvm::Value *getExtraInhabitantIndex(IRGenFunction &IGF, Address src,
+                                       SILType T,
+                                       bool isOutlined) const override {
+    src = projectFirstElement(IGF, src);
+    return getHeapObjectExtraInhabitantIndex(IGF, src);
+  }
+  APInt getFixedExtraInhabitantMask(IRGenModule &IGM) const override {
+    auto pointerSize = IGM.getPointerSize().getValueInBits();
+    APInt bits = APInt::getAllOnesValue(pointerSize);
+    bits = bits.zext(pointerSize * 2);
+    return bits;
+  }
+  void storeExtraInhabitant(IRGenFunction &IGF, llvm::Value *index,
+                            Address dest, SILType T,
+                            bool isOutlined) const override {
+    dest = projectFirstElement(IGF, dest);
+    storeHeapObjectExtraInhabitant(IGF, index, dest);
+  }
+};
+
+}
+
+llvm::StructType *IRGenModule::getIntegerLiteralTy() {
+  if (!IntegerLiteralTy) {
+    IntegerLiteralTy =
+      llvm::StructType::create(LLVMContext, {
+                                 SizeTy->getPointerTo(),
+                                 SizeTy
+                               }, "swift.int_literal");
+  }
+  return IntegerLiteralTy;
+}
+
+const LoadableTypeInfo &
+TypeConverter::getIntegerLiteralTypeInfo() {
+  if (!IntegerLiteralTI) {
+    auto ty = IGM.getIntegerLiteralTy();
+
+    SpareBitVector spareBits;
+    spareBits.append(IGM.getHeapObjectSpareBits());
+    spareBits.appendClearBits(IGM.getPointerSize().getValueInBits());
+
+    IntegerLiteralTI =
+      new IntegerLiteralTypeInfo(ty, IGM.getPointerSize() * 2,
+                                 IGM.getPointerAlignment(),
+                                 std::move(spareBits));
+  }
+  return *IntegerLiteralTI;
+}
+
+ConstantIntegerLiteral
+irgen::emitConstantIntegerLiteral(IRGenModule &IGM, IntegerLiteralInst *ILI) {
+  return IGM.getConstantIntegerLiteral(ILI->getValue());
+}
+
+ConstantIntegerLiteral
+IRGenModule::getConstantIntegerLiteral(APInt value) {
+  if (!ConstantIntegerLiterals)
+    ConstantIntegerLiterals.reset(new ConstantIntegerLiteralMap());
+
+  return ConstantIntegerLiterals->get(*this, std::move(value));
+}
+
+ConstantIntegerLiteral
+ConstantIntegerLiteralMap::get(IRGenModule &IGM, APInt &&value) {
+  auto &entry = map[value];
+  if (entry.Data) return entry;
+
+  assert(value.getMinSignedBits() == value.getBitWidth() &&
+         "expected IntegerLiteral value to be maximally compact");
+
+  // We're going to break the value down into pointer-sized chunks.
+  uint64_t chunkSizeInBits = IGM.getPointerSize().getValueInBits();
+
+  // Count how many bits are needed to store the value, including the sign bit.
+  uint64_t minWidthInBits = value.getBitWidth();
+
+  // Round up to the nearest multiple of the chunk size.
+  uint64_t storageWidthInBits = (minWidthInBits + chunkSizeInBits - 1)
+                                & ~(chunkSizeInBits - 1);
+
+  // Extend the value to that width.  We guarantee that extra bits in the
+  // chunks will be appropriately sign-extended.
+  value = value.sextOrTrunc(storageWidthInBits);
+
+  // Extract the individual chunks from the extended value.
+  uint64_t numChunks = storageWidthInBits / chunkSizeInBits;
+  SmallVector<llvm::Constant *, 4> chunks;
+  chunks.reserve(numChunks);
+  for (uint64_t i = 0; i != numChunks; ++i) {
+    auto chunk = value.extractBits(chunkSizeInBits, i * chunkSizeInBits);
+    chunks.push_back(llvm::ConstantInt::get(IGM.SizeTy, std::move(chunk)));
+  }
+
+  // Build a global to hold the chunks.
+  // TODO: make this shared within the image
+  auto arrayTy = llvm::ArrayType::get(IGM.SizeTy, numChunks);
+  auto initV = llvm::ConstantArray::get(arrayTy, chunks);
+  auto globalArray =
+    new llvm::GlobalVariable(*IGM.getModule(), arrayTy, /*constant*/ true,
+                             llvm::GlobalVariable::PrivateLinkage, initV,
+                             IGM.EnableValueNames
+                               ? Twine("intliteral.") + value.toString(10, true)
+                               : "");
+  globalArray->setUnnamedAddr(llvm::GlobalVariable::UnnamedAddr::Global);
+
+  // Various clients expect this to be a i64*, not an [N x i64]*, so cast down.
+  auto zero = llvm::ConstantInt::get(IGM.Int32Ty, 0);
+  llvm::Constant *indices[] = { zero, zero };
+  auto data = llvm::ConstantExpr::getInBoundsGetElementPtr(arrayTy, globalArray,
+                                                           indices);
+
+  // Build the flags word.
+  auto flags = IntegerLiteralFlags(minWidthInBits, value.isNegative());
+  auto flagsV = llvm::ConstantInt::get(IGM.SizeTy, flags.getOpaqueValue());
+
+  // Cache the global.
+  entry.Data = data;
+  entry.Flags = flagsV;
+  return entry;
+}
+
+void irgen::emitIntegerLiteralCheckedTrunc(IRGenFunction &IGF,
+                                           Explosion &in,
+                                           llvm::IntegerType *resultTy,
+                                           bool resultIsSigned,
+                                           Explosion &out) {
+  Address data(in.claimNext(), IGF.IGM.getPointerAlignment());
+  auto flags = in.claimNext();
+
+  size_t chunkWidth = IGF.IGM.getPointerSize().getValueInBits();
+  size_t resultWidth = resultTy->getBitWidth();
+
+  // The number of bits required to express the value, including the sign bit.
+  auto valueWidth = IGF.Builder.CreateLShr(flags,
+                    IGF.IGM.getSize(Size(IntegerLiteralFlags::BitWidthShift)));
+
+  // The maximum number of chunks that we need to read in order to fill the
+  // result type: ceil(resultWidth / chunkWidth).
+  // Note that we won't actually end up reading the final chunk if we're
+  // building an unsigned value that requires e.g. 65 bits to express:
+  // there's only one meaningful bit there, and we know it's zero from the
+  // isNegative check.
+  size_t maxNumChunks = (resultWidth + chunkWidth - 1) / chunkWidth;
+
+  // One branch from invalidBB, one branch at each intermediate point in the
+  // do-we-have-more-chunks chain, and one branch at the end.
+  auto numPHIEntries = maxNumChunks + /*overflow*/ 1;
+
+  auto boolTy = IGF.IGM.Int1Ty;
+  auto doneBB = IGF.createBasicBlock("intliteral.trunc.done");
+  auto resultPHI = llvm::PHINode::Create(resultTy, numPHIEntries, "", doneBB);
+  auto overflowPHI = llvm::PHINode::Create(boolTy, numPHIEntries, "", doneBB);
+  out.add(resultPHI);
+  out.add(overflowPHI);
+
+  auto validBB = IGF.createBasicBlock("intliteral.trunc.valid");
+  auto invalidBB = IGF.createBasicBlock("intliteral.trunc.invalid");
+
+  // Check whether the value fits in the result type.
+  // If the result is signed, then we need valueWidth <= resultWidth.
+  // Otherwise we need valueWidth <= resultWidth + 1 && !isNegative.
+  {
+    llvm::Value *hasOverflow;
+    if (resultIsSigned) {
+      hasOverflow = IGF.Builder.CreateICmpUGT(valueWidth,
+                                        IGF.IGM.getSize(Size(resultWidth)));
+    } else {
+      static_assert(IntegerLiteralFlags::IsNegativeFlag == 1,
+                    "hardcoded in this truncation");
+      auto isNegative = IGF.Builder.CreateTrunc(flags, boolTy);
+      auto tooBig = IGF.Builder.CreateICmpUGT(valueWidth,
+                                        IGF.IGM.getSize(Size(resultWidth + 1)));
+      hasOverflow = IGF.Builder.CreateOr(isNegative, tooBig);
+    }
+    IGF.Builder.CreateCondBr(hasOverflow, invalidBB, validBB);
+  }
+
+  // In the invalid block, we just need to construct the result.  This block
+  // only exists to split the otherwise-critical edge.
+  IGF.Builder.emitBlock(invalidBB);
+  {
+    resultPHI->addIncoming(llvm::ConstantInt::get(resultTy, 0), invalidBB);
+    overflowPHI->addIncoming(llvm::ConstantInt::get(boolTy, 1), invalidBB);
+    IGF.Builder.CreateBr(doneBB);
+  }
+
+  // Okay, the value fits in the result type, so overflow is off the table
+  // and we just need to assemble a value of resultTy.  But we might not have
+  // the full complement of chunks.
+  IGF.Builder.emitBlock(validBB);
+  {
+    auto firstChunk = IGF.Builder.CreateLoad(data);
+
+    // The easy case is if resultWidth <= chunkWidth, in which case knowing
+    // that we haven't overflowed is sufficient to say that we can just
+    // use the first chunk.
+    if (resultWidth <= chunkWidth) {
+      auto result = IGF.Builder.CreateTrunc(firstChunk, resultTy);
+      resultPHI->addIncoming(result, validBB);
+      overflowPHI->addIncoming(llvm::ConstantInt::get(boolTy, 0), validBB);
+      IGF.Builder.CreateBr(doneBB);
+
+    // Otherwise, we're going to have to test dynamically how many chunks
+    // we need to read.
+    } else {
+      assert(maxNumChunks >= 2);
+      llvm::Value *cur = firstChunk;
+      for (size_t i = 1; i != maxNumChunks; ++i) {
+        auto extendBB = IGF.createBasicBlock("intliteral.trunc.finish");
+        auto nextBB = IGF.createBasicBlock("intliteral.trunc.next");
+
+        // If the result is signed, then we're done if:
+        //   valueWidth <= bitsInChunksReadSoFar
+        // If the result is unsigned, then we're done if:
+        //   valueWidth <= bitsInChunksReadSoFar + 1
+        // (because we know the next bit will be zero)
+        auto limit = i * chunkWidth + size_t(!resultIsSigned);
+        auto isComplete =
+          IGF.Builder.CreateICmpULE(valueWidth, IGF.IGM.getSize(Size(limit)));
+        IGF.Builder.CreateCondBr(isComplete, extendBB, nextBB);
+
+        // If we're done, extend the current value to the result type and
+        // then branch out.
+        IGF.Builder.emitBlock(extendBB);
+        {
+          auto extendedResult =
+            resultIsSigned ? IGF.Builder.CreateSExt(cur, resultTy)
+                           : IGF.Builder.CreateZExt(cur, resultTy);
+          resultPHI->addIncoming(extendedResult, extendBB);
+          overflowPHI->addIncoming(llvm::ConstantInt::get(boolTy, 0), extendBB);
+          IGF.Builder.CreateBr(doneBB);
+        }
+
+        // Otherwise, load the next chunk.
+        IGF.Builder.emitBlock(nextBB);
+        auto nextChunkAddr =
+          IGF.Builder.CreateConstArrayGEP(data, i, IGF.IGM.getPointerSize());
+        auto nextChunk = IGF.Builder.CreateLoad(nextChunkAddr);
+
+        // Zero-extend the current value and the chunk and then shift the
+        // chunk into place.  If this is the last iteration, we should use
+        // the final result type; the shift might then drop bits, but they
+        // should just be sign-extension bits.
+        auto nextTy = (i + 1 == maxNumChunks
+                         ? resultTy
+                         : llvm::IntegerType::get(IGF.IGM.getLLVMContext(),
+                                                  (i + 1) * chunkWidth));
+        cur = IGF.Builder.CreateZExt(cur, nextTy);
+        auto shiftedNextChunk =
+          IGF.Builder.CreateShl(IGF.Builder.CreateZExt(nextChunk, nextTy),
+                                i * chunkWidth);
+        cur = IGF.Builder.CreateAdd(cur, shiftedNextChunk);
+      }
+
+      // Given the overflow check before, we know we don't need to look at
+      // any more chunks.
+      assert(cur->getType() == resultTy);
+      auto curBB = IGF.Builder.GetInsertBlock();
+      resultPHI->addIncoming(cur, curBB);
+      overflowPHI->addIncoming(llvm::ConstantInt::get(boolTy, 0), curBB);
+      IGF.Builder.CreateBr(doneBB);
+    }
+  }
+
+  // Emit the continuation block.  We've already set up the PHIs here and
+  // add them to `out`, so there's nothing else to do.
+  IGF.Builder.emitBlock(doneBB);
+}
+
+static llvm::Value *emitIntegerLiteralToFloatCall(IRGenFunction &IGF,
+                                                  llvm::Value *data,
+                                                  llvm::Value *flags,
+                                                  unsigned bitWidth) {
+  assert(bitWidth == 32 || bitWidth == 64);
+  auto fn = bitWidth == 32 ? IGF.IGM.getIntToFloat32Fn()
+                           : IGF.IGM.getIntToFloat64Fn();
+  auto call = IGF.Builder.CreateCall(fn, {data, flags});
+  call->setCallingConv(IGF.IGM.SwiftCC);
+  call->setDoesNotThrow();
+  call->setOnlyReadsMemory();
+  call->setOnlyAccessesArgMemory();
+
+  return call;
+}
+
+llvm::Value *irgen::emitIntegerLiteralToFP(IRGenFunction &IGF,
+                                           Explosion &in,
+                                           llvm::Type *toType) {
+  auto data = in.claimNext();
+  auto flags = in.claimNext();
+
+  assert(toType->isFloatingPointTy());
+  switch (toType->getTypeID()) {
+  case llvm::Type::HalfTyID: {
+    auto flt = emitIntegerLiteralToFloatCall(IGF, data, flags, 32);
+    return IGF.Builder.CreateFPTrunc(flt, toType);
+  }
+
+  case llvm::Type::FloatTyID:
+    return emitIntegerLiteralToFloatCall(IGF, data, flags, 32);
+
+  case llvm::Type::DoubleTyID:
+    return emitIntegerLiteralToFloatCall(IGF, data, flags, 64);
+
+  // TODO: add runtime functions for some of these?
+  case llvm::Type::X86_FP80TyID:
+  case llvm::Type::FP128TyID:
+  case llvm::Type::PPC_FP128TyID: {
+    auto dbl = emitIntegerLiteralToFloatCall(IGF, data, flags, 64);
+    return IGF.Builder.CreateFPExt(dbl, toType);
+  }
+
+  default:
+    llvm_unreachable("not a floating-point type");
+  }
+}
diff --git a/lib/IRGen/GenIntegerLiteral.h b/lib/IRGen/GenIntegerLiteral.h
new file mode 100644
index 0000000..91d6bd6
--- /dev/null
+++ b/lib/IRGen/GenIntegerLiteral.h
@@ -0,0 +1,73 @@
+//===--- GenIntegerLiteral.h - IRGen for Builtin.IntegerLiteral -*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines interfaces for emitting code for Builtin.IntegerLiteral
+// values.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SWIFT_IRGEN_GENINTEGERLITERAL_H
+#define SWIFT_IRGEN_GENINTEGERLITERAL_H
+
+#include "swift/Basic/APIntMap.h"
+
+namespace llvm {
+class Constant;
+class IntegerType;
+class Type;
+class Value;
+}
+
+namespace swift {
+class IntegerLiteralInst;
+
+namespace irgen {
+class Explosion;
+class IRGenFunction;
+class IRGenModule;
+
+/// A constant integer literal value.
+struct ConstantIntegerLiteral {
+  llvm::Constant *Data;
+  llvm::Constant *Flags;
+};
+
+/// A map for caching globally-emitted constant integers.
+class ConstantIntegerLiteralMap {
+  APIntMap<ConstantIntegerLiteral> map;
+
+public:
+  ConstantIntegerLiteralMap() {}
+
+  ConstantIntegerLiteral get(IRGenModule &IGM, APInt &&value);
+};
+
+/// Construct a constant IntegerLiteral from an IntegerLiteralInst.
+ConstantIntegerLiteral
+emitConstantIntegerLiteral(IRGenModule &IGM, IntegerLiteralInst *ILI);
+
+/// Emit a checked truncation of an IntegerLiteral value.
+void emitIntegerLiteralCheckedTrunc(IRGenFunction &IGF,
+                                    Explosion &in,
+                                    llvm::IntegerType *resultTy,
+                                    bool resultIsSigned,
+                                    Explosion &out);
+
+/// Emit a sitofp operation on an IntegerLiteral value.
+llvm::Value *emitIntegerLiteralToFP(IRGenFunction &IGF,
+                                    Explosion &in,
+                                    llvm::Type *toType);
+
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/lib/IRGen/GenMeta.cpp b/lib/IRGen/GenMeta.cpp
index de875cd..f220f02 100644
--- a/lib/IRGen/GenMeta.cpp
+++ b/lib/IRGen/GenMeta.cpp
@@ -2293,9 +2293,10 @@
 
 static void emitFieldOffsetGlobals(IRGenModule &IGM,
                                    ClassDecl *classDecl,
-                                   const ClassLayout &classLayout) {
+                                   const ClassLayout &fragileLayout,
+                                   const ClassLayout &resilientLayout) {
   for (auto prop : classDecl->getStoredProperties()) {
-    auto fieldInfo = classLayout.getFieldAccessAndElement(prop);
+    auto fieldInfo = fragileLayout.getFieldAccessAndElement(prop);
     auto access = fieldInfo.first;
     auto element = fieldInfo.second;
 
@@ -2323,8 +2324,19 @@
       auto offsetVar = cast<llvm::GlobalVariable>(offsetAddr.getAddress());
       offsetVar->setInitializer(fieldOffsetOrZero);
 
-      // If we know the offset won't change, make it a constant.
-      offsetVar->setConstant(access == FieldAccess::ConstantDirect);
+      // If the offset is constant in the resilient layout, it will not change
+      // at runtime, and the global can be true const.
+      //
+      // If it is constant in the fragile layout only, newer Objective-C
+      // runtimes will still update them in place, so make sure to check the
+      // correct layout.
+      auto resilientInfo = resilientLayout.getFieldAccessAndElement(prop);
+      if (resilientInfo.first == FieldAccess::ConstantDirect) {
+        // If it is constant in the resilient layout, it should be constant in
+        // the fragile layout also.
+        assert(access == FieldAccess::ConstantDirect);
+        offsetVar->setConstant(true);
+      }
 
       break;
     }
@@ -3015,11 +3027,12 @@
 
 /// Emit the type metadata or metadata template for a class.
 void irgen::emitClassMetadata(IRGenModule &IGM, ClassDecl *classDecl,
-                              const ClassLayout &fieldLayout) {
+                              const ClassLayout &fragileLayout,
+                              const ClassLayout &resilientLayout) {
   assert(!classDecl->isForeign());
   PrettyStackTraceDecl stackTraceRAII("emitting metadata for", classDecl);
 
-  emitFieldOffsetGlobals(IGM, classDecl, fieldLayout);
+  emitFieldOffsetGlobals(IGM, classDecl, fragileLayout, resilientLayout);
 
   // Set up a dummy global to stand in for the metadata object while we produce
   // relative references.
@@ -3034,28 +3047,28 @@
   bool canBeConstant;
   if (classDecl->isGenericContext()) {
     GenericClassMetadataBuilder builder(IGM, classDecl, init,
-                                        fieldLayout);
+                                        fragileLayout);
     builder.layout();
     canBeConstant = true;
 
     builder.createMetadataAccessFunction();
   } else if (doesClassMetadataRequireRelocation(IGM, classDecl)) {
     ResilientClassMetadataBuilder builder(IGM, classDecl, init,
-                                          fieldLayout);
+                                          fragileLayout);
     builder.layout();
     canBeConstant = true;
 
     builder.createMetadataAccessFunction();
   } else if (doesClassMetadataRequireInitialization(IGM, classDecl)) {
     SingletonClassMetadataBuilder builder(IGM, classDecl, init,
-                                          fieldLayout);
+                                          fragileLayout);
     builder.layout();
     canBeConstant = builder.canBeConstant();
 
     builder.createMetadataAccessFunction();
   } else {
     FixedClassMetadataBuilder builder(IGM, classDecl, init,
-                                      fieldLayout);
+                                      fragileLayout);
     builder.layout();
     canBeConstant = builder.canBeConstant();
 
diff --git a/lib/IRGen/GenMeta.h b/lib/IRGen/GenMeta.h
index e3de497..0b20a6a 100644
--- a/lib/IRGen/GenMeta.h
+++ b/lib/IRGen/GenMeta.h
@@ -52,7 +52,8 @@
 
   /// Emit the metadata associated with the given class declaration.
   void emitClassMetadata(IRGenModule &IGM, ClassDecl *theClass,
-                         const ClassLayout &fieldLayout);
+                         const ClassLayout &fragileLayout,
+                         const ClassLayout &resilientLayout);
 
   /// Emit the constant initializer of the type metadata candidate for
   /// the given foreign class declaration.
diff --git a/lib/IRGen/GenType.cpp b/lib/IRGen/GenType.cpp
index fa7e89b..adecc37 100644
--- a/lib/IRGen/GenType.cpp
+++ b/lib/IRGen/GenType.cpp
@@ -44,7 +44,7 @@
 #include "Outlining.h"
 #include "ProtocolInfo.h"
 #include "ReferenceTypeInfo.h"
-#include "ScalarTypeInfo.h"
+#include "ScalarPairTypeInfo.h"
 #include "NativeConventionSchema.h"
 #include "IRGenMangler.h"
 #include "NonFixedTypeInfo.h"
@@ -1594,7 +1594,8 @@
     }
     llvm_unreachable("bad builtin floating-point type kind");
   case TypeKind::BuiltinInteger: {
-    unsigned BitWidth = IGM.getBuiltinIntegerWidth(cast<BuiltinIntegerType>(ty));
+    auto intTy = cast<BuiltinIntegerType>(ty);
+    unsigned BitWidth = IGM.getBuiltinIntegerWidth(intTy);
     unsigned ByteSize = (BitWidth+7U)/8U;
     // Round up the memory size and alignment to a power of 2.
     if (!llvm::isPowerOf2_32(ByteSize))
@@ -1664,6 +1665,8 @@
                            getFixedBufferAlignment(IGM));
   case TypeKind::BuiltinRawPointer:
     return &getRawPointerTypeInfo();
+  case TypeKind::BuiltinIntegerLiteral:
+    return &getIntegerLiteralTypeInfo();
   case TypeKind::BuiltinFloat:
   case TypeKind::BuiltinInteger:
   case TypeKind::BuiltinVector: {
diff --git a/lib/IRGen/GenType.h b/lib/IRGen/GenType.h
index 290ac37..a258521 100644
--- a/lib/IRGen/GenType.h
+++ b/lib/IRGen/GenType.h
@@ -99,6 +99,7 @@
   const TypeInfo *TypeMetadataPtrTI = nullptr;
   const TypeInfo *ObjCClassPtrTI = nullptr;
   const LoadableTypeInfo *EmptyTI = nullptr;
+  const LoadableTypeInfo *IntegerLiteralTI = nullptr;
 
   const TypeInfo *AccessibleResilientStructTI = nullptr;
   const TypeInfo *InaccessibleResilientStructTI = nullptr;
@@ -168,6 +169,7 @@
   const TypeInfo &getObjCClassPtrTypeInfo();
   const LoadableTypeInfo &getWitnessTablePtrTypeInfo();
   const LoadableTypeInfo &getEmptyTypeInfo();
+  const LoadableTypeInfo &getIntegerLiteralTypeInfo();
   const TypeInfo &getResilientStructTypeInfo(IsABIAccessible_t abiAccessible);
   const ProtocolInfo &getProtocolInfo(ProtocolDecl *P, ProtocolInfoKind kind);
   const LoadableTypeInfo &getOpaqueStorageTypeInfo(Size storageSize,
diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp
index 52ae291..053d87e 100644
--- a/lib/IRGen/IRGenDebugInfo.cpp
+++ b/lib/IRGen/IRGenDebugInfo.cpp
@@ -1026,6 +1026,12 @@
       break;
     }
 
+    case TypeKind::BuiltinIntegerLiteral: {
+      Encoding = llvm::dwarf::DW_ATE_unsigned; // ?
+      SizeInBits = getSizeOfBasicType(DbgTy);
+      break;
+    }
+
     case TypeKind::BuiltinFloat: {
       auto *FloatTy = BaseTy->castTo<BuiltinFloatType>();
       // Assuming that the bitwidth and FloatTy->getFPKind() are identical.
diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp
index 95b5f46..ca38053 100644
--- a/lib/IRGen/IRGenModule.cpp
+++ b/lib/IRGen/IRGenModule.cpp
@@ -48,6 +48,7 @@
 #include "llvm/Support/MD5.h"
 
 #include "GenEnum.h"
+#include "GenIntegerLiteral.h"
 #include "GenType.h"
 #include "IRGenModule.h"
 #include "IRGenDebugInfo.h"
diff --git a/lib/IRGen/IRGenModule.h b/lib/IRGen/IRGenModule.h
index 1e0cdd3..0c4177f 100644
--- a/lib/IRGen/IRGenModule.h
+++ b/lib/IRGen/IRGenModule.h
@@ -110,6 +110,8 @@
   class ClangTypeConverter;
   class ClassMetadataLayout;
   class ConformanceInfo;
+  struct ConstantIntegerLiteral;
+  class ConstantIntegerLiteralMap;
   class DebugTypeInfo;
   class EnumImplStrategy;
   class EnumMetadataLayout;
@@ -730,6 +732,8 @@
   llvm::Type *getValueWitnessTy(ValueWitness index);
   Signature getValueWitnessSignature(ValueWitness index);
 
+  llvm::StructType *getIntegerLiteralTy();
+
   void unimplemented(SourceLoc, StringRef Message);
   LLVM_ATTRIBUTE_NORETURN
   void fatal_unimplemented(SourceLoc, StringRef Message);
@@ -759,6 +763,7 @@
   llvm::Type *ValueWitnessTys[MaxNumValueWitnesses];
   llvm::FunctionType *AssociatedTypeWitnessTableAccessFunctionTy = nullptr;
   llvm::StructType *GenericWitnessTableCacheTy = nullptr;
+  llvm::StructType *IntegerLiteralTy = nullptr;
   
   llvm::DenseMap<llvm::Type *, SpareBitVector> SpareBitsForTypes;
   
@@ -865,6 +870,8 @@
                                                     CanDependentMemberType dmt);
   ConstantReference getConstantReferenceForProtocolDescriptor(ProtocolDecl *proto);
 
+  ConstantIntegerLiteral getConstantIntegerLiteral(APInt value);
+
   void addUsedGlobal(llvm::GlobalValue *global);
   void addCompilerUsedGlobal(llvm::GlobalValue *global);
   void addObjCClass(llvm::Constant *addr, bool nonlazy);
@@ -936,6 +943,8 @@
   llvm::StringMap<llvm::Constant*> ObjCSelectorRefs;
   llvm::StringMap<llvm::Constant*> ObjCMethodNames;
 
+  std::unique_ptr<ConstantIntegerLiteralMap> ConstantIntegerLiterals;
+
   /// Maps to constant swift 'String's.
   llvm::StringMap<llvm::Constant*> GlobalConstantStrings;
   llvm::StringMap<llvm::Constant*> GlobalConstantUTF16Strings;
diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp
index f60ca3c..0f633df 100644
--- a/lib/IRGen/IRGenSIL.cpp
+++ b/lib/IRGen/IRGenSIL.cpp
@@ -64,6 +64,7 @@
 #include "GenExistential.h"
 #include "GenFunc.h"
 #include "GenHeap.h"
+#include "GenIntegerLiteral.h"
 #include "GenObjC.h"
 #include "GenOpaque.h"
 #include "GenPoly.h"
@@ -2510,10 +2511,15 @@
 }
 
 void IRGenSILFunction::visitIntegerLiteralInst(swift::IntegerLiteralInst *i) {
-  llvm::Value *constant = emitConstantInt(IGM, i);
-
   Explosion e;
-  e.add(constant);
+  if (i->getType().is<BuiltinIntegerLiteralType>()) {
+    auto pair = emitConstantIntegerLiteral(IGM, i);
+    e.add(pair.Data);
+    e.add(pair.Flags);
+  } else {
+    llvm::Value *constant = emitConstantInt(IGM, i);
+    e.add(constant);
+  }
   setLoweredExplosion(i, e);
 }
 
@@ -2712,12 +2718,8 @@
 
 static llvm::ConstantInt *
 getSwitchCaseValue(IRGenFunction &IGF, SILValue val) {
-  if (auto *IL = dyn_cast<IntegerLiteralInst>(val)) {
-    return dyn_cast<llvm::ConstantInt>(emitConstantInt(IGF.IGM, IL));
-  }
-  else {
-    llvm_unreachable("Switch value cases should be integers");
-  }
+  auto *IL = cast<IntegerLiteralInst>(val);
+  return cast<llvm::ConstantInt>(emitConstantInt(IGF.IGM, IL));
 }
 
 static void
diff --git a/lib/IRGen/Linking.cpp b/lib/IRGen/Linking.cpp
index caa09f8..c4aaebe 100644
--- a/lib/IRGen/Linking.cpp
+++ b/lib/IRGen/Linking.cpp
@@ -763,6 +763,94 @@
   }
 }
 
+bool LinkEntity::isWeakImported(ModuleDecl *module) const {
+  switch (getKind()) {
+  case Kind::SILGlobalVariable:
+    if (getSILGlobalVariable()->getDecl())
+      return getSILGlobalVariable()->getDecl()->isWeakImported(module);
+    return false;
+
+  case Kind::SILFunction: {
+    // For imported functions check the Clang declaration.
+    if (auto clangOwner = getSILFunction()->getClangNodeOwner())
+      return clangOwner->isWeakImported(module);
+
+    // For native functions check a flag on the SILFunction
+    // itself.
+    if (getSILFunction()->isWeakLinked())
+      return getSILFunction()->isAvailableExternally();
+    return false;
+  }
+
+  case Kind::AssociatedConformanceDescriptor:
+  case Kind::DefaultAssociatedConformanceAccessor: {
+    // Associated conformance descriptors use the protocol as
+    // their declaration, but are weak linked if the associated
+    // type stored in extra storage area is weak linked.
+    auto assocConformance = getAssociatedConformance();
+    auto *depMemTy = assocConformance.first->castTo<DependentMemberType>();
+    return depMemTy->getAssocType()->isWeakImported(module);
+  }
+
+  case Kind::TypeMetadata:
+  case Kind::TypeMetadataAccessFunction: {
+    if (auto *nominalDecl = getType()->getAnyNominal())
+      return nominalDecl->isWeakImported(module);
+    return false;
+  }
+
+  case Kind::DispatchThunk:
+  case Kind::DispatchThunkInitializer:
+  case Kind::DispatchThunkAllocator:
+  case Kind::MethodDescriptor:
+  case Kind::MethodDescriptorInitializer:
+  case Kind::MethodDescriptorAllocator:
+  case Kind::MethodLookupFunction:
+  case Kind::EnumCase:
+  case Kind::FieldOffset:
+  case Kind::ObjCClass:
+  case Kind::ObjCClassRef:
+  case Kind::ObjCMetaclass:
+  case Kind::SwiftMetaclassStub:
+  case Kind::ObjCMetadataUpdateFunction:
+  case Kind::ClassMetadataBaseOffset:
+  case Kind::PropertyDescriptor:
+  case Kind::NominalTypeDescriptor:
+  case Kind::ModuleDescriptor:
+  case Kind::ProtocolDescriptor:
+  case Kind::ProtocolRequirementsBaseDescriptor:
+  case Kind::AssociatedTypeDescriptor:
+    return getDecl()->isWeakImported(module);
+
+  // TODO: Revisit some of the below, for weak conformances.
+  case Kind::TypeMetadataPattern:
+  case Kind::TypeMetadataInstantiationCache:
+  case Kind::TypeMetadataInstantiationFunction:
+  case Kind::TypeMetadataSingletonInitializationCache:
+  case Kind::TypeMetadataCompletionFunction:
+  case Kind::ExtensionDescriptor:
+  case Kind::AnonymousDescriptor:
+  case Kind::DirectProtocolWitnessTable:
+  case Kind::ProtocolWitnessTablePattern:
+  case Kind::GenericProtocolWitnessTableInstantiationFunction:
+  case Kind::AssociatedTypeWitnessTableAccessFunction:
+  case Kind::ReflectionAssociatedTypeDescriptor:
+  case Kind::ProtocolConformanceDescriptor:
+  case Kind::ProtocolWitnessTableLazyAccessFunction:
+  case Kind::ProtocolWitnessTableLazyCacheVariable:
+  case Kind::ValueWitness:
+  case Kind::ValueWitnessTable:
+  case Kind::TypeMetadataLazyCacheVariable:
+  case Kind::ForeignTypeMetadataCandidate:
+  case Kind::ReflectionBuiltinDescriptor:
+  case Kind::ReflectionFieldDescriptor:
+  case Kind::CoroutineContinuationPrototype:
+    return false;
+  }
+
+  llvm_unreachable("Bad link entity kind");
+}
+
 const SourceFile *LinkEntity::getSourceFileForEmission() const {
   const SourceFile *sf;
   
diff --git a/lib/IRGen/MetadataRequest.cpp b/lib/IRGen/MetadataRequest.cpp
index d05f28f..a62180e 100644
--- a/lib/IRGen/MetadataRequest.cpp
+++ b/lib/IRGen/MetadataRequest.cpp
@@ -865,6 +865,12 @@
     }
 
     MetadataResponse
+    visitBuiltinIntegerLiteralType(CanBuiltinIntegerLiteralType type,
+                                   DynamicMetadataRequest request) {
+      return emitDirectMetadataRef(type);
+    }
+
+    MetadataResponse
     visitBuiltinNativeObjectType(CanBuiltinNativeObjectType type,
                                  DynamicMetadataRequest request) {
       return emitDirectMetadataRef(type);
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 44303a1..fb04105 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -960,8 +960,8 @@
 
 /// Copy a numeric literal value into AST-owned memory, stripping underscores
 /// so the semantic part of the value can be parsed by APInt/APFloat parsers.
-static StringRef copyAndStripUnderscores(ASTContext &C, StringRef orig) {
-  char *start = static_cast<char*>(C.Allocate(orig.size(), 1));
+StringRef Parser::copyAndStripUnderscores(StringRef orig) {
+  char *start = static_cast<char*>(Context.Allocate(orig.size(), 1));
   char *p = start;
 
   if (p) {
@@ -1439,7 +1439,7 @@
   SyntaxParsingContext ExprContext(SyntaxContext, SyntaxContextKind::Expr);
   switch (Tok.getKind()) {
   case tok::integer_literal: {
-    StringRef Text = copyAndStripUnderscores(Context, Tok.getText());
+    StringRef Text = copyAndStripUnderscores(Tok.getText());
     SourceLoc Loc = consumeToken(tok::integer_literal);
     ExprContext.setCreateSyntax(SyntaxKind::IntegerLiteralExpr);
     return makeParserResult(new (Context)
@@ -1447,7 +1447,7 @@
                                                    /*Implicit=*/false));
   }
   case tok::floating_literal: {
-    StringRef Text = copyAndStripUnderscores(Context, Tok.getText());
+    StringRef Text = copyAndStripUnderscores(Tok.getText());
     SourceLoc Loc = consumeToken(tok::floating_literal);
     ExprContext.setCreateSyntax(SyntaxKind::FloatLiteralExpr);
     return makeParserResult(new (Context) FloatLiteralExpr(Text, Loc,
@@ -1598,7 +1598,7 @@
       memcpy(Ptr, "0.", 2);
       memcpy(Ptr+2, Tok.getText().data(), Tok.getLength());
       auto FltText = StringRef(Ptr, Tok.getLength()+2);
-      FltText = copyAndStripUnderscores(Context, FltText);
+      FltText = copyAndStripUnderscores(FltText);
       
       consumeToken(tok::integer_literal);
       return makeParserResult(new (Context)
diff --git a/lib/ParseSIL/ParseSIL.cpp b/lib/ParseSIL/ParseSIL.cpp
index 2d282df..e7df5b1 100644
--- a/lib/ParseSIL/ParseSIL.cpp
+++ b/lib/ParseSIL/ParseSIL.cpp
@@ -276,14 +276,29 @@
 
     bool parseVerbatim(StringRef identifier);
 
-    template <typename T> bool parseInteger(T &Result, const Diagnostic &D) {
+    template <typename T>
+    bool parseInteger(T &Result, const Diagnostic &D) {
       if (!P.Tok.is(tok::integer_literal)) {
         P.diagnose(P.Tok, D);
         return true;
       }
-      P.Tok.getText().getAsInteger(0, Result);
+      bool error = parseIntegerLiteral(P.Tok.getText(), 0, Result);
       P.consumeToken(tok::integer_literal);
-      return false;
+      return error;
+    }
+
+    template <typename T>
+    bool parseIntegerLiteral(StringRef text, unsigned radix, T &result) {
+      text = prepareIntegerLiteralForParsing(text);
+      return text.getAsInteger(radix, result);
+    }
+
+    StringRef prepareIntegerLiteralForParsing(StringRef text) {
+      // tok::integer_literal can contain characters that the library
+      // parsing routines don't expect.
+      if (text.contains('_'))
+        text = P.copyAndStripUnderscores(text);
+      return text;
     }
 
     /// @}
@@ -1352,7 +1367,7 @@
       } else
         break;
     } else if (ParseState < 2 && P.Tok.is(tok::integer_literal)) {
-      P.Tok.getText().getAsInteger(0, uncurryLevel);
+      parseIntegerLiteral(P.Tok.getText(), 0, uncurryLevel);
       P.consumeToken(tok::integer_literal);
       ParseState = 2;
     } else
@@ -1475,7 +1490,7 @@
         return true;
       }
       uint16_t ArgNo;
-      if (P.Tok.getText().getAsInteger(0, ArgNo))
+      if (parseIntegerLiteral(P.Tok.getText(), 0, ArgNo))
         return true;
       Var.ArgNo = ArgNo;
     } else if (Key == "let") {
@@ -1916,7 +1931,7 @@
            return true;
          
          if (!P.Tok.is(tok::integer_literal)
-             || P.Tok.getText().getAsInteger(0, index))
+             || parseIntegerLiteral(P.Tok.getText(), 0, index))
            return true;
          
          P.consumeToken(tok::integer_literal);
@@ -2342,21 +2357,20 @@
       return true;
     }
     
-    auto intTy = Ty.getAs<BuiltinIntegerType>();
+    auto intTy = Ty.getAs<AnyBuiltinIntegerType>();
     if (!intTy) {
       P.diagnose(P.Tok, diag::sil_integer_literal_not_integer_type);
       return true;
     }
-    
-    APInt value(intTy->getGreatestWidth(), 0);
-    bool error = P.Tok.getText().getAsInteger(0, value);
-    assert(!error && "integer_literal token did not parse as APInt?!");
-    (void)error;
-    
-    if (Negative)
-      value = -value; 
-    if (value.getBitWidth() != intTy->getGreatestWidth())
-      value = value.zextOrTrunc(intTy->getGreatestWidth());
+
+    StringRef text = prepareIntegerLiteralForParsing(P.Tok.getText());
+
+    bool error;
+    APInt value = intTy->getWidth().parse(text, 0, Negative, &error);
+    if (error) {
+      P.diagnose(P.Tok, diag::sil_integer_literal_not_well_formed, intTy);
+      return true;
+    }
 
     P.consumeToken(tok::integer_literal);
     if (parseSILDebugLocation(InstLoc, B))
@@ -2381,9 +2395,11 @@
       P.diagnose(P.Tok, diag::sil_float_literal_not_float_type);
       return true;
     }
+
+    StringRef text = prepareIntegerLiteralForParsing(P.Tok.getText());
     
     APInt bits(floatTy->getBitWidth(), 0);
-    bool error = P.Tok.getText().getAsInteger(0, bits);
+    bool error = text.getAsInteger(0, bits);
     assert(!error && "float_literal token did not parse as APInt?!");
     (void)error;
     
@@ -2508,7 +2524,7 @@
     }
     
     unsigned Index;
-    bool error = P.Tok.getText().getAsInteger(0, Index);
+    bool error = parseIntegerLiteral(P.Tok.getText(), 0, Index);
     assert(!error && "project_box index did not parse as integer?!");
     (void)error;
 
@@ -3912,7 +3928,7 @@
     unsigned Field = 0;
     TupleType *TT = Val->getType().getAs<TupleType>();
     if (P.Tok.isNot(tok::integer_literal) ||
-        P.Tok.getText().getAsInteger(10, Field) ||
+        parseIntegerLiteral(P.Tok.getText(), 10, Field) ||
         Field >= TT->getNumElements()) {
       P.diagnose(P.Tok, diag::sil_tuple_inst_wrong_field);
       return true;
diff --git a/lib/SIL/SILFunctionBuilder.cpp b/lib/SIL/SILFunctionBuilder.cpp
index a30dc9b..71213aa 100644
--- a/lib/SIL/SILFunctionBuilder.cpp
+++ b/lib/SIL/SILFunctionBuilder.cpp
@@ -57,9 +57,6 @@
   // @_silgen_name and @_cdecl functions may be called from C code somewhere.
   if (Attrs.hasAttribute<SILGenNameAttr>() || Attrs.hasAttribute<CDeclAttr>())
     F->setHasCReferences(true);
-
-  if (Attrs.hasAttribute<WeakLinkedAttr>())
-    F->setWeakLinked();
 }
 
 SILFunction *
@@ -115,6 +112,9 @@
     if (constant.isForeign && decl->hasClangNode())
       F->setClangNodeOwner(decl);
 
+    if (decl->isWeakImported(/*fromModule=*/nullptr))
+      F->setWeakLinked();
+
     if (auto *accessor = dyn_cast<AccessorDecl>(decl)) {
       auto *storage = accessor->getStorage();
       // Add attributes for e.g. computed properties.
diff --git a/lib/SIL/SILInstructions.cpp b/lib/SIL/SILInstructions.cpp
index db564d4..21a1fe6 100644
--- a/lib/SIL/SILInstructions.cpp
+++ b/lib/SIL/SILInstructions.cpp
@@ -646,32 +646,54 @@
 IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc,
                                                SILType Ty, const APInt &Value,
                                                SILModule &M) {
-  auto intTy = Ty.castTo<BuiltinIntegerType>();
-  assert(intTy->getGreatestWidth() == Value.getBitWidth() &&
-         "IntegerLiteralInst APInt value's bit width doesn't match type");
-  (void)intTy;
+#ifndef NDEBUG
+  if (auto intTy = Ty.getAs<BuiltinIntegerType>()) {
+    assert(intTy->getGreatestWidth() == Value.getBitWidth() &&
+           "IntegerLiteralInst APInt value's bit width doesn't match type");
+  } else {
+    assert(Ty.is<BuiltinIntegerLiteralType>());
+    assert(Value.getBitWidth() == Value.getMinSignedBits());
+  }
+#endif
 
   void *buf = allocateLiteralInstWithBitSize<IntegerLiteralInst>(M,
                                                           Value.getBitWidth());
   return ::new (buf) IntegerLiteralInst(Loc, Ty, Value);
 }
 
+static APInt getAPInt(AnyBuiltinIntegerType *anyIntTy, intmax_t value) {
+  // If we're forming a fixed-width type, build using the greatest width.
+  if (auto intTy = dyn_cast<BuiltinIntegerType>(anyIntTy))
+    return APInt(intTy->getGreatestWidth(), value);
+
+  // Otherwise, build using the size of the type and then truncate to the
+  // minimum width necessary.
+  APInt result(8 * sizeof(value), value, /*signed*/ true);
+  result = result.trunc(result.getMinSignedBits());
+  return result;
+}
+
 IntegerLiteralInst *IntegerLiteralInst::create(SILDebugLocation Loc,
                                                SILType Ty, intmax_t Value,
                                                SILModule &M) {
-  auto intTy = Ty.castTo<BuiltinIntegerType>();
-  return create(Loc, Ty,
-                APInt(intTy->getGreatestWidth(), Value), M);
+  auto intTy = Ty.castTo<AnyBuiltinIntegerType>();
+  return create(Loc, Ty, getAPInt(intTy, Value), M);
+}
+
+static SILType getGreatestIntegerType(Type type, SILModule &M) {
+  if (auto intTy = type->getAs<BuiltinIntegerType>()) {
+    return SILType::getBuiltinIntegerType(intTy->getGreatestWidth(),
+                                          M.getASTContext());
+  } else {
+    assert(type->is<BuiltinIntegerLiteralType>());
+    return SILType::getBuiltinIntegerLiteralType(M.getASTContext());
+  }
 }
 
 IntegerLiteralInst *IntegerLiteralInst::create(IntegerLiteralExpr *E,
                                                SILDebugLocation Loc,
                                                SILModule &M) {
-  return create(
-      Loc, SILType::getBuiltinIntegerType(
-               E->getType()->castTo<BuiltinIntegerType>()->getGreatestWidth(),
-               M.getASTContext()),
-      E->getValue(), M);
+  return create(Loc, getGreatestIntegerType(E->getType(), M), E->getValue(), M);
 }
 
 /// getValue - Return the APInt for the underlying integer literal.
diff --git a/lib/SIL/SILType.cpp b/lib/SIL/SILType.cpp
index 59574bc..830acd6 100644
--- a/lib/SIL/SILType.cpp
+++ b/lib/SIL/SILType.cpp
@@ -42,6 +42,10 @@
   return getPrimitiveObjectType(C.TheRawPointerType);
 }
 
+SILType SILType::getBuiltinIntegerLiteralType(const ASTContext &C) {
+  return getPrimitiveObjectType(C.TheIntegerLiteralType);
+}
+
 SILType SILType::getBuiltinIntegerType(unsigned bitWidth,
                                        const ASTContext &C) {
   return getPrimitiveObjectType(CanType(BuiltinIntegerType::get(bitWidth, C)));
diff --git a/lib/SIL/SILVerifier.cpp b/lib/SIL/SILVerifier.cpp
index 652d4de..3253b68 100644
--- a/lib/SIL/SILVerifier.cpp
+++ b/lib/SIL/SILVerifier.cpp
@@ -1468,7 +1468,7 @@
   }
 
   void checkIntegerLiteralInst(IntegerLiteralInst *ILI) {
-    require(ILI->getType().is<BuiltinIntegerType>(),
+    require(ILI->getType().is<AnyBuiltinIntegerType>(),
             "invalid integer literal type");
   }
 
diff --git a/lib/SIL/TypeLowering.cpp b/lib/SIL/TypeLowering.cpp
index 44e6058..4af17f2 100644
--- a/lib/SIL/TypeLowering.cpp
+++ b/lib/SIL/TypeLowering.cpp
@@ -187,6 +187,7 @@
     }
 
     IMPL(BuiltinInteger, Trivial)
+    IMPL(BuiltinIntegerLiteral, Trivial)
     IMPL(BuiltinFloat, Trivial)
     IMPL(BuiltinRawPointer, Trivial)
     IMPL(BuiltinNativeObject, Reference)
diff --git a/lib/SILGen/SILGenLValue.cpp b/lib/SILGen/SILGenLValue.cpp
index 3d926a7..a231080 100644
--- a/lib/SILGen/SILGenLValue.cpp
+++ b/lib/SILGen/SILGenLValue.cpp
@@ -1070,8 +1070,13 @@
   }
 
   // Compare a variety of literals.
-  if (auto *il1 = dyn_cast<IntegerLiteralExpr>(e1))
-    return il1->getValue() == cast<IntegerLiteralExpr>(e2)->getValue();
+  if (auto *il1 = dyn_cast<IntegerLiteralExpr>(e1)) {
+    const auto &val1 = il1->getValue();
+    const auto &val2 = cast<IntegerLiteralExpr>(e2)->getValue();
+    // If the integers are arbitrary-precision, their bit-widths may differ,
+    // but only if they represent different values.
+    return val1.getBitWidth() == val2.getBitWidth() && val1 == val2;
+  }
   if (auto *il1 = dyn_cast<FloatLiteralExpr>(e1))
     return il1->getValue().bitwiseIsEqual(
                                         cast<FloatLiteralExpr>(e2)->getValue());
diff --git a/lib/SILGen/SILGenPattern.cpp b/lib/SILGen/SILGenPattern.cpp
index fb339a3..bf0bade 100644
--- a/lib/SILGen/SILGenPattern.cpp
+++ b/lib/SILGen/SILGenPattern.cpp
@@ -2267,6 +2267,9 @@
     SILBasicBlock *caseBB = caseBBs[i].second;
     SGF.B.setInsertionPoint(caseBB);
 
+    // We're in conditionally-executed code; enter a scope.
+    Scope scope(SGF.Cleanups, CleanupLocation::get(loc));
+
     SILValue result
       = SILUndef::get(SGF.SGM.Types.getEmptyTupleType(), SGF.SGM.M);
     ConsumableManagedValue CMV =
diff --git a/lib/SILOptimizer/LoopTransforms/LICM.cpp b/lib/SILOptimizer/LoopTransforms/LICM.cpp
index f7a8161..b5e03c8 100644
--- a/lib/SILOptimizer/LoopTransforms/LICM.cpp
+++ b/lib/SILOptimizer/LoopTransforms/LICM.cpp
@@ -654,7 +654,9 @@
       case SILInstructionKind::BeginAccessInst: {
         auto *BI = dyn_cast<BeginAccessInst>(&Inst);
         assert(BI && "Expected a Begin Access");
-        BeginAccesses.push_back(BI);
+        if (BI->getEnforcement() == SILAccessEnforcement::Dynamic) {
+          BeginAccesses.push_back(BI);
+        }
         checkSideEffects(Inst, MayWrites);
         break;
       }
diff --git a/lib/SILOptimizer/PassManager/PassPipeline.cpp b/lib/SILOptimizer/PassManager/PassPipeline.cpp
index e46f54d..384bd4c 100644
--- a/lib/SILOptimizer/PassManager/PassPipeline.cpp
+++ b/lib/SILOptimizer/PassManager/PassPipeline.cpp
@@ -195,6 +195,7 @@
   P.addSimplifyCFG();
   // Optimize access markers for better LICM: might merge accesses
   // It will also set the no_nested_conflict for dynamic accesses
+  P.addAccessEnforcementReleaseSinking();
   P.addAccessEnforcementOpts();
   P.addHighLevelLICM();
   // Simplify CFG after LICM that creates new exit blocks
@@ -202,6 +203,7 @@
   // LICM might have added new merging potential by hoisting
   // we don't want to restart the pipeline - ignore the
   // potential of merging out of two loops
+  P.addAccessEnforcementReleaseSinking();
   P.addAccessEnforcementOpts();
   // Start of loop unrolling passes.
   P.addArrayCountPropagation();
@@ -465,6 +467,7 @@
   P.addCodeSinking();
   // Optimize access markers for better LICM: might merge accesses
   // It will also set the no_nested_conflict for dynamic accesses
+  P.addAccessEnforcementReleaseSinking();
   P.addAccessEnforcementOpts();
   P.addLICM();
   // Simplify CFG after LICM that creates new exit blocks
@@ -472,6 +475,7 @@
   // LICM might have added new merging potential by hoisting
   // we don't want to restart the pipeline - ignore the
   // potential of merging out of two loops
+  P.addAccessEnforcementReleaseSinking();
   P.addAccessEnforcementOpts();
 
   // Optimize overflow checks.
@@ -494,6 +498,7 @@
 // - don't require IRGen information.
 static void addLastChanceOptPassPipeline(SILPassPipelinePlan &P) {
   // Optimize access markers for improved IRGen after all other optimizations.
+  P.addAccessEnforcementReleaseSinking();
   P.addAccessEnforcementOpts();
   P.addAccessEnforcementWMO();
   P.addAccessEnforcementDom();
diff --git a/lib/SILOptimizer/Transforms/AccessEnforcementReleaseSinking.cpp b/lib/SILOptimizer/Transforms/AccessEnforcementReleaseSinking.cpp
new file mode 100644
index 0000000..e0d3405
--- /dev/null
+++ b/lib/SILOptimizer/Transforms/AccessEnforcementReleaseSinking.cpp
@@ -0,0 +1,124 @@
+//===--- AccessEnforcementReleaseSinking.cpp - release sinking opt ---===//
+//
+// This source file is part of the Swift.org open source project
+//
+// Copyright (c) 2014 - 2018 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// This function pass sinks releases out of access scopes.
+///
+/// General case:
+/// begin_access A
+/// ...
+/// strong_release / release_value / destroy
+/// end_access
+///
+/// The release instruction can be sunk below the end_access instruction,
+/// This extends the lifetime of the released value, but, might allow us to
+/// Mark the access scope as no nested conflict.
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "access-enforcement-release"
+
+#include "swift/SIL/ApplySite.h"
+#include "swift/SIL/DebugUtils.h"
+#include "swift/SIL/SILFunction.h"
+#include "swift/SILOptimizer/PassManager/Transforms.h"
+
+using namespace swift;
+
+// Returns a bool: If this is a "sinkable" instruction type for this opt
+static bool isSinkable(SILInstruction &inst) {
+  switch (inst.getKind()) {
+  default:
+    return false;
+  case SILInstructionKind::DestroyValueInst:
+  case SILInstructionKind::ReleaseValueInst:
+  case SILInstructionKind::ReleaseValueAddrInst:
+  case SILInstructionKind::StrongReleaseInst:
+  case SILInstructionKind::UnmanagedReleaseValueInst:
+    return true;
+  }
+}
+
+// Returns a bool: If this is a "barrier" instruction for this opt
+static bool isBarrier(SILInstruction &inst) {
+  switch (inst.getKind()) {
+  default:
+    return FullApplySite::isa(&inst) != FullApplySite();
+  case SILInstructionKind::BeginAccessInst:
+  case SILInstructionKind::BeginUnpairedAccessInst:
+  case SILInstructionKind::IsUniqueInst:
+    return true;
+  }
+}
+
+// Processes a block bottom-up, keeping a lookout for end_access instructions
+// If we encounter a "barrier" we clear out the current end_access
+// If we encounter a "release", and we have a current end_access, we sink it
+static void processBlock(SILBasicBlock &block) {
+  EndAccessInst *bottomEndAccessInst = nullptr;
+  for (auto reverseIt = block.rbegin(); reverseIt != block.rend();
+       ++reverseIt) {
+    SILInstruction &currIns = *reverseIt;
+    if (auto *currEAI = dyn_cast<EndAccessInst>(&currIns)) {
+      if (!bottomEndAccessInst) {
+        bottomEndAccessInst = currEAI;
+      }
+    } else if (isBarrier(currIns)) {
+      LLVM_DEBUG(llvm::dbgs() << "Found a barrier " << currIns
+                              << ", clearing last seen end_access\n");
+      bottomEndAccessInst = nullptr;
+    } else if (isSinkable(currIns)) {
+      LLVM_DEBUG(llvm::dbgs()
+                 << "Found a sinkable instruction " << currIns << "\n");
+      if (!bottomEndAccessInst) {
+        LLVM_DEBUG(
+            llvm::dbgs()
+            << "Cannot be sunk: no open barrier-less end_access found\n");
+        continue;
+      }
+      LLVM_DEBUG(llvm::dbgs() << "Moving sinkable instruction below "
+                              << *bottomEndAccessInst << "\n");
+      // We need to avoid iterator invalidation:
+      // We know this is not the last instruction of the block:
+      // 1) not a TermInst
+      // 2) bottomEndAccessInst != nil
+      assert(reverseIt != block.rbegin() &&
+             "Did not expect a sinkable instruction at block's end");
+      // Go back to previous iteration
+      auto prevIt = reverseIt;
+      --prevIt;
+      // Move the instruction after the end_access
+      currIns.moveAfter(bottomEndAccessInst);
+      // make reverseIt into a valid iterator again
+      reverseIt = prevIt;
+    }
+  }
+}
+
+namespace {
+struct AccessEnforcementReleaseSinking : public SILFunctionTransform {
+  void run() override {
+    SILFunction *F = getFunction();
+    if (F->empty())
+      return;
+
+    LLVM_DEBUG(llvm::dbgs() << "Running AccessEnforcementReleaseSinking on "
+                            << F->getName() << "\n");
+
+    for (SILBasicBlock &currBB : *F) {
+      processBlock(currBB);
+    }
+  }
+};
+} // namespace
+
+SILTransform *swift::createAccessEnforcementReleaseSinking() {
+  return new AccessEnforcementReleaseSinking();
+}
diff --git a/lib/SILOptimizer/Transforms/CMakeLists.txt b/lib/SILOptimizer/Transforms/CMakeLists.txt
index e3bf694..4ded5f5 100644
--- a/lib/SILOptimizer/Transforms/CMakeLists.txt
+++ b/lib/SILOptimizer/Transforms/CMakeLists.txt
@@ -2,6 +2,7 @@
   ARCCodeMotion.cpp
   AccessEnforcementDom.cpp
   AccessEnforcementOpts.cpp
+  AccessEnforcementReleaseSinking.cpp 
   AccessEnforcementWMO.cpp
   AllocBoxToStack.cpp
   ArrayCountPropagation.cpp
diff --git a/lib/SILOptimizer/Utils/ConstantFolding.cpp b/lib/SILOptimizer/Utils/ConstantFolding.cpp
index e59532f..259c08e 100644
--- a/lib/SILOptimizer/Utils/ConstantFolding.cpp
+++ b/lib/SILOptimizer/Utils/ConstantFolding.cpp
@@ -667,20 +667,6 @@
   }
 }
 
-static std::pair<bool, bool> getTypeSignedness(const BuiltinInfo &Builtin) {
-  bool SrcTySigned =
-  (Builtin.ID == BuiltinValueKind::SToSCheckedTrunc ||
-   Builtin.ID == BuiltinValueKind::SToUCheckedTrunc ||
-   Builtin.ID == BuiltinValueKind::SUCheckedConversion);
-
-  bool DstTySigned =
-  (Builtin.ID == BuiltinValueKind::SToSCheckedTrunc ||
-   Builtin.ID == BuiltinValueKind::UToSCheckedTrunc ||
-   Builtin.ID == BuiltinValueKind::USCheckedConversion);
-
-  return std::pair<bool, bool>(SrcTySigned, DstTySigned);
-}
-
 static SILValue
 constantFoldAndCheckIntegerConversions(BuiltinInst *BI,
                                        const BuiltinInfo &Builtin,
@@ -697,12 +683,21 @@
   auto *V = dyn_cast<IntegerLiteralInst>(Args[0]);
   if (!V)
     return nullptr;
+
   APInt SrcVal = V->getValue();
+  auto SrcBitWidth = SrcVal.getBitWidth();
+
+  bool DstTySigned = (Builtin.ID == BuiltinValueKind::SToSCheckedTrunc ||
+                      Builtin.ID == BuiltinValueKind::UToSCheckedTrunc ||
+                      Builtin.ID == BuiltinValueKind::USCheckedConversion);
+  bool SrcTySigned = (Builtin.ID == BuiltinValueKind::SToSCheckedTrunc ||
+                      Builtin.ID == BuiltinValueKind::SToUCheckedTrunc ||
+                      Builtin.ID == BuiltinValueKind::SUCheckedConversion);
 
   // Get source type and bit width.
-  Type SrcTy = Builtin.Types[0];
-  uint32_t SrcBitWidth =
-    Builtin.Types[0]->castTo<BuiltinIntegerType>()->getGreatestWidth();
+  auto SrcTy = Builtin.Types[0]->castTo<AnyBuiltinIntegerType>();
+  assert((SrcTySigned || !isa<BuiltinIntegerLiteralType>(SrcTy)) &&
+         "only the signed intrinsics can be used with integer literals");
 
   // Compute the destination (for SrcBitWidth < DestBitWidth) and enough info
   // to check for overflow.
@@ -718,36 +713,36 @@
     // Report an error if the sign bit is set.
     OverflowError = SrcVal.isNegative();
 
-  // Process truncation from unsigned to signed.
-  } else if (Builtin.ID != BuiltinValueKind::UToSCheckedTrunc) {
-    assert(Builtin.Types.size() == 2);
-    DstTy = Builtin.Types[1];
-    uint32_t DstBitWidth =
-      DstTy->castTo<BuiltinIntegerType>()->getGreatestWidth();
-    //     Result = trunc_IntFrom_IntTo(Val)
-    //   For signed destination:
-    //     sext_IntFrom(Result) == Val ? Result : overflow_error
-    //   For signed destination:
-    //     zext_IntFrom(Result) == Val ? Result : overflow_error
-    Result = SrcVal.trunc(DstBitWidth);
-    // Get the signedness of the destination.
-    bool Signed = (Builtin.ID == BuiltinValueKind::SToSCheckedTrunc);
-    APInt Ext = Signed ? Result.sext(SrcBitWidth) : Result.zext(SrcBitWidth);
-    OverflowError = (SrcVal != Ext);
-
-  // Process the rest of truncations.
+  // Process the checked truncations.
   } else {
     assert(Builtin.Types.size() == 2);
     DstTy = Builtin.Types[1];
     uint32_t DstBitWidth =
-      Builtin.Types[1]->castTo<BuiltinIntegerType>()->getGreatestWidth();
-    // Compute the destination (for SrcBitWidth < DestBitWidth):
-    //   Result = trunc_IntTo(Val)
-    //   Trunc  = trunc_'IntTo-1bit'(Val)
-    //   zext_IntFrom(Trunc) == Val ? Result : overflow_error
-    Result = SrcVal.trunc(DstBitWidth);
-    APInt TruncVal = SrcVal.trunc(DstBitWidth - 1);
-    OverflowError = (SrcVal != TruncVal.zext(SrcBitWidth));
+      DstTy->castTo<BuiltinIntegerType>()->getGreatestWidth();
+
+    assert((DstBitWidth < SrcBitWidth || !SrcTy->getWidth().isFixedWidth()) &&
+           "preconditions on builtin trunc operations should prevent"
+           "fixed-width truncations that actually extend");
+
+    // The only way a true extension can overflow is if the value is
+    // negative and the result is unsigned.
+    if (DstBitWidth > SrcBitWidth) {
+      OverflowError = (SrcTySigned && !DstTySigned && SrcVal.isNegative());
+      Result = (SrcTySigned ? SrcVal.sext(DstBitWidth)
+                            : SrcVal.zext(DstBitWidth));
+
+    // A same-width change can overflow if the top bit disagrees.
+    } else if (DstBitWidth == SrcBitWidth) {
+      OverflowError = (SrcTySigned != DstTySigned && SrcVal.isNegative());
+      Result = SrcVal;
+
+    // A truncation can overflow if the value changes.
+    } else {
+      Result = SrcVal.trunc(DstBitWidth);
+      APInt Ext = (DstTySigned ? Result.sext(SrcBitWidth)
+                               : Result.zext(SrcBitWidth));
+      OverflowError = (SrcVal != Ext);
+    }
   }
 
   // Check for overflow.
@@ -777,10 +772,10 @@
       }
     }
 
-
-    // Assume that we are converting from a literal if the Source size is
-    // 2048. Is there a better way to identify conversions from literals?
-    bool Literal = (SrcBitWidth == 2048);
+    // Assume that we're converting from a literal if the source type is
+    // IntegerLiteral.  Is there a better way to identify this if we start
+    // using Builtin.IntegerLiteral in an exposed type?
+    bool Literal = isa<BuiltinIntegerLiteralType>(SrcTy);
 
     // FIXME: This will prevent hard error in cases the error is coming
     // from ObjC interoperability code. Currently, we treat NSUInteger as
@@ -803,8 +798,6 @@
 
     // Otherwise report the overflow error.
     if (Literal) {
-      bool SrcTySigned, DstTySigned;
-      std::tie(SrcTySigned, DstTySigned) = getTypeSignedness(Builtin);
       SmallString<10> SrcAsString;
       SrcVal.toString(SrcAsString, /*radix*/10, SrcTySigned);
 
@@ -814,15 +807,13 @@
 
         // If this is a negative literal in an unsigned type, use a specific
         // diagnostic.
-        if (SrcTySigned && !DstTySigned && SrcVal.isNegative())
+        if (!DstTySigned && SrcVal.isNegative())
           diagID = diag::negative_integer_literal_overflow_unsigned;
 
         diagnose(M.getASTContext(), Loc.getSourceLoc(),
                  diagID, UserDstTy, SrcAsString);
       // Otherwise, print the Builtin Types.
       } else {
-        bool SrcTySigned, DstTySigned;
-        std::tie(SrcTySigned, DstTySigned) = getTypeSignedness(Builtin);
         diagnose(M.getASTContext(), Loc.getSourceLoc(),
                  diag::integer_literal_overflow_builtin_types,
                  DstTySigned, DstTy, SrcAsString);
@@ -843,8 +834,6 @@
         } else {
           // Since builtin types are sign-agnostic, print the signedness
           // separately.
-          bool SrcTySigned, DstTySigned;
-          std::tie(SrcTySigned, DstTySigned) = getTypeSignedness(Builtin);
           diagnose(M.getASTContext(), Loc.getSourceLoc(),
                    diag::integer_conversion_overflow_builtin_types,
                    SrcTySigned, SrcTy, DstTySigned, DstTy);
diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp
index 7fc4a57..e04713d 100644
--- a/lib/Sema/CSApply.cpp
+++ b/lib/Sema/CSApply.cpp
@@ -1828,7 +1828,7 @@
     Expr *handleIntegerLiteralExpr(LiteralExpr *expr) {
       // If the literal has been assigned a builtin integer type,
       // don't mess with it.
-      if (cs.getType(expr)->is<BuiltinIntegerType>())
+      if (cs.getType(expr)->is<AnyBuiltinIntegerType>())
         return expr;
 
       auto &tc = cs.getTypeChecker();
@@ -1868,9 +1868,7 @@
                tc.Context.Id_IntegerLiteralType,
                initName,
                builtinProtocol,
-               // Note that 'MaxIntegerType' is guaranteed to be available.
-               // Otherwise it would be caught by CSGen::visitLiteralExpr
-               tc.getMaxIntegerType(dc),
+               tc.Context.TheIntegerLiteralType,
                builtinInitName,
                nullptr,
                diag::integer_literal_broken_proto,
diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp
index d6ea4e7..be248a9 100644
--- a/lib/Sema/CSDiagnostics.cpp
+++ b/lib/Sema/CSDiagnostics.cpp
@@ -113,6 +113,8 @@
     }
 
     locator = cs.getConstraintLocator(member);
+  } else if (auto *UME = dyn_cast<UnresolvedMemberExpr>(anchor)) {
+    locator = cs.getConstraintLocator(locator, PathEltKind::UnresolvedMember);
   } else if (isa<SubscriptExpr>(anchor)) {
     ConstraintLocatorBuilder subscript(locator);
     locator = cs.getConstraintLocator(
diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp
index 3b099b6..9d1b7d9 100644
--- a/lib/Sema/CSGen.cpp
+++ b/lib/Sema/CSGen.cpp
@@ -1203,44 +1203,6 @@
       if (!protocol)
         return nullptr;
 
-      // Make sure that MaxIntegerType is defined if it would used later
-      // during constraint solving (CSApply).
-      if (isa<IntegerLiteralExpr>(expr) ||
-          (isa<MagicIdentifierLiteralExpr>(expr) &&
-           dyn_cast<MagicIdentifierLiteralExpr>(expr)->isColumn())) {
-
-        auto maxIntType = CS.TC.getMaxIntegerType(CS.DC);
-        if (maxIntType.isNull()) {
-          CS.TC.diagnose(expr->getLoc(), diag::no_MaxBuiltinIntegerType_found);
-          return nullptr;
-        }
-
-        // In the case of integer literal, make sure that the literal value
-        // will fit within the bit width of the maximum integer type.
-        if (IntegerLiteralExpr *intLit = dyn_cast<IntegerLiteralExpr>(expr)) {
-          unsigned maxWidth =
-              maxIntType->castTo<BuiltinIntegerType>()->getGreatestWidth();
-          APInt magnitude = intLit->getRawMagnitude();
-          unsigned magWidth = magnitude.getActiveBits();
-          bool isNegative = intLit->isNegative();
-
-          // Compute the literal bit width in the signed two's complement form.
-          // This is generally one more than the magnitude width, but is the
-          // same when the literal is of the form -2^i (for some Nat `i`).
-          unsigned signedLitWidth =
-              (isNegative && (magnitude.countTrailingZeros() == magWidth - 1))
-                  ? magWidth
-                  : (magWidth + 1);
-
-          if (signedLitWidth > maxWidth) { // overflow?
-            CS.TC.diagnose(expr->getLoc(),
-                           diag::integer_literal_overflows_maxwidth, maxWidth,
-                           signedLitWidth);
-            return nullptr;
-          }
-        }
-      }
-
       auto tv = CS.createTypeVariable(CS.getConstraintLocator(expr),
                                       TVO_PrefersSubtypeBinding);
       CS.addConstraint(ConstraintKind::LiteralConformsTo, tv,
diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp
index dd1dad1..ab2946a 100644
--- a/lib/Sema/TypeCheckDecl.cpp
+++ b/lib/Sema/TypeCheckDecl.cpp
@@ -1265,12 +1265,11 @@
                                                  /*Implicit=*/true);
     }
     // If the prevValue is not a well-typed integer, then break.
-    // This could happen if the literal value overflows _MaxBuiltinIntegerType.
     if (!prevValue->getType())
       return nullptr;
 
     if (auto intLit = dyn_cast<IntegerLiteralExpr>(prevValue)) {
-      APInt nextVal = intLit->getValue() + 1;
+      APInt nextVal = intLit->getValue().sextOrSelf(128) + 1;
       bool negative = nextVal.slt(0);
       if (negative)
         nextVal = -nextVal;
diff --git a/lib/Sema/TypeCheckSwitchStmt.cpp b/lib/Sema/TypeCheckSwitchStmt.cpp
index ac11876..4d1b9b7 100644
--- a/lib/Sema/TypeCheckSwitchStmt.cpp
+++ b/lib/Sema/TypeCheckSwitchStmt.cpp
@@ -20,7 +20,7 @@
 #include "swift/AST/Pattern.h"
 #include "swift/Basic/STLExtras.h"
 
-#include <llvm/ADT/APInt.h>
+#include "swift/Basic/APIntMap.h"
 #include <llvm/ADT/APFloat.h>
 
 #include <numeric>
@@ -31,22 +31,6 @@
 #define DEBUG_TYPE "TypeCheckSwitchStmt"
 
 namespace {
-  struct DenseMapAPIntKeyInfo {
-    static inline APInt getEmptyKey() { return APInt(); }
-
-    static inline APInt getTombstoneKey() {
-      return APInt::getAllOnesValue(/*bitwidth*/1);
-    }
-
-    static unsigned getHashValue(const APInt &Key) {
-      return static_cast<unsigned>(hash_value(Key));
-    }
-
-    static bool isEqual(const APInt &LHS, const APInt &RHS) {
-      return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
-    }
-  };
-
   struct DenseMapAPFloatKeyInfo {
     static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); }
     static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus(), 2); }
@@ -858,7 +842,7 @@
     TypeChecker &TC;
     const SwitchStmt *Switch;
     const DeclContext *DC;
-    llvm::DenseMap<APInt, Expr *, ::DenseMapAPIntKeyInfo> IntLiteralCache;
+    APIntMap<Expr *> IntLiteralCache;
     llvm::DenseMap<APFloat, Expr *, ::DenseMapAPFloatKeyInfo> FloatLiteralCache;
     llvm::DenseMap<StringRef, Expr *> StringLiteralCache;
     
@@ -886,12 +870,8 @@
         return !cacheVal.second;
       }
       case ExprKind::IntegerLiteral: {
-        // FIXME: The magic number 128 is bad and we should actually figure out
-        // the bitwidth.  But it's too early in Sema to get it.
         auto *ILE = cast<IntegerLiteralExpr>(EL);
-        auto cacheVal =
-            IntLiteralCache.insert(
-                {ILE->getValue(ILE->getDigitsText(), 128, ILE->isNegative()), ILE});
+        auto cacheVal = IntLiteralCache.insert({ILE->getRawValue(), ILE});
         PrevPattern = (cacheVal.first != IntLiteralCache.end())
                     ? cacheVal.first->getSecond()
                     : nullptr;
diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp
index cf6accc..285b410 100644
--- a/lib/Sema/TypeCheckType.cpp
+++ b/lib/Sema/TypeCheckType.cpp
@@ -432,31 +432,6 @@
   return ::getStdlibType(*this, UInt8Type, dc, "UInt8");
 }
 
-/// Returns the maximum-sized builtin integer type.
-Type TypeChecker::getMaxIntegerType(DeclContext *dc) {
-  if (!MaxIntegerType.isNull())
-    return MaxIntegerType;
-
-  SmallVector<ValueDecl *, 1> lookupResults;
-  getStdlibModule(dc)->lookupValue(/*AccessPath=*/{},
-                                   Context.Id_MaxBuiltinIntegerType,
-                                   NLKind::QualifiedLookup, lookupResults);
-  if (lookupResults.size() != 1)
-    return MaxIntegerType;
-
-  auto *maxIntegerTypeDecl = dyn_cast<TypeAliasDecl>(lookupResults.front());
-  if (!maxIntegerTypeDecl)
-    return MaxIntegerType;
-
-  validateDecl(maxIntegerTypeDecl);
-  if (!maxIntegerTypeDecl->hasInterfaceType() ||
-      !maxIntegerTypeDecl->getDeclaredInterfaceType()->is<BuiltinIntegerType>())
-    return MaxIntegerType;
-
-  MaxIntegerType = maxIntegerTypeDecl->getUnderlyingTypeLoc().getType();
-  return MaxIntegerType;
-}
-
 /// Find the standard type of exceptions.
 ///
 /// We call this the "exception type" to try to avoid confusion with
diff --git a/lib/Sema/TypeChecker.h b/lib/Sema/TypeChecker.h
index 40e68a2..7a2ea6f 100644
--- a/lib/Sema/TypeChecker.h
+++ b/lib/Sema/TypeChecker.h
@@ -832,7 +832,6 @@
   Type getIntType(DeclContext *dc);
   Type getInt8Type(DeclContext *dc);
   Type getUInt8Type(DeclContext *dc);
-  Type getMaxIntegerType(DeclContext *dc);
   Type getNSObjectType(DeclContext *dc);
   Type getObjCSelectorType(DeclContext *dc);
   Type getExceptionType(DeclContext *dc, SourceLoc loc);
diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp
index 39a9bab..b201980 100644
--- a/lib/Serialization/Deserialization.cpp
+++ b/lib/Serialization/Deserialization.cpp
@@ -1622,8 +1622,8 @@
                                            getXRefDeclNameForError());
       }
 
-      uint32_t paramIndex;
-      XRefGenericParamPathPieceLayout::readRecord(scratch, paramIndex);
+      uint32_t depth, paramIndex;
+      XRefGenericParamPathPieceLayout::readRecord(scratch, depth, paramIndex);
 
       pathTrace.addGenericParam(paramIndex);
 
@@ -1645,7 +1645,7 @@
           assert(paramList && "Couldn't find constrained extension");
         } else {
           // Simple case: use the nominal type's generic parameters.
-          paramList = nominal->getGenericParams();
+          paramList = nominal->getGenericParamsOfContext();
         }
       } else if (auto alias = dyn_cast<TypeAliasDecl>(base)) {
         paramList = alias->getGenericParams();
@@ -1660,6 +1660,18 @@
             "cross-reference to generic param for non-generic type",
             pathTrace, getXRefDeclNameForError());
       }
+
+      unsigned currentDepth = paramList->getDepth();
+      if (currentDepth < depth) {
+        return llvm::make_error<XRefError>(
+            "a containing type has been made non-generic",
+            pathTrace, getXRefDeclNameForError());
+      }
+      while (currentDepth > depth) {
+        paramList = paramList->getOuterParameters();
+        --currentDepth;
+      }
+
       if (paramIndex >= paramList->size()) {
         return llvm::make_error<XRefError>(
             "generic argument index out of bounds",
diff --git a/lib/Serialization/DeserializeSIL.cpp b/lib/Serialization/DeserializeSIL.cpp
index a259b4c..45fcbf8 100644
--- a/lib/Serialization/DeserializeSIL.cpp
+++ b/lib/Serialization/DeserializeSIL.cpp
@@ -1535,10 +1535,11 @@
   }
   case SILInstructionKind::IntegerLiteralInst: {
     auto Ty = MF->getType(TyID);
-    auto intTy = Ty->castTo<BuiltinIntegerType>();
-    StringRef StringVal = MF->getIdentifierText(ValID);
-    // Build APInt from string.
-    APInt value(intTy->getGreatestWidth(), StringVal, 10);
+    auto intTy = Ty->castTo<AnyBuiltinIntegerType>();
+    StringRef text = MF->getIdentifierText(ValID);
+    bool negate = text[0] == '-';
+    if (negate) text = text.drop_front();
+    APInt value = intTy->getWidth().parse(text, 10, negate);
     ResultVal = Builder.createIntegerLiteral(Loc,
         getSILType(Ty, (SILValueCategory)TyCategory),
         value);
diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp
index 78b2b8d..adda8dd 100644
--- a/lib/Serialization/Serialization.cpp
+++ b/lib/Serialization/Serialization.cpp
@@ -2026,6 +2026,7 @@
            "Cannot cross reference a generic type decl at module scope.");
     abbrCode = DeclTypeAbbrCodes[XRefGenericParamPathPieceLayout::Code];
     XRefGenericParamPathPieceLayout::emitRecord(Out, ScratchRecord, abbrCode,
+                                                genericParam->getDepth(),
                                                 genericParam->getIndex());
     return;
   }
@@ -3631,6 +3632,7 @@
     llvm_unreachable("should not serialize an invalid type");
 
   case TypeKind::BuiltinInteger:
+  case TypeKind::BuiltinIntegerLiteral:
   case TypeKind::BuiltinFloat:
   case TypeKind::BuiltinRawPointer:
   case TypeKind::BuiltinNativeObject:
diff --git a/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift b/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift
index 8e1d876..6751b01 100644
--- a/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift
+++ b/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift
@@ -77,9 +77,6 @@
   // Sequence
   public static var makeIterator = TypeIndexed(0)
   public static var underestimatedCount = TypeIndexed(0)
-  public static var map = TypeIndexed(0)
-  public static var filter = TypeIndexed(0)
-  public static var forEach = TypeIndexed(0)
   public static var dropFirst = TypeIndexed(0)
   public static var dropLast = TypeIndexed(0)
   public static var dropWhile = TypeIndexed(0)
@@ -101,20 +98,15 @@
   public static var successor = TypeIndexed(0)
   public static var formSuccessor = TypeIndexed(0)
   public static var indices = TypeIndexed(0)
-  public static var prefixUpTo = TypeIndexed(0)
-  public static var prefixThrough = TypeIndexed(0)
-  public static var suffixFrom = TypeIndexed(0)
   public static var isEmpty = TypeIndexed(0)
   public static var count = TypeIndexed(0)
   public static var _customIndexOfEquatableElement = TypeIndexed(0)
-  public static var first = TypeIndexed(0)
   public static var advance = TypeIndexed(0)
   public static var advanceLimit = TypeIndexed(0)
   public static var distance = TypeIndexed(0)
   // BidirectionalCollection
   public static var predecessor = TypeIndexed(0)
   public static var formPredecessor = TypeIndexed(0)
-  public static var last = TypeIndexed(0)
   // MutableCollection
   public static var subscriptIndexSet = TypeIndexed(0)
   public static var subscriptRangeSet = TypeIndexed(0)
@@ -222,25 +214,6 @@
     return base.underestimatedCount
   }
 
-  public func map<T>(
-    _ transform: (Element) throws -> T
-  ) rethrows -> [T] {
-    SequenceLog.map[selfType] += 1
-    return try base.map(transform)
-  }
-
-  public func filter(
-    _ isIncluded: (Element) throws -> Bool
-  ) rethrows -> [Element] {
-    SequenceLog.filter[selfType] += 1
-    return try base.filter(isIncluded)
-  }
-
-  public func forEach(_ body: (Element) throws -> Void) rethrows {
-    SequenceLog.forEach[selfType] += 1
-    try base.forEach(body)
-  }
-
   public func dropFirst(_ n: Int) -> SubSequence {
     SequenceLog.dropFirst[selfType] += 1
     return base.dropFirst(n)
@@ -336,17 +309,13 @@
   }
 
   public subscript(position: Index) -> Element {
-    get {
-      CollectionLog.subscriptIndex[selfType] += 1
-      return base[position]
-    }
+    CollectionLog.subscriptIndex[selfType] += 1
+    return base[position]
   }
 
   public subscript(bounds: Range<Index>) -> SubSequence {
-    get {
-      CollectionLog.subscriptRange[selfType] += 1
-      return base[bounds]
-    }
+    CollectionLog.subscriptRange[selfType] += 1
+    return base[bounds]
   }
 
   public func _failEarlyRangeCheck(_ index: Index, bounds: Range<Index>) {
@@ -374,21 +343,6 @@
     return base.indices
   }
 
-  public func prefix(upTo end: Index) -> SubSequence {
-    CollectionLog.prefixUpTo[selfType] += 1
-    return base.prefix(upTo: end)
-  }
-
-  public func prefix(through position: Index) -> SubSequence {
-    CollectionLog.prefixThrough[selfType] += 1
-    return base.prefix(through: position)
-  }
-
-  public func suffix(from start: Index) -> SubSequence {
-    CollectionLog.suffixFrom[selfType] += 1
-    return base.suffix(from: start)
-  }
-
   public var isEmpty: Bool {
     CollectionLog.isEmpty[selfType] += 1
     return base.isEmpty
@@ -406,11 +360,6 @@
     return base._customIndexOfEquatableElement(element)
   }
 
-  public var first: Element? {
-    CollectionLog.first[selfType] += 1
-    return base.first
-  }
-
   public func index(_ i: Index, offsetBy n: Int) -> Index {
     CollectionLog.advance[selfType] += 1
     return base.index(i, offsetBy: n)
@@ -443,11 +392,6 @@
     BidirectionalCollectionLog.formPredecessor[selfType] += 1
     base.formIndex(before: &i)
   }
-
-  public var last: Element? {
-    BidirectionalCollectionLog.last[selfType] += 1
-    return base.last
-  }
 }
 
 public typealias LoggingRandomAccessCollection<Base: RandomAccessCollection> 
diff --git a/stdlib/private/SwiftPrivate/CMakeLists.txt b/stdlib/private/SwiftPrivate/CMakeLists.txt
index ac7c473..2e13567 100644
--- a/stdlib/private/SwiftPrivate/CMakeLists.txt
+++ b/stdlib/private/SwiftPrivate/CMakeLists.txt
@@ -5,6 +5,14 @@
   IO.swift
   ShardedAtomicCounter.swift
 
+  SWIFT_MODULE_DEPENDS_IOS Darwin
+  SWIFT_MODULE_DEPENDS_OSX Darwin
+  SWIFT_MODULE_DEPENDS_TVOS Darwin
+  SWIFT_MODULE_DEPENDS_WATCHOS Darwin
+  SWIFT_MODULE_DEPENDS_LINUX Glibc
+  SWIFT_MODULE_DEPENDS_FREEBSD Glibc
+  SWIFT_MODULE_DEPENDS_CYGWIN Glibc
+  SWIFT_MODULE_DEPENDS_HAIKU Glibc
   SWIFT_COMPILE_FLAGS
   INSTALL_IN_COMPONENT stdlib-experimental)
 
diff --git a/stdlib/public/core/BidirectionalCollection.swift b/stdlib/public/core/BidirectionalCollection.swift
index c3c24bc..a038f64 100644
--- a/stdlib/public/core/BidirectionalCollection.swift
+++ b/stdlib/public/core/BidirectionalCollection.swift
@@ -185,20 +185,6 @@
   ///     // c == MyFancyCollection([2, 4, 6, 8, 10])
   override var indices: Indices { get }
   
-  // TODO: swift-3-indexing-model: tests.
-  /// The last element of the collection.
-  ///
-  /// If the collection is empty, the value of this property is `nil`.
-  ///
-  ///     let numbers = [10, 20, 30, 40, 50]
-  ///     if let lastNumber = numbers.last {
-  ///         print(lastNumber)
-  ///     }
-  ///     // Prints "50"
-  ///     
-  /// - Complexity: O(1)
-  var last: Element? { get }
-
   /// Accesses a contiguous subrange of the collection's elements.
   ///
   /// The accessed slice uses the same indices for the same elements as the
diff --git a/stdlib/public/core/Collection.swift b/stdlib/public/core/Collection.swift
index 41d735b..1462f75 100644
--- a/stdlib/public/core/Collection.swift
+++ b/stdlib/public/core/Collection.swift
@@ -477,108 +477,6 @@
   ///     // c == MyFancyCollection([2, 4, 6, 8, 10])
   var indices: Indices { get }
 
-  /// Returns a subsequence from the start of the collection up to, but not
-  /// including, the specified position.
-  ///
-  /// The resulting subsequence *does not include* the element at the position
-  /// `end`. The following example searches for the index of the number `40`
-  /// in an array of integers, and then prints the prefix of the array up to,
-  /// but not including, that index:
-  ///
-  ///     let numbers = [10, 20, 30, 40, 50, 60]
-  ///     if let i = numbers.firstIndex(of: 40) {
-  ///         print(numbers.prefix(upTo: i))
-  ///     }
-  ///     // Prints "[10, 20, 30]"
-  ///
-  /// Passing the collection's starting index as the `end` parameter results in
-  /// an empty subsequence.
-  ///
-  ///     print(numbers.prefix(upTo: numbers.startIndex))
-  ///     // Prints "[]"
-  ///
-  /// Using the `prefix(upTo:)` method is equivalent to using a partial
-  /// half-open range as the collection's subscript. The subscript notation is
-  /// preferred over `prefix(upTo:)`.
-  ///
-  ///     if let i = numbers.firstIndex(of: 40) {
-  ///         print(numbers[..<i])
-  ///     }
-  ///     // Prints "[10, 20, 30]"
-  ///
-  /// - Parameter end: The "past the end" index of the resulting subsequence.
-  ///   `end` must be a valid index of the collection.
-  /// - Returns: A subsequence up to, but not including, the `end` position.
-  ///
-  /// - Complexity: O(1)
-  __consuming func prefix(upTo end: Index) -> SubSequence
-
-  /// Returns a subsequence from the specified position to the end of the
-  /// collection.
-  ///
-  /// The following example searches for the index of the number `40` in an
-  /// array of integers, and then prints the suffix of the array starting at
-  /// that index:
-  ///
-  ///     let numbers = [10, 20, 30, 40, 50, 60]
-  ///     if let i = numbers.firstIndex(of: 40) {
-  ///         print(numbers.suffix(from: i))
-  ///     }
-  ///     // Prints "[40, 50, 60]"
-  ///
-  /// Passing the collection's `endIndex` as the `start` parameter results in
-  /// an empty subsequence.
-  ///
-  ///     print(numbers.suffix(from: numbers.endIndex))
-  ///     // Prints "[]"
-  ///
-  /// Using the `suffix(from:)` method is equivalent to using a partial range
-  /// from the index as the collection's subscript. The subscript notation is
-  /// preferred over `suffix(from:)`.
-  ///
-  ///     if let i = numbers.firstIndex(of: 40) {
-  ///         print(numbers[i...])
-  ///     }
-  ///     // Prints "[40, 50, 60]"
-  ///
-  /// - Parameter start: The index at which to start the resulting subsequence.
-  ///   `start` must be a valid index of the collection.
-  /// - Returns: A subsequence starting at the `start` position.
-  ///
-  /// - Complexity: O(1)
-  __consuming func suffix(from start: Index) -> SubSequence
-
-  /// Returns a subsequence from the start of the collection through the
-  /// specified position.
-  ///
-  /// The resulting subsequence *includes* the element at the position `end`. 
-  /// The following example searches for the index of the number `40` in an
-  /// array of integers, and then prints the prefix of the array up to, and
-  /// including, that index:
-  ///
-  ///     let numbers = [10, 20, 30, 40, 50, 60]
-  ///     if let i = numbers.firstIndex(of: 40) {
-  ///         print(numbers.prefix(through: i))
-  ///     }
-  ///     // Prints "[10, 20, 30, 40]"
-  ///
-  /// Using the `prefix(through:)` method is equivalent to using a partial
-  /// closed range as the collection's subscript. The subscript notation is
-  /// preferred over `prefix(through:)`.
-  ///
-  ///     if let i = numbers.firstIndex(of: 40) {
-  ///         print(numbers[...i])
-  ///     }
-  ///     // Prints "[10, 20, 30, 40]"
-  ///
-  /// - Parameter end: The index of the last element to include in the
-  ///   resulting subsequence. `end` must be a valid index of the collection
-  ///   that is not equal to the `endIndex` property.
-  /// - Returns: A subsequence up to, and including, the `end` position.
-  ///
-  /// - Complexity: O(1)
-  __consuming func prefix(through position: Index) -> SubSequence
-
   /// A Boolean value indicating whether the collection is empty.
   ///
   /// When you need to check whether your collection is empty, use the
@@ -632,22 +530,6 @@
   /// - Complexity: Hopefully less than O(`count`).
   func _customLastIndexOfEquatableElement(_ element: Element) -> Index??
 
-  // FIXME(move-only types): `first` might not be implementable by collections
-  // with move-only elements, since they would need to be able to somehow form
-  // a temporary `Optional<Element>` value from a non-optional Element without
-  // modifying the collection.
-
-  /// The first element of the collection.
-  ///
-  /// If the collection is empty, the value of this property is `nil`.
-  /// 
-  ///     let numbers = [10, 20, 30, 40, 50]
-  ///     if let firstNumber = numbers.first {
-  ///         print(firstNumber)
-  ///     }
-  ///     // Prints "10"
-  var first: Element? { get }
-
   /// Returns an index that is the specified distance from the given index.
   ///
   /// The following example obtains an index advanced four positions from a
@@ -1346,8 +1228,7 @@
   @inlinable
   public __consuming func dropFirst(_ k: Int) -> SubSequence {
     _precondition(k >= 0, "Can't drop a negative number of elements from a collection")
-    let start = index(startIndex,
-      offsetBy: k, limitedBy: endIndex) ?? endIndex
+    let start = index(startIndex, offsetBy: k, limitedBy: endIndex) ?? endIndex
     return self[start..<endIndex]
   }
 
diff --git a/stdlib/public/core/CompilerProtocols.swift b/stdlib/public/core/CompilerProtocols.swift
index 0a374ff..61969da 100644
--- a/stdlib/public/core/CompilerProtocols.swift
+++ b/stdlib/public/core/CompilerProtocols.swift
@@ -233,7 +233,7 @@
 }
 
 public protocol _ExpressibleByBuiltinIntegerLiteral {
-  init(_builtinIntegerLiteral value: _MaxBuiltinIntegerType)
+  init(_builtinIntegerLiteral value: Builtin.IntLiteral)
 }
 
 /// A type that can be initialized with an integer literal.
diff --git a/stdlib/public/core/Dictionary.swift b/stdlib/public/core/Dictionary.swift
index ffa4e92..39bc289 100644
--- a/stdlib/public/core/Dictionary.swift
+++ b/stdlib/public/core/Dictionary.swift
@@ -728,19 +728,6 @@
   public var isEmpty: Bool {
     return count == 0
   }
-
-  /// The first element of the dictionary.
-  ///
-  /// The first element of the dictionary is not necessarily the first element
-  /// added to the dictionary. Don't expect any particular ordering of
-  /// dictionary elements.
-  ///
-  /// If the dictionary is empty, the value of this property is `nil`.
-  @inlinable
-  public var first: Element? {
-    var it = makeIterator()
-    return it.next()
-  }
 }
 
 extension Dictionary {
diff --git a/stdlib/public/core/ExistentialCollection.swift.gyb b/stdlib/public/core/ExistentialCollection.swift.gyb
index 9c4ed30..0ddc3dd 100644
--- a/stdlib/public/core/ExistentialCollection.swift.gyb
+++ b/stdlib/public/core/ExistentialCollection.swift.gyb
@@ -352,9 +352,6 @@
   func _customLastIndexOfEquatableElement(element: Element) -> Index??
   */
 
-  @inlinable // FIXME(sil-serialize-all)
-  internal var _first: Element? { _abstract() }
-
   @inlinable
   internal init(
     _startIndex: _AnyIndexBox,
@@ -385,8 +382,6 @@
   internal func _index(before i: _AnyIndexBox) -> _AnyIndexBox { _abstract() }
   @inlinable
   internal func _formIndex(before i: _AnyIndexBox) { _abstract() }
-  @inlinable
-  internal var _last: Element? { _abstract() }
 %   end
 }
 
@@ -617,11 +612,6 @@
     return numericCast(_base.count)
   }
 
-  @inlinable
-  internal override var _first: Element? {
-    return _base.first
-  }
-
 %     if Kind in ['BidirectionalCollection', 'RandomAccessCollection']:
   @inlinable
   internal override func _index(before position: _AnyIndexBox) -> _AnyIndexBox {
@@ -636,10 +626,6 @@
     fatalError("Index type mismatch!")
   }
 
-  @inlinable
-  internal override var _last: Element? {
-    return _base.last
-  }
 %     end
 
 %   end
@@ -1118,11 +1104,6 @@
     return _box._count
   }
 
-  @inlinable
-  public var first: Element? {
-    return _box._first
-  }
-
 %   if Traversal == 'Bidirectional' or Traversal == 'RandomAccess':
   @inlinable
   public func index(before i: Index) -> Index {
@@ -1138,11 +1119,6 @@
       i = index(before: i)
     }
   }
-
-  @inlinable
-  public var last: Element? {
-    return _box._last
-  }
 %   end
 }
 
diff --git a/stdlib/public/core/FloatingPointTypes.swift.gyb b/stdlib/public/core/FloatingPointTypes.swift.gyb
index 283ad12..dcc62ed 100644
--- a/stdlib/public/core/FloatingPointTypes.swift.gyb
+++ b/stdlib/public/core/FloatingPointTypes.swift.gyb
@@ -1438,8 +1438,8 @@
 extension ${Self} : _ExpressibleByBuiltinIntegerLiteral, ExpressibleByIntegerLiteral {
   @_transparent
   public
-  init(_builtinIntegerLiteral value: Builtin.Int${builtinIntLiteralBits}){
-    self = ${Self}(Builtin.itofp_with_overflow_Int${builtinIntLiteralBits}_FPIEEE${bits}(value))
+  init(_builtinIntegerLiteral value: Builtin.IntLiteral){
+    self = ${Self}(Builtin.itofp_with_overflow_IntLiteral_FPIEEE${bits}(value))
   }
 
   /// Creates a new value from the given integer literal.
diff --git a/stdlib/public/core/Hasher.swift b/stdlib/public/core/Hasher.swift
index 488ce08..c185095 100644
--- a/stdlib/public/core/Hasher.swift
+++ b/stdlib/public/core/Hasher.swift
@@ -162,24 +162,24 @@
 // FIXME: Remove @usableFromInline and @_fixed_layout once Hasher is resilient.
 // rdar://problem/38549901
 @usableFromInline @_fixed_layout
-internal struct _BufferingHasher<RawCore: _HasherCore> {
+internal struct _BufferingHasher<Core: _HasherCore> {
   private var _buffer: _HasherTailBuffer
-  private var _core: RawCore
+  private var _core: Core
 
   @inline(__always)
-  internal init(core: RawCore) {
+  internal init(core: Core) {
     self._buffer = _HasherTailBuffer()
     self._core = core
   }
 
   @inline(__always)
   internal init() {
-    self.init(core: RawCore())
+    self.init(core: Core())
   }
 
   @inline(__always)
   internal init(seed: Int) {
-    self.init(core: RawCore(seed: seed))
+    self.init(core: Core(seed: seed))
   }
 
   @inline(__always)
@@ -300,13 +300,9 @@
   // FIXME: Remove @usableFromInline once Hasher is resilient.
   // rdar://problem/38549901
   @usableFromInline
-  internal typealias RawCore = _SipHash13Core
-  // FIXME: Remove @usableFromInline once Hasher is resilient.
-  // rdar://problem/38549901
-  @usableFromInline
-  internal typealias Core = _BufferingHasher<RawCore>
+  internal typealias _BufferingCore = _BufferingHasher<_Core>
 
-  internal var _core: Core
+  internal var _core: _BufferingCore
 
   /// Creates a new hasher.
   ///
@@ -314,7 +310,7 @@
   /// startup, usually from a high-quality random source.
   @_effects(releasenone)
   public init() {
-    self._core = Core()
+    self._core = _BufferingCore()
   }
 
   /// Initialize a new hasher using the specified seed value.
@@ -322,14 +318,14 @@
   @usableFromInline
   @_effects(releasenone)
   internal init(_seed: Int) {
-    self._core = Core(seed: _seed)
+    self._core = _BufferingCore(seed: _seed)
   }
 
   /// Initialize a new hasher using the specified seed value.
   @usableFromInline // @testable
   @_effects(releasenone)
   internal init(_rawSeed: (UInt64, UInt64)) {
-    self._core = Core(core: RawCore(rawSeed: _rawSeed))
+    self._core = _BufferingCore(core: _Core(rawSeed: _rawSeed))
   }
 
   /// Indicates whether we're running in an environment where hashing needs to
@@ -445,7 +441,7 @@
   @_effects(readnone)
   @usableFromInline
   internal static func _hash(seed: Int, _ value: UInt64) -> Int {
-    var core = RawCore(seed: seed)
+    var core = _Core(seed: seed)
     core.compress(value)
     let tbc = _HasherTailBuffer(tail: 0, byteCount: 8)
     return Int(truncatingIfNeeded: core.finalize(tailAndByteCount: tbc.value))
@@ -454,7 +450,7 @@
   @_effects(readnone)
   @usableFromInline
   internal static func _hash(seed: Int, _ value: UInt) -> Int {
-    var core = RawCore(seed: seed)
+    var core = _Core(seed: seed)
 #if arch(i386) || arch(arm)
     _sanityCheck(UInt.bitWidth < UInt64.bitWidth)
     let tbc = _HasherTailBuffer(
@@ -475,7 +471,7 @@
     bytes value: UInt64,
     count: Int) -> Int {
     _sanityCheck(count >= 0 && count < 8)
-    var core = RawCore(seed: seed)
+    var core = _Core(seed: seed)
     let tbc = _HasherTailBuffer(tail: value, byteCount: count)
     return Int(truncatingIfNeeded: core.finalize(tailAndByteCount: tbc.value))
   }
@@ -485,7 +481,7 @@
   internal static func _hash(
     seed: Int,
     bytes: UnsafeRawBufferPointer) -> Int {
-    var core = Core(seed: seed)
+    var core = _BufferingCore(seed: seed)
     core.combine(bytes: bytes)
     return Int(truncatingIfNeeded: core.finalize())
   }
diff --git a/stdlib/public/core/IntegerTypes.swift.gyb b/stdlib/public/core/IntegerTypes.swift.gyb
index 8ad4e06..789a72e 100644
--- a/stdlib/public/core/IntegerTypes.swift.gyb
+++ b/stdlib/public/core/IntegerTypes.swift.gyb
@@ -23,10 +23,6 @@
 # Number of bits in the Builtin.Word type
 word_bits = int(CMAKE_SIZEOF_VOID_P) * 8
 
-# Number of bits in integer literals.
-builtinIntLiteralBits = 2048
-IntLiteral = 'Int%s' % builtinIntLiteralBits
-
 class struct(object):
   def __init__(self, **kw):
     self.__dict__ = kw
@@ -1112,8 +1108,8 @@
 
 
   @_transparent
-  public init(_builtinIntegerLiteral x: _MaxBuiltinIntegerType) {
-    _value = Builtin.s_to_${u}_checked_trunc_${IntLiteral}_${BuiltinName}(x).0
+  public init(_builtinIntegerLiteral x: Builtin.IntLiteral) {
+    _value = Builtin.s_to_${u}_checked_trunc_IntLiteral_${BuiltinName}(x).0
   }
 
   /// Creates a new instance with the same memory representation as the given
diff --git a/stdlib/public/core/LazyCollection.swift b/stdlib/public/core/LazyCollection.swift
index d518ade..9cff798 100644
--- a/stdlib/public/core/LazyCollection.swift
+++ b/stdlib/public/core/LazyCollection.swift
@@ -201,12 +201,6 @@
     return _base._customLastIndexOfEquatableElement(element)
   }
 
-  /// Returns the first element of `self`, or `nil` if `self` is empty.
-  @inlinable
-  public var first: Element? {
-    return _base.first
-  }
-
   // TODO: swift-3-indexing-model - add docs
   @inlinable
   public func index(_ i: Index, offsetBy n: Int) -> Index {
@@ -235,11 +229,6 @@
   public func index(before i: Index) -> Index {
     return _base.index(before: i)
   }
-
-  @inlinable
-  public var last: Element? {
-    return _base.last
-  }
 }
 
 extension LazyCollection : RandomAccessCollection
diff --git a/stdlib/public/core/Map.swift b/stdlib/public/core/Map.swift
index 8c2da07..cd569b1 100644
--- a/stdlib/public/core/Map.swift
+++ b/stdlib/public/core/Map.swift
@@ -188,9 +188,6 @@
   }
 
   @inlinable
-  public var first: Element? { return _base.first.map(_transform) }
-
-  @inlinable
   public func index(_ i: Index, offsetBy n: Int) -> Index {
     return _base.index(i, offsetBy: n)
   }
@@ -223,9 +220,6 @@
   public func formIndex(before i: inout Index) {
     _base.formIndex(before: &i)
   }
-
-  @inlinable
-  public var last: Element? { return _base.last.map(_transform) }
 }
 
 extension LazyMapCollection : RandomAccessCollection
diff --git a/stdlib/public/core/Policy.swift b/stdlib/public/core/Policy.swift
index 782eb33..2420a7a 100644
--- a/stdlib/public/core/Policy.swift
+++ b/stdlib/public/core/Policy.swift
@@ -109,14 +109,6 @@
 //===----------------------------------------------------------------------===//
 // Default types for unconstrained number literals
 //===----------------------------------------------------------------------===//
-// Integer literals are limited to 2048 bits.
-// The intent is to have arbitrary-precision literals, but implementing that
-// requires more work.
-//
-// Rationale: 1024 bits are enough to represent the absolute value of min/max
-// IEEE Binary64, and we need 1 bit to represent the sign.  Instead of using
-// 1025, we use the next round number -- 2048.
-public typealias _MaxBuiltinIntegerType = Builtin.Int2048
 #if !os(Windows) && (arch(i386) || arch(x86_64))
 public typealias _MaxBuiltinFloatType = Builtin.FPIEEE80
 #else
diff --git a/stdlib/public/core/Sequence.swift b/stdlib/public/core/Sequence.swift
index 5e56d90..56ac1b0 100644
--- a/stdlib/public/core/Sequence.swift
+++ b/stdlib/public/core/Sequence.swift
@@ -348,81 +348,6 @@
   ///   In this case, see the documentation of `Collection.underestimatedCount`.
   var underestimatedCount: Int { get }
 
-  /// Returns an array containing the results of mapping the given closure
-  /// over the sequence's elements.
-  ///
-  /// In this example, `map` is used first to convert the names in the array
-  /// to lowercase strings and then to count their characters.
-  ///
-  ///     let cast = ["Vivien", "Marlon", "Kim", "Karl"]
-  ///     let lowercaseNames = cast.map { $0.lowercased() }
-  ///     // 'lowercaseNames' == ["vivien", "marlon", "kim", "karl"]
-  ///     let letterCounts = cast.map { $0.count }
-  ///     // 'letterCounts' == [6, 6, 3, 4]
-  ///
-  /// - Parameter transform: A mapping closure. `transform` accepts an
-  ///   element of this sequence as its parameter and returns a transformed
-  ///   value of the same or of a different type.
-  /// - Returns: An array containing the transformed elements of this
-  ///   sequence.
-  ///
-  /// - Complexity: O(*n*), where *n* is the length of the sequence.
-  func map<T>(
-    _ transform: (Element) throws -> T
-  ) rethrows -> [T]
-
-  /// Returns an array containing, in order, the elements of the sequence
-  /// that satisfy the given predicate.
-  ///
-  /// In this example, `filter(_:)` is used to include only names shorter than
-  /// five characters.
-  ///
-  ///     let cast = ["Vivien", "Marlon", "Kim", "Karl"]
-  ///     let shortNames = cast.filter { $0.count < 5 }
-  ///     print(shortNames)
-  ///     // Prints "["Kim", "Karl"]"
-  ///
-  /// - Parameter isIncluded: A closure that takes an element of the
-  ///   sequence as its argument and returns a Boolean value indicating
-  ///   whether the element should be included in the returned array.
-  /// - Returns: An array of the elements that `isIncluded` allowed.
-  ///
-  /// - Complexity: O(*n*), where *n* is the length of the sequence.
-  __consuming func filter(
-    _ isIncluded: (Element) throws -> Bool
-  ) rethrows -> [Element]
-
-  /// Calls the given closure on each element in the sequence in the same order
-  /// as a `for`-`in` loop.
-  ///
-  /// The two loops in the following example produce the same output:
-  ///
-  ///     let numberWords = ["one", "two", "three"]
-  ///     for word in numberWords {
-  ///         print(word)
-  ///     }
-  ///     // Prints "one"
-  ///     // Prints "two"
-  ///     // Prints "three"
-  ///
-  ///     numberWords.forEach { word in
-  ///         print(word)
-  ///     }
-  ///     // Same as above
-  ///
-  /// Using the `forEach` method is distinct from a `for`-`in` loop in two
-  /// important ways:
-  ///
-  /// 1. You cannot use a `break` or `continue` statement to exit the current
-  ///    call of the `body` closure or skip subsequent calls.
-  /// 2. Using the `return` statement in the `body` closure will exit only from
-  ///    the current call to `body`, not from any outer scope, and won't skip
-  ///    subsequent calls.
-  ///
-  /// - Parameter body: A closure that takes an element of the sequence as a
-  ///   parameter.
-  func forEach(_ body: (Element) throws -> Void) rethrows
-
   // Note: The complexity of Sequence.dropFirst(_:) requirement
   // is documented as O(n) because Collection.dropFirst(_:) is
   // implemented in O(n), even though the default
diff --git a/stdlib/public/core/SequenceWrapper.swift b/stdlib/public/core/SequenceWrapper.swift
index 84e260f..3385259 100644
--- a/stdlib/public/core/SequenceWrapper.swift
+++ b/stdlib/public/core/SequenceWrapper.swift
@@ -22,7 +22,7 @@
   associatedtype Base : Sequence where Base.Element == Element
   associatedtype Iterator = Base.Iterator
   associatedtype SubSequence = Base.SubSequence
-  
+
   var _base: Base { get }
 }
 
@@ -45,7 +45,7 @@
   public __consuming func makeIterator() -> Iterator {
     return self._base.makeIterator()
   }
-  
+
   @inlinable // generic-performance
   @discardableResult
   public __consuming func _copyContents(
@@ -57,25 +57,6 @@
 
 extension _SequenceWrapper {
   @inlinable // generic-performance
-  public func map<T>(
-    _ transform: (Element) throws -> T
-) rethrows -> [T] {
-    return try _base.map(transform)
-  }
-  
-  @inlinable // generic-performance
-  public __consuming func filter(
-    _ isIncluded: (Element) throws -> Bool
-  ) rethrows -> [Element] {
-    return try _base.filter(isIncluded)
-  }
-
-  @inlinable // generic-performance
-  public func forEach(_ body: (Element) throws -> Void) rethrows {
-    return try _base.forEach(body)
-  }
-  
-  @inlinable // generic-performance
   public func _customContainsEquatableElement(
     _ element: Element
   ) -> Bool? { 
diff --git a/stdlib/public/core/Set.swift b/stdlib/public/core/Set.swift
index 10068c8..4bc5380 100644
--- a/stdlib/public/core/Set.swift
+++ b/stdlib/public/core/Set.swift
@@ -391,18 +391,6 @@
   public var isEmpty: Bool {
     return count == 0
   }
-
-  /// The first element of the set.
-  ///
-  /// The first element of the set is not necessarily the first element added
-  /// to the set. Don't expect any particular ordering of set elements.
-  ///
-  /// If the set is empty, the value of this property is `nil`.
-  @inlinable
-  public var first: Element? {
-    var iterator = makeIterator()
-    return iterator.next()
-  }
 }
 
 // FIXME: rdar://problem/23549059 (Optimize == for Set)
diff --git a/stdlib/public/core/SipHash.swift b/stdlib/public/core/SipHash.swift
index e3412f2..e13be21 100644
--- a/stdlib/public/core/SipHash.swift
+++ b/stdlib/public/core/SipHash.swift
@@ -19,181 +19,88 @@
 /// * Daniel J. Bernstein <djb@cr.yp.to>
 //===----------------------------------------------------------------------===//
 
-// FIXME: Remove @usableFromInline and @_fixed_layout once Hasher is resilient.
-// rdar://problem/38549901
-@usableFromInline @_fixed_layout
-internal struct _SipHashState {
-  // "somepseudorandomlygeneratedbytes"
-  fileprivate var v0: UInt64 = 0x736f6d6570736575
-  fileprivate var v1: UInt64 = 0x646f72616e646f6d
-  fileprivate var v2: UInt64 = 0x6c7967656e657261
-  fileprivate var v3: UInt64 = 0x7465646279746573
+extension Hasher {
+  // FIXME: Remove @usableFromInline and @_fixed_layout once Hasher is resilient.
+  // rdar://problem/38549901
+  @usableFromInline @_fixed_layout
+  internal struct _State {
+    // "somepseudorandomlygeneratedbytes"
+    fileprivate var v0: UInt64 = 0x736f6d6570736575
+    fileprivate var v1: UInt64 = 0x646f72616e646f6d
+    fileprivate var v2: UInt64 = 0x6c7967656e657261
+    fileprivate var v3: UInt64 = 0x7465646279746573
+    // The fields below are reserved for future use. They aren't currently used.
+    fileprivate var v4: UInt64 = 0
+    fileprivate var v5: UInt64 = 0
+    fileprivate var v6: UInt64 = 0
+    fileprivate var v7: UInt64 = 0
 
-  @inline(__always)
-  fileprivate init(rawSeed: (UInt64, UInt64)) {
-    v3 ^= rawSeed.1
-    v2 ^= rawSeed.0
-    v1 ^= rawSeed.1
-    v0 ^= rawSeed.0
-  }
-
-  @inline(__always)
-  fileprivate
-  static func _rotateLeft(_ x: UInt64, by amount: UInt64) -> UInt64 {
-    return (x &<< amount) | (x &>> (64 - amount))
-  }
-
-  @inline(__always)
-  fileprivate mutating func _round() {
-    v0 = v0 &+ v1
-    v1 = _SipHashState._rotateLeft(v1, by: 13)
-    v1 ^= v0
-    v0 = _SipHashState._rotateLeft(v0, by: 32)
-    v2 = v2 &+ v3
-    v3 = _SipHashState._rotateLeft(v3, by: 16)
-    v3 ^= v2
-    v0 = v0 &+ v3
-    v3 = _SipHashState._rotateLeft(v3, by: 21)
-    v3 ^= v0
-    v2 = v2 &+ v1
-    v1 = _SipHashState._rotateLeft(v1, by: 17)
-    v1 ^= v2
-    v2 = _SipHashState._rotateLeft(v2, by: 32)
-  }
-
-  @inline(__always)
-  fileprivate func _extract() -> UInt64 {
-    return v0 ^ v1 ^ v2 ^ v3
-  }
-}
-
-// FIXME: Remove @usableFromInline and @_fixed_layout once Hasher is resilient.
-// rdar://problem/38549901
-@usableFromInline @_fixed_layout
-internal struct _SipHash13Core: _HasherCore {
-  private var _state: _SipHashState
-
-  @inline(__always)
-  internal init(rawSeed: (UInt64, UInt64)) {
-    _state = _SipHashState(rawSeed: rawSeed)
-  }
-
-  @inline(__always)
-  internal mutating func compress(_ m: UInt64) {
-    _state.v3 ^= m
-    _state._round()
-    _state.v0 ^= m
-  }
-
-  @inline(__always)
-  internal mutating func finalize(tailAndByteCount: UInt64) -> UInt64 {
-    compress(tailAndByteCount)
-    _state.v2 ^= 0xff
-    for _ in 0..<3 {
-      _state._round()
+    @inline(__always)
+    fileprivate init(rawSeed: (UInt64, UInt64)) {
+      v3 ^= rawSeed.1
+      v2 ^= rawSeed.0
+      v1 ^= rawSeed.1
+      v0 ^= rawSeed.0
     }
-    return _state._extract()
-  }
-}
 
-internal struct _SipHash24Core: _HasherCore {
-  private var _state: _SipHashState
-
-  @inline(__always)
-  internal init(rawSeed: (UInt64, UInt64)) {
-    _state = _SipHashState(rawSeed: rawSeed)
-  }
-
-  @inline(__always)
-  internal mutating func compress(_ m: UInt64) {
-    _state.v3 ^= m
-    _state._round()
-    _state._round()
-    _state.v0 ^= m
-  }
-
-  @inline(__always)
-  internal mutating func finalize(tailAndByteCount: UInt64) -> UInt64 {
-    compress(tailAndByteCount)
-
-    _state.v2 ^= 0xff
-    for _ in 0..<4 {
-      _state._round()
+    @inline(__always)
+    fileprivate
+    static func _rotateLeft(_ x: UInt64, by amount: UInt64) -> UInt64 {
+      return (x &<< amount) | (x &>> (64 - amount))
     }
-    return _state._extract()
+
+    @inline(__always)
+    fileprivate mutating func _round() {
+      v0 = v0 &+ v1
+      v1 = Hasher._State._rotateLeft(v1, by: 13)
+      v1 ^= v0
+      v0 = Hasher._State._rotateLeft(v0, by: 32)
+      v2 = v2 &+ v3
+      v3 = Hasher._State._rotateLeft(v3, by: 16)
+      v3 ^= v2
+      v0 = v0 &+ v3
+      v3 = Hasher._State._rotateLeft(v3, by: 21)
+      v3 ^= v0
+      v2 = v2 &+ v1
+      v1 = Hasher._State._rotateLeft(v1, by: 17)
+      v1 ^= v2
+      v2 = Hasher._State._rotateLeft(v2, by: 32)
+    }
+
+    @inline(__always)
+    fileprivate func _extract() -> UInt64 {
+      return v0 ^ v1 ^ v2 ^ v3
+    }
   }
 }
 
-// FIXME: This type only exists to facilitate testing, and should not exist in
-// production builds.
-@usableFromInline // @testable
-internal struct _SipHash13 {
-  internal typealias Core = _SipHash13Core
+extension Hasher {
+  // FIXME: Remove @usableFromInline and @_fixed_layout once Hasher is resilient.
+  // rdar://problem/38549901
+  @usableFromInline @_fixed_layout
+  internal struct _Core: _HasherCore {
+    private var _state: Hasher._State
 
-  internal var _core: _BufferingHasher<Core>
+    @inline(__always)
+    internal init(rawSeed: (UInt64, UInt64)) {
+      _state = Hasher._State(rawSeed: rawSeed)
+    }
 
-  @usableFromInline // @testable
-  internal init(_rawSeed: (UInt64, UInt64)) {
-    _core = _BufferingHasher(core: Core(rawSeed: _rawSeed))
-  }
-  @usableFromInline // @testable
-  internal mutating func _combine(_ v: UInt) { _core.combine(v) }
-  @usableFromInline // @testable
-  internal mutating func _combine(_ v: UInt64) { _core.combine(v) }
-  @usableFromInline // @testable
-  internal mutating func _combine(_ v: UInt32) { _core.combine(v) }
-  @usableFromInline // @testable
-  internal mutating func _combine(_ v: UInt16) { _core.combine(v) }
-  @usableFromInline // @testable
-  internal mutating func _combine(_ v: UInt8) { _core.combine(v) }
-  @usableFromInline // @testable
-  internal mutating func _combine(bytes v: UInt64, count: Int) {
-    _core.combine(bytes: v, count: count)
-  }
-  @usableFromInline // @testable
-  internal mutating func combine(bytes: UnsafeRawBufferPointer) {
-    _core.combine(bytes: bytes)
-  }
-  @usableFromInline // @testable
-  internal __consuming func finalize() -> UInt64 {
-    var core = _core
-    return core.finalize()
-  }
-}
+    @inline(__always)
+    internal mutating func compress(_ m: UInt64) {
+      _state.v3 ^= m
+      _state._round()
+      _state.v0 ^= m
+    }
 
-// FIXME: This type only exists to facilitate testing, and should not exist in
-// production builds.
-@usableFromInline // @testable
-internal struct _SipHash24 {
-  internal typealias Core = _SipHash24Core
-
-  internal var _core: _BufferingHasher<Core>
-
-  @usableFromInline // @testable
-  internal init(_rawSeed: (UInt64, UInt64)) {
-    _core = _BufferingHasher(core: Core(rawSeed: _rawSeed))
-  }
-  @usableFromInline // @testable
-  internal mutating func _combine(_ v: UInt) { _core.combine(v) }
-  @usableFromInline // @testable
-  internal mutating func _combine(_ v: UInt64) { _core.combine(v) }
-  @usableFromInline // @testable
-  internal mutating func _combine(_ v: UInt32) { _core.combine(v) }
-  @usableFromInline // @testable
-  internal mutating func _combine(_ v: UInt16) { _core.combine(v) }
-  @usableFromInline // @testable
-  internal mutating func _combine(_ v: UInt8) { _core.combine(v) }
-  @usableFromInline // @testable
-  internal mutating func _combine(bytes v: UInt64, count: Int) {
-    _core.combine(bytes: v, count: count)
-  }
-  @usableFromInline // @testable
-  internal mutating func combine(bytes: UnsafeRawBufferPointer) {
-    _core.combine(bytes: bytes)
-  }
-  @usableFromInline // @testable
-  internal __consuming func finalize() -> UInt64 {
-    var core = _core
-    return core.finalize()
+    @inline(__always)
+    internal mutating func finalize(tailAndByteCount: UInt64) -> UInt64 {
+      compress(tailAndByteCount)
+      _state.v2 ^= 0xff
+      for _ in 0..<3 {
+        _state._round()
+      }
+      return _state._extract()
+    }
   }
 }
diff --git a/stdlib/public/core/StringHashable.swift b/stdlib/public/core/StringHashable.swift
index 5ff449a..a170ab0 100644
--- a/stdlib/public/core/StringHashable.swift
+++ b/stdlib/public/core/StringHashable.swift
@@ -13,13 +13,13 @@
 import SwiftShims
 
 extension _UnmanagedString where CodeUnit == UInt8 {
-  internal func hashASCII(into core: inout Hasher.Core) {
+  internal func hashASCII(into core: inout Hasher._BufferingCore) {
     core.combine(bytes: rawBuffer)
   }
 }
 
 extension BidirectionalCollection where Element == UInt16, SubSequence == Self {
-  internal func hashUTF16(into core: inout Hasher.Core) {
+  internal func hashUTF16(into core: inout Hasher._BufferingCore) {
     for i in self.indices {
       let cu = self[i]
       let cuIsASCII = cu <= 0x7F
@@ -62,7 +62,7 @@
   }
 
   internal func _rawHashValue(seed: Int) -> Int {
-    var core = Hasher.Core(seed: seed)
+    var core = Hasher._BufferingCore(seed: seed)
     self.hashUTF16(into: &core)
     return Int(truncatingIfNeeded: core.finalize())
   }
@@ -75,7 +75,7 @@
   }
 
   internal func _rawHashValue(seed: Int) -> Int {
-    var core = Hasher.Core(seed: seed)
+    var core = Hasher._BufferingCore(seed: seed)
     self.hashUTF16(into: &core)
     return Int(truncatingIfNeeded: core.finalize())
   }
diff --git a/stdlib/public/runtime/Casting.cpp b/stdlib/public/runtime/Casting.cpp
index aeaa171..3b45149 100644
--- a/stdlib/public/runtime/Casting.cpp
+++ b/stdlib/public/runtime/Casting.cpp
@@ -362,8 +362,24 @@
 #endif
 
   
-  case MetadataKind::Existential: // FIXME
-  case MetadataKind::ExistentialMetatype: // FIXME
+  case MetadataKind::Existential: {
+#if SWIFT_OBJC_INTEROP
+    // If all protocols are @objc and at least one of them conforms to the
+    // protocol, succeed.
+    auto existential = cast<ExistentialTypeMetadata>(type);
+    if (!existential->isObjC())
+      return false;
+    for (auto existentialProto : existential->getProtocols()) {
+      if (protocol_conformsToProtocol(existentialProto.getObjCProtocol(),
+                                      protocol.getObjCProtocol()))
+        return true;
+    }
+#endif
+
+    return false;
+  }
+
+  case MetadataKind::ExistentialMetatype:
   default:
     return false;
   }
diff --git a/stdlib/public/runtime/KnownMetadata.cpp b/stdlib/public/runtime/KnownMetadata.cpp
index 6536f9e..02813bb 100644
--- a/stdlib/public/runtime/KnownMetadata.cpp
+++ b/stdlib/public/runtime/KnownMetadata.cpp
@@ -16,6 +16,7 @@
 
 #include "swift/Runtime/Metadata.h"
 #include "swift/Runtime/HeapObject.h"
+#include "swift/Runtime/Numeric.h"
 #include "MetadataImpl.h"
 #include "Private.h"
 #include <cstring>
@@ -38,10 +39,11 @@
     char data[16];
   };
 
-  struct alignas(32) int256_like {
+  static_assert(MaximumAlignment == 16, "max alignment was hardcoded");
+  struct alignas(16) int256_like {
     char data[32];
   };
-  struct alignas(64) int512_like {
+  struct alignas(16) int512_like {
     char data[64];
   };
 
@@ -65,6 +67,7 @@
     using Bi512_ = int512_like;
 
     using Bw = intptr_t;
+    using BL_ = IntegerLiteral;
 
     using Bf16_ = uint16_t;
     using Bf32_ = float;
@@ -120,8 +123,9 @@
   SET_FIXED_ALIGNMENT(uint32_t, 4)
   SET_FIXED_ALIGNMENT(uint64_t, 8)
   SET_FIXED_ALIGNMENT(int128_like, 16)
-  SET_FIXED_ALIGNMENT(int256_like, 32)
-  SET_FIXED_ALIGNMENT(int512_like, 64)
+  static_assert(MaximumAlignment == 16, "max alignment was hardcoded");
+  SET_FIXED_ALIGNMENT(int256_like, 16)
+  SET_FIXED_ALIGNMENT(int512_like, 16)
 
 #undef SET_FIXED_ALIGNMENT
 
diff --git a/test/Constraints/generics.swift b/test/Constraints/generics.swift
index 258bf16..6219fc9 100644
--- a/test/Constraints/generics.swift
+++ b/test/Constraints/generics.swift
@@ -618,8 +618,8 @@
   }
 
   var s = S(id: S.Id())
-  let _: E = .foo(s)   // expected-error {{generic enum 'E' requires that 'S' conform to 'P'}}
-  let _: E = .bar([s]) // expected-error {{generic enum 'E' requires that 'S' conform to 'P'}}
+  let _: E = .foo(s)   // expected-error {{enum case 'foo' requires that 'S' conform to 'P'}}
+  let _: E = .bar([s]) // expected-error {{enum case 'bar' requires that 'S' conform to 'P'}}
 }
 
 // SR-8934
@@ -629,3 +629,5 @@
 let arr = [BottleLayout]()
 let layout = BottleLayout(count:1)
 let ix = arr.firstIndex(of:layout) // expected-error {{argument type 'BottleLayout' does not conform to expected type 'Equatable'}}
+
+let _: () -> UInt8 = { .init("a" as Unicode.Scalar) } // expected-error {{initializer 'init(_:)' requires that 'Unicode.Scalar' conform to 'BinaryInteger'}}
diff --git a/test/DebugInfo/local-vars.swift.gyb b/test/DebugInfo/local-vars.swift.gyb
index 5a9af6e..ef7423a 100644
--- a/test/DebugInfo/local-vars.swift.gyb
+++ b/test/DebugInfo/local-vars.swift.gyb
@@ -2,6 +2,7 @@
 // test only verifies that the variables show up in the debug info at
 // all. There are other tests testing liveness and representation.
 
+// REQUIRES: rdar45708367
 // RUN: %gyb %s -o %t.swift
 // RUN: %target-swift-frontend %t.swift -g -emit-ir -o - | %FileCheck %t.swift
 // RUN: %target-swift-frontend %t.swift -g -c -o %t.o
diff --git a/test/DebugInfo/value-update.sil b/test/DebugInfo/value-update.sil
index 85813de..c1975d3 100644
--- a/test/DebugInfo/value-update.sil
+++ b/test/DebugInfo/value-update.sil
@@ -37,8 +37,8 @@
   // CHECK: {{^}}}
 }
 
-// Swift.Int.init (_builtinIntegerLiteral : Builtin.Int2048) -> Swift.Int
-sil [transparent] [serialized] @_TFSiCfT22_builtinIntegerLiteralBi2048__Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+// Swift.Int.init (_builtinIntegerLiteral : Builtin.IntLiteral) -> Swift.Int
+sil [transparent] [serialized] @_TFSiCfT22_builtinIntegerLiteralBI__Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
 
 // StdlibUnittest._blackHole <A> (A) -> ()
 sil @_TF14StdlibUnittest10_blackHoleurFxT_ : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
diff --git a/test/Driver/emit-interface.swift b/test/Driver/emit-interface.swift
index e4966bb..beb0b73 100644
--- a/test/Driver/emit-interface.swift
+++ b/test/Driver/emit-interface.swift
@@ -19,3 +19,10 @@
 // CHECK-EXPLICIT-PATH: swift -frontend
 // CHECK-EXPLICIT-PATH-SAME: emit-interface.swift
 // CHECK-EXPLICIT-PATH-SAME: -emit-parseable-module-interface-path {{.+}}/unrelated.swiftinterface
+
+// Ensure that we emit arguments when we force filelists as well
+// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.9 %s -emit-parseable-module-interface -o %t/foo -module-name foo -force-single-frontend-invocation -driver-filelist-threshold=0 2>&1 | %FileCheck -check-prefix=CHECK-FILELIST %s
+
+// CHECK-FILELIST: swift -frontend
+// CHECK-FILELIST-SAME: -supplementary-output-file-map
+// CHECK-FILELIST-NOT: emit-interface.swift{{ }}
diff --git a/test/FixCode/fixits-apply-objc.swift b/test/FixCode/fixits-apply-objc.swift
index 358c692..2a3f292 100644
--- a/test/FixCode/fixits-apply-objc.swift
+++ b/test/FixCode/fixits-apply-objc.swift
@@ -1,4 +1,4 @@
-// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -disable-objc-attr-requires-foundation-module -typecheck %s -emit-fixits-path %t.remap -swift-version 3
+// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -disable-objc-attr-requires-foundation-module -typecheck %s -emit-fixits-path %t.remap
 // RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
 import ObjectiveC
 
diff --git a/test/FixCode/fixits-apply-objc.swift.result b/test/FixCode/fixits-apply-objc.swift.result
index b4f12b9..607a3bd 100644
--- a/test/FixCode/fixits-apply-objc.swift.result
+++ b/test/FixCode/fixits-apply-objc.swift.result
@@ -1,4 +1,4 @@
-// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -disable-objc-attr-requires-foundation-module -typecheck %s -emit-fixits-path %t.remap -swift-version 3
+// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -disable-objc-attr-requires-foundation-module -typecheck %s -emit-fixits-path %t.remap
 // RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
 import ObjectiveC
 
diff --git a/test/IDE/print_types.swift b/test/IDE/print_types.swift
index 5096844..cbcf290 100644
--- a/test/IDE/print_types.swift
+++ b/test/IDE/print_types.swift
@@ -14,46 +14,46 @@
 
   var a1 = 42
 // CHECK: VarDecl '''a1''' Int{{$}}
-// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Int2048{{$}}
+// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Builtin.IntLiteral{{$}}
 // FULL:  VarDecl '''a1''' Swift.Int{{$}}
-// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Int2048{{$}}
+// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Builtin.IntLiteral{{$}}
   a1 = 17; _ = a1
 
   
   var a2 : Int = 42
 // CHECK: VarDecl '''a2''' Int{{$}}
-// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Int2048{{$}}
+// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Builtin.IntLiteral{{$}}
 // FULL:  VarDecl '''a2''' Swift.Int{{$}}
-// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Int2048{{$}}
+// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Builtin.IntLiteral{{$}}
   a2 = 17; _ = a2
 
   var a3 = Int16(42)
 // CHECK: VarDecl '''a3''' Int16{{$}}
-// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Int2048{{$}}
+// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Builtin.IntLiteral{{$}}
 // FULL:  VarDecl '''a3''' Swift.Int16{{$}}
-// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Int2048{{$}}
+// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Builtin.IntLiteral{{$}}
   a3 = 17; _ = a3
 
 
   var a4 = Int32(42)
 // CHECK: VarDecl '''a4''' Int32{{$}}
-// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Int2048{{$}}
+// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Builtin.IntLiteral{{$}}
 // FULL:  VarDecl '''a4''' Swift.Int32{{$}}
-// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Int2048{{$}}
+// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Builtin.IntLiteral{{$}}
   a4 = 17; _ = a4
 
   var a5 : Int64 = 42
 // CHECK: VarDecl '''a5''' Int64{{$}}
-// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Int2048{{$}}
+// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Builtin.IntLiteral{{$}}
 // FULL:  VarDecl '''a5''' Swift.Int64{{$}}
-// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Int2048{{$}}
+// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Builtin.IntLiteral{{$}}
   a5 = 17; _ = a5
 
   var typealias1 : MyInt = 42
 // CHECK: VarDecl '''typealias1''' MyInt{{$}}
-// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Int2048{{$}}
+// CHECK:         IntegerLiteralExpr:[[@LINE-2]] '''42''' Builtin.IntLiteral{{$}}
 // FULL:  VarDecl '''typealias1''' MyInt{{$}}
-// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Int2048{{$}}
+// FULL:          IntegerLiteralExpr:[[@LINE-4]] '''42''' Builtin.IntLiteral{{$}}
   _ = typealias1 ; typealias1 = 1
 
   var optional1 = Optional<Int>.none
diff --git a/test/IRGen/Inputs/weak_import_native_helper.swift b/test/IRGen/Inputs/weak_import_native_helper.swift
index 6e6c557..6ba6bdf 100644
--- a/test/IRGen/Inputs/weak_import_native_helper.swift
+++ b/test/IRGen/Inputs/weak_import_native_helper.swift
@@ -103,3 +103,15 @@
 
 @_weakLinked
 open class GenericC<T> {}
+
+public protocol OtherProtocol {}
+public struct ConcreteType : OtherProtocol {}
+
+public protocol ProtocolWithWeakMembers {
+  @_weakLinked associatedtype T : OtherProtocol = ConcreteType
+  @_weakLinked func f()
+}
+
+extension ProtocolWithWeakMembers {
+  @_weakLinked public func f() {}
+}
diff --git a/test/IRGen/completely_fragile_class_layout.sil b/test/IRGen/completely_fragile_class_layout.sil
index 7060dd8..2c71089 100644
--- a/test/IRGen/completely_fragile_class_layout.sil
+++ b/test/IRGen/completely_fragile_class_layout.sil
@@ -37,8 +37,8 @@
 
 // Field offsets are statically known:
 // CHECK-DAG: @"$s31completely_fragile_class_layout23ClassWithResilientFieldC5firstSivpWvd" = hidden constant i64 16, align 8
-// CHECK-DAG: @"$s31completely_fragile_class_layout23ClassWithResilientFieldC6second16resilient_struct4SizeVvpWvd" = hidden constant i64 24, align 8
-// CHECK-DAG: @"$s31completely_fragile_class_layout23ClassWithResilientFieldC5thirdSivpWvd" = hidden constant i64 40, align 8
+// CHECK-DAG: @"$s31completely_fragile_class_layout23ClassWithResilientFieldC6second16resilient_struct4SizeVvpWvd" = hidden global i64 24, align 8
+// CHECK-DAG: @"$s31completely_fragile_class_layout23ClassWithResilientFieldC5thirdSivpWvd" = hidden global i64 40, align 8
 
 
 // RO-data for ClassWithResilientField:
@@ -91,8 +91,8 @@
 sil_vtable ClassWithResilientEnum {}
 
 // Field offsets are statically known:
-// CHECK-LABEL: @"$s31completely_fragile_class_layout22ClassWithResilientEnumC5firstAA0hfG7PayloadOvpWvd" = hidden constant i64 16, align 8
-// CHECK-LABEL: @"$s31completely_fragile_class_layout22ClassWithResilientEnumC6seconds4Int8VvpWvd" = hidden constant i64 25, align 8
+// CHECK-LABEL: @"$s31completely_fragile_class_layout22ClassWithResilientEnumC5firstAA0hfG7PayloadOvpWvd" = hidden global i64 16, align 8
+// CHECK-LABEL: @"$s31completely_fragile_class_layout22ClassWithResilientEnumC6seconds4Int8VvpWvd" = hidden global i64 25, align 8
 
 
 // Make sure extra inhabitants work when reading a legacy layout -- the
@@ -105,8 +105,8 @@
 sil_vtable ClassWithResilientRef {}
 
 // Field offsets are statically known:
-// CHECK-LABEL: @"$s31completely_fragile_class_layout21ClassWithResilientRefC5first16resilient_struct0gH0VSgvpWvd" = hidden constant i64 16, align 8
-// CHECK-LABEL: @"$s31completely_fragile_class_layout21ClassWithResilientRefC6secondSivpWvd" = hidden constant i64 24, align 8
+// CHECK-LABEL: @"$s31completely_fragile_class_layout21ClassWithResilientRefC5first16resilient_struct0gH0VSgvpWvd" = hidden global i64 16, align 8
+// CHECK-LABEL: @"$s31completely_fragile_class_layout21ClassWithResilientRefC6secondSivpWvd" = hidden global i64 24, align 8
 
 
 // When allocating a class with resiliently-sized fields, we must still load
diff --git a/test/IRGen/int_to_fp.sil b/test/IRGen/int_to_fp.sil
deleted file mode 100644
index 0a4aabb..0000000
--- a/test/IRGen/int_to_fp.sil
+++ /dev/null
@@ -1,31 +0,0 @@
-// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -emit-ir %s | %FileCheck %s
-
-// Test if llvm can generate code for it
-// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -c %s
-
-sil_stage canonical
-
-import Builtin
-
-// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc float @test_large(i2048* noalias nocapture dereferenceable(256)
-// CHECK: %1 = load i2048, i2048* %0, align 16
-// CHECK: %2 = trunc i2048 %1 to i64
-// CHECK: %3 = sitofp i64 %2 to float
-// CHECK: ret float %3
-sil  @test_large : $@convention(thin) (Builtin.Int2048) -> Builtin.FPIEEE32 {
-bb0(%0 : $Builtin.Int2048):
-  %2 = builtin "itofp_with_overflow_Int2048_FPIEEE32"(%0 : $Builtin.Int2048) : $Builtin.FPIEEE32
-  return %2 : $Builtin.FPIEEE32
-}
-
-// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc float @test_small
-// CHECK: %1 = sext i32 %0 to i64
-// CHECK: %2 = sitofp i64 %1 to float
-// CHECK: ret float %2
-sil @test_small : $@convention(thin) (Builtin.Int32) -> Builtin.FPIEEE32 {
-bb0(%0 : $Builtin.Int32):
-  %2 = builtin "itofp_with_overflow_Int32_FPIEEE32"(%0 : $Builtin.Int32) : $Builtin.FPIEEE32
-  return %2 : $Builtin.FPIEEE32
-}
-
-
diff --git a/test/IRGen/integer_literal.sil b/test/IRGen/integer_literal.sil
new file mode 100644
index 0000000..cf82300
--- /dev/null
+++ b/test/IRGen/integer_literal.sil
@@ -0,0 +1,356 @@
+// RUN: %swift -target armv7-apple-ios10 -module-name integer_literal %s -gnone -emit-ir | %FileCheck %s
+
+// REQUIRES: CODEGENERATOR=ARM
+
+// We use a 32-bit target because it makes the literals smaller.
+
+sil_stage canonical
+
+import Builtin
+
+/***************************************************************************/
+/* constant emission tests                                                 */
+/***************************************************************************/
+
+// CHECK: @intliteral.-2147483648 =
+// CHECK-SAME: private unnamed_addr constant [1 x i32] [i32 -2147483648]
+
+// CHECK: @intliteral.2147483648 =
+// CHECK-SAME: private unnamed_addr constant [2 x i32] [i32 -2147483648, i32 0]
+
+// CHECK: @intliteral.0 =
+// CHECK-SAME: private unnamed_addr constant [1 x i32] zeroinitializer
+
+// CHECK: @intliteral.-1 =
+// CHECK-SAME: private unnamed_addr constant [1 x i32] [i32 -1]
+
+// CHECK: @intliteral.60 =
+// CHECK-SAME: private unnamed_addr constant [1 x i32] [i32 60]
+
+sil @use_literal : $@convention(thin) (Builtin.IntLiteral) -> ()
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @constant_corner_cases
+sil @constant_corner_cases : $() -> () {
+entry:
+  %fn = function_ref @use_literal : $@convention(thin) (Builtin.IntLiteral) -> ()
+
+  // CHECK:         call swiftcc void @use_literal(i32* getelementptr inbounds ([1 x i32], [1 x i32]* @intliteral.-2147483648, i32 0, i32 0), i32 8193)
+  //   8193 == 32 << 8 + 1 (negative)
+  %0 = integer_literal $Builtin.IntLiteral, -0x8000_0000
+  apply %fn(%0) : $@convention(thin) (Builtin.IntLiteral) -> ()
+
+  // CHECK-NEXT:    call swiftcc void @use_literal(i32* getelementptr inbounds ([2 x i32], [2 x i32]* @intliteral.2147483648, i32 0, i32 0), i32 8448)
+  //   8448 == 33 << 8
+  %1 = integer_literal $Builtin.IntLiteral, 0x8000_0000
+  apply %fn(%1) : $@convention(thin) (Builtin.IntLiteral) -> ()
+
+  // CHECK-NEXT:    call swiftcc void @use_literal(i32* getelementptr inbounds ([1 x i32], [1 x i32]* @intliteral.0, i32 0, i32 0), i32 256)
+  //   256 == 1 << 8
+  %3 = integer_literal $Builtin.IntLiteral, 0
+  apply %fn(%3) : $@convention(thin) (Builtin.IntLiteral) -> ()
+
+  // CHECK-NEXT:    call swiftcc void @use_literal(i32* getelementptr inbounds ([1 x i32], [1 x i32]* @intliteral.-1, i32 0, i32 0), i32 257)
+  //   257 == 1 << 8 + 1 (negative)
+  %4 = integer_literal $Builtin.IntLiteral, -1
+  apply %fn(%4) : $@convention(thin) (Builtin.IntLiteral) -> ()
+
+  // CHECK-NEXT:    ret void
+  %v = tuple ()
+  return %v : $()
+}
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @redundant_literals
+sil @redundant_literals : $() -> () {
+entry:
+  %fn = function_ref @use_literal : $@convention(thin) (Builtin.IntLiteral) -> ()
+
+  // CHECK:         call swiftcc void @use_literal(i32* getelementptr inbounds ([1 x i32], [1 x i32]* @intliteral.60, i32 0, i32 0), i32 1792)
+  //   1792 == 7 << 8
+  %0 = integer_literal $Builtin.IntLiteral, 60
+  apply %fn(%0) : $@convention(thin) (Builtin.IntLiteral) -> ()
+
+  // CHECK-NEXT:    call swiftcc void @use_literal(i32* getelementptr inbounds ([1 x i32], [1 x i32]* @intliteral.60, i32 0, i32 0), i32 1792)
+  //   1792 == 7 << 8
+  %1 = integer_literal $Builtin.IntLiteral, 60
+  apply %fn(%1) : $@convention(thin) (Builtin.IntLiteral) -> ()
+
+  // CHECK-NEXT:    ret void
+  %v = tuple ()
+  return %v : $()
+}
+
+
+
+/***************************************************************************/
+/* s_to_s_checked_trunc tests                                              */
+/***************************************************************************/
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc {{.*}} @trunc_s16
+sil @trunc_s16 : $(Builtin.IntLiteral) -> (Builtin.Int16, Builtin.Int1) {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:         [[WIDTH:%.*]] = lshr i32 %1, 8
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = icmp ugt i32 [[WIDTH]], 16
+  // CHECK-NEXT:    br i1 [[OVERFLOW]], label %[[INVALID:[a-z.]+]], label %[[VALID:[a-z.]+]]
+  // CHECK:       [[INVALID]]:
+  // CHECK-NEXT:    br label %[[DONE:[a-z.]+]]
+  // CHECK:       [[VALID]]:
+  // CHECK-NEXT:    [[CHUNK0:%.*]] = load i32, i32* %0, align 4
+  // CHECK-NEXT:    [[CHUNK0_TRUNC:%.*]] = trunc i32 [[CHUNK0]] to i16
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[DONE]]:
+  // CHECK-NEXT:    [[RESULT:%.*]] = phi i16 [ 0, %[[INVALID]] ], [ [[CHUNK0_TRUNC]], %[[VALID]] ]
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = phi i1 [ true, %[[INVALID]] ], [ false, %[[VALID]] ]
+
+  %tuple = builtin "s_to_s_checked_trunc_IntLiteral_Int16"(%0 : $Builtin.IntLiteral) : $(Builtin.Int16, Builtin.Int1)
+  return %tuple : $(Builtin.Int16, Builtin.Int1)
+}
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc { i32, i1 } @trunc_s32
+sil @trunc_s32 : $(Builtin.IntLiteral) -> (Builtin.Int32, Builtin.Int1) {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:         [[WIDTH:%.*]] = lshr i32 %1, 8
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = icmp ugt i32 [[WIDTH]], 32
+  // CHECK-NEXT:    br i1 [[OVERFLOW]], label %[[INVALID:[a-z.]+]], label %[[VALID:[a-z.]+]]
+  // CHECK:       [[INVALID]]:
+  // CHECK-NEXT:    br label %[[DONE:[a-z.]+]]
+  // CHECK:       [[VALID]]:
+  // CHECK-NEXT:    [[CHUNK0:%.*]] = load i32, i32* %0, align 4
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[DONE]]:
+  // CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, %[[INVALID]] ], [ [[CHUNK0]], %[[VALID]] ]
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = phi i1 [ true, %[[INVALID]] ], [ false, %[[VALID]] ]
+
+  %tuple = builtin "s_to_s_checked_trunc_IntLiteral_Int32"(%0 : $Builtin.IntLiteral) : $(Builtin.Int32, Builtin.Int1)
+  return %tuple : $(Builtin.Int32, Builtin.Int1)
+}
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc {{.*}} @trunc_s48
+sil @trunc_s48 : $(Builtin.IntLiteral) -> (Builtin.Int48, Builtin.Int1) {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:         [[WIDTH:%.*]] = lshr i32 %1, 8
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = icmp ugt i32 [[WIDTH]], 48
+  // CHECK-NEXT:    br i1 [[OVERFLOW]], label %[[INVALID:[a-z.]+]], label %[[VALID:[a-z.]+]]
+  // CHECK:       [[INVALID]]:
+  // CHECK-NEXT:    br label %[[DONE:[a-z.]+]]
+  // CHECK:       [[VALID]]:
+  // CHECK-NEXT:    [[CHUNK0:%.*]] = load i32, i32* %0, align 4
+  // CHECK-NEXT:    [[FINISHED0:%.*]] = icmp ule i32 [[WIDTH]], 32
+  // CHECK-NEXT:    br i1 [[FINISHED0]], label %[[FINISH0:[a-z.]+]], label %[[NEXT0:[a-z.]+]]
+  // CHECK:       [[FINISH0]]:
+  // CHECK-NEXT:    [[RESULT0:%.*]] = sext i32 [[CHUNK0]] to i48
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[NEXT0]]:
+  // CHECK-NEXT:    [[CHUNKADDR1:%.*]] = getelementptr inbounds i32, i32* %0, i32 1
+  // CHECK-NEXT:    [[CHUNK1:%.*]] = load i32, i32* [[CHUNKADDR1]], align 4
+  // CHECK-NEXT:    [[EXTEND1:%.*]] = zext i32 [[CHUNK0]] to i48
+  // CHECK-NEXT:    [[CHUNK1EXT:%.*]] = zext i32 [[CHUNK1]] to i48
+  // CHECK-NEXT:    [[CHUNK1SHIFT:%.*]] = shl i48 [[CHUNK1EXT]], 32
+  // CHECK-NEXT:    [[RESULT1:%.*]] = add i48 [[EXTEND1]], [[CHUNK1SHIFT]]
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[DONE]]:
+  // CHECK-NEXT:    [[RESULT:%.*]] = phi i48 [ 0, %[[INVALID]] ], [ [[RESULT0]], %[[FINISH0]] ], [ [[RESULT1]], %[[NEXT0]] ]
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = phi i1 [ true, %[[INVALID]] ], [ false, %[[FINISH0]] ], [ false, %[[NEXT0]] ]
+
+  %tuple = builtin "s_to_s_checked_trunc_IntLiteral_Int48"(%0 : $Builtin.IntLiteral) : $(Builtin.Int48, Builtin.Int1)
+  return %tuple : $(Builtin.Int48, Builtin.Int1)
+}
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc { i64, i1 } @trunc_s64
+sil @trunc_s64 : $(Builtin.IntLiteral) -> (Builtin.Int64, Builtin.Int1) {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:         [[WIDTH:%.*]] = lshr i32 %1, 8
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = icmp ugt i32 [[WIDTH]], 64
+  // CHECK-NEXT:    br i1 [[OVERFLOW]], label %[[INVALID:[a-z.]+]], label %[[VALID:[a-z.]+]]
+  // CHECK:       [[INVALID]]:
+  // CHECK-NEXT:    br label %[[DONE:[a-z.]+]]
+  // CHECK:       [[VALID]]:
+  // CHECK-NEXT:    [[CHUNK0:%.*]] = load i32, i32* %0, align 4
+  // CHECK-NEXT:    [[FINISHED0:%.*]] = icmp ule i32 [[WIDTH]], 32
+  // CHECK-NEXT:    br i1 [[FINISHED0]], label %[[FINISH0:[a-z.]+]], label %[[NEXT0:[a-z.]+]]
+  // CHECK:       [[FINISH0]]:
+  // CHECK-NEXT:    [[RESULT0:%.*]] = sext i32 [[CHUNK0]] to i64
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[NEXT0]]:
+  // CHECK-NEXT:    [[CHUNKADDR1:%.*]] = getelementptr inbounds i32, i32* %0, i32 1
+  // CHECK-NEXT:    [[CHUNK1:%.*]] = load i32, i32* [[CHUNKADDR1]], align 4
+  // CHECK-NEXT:    [[EXTEND1:%.*]] = zext i32 [[CHUNK0]] to i64
+  // CHECK-NEXT:    [[CHUNK1EXT:%.*]] = zext i32 [[CHUNK1]] to i64
+  // CHECK-NEXT:    [[CHUNK1SHIFT:%.*]] = shl i64 [[CHUNK1EXT]], 32
+  // CHECK-NEXT:    [[RESULT1:%.*]] = add i64 [[EXTEND1]], [[CHUNK1SHIFT]]
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[DONE]]:
+  // CHECK-NEXT:    [[RESULT:%.*]] = phi i64 [ 0, %[[INVALID]] ], [ [[RESULT0]], %[[FINISH0]] ], [ [[RESULT1]], %[[NEXT0]] ]
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = phi i1 [ true, %[[INVALID]] ], [ false, %[[FINISH0]] ], [ false, %[[NEXT0]] ]
+
+  %tuple = builtin "s_to_s_checked_trunc_IntLiteral_Int64"(%0 : $Builtin.IntLiteral) : $(Builtin.Int64, Builtin.Int1)
+  return %tuple : $(Builtin.Int64, Builtin.Int1)
+}
+
+
+
+/***************************************************************************/
+/* s_to_u_checked_trunc tests                                              */
+/***************************************************************************/
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc {{.*}} @trunc_u16
+sil @trunc_u16 : $(Builtin.IntLiteral) -> (Builtin.Int16, Builtin.Int1) {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:         [[WIDTH:%.*]] = lshr i32 %1, 8
+  // CHECK-NEXT:    [[NEGATIVE:%.*]] = trunc i32 %1 to i1
+  // CHECK-NEXT:    [[LARGE:%.*]] = icmp ugt i32 [[WIDTH]], 17
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = or i1 [[NEGATIVE]], [[LARGE]]
+  // CHECK-NEXT:    br i1 [[OVERFLOW]], label %[[INVALID:[a-z.]+]], label %[[VALID:[a-z.]+]]
+  // CHECK:       [[INVALID]]:
+  // CHECK-NEXT:    br label %[[DONE:[a-z.]+]]
+  // CHECK:       [[VALID]]:
+  // CHECK-NEXT:    [[CHUNK0:%.*]] = load i32, i32* %0, align 4
+  // CHECK-NEXT:    [[CHUNK0_TRUNC:%.*]] = trunc i32 [[CHUNK0]] to i16
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[DONE]]:
+  // CHECK-NEXT:    [[RESULT:%.*]] = phi i16 [ 0, %[[INVALID]] ], [ [[CHUNK0_TRUNC]], %[[VALID]] ]
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = phi i1 [ true, %[[INVALID]] ], [ false, %[[VALID]] ]
+
+  %tuple = builtin "s_to_u_checked_trunc_IntLiteral_Int16"(%0 : $Builtin.IntLiteral) : $(Builtin.Int16, Builtin.Int1)
+  return %tuple : $(Builtin.Int16, Builtin.Int1)
+}
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc { i32, i1 } @trunc_u32
+sil @trunc_u32 : $(Builtin.IntLiteral) -> (Builtin.Int32, Builtin.Int1) {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:         [[WIDTH:%.*]] = lshr i32 %1, 8
+  // CHECK-NEXT:    [[NEGATIVE:%.*]] = trunc i32 %1 to i1
+  // CHECK-NEXT:    [[LARGE:%.*]] = icmp ugt i32 [[WIDTH]], 33
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = or i1 [[NEGATIVE]], [[LARGE]]
+  // CHECK-NEXT:    br i1 [[OVERFLOW]], label %[[INVALID:[a-z.]+]], label %[[VALID:[a-z.]+]]
+  // CHECK:       [[INVALID]]:
+  // CHECK-NEXT:    br label %[[DONE:[a-z.]+]]
+  // CHECK:       [[VALID]]:
+  // CHECK-NEXT:    [[CHUNK0:%.*]] = load i32, i32* %0, align 4
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[DONE]]:
+  // CHECK-NEXT:    [[RESULT:%.*]] = phi i32 [ 0, %[[INVALID]] ], [ [[CHUNK0]], %[[VALID]] ]
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = phi i1 [ true, %[[INVALID]] ], [ false, %[[VALID]] ]
+
+  %tuple = builtin "s_to_u_checked_trunc_IntLiteral_Int32"(%0 : $Builtin.IntLiteral) : $(Builtin.Int32, Builtin.Int1)
+  return %tuple : $(Builtin.Int32, Builtin.Int1)
+}
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc {{.*}} @trunc_u48
+sil @trunc_u48 : $(Builtin.IntLiteral) -> (Builtin.Int48, Builtin.Int1) {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:         [[WIDTH:%.*]] = lshr i32 %1, 8
+  // CHECK-NEXT:    [[NEGATIVE:%.*]] = trunc i32 %1 to i1
+  // CHECK-NEXT:    [[LARGE:%.*]] = icmp ugt i32 [[WIDTH]], 49
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = or i1 [[NEGATIVE]], [[LARGE]]
+  // CHECK-NEXT:    br i1 [[OVERFLOW]], label %[[INVALID:[a-z.]+]], label %[[VALID:[a-z.]+]]
+  // CHECK:       [[INVALID]]:
+  // CHECK-NEXT:    br label %[[DONE:[a-z.]+]]
+  // CHECK:       [[VALID]]:
+  // CHECK-NEXT:    [[CHUNK0:%.*]] = load i32, i32* %0, align 4
+  // CHECK-NEXT:    [[FINISHED0:%.*]] = icmp ule i32 [[WIDTH]], 33
+  // CHECK-NEXT:    br i1 [[FINISHED0]], label %[[FINISH0:[a-z.]+]], label %[[NEXT0:[a-z.]+]]
+  // CHECK:       [[FINISH0]]:
+  // CHECK-NEXT:    [[RESULT0:%.*]] = zext i32 [[CHUNK0]] to i48
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[NEXT0]]:
+  // CHECK-NEXT:    [[CHUNKADDR1:%.*]] = getelementptr inbounds i32, i32* %0, i32 1
+  // CHECK-NEXT:    [[CHUNK1:%.*]] = load i32, i32* [[CHUNKADDR1]], align 4
+  // CHECK-NEXT:    [[EXTEND1:%.*]] = zext i32 [[CHUNK0]] to i48
+  // CHECK-NEXT:    [[CHUNK1EXT:%.*]] = zext i32 [[CHUNK1]] to i48
+  // CHECK-NEXT:    [[CHUNK1SHIFT:%.*]] = shl i48 [[CHUNK1EXT]], 32
+  // CHECK-NEXT:    [[RESULT1:%.*]] = add i48 [[EXTEND1]], [[CHUNK1SHIFT]]
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[DONE]]:
+  // CHECK-NEXT:    [[RESULT:%.*]] = phi i48 [ 0, %[[INVALID]] ], [ [[RESULT0]], %[[FINISH0]] ], [ [[RESULT1]], %[[NEXT0]] ]
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = phi i1 [ true, %[[INVALID]] ], [ false, %[[FINISH0]] ], [ false, %[[NEXT0]] ]
+
+  %tuple = builtin "s_to_u_checked_trunc_IntLiteral_Int48"(%0 : $Builtin.IntLiteral) : $(Builtin.Int48, Builtin.Int1)
+  return %tuple : $(Builtin.Int48, Builtin.Int1)
+}
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc { i64, i1 } @trunc_u64
+sil @trunc_u64 : $(Builtin.IntLiteral) -> (Builtin.Int64, Builtin.Int1) {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:         [[WIDTH:%.*]] = lshr i32 %1, 8
+  // CHECK-NEXT:    [[NEGATIVE:%.*]] = trunc i32 %1 to i1
+  // CHECK-NEXT:    [[LARGE:%.*]] = icmp ugt i32 [[WIDTH]], 65
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = or i1 [[NEGATIVE]], [[LARGE]]
+  // CHECK-NEXT:    br i1 [[OVERFLOW]], label %[[INVALID:[a-z.]+]], label %[[VALID:[a-z.]+]]
+  // CHECK:       [[INVALID]]:
+  // CHECK-NEXT:    br label %[[DONE:[a-z.]+]]
+  // CHECK:       [[VALID]]:
+  // CHECK-NEXT:    [[CHUNK0:%.*]] = load i32, i32* %0, align 4
+  // CHECK-NEXT:    [[FINISHED0:%.*]] = icmp ule i32 [[WIDTH]], 33
+  // CHECK-NEXT:    br i1 [[FINISHED0]], label %[[FINISH0:[a-z.]+]], label %[[NEXT0:[a-z.]+]]
+  // CHECK:       [[FINISH0]]:
+  // CHECK-NEXT:    [[RESULT0:%.*]] = zext i32 [[CHUNK0]] to i64
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[NEXT0]]:
+  // CHECK-NEXT:    [[CHUNKADDR1:%.*]] = getelementptr inbounds i32, i32* %0, i32 1
+  // CHECK-NEXT:    [[CHUNK1:%.*]] = load i32, i32* [[CHUNKADDR1]], align 4
+  // CHECK-NEXT:    [[EXTEND1:%.*]] = zext i32 [[CHUNK0]] to i64
+  // CHECK-NEXT:    [[CHUNK1EXT:%.*]] = zext i32 [[CHUNK1]] to i64
+  // CHECK-NEXT:    [[CHUNK1SHIFT:%.*]] = shl i64 [[CHUNK1EXT]], 32
+  // CHECK-NEXT:    [[RESULT1:%.*]] = add i64 [[EXTEND1]], [[CHUNK1SHIFT]]
+  // CHECK-NEXT:    br label %[[DONE]]
+  // CHECK:       [[DONE]]:
+  // CHECK-NEXT:    [[RESULT:%.*]] = phi i64 [ 0, %[[INVALID]] ], [ [[RESULT0]], %[[FINISH0]] ], [ [[RESULT1]], %[[NEXT0]] ]
+  // CHECK-NEXT:    [[OVERFLOW:%.*]] = phi i1 [ true, %[[INVALID]] ], [ false, %[[FINISH0]] ], [ false, %[[NEXT0]] ]
+
+  %tuple = builtin "s_to_u_checked_trunc_IntLiteral_Int64"(%0 : $Builtin.IntLiteral) : $(Builtin.Int64, Builtin.Int1)
+  return %tuple : $(Builtin.Int64, Builtin.Int1)
+}
+
+
+
+/***************************************************************************/
+/* itofp_with_overflow tests                                               */
+/***************************************************************************/
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc half @sitofp16
+sil @sitofp16 : $(Builtin.IntLiteral) -> Builtin.FPIEEE16 {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:      [[T0:%.*]] = call swiftcc float @swift_intToFloat32(i32* %0, i32 %1)
+  // CHECK-NEXT: [[T1:%.*]] = fptrunc float [[T0]] to half
+  // CHECK-NEXT: ret half [[T1]]
+  %result = builtin "itofp_with_overflow_IntLiteral_FPIEEE16"(%0 : $Builtin.IntLiteral) : $Builtin.FPIEEE16
+  return %result : $Builtin.FPIEEE16
+}
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc float @sitofp32
+sil @sitofp32 : $(Builtin.IntLiteral) -> Builtin.FPIEEE32 {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:      [[T0:%.*]] = call swiftcc float @swift_intToFloat32(i32* %0, i32 %1)
+  // CHECK-NEXT: ret float [[T0]]
+  %result = builtin "itofp_with_overflow_IntLiteral_FPIEEE32"(%0 : $Builtin.IntLiteral) : $Builtin.FPIEEE32
+  return %result : $Builtin.FPIEEE32
+}
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc double @sitofp64
+sil @sitofp64 : $(Builtin.IntLiteral) -> Builtin.FPIEEE64 {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:      [[T0:%.*]] = call swiftcc double @swift_intToFloat64(i32* %0, i32 %1)
+  // CHECK-NEXT: ret double [[T0]]
+  %result = builtin "itofp_with_overflow_IntLiteral_FPIEEE64"(%0 : $Builtin.IntLiteral) : $Builtin.FPIEEE64
+  return %result : $Builtin.FPIEEE64
+}
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc x86_fp80 @sitofp80
+sil @sitofp80 : $(Builtin.IntLiteral) -> Builtin.FPIEEE80 {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:      [[T0:%.*]] = call swiftcc double @swift_intToFloat64(i32* %0, i32 %1)
+  // CHECK-NEXT: [[T1:%.*]] = fpext double [[T0]] to x86_fp80
+  // CHECK-NEXT: ret x86_fp80 [[T1]]
+  %result = builtin "itofp_with_overflow_IntLiteral_FPIEEE80"(%0 : $Builtin.IntLiteral) : $Builtin.FPIEEE80
+  return %result : $Builtin.FPIEEE80
+}
+
+// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc fp128 @sitofp128
+sil @sitofp128 : $(Builtin.IntLiteral) -> Builtin.FPIEEE128 {
+entry(%0 : @trivial $Builtin.IntLiteral):
+  // CHECK:      [[T0:%.*]] = call swiftcc double @swift_intToFloat64(i32* %0, i32 %1)
+  // CHECK-NEXT: [[T1:%.*]] = fpext double [[T0]] to fp128
+  // CHECK-NEXT: ret fp128 [[T1]]
+  %result = builtin "itofp_with_overflow_IntLiteral_FPIEEE128"(%0 : $Builtin.IntLiteral) : $Builtin.FPIEEE128
+  return %result : $Builtin.FPIEEE128
+}
diff --git a/test/IRGen/weak_import_native.swift b/test/IRGen/weak_import_native.swift
index 25301f7..361c842 100644
--- a/test/IRGen/weak_import_native.swift
+++ b/test/IRGen/weak_import_native.swift
@@ -5,6 +5,12 @@
 
 import weak_import_native_helper
 
+// CHECK-DAG: @"$s25weak_import_native_helper23ProtocolWithWeakMembersP1TAC_AA05OtherE0Tn" = extern_weak global %swift.protocol_requirement
+// CHECK-DAG: @"$s1T25weak_import_native_helper23ProtocolWithWeakMembersPTl" = extern_weak global %swift.protocol_requirement
+// CHECK-DAG: @"$s25weak_import_native_helper23ProtocolWithWeakMembersP1fyyFTq" = extern_weak global %swift.method_descriptor
+// CHECK-DAG: declare extern_weak swiftcc void @"$s25weak_import_native_helper23ProtocolWithWeakMembersPAAE1fyyF"(%swift.type*, i8**, %swift.opaque* noalias nocapture swiftself)
+struct ConformsToProtocolWithWeakMembers : ProtocolWithWeakMembers {}
+
 func testTopLevel() {
   // CHECK-DAG: declare extern_weak {{.+}} @"$s25weak_import_native_helper2fnyyF"()
   fn()
@@ -52,10 +58,16 @@
 }
 
 func testEnum() {
-  // FIXME: We're still referencing tags directly.
+  // CHECK-DAG: @"$s25weak_import_native_helper1EO6strongyA2CmFWC" = external constant i32
   _ = E.strong
+
+  // CHECK-DAG: @"$s25weak_import_native_helper1EO0A0yA2CmFWC" = extern_weak constant i32
   _ = E.weak
+
+  // CHECK-DAG: @"$s25weak_import_native_helper1EO11strongAssocyACSicACmFWC" = external constant i32
   _ = E.strongAssoc(0)
+
+  // CHECK-DAG: @"$s25weak_import_native_helper1EO0A5AssocyACSicACmFWC" = extern_weak constant i32
   _ = E.weakAssoc(0)
 }
 
@@ -66,25 +78,23 @@
   // CHECK-DAG: declare extern_weak {{.+}} @"$s25weak_import_native_helper1CC2fnyyFTj"
   c.fn()
 
-  // FIXME: vtable dispatch functions for accessors should also be weak
-
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1CC10storedPropSivgTj"
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1CC10storedPropSivsTj"
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1CC10storedPropSivMTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1CC10storedPropSivgTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1CC10storedPropSivsTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1CC10storedPropSivMTj"
   let x = c.storedProp
   c.storedProp = x
   c.storedProp += 1
 
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1CC12computedPropSivgTj"
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1CC12computedPropSivsTj"
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1CC12computedPropSivMTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1CC12computedPropSivgTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1CC12computedPropSivsTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1CC12computedPropSivMTj"
   let y = c.computedProp
   c.computedProp = y
   c.computedProp += 1
 
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1CCyS2icigTj"
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1CCyS2icisTj"
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1CCyS2iciMTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1CCyS2icigTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1CCyS2icisTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1CCyS2iciMTj"
   let z = c[0]
   c[0] = z
   c[0] += 1
@@ -104,18 +114,16 @@
   // CHECK-DAG: declare extern_weak {{.+}} @"$s25weak_import_native_helper1PP2fnyyFTj"
   p.fn()
 
-  // FIXME: witness table dispatch functions for accessors should also be weak
-
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1PP4propSivgTj"
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1PP4propSivsTj"
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1PP4propSivMTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1PP4propSivgTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1PP4propSivsTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1PP4propSivMTj"
   let x = p.prop
   mutP.prop = x
   mutP.prop += 1
 
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1PPyS2icigTj"
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1PPyS2icisTj"
-  // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper1PPyS2iciMTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1PPyS2icigTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1PPyS2icisTj"
+  // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper1PPyS2iciMTj"
   let z = p[0]
   mutP[0] = z
   mutP[0] += 1
@@ -137,27 +145,24 @@
 }
 
 func testWeakTypes() -> [Any.Type] {
-  // FIXME: These should be weak.
-  // CHECK-DAG: declare swiftcc %swift.metadata_response @"$s25weak_import_native_helper5WeakSVMa"
-  // CHECK-DAG: declare swiftcc %swift.metadata_response @"$s25weak_import_native_helper5WeakEOMa"
-  // CHECK-DAG: declare swiftcc %swift.metadata_response @"$s25weak_import_native_helper5WeakCCMa"
+  // CHECK-DAG: declare extern_weak swiftcc %swift.metadata_response @"$s25weak_import_native_helper5WeakSVMa"
+  // CHECK-DAG: declare extern_weak swiftcc %swift.metadata_response @"$s25weak_import_native_helper5WeakEOMa"
+  // CHECK-DAG: declare extern_weak swiftcc %swift.metadata_response @"$s25weak_import_native_helper5WeakCCMa"
   // CHECK-DAG: @"$s25weak_import_native_helper5WeakPMp" = extern_weak global %swift.protocol
-  // CHECK-DAG: declare swiftcc %swift.metadata_response @"$s25weak_import_native_helper8GenericSVMa"
-  // CHECK-DAG: declare swiftcc %swift.metadata_response @"$s25weak_import_native_helper8GenericEOMa"
-  // CHECK-DAG: declare swiftcc %swift.metadata_response @"$s25weak_import_native_helper8GenericCCMa"
+  // CHECK-DAG: declare extern_weak swiftcc %swift.metadata_response @"$s25weak_import_native_helper8GenericSVMa"
+  // CHECK-DAG: declare extern_weak swiftcc %swift.metadata_response @"$s25weak_import_native_helper8GenericEOMa"
+  // CHECK-DAG: declare extern_weak swiftcc %swift.metadata_response @"$s25weak_import_native_helper8GenericCCMa"
   return [WeakS.self, WeakE.self, WeakC.self, WeakP.self, GenericS<Int>.self, GenericE<Int>.self, GenericC<Int>.self]
 }
 
 class WeakSub: WeakC {
   deinit {
-    // FIXME: This should be weak.
-    // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper5WeakCCfd"
+    // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper5WeakCCfd"
   }
 }
 
 class WeakGenericSub: GenericC<Int> {
   deinit {
-    // FIXME: This should be weak.
-    // CHECK-DAG: declare swiftcc {{.+}} @"$s25weak_import_native_helper8GenericCCfd"
+    // CHECK-DAG: declare extern_weak swiftcc {{.+}} @"$s25weak_import_native_helper8GenericCCfd"
   }
 }
diff --git a/test/ParseableInterface/DefaultArgs.swiftinterface b/test/ParseableInterface/DefaultArgs.swiftinterface
index 8fe8131..8cf428a 100644
--- a/test/ParseableInterface/DefaultArgs.swiftinterface
+++ b/test/ParseableInterface/DefaultArgs.swiftinterface
@@ -8,18 +8,18 @@
   public func hasDefaults(a: Int = 4, b: Int = 1 + 2)
 
   // CHECK-LABEL: sil hidden @$s11DefaultArgs9SomeClassC11hasDefaults1a1bySi_SitFfA_
-  // CHECK: integer_literal $Builtin.Int2048, 4
+  // CHECK: integer_literal $Builtin.IntLiteral, 4
   // CHECK: end sil function '$s11DefaultArgs9SomeClassC11hasDefaults1a1bySi_SitFfA_'
 
   // CHECK-LABEL: sil hidden @$s11DefaultArgs9SomeClassC11hasDefaults1a1bySi_SitFfA0_
-  // CHECK: integer_literal $Builtin.Int2048, 1
-  // CHECK: integer_literal $Builtin.Int2048, 2
+  // CHECK: integer_literal $Builtin.IntLiteral, 1
+  // CHECK: integer_literal $Builtin.IntLiteral, 2
   // CHECK: function_ref @$sSi1poiyS2i_SitFZ
   // CHECK: end sil function '$s11DefaultArgs9SomeClassC11hasDefaults1a1bySi_SitFfA0_'
 
   public init(a: Int = 5)
 
   // CHECK-LABEL: sil hidden @$s11DefaultArgs9SomeClassC1aACSi_tcfcfA_
-  // CHECK: integer_literal $Builtin.Int2048, 5
+  // CHECK: integer_literal $Builtin.IntLiteral, 5
   // CHECK: end sil function '$s11DefaultArgs9SomeClassC1aACSi_tcfcfA_'
 }
diff --git a/test/ParseableInterface/option-preservation.swift b/test/ParseableInterface/option-preservation.swift
index ea727fa..9f217eb 100644
--- a/test/ParseableInterface/option-preservation.swift
+++ b/test/ParseableInterface/option-preservation.swift
@@ -1,6 +1,18 @@
+// RUN: %empty-directory(%t)
+
 // RUN: %target-swift-frontend -enable-resilience -emit-parseable-module-interface-path %t.swiftinterface -module-name t %s -emit-module -o /dev/null
 // RUN: %FileCheck %s < %t.swiftinterface -check-prefix=CHECK-SWIFTINTERFACE
 //
 // CHECK-SWIFTINTERFACE: {{swift-module-flags:.* -enable-resilience}}
 
+// Make sure flags show up when filelists are enabled
+
+// RUN: %target-build-swift %s -driver-filelist-threshold=0 -emit-parseable-module-interface -o %t/foo -module-name foo -module-link-name fooCore -force-single-frontend-invocation 2>&1
+// RUN: %FileCheck %s < %t/foo.swiftinterface --check-prefix CHECK-FILELIST-INTERFACE
+
+// CHECK-FILELIST-INTERFACE: swift-module-flags:
+// CHECK-FILELIST-INTERFACE-SAME: -target
+// CHECK-FILELIST-INTERFACE-SAME: -module-link-name fooCore
+// CHECK-FILELIST-INTERFACE-SAME: -module-name foo
+
 public func foo() { }
diff --git a/test/Prototypes/DoubleWidth.swift.gyb b/test/Prototypes/DoubleWidth.swift.gyb
index fff9183..10c90f2 100644
--- a/test/Prototypes/DoubleWidth.swift.gyb
+++ b/test/Prototypes/DoubleWidth.swift.gyb
@@ -177,38 +177,38 @@
 // This conformance is only possible once the type is in the stdlib, as it uses
 // Builtin
 extension DoubleWidth: _ExpressibleByBuiltinIntegerLiteral {
-  public init(_builtinIntegerLiteral _x: _MaxBuiltinIntegerType) {
+  public init(_builtinIntegerLiteral _x: Builtin.IntegerLiteral) {
     var _x = _x
     self = DoubleWidth()
 
     // If we can capture the entire literal in a single Int64, stop there.
     // This avoids some potential deep recursion due to literal expressions in
     // other DoubleWidth methods.
-    let (_value, _overflow) = Builtin.s_to_s_checked_trunc_Int2048_Int64(_x)
+    let (_value, _overflow) = Builtin.s_to_s_checked_trunc_IntLiteral_Int64(_x)
     if !Bool(_overflow) {
       self = DoubleWidth(Int64(_value))
       return
     }
 
     // Convert all but the most significant 64 bits as unsigned integers.
-    let _shift = Builtin.sext_Int64_Int2048((64 as Int64)._value)
+    let _shift = Builtin.sext_Int64_IntLiteral((64 as Int64)._value)
     let lowWordCount = (bitWidth - 1) / 64
     for i in 0..<lowWordCount {
       let value =
-        DoubleWidth(UInt64(Builtin.s_to_u_checked_trunc_Int2048_Int64(_x).0))
+        DoubleWidth(UInt64(Builtin.s_to_u_checked_trunc_IntLiteral_Int64(_x).0))
           &<< DoubleWidth(i * 64)
       self |= value
-      _x = Builtin.ashr_Int2048(_x, _shift)
+      _x = Builtin.ashr_IntLiteral(_x, _shift)
     }
 
     // Finally, convert the most significant 64 bits and check for overflow.
     let overflow: Bool
     if Base.isSigned {
-      let (_value, _overflow) = Builtin.s_to_s_checked_trunc_Int2048_Int64(_x)
+      let (_value, _overflow) = Builtin.s_to_s_checked_trunc_IntLiteral_Int64(_x)
       self |= DoubleWidth(Int64(_value)) &<< DoubleWidth(lowWordCount * 64)
       overflow = Bool(_overflow)
     } else {
-      let (_value, _overflow) = Builtin.s_to_u_checked_trunc_Int2048_Int64(_x)
+      let (_value, _overflow) = Builtin.s_to_u_checked_trunc_IntLiteral_Int64(_x)
       self |= DoubleWidth(UInt64(_value)) &<< DoubleWidth(lowWordCount * 64)
       overflow = Bool(_overflow)
     }
diff --git a/test/Runtime/demangleToMetadataObjC.swift b/test/Runtime/demangleToMetadataObjC.swift
index 133dd49..a18bd5f 100644
--- a/test/Runtime/demangleToMetadataObjC.swift
+++ b/test/Runtime/demangleToMetadataObjC.swift
@@ -14,6 +14,7 @@
 @objc enum E: Int { case a }
 @objc protocol P1 { }
 protocol P2 { }
+@objc protocol P3: P1 { }
 
 DemangleToMetadataTests.test("@objc classes") {
   expectEqual(type(of: C()), _typeByMangledName("4main1CC")!)
@@ -96,5 +97,11 @@
     _typeByMangledName("ShySo18CFMutableStringRefaG")!)
 }
 
+class F<T: P1> { }
+
+DemangleToMetadataTests.test("runtime conformance check for @objc protocol inheritance") {
+  expectEqual(F<P3>.self, _typeByMangledName("4main1FCyAA2P3PG")!)
+}
+
 runAllTests()
 
diff --git a/test/SIL/Parser/SILDeclRef.sil b/test/SIL/Parser/SILDeclRef.sil
index f4d5ee1..3139aa4 100644
--- a/test/SIL/Parser/SILDeclRef.sil
+++ b/test/SIL/Parser/SILDeclRef.sil
@@ -48,8 +48,8 @@
 // P.boo() -> Int32
 sil @_TFE10SILDeclRefPS_1P3boofT_Vs5Int32 : $@convention(method) <Self where Self : P> (@in_guaranteed Self) -> Int32
 
-// Int32.init(_builtinIntegerLiteral : Builtin.Int2048) -> Int32
-sil public_external [transparent] [serialized] @_TFVs5Int32CfT22_builtinIntegerLiteralBi2048__S_ : $@convention(method) (Builtin.Int2048, @thin Int32.Type) -> Int32
+// Int32.init(_builtinIntegerLiteral : Builtin.IntLiteral) -> Int32
+sil public_external [transparent] [serialized] @_TFVs5Int32CfT22_builtinIntegerLiteralBI__S_ : $@convention(method) (Builtin.IntLiteral, @thin Int32.Type) -> Int32
 
 // Base.foo() -> Int32
 sil @_TFC10SILDeclRef4Base3foofT_Vs5Int32 : $@convention(method) (@guaranteed Base) -> Int32
diff --git a/test/SILGen/Inputs/switch_bool.h b/test/SILGen/Inputs/switch_bool.h
new file mode 100644
index 0000000..b059b86
--- /dev/null
+++ b/test/SILGen/Inputs/switch_bool.h
@@ -0,0 +1,8 @@
+
+@import Foundation;
+
+typedef NSString * MyStringEnum NS_EXTENSIBLE_STRING_ENUM;
+extern MyStringEnum const MyStringEnumCase1;
+extern MyStringEnum const MyStringEnumCase2;
+extern MyStringEnum const MyStringEnumCase3;
+extern MyStringEnum const MyStringEnumCase4;
diff --git a/test/SILGen/auto_generated_super_init_call.swift b/test/SILGen/auto_generated_super_init_call.swift
index 34a21a0..237da70 100644
--- a/test/SILGen/auto_generated_super_init_call.swift
+++ b/test/SILGen/auto_generated_super_init_call.swift
@@ -13,7 +13,7 @@
   override init() {
     y = 42
 // CHECK-LABEL: sil hidden @$s30auto_generated_super_init_call16SomeDerivedClassC{{[_0-9a-zA-Z]*}}fc : $@convention(method) (@owned SomeDerivedClass) -> @owned SomeDerivedClass
-// CHECK: integer_literal $Builtin.Int2048, 42
+// CHECK: integer_literal $Builtin.IntLiteral, 42
 // CHECK: [[SELFLOAD:%[0-9]+]] = load [take] [[SELF:%[0-9]+]] : $*SomeDerivedClass
 // CHECK-NEXT: [[PARENT:%[0-9]+]] = upcast [[SELFLOAD]] : $SomeDerivedClass to $Parent
 // CHECK-NEXT: // function_ref
diff --git a/test/SILGen/default_arguments.swift b/test/SILGen/default_arguments.swift
index ddbb812..0912191 100644
--- a/test/SILGen/default_arguments.swift
+++ b/test/SILGen/default_arguments.swift
@@ -9,9 +9,9 @@
 // Default argument for first parameter.
 // CHECK-LABEL: sil hidden @$s17default_arguments7defarg11i1d1sySi_SdSStFfA_ : $@convention(thin) () -> Int
 // CHECK: [[INT:%[0-9]+]] = metatype $@thin Int.Type
-// CHECK: [[LIT:%[0-9]+]] = integer_literal $Builtin.Int2048, 17
-// CHECK: [[CVT:%[0-9]+]] = function_ref @$sSi22_builtinIntegerLiteralSiBi{{[_0-9]*}}__tcfC
-// CHECK: [[RESULT:%[0-9]+]] = apply [[CVT]]([[LIT]], [[INT]]) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
+// CHECK: [[LIT:%[0-9]+]] = integer_literal $Builtin.IntLiteral, 17
+// CHECK: [[CVT:%[0-9]+]] = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC
+// CHECK: [[RESULT:%[0-9]+]] = apply [[CVT]]([[LIT]], [[INT]]) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
 // CHECK: return [[RESULT]] : $Int
 
 // Default argument for third parameter.
@@ -44,9 +44,9 @@
 // CHECK-LABEL: sil hidden @$s17default_arguments15testDefaultArg2{{[_0-9a-zA-Z]*}}F
 func testDefaultArg2() {
 // CHECK:  [[INT64:%[0-9]+]] = metatype $@thin Int.Type
-// CHECK:  [[INTLIT:%[0-9]+]] = integer_literal $Builtin.Int2048, 5
-// CHECK:  [[LITFN:%[0-9]+]] = function_ref @$sSi22_builtinIntegerLiteralSiBi{{[_0-9]*}}__tcfC
-// CHECK:  [[I:%[0-9]+]] = apply [[LITFN]]([[INTLIT]], [[INT64]]) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
+// CHECK:  [[INTLIT:%[0-9]+]] = integer_literal $Builtin.IntLiteral, 5
+// CHECK:  [[LITFN:%[0-9]+]] = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC
+// CHECK:  [[I:%[0-9]+]] = apply [[LITFN]]([[INTLIT]], [[INT64]]) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
 // CHECK:  [[DFN:%[0-9]+]] = function_ref @$s17default_arguments7defarg2{{.*}}A0_ : $@convention(thin) () -> Double
 // CHECK:  [[D:%[0-9]+]] = apply [[DFN]]() : $@convention(thin) () -> Double
 // CHECK:  [[SFN:%[0-9]+]] = function_ref @$s17default_arguments7defarg2{{.*}}A1_ : $@convention(thin) () -> @owned String
@@ -64,7 +64,7 @@
   // CHECK: string_literal utf16{{.*}}default_arguments.swift
 
   // CHECK-LABEL: sil private [transparent] @$s17default_arguments17testAutocloseFileyyFSiyXKfu0_ : $@convention(thin) () -> Int
-  // CHECK: integer_literal $Builtin.Int2048, [[@LINE+1]]
+  // CHECK: integer_literal $Builtin.IntLiteral, [[@LINE+1]]
   autocloseFile()
 }
 
@@ -249,10 +249,10 @@
 func r18400194(_ a: Int, x: Int = 97) {}
 
 // CHECK-LABEL: sil hidden @$s17default_arguments9r18400194_1xySi_SitFfA0_
-// CHECK: integer_literal $Builtin.Int2048, 97
+// CHECK: integer_literal $Builtin.IntLiteral, 97
 
 // CHECK-LABEL: sil hidden @$s17default_arguments14test_r18400194yyF
-// CHECK: integer_literal $Builtin.Int2048, 1
+// CHECK: integer_literal $Builtin.IntLiteral, 1
 // CHECK:  function_ref @$s17default_arguments9r18400194_1xySi_SitFfA0_ : $@convention(thin) () -> Int
 // CHECK: function_ref @$s17default_arguments9r18400194_1xySi_SitF : $@convention(thin) (Int, Int) -> (){{.*}}
 func test_r18400194() {
diff --git a/test/SILGen/default_constructor.swift b/test/SILGen/default_constructor.swift
index cf54506..dc5f1d9 100644
--- a/test/SILGen/default_constructor.swift
+++ b/test/SILGen/default_constructor.swift
@@ -16,9 +16,9 @@
 
 // CHECK-LABEL: sil hidden [transparent] @$s19default_constructor1DV1iSivpfi : $@convention(thin) () -> (Int, Double)
 // CHECK:      [[METATYPE:%.*]] = metatype $@thin Int.Type
-// CHECK-NEXT: [[VALUE:%.*]] = integer_literal $Builtin.Int2048, 2
-// CHECK:      [[FN:%.*]] = function_ref @$sSi22_builtinIntegerLiteralSiBi2048__tcfC : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
-// CHECK-NEXT: [[LEFT:%.*]] = apply [[FN]]([[VALUE]], [[METATYPE]]) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
+// CHECK-NEXT: [[VALUE:%.*]] = integer_literal $Builtin.IntLiteral, 2
+// CHECK:      [[FN:%.*]] = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
+// CHECK-NEXT: [[LEFT:%.*]] = apply [[FN]]([[VALUE]], [[METATYPE]]) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
 // CHECK-NEXT: [[METATYPE:%.*]] = metatype $@thin Double.Type
 // CHECK-NEXT: [[VALUE:%.*]] = float_literal $Builtin.FPIEEE{{64|80}}, {{0x400C000000000000|0x4000E000000000000000}}
 // CHECK:      [[FN:%.*]] = function_ref @$sSd20_builtinFloatLiteralSdBf{{64|80}}__tcfC : $@convention(method) (Builtin.FPIEEE{{64|80}}, @thin Double.Type) -> Double
diff --git a/test/SILGen/enum_resilience.swift b/test/SILGen/enum_resilience.swift
index cf5d8fe..885dadb 100644
--- a/test/SILGen/enum_resilience.swift
+++ b/test/SILGen/enum_resilience.swift
@@ -56,13 +56,13 @@
   // CHECK: switch_enum_addr %2 : $*Medium, case #Medium.Paper!enumelt: [[PAPER:[^ ]+]], case #Medium.Canvas!enumelt: [[CANVAS:[^ ]+]], default [[DEFAULT:[^ ]+]]
   switch m {
   // CHECK: [[PAPER]]:
-  // CHECK: integer_literal $Builtin.Int2048, 0
+  // CHECK: integer_literal $Builtin.IntLiteral, 0
   case .Paper: return 0
   // CHECK: [[CANVAS]]:
-  // CHECK: integer_literal $Builtin.Int2048, 1
+  // CHECK: integer_literal $Builtin.IntLiteral, 1
   case .Canvas: return 1
   // CHECK: [[DEFAULT]]:
-  // CHECK: integer_literal $Builtin.Int2048, -1
+  // CHECK: integer_literal $Builtin.IntLiteral, -1
   default: return -1
   }
 } // CHECK: end sil function '$s15enum_resilience22resilientSwitchDefaultys5Int32V0c1_A06MediumOF'
@@ -72,13 +72,13 @@
   // CHECK: switch_enum_addr %2 : $*Medium, case #Medium.Paper!enumelt: [[PAPER:[^ ]+]], case #Medium.Canvas!enumelt: [[CANVAS:[^ ]+]], default [[DEFAULT:[^ ]+]]
   switch m {
   // CHECK: [[PAPER]]:
-  // CHECK: integer_literal $Builtin.Int2048, 0
+  // CHECK: integer_literal $Builtin.IntLiteral, 0
   case .Paper: return 0
   // CHECK: [[CANVAS]]:
-  // CHECK: integer_literal $Builtin.Int2048, 1
+  // CHECK: integer_literal $Builtin.IntLiteral, 1
   case .Canvas: return 1
   // CHECK: [[DEFAULT]]:
-  // CHECK: integer_literal $Builtin.Int2048, -1
+  // CHECK: integer_literal $Builtin.IntLiteral, -1
   @unknown case _: return -1
   }
 } // CHECK: end sil function '$s15enum_resilience26resilientSwitchUnknownCaseys5Int32V0c1_A06MediumOF'
@@ -88,19 +88,19 @@
   // CHECK: switch_enum_addr %2 : $*Medium, case #Medium.Paper!enumelt: [[PAPER:[^ ]+]], case #Medium.Canvas!enumelt: [[CANVAS:[^ ]+]], case #Medium.Pamphlet!enumelt.1: [[PAMPHLET:[^ ]+]], case #Medium.Postcard!enumelt.1: [[POSTCARD:[^ ]+]], default [[DEFAULT:[^ ]+]]
   switch m {
   // CHECK: [[PAPER]]:
-  // CHECK: integer_literal $Builtin.Int2048, 0
+  // CHECK: integer_literal $Builtin.IntLiteral, 0
   case .Paper: return 0
   // CHECK: [[CANVAS]]:
-  // CHECK: integer_literal $Builtin.Int2048, 1
+  // CHECK: integer_literal $Builtin.IntLiteral, 1
   case .Canvas: return 1
   // CHECK: [[PAMPHLET]]:
-  // CHECK: integer_literal $Builtin.Int2048, 2
+  // CHECK: integer_literal $Builtin.IntLiteral, 2
   case .Pamphlet: return 2
   // CHECK: [[POSTCARD]]:
-  // CHECK: integer_literal $Builtin.Int2048, 3
+  // CHECK: integer_literal $Builtin.IntLiteral, 3
   case .Postcard: return 3
   // CHECK: [[DEFAULT]]:
-  // CHECK: integer_literal $Builtin.Int2048, -1
+  // CHECK: integer_literal $Builtin.IntLiteral, -1
   @unknown case _: return -1
   }
 }
diff --git a/test/SILGen/expressions.swift b/test/SILGen/expressions.swift
index 9634d73..a4c68da 100644
--- a/test/SILGen/expressions.swift
+++ b/test/SILGen/expressions.swift
@@ -82,7 +82,7 @@
   var e:SillyString = "foo"
 }
 // CHECK-LABEL: sil hidden @$s11expressions8literalsyyF
-// CHECK: integer_literal $Builtin.Int2048, 1
+// CHECK: integer_literal $Builtin.IntLiteral, 1
 // CHECK: float_literal $Builtin.FPIEEE{{64|80}}, {{0x3FF4000000000000|0x3FFFA000000000000000}}
 // CHECK: string_literal utf16 "foö"
 // CHECK: string_literal utf8 "foo"
@@ -506,13 +506,13 @@
   
   // This should expand to the column number of the first _.
   var tmp = #column
-  // CHECK: integer_literal $Builtin.Int2048, 13
+  // CHECK: integer_literal $Builtin.IntLiteral, 13
 
   // This should expand to the column number of the (, not to the column number
   // of #column in the default argument list of this function.
   // rdar://14315674
   magic_identifier_expansion()
-  // CHECK: integer_literal $Builtin.Int2048, 29
+  // CHECK: integer_literal $Builtin.IntLiteral, 29
 }
 
 func print_string() {
diff --git a/test/SILGen/generic_literals.swift b/test/SILGen/generic_literals.swift
index 42d1125..132fc76 100644
--- a/test/SILGen/generic_literals.swift
+++ b/test/SILGen/generic_literals.swift
@@ -7,9 +7,9 @@
   // CHECK: [[TMETA:%.*]] = metatype $@thick T.Type
   // CHECK: [[LITVAR:%.*]] = alloc_stack $T.IntegerLiteralType
   // CHECK: [[LITMETA:%.*]] = metatype $@thick T.IntegerLiteralType.Type
-  // CHECK: [[INTLIT:%.*]] = integer_literal $Builtin.Int2048, 17
+  // CHECK: [[INTLIT:%.*]] = integer_literal $Builtin.IntLiteral, 17
   // CHECK: [[BUILTINCONV:%.*]] = witness_method $T.IntegerLiteralType, #_ExpressibleByBuiltinIntegerLiteral.init!allocator.1
-  // CHECK: [[LIT:%.*]] = apply [[BUILTINCONV]]<T.IntegerLiteralType>([[LITVAR]], [[INTLIT]], [[LITMETA]]) : $@convention(witness_method: _ExpressibleByBuiltinIntegerLiteral) <τ_0_0 where τ_0_0 : _ExpressibleByBuiltinIntegerLiteral> (Builtin.Int2048, @thick τ_0_0.Type) -> @out τ_0_0
+  // CHECK: [[LIT:%.*]] = apply [[BUILTINCONV]]<T.IntegerLiteralType>([[LITVAR]], [[INTLIT]], [[LITMETA]]) : $@convention(witness_method: _ExpressibleByBuiltinIntegerLiteral) <τ_0_0 where τ_0_0 : _ExpressibleByBuiltinIntegerLiteral> (Builtin.IntLiteral, @thick τ_0_0.Type) -> @out τ_0_0
   // CHECK: [[TCONV:%.*]] = witness_method $T, #ExpressibleByIntegerLiteral.init!allocator.1
   // CHECK: apply [[TCONV]]<T>([[ADDR]], [[LITVAR]], [[TMETA]]) : $@convention(witness_method: ExpressibleByIntegerLiteral) <τ_0_0 where τ_0_0 : ExpressibleByIntegerLiteral> (@in τ_0_0.IntegerLiteralType, @thick τ_0_0.Type) -> @out τ_0_0
 
diff --git a/test/SILGen/objc_enum.swift b/test/SILGen/objc_enum.swift
index 463afa0..8277641 100644
--- a/test/SILGen/objc_enum.swift
+++ b/test/SILGen/objc_enum.swift
@@ -36,8 +36,8 @@
 
 extension NSRuncingOptions: Bub {}
 
-// CHECK-32-DAG: integer_literal $Builtin.Int2048, -2147483648
-// CHECK-64-DAG: integer_literal $Builtin.Int2048, 2147483648
+// CHECK-32-DAG: integer_literal $Builtin.IntLiteral, -2147483648
+// CHECK-64-DAG: integer_literal $Builtin.IntLiteral, 2147483648
 _ = NSFungingMask.toTheMax
 
 // CHECK-DAG: sil_witness_table shared [serialized] NSRuncingOptions: RawRepresentable module gizmo
diff --git a/test/SILGen/opaque_ownership.swift b/test/SILGen/opaque_ownership.swift
index a32b71e..32fc8a6 100644
--- a/test/SILGen/opaque_ownership.swift
+++ b/test/SILGen/opaque_ownership.swift
@@ -111,7 +111,7 @@
   return lhs.rawValue == rhs.rawValue
 }
 
-public typealias _MaxBuiltinIntegerType = Builtin.Int2048
+public typealias _MaxBuiltinIntegerType = Builtin.IntLiteral
 
 public protocol _ExpressibleByBuiltinIntegerLiteral {
   init(_builtinIntegerLiteral value: _MaxBuiltinIntegerType)
@@ -139,7 +139,7 @@
 public struct Int64 : ExpressibleByIntegerLiteral, _ExpressibleByBuiltinIntegerLiteral, Equatable {
   public var _value: Builtin.Int64
   public init(_builtinIntegerLiteral x: _MaxBuiltinIntegerType) {
-    _value = Builtin.s_to_s_checked_trunc_Int2048_Int64(x).0
+    _value = Builtin.s_to_s_checked_trunc_IntLiteral_Int64(x).0
   }
   public typealias IntegerLiteralType = Int64
   public init(integerLiteral value: Int64) {
diff --git a/test/SILGen/opaque_values_silgen.swift b/test/SILGen/opaque_values_silgen.swift
index 7cb86ba..2383d82 100644
--- a/test/SILGen/opaque_values_silgen.swift
+++ b/test/SILGen/opaque_values_silgen.swift
@@ -378,8 +378,8 @@
 // CHECK-LABEL: sil hidden @$s20opaque_values_silgen21s160_______callAnyArgyyF : $@convention(thin) () -> () {
 // CHECK: bb0:
 // CHECK:   [[INT_TYPE:%.*]] = metatype $@thin Int.Type
-// CHECK:   [[INT_LIT:%.*]] = integer_literal $Builtin.Int2048, 42
-// CHECK:   [[INT_ARG:%.*]] = apply %{{.*}}([[INT_LIT]], [[INT_TYPE]]) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
+// CHECK:   [[INT_LIT:%.*]] = integer_literal $Builtin.IntLiteral, 42
+// CHECK:   [[INT_ARG:%.*]] = apply %{{.*}}([[INT_LIT]], [[INT_TYPE]]) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
 // CHECK:   [[INIT_OPAQUE:%.*]] = init_existential_value [[INT_ARG]] : $Int, $Int, $Any
 // CHECK:   apply %{{.*}}([[INIT_OPAQUE]]) : $@convention(thin) (@in_guaranteed Any) -> ()
 // CHECK:   return %{{.*}} : $()
@@ -394,8 +394,8 @@
 // CHECK: bb0:
 // CHECK-NOT: alloc_stack
 // CHECK:   [[INT_TYPE:%.*]] = metatype $@thin Int.Type
-// CHECK:   [[INT_LIT:%.*]] = integer_literal $Builtin.Int2048, 42
-// CHECK:   [[INT_ARG:%.*]] = apply %{{.*}}([[INT_LIT]], [[INT_TYPE]]) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
+// CHECK:   [[INT_LIT:%.*]] = integer_literal $Builtin.IntLiteral, 42
+// CHECK:   [[INT_ARG:%.*]] = apply %{{.*}}([[INT_LIT]], [[INT_TYPE]]) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
 // CHECK:   [[INT_CAST:%.*]] = unconditional_checked_cast_value [[INT_ARG]] : $Int to $T
 // CHECK:   [[CAST_BORROW:%.*]] = begin_borrow [[INT_CAST]] : $T
 // CHECK:   [[RETURN_VAL:%.*]] = copy_value [[CAST_BORROW]] : $T
@@ -412,8 +412,8 @@
 // ---
 // CHECK-LABEL: sil hidden @$s20opaque_values_silgen21s180_______return_fooAA3Foo_pyF : $@convention(thin) () -> @out Foo {
 // CHECK: bb0:
-// CHECK:   [[INT_LIT:%.*]] = integer_literal $Builtin.Int2048, 42
-// CHECK:   [[INT_ARG:%.*]] = apply %{{.*}}([[INT_LIT]], [[INT_TYPE]]) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
+// CHECK:   [[INT_LIT:%.*]] = integer_literal $Builtin.IntLiteral, 42
+// CHECK:   [[INT_ARG:%.*]] = apply %{{.*}}([[INT_LIT]], [[INT_TYPE]]) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
 // CHECK:   [[INT_CAST:%.*]] = unconditional_checked_cast_value [[INT_ARG]] : $Int to $Foo
 // CHECK:   return [[INT_CAST]] : $Foo
 // CHECK-LABEL: } // end sil function '$s20opaque_values_silgen21s180_______return_fooAA3Foo_pyF'
@@ -531,8 +531,8 @@
 // CHECK: bb0:
 // CHECK:   [[BOX_MTYPE:%.*]] = metatype $@thin Box<Int>.Type
 // CHECK:   [[MTYPE:%.*]] = metatype $@thin Int.Type
-// CHECK:   [[INTLIT:%.*]] = integer_literal $Builtin.Int2048, 42
-// CHECK:   [[AINT:%.*]] = apply {{.*}}([[INTLIT]], [[MTYPE]]) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
+// CHECK:   [[INTLIT:%.*]] = integer_literal $Builtin.IntLiteral, 42
+// CHECK:   [[AINT:%.*]] = apply {{.*}}([[INTLIT]], [[MTYPE]]) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
 // CHECK:   apply {{.*}}<Int>([[AINT]], [[BOX_MTYPE]]) : $@convention(method) <τ_0_0> (@in τ_0_0, @thin Box<τ_0_0>.Type) -> @out Box<τ_0_0>
 // CHECK:   return %{{.*}} : $()
 // CHECK-LABEL: } // end sil function '$s20opaque_values_silgen21s250_________testBoxTyyF'
diff --git a/test/SILGen/protocol_optional.swift b/test/SILGen/protocol_optional.swift
index 3c6d3ad..647bd7d 100644
--- a/test/SILGen/protocol_optional.swift
+++ b/test/SILGen/protocol_optional.swift
@@ -58,9 +58,9 @@
   // CHECK:   [[READ:%.*]] = begin_access [read] [unknown] [[PT]] : $*T
   // CHECK:   [[T:%[0-9]+]] = load [copy] [[READ]] : $*T
   // CHECK:   [[INT64:%[0-9]+]] = metatype $@thin Int.Type
-  // CHECK:   [[FIVELIT:%[0-9]+]] = integer_literal $Builtin.Int2048, 5
+  // CHECK:   [[FIVELIT:%[0-9]+]] = integer_literal $Builtin.IntLiteral, 5
   // CHECK:   [[INTCONV:%[0-9]+]] = function_ref @$sSi2{{[_0-9a-zA-Z]*}}fC
-  // CHECK:   [[FIVE:%[0-9]+]] = apply [[INTCONV]]([[FIVELIT]], [[INT64]]) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
+  // CHECK:   [[FIVE:%[0-9]+]] = apply [[INTCONV]]([[FIVELIT]], [[INT64]]) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
   // CHECK:   alloc_stack $Optional<Int>
   // CHECK:   dynamic_method_br [[T]] : $T, #P1.subscript!getter.1.foreign
   var subscriptRef = t[5]
diff --git a/test/SILGen/sil_locations.swift b/test/SILGen/sil_locations.swift
index cad8643..9874137 100644
--- a/test/SILGen/sil_locations.swift
+++ b/test/SILGen/sil_locations.swift
@@ -132,13 +132,13 @@
   switch (switchfoo(), switchbar()) {
   // CHECK: store {{.*}}, loc "{{.*}}":[[@LINE-1]]
   case (1,2):
-  // CHECK: integer_literal $Builtin.Int2048, 2, loc "{{.*}}":[[@LINE-3]]:10
+  // CHECK: integer_literal $Builtin.IntLiteral, 2, loc "{{.*}}":[[@LINE-3]]:10
   // FIXME: Location info is missing.
   // CHECK: cond_br
   //
     var z: Int = 200
   // CHECK: [[VAR_Z:%[0-9]+]] = alloc_box ${ var Int }, var, name "z"{{.*}}line:[[@LINE-1]]:9
-  // CHECK: integer_literal $Builtin.Int2048, 200, loc "{{.*}}":[[@LINE-2]]:18
+  // CHECK: integer_literal $Builtin.IntLiteral, 200, loc "{{.*}}":[[@LINE-2]]:18
     x = z
   // CHECK:  destroy_value [[VAR_Z]]{{.*}}, loc "{{.*}}":[[@LINE-1]]:9, {{.*}}:cleanup
   case (3, let y):
@@ -178,7 +178,7 @@
 
   // CHECK-LABEL: sil hidden @$s13sil_locations7testForyyF
   // CHECK: [[VAR_Y_IN_FOR:%[0-9]+]]  = alloc_box ${ var Int }, var, name "y", loc "{{.*}}":[[@LINE-10]]:9
-  // CHECK: integer_literal $Builtin.Int2048, 300, loc "{{.*}}":[[@LINE-11]]:18
+  // CHECK: integer_literal $Builtin.IntLiteral, 300, loc "{{.*}}":[[@LINE-11]]:18
   // CHECK: destroy_value [[VAR_Y_IN_FOR]] : ${ var Int }
   // CHECK: br bb{{.*}}, loc "{{.*}}":[[@LINE-10]]:7
   // CHECK: destroy_value [[VAR_Y_IN_FOR]] : ${ var Int }
@@ -193,8 +193,8 @@
   var d = "foo"
   // CHECK-LABEL: sil hidden @$s13sil_locations10testTuplesyyF
   // CHECK: tuple_element_addr {{.*}}, loc "{{.*}}":[[@LINE-4]]:11
-  // CHECK: integer_literal $Builtin.Int2048, 2, loc "{{.*}}":[[@LINE-5]]:12
-  // CHECK: integer_literal $Builtin.Int2048, 3, loc "{{.*}}":[[@LINE-6]]:14
+  // CHECK: integer_literal $Builtin.IntLiteral, 2, loc "{{.*}}":[[@LINE-5]]:12
+  // CHECK: integer_literal $Builtin.IntLiteral, 3, loc "{{.*}}":[[@LINE-6]]:14
   // CHECK: tuple_element_addr {{.*}}, loc "{{.*}}":[[@LINE-6]]:12
   // CHECK: tuple_element_addr {{.*}}, loc "{{.*}}":[[@LINE-7]]:16  
 }
@@ -245,8 +245,8 @@
   
   // CHECK: string_literal utf8 "Ankeny", loc "{{.*}}":[[@LINE-4]]:23
 
-  // CHECK: integer_literal $Builtin.Int2048, 1, loc "{{.*}}":[[@LINE-6]]:33
-  // CHECK: integer_literal $Builtin.Int2048, 2, loc "{{.*}}":[[@LINE-7]]:48
+  // CHECK: integer_literal $Builtin.IntLiteral, 1, loc "{{.*}}":[[@LINE-6]]:33
+  // CHECK: integer_literal $Builtin.IntLiteral, 2, loc "{{.*}}":[[@LINE-7]]:48
 
   
   
diff --git a/test/SILGen/source_location.swift b/test/SILGen/source_location.swift
index d0f5eea..b98a52d 100644
--- a/test/SILGen/source_location.swift
+++ b/test/SILGen/source_location.swift
@@ -7,7 +7,7 @@
 _ = printSourceLocation()
 // CHECK: [[CALLER_FILE_VAL:%.*]] = string_literal utf16 "caller.swift",
 // CHECK: [[CALLER_FILE:%.*]] = apply {{.*}}([[CALLER_FILE_VAL]],
-// CHECK: [[CALLER_LINE_VAL:%.*]] = integer_literal $Builtin.Int{{[0-9]+}}, 10000,
+// CHECK: [[CALLER_LINE_VAL:%.*]] = integer_literal $Builtin.IntLiteral, 10000,
 // CHECK: [[CALLER_LINE:%.*]] = apply {{.*}}([[CALLER_LINE_VAL]],
 // CHECK: [[PRINT_SOURCE_LOCATION:%.*]] = function_ref @$s15source_location19printSourceLocation4file4lineySS_SitF
 // CHECK: apply [[PRINT_SOURCE_LOCATION]]([[CALLER_FILE]], [[CALLER_LINE]])
@@ -19,6 +19,6 @@
 // CHECK: [[INPLACE_FILE:%.*]] = apply {{.*}}([[INPLACE_FILE_VAL]],
 // CHECK: store [[INPLACE_FILE]] to [init] [[FILE_ADDR]]
 // CHECK: [[LINE_ADDR:%.*]] = global_addr @$s15source_location4LINESiv
-// CHECK: [[INPLACE_LINE_VAL:%.*]] = integer_literal $Builtin.Int{{[0-9]+}}, 20000,
+// CHECK: [[INPLACE_LINE_VAL:%.*]] = integer_literal $Builtin.IntLiteral, 20000,
 // CHECK: [[INPLACE_LINE:%.*]] = apply {{.*}}([[INPLACE_LINE_VAL]],
 // CHECK: store [[INPLACE_LINE]] to [trivial] [[LINE_ADDR]]
diff --git a/test/SILGen/statements.swift b/test/SILGen/statements.swift
index 5395056..a48707b 100644
--- a/test/SILGen/statements.swift
+++ b/test/SILGen/statements.swift
@@ -34,9 +34,9 @@
 }
 
 // CHECK-LABEL: sil hidden @{{.*}}assignment
-// CHECK: integer_literal $Builtin.Int2048, 42
+// CHECK: integer_literal $Builtin.IntLiteral, 42
 // CHECK: assign
-// CHECK: integer_literal $Builtin.Int2048, 57
+// CHECK: integer_literal $Builtin.IntLiteral, 57
 // CHECK: assign
 
 func if_test(_ x: Int, y: Bool) {
@@ -356,7 +356,7 @@
 
 // CHECK-LABEL: sil hidden @$s10statements7test_doyyF
 func test_do() {
-  // CHECK: integer_literal $Builtin.Int2048, 0
+  // CHECK: integer_literal $Builtin.IntLiteral, 0
   // CHECK: [[BAR:%.*]] = function_ref @$s10statements3baryySiF
   // CHECK: apply [[BAR]](
   bar(0)
@@ -367,7 +367,7 @@
     let obj = MyClass()
     _ = obj
     
-    // CHECK: integer_literal $Builtin.Int2048, 1
+    // CHECK: integer_literal $Builtin.IntLiteral, 1
     // CHECK: [[BAR:%.*]] = function_ref @$s10statements3baryySiF
     // CHECK: apply [[BAR]](
     bar(1)
@@ -377,7 +377,7 @@
     // CHECK-NOT: br bb
   }
 
-  // CHECK: integer_literal $Builtin.Int2048, 2
+  // CHECK: integer_literal $Builtin.IntLiteral, 2
   // CHECK: [[BAR:%.*]] = function_ref @$s10statements3baryySiF
   // CHECK: apply [[BAR]](
   bar(2)
@@ -385,7 +385,7 @@
 
 // CHECK-LABEL: sil hidden @$s10statements15test_do_labeledyyF
 func test_do_labeled() {
-  // CHECK: integer_literal $Builtin.Int2048, 0
+  // CHECK: integer_literal $Builtin.IntLiteral, 0
   // CHECK: [[BAR:%.*]] = function_ref @$s10statements3baryySiF
   // CHECK: apply [[BAR]](
   bar(0)
@@ -397,7 +397,7 @@
     let obj = MyClass()
     _ = obj
 
-    // CHECK: integer_literal $Builtin.Int2048, 1
+    // CHECK: integer_literal $Builtin.IntLiteral, 1
     // CHECK: [[BAR:%.*]] = function_ref @$s10statements3baryySiF
     // CHECK: apply [[BAR]](
     bar(1)
@@ -412,7 +412,7 @@
     }
 
     // CHECK: bb3:
-    // CHECK: integer_literal $Builtin.Int2048, 2
+    // CHECK: integer_literal $Builtin.IntLiteral, 2
     // CHECK: [[BAR:%.*]] = function_ref @$s10statements3baryySiF
     // CHECK: apply [[BAR]](
     bar(2)
@@ -427,7 +427,7 @@
     }
 
     // CHECK: bb5:
-    // CHECK: integer_literal $Builtin.Int2048, 3
+    // CHECK: integer_literal $Builtin.IntLiteral, 3
     // CHECK: [[BAR:%.*]] = function_ref @$s10statements3baryySiF
     // CHECK: apply [[BAR]](
     bar(3)
@@ -436,7 +436,7 @@
     // CHECK: br bb6
   }
 
-  // CHECK: integer_literal $Builtin.Int2048, 4
+  // CHECK: integer_literal $Builtin.IntLiteral, 4
   // CHECK: [[BAR:%.*]] = function_ref @$s10statements3baryySiF
   // CHECK: apply [[BAR]](
   bar(4)
diff --git a/test/SILGen/switch.swift b/test/SILGen/switch.swift
index 18aaace..0d15cb6 100644
--- a/test/SILGen/switch.swift
+++ b/test/SILGen/switch.swift
@@ -984,13 +984,13 @@
 
   // CHECK: [[SOMEBB]](%3 : @trivial $Int):
   // CHECK-NEXT: debug_value %3 : $Int, let, name "x"
-  // CHECK: integer_literal $Builtin.Int2048, 0
+  // CHECK: integer_literal $Builtin.IntLiteral, 0
 
   case .none:
     return 42
 
   // CHECK: [[NILBB]]:
-  // CHECK: integer_literal $Builtin.Int2048, 42
+  // CHECK: integer_literal $Builtin.IntLiteral, 42
   }
 }
 
@@ -1006,13 +1006,13 @@
 
   // CHECK: [[SOMEBB]](%3 : @trivial $Int):
   // CHECK-NEXT: debug_value %3 : $Int, let, name "x"
-  // CHECK: integer_literal $Builtin.Int2048, 0
+  // CHECK: integer_literal $Builtin.IntLiteral, 0
 
   case nil:
     return 42
 
   // CHECK: [[NILBB]]:
-  // CHECK: integer_literal $Builtin.Int2048, 42
+  // CHECK: integer_literal $Builtin.IntLiteral, 42
   }
 }
 
diff --git a/test/SILGen/switch_bool.swift b/test/SILGen/switch_bool.swift
new file mode 100644
index 0000000..28d6a9d
--- /dev/null
+++ b/test/SILGen/switch_bool.swift
@@ -0,0 +1,22 @@
+// RUN: %target-swift-emit-silgen -module-name switch_bool -import-objc-header %S/Inputs/switch_bool.h %s
+
+// REQUIRES: objc_interop
+
+// For now this test just makes sure that we do not crash on this pattern by
+// running into dominance problems due to not-scoping the subcases of the
+// SwitchValue. So performing a FileCheck test is not really needed. Feel free
+// to add the FileCheck invocation if additional tests require FileCheck though.
+
+func properlyScopeSubcasesOfEmitBoolDispatch() {
+  let e = Optional<MyStringEnum>.none
+  switch (e, false) {
+  case (MyStringEnum.case1?, false):
+    break
+  case (let e?, _):
+    let y = {
+      return e
+    }
+  default:
+    break
+  }
+}
diff --git a/test/SILGen/toplevel.swift b/test/SILGen/toplevel.swift
index 87858c2..ac718d1 100644
--- a/test/SILGen/toplevel.swift
+++ b/test/SILGen/toplevel.swift
@@ -13,7 +13,7 @@
 // -- initialize x
 // CHECK: alloc_global @$s8toplevel1xSiv
 // CHECK: [[X:%[0-9]+]] = global_addr @$s8toplevel1xSivp : $*Int
-// CHECK: integer_literal $Builtin.Int2048, 999
+// CHECK: integer_literal $Builtin.IntLiteral, 999
 // CHECK: store {{.*}} to [trivial] [[X]]
 
 var x = 999
@@ -23,7 +23,7 @@
 }
 
 // -- assign x
-// CHECK: integer_literal $Builtin.Int2048, 0
+// CHECK: integer_literal $Builtin.IntLiteral, 0
 // CHECK: [[WRITE:%.*]] = begin_access [modify] [dynamic] [[X]] : $*Int
 // CHECK: assign {{.*}} to [[WRITE]]
 // CHECK: [[PRINT_X:%[0-9]+]] = function_ref @$s8toplevel7print_xyyF :
diff --git a/test/SILOptimizer/access_enforcement_selection.swift b/test/SILOptimizer/access_enforcement_selection.swift
index 31cf446..bad7183 100644
--- a/test/SILOptimizer/access_enforcement_selection.swift
+++ b/test/SILOptimizer/access_enforcement_selection.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -enforce-exclusivity=checked -Onone -emit-sil -parse-as-library %s -Xllvm -debug-only=access-enforcement-selection -swift-version 3 2>&1 | %FileCheck %s
+// RUN: %target-swift-frontend -enforce-exclusivity=checked -Onone -emit-sil -parse-as-library %s -Xllvm -debug-only=access-enforcement-selection 2>&1 | %FileCheck %s
 // REQUIRES: asserts
 
 // This is a source-level test because it helps bring up the entire -Onone pipeline with the access markers.
diff --git a/test/SILOptimizer/access_sink.sil b/test/SILOptimizer/access_sink.sil
new file mode 100644
index 0000000..4d38667
--- /dev/null
+++ b/test/SILOptimizer/access_sink.sil
@@ -0,0 +1,217 @@
+// RUN: %target-sil-opt -access-enforcement-release -assume-parsing-unqualified-ownership-sil %s -enable-sil-verify-all | %FileCheck %s
+//
+// Test the AccessEnforcementReleaseSinking pass in isolation.
+// This ensures that no upstream passes have removed SIL-level access markers
+// that are required to ensure the pass is not overly optimistic.
+
+sil_stage canonical
+
+import Builtin
+import Swift
+import SwiftShims
+
+struct X {
+  @sil_stored var i: Int64 { get set }
+  init(i: Int64)
+  init()
+}
+
+var globalX: X
+
+sil_global hidden @globalX : $X
+
+sil hidden_external [global_init] @globalAddressor : $@convention(thin) () -> Builtin.RawPointer
+
+// public func testSimpleRelease() {
+// Checks the simple case of release sinking
+//
+// CHECK-LABEL: sil @testSimpleRelease : $@convention(thin) () -> () {
+// CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
+// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [modify] [dynamic] [[GLOBAL]] : $*X
+// CHECK-NEXT: [[LOADED:%.*]] = load [[BEGIN]] : $*X
+// CHECK-NEXT: end_access [[BEGIN]] : $*X
+// CHECK-NEXT: release_value [[LOADED]]
+// CHECK-LABEL: } // end sil function 'testSimpleRelease'
+sil @testSimpleRelease : $@convention(thin) () -> () {
+bb0:
+  %0 = global_addr @globalX: $*X
+  %1 = begin_access [modify] [dynamic] %0 : $*X
+  %2 = load %1 : $*X
+  release_value %2 : $X
+  end_access %1 : $*X
+  %ret = tuple ()
+  return %ret : $()
+}
+
+// public func testMultiBlocklSimpleRelease() {
+// Checks the simple case of release sinking with the begin_access in a different block
+//
+// CHECK-LABEL: sil @testMultiBlocklSimpleRelease : $@convention(thin) () -> () {
+// CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
+// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [modify] [dynamic] [[GLOBAL]] : $*X
+// CHECK-NEXT: [[LOADED:%.*]] = load [[BEGIN]] : $*X
+// CHECK-NEXT: br bb1
+// CHECK: bb1
+// CHECK-NEXT: end_access [[BEGIN]] : $*X
+// CHECK-NEXT: release_value [[LOADED]]
+// CHECK-LABEL: } // end sil function 'testMultiBlocklSimpleRelease'
+sil @testMultiBlocklSimpleRelease : $@convention(thin) () -> () {
+bb0:
+  %0 = global_addr @globalX: $*X
+  %1 = begin_access [modify] [dynamic] %0 : $*X
+  %2 = load %1 : $*X
+  br bb1
+  
+bb1:
+  release_value %2 : $X
+  end_access %1 : $*X
+  %ret = tuple ()
+  return %ret : $()
+}
+
+// public func testMultiBlocklBailOnRelease() {
+// Checks bailing (for now) on the simple case due to the release being in a different block
+//
+// CHECK-LABEL: sil @testMultiBlocklBailOnRelease : $@convention(thin) () -> () {
+// CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
+// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [modify] [dynamic] [[GLOBAL]] : $*X
+// CHECK-NEXT: [[LOADED:%.*]] = load [[BEGIN]] : $*X
+// CHECK-NEXT: release_value [[LOADED]]
+// CHECK-NEXT: br bb1
+// CHECK: bb1
+// CHECK-NEXT: end_access [[BEGIN]] : $*X
+// CHECK-LABEL: } // end sil function 'testMultiBlocklBailOnRelease'
+sil @testMultiBlocklBailOnRelease : $@convention(thin) () -> () {
+bb0:
+  %0 = global_addr @globalX: $*X
+  %1 = begin_access [modify] [dynamic] %0 : $*X
+  %2 = load %1 : $*X
+  release_value %2 : $X
+  br bb1
+  
+bb1:
+  end_access %1 : $*X
+  %ret = tuple ()
+  return %ret : $()
+}
+
+// public func testApplyBarrier() {
+// Checks we don't sink across apply-site barrier
+//
+// CHECK-LABEL: sil @testApplyBarrier : $@convention(thin) () -> () {
+// CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
+// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [modify] [dynamic] [[GLOBAL]] : $*X
+// CHECK-NEXT: [[LOADED:%.*]] = load [[BEGIN]] : $*X
+// CHECK-NEXT: release_value [[LOADED]]
+// CHECK: apply
+// CHECK-NEXT: end_access [[BEGIN]] : $*X
+// CHECK-LABEL: } // end sil function 'testApplyBarrier'
+sil @testApplyBarrier : $@convention(thin) () -> () {
+bb0:
+  %0 = global_addr @globalX: $*X
+  %1 = begin_access [modify] [dynamic] %0 : $*X
+  %2 = load %1 : $*X
+  release_value %2 : $X
+  %u0 = function_ref @globalAddressor : $@convention(thin) () -> Builtin.RawPointer
+  %u1 = apply %u0() : $@convention(thin) () -> Builtin.RawPointer
+  end_access %1 : $*X
+  %ret = tuple ()
+  return %ret : $()
+}
+
+// public func testUniquenessBarrier() {
+// Checks we don't sink across a uniqueness check
+//
+// CHECK-LABEL: sil @testUniquenessBarrier : $@convention(thin) () -> () {
+// CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
+// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [modify] [dynamic] [[GLOBAL]] : $*X
+// CHECK-NEXT: [[LOADED:%.*]] = load [[BEGIN]] : $*X
+// CHECK-NEXT: release_value [[LOADED]]
+// CHECK-NEXT: is_unique
+// CHECK-NEXT: end_access [[BEGIN]] : $*X
+// CHECK-LABEL: } // end sil function 'testUniquenessBarrier'
+sil @testUniquenessBarrier : $@convention(thin) () -> () {
+bb0:
+  %0 = global_addr @globalX: $*X
+  %1 = begin_access [modify] [dynamic] %0 : $*X
+  %2 = load %1 : $*X
+  release_value %2 : $X
+  is_unique %1 : $*X
+  end_access %1 : $*X
+  %ret = tuple ()
+  return %ret : $()
+}
+
+// public func testBeginBarrier() {
+// Checks we don't sink across begin_access barrier
+//
+// CHECK-LABEL: sil @testBeginBarrier : $@convention(thin) () -> () {
+// CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
+// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [modify] [dynamic] [[GLOBAL]] : $*X
+// CHECK-NEXT: [[LOADED:%.*]] = load [[BEGIN]] : $*X
+// CHECK-NEXT: release_value [[LOADED]]
+// CHECK-NEXT: [[BEGIN2:%.*]] = begin_access [modify] [dynamic] [[GLOBAL]] : $*X
+// CHECK-NEXT: end_access [[BEGIN2]] : $*X
+// CHECK-NEXT: end_access [[BEGIN]] : $*X
+// CHECK-LABEL: } // end sil function 'testBeginBarrier'
+sil @testBeginBarrier : $@convention(thin) () -> () {
+bb0:
+  %0 = global_addr @globalX: $*X
+  %1 = begin_access [modify] [dynamic] %0 : $*X
+  %2 = load %1 : $*X
+  release_value %2 : $X
+  %b0 = begin_access [modify] [dynamic] %0 : $*X
+  end_access %b0 : $*X
+  end_access %1 : $*X
+  %ret = tuple ()
+  return %ret : $()
+}
+
+// public func testSinkCrossMultiEnds() {
+// Checks that we choose the *bottom* end_access when sinking
+//
+// CHECK-LABEL: sil @testSinkCrossMultiEnds : $@convention(thin) () -> () {
+// CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
+// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [modify] [dynamic] [[GLOBAL]] : $*X
+// CHECK-NEXT: [[BEGIN2:%.*]] = begin_access [modify] [dynamic] [[GLOBAL]] : $*X
+// CHECK-NEXT: [[LOADED:%.*]] = load [[BEGIN]] : $*X
+// CHECK-NEXT: end_access [[BEGIN2]] : $*X
+// CHECK-NEXT: end_access [[BEGIN]] : $*X
+// CHECK-NEXT: release_value [[LOADED]]
+// CHECK-LABEL: } // end sil function 'testSinkCrossMultiEnds'
+sil @testSinkCrossMultiEnds : $@convention(thin) () -> () {
+bb0:
+  %0 = global_addr @globalX: $*X
+  %1 = begin_access [modify] [dynamic] %0 : $*X
+  %b0 = begin_access [modify] [dynamic] %0 : $*X
+  %2 = load %1 : $*X
+  release_value %2 : $X
+  end_access %b0 : $*X
+  end_access %1 : $*X
+  %ret = tuple ()
+  return %ret : $()
+}
+
+// public func testSinkAfterBarrierEncounter() {
+// Checks that we sink after barrier resetting
+//
+// CHECK-LABEL: sil @testSinkAfterBarrierEncounter : $@convention(thin) () -> () {
+// CHECK: [[GLOBAL:%.*]] = global_addr @globalX : $*X
+// CHECK-NEXT: [[BEGIN:%.*]] = begin_access [modify] [dynamic] [[GLOBAL]] : $*X
+// CHECK-NEXT: [[LOADED:%.*]] = load [[BEGIN]] : $*X
+// CHECK-NEXT: end_access [[BEGIN]] : $*X
+// CHECK-NEXT: release_value [[LOADED]]
+// CHECK-NEXT: [[BEGIN2:%.*]] = begin_access [modify] [dynamic] [[GLOBAL]] : $*X
+// CHECK-LABEL: } // end sil function 'testSinkAfterBarrierEncounter'
+sil @testSinkAfterBarrierEncounter : $@convention(thin) () -> () {
+bb0:
+  %0 = global_addr @globalX: $*X
+  %1 = begin_access [modify] [dynamic] %0 : $*X
+  %2 = load %1 : $*X
+  release_value %2 : $X
+  end_access %1 : $*X
+  %b0 = begin_access [modify] [dynamic] %0 : $*X
+  end_access %b0 : $*X
+  %ret = tuple ()
+  return %ret : $()
+}
diff --git a/test/SILOptimizer/capturepromotion-wrong-lexicalscope.swift b/test/SILOptimizer/capturepromotion-wrong-lexicalscope.swift
index 6845180..0deb31c 100644
--- a/test/SILOptimizer/capturepromotion-wrong-lexicalscope.swift
+++ b/test/SILOptimizer/capturepromotion-wrong-lexicalscope.swift
@@ -7,9 +7,9 @@
 // CHECK:   %0 = alloc_box ${ var Int }, var, name "x", loc {{.*}}:32:7, scope 3
 // CHECK:   %1 = project_box %0 : ${ var Int }, 0, loc {{.*}}:32:7, scope 3
 // CHECK:   %2 = metatype $@thin Int.Type, loc {{.*}}:32:11, scope 3
-// CHECK:   %3 = integer_literal $Builtin.Int2048, 1, loc {{.*}}:32:11, scope 3
-// CHECK:   %4 = function_ref @$sSi22_builtinIntegerLiteralSiBi2048__tcfC : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int, loc {{.*}}:32:11, scope 3
-// CHECK:   %5 = apply %4(%3, %2) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int, loc {{.*}}:32:11, scope 3
+// CHECK:   %3 = integer_literal $Builtin.IntLiteral, 1, loc {{.*}}:32:11, scope 3
+// CHECK:   %4 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int, loc {{.*}}:32:11, scope 3
+// CHECK:   %5 = apply %4(%3, %2) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int, loc {{.*}}:32:11, scope 3
 // CHECK:   store %5 to [trivial] %1 : $*Int, loc {{.*}}:32:11, scope 3
 // CHECK:   %7 = copy_value %0 : ${ var Int }, loc {{.*}}:33:11, scope 3
 // CHECK:   %8 = project_box %7 : ${ var Int }, 0, loc {{.*}}:33:11, scope 3
diff --git a/test/SILOptimizer/constant_propagation.sil b/test/SILOptimizer/constant_propagation.sil
index 7a4a8e6..031fe62 100644
--- a/test/SILOptimizer/constant_propagation.sil
+++ b/test/SILOptimizer/constant_propagation.sil
@@ -511,12 +511,12 @@
 // dead cond_fail instructions.
 sil @fold_condfail_instructions : $@convention(thin) () -> Int64 {
 bb0:
-  %0 = integer_literal $Builtin.Int2048, 1        // user: %2
-  %2 = builtin "s_to_s_checked_trunc_Int2048_Int64"(%0 : $Builtin.Int2048) : $(Builtin.Int64, Builtin.Int1) // user: %3
+  %0 = integer_literal $Builtin.IntLiteral, 1        // user: %2
+  %2 = builtin "s_to_s_checked_trunc_IntLiteral_Int64"(%0 : $Builtin.IntLiteral) : $(Builtin.Int64, Builtin.Int1) // user: %3
   %3 = tuple_extract %2 : $(Builtin.Int64, Builtin.Int1), 0 // user: %4
   %4 = struct $Int64 (%3 : $Builtin.Int64)        // users: %14, %5
-  %6 = integer_literal $Builtin.Int2048, 2        // user: %8
-  %8 = builtin "s_to_s_checked_trunc_Int2048_Int64"(%6 : $Builtin.Int2048) : $(Builtin.Int64, Builtin.Int1) // user: %9
+  %6 = integer_literal $Builtin.IntLiteral, 2        // user: %8
+  %8 = builtin "s_to_s_checked_trunc_IntLiteral_Int64"(%6 : $Builtin.IntLiteral) : $(Builtin.Int64, Builtin.Int1) // user: %9
   %9 = tuple_extract %8 : $(Builtin.Int64, Builtin.Int1), 0 // user: %10
   %10 = struct $Int64 (%9 : $Builtin.Int64)       // users: %15, %11
   %12 = integer_literal $Builtin.Int1, -1         // user: %16
@@ -545,25 +545,25 @@
 sil @properly_handle_eliminated_instructions_in_worklist : $@convention(method) (Bool, @inout UInt) -> () {
 bb0(%0 : $Bool, %1 : $*UInt):
   %2 = load %1 : $*UInt
-  %3 = integer_literal $Builtin.Int2048, 1
-  %5 = builtin "s_to_u_checked_trunc_Int2048_Word"(%3 : $Builtin.Int2048) : $(Builtin.Word, Builtin.Int1)
+  %3 = integer_literal $Builtin.IntLiteral, 1
+  %5 = builtin "s_to_u_checked_trunc_IntLiteral_Word"(%3 : $Builtin.IntLiteral) : $(Builtin.Word, Builtin.Int1)
   %6 = tuple_extract %5 : $(Builtin.Word, Builtin.Int1), 0
   %7 = tuple_extract %5 : $(Builtin.Word, Builtin.Int1), 1
   %8 = struct $UInt (%6 : $Builtin.Word)
-  %9 = integer_literal $Builtin.Int2048, 0
-  %11 = builtin "s_to_u_checked_trunc_Int2048_Word"(%9 : $Builtin.Int2048) : $(Builtin.Word, Builtin.Int1)
+  %9 = integer_literal $Builtin.IntLiteral, 0
+  %11 = builtin "s_to_u_checked_trunc_IntLiteral_Word"(%9 : $Builtin.IntLiteral) : $(Builtin.Word, Builtin.Int1)
   %12 = tuple_extract %11 : $(Builtin.Word, Builtin.Int1), 0
   %13 = tuple_extract %11 : $(Builtin.Word, Builtin.Int1), 1
   %14 = struct $UInt (%12 : $Builtin.Word)
-  %15 = integer_literal $Builtin.Int2048, 1
-  %17 = builtin "s_to_u_checked_trunc_Int2048_Word"(%15 : $Builtin.Int2048) : $(Builtin.Word, Builtin.Int1)
+  %15 = integer_literal $Builtin.IntLiteral, 1
+  %17 = builtin "s_to_u_checked_trunc_IntLiteral_Word"(%15 : $Builtin.IntLiteral) : $(Builtin.Word, Builtin.Int1)
   %18 = tuple_extract %17 : $(Builtin.Word, Builtin.Int1), 0
   %19 = tuple_extract %17 : $(Builtin.Word, Builtin.Int1), 1
   %20 = struct $UInt (%18 : $Builtin.Word)
   %22 = struct_extract %14 : $UInt, #UInt.value
   %23 = struct_extract %20 : $UInt, #UInt.value
-  %25 = integer_literal $Builtin.Int2048, 0
-  %27 = builtin "s_to_s_checked_trunc_Int2048_Word"(%25 : $Builtin.Int2048) : $(Builtin.Word, Builtin.Int1)
+  %25 = integer_literal $Builtin.IntLiteral, 0
+  %27 = builtin "s_to_s_checked_trunc_IntLiteral_Word"(%25 : $Builtin.IntLiteral) : $(Builtin.Word, Builtin.Int1)
   %28 = tuple_extract %27 : $(Builtin.Word, Builtin.Int1), 0
   %29 = tuple_extract %27 : $(Builtin.Word, Builtin.Int1), 1
   %30 = struct $Int (%28 : $Builtin.Word)
diff --git a/test/SILOptimizer/devirt_access.sil b/test/SILOptimizer/devirt_access.sil
index 3f4932b..2778e8d 100644
--- a/test/SILOptimizer/devirt_access.sil
+++ b/test/SILOptimizer/devirt_access.sil
@@ -66,7 +66,7 @@
 }
 
 sil @_TFC14devirt_access21X4pingfS0_FT_Si : $@convention(method) (@guaranteed X) -> Int
-sil public_external [transparent] @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+sil public_external [transparent] @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
 sil @_TFC14devirt_access21Xd : $@convention(method) (@guaranteed X) -> @owned Builtin.NativeObject
 sil @_TFC14devirt_access21XD : $@convention(method) (@guaranteed X) -> ()
 sil @_TFC14devirt_access21XcfMS0_FT_S0_ : $@convention(method) (@owned X) -> @owned X
diff --git a/test/SILOptimizer/devirt_access_serialized.sil b/test/SILOptimizer/devirt_access_serialized.sil
index 2e4d01c..0dbb549 100644
--- a/test/SILOptimizer/devirt_access_serialized.sil
+++ b/test/SILOptimizer/devirt_access_serialized.sil
@@ -20,7 +20,7 @@
 }
 
 sil [serialized] @_TFC14devirt_access21X4pingfS0_FT_Si : $@convention(method) (@guaranteed X) -> Int
-sil public_external [transparent] @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+sil public_external [transparent] @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
 sil @_TFC14devirt_access21Xd : $@convention(method) (@guaranteed X) -> @owned Builtin.NativeObject
 sil @_TFC14devirt_access21XD : $@convention(method) (@guaranteed X) -> ()
 sil @_TFC14devirt_access21XcfMS0_FT_S0_ : $@convention(method) (@owned X) -> @owned X
diff --git a/test/SILOptimizer/devirt_try_apply.sil b/test/SILOptimizer/devirt_try_apply.sil
index 08ec9e3..ca59e86 100644
--- a/test/SILOptimizer/devirt_try_apply.sil
+++ b/test/SILOptimizer/devirt_try_apply.sil
@@ -107,7 +107,7 @@
 }
 
 
-sil [transparent] [serialized] @_TFVs5Int32CfMS_FT22_builtinIntegerLiteralBi2048__S_ : $@convention(thin) (Builtin.Int2048, @thin Int32.Type) -> Int32
+sil [transparent] [serialized] @_TFVs5Int32CfMS_FT22_builtinIntegerLiteralBI__S_ : $@convention(thin) (Builtin.IntLiteral, @thin Int32.Type) -> Int32
 
 
 sil hidden [noinline] @_TFC16devirt_try_apply4Base4boo1fS0_FzT_S0_ : $@convention(method) (@guaranteed Base) -> (@owned Base, @error Error) {
diff --git a/test/SILOptimizer/eager_specialize.sil b/test/SILOptimizer/eager_specialize.sil
index dfb31b5..b744967 100644
--- a/test/SILOptimizer/eager_specialize.sil
+++ b/test/SILOptimizer/eager_specialize.sil
@@ -154,11 +154,11 @@
   %5 = function_ref @$ss2neoiySbx_xts9EquatableRzlFZ : $@convention(thin) <τ_0_0 where τ_0_0 : Equatable> (@in τ_0_0, @in τ_0_0) -> Bool
   %6 = alloc_stack $T
   copy_addr %2 to [initialization] %6 : $*T
-  %8 = witness_method $T, #_ExpressibleByBuiltinIntegerLiteral.init!allocator.1 : $@convention(witness_method: _ExpressibleByBuiltinIntegerLiteral) <τ_0_0 where τ_0_0 : _ExpressibleByBuiltinIntegerLiteral> (Builtin.Int2048, @thick τ_0_0.Type) -> @out τ_0_0
+  %8 = witness_method $T, #_ExpressibleByBuiltinIntegerLiteral.init!allocator.1 : $@convention(witness_method: _ExpressibleByBuiltinIntegerLiteral) <τ_0_0 where τ_0_0 : _ExpressibleByBuiltinIntegerLiteral> (Builtin.IntLiteral, @thick τ_0_0.Type) -> @out τ_0_0
   %9 = metatype $@thick T.Type
-  %10 = integer_literal $Builtin.Int2048, 0
+  %10 = integer_literal $Builtin.IntLiteral, 0
   %11 = alloc_stack $T
-  %12 = apply %8<T>(%11, %10, %9) : $@convention(witness_method: _ExpressibleByBuiltinIntegerLiteral) <τ_0_0 where τ_0_0 : _ExpressibleByBuiltinIntegerLiteral> (Builtin.Int2048, @thick τ_0_0.Type) -> @out τ_0_0
+  %12 = apply %8<T>(%11, %10, %9) : $@convention(witness_method: _ExpressibleByBuiltinIntegerLiteral) <τ_0_0 where τ_0_0 : _ExpressibleByBuiltinIntegerLiteral> (Builtin.IntLiteral, @thick τ_0_0.Type) -> @out τ_0_0
   %13 = apply %5<T>(%6, %11) : $@convention(thin) <τ_0_0 where τ_0_0 : Equatable> (@in τ_0_0, @in τ_0_0) -> Bool
   %14 = struct_extract %13 : $Bool, #Bool._value
   dealloc_stack %11 : $*T
diff --git a/test/SILOptimizer/mandatory_inlining.sil b/test/SILOptimizer/mandatory_inlining.sil
index 2162eda..0160371 100644
--- a/test/SILOptimizer/mandatory_inlining.sil
+++ b/test/SILOptimizer/mandatory_inlining.sil
@@ -710,9 +710,9 @@
 
 
 
-sil [transparent] @convertFromBuiltinIntegerLiteral : $@convention(thin) (Builtin.Int2048, @thin Int64.Type) -> Int64 {
-bb0(%0 : $Builtin.Int2048, %1 : $@thin Int64.Type):
-  %3 = builtin "s_to_s_checked_trunc_Int2048_Int64"(%0 : $Builtin.Int2048) : $(Builtin.Int64, Builtin.Int1)
+sil [transparent] @convertFromBuiltinIntegerLiteral : $@convention(thin) (Builtin.IntLiteral, @thin Int64.Type) -> Int64 {
+bb0(%0 : $Builtin.IntLiteral, %1 : $@thin Int64.Type):
+  %3 = builtin "s_to_s_checked_trunc_IntLiteral_Int64"(%0 : $Builtin.IntLiteral) : $(Builtin.Int64, Builtin.Int1)
   %4 = tuple_extract %3 : $(Builtin.Int64, Builtin.Int1), 0
   %5 = struct $Int64 (%4 : $Builtin.Int64)
   return %5 : $Int64
@@ -723,10 +723,10 @@
   %0 = tuple ()
   %1 = alloc_box ${ var Int64 }
   %1a = project_box %1 : ${ var Int64 }, 0
-  %2 = function_ref @convertFromBuiltinIntegerLiteral : $@convention(thin) (Builtin.Int2048, @thin Int64.Type) -> Int64
+  %2 = function_ref @convertFromBuiltinIntegerLiteral : $@convention(thin) (Builtin.IntLiteral, @thin Int64.Type) -> Int64
   %3 = metatype $@thin Int64.Type
-  %4 = integer_literal $Builtin.Int2048, 1
-  %5 = apply %2(%4, %3) : $@convention(thin) (Builtin.Int2048, @thin Int64.Type) -> Int64
+  %4 = integer_literal $Builtin.IntLiteral, 1
+  %5 = apply %2(%4, %3) : $@convention(thin) (Builtin.IntLiteral, @thin Int64.Type) -> Int64
   store %5 to %1a : $*Int64
   strong_release %1 : ${ var Int64 }
   %8 = tuple ()
diff --git a/test/SILOptimizer/optimize_never.sil b/test/SILOptimizer/optimize_never.sil
index 41a0197..60ad31c 100644
--- a/test/SILOptimizer/optimize_never.sil
+++ b/test/SILOptimizer/optimize_never.sil
@@ -90,7 +90,7 @@
 }
 
 
-sil [transparent] [serialized] @$ss5Int32V22_builtinIntegerLiteralABBi2048__tcfC : $@convention(thin) (Builtin.Int2048, @thin Int32.Type) -> Int32
+sil [transparent] [serialized] @$ss5Int32V22_builtinIntegerLiteralABBI__tcfC : $@convention(thin) (Builtin.IntLiteral, @thin Int32.Type) -> Int32
 
 
 sil @$s14optimize_never1CCfD : $@convention(method) (@owned C) -> () {
@@ -226,7 +226,7 @@
 }
 
 
-sil [transparent] [serialized] @$sSi22_builtinIntegerLiteralSiBi2048__tcfC : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+sil [transparent] [serialized] @$sSi22_builtinIntegerLiteralSiBI__tcfC : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
 
 
 sil @$s14optimize_never10transform2ys5Int32VADF : $@convention(thin) (Int32) -> Int32 {
diff --git a/test/SILOptimizer/performance_inliner.sil b/test/SILOptimizer/performance_inliner.sil
index 8394874..2d96518 100644
--- a/test/SILOptimizer/performance_inliner.sil
+++ b/test/SILOptimizer/performance_inliner.sil
@@ -302,10 +302,10 @@
 sil @trivial_witness_method_caller : $@convention(thin) () -> () {
   %0 = alloc_box ${ var Int64 }, var, name "x"
   %1 = project_box %0 : ${ var Int64 }, 0
-  %2 = function_ref @$ss5Int64V22_builtinIntegerLiteralABBi2048__tcfC : $@convention(method) (Builtin.Int2048, @thin Int64.Type) -> Int64 // user: %5
+  %2 = function_ref @$ss5Int64V22_builtinIntegerLiteralABBI__tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int64.Type) -> Int64 // user: %5
   %3 = metatype $@thin Int64.Type
-  %4 = integer_literal $Builtin.Int2048, 0
-  %5 = apply %2(%4, %3) : $@convention(method) (Builtin.Int2048, @thin Int64.Type) -> Int64
+  %4 = integer_literal $Builtin.IntLiteral, 0
+  %5 = apply %2(%4, %3) : $@convention(method) (Builtin.IntLiteral, @thin Int64.Type) -> Int64
   store %5 to %1 : $*Int64
   %6 = function_ref @trivial_witness_method : $@convention(witness_method: P) (@inout Int64) -> Int64
   %7 = apply %6 (%1) : $@convention(witness_method: P) (@inout Int64) -> Int64
@@ -314,7 +314,7 @@
 }
 
 // Int64.init(_builtinIntegerLiteral:)
-sil [transparent] [serialized] @$ss5Int64V22_builtinIntegerLiteralABBi2048__tcfC : $@convention(method) (Builtin.Int2048, @thin Int64.Type) -> Int64
+sil [transparent] [serialized] @$ss5Int64V22_builtinIntegerLiteralABBI__tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int64.Type) -> Int64
 
 
 // We can inline function_refs with c calling convention.
@@ -711,13 +711,13 @@
 // CHECK-LABEL: [noinline] @noinline_callee
 sil [noinline] @noinline_callee : $@convention(thin) () -> Int {
 bb0:
-  %0 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+  %0 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
   %1 = metatype $@thin Int.Type
-  %2 = integer_literal $Builtin.Int2048, 0
-  %3 = apply %0(%2, %1) : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+  %2 = integer_literal $Builtin.IntLiteral, 0
+  %3 = apply %0(%2, %1) : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
   return %3 : $Int
 }
-sil [transparent] @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+sil [transparent] @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
 
 sil @unknown_function : $@convention(thin) () -> ()
 
diff --git a/test/SILOptimizer/recursive_func.sil b/test/SILOptimizer/recursive_func.sil
index 50ebcd1..9b65ce2 100644
--- a/test/SILOptimizer/recursive_func.sil
+++ b/test/SILOptimizer/recursive_func.sil
@@ -19,11 +19,11 @@
 bb0(%c : $Builtin.Int32, %v : $Builtin.RawPointer):
   // function_ref test.test (Swift.Int) -> ()
   %0 = function_ref @_TF4test4testFSiT_ : $@convention(thin) (Int) -> () // user: %5
-  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.Int2048) -> Swift.Int
-  %1 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %4
+  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.IntLiteral) -> Swift.Int
+  %1 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %4
   %2 = metatype $@thin Int.Type                   // user: %4
-  %3 = integer_literal $Builtin.Int2048, 1000     // user: %4
-  %4 = apply %1(%3, %2) : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %5
+  %3 = integer_literal $Builtin.IntLiteral, 1000     // user: %4
+  %4 = apply %1(%3, %2) : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %5
   %5 = apply %0(%4) : $@convention(thin) (Int) -> ()
   %6 = integer_literal $Builtin.Int32, 0
   return %6 : $Builtin.Int32
@@ -37,11 +37,11 @@
   %4 = function_ref @_TFSb21_getBuiltinLogicValuefSbFT_Bi1_ : $@convention(method) (Bool) -> Builtin.Int1 // user: %11
   // function_ref Swift.>= @infix (Swift.Int, Swift.Int) -> Swift.Bool
   %5 = function_ref @_TFsoi2geFTSiSi_Sb : $@convention(thin) (Int, Int) -> Bool // user: %10
-  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.Int2048) -> Swift.Int
-  %6 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %9
+  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.IntLiteral) -> Swift.Int
+  %6 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %9
   %7 = metatype $@thin Int.Type                   // user: %9
-  %8 = integer_literal $Builtin.Int2048, 2        // user: %9
-  %9 = apply %6(%8, %7) : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %10
+  %8 = integer_literal $Builtin.IntLiteral, 2        // user: %9
+  %9 = apply %6(%8, %7) : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %10
   %10 = apply %5(%0, %9) : $@convention(thin) (Int, Int) -> Bool // user: %11
   %11 = apply %4(%10) : $@convention(method) (Bool) -> Builtin.Int1 // user: %12
   cond_br %11, bb1, bb2                           // id: %12
@@ -51,22 +51,22 @@
   %14 = class_method %1 : $REC, #REC.recursive!1 : (REC) -> (Int) -> (), $@convention(method) (Int, @guaranteed REC) -> () // user: %21
   // function_ref Swift.- @infix (Swift.Int, Swift.Int) -> Swift.Int
   %15 = function_ref @_TFsoi1sFTSiSi_Si : $@convention(thin) (Int, Int) -> Int // user: %20
-  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.Int2048) -> Swift.Int
-  %16 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %19
+  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.IntLiteral) -> Swift.Int
+  %16 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %19
   %17 = metatype $@thin Int.Type                  // user: %19
-  %18 = integer_literal $Builtin.Int2048, 2       // user: %19
-  %19 = apply %16(%18, %17) : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %20
+  %18 = integer_literal $Builtin.IntLiteral, 2       // user: %19
+  %19 = apply %16(%18, %17) : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %20
   %20 = apply %15(%0, %19) : $@convention(thin) (Int, Int) -> Int // user: %21
   %21 = apply %14(%20, %1) : $@convention(method) (Int, @guaranteed REC) -> ()
   strong_retain %1 : $REC                         // id: %22
   %23 = class_method %1 : $REC, #REC.recursive!1 : (REC) -> (Int) -> (), $@convention(method) (Int, @guaranteed REC) -> () // user: %30
   // function_ref Swift.- @infix (Swift.Int, Swift.Int) -> Swift.Int
   %24 = function_ref @_TFsoi1sFTSiSi_Si : $@convention(thin) (Int, Int) -> Int // user: %29
-  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.Int2048) -> Swift.Int
-  %25 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %28
+  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.IntLiteral) -> Swift.Int
+  %25 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %28
   %26 = metatype $@thin Int.Type                  // user: %28
-  %27 = integer_literal $Builtin.Int2048, 1       // user: %28
-  %28 = apply %25(%27, %26) : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %29
+  %27 = integer_literal $Builtin.IntLiteral, 1       // user: %28
+  %28 = apply %25(%27, %26) : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %29
   %29 = apply %24(%0, %28) : $@convention(thin) (Int, Int) -> Int // user: %30
   %30 = apply %23(%29, %1) : $@convention(method) (Int, @guaranteed REC) -> ()
   br bb2                                          // id: %31
@@ -83,8 +83,8 @@
 // Swift.>= @infix (Swift.Int, Swift.Int) -> Swift.Bool
 sil [transparent] @_TFsoi2geFTSiSi_Sb : $@convention(thin) (Int, Int) -> Bool
 
-// Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.Int2048) -> Swift.Int
-sil [transparent] @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+// Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.IntLiteral) -> Swift.Int
+sil [transparent] @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
 
 // Swift.- @infix (Swift.Int, Swift.Int) -> Swift.Int
 sil [transparent] @_TFsoi1sFTSiSi_Si : $@convention(thin) (Int, Int) -> Int
diff --git a/test/SILOptimizer/recursive_single.sil b/test/SILOptimizer/recursive_single.sil
index ab834e3..13247b3 100644
--- a/test/SILOptimizer/recursive_single.sil
+++ b/test/SILOptimizer/recursive_single.sil
@@ -20,11 +20,11 @@
 bb0(%c : $Builtin.Int32, %v : $Builtin.RawPointer):
   // function_ref single.test (Swift.Int) -> ()
   %0 = function_ref @_TF6single4testFSiT_ : $@convention(thin) (Int) -> () // user: %5
-  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.Int2048) -> Swift.Int
-  %1 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %4
+  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.IntLiteral) -> Swift.Int
+  %1 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %4
   %2 = metatype $@thin Int.Type                   // user: %4
-  %3 = integer_literal $Builtin.Int2048, 1000     // user: %4
-  %4 = apply %1(%3, %2) : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %5
+  %3 = integer_literal $Builtin.IntLiteral, 1000     // user: %4
+  %4 = apply %1(%3, %2) : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %5
   %5 = apply %0(%4) : $@convention(thin) (Int) -> ()
   %6 = integer_literal $Builtin.Int32, 0
   return %6 : $Builtin.Int32
@@ -39,11 +39,11 @@
   %4 = function_ref @_TFSb21_getBuiltinLogicValuefSbFT_Bi1_ : $@convention(method) (Bool) -> Builtin.Int1 // user: %11
   // function_ref Swift.>= @infix (Swift.Int, Swift.Int) -> Swift.Bool
   %5 = function_ref @_TFsoi2geFTSiSi_Sb : $@convention(thin) (Int, Int) -> Bool // user: %10
-  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.Int2048) -> Swift.Int
-  %6 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %9
+  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.IntLiteral) -> Swift.Int
+  %6 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %9
   %7 = metatype $@thin Int.Type                   // user: %9
-  %8 = integer_literal $Builtin.Int2048, 2        // user: %9
-  %9 = apply %6(%8, %7) : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %10
+  %8 = integer_literal $Builtin.IntLiteral, 2        // user: %9
+  %9 = apply %6(%8, %7) : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %10
   %10 = apply %5(%0, %9) : $@convention(thin) (Int, Int) -> Bool // user: %11
   %11 = apply %4(%10) : $@convention(method) (Bool) -> Builtin.Int1 // user: %12
   cond_br %11, bb1, bb2                           // id: %12
@@ -53,11 +53,11 @@
   %14 = class_method %1 : $REC, #REC.recursive!1 : (REC) -> (Int) -> (), $@convention(method) (Int, @guaranteed REC) -> () // user: %21
   // function_ref Swift.- @infix (Swift.Int, Swift.Int) -> Swift.Int
   %15 = function_ref @_TFsoi1sFTSiSi_Si : $@convention(thin) (Int, Int) -> Int // user: %20
-  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.Int2048) -> Swift.Int
-  %16 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %19
+  // function_ref Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.IntLiteral) -> Swift.Int
+  %16 = function_ref @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %19
   %17 = metatype $@thin Int.Type                  // user: %19
-  %18 = integer_literal $Builtin.Int2048, 2       // user: %19
-  %19 = apply %16(%18, %17) : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int // user: %20
+  %18 = integer_literal $Builtin.IntLiteral, 2       // user: %19
+  %19 = apply %16(%18, %17) : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %20
   %20 = apply %15(%0, %19) : $@convention(thin) (Int, Int) -> Int // user: %21
   %21 = apply %14(%20, %1) : $@convention(method) (Int, @guaranteed REC) -> ()
   br bb2                                          // id: %22
@@ -74,8 +74,8 @@
 // Swift.>= @infix (Swift.Int, Swift.Int) -> Swift.Bool
 sil [transparent] @_TFsoi2geFTSiSi_Sb : $@convention(thin) (Int, Int) -> Bool
 
-// Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.Int2048) -> Swift.Int
-sil [transparent] @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBi2048_Si : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+// Swift.Int._convertFromBuiltinIntegerLiteral (Swift.Int.Type)(Builtin.IntLiteral) -> Swift.Int
+sil [transparent] @_TFSi33_convertFromBuiltinIntegerLiteralfMSiFBI_Si : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
 
 // Swift.- @infix (Swift.Int, Swift.Int) -> Swift.Int
 sil [transparent] @_TFsoi1sFTSiSi_Si : $@convention(thin) (Int, Int) -> Int
diff --git a/test/SILOptimizer/specialize.sil b/test/SILOptimizer/specialize.sil
index ef90591..fee76dd 100644
--- a/test/SILOptimizer/specialize.sil
+++ b/test/SILOptimizer/specialize.sil
@@ -101,10 +101,10 @@
   return %9 : $Int32                              // id: %11
 }
 
-// Swift.Int32._convertFromBuiltinIntegerLiteral (Swift.Int32.Type)(Builtin.Int2048) -> Swift.Int32
-sil public_external [transparent] @$sSi33_convertFromBuiltinIntegerLiteralySiBi2048_cSimF : $@convention(thin) (Builtin.Int2048, @thin Int32.Type) -> Int32 {
-bb0(%0 : $Builtin.Int2048, %1 : $@thin Int32.Type):
-  %3 = builtin "s_to_s_checked_trunc_Int2048_Int32"(%0 : $Builtin.Int2048) : $(Builtin.Int32, Builtin.Int1)
+// Swift.Int32._convertFromBuiltinIntegerLiteral (Swift.Int32.Type)(Builtin.IntLiteral) -> Swift.Int32
+sil public_external [transparent] @$sSi33_convertFromBuiltinIntegerLiteralySiBI_cSimF : $@convention(thin) (Builtin.IntLiteral, @thin Int32.Type) -> Int32 {
+bb0(%0 : $Builtin.IntLiteral, %1 : $@thin Int32.Type):
+  %3 = builtin "s_to_s_checked_trunc_IntLiteral_Int32"(%0 : $Builtin.IntLiteral) : $(Builtin.Int32, Builtin.Int1)
   %4 = tuple_extract %3 : $(Builtin.Int32, Builtin.Int1), 0 // user: %5
   %5 = struct $Int32 (%4 : $Builtin.Int32)           // user: %6
   return %5 : $Int32                                // id: %6
diff --git a/test/Sema/diag_max_builtin_overflows.swift b/test/Sema/diag_max_builtin_overflows.swift
index 3209a0c..207b70a 100644
--- a/test/Sema/diag_max_builtin_overflows.swift
+++ b/test/Sema/diag_max_builtin_overflows.swift
@@ -1,7 +1,11 @@
 // RUN: %target-typecheck-verify-swift
 //
-// Tests that check whether large literals that are outside the range
-// of Builtin.Int2048 are diagnosed in the Sema phase.
+// These tests used to verify that large literals that were outside the
+// range of the maximum integer literal type were diagnosed in Sema.
+// Now it tests that they aren't diagnosed at all.
+//
+// ...also this test is somewhat slow to type-check and may indicate that
+// we're doing a lot of unnecessary copies of these values.
 
 import StdlibUnittest
 
@@ -16,12 +20,10 @@
 
   // Smallest positive integer that overflows 2048 bits
   let firstOverflow: Int64 = 0x80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
-  // expected-error@-1 {{integer literal needs 2049 bits, exceeding limit of 2048 bits}}
   _blackHole(firstOverflow)
 
   // Largest negative integer that overflows 2048 bits
   let firstNegOverflow: Int64 = -0x80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
-  // expected-error@-1 {{integer literal needs 2049 bits, exceeding limit of 2048 bits}}
   _blackHole(firstNegOverflow)
 
   let max2048Dec: Int64 = 16158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115327
@@ -33,13 +35,11 @@
 
   // Smallest positive integer that overflows 2048 bits
   let firstOverflowDec: Int64 = 16158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115328
-  // expected-error@-1 {{integer literal needs 2049 bits, exceeding limit of 2048 bits}}
-  _blackHole(firstOverflow)
+  _blackHole(firstOverflowDec)
 
   // Largest negative integer that overflows 2048 bits
   let firstNegOverflowDec: Int64 = -16158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115329
-  // expected-error@-1 {{integer literal needs 2049 bits, exceeding limit of 2048 bits}}
-  _blackHole(firstOverflow)
+  _blackHole(firstNegOverflowDec)
 
   // testing correct handling of C-Octal representation
   let x: Int64 = 00016158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115327
@@ -52,7 +52,6 @@
 func testMaxIntLiteralOverflowInArithmetic() {
   _blackHole(
     -00016158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115329 - 1)
-  // expected-error@-1 {{integer literal needs 2049 bits, exceeding limit of 2048 bits}}
 
   // Note that in the following test cases there is no literal overflow,
   // but there is an arithmetic overflow, which would be detected by the
@@ -64,17 +63,15 @@
     -00016158503035655503650357438344334975980222051334857742016065172713762327569433945446598600705761456731844358980460949009747059779575245460547544076193224141560315438683650498045875098875194826053398028819192033784138396109321309878080919047169238085235290822926018152521443787945770532904303776199561965192760957166694834171210342487393282284747428088017663161029038902829665513096354230157075129296432088558362971801859230928678799175576150822952201848806616643615613562842355410104862578550863465661734839271290328348967522998634176499319107762583194718667771801067716614802322659239302476074096777926805529798115327 + 1)
 }
 
-func testMaxInLiteralOverflowInEnum() {
+func testMaxIntLiteralOverflowInEnum() {
 
   enum TernaryDigit: Int8 {
     case zero = 0, one, two
   }
 
   _blackHole(TernaryDigit(rawValue: 0x800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000))
-  // expected-error@-1 {{integer literal needs 2053 bits, exceeding limit of 2048 bits}}
 
-  enum BuggyTernaryDigit: Int8 { // expected-error {{'BuggyTernaryDigit' declares raw type 'Int8', but does not conform to RawRepresentable and conformance could not be synthesized}}
+  enum BuggyTernaryDigit: Int8 {
     case zero = 0x800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, one, two
-    // expected-error@-1 {{integer literal needs 2053 bits, exceeding limit of 2048 bits}}
   }
 }
diff --git a/test/Serialization/Inputs/def_basic.sil b/test/Serialization/Inputs/def_basic.sil
index d7ce01f..50f6ada 100644
--- a/test/Serialization/Inputs/def_basic.sil
+++ b/test/Serialization/Inputs/def_basic.sil
@@ -885,22 +885,22 @@
 // CHECK-LABEL: [noinline] @noinline_callee
 sil [transparent] [serialized] [noinline] @noinline_callee : $@convention(thin) () -> Int {
 bb0:
-  %0 = function_ref @$sSi33_convertFromBuiltinIntegerLiteralySiBi2048_cSimF : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+  %0 = function_ref @$sSi33_convertFromBuiltinIntegerLiteralySiBI_cSimF : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
   %1 = metatype $@thin Int.Type
-  %2 = integer_literal $Builtin.Int2048, 0
-  %3 = apply %0(%2, %1) : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+  %2 = integer_literal $Builtin.IntLiteral, 0
+  %3 = apply %0(%2, %1) : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
   return %3 : $Int
 }
 // CHECK-LABEL: [always_inline] @always_inline_callee
 sil [transparent] [serialized] [always_inline] @always_inline_callee : $@convention(thin) () -> Int {
 bb0:
-  %0 = function_ref @$sSi33_convertFromBuiltinIntegerLiteralySiBi2048_cSimF : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+  %0 = function_ref @$sSi33_convertFromBuiltinIntegerLiteralySiBI_cSimF : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
   %1 = metatype $@thin Int.Type
-  %2 = integer_literal $Builtin.Int2048, 0
-  %3 = apply %0(%2, %1) : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+  %2 = integer_literal $Builtin.IntLiteral, 0
+  %3 = apply %0(%2, %1) : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
   return %3 : $Int
 }
-sil [transparent] [serialized] [transparent] @$sSi33_convertFromBuiltinIntegerLiteralySiBi2048_cSimF : $@convention(thin) (Builtin.Int2048, @thin Int.Type) -> Int
+sil [transparent] [serialized] [transparent] @$sSi33_convertFromBuiltinIntegerLiteralySiBI_cSimF : $@convention(thin) (Builtin.IntLiteral, @thin Int.Type) -> Int
 
 // CHECK-LABEL: [_semantics "foo"] @test_semantics : $@convention(thin) () -> ()
 sil [transparent] [serialized] [_semantics "foo"] @test_semantics : $@convention(thin) () -> () {
diff --git a/test/Serialization/Inputs/xref-generic-params-other-extensions-constrained.swift b/test/Serialization/Inputs/xref-generic-params-other-extensions-constrained.swift
new file mode 100644
index 0000000..2f5b721
--- /dev/null
+++ b/test/Serialization/Inputs/xref-generic-params-other-extensions-constrained.swift
@@ -0,0 +1,28 @@
+public struct OuterNonGeneric {}
+extension OuterNonGeneric {
+  public struct InnerNonGeneric {}
+  public struct InnerGeneric<Y1, Y2> {}
+}
+
+public struct OuterGeneric<X1, X2> {}
+extension OuterGeneric {
+  public struct InnerNonGeneric {}
+  public struct InnerGeneric<Y1, Y2> {}
+}
+
+
+extension OuterNonGeneric.InnerNonGeneric {
+  public typealias AliasTy = ()
+}
+
+extension OuterNonGeneric.InnerGeneric where Y1: Equatable {
+  public typealias AliasTy = (Y1, Y2)
+}
+
+extension OuterGeneric.InnerNonGeneric where X1: Equatable {
+  public typealias AliasTy = (X1, X2)
+}
+
+extension OuterGeneric.InnerGeneric where X1: Equatable, Y1: Equatable {
+  public typealias AliasTy = (X1, X2, Y1, Y2)
+}
diff --git a/test/Serialization/Inputs/xref-generic-params-other-extensions-mixed.swift b/test/Serialization/Inputs/xref-generic-params-other-extensions-mixed.swift
new file mode 100644
index 0000000..5ea2902
--- /dev/null
+++ b/test/Serialization/Inputs/xref-generic-params-other-extensions-mixed.swift
@@ -0,0 +1,19 @@
+public struct OuterNonGeneric {}
+extension OuterNonGeneric {
+  public struct InnerNonGeneric {
+    public typealias AliasTy = ()
+  }
+  public struct InnerGeneric<Y1, Y2> {
+    public typealias AliasTy = (Y1, Y2)
+  }
+}
+
+public struct OuterGeneric<X1, X2> {}
+extension OuterGeneric {
+  public struct InnerNonGeneric {
+    public typealias AliasTy = (X1, X2)
+  }
+  public struct InnerGeneric<Y1, Y2> {
+    public typealias AliasTy = (X1, X2, Y1, Y2)
+  }
+}
diff --git a/test/Serialization/Inputs/xref-generic-params-other-extensions.swift b/test/Serialization/Inputs/xref-generic-params-other-extensions.swift
new file mode 100644
index 0000000..c7ef407
--- /dev/null
+++ b/test/Serialization/Inputs/xref-generic-params-other-extensions.swift
@@ -0,0 +1,28 @@
+public struct OuterNonGeneric {}
+extension OuterNonGeneric {
+  public struct InnerNonGeneric {}
+  public struct InnerGeneric<Y1, Y2> {}
+}
+
+public struct OuterGeneric<X1, X2> {}
+extension OuterGeneric {
+  public struct InnerNonGeneric {}
+  public struct InnerGeneric<Y1, Y2> {}
+}
+
+
+extension OuterNonGeneric.InnerNonGeneric {
+  public typealias AliasTy = ()
+}
+
+extension OuterNonGeneric.InnerGeneric {
+  public typealias AliasTy = (Y1, Y2)
+}
+
+extension OuterGeneric.InnerNonGeneric {
+  public typealias AliasTy = (X1, X2)
+}
+
+extension OuterGeneric.InnerGeneric {
+  public typealias AliasTy = (X1, X2, Y1, Y2)
+}
diff --git a/test/Serialization/Inputs/xref-generic-params-other.swift b/test/Serialization/Inputs/xref-generic-params-other.swift
new file mode 100644
index 0000000..1f9e334
--- /dev/null
+++ b/test/Serialization/Inputs/xref-generic-params-other.swift
@@ -0,0 +1,17 @@
+public struct OuterNonGeneric {
+  public struct InnerNonGeneric {
+    public typealias AliasTy = ()
+  }
+  public struct InnerGeneric<Y1, Y2> {
+    public typealias AliasTy = (Y1, Y2)
+  }
+}
+
+public struct OuterGeneric<X1, X2> {
+  public struct InnerNonGeneric {
+    public typealias AliasTy = (X1, X2)
+  }
+  public struct InnerGeneric<Y1, Y2> {
+    public typealias AliasTy = (X1, X2, Y1, Y2)
+  }
+}
diff --git a/test/Serialization/inherited-initializer.swift b/test/Serialization/inherited-initializer.swift
index 34c40b1..b7beffd 100644
--- a/test/Serialization/inherited-initializer.swift
+++ b/test/Serialization/inherited-initializer.swift
@@ -14,8 +14,8 @@
   // CHECK: apply [[INIT]]([[ARG]], {{%.+}})
   _ = InheritsInit()
 
-  // CHECK: [[VALUE:%.+]] = integer_literal $Builtin.Int2048, 5
-  // CHECK: [[ARG:%.+]] = apply {{%.+}}([[VALUE]], {{%.+}}) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
+  // CHECK: [[VALUE:%.+]] = integer_literal $Builtin.IntLiteral, 5
+  // CHECK: [[ARG:%.+]] = apply {{%.+}}([[VALUE]], {{%.+}}) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
   // CHECK: [[INIT:%.+]] = function_ref @$s4main12InheritsInitCyACSicfC
   // CHECK: apply [[INIT]]([[ARG]], {{%.+}})
   _ = InheritsInit(5)
diff --git a/test/Serialization/xref-extensions.swift b/test/Serialization/xref-extensions-counters.swift
similarity index 100%
rename from test/Serialization/xref-extensions.swift
rename to test/Serialization/xref-extensions-counters.swift
diff --git a/test/Serialization/xref-generic-params.swift b/test/Serialization/xref-generic-params.swift
new file mode 100644
index 0000000..6e7ab1a
--- /dev/null
+++ b/test/Serialization/xref-generic-params.swift
@@ -0,0 +1,40 @@
+// RUN: %empty-directory(%t)
+
+// Run the same test several times, providing the nested types a different way
+// each time.
+
+// RUN: %target-swift-frontend -emit-module -o %t/a.swiftmodule -primary-file %s %S/Inputs/xref-generic-params-other.swift -module-name main
+// RUN: %target-swift-frontend -emit-module -o %t/b.swiftmodule %s -primary-file %S/Inputs/xref-generic-params-other.swift -module-name main
+// RUN: %target-swift-frontend -merge-modules -emit-module -o %t/main.swiftmodule %t/a.swiftmodule %t/b.swiftmodule -module-name main
+// RUN: %target-swift-ide-test -print-module -module-to-print=main -I %t -source-filename=x | %FileCheck %s
+
+// RUN: %target-swift-frontend -emit-module -o %t/a-extensions.swiftmodule -primary-file %s %S/Inputs/xref-generic-params-other-extensions.swift -module-name extensions
+// RUN: %target-swift-frontend -emit-module -o %t/b-extensions.swiftmodule %s -primary-file %S/Inputs/xref-generic-params-other-extensions.swift -module-name extensions
+// RUN: %target-swift-frontend -merge-modules -emit-module -o %t/extensions.swiftmodule %t/a-extensions.swiftmodule %t/b-extensions.swiftmodule -module-name extensions
+// RUN: %target-swift-ide-test -print-module -module-to-print=extensions -I %t -source-filename=x | %FileCheck %s
+
+// RUN: %target-swift-frontend -emit-module -o %t/a-extensions_mixed.swiftmodule -primary-file %s %S/Inputs/xref-generic-params-other-extensions-mixed.swift -module-name extensions_mixed
+// RUN: %target-swift-frontend -emit-module -o %t/b-extensions_mixed.swiftmodule %s -primary-file %S/Inputs/xref-generic-params-other-extensions-mixed.swift -module-name extensions_mixed
+// RUN: %target-swift-frontend -merge-modules -emit-module -o %t/extensions_mixed.swiftmodule %t/a-extensions_mixed.swiftmodule %t/b-extensions_mixed.swiftmodule -module-name extensions_mixed
+// RUN: %target-swift-ide-test -print-module -module-to-print=extensions_mixed -I %t -source-filename=x | %FileCheck %s
+
+// RUN: %target-swift-frontend -emit-module -o %t/a-extensions_constrained.swiftmodule -primary-file %s %S/Inputs/xref-generic-params-other-extensions-constrained.swift -module-name extensions_constrained
+// RUN: %target-swift-frontend -emit-module -o %t/b-extensions_constrained.swiftmodule %s -primary-file %S/Inputs/xref-generic-params-other-extensions-constrained.swift -module-name extensions_constrained
+// RUN: %target-swift-frontend -merge-modules -emit-module -o %t/extensions_constrained.swiftmodule %t/a-extensions_constrained.swiftmodule %t/b-extensions_constrained.swiftmodule -module-name extensions_constrained
+// RUN: %target-swift-ide-test -print-module -module-to-print=extensions_constrained -I %t -source-filename=x | %FileCheck %s
+
+public struct A: Equatable {}
+public struct B: Equatable {}
+public struct C: Equatable {}
+public struct D: Equatable {}
+
+// CHECK-LABEL: func test(
+public func test(
+// CHECK-SAME: _: OuterNonGeneric.InnerNonGeneric.AliasTy
+  _: OuterNonGeneric.InnerNonGeneric.AliasTy,
+// CHECK-SAME: _: OuterNonGeneric.InnerGeneric<C, D>.AliasTy
+  _: OuterNonGeneric.InnerGeneric<C, D>.AliasTy,
+// CHECK-SAME: _: OuterGeneric<A, B>.InnerNonGeneric.AliasTy
+  _: OuterGeneric<A, B>.InnerNonGeneric.AliasTy,
+// CHECK-SAME: _: OuterGeneric<A, B>.InnerGeneric<C, D>.AliasTy
+  _: OuterGeneric<A, B>.InnerGeneric<C, D>.AliasTy) {}
diff --git a/test/api-digester/Inputs/stdlib-stable-abi.json b/test/api-digester/Inputs/stdlib-stable-abi.json
index 567ad36..67a09f2 100644
--- a/test/api-digester/Inputs/stdlib-stable-abi.json
+++ b/test/api-digester/Inputs/stdlib-stable-abi.json
@@ -40431,11 +40431,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:s35_ExpressibleByBuiltinIntegerLiteralP08_builtindE0xBi2048__tcfc",
+          "usr": "s:s35_ExpressibleByBuiltinIntegerLiteralP08_builtindE0xBI__tcfc",
           "moduleName": "Swift",
           "genericSig": "<τ_0_0 where τ_0_0 : _ExpressibleByBuiltinIntegerLiteral>",
           "protocolReq": true
@@ -75430,11 +75430,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:Sf22_builtinIntegerLiteralSfBi2048__tcfc",
+          "usr": "s:Sf22_builtinIntegerLiteralSfBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -78487,11 +78487,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:Sd22_builtinIntegerLiteralSdBi2048__tcfc",
+          "usr": "s:Sd22_builtinIntegerLiteralSdBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -81771,11 +81771,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:s7Float80V22_builtinIntegerLiteralABBi2048__tcfc",
+          "usr": "s:s7Float80V22_builtinIntegerLiteralABBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -93712,11 +93712,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:s5UInt8V22_builtinIntegerLiteralABBi2048__tcfc",
+          "usr": "s:s5UInt8V22_builtinIntegerLiteralABBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -97012,11 +97012,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:s4Int8V22_builtinIntegerLiteralABBi2048__tcfc",
+          "usr": "s:s4Int8V22_builtinIntegerLiteralABBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -100294,11 +100294,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:s6UInt16V22_builtinIntegerLiteralABBi2048__tcfc",
+          "usr": "s:s6UInt16V22_builtinIntegerLiteralABBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -103517,11 +103517,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:s5Int16V22_builtinIntegerLiteralABBi2048__tcfc",
+          "usr": "s:s5Int16V22_builtinIntegerLiteralABBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -106747,11 +106747,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:s6UInt32V22_builtinIntegerLiteralABBi2048__tcfc",
+          "usr": "s:s6UInt32V22_builtinIntegerLiteralABBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -109884,11 +109884,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:s5Int32V22_builtinIntegerLiteralABBi2048__tcfc",
+          "usr": "s:s5Int32V22_builtinIntegerLiteralABBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -113087,11 +113087,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:s6UInt64V22_builtinIntegerLiteralABBi2048__tcfc",
+          "usr": "s:s6UInt64V22_builtinIntegerLiteralABBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -116160,11 +116160,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:s5Int64V22_builtinIntegerLiteralABBi2048__tcfc",
+          "usr": "s:s5Int64V22_builtinIntegerLiteralABBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -119299,11 +119299,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:Su22_builtinIntegerLiteralSuBi2048__tcfc",
+          "usr": "s:Su22_builtinIntegerLiteralSuBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
@@ -122534,11 +122534,11 @@
             {
               "kind": "TypeNominal",
               "name": "BuiltinInteger",
-              "printedName": "Builtin.Int2048"
+              "printedName": "Builtin.IntLiteral"
             }
           ],
           "declKind": "Constructor",
-          "usr": "s:Si22_builtinIntegerLiteralSiBi2048__tcfc",
+          "usr": "s:Si22_builtinIntegerLiteralSiBI__tcfc",
           "moduleName": "Swift",
           "declAttributes": [
             "Transparent"
diff --git a/test/api-digester/Outputs/stability-stdlib-abi.swift.expected b/test/api-digester/Outputs/stability-stdlib-abi.swift.expected
index 2a07cc6..7c828c1 100644
--- a/test/api-digester/Outputs/stability-stdlib-abi.swift.expected
+++ b/test/api-digester/Outputs/stability-stdlib-abi.swift.expected
@@ -11,11 +11,20 @@
 Constructor _BridgeStorage.init(native:bits:) has been removed
 Constructor _BridgeableMetatype.init(value:) has been removed
 Func AnyHashable._downCastConditional(into:) has been removed
+Func Collection.prefix(through:) has been removed
+Func Collection.prefix(upTo:) has been removed
+Func Collection.suffix(from:) has been removed
+Func Sequence.filter(_:) has been removed
+Func Sequence.forEach(_:) has been removed
+Func Sequence.map(_:) has been removed
 Func _BridgeStorage.isNativeWithClearedSpareBits(_:) has been removed
 Func _BridgeStorage.isUniquelyReferenced_native_noSpareBits() has been removed
 Func _CocoaDictionary.Index.copy() has been removed
 Func _ContiguousArrayStorage._getNonVerbatimBridgedHeapBuffer() has been removed
 Func _ContiguousArrayStorage._withVerbatimBridgedUnsafeBufferImpl(_:) has been removed
+Func _SequenceWrapper.filter(_:) has been removed
+Func _SequenceWrapper.forEach(_:) has been removed
+Func _SequenceWrapper.map(_:) has been removed
 Func __ContiguousArrayStorageBase._getNonVerbatimBridgedHeapBuffer() has been removed
 Func __EmptyArrayStorage._getNonVerbatimBridgedHeapBuffer() has been removed
 Func __SwiftDeferredNSArray._destroyBridgedStorage(_:) has been removed
@@ -26,20 +35,45 @@
 Protocol _HeapBufferHeader_ has been removed
 Struct _ConcreteHashableBox has been removed
 Struct _HeapBufferHeader has been removed
+Struct _SipHash13 has been removed
+Struct _SipHash13Core has been removed
+Struct _SipHash24 has been removed
+Struct _SipHashState has been removed
 Subscript ManagedBufferPointer.subscript(_:) has been removed
+Var AnyBidirectionalCollection.first has been removed
+Var AnyBidirectionalCollection.last has been removed
+Var AnyCollection.first has been removed
+Var AnyRandomAccessCollection.first has been removed
+Var AnyRandomAccessCollection.last has been removed
+Var BidirectionalCollection.last has been removed
+Var Collection.first has been removed
+Var Dictionary.first has been removed
+Var LazyCollection.first has been removed
+Var LazyCollection.last has been removed
+Var LazyMapCollection.first has been removed
+Var LazyMapCollection.last has been removed
 Var ManagedBufferPointer.baseAddress has been removed
 Var ManagedBufferPointer.storage has been removed
 Var ManagedBufferPointer.value has been removed
 Var Optional._nilSentinel has been removed
+Var Set.first has been removed
+Var _AnyBidirectionalCollectionBox._last has been removed
+Var _AnyCollectionBox._first has been removed
 Var _ArrayBuffer.deferredTypeCheckMask has been removed
+Var _BidirectionalCollectionBox._first has been removed
+Var _BidirectionalCollectionBox._last has been removed
 Var _BridgeStorage._isTagged has been removed
 Var _BridgeStorage.nativeInstance_noSpareBits has been removed
 Var _BridgeStorage.spareBits has been removed
 Var _BridgeableMetatype.value has been removed
 Var _CocoaDictionary.Index._object has been removed
 Var _CocoaSet.Index._object has been removed
+Var _CollectionBox._first has been removed
+Var _RandomAccessCollectionBox._first has been removed
+Var _RandomAccessCollectionBox._last has been removed
 Var __SwiftDeferredNSArray._heapBufferBridged has been removed
 Var __SwiftDeferredNSArray._heapBufferBridgedPtr has been removed
+Var Hasher._core has declared type change from _BufferingHasher<_SipHash13Core> to _BufferingHasher<Hasher._Core>
 
 /* Moved Decls */
 
diff --git a/test/api-digester/Outputs/stability-stdlib-source.swift.expected b/test/api-digester/Outputs/stability-stdlib-source.swift.expected
index e548788..cf738e4 100644
--- a/test/api-digester/Outputs/stability-stdlib-source.swift.expected
+++ b/test/api-digester/Outputs/stability-stdlib-source.swift.expected
@@ -4,6 +4,28 @@
 /* RawRepresentable Changes */
 
 /* Removed Decls */
+Func Collection.prefix(through:) has been removed
+Func Collection.prefix(upTo:) has been removed
+Func Collection.suffix(from:) has been removed
+Func Sequence.filter(_:) has been removed
+Func Sequence.forEach(_:) has been removed
+Func Sequence.map(_:) has been removed
+Func _SequenceWrapper.filter(_:) has been removed
+Func _SequenceWrapper.forEach(_:) has been removed
+Func _SequenceWrapper.map(_:) has been removed
+Var AnyBidirectionalCollection.first has been removed
+Var AnyBidirectionalCollection.last has been removed
+Var AnyCollection.first has been removed
+Var AnyRandomAccessCollection.first has been removed
+Var AnyRandomAccessCollection.last has been removed
+Var BidirectionalCollection.last has been removed
+Var Collection.first has been removed
+Var Dictionary.first has been removed
+Var LazyCollection.first has been removed
+Var LazyCollection.last has been removed
+Var LazyMapCollection.first has been removed
+Var LazyMapCollection.last has been removed
+Var Set.first has been removed
 
 /* Moved Decls */
 
diff --git a/validation-test/Evolution/Inputs/protocol_add_requirements.swift b/validation-test/Evolution/Inputs/protocol_add_requirements.swift
index ba05853..d0c0f2e 100644
--- a/validation-test/Evolution/Inputs/protocol_add_requirements.swift
+++ b/validation-test/Evolution/Inputs/protocol_add_requirements.swift
@@ -19,7 +19,7 @@
   func unimportantOperation() -> Element
 
 #if AFTER
-  func uselessOperation() -> Element
+  @_weakLinked func uselessOperation() -> Element
 #endif
 }
 
@@ -29,7 +29,7 @@
   }
 
 #if AFTER
-  public func uselessOperation() -> Element {
+  @_weakLinked public func uselessOperation() -> Element {
     return unimportantOperation().increment()
   }
 #endif
@@ -56,12 +56,12 @@
   init(name: String)
 
 #if AFTER
-  init?(nickname: String)
+  @_weakLinked init?(nickname: String)
 #endif
 }
 
 extension AddConstructorsProtocol {
-  public init?(nickname: String) {
+  @_weakLinked public init?(nickname: String) {
     if nickname == "" {
       return nil
     }
@@ -85,15 +85,15 @@
   var maxRPM: Int { get set }
 
 #if AFTER
-  var maxSafeSpeed: Int { get set }
-  var minSafeSpeed: Int { get nonmutating set }
-  var redLine: Int { mutating get set }
+  @_weakLinked var maxSafeSpeed: Int { get set }
+  @_weakLinked var minSafeSpeed: Int { get nonmutating set }
+  @_weakLinked var redLine: Int { mutating get set }
 #endif
 }
 
 extension AddPropertiesProtocol {
 #if AFTER
-  public var maxSafeSpeed: Int {
+  @_weakLinked public var maxSafeSpeed: Int {
     get {
       return topSpeed / 2
     }
@@ -102,7 +102,7 @@
     }
   }
 
-  public var minSafeSpeed: Int {
+  @_weakLinked public var minSafeSpeed: Int {
     get {
       return topSpeed / 4
     }
@@ -111,7 +111,7 @@
     }
   }
 
-  public var redLine: Int {
+  @_weakLinked public var redLine: Int {
     get {
       return maxRPM - 2000
     }
@@ -153,12 +153,12 @@
   mutating func set(key key: Key, value: Value)
 
 #if AFTER
-  subscript(key: Key) -> Value { get set }
+  @_weakLinked subscript(key: Key) -> Value { get set }
 #endif
 }
 
 extension AddSubscriptProtocol {
-  public subscript(key: Key) -> Value {
+  @_weakLinked public subscript(key: Key) -> Value {
     get {
       return get(key: key)
     }
@@ -188,8 +188,8 @@
 
 public protocol AddAssocTypesProtocol {
 #if AFTER
-  associatedtype AssocType = Self
-  associatedtype AssocType2: SimpleProtocol = Wrapper<AssocType>
+  @_weakLinked associatedtype AssocType = Self
+  @_weakLinked associatedtype AssocType2: SimpleProtocol = Wrapper<AssocType>
 #endif
 }
 
diff --git a/validation-test/Evolution/test_protocol_add_requirements.swift b/validation-test/Evolution/test_protocol_add_requirements.swift
index 2acfb7e..3a41559 100644
--- a/validation-test/Evolution/test_protocol_add_requirements.swift
+++ b/validation-test/Evolution/test_protocol_add_requirements.swift
@@ -1,4 +1,4 @@
-// RUN: %target-resilience-test --no-backward-deployment
+// RUN: %target-resilience-test
 // REQUIRES: executable_test
 
 import StdlibUnittest
diff --git a/validation-test/Evolution/test_protocol_reorder_requirements.swift b/validation-test/Evolution/test_protocol_reorder_requirements.swift
index 581f232..d7aef98 100644
--- a/validation-test/Evolution/test_protocol_reorder_requirements.swift
+++ b/validation-test/Evolution/test_protocol_reorder_requirements.swift
@@ -1,4 +1,4 @@
-// RUN: %target-resilience-test --no-backward-deployment
+// RUN: %target-resilience-test
 // REQUIRES: executable_test
 
 import StdlibUnittest
diff --git a/validation-test/stdlib/CollectionType.swift.gyb b/validation-test/stdlib/CollectionType.swift.gyb
index 52c6e73..77e9dfb 100644
--- a/validation-test/stdlib/CollectionType.swift.gyb
+++ b/validation-test/stdlib/CollectionType.swift.gyb
@@ -144,8 +144,6 @@
   return result
 }
 
-% for Implementation in [ 'Default', 'Custom' ]:
-
 %   for dispatch in [ 'Static', 'Generic' ]:
 
 CollectionTypeTests.test("filter/Collection/${Implementation}Implementation/${dispatch}") {
@@ -161,9 +159,6 @@
       let closureLifetimeTracker = LifetimeTracked(0)
       expectEqual(1, LifetimeTracked.instances)
       var timesClosureWasCalled = 0
-%     if Implementation == 'Custom':
-      MinimalCollectionWithCustomFilter<OpaqueValue<Int>>.timesFilterWasCalled = 0
-%     end
       var result = call${dispatch}CollectionFilter(s) {
         (element) in
         _blackHole(closureLifetimeTracker)
@@ -172,23 +167,17 @@
       }
       expectType([OpaqueValue<Int>].self, &result)
       expectEqual(test.expected, result.map { $0.value })
-%     if Implementation == 'Custom':
-      expectEqual(1, MinimalCollectionWithCustomFilter<OpaqueValue<Int>>.timesFilterWasCalled)
-%     end
-      expectEqual(
-        test.sequence, s.map { $0.value }, "collection should not be consumed")
+      expectEqual(test.sequence, s.map { $0.value }, 
+        "collection should not be consumed")
       expectEqual(test.sequence.count, timesClosureWasCalled,
         "filter() should be eager and should only call its predicate once per element")
-      expectGE(
-        2 * result.count, result.capacity,
+      expectGE(2 * result.count, result.capacity,
         "filter() should not reserve capacity"
         + "(it does not know how much the predicate will filter out)")
     }
   }
 }
 
-%   end
-
 % end
 
 //===----------------------------------------------------------------------===//
@@ -196,11 +185,7 @@
 //===----------------------------------------------------------------------===//
 var MinimalCollectionWithCustomMap_timesMapWasCalled: Int = 0
 
-% for Implementation in [ 'Default', 'Custom' ]:
-
-struct MinimalCollectionWith${Implementation}Map<Element>
-  : Collection {
-
+struct MinimalCollectionWithDefaultMap<Element>: Collection {
   init(_ data: [Element], underestimatedCount: UnderestimatedCountBehavior) {
     self._data = MinimalCollection(
       elements: data, underestimatedCount: underestimatedCount)
@@ -227,32 +212,8 @@
   }
 
   var _data: MinimalCollection<Element>
-
-
-%   if Implementation == 'Custom':
-
-  static var timesMapWasCalled: Int {
-    get {
-      return MinimalCollectionWithCustomMap_timesMapWasCalled
-    }
-    set {
-      MinimalCollectionWithCustomMap_timesMapWasCalled = newValue
-    }
-  }
-
-  func map<T>(
-    _ transform: (Element) throws -> T
-  ) rethrows -> [T] {
-    MinimalCollectionWithCustomMap.timesMapWasCalled += 1
-    return try _data.map(transform)
-  }
-
-%   end
-
 }
 
-% end
-
 func callStaticCollectionMap<T>(
   _ collection: MinimalCollectionWithDefaultMap<OpaqueValue<Int>>,
   transform: (OpaqueValue<Int>) -> T
@@ -262,15 +223,6 @@
   return result
 }
 
-func callStaticCollectionMap<T>(
-  _ collection: MinimalCollectionWithCustomMap<OpaqueValue<Int>>,
-  transform: (OpaqueValue<Int>) -> T
-) -> [T] {
-  var result = collection.map(transform)
-  expectType([T].self, &result)
-  return result
-}
-
 func callGenericCollectionMap<C : Collection, T>(
   _ collection: C,
   transform: (C.Iterator.Element) -> T
@@ -280,9 +232,7 @@
   return result
 }
 
-% for Implementation in [ 'Default', 'Custom' ]:
-
-%   for dispatch in [ 'Static', 'Generic' ]:
+% for dispatch in [ 'Static', 'Generic' ]:
 
 CollectionTypeTests.test(
   "map/Collection/${Implementation}Implementation/${dispatch}"
@@ -293,19 +243,12 @@
       UnderestimatedCountBehavior.half,
       UnderestimatedCountBehavior.value(0)
     ] {
-      let s = MinimalCollectionWith${Implementation}Map<
-        OpaqueValue<Int>
-      >(
+      let s = MinimalCollectionWithDefaultMap<OpaqueValue<Int>>(
         test.sequence.map(OpaqueValue.init),
         underestimatedCount: underestimatedCountBehavior)
       let closureLifetimeTracker = LifetimeTracked(0)
       expectEqual(1, LifetimeTracked.instances)
       var timesClosureWasCalled = 0
-%     if Implementation == 'Custom':
-      MinimalCollectionWithCustomMap<
-        OpaqueValue<Int>
-      >.timesMapWasCalled = 0
-%     end
       var result = call${dispatch}CollectionMap(s) {
         (element: OpaqueValue<Int>) -> OpaqueValue<Int32> in
         _blackHole(closureLifetimeTracker)
@@ -314,12 +257,6 @@
       }
       expectType([OpaqueValue<Int32>].self, &result)
       expectEqual(test.expected, result.map { $0.value })
-%     if Implementation == 'Custom':
-      expectEqual(
-        1, MinimalCollectionWithCustomMap<
-          OpaqueValue<Int>
-        >.timesMapWasCalled)
-%     end
       expectEqual(test.sequence, s.map { $0.value },
         "collection should not be consumed")
       expectEqual(test.sequence.count, timesClosureWasCalled,
@@ -329,8 +266,6 @@
   }
 }
 
-%   end
-
 % end
 
 //===----------------------------------------------------------------------===//
@@ -603,15 +538,6 @@
   expectCustomizable(tester, tester.log.isEmpty)
 }
 
-//===----------------------------------------------------------------------===//
-// first
-//===----------------------------------------------------------------------===//
-
-CollectionTypeTests.test("first/dispatch") {
-  let tester = CollectionLog.dispatchTester([OpaqueValue(1)])
-  _ = tester.first
-  expectCustomizable(tester, tester.log.first)
-}
 
 //===----------------------------------------------------------------------===//
 // count
@@ -754,37 +680,6 @@
 }
 
 //===----------------------------------------------------------------------===//
-// prefix(through:)
-//===----------------------------------------------------------------------===//
-
-CollectionTypeTests.test("Collection/prefix(through:)/dispatch") {
-  let tester = CollectionLog.dispatchTester([1, 2, 3].map(OpaqueValue.init))
-  _ = tester.prefix(through: 1)
-  expectCustomizable(tester, tester.log.prefixThrough)
-}
-
-//===----------------------------------------------------------------------===//
-// prefix(upTo:)
-//===----------------------------------------------------------------------===//
-
-CollectionTypeTests.test("Collection/prefix(upTo:)/dispatch") {
-  let tester = CollectionLog.dispatchTester([OpaqueValue(1)])
-  _ = tester.prefix(upTo: 1)
-  expectCustomizable(tester, tester.log.prefixUpTo)
-}
-
-//===----------------------------------------------------------------------===//
-// suffix(from:)
-//===----------------------------------------------------------------------===//
-
-CollectionTypeTests.test("Collection/suffix(from:)/dispatch") {
-  let tester = CollectionLog.dispatchTester([1, 2, 3].map(OpaqueValue.init))
-  _ = tester.suffix(from: 1)
-  expectCustomizable(tester, tester.log.suffixFrom)
-}
-
-
-//===----------------------------------------------------------------------===//
 // MutableCollection
 //===----------------------------------------------------------------------===//
 
diff --git a/validation-test/stdlib/ExistentialCollection.swift.gyb b/validation-test/stdlib/ExistentialCollection.swift.gyb
index 371cf55..d0e173a 100644
--- a/validation-test/stdlib/ExistentialCollection.swift.gyb
+++ b/validation-test/stdlib/ExistentialCollection.swift.gyb
@@ -151,18 +151,6 @@
     _ = s.underestimatedCount
   }
 
-  Log.map.expectIncrement(Base.self) {
-    _ = s.map { $0 }
-  }
-
-  Log.filter.expectIncrement(Base.self) {
-    _ = s.filter { (_) in true }
-  }
-
-  Log.forEach.expectIncrement(Base.self) {
-    _ = s.forEach { (_) in }
-  }
-
   Log.dropFirst.expectIncrement(Base.self) {
     _ = s.dropFirst(0)
   }
@@ -331,23 +319,6 @@
     _blackHole(x)
   }
 %   end
-
-  Log.first.expectIncrement(Base.self) {
-    Log.startIndex.expectUnchanged(Base.self) {
-      Log.makeIterator.expectUnchanged(Base.self) {
-        _ = c.first
-      }
-    }
-  }
-
-%   if Traversal in ['Bidirectional', 'RandomAccess']:
-  BidirectionalCollectionLog.last.expectIncrement(Base.self) {
-    Log.endIndex.expectUnchanged(Base.self) {
-      _ = c.last
-    }
-  }
-%   end
-
 }
 %   end
 % end
diff --git a/validation-test/stdlib/Lazy.swift.gyb b/validation-test/stdlib/Lazy.swift.gyb
index e65d78a..3ca4705 100644
--- a/validation-test/stdlib/Lazy.swift.gyb
+++ b/validation-test/stdlib/Lazy.swift.gyb
@@ -745,7 +745,6 @@
   CollectionLog._customIndexOfEquatableElement.expectIncrement(baseType) {
     _ = s._customIndexOfEquatableElement(OpaqueValue(0))
   }
-  CollectionLog.first.expectIncrement(baseType) { _ = s.first }
 }
 
 //===--- Map --------------------------------------------------------------===//
@@ -843,9 +842,6 @@
   CollectionLog.isEmpty.expectIncrement(type(of: base)) {
     _ = mapped.isEmpty
   }
-  CollectionLog.first.expectIncrement(type(of: base)) {
-    _ = mapped.first
-  }
   CollectionLog.underestimatedCount.expectIncrement(type(of: base)) {
     _ = mapped.underestimatedCount
   }
diff --git a/validation-test/stdlib/MicroStdlib/Inputs/Swift.swift b/validation-test/stdlib/MicroStdlib/Inputs/Swift.swift
index 490b540..a2febd8 100644
--- a/validation-test/stdlib/MicroStdlib/Inputs/Swift.swift
+++ b/validation-test/stdlib/MicroStdlib/Inputs/Swift.swift
@@ -10,7 +10,7 @@
 }
 
 public typealias IntegerLiteralType = Int
-public typealias _MaxBuiltinIntegerType = Builtin.Int2048
+public typealias _MaxBuiltinIntegerType = Builtin.IntLiteral
 public typealias _MaxBuiltinFloatType = Builtin.FPIEEE80
 
 public protocol _ExpressibleByBuiltinIntegerLiteral {
@@ -37,7 +37,7 @@
     self = 0
   }
   public init(_builtinIntegerLiteral value: _MaxBuiltinIntegerType) {
-    let builtinValue = Builtin.truncOrBitCast_Int2048_Word(value)
+    let builtinValue = Builtin.s_to_s_checked_trunc_IntLiteral_Word(value).0
     self.value = builtinValue
   }
   public init(integerLiteral value: IntegerLiteralType) {
@@ -50,7 +50,7 @@
     self.init(integerLiteral: 0)
   }
   public init(_builtinIntegerLiteral value: _MaxBuiltinIntegerType) {
-    let builtinValue = Builtin.truncOrBitCast_Int2048_Int32(value)
+    let builtinValue = Builtin.s_to_s_checked_trunc_IntLiteral_Int32(value).0
     self.value = builtinValue
   }
   public init(integerLiteral value: IntegerLiteralType) {
@@ -64,7 +64,7 @@
     self.init(integerLiteral: 0)
   }
   public init(_builtinIntegerLiteral value: _MaxBuiltinIntegerType) {
-    let builtinValue = Builtin.truncOrBitCast_Int2048_Int8(value)
+    let builtinValue = Builtin.s_to_s_checked_trunc_IntLiteral_Int8(value).0
     self.value = builtinValue
   }
   public init(integerLiteral value: IntegerLiteralType) {
diff --git a/validation-test/stdlib/SequenceType.swift.gyb b/validation-test/stdlib/SequenceType.swift.gyb
index ed11996..6b1316b 100644
--- a/validation-test/stdlib/SequenceType.swift.gyb
+++ b/validation-test/stdlib/SequenceType.swift.gyb
@@ -725,12 +725,6 @@
 // filter()
 //===----------------------------------------------------------------------===//
 
-SequenceTypeTests.test("filter/Sequence/Dispatch") {
-  let tester = SequenceLog.dispatchTester([OpaqueValue(1)])
-  _ = tester.filter { _ in false }
-  expectCustomizable(tester, tester.log.filter)
-}
-
 SequenceTypeTests.test("filter/Sequence/Semantics") {
   for test in filterTests {
     for underestimatedCountBehavior in [
@@ -838,9 +832,7 @@
   return result
 }
 
-% for Implementation in ['Default', 'Custom']:
-
-%   for dispatch in ['Static', 'Generic']:
+% for dispatch in ['Static', 'Generic']:
 
 SequenceTypeTests.test(
   "map/Sequence/${Implementation}Implementation/${dispatch}"
@@ -857,9 +849,6 @@
       let closureLifetimeTracker = LifetimeTracked(0)
       expectEqual(1, LifetimeTracked.instances)
       var timesClosureWasCalled = 0
-%     if Implementation == 'Custom':
-      MinimalSequenceWithCustomMap<OpaqueValue<Int>>.timesMapWasCalled = 0
-%     end
       var result = call${dispatch}SequenceMap(s) {
         (element: OpaqueValue<Int>) -> OpaqueValue<Int32> in
         _blackHole(closureLifetimeTracker)
@@ -868,21 +857,14 @@
       }
       expectType([OpaqueValue<Int32>].self, &result)
       expectEqual(test.expected, result.map { $0.value })
-%     if Implementation == 'Custom':
-      expectEqual(
-        1, MinimalSequenceWithCustomMap<OpaqueValue<Int>>.timesMapWasCalled)
-%     end
       expectEqual([], s.map { $0.value }, "sequence should be consumed")
-      expectEqual(
-        test.sequence.count, timesClosureWasCalled,
+      expectEqual(        test.sequence.count, timesClosureWasCalled,
         "map() should be eager and should only call its predicate"
         + "once per element")
     }
   }
 }
 
-%   end
-
 % end
 
 //===----------------------------------------------------------------------===//
@@ -962,16 +944,6 @@
 }
 
 //===----------------------------------------------------------------------===//
-// forEach()
-//===----------------------------------------------------------------------===//
-
-SequenceTypeTests.test("forEach/dispatch") {
-  let tester = SequenceLog.dispatchTester([OpaqueValue(1)])
-  tester.forEach { print($0) }
-  expectCustomizable(tester, tester.log.forEach)
-}
-
-//===----------------------------------------------------------------------===//
 // dropFirst()
 //===----------------------------------------------------------------------===//
 
diff --git a/validation-test/stdlib/SequenceWrapperTest.swift b/validation-test/stdlib/SequenceWrapperTest.swift
index 4ae6c9d..e29524b 100644
--- a/validation-test/stdlib/SequenceWrapperTest.swift
+++ b/validation-test/stdlib/SequenceWrapperTest.swift
@@ -60,17 +60,6 @@
     dispatchLog.underestimatedCount)
 }
 
-sequenceWrapperTests.test("Dispatch/map") {
-  expectWrapperDispatch(
-    direct.map { $0 }, indirect.map { $0 }, dispatchLog.map)
-}
-
-sequenceWrapperTests.test("Dispatch/filter") {
-  expectWrapperDispatch(
-    direct.filter { _ in true },
-    indirect.filter { _ in true }, dispatchLog.filter)
-}
-
 sequenceWrapperTests.test("Dispatch/_customContainsEquatableElement") {
   expectWrapperDispatch(
     direct._customContainsEquatableElement(OpaqueValue(1)),
diff --git a/validation-test/stdlib/SipHash.swift b/validation-test/stdlib/SipHash.swift
index 060cd93..dd15adf 100644
--- a/validation-test/stdlib/SipHash.swift
+++ b/validation-test/stdlib/SipHash.swift
@@ -1,4 +1,4 @@
-// RUN: %target-run-stdlib-swiftgyb
+// RUN: %target-run-stdlib-swift
 // REQUIRES: executable_test
 
 import StdlibUnittest
@@ -8,12 +8,6 @@
 extension Hasher {
   typealias HashValue = Int
 }
-extension _SipHash13 {
-  typealias HashValue = UInt64
-}
-extension _SipHash24 {
-  typealias HashValue = UInt64
-}
 
 struct SipHashTest {
   let input: [UInt8]
@@ -47,89 +41,6 @@
   }
 }
 
-let sipHash24Tests: [SipHashTest] = [
-  // Test vectors from the reference C implementation, which was released
-  // to public domain by:
-  //
-  // * Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>
-  // * Daniel J. Bernstein <djb@cr.yp.to>
-  SipHashTest(referenceVectorIndex: 0, output: 0x726fdb47dd0e0e31),
-  SipHashTest(referenceVectorIndex: 1, output: 0x74f839c593dc67fd),
-  SipHashTest(referenceVectorIndex: 2, output: 0x0d6c8009d9a94f5a),
-  SipHashTest(referenceVectorIndex: 3, output: 0x85676696d7fb7e2d),
-  SipHashTest(referenceVectorIndex: 4, output: 0xcf2794e0277187b7),
-  SipHashTest(referenceVectorIndex: 5, output: 0x18765564cd99a68d),
-  SipHashTest(referenceVectorIndex: 6, output: 0xcbc9466e58fee3ce),
-  SipHashTest(referenceVectorIndex: 7, output: 0xab0200f58b01d137),
-  SipHashTest(referenceVectorIndex: 8, output: 0x93f5f5799a932462),
-  SipHashTest(referenceVectorIndex: 9, output: 0x9e0082df0ba9e4b0),
-  SipHashTest(referenceVectorIndex: 10, output: 0x7a5dbbc594ddb9f3),
-  SipHashTest(referenceVectorIndex: 11, output: 0xf4b32f46226bada7),
-  SipHashTest(referenceVectorIndex: 12, output: 0x751e8fbc860ee5fb),
-  SipHashTest(referenceVectorIndex: 13, output: 0x14ea5627c0843d90),
-  SipHashTest(referenceVectorIndex: 14, output: 0xf723ca908e7af2ee),
-  SipHashTest(referenceVectorIndex: 15, output: 0xa129ca6149be45e5),
-  SipHashTest(referenceVectorIndex: 16, output: 0x3f2acc7f57c29bdb),
-  SipHashTest(referenceVectorIndex: 17, output: 0x699ae9f52cbe4794),
-  SipHashTest(referenceVectorIndex: 18, output: 0x4bc1b3f0968dd39c),
-  SipHashTest(referenceVectorIndex: 19, output: 0xbb6dc91da77961bd),
-  SipHashTest(referenceVectorIndex: 20, output: 0xbed65cf21aa2ee98),
-  SipHashTest(referenceVectorIndex: 21, output: 0xd0f2cbb02e3b67c7),
-  SipHashTest(referenceVectorIndex: 22, output: 0x93536795e3a33e88),
-  SipHashTest(referenceVectorIndex: 23, output: 0xa80c038ccd5ccec8),
-  SipHashTest(referenceVectorIndex: 24, output: 0xb8ad50c6f649af94),
-  SipHashTest(referenceVectorIndex: 25, output: 0xbce192de8a85b8ea),
-  SipHashTest(referenceVectorIndex: 26, output: 0x17d835b85bbb15f3),
-  SipHashTest(referenceVectorIndex: 27, output: 0x2f2e6163076bcfad),
-  SipHashTest(referenceVectorIndex: 28, output: 0xde4daaaca71dc9a5),
-  SipHashTest(referenceVectorIndex: 29, output: 0xa6a2506687956571),
-  SipHashTest(referenceVectorIndex: 30, output: 0xad87a3535c49ef28),
-  SipHashTest(referenceVectorIndex: 31, output: 0x32d892fad841c342),
-  SipHashTest(referenceVectorIndex: 32, output: 0x7127512f72f27cce),
-  SipHashTest(referenceVectorIndex: 33, output: 0xa7f32346f95978e3),
-  SipHashTest(referenceVectorIndex: 34, output: 0x12e0b01abb051238),
-  SipHashTest(referenceVectorIndex: 35, output: 0x15e034d40fa197ae),
-  SipHashTest(referenceVectorIndex: 36, output: 0x314dffbe0815a3b4),
-  SipHashTest(referenceVectorIndex: 37, output: 0x027990f029623981),
-  SipHashTest(referenceVectorIndex: 38, output: 0xcadcd4e59ef40c4d),
-  SipHashTest(referenceVectorIndex: 39, output: 0x9abfd8766a33735c),
-  SipHashTest(referenceVectorIndex: 40, output: 0x0e3ea96b5304a7d0),
-  SipHashTest(referenceVectorIndex: 41, output: 0xad0c42d6fc585992),
-  SipHashTest(referenceVectorIndex: 42, output: 0x187306c89bc215a9),
-  SipHashTest(referenceVectorIndex: 43, output: 0xd4a60abcf3792b95),
-  SipHashTest(referenceVectorIndex: 44, output: 0xf935451de4f21df2),
-  SipHashTest(referenceVectorIndex: 45, output: 0xa9538f0419755787),
-  SipHashTest(referenceVectorIndex: 46, output: 0xdb9acddff56ca510),
-  SipHashTest(referenceVectorIndex: 47, output: 0xd06c98cd5c0975eb),
-  SipHashTest(referenceVectorIndex: 48, output: 0xe612a3cb9ecba951),
-  SipHashTest(referenceVectorIndex: 49, output: 0xc766e62cfcadaf96),
-  SipHashTest(referenceVectorIndex: 50, output: 0xee64435a9752fe72),
-  SipHashTest(referenceVectorIndex: 51, output: 0xa192d576b245165a),
-  SipHashTest(referenceVectorIndex: 52, output: 0x0a8787bf8ecb74b2),
-  SipHashTest(referenceVectorIndex: 53, output: 0x81b3e73d20b49b6f),
-  SipHashTest(referenceVectorIndex: 54, output: 0x7fa8220ba3b2ecea),
-  SipHashTest(referenceVectorIndex: 55, output: 0x245731c13ca42499),
-  SipHashTest(referenceVectorIndex: 56, output: 0xb78dbfaf3a8d83bd),
-  SipHashTest(referenceVectorIndex: 57, output: 0xea1ad565322a1a0b),
-  SipHashTest(referenceVectorIndex: 58, output: 0x60e61c23a3795013),
-  SipHashTest(referenceVectorIndex: 59, output: 0x6606d7e446282b93),
-  SipHashTest(referenceVectorIndex: 60, output: 0x6ca4ecb15c5f91e1),
-  SipHashTest(referenceVectorIndex: 61, output: 0x9f626da15c9625f3),
-  SipHashTest(referenceVectorIndex: 62, output: 0xe51b38608ef25f57),
-  SipHashTest(referenceVectorIndex: 63, output: 0x958a324ceb064572),
-  // End of reference test vectors.
-
-  SipHashTest(
-    input: [
-      0x72, 0xdc, 0xde, 0xd4, 0x6d, 0xb4, 0xc8, 0xa1,
-      0xcf, 0x22, 0xe2, 0x7f, 0xe3, 0xf6, 0xe5, 0x6d,
-      0x8b, 0x66, 0x0b, 0xaf, 0xba, 0x16, 0x25, 0xf3,
-      0x63, 0x8e, 0x69, 0x80, 0xf3, 0x7e, 0xd6, 0xe3,
-    ],
-    seed: (0xa3432fc680796c34, 0x1173946a79aeaae5),
-    output: 0x058b04535972ff2b),
-]
-
 let sipHash13Tests: [SipHashTest] = [
   SipHashTest(referenceVectorIndex: 0, output: 0xabac0158050fc4dc),
   SipHashTest(referenceVectorIndex: 1, output: 0xc9f49bf37d57ca93),
@@ -237,25 +148,19 @@
   }
 }
 
-% for (Self, tests) in [
-%   ('Hasher', 'sipHash13Tests'),
-%   ('_SipHash13', 'sipHash13Tests'),
-%   ('_SipHash24', 'sipHash24Tests')
-% ]:
-
-SipHashTests.test("${Self}/combine(UnsafeRawBufferPointer)")
-  .forEach(in: ${tests}) { test in
-  var hasher = ${Self}(_rawSeed: test.seed)
+SipHashTests.test("Hasher/combine(UnsafeRawBufferPointer)")
+  .forEach(in: sipHash13Tests) { test in
+  var hasher = Hasher(_rawSeed: test.seed)
   test.input.withUnsafeBytes { hasher.combine(bytes: $0) }
   let hash = hasher.finalize()
-  expectEqual(${Self}.HashValue(truncatingIfNeeded: test.output), hash)
+  expectEqual(Hasher.HashValue(truncatingIfNeeded: test.output), hash)
 }
 
-SipHashTests.test("${Self}/combine(UnsafeRawBufferPointer)/pattern")
-  .forEach(in: cartesianProduct(${tests}, incrementalPatterns)) { test_ in
+SipHashTests.test("Hasher/combine(UnsafeRawBufferPointer)/pattern")
+  .forEach(in: cartesianProduct(sipHash13Tests, incrementalPatterns)) { test_ in
   let (test, pattern) = test_
 
-  var hasher = ${Self}(_rawSeed: test.seed)
+  var hasher = Hasher(_rawSeed: test.seed)
   var chunkSizes = Loop(pattern).makeIterator()
   var startIndex = 0
   while startIndex != test.input.endIndex {
@@ -267,43 +172,52 @@
     startIndex += chunkSize
   }
   let hash = hasher.finalize()
-  expectEqual(${Self}.HashValue(truncatingIfNeeded: test.output), hash)
+  expectEqual(Hasher.HashValue(truncatingIfNeeded: test.output), hash)
 }
 
-% for data_type in ['UInt', 'UInt64', 'UInt32', 'UInt16', 'UInt8']:
-SipHashTests.test("${Self}._combine(${data_type})")
-  .forEach(in: ${tests}) { test in
 
-  var hasher = ${Self}(_rawSeed: test.seed)
+func testIntegerType<I: FixedWidthInteger>(
+  _ type: I.Type,
+  combiner: @escaping (inout Hasher, I) -> Void) {
+  SipHashTests.test("Hasher._combine(\(type.self))")
+    .forEach(in: sipHash13Tests) { test in
 
-  // Load little-endian chunks and combine them into the hasher.
-  let bitWidth = ${data_type}.bitWidth
-  var i = 0
-  var count = 0
-  var chunk: ${data_type} = 0
-  while i < test.input.count {
-    chunk |= ${data_type}(test.input[i]) << (8 * count)
-    i += 1
-    count += 1
-    if 8 * count == bitWidth {
-      hasher._combine(chunk)
-      count = 0
-      chunk = 0
+    var hasher = Hasher(_rawSeed: test.seed)
+
+    // Load little-endian chunks and combine them into the hasher.
+    let bitWidth = I.bitWidth
+    var i = 0
+    var count = 0
+    var chunk: I = 0
+    while i < test.input.count {
+      chunk |= I(test.input[i]) << (8 * count)
+      i += 1
+      count += 1
+      if 8 * count == bitWidth {
+        combiner(&hasher, chunk)
+        count = 0
+        chunk = 0
+      }
     }
-  }
-  // Combine tail bytes.
-  if count > 0 {
-    hasher._combine(bytes: UInt64(truncatingIfNeeded: chunk), count: count)
-  }
+    // Combine tail bytes.
+    if count > 0 {
+      hasher._combine(bytes: UInt64(truncatingIfNeeded: chunk), count: count)
+    }
 
-  let hash = hasher.finalize()
-  expectEqual(${Self}.HashValue(truncatingIfNeeded: test.output), hash)
+    let hash = hasher.finalize()
+    expectEqual(Hasher.HashValue(truncatingIfNeeded: test.output), hash)
+  }
 }
-% end
 
-SipHashTests.test("${Self}/OperationsAfterFinalize") {
+testIntegerType(UInt.self) { $0._combine($1) }
+testIntegerType(UInt64.self) { $0._combine($1) }
+testIntegerType(UInt32.self) { $0._combine($1) }
+testIntegerType(UInt16.self) { $0._combine($1) }
+testIntegerType(UInt8.self) { $0._combine($1) }
+
+SipHashTests.test("Hasher/OperationsAfterFinalize") {
   // Verify that finalize is nonmutating.
-  var hasher1 = ${Self}(_rawSeed: (0, 0))
+  var hasher1 = Hasher(_rawSeed: (0, 0))
   hasher1._combine(1 as UInt8)
   _ = hasher1.finalize()
   // Hasher is now consumed. The operations below are illegal, but this isn't
@@ -314,13 +228,11 @@
   let hash1b = hasher1.finalize()
   expectEqual(hash1a, hash1b)
 
-  var hasher2 = ${Self}(_rawSeed: (0, 0))
+  var hasher2 = Hasher(_rawSeed: (0, 0))
   hasher2._combine(1 as UInt8)
   hasher2._combine(2 as UInt16)
   let hash2 = hasher2.finalize()
   expectEqual(hash1a, hash2)
 }
-% end
 
 runAllTests()
-