Merge pull request #12651 from rudkx/remove-illegal-use-of-iuo

Rework an initialization to remove a use of an IUO that was banned by…
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 65f6479..8c019f5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,24 @@
 Swift 4.1
 ---------
 
+* [SE-0161][] is fully implemented. KeyPaths now support subscript, optional
+  chaining, and optional force-unwrapping components.
+
+* [SE-0186][]
+
+  It is no longer valid to use the ownership keywords `weak` and `unowned` for property declarations in protocols. These keywords are meaningless and misleading when used in a protocol as they don't have any effect.
+
+  In Swift 3 and 4 mode the following example will produce a warning with a fix-it to remove the keyword. In Swift 5 mode and above an error will be produced.
+
+  ```swift
+  class A {}
+
+  protocol P {
+      weak var weakVar: A? { get set }
+      unowned var unownedVar: A { get set }
+  }
+  ```
+
 * [SE-0185][]
 
   Structs and enums that declare a conformance to `Equatable`/`Hashable` now get an automatically synthesized implementation of `==`/`hashValue`. For structs, all stored properties must be `Equatable`/`Hashable`. For enums, all enum cases with associated values must be `Equatable`/`Hashable`.
@@ -6754,3 +6772,4 @@
 [SE-0183]: <https://github.com/apple/swift-evolution/blob/master/proposals/0183-substring-affordances.md>
 [SE-0184]: <https://github.com/apple/swift-evolution/blob/master/proposals/0184-unsafe-pointers-add-missing.md>
 [SE-0185]: <https://github.com/apple/swift-evolution/blob/master/proposals/0185-synthesize-equatable-hashable.md>
+[SE-0186]: <https://github.com/apple/swift-evolution/blob/master/proposals/0186-remove-ownership-keyword-support-in-protocols.md>
diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake
index 53081bd..6db2e9a 100644
--- a/cmake/modules/AddSwift.cmake
+++ b/cmake/modules/AddSwift.cmake
@@ -1531,6 +1531,11 @@
             if("${sdk}" STREQUAL "ANDROID")
               list(APPEND swiftlib_private_link_libraries_targets
                    "-latomic")
+            # the same issue on FreeBSD, missing symbols:
+            # __atomic_store, __atomic_compare_exchange, __atomic_load
+            elseif("${sdk}" STREQUAL "FREEBSD")
+              list(APPEND swiftlib_private_link_libraries_targets
+                   "${SWIFTLIB_DIR}/clang/lib/freebsd/libclang_rt.builtins-${arch}.a")
             endif()
           elseif("${lib}" STREQUAL "ICU_I18N")
             list(APPEND swiftlib_private_link_libraries_targets
diff --git a/include/swift/AST/DiagnosticsDriver.def b/include/swift/AST/DiagnosticsDriver.def
index a589010..fbafa1f 100644
--- a/include/swift/AST/DiagnosticsDriver.def
+++ b/include/swift/AST/DiagnosticsDriver.def
@@ -136,6 +136,11 @@
 ERROR(error_profile_missing,none,
       "no profdata file exists at '%0'", (StringRef))
 
+WARNING(warn_opt_remark_disabled, none,
+        "Emission of optimization records has been disabled, because it "
+        "requires a single compiler invocation: consider enabling the "
+        "-whole-module-optimization flag", ())
+
 #ifndef DIAG_NO_UNDEF
 # if defined(DIAG)
 #  undef DIAG
diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def
index f18ce60..8fa09bc 100644
--- a/include/swift/AST/DiagnosticsSema.def
+++ b/include/swift/AST/DiagnosticsSema.def
@@ -1635,17 +1635,18 @@
      (DescriptiveDeclKind, DeclName, DeclName))
 
 // "Near matches"
-WARNING(optional_req_near_match,none,
-        "%0 %1 nearly matches optional requirement %2 of protocol %3",
-        (DescriptiveDeclKind, DeclName, DeclName, DeclName))
+WARNING(req_near_match,none,
+        "%0 %1 nearly matches %select{defaulted|optional}2 requirement %3 "
+        "of protocol %4",
+        (DescriptiveDeclKind, DeclName, bool, DeclName, DeclName))
 NOTE(optional_req_nonobjc_near_match_add_objc,none,
      "add '@objc' to provide an Objective-C entrypoint", ())
-NOTE(optional_req_near_match_move,none,
+NOTE(req_near_match_move,none,
      "move %0 to %select{an|another}1 extension to silence this warning",
      (DeclName, unsigned))
-NOTE(optional_req_near_match_nonobjc,none,
+NOTE(req_near_match_nonobjc,none,
      "add '@nonobjc' to silence this %select{warning|error}0", (bool))
-NOTE(optional_req_near_match_access,none,
+NOTE(req_near_match_access,none,
      "make %0 %select{ERROR|private|private|non-public|non-public}1 to silence this "
      "warning", (DeclName, AccessLevel))
 
@@ -1924,10 +1925,6 @@
 NOTE(override_unnecessary_IUO_silence,none,
      "add parentheses to silence this warning", ())
 
-ERROR(iuo_in_illegal_position,none,
-      "implicitly unwrapped optionals are only allowed at top level and as "
-      "function results", ())
-
 ERROR(override_mutable_covariant_property,none,
       "cannot override mutable property %0 of type %1 with covariant type %2",
       (Identifier, Type, Type))
@@ -3111,6 +3108,22 @@
 ERROR(tuple_ellipsis,none,
       "cannot create a variadic tuple", ())
 
+WARNING(implicitly_unwrapped_optional_spelling_deprecated,none,
+        "the spelling 'ImplicitlyUnwrappedOptional' is deprecated", ())
+
+WARNING(implicitly_unwrapped_optional_spelling_deprecated_with_fixit,none,
+        "the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name", ())
+
+ERROR(implicitly_unwrapped_optional_spelling_error,none,
+        "the spelling 'ImplicitlyUnwrappedOptional' in unsupported; use an explicit type followed by '!'", ())
+
+ERROR(implicitly_unwrapped_optional_spelling_error_with_fixit,none,
+        "the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name", ())
+
+ERROR(iuo_in_illegal_position,none,
+      "implicitly unwrapped optionals are only allowed at top level and as "
+      "function results", ())
+
 // Ownership
 ERROR(invalid_ownership_type,none,
       "'%select{strong|weak|unowned|unowned}0' may only be applied to "
diff --git a/include/swift/AST/GenericSignatureBuilder.h b/include/swift/AST/GenericSignatureBuilder.h
index 508f9e2..cd38cde 100644
--- a/include/swift/AST/GenericSignatureBuilder.h
+++ b/include/swift/AST/GenericSignatureBuilder.h
@@ -91,9 +91,12 @@
   using UnresolvedType = llvm::PointerUnion<PotentialArchetype *, Type>;
   class ResolvedType;
 
-  using RequirementRHS =
+  using UnresolvedRequirementRHS =
       llvm::PointerUnion3<Type, PotentialArchetype *, LayoutConstraint>;
 
+  using RequirementRHS =
+    llvm::PointerUnion3<Type, PotentialArchetype *, LayoutConstraint>;
+
   /// The location of a requirement as written somewhere in the source.
   typedef llvm::PointerUnion<const TypeRepr *, const RequirementRepr *>
     WrittenRequirementLoc;
@@ -158,7 +161,7 @@
     /// the equivalence class that is held together by derived constraints.
     struct DerivedSameTypeComponent {
       /// The potential archetype that acts as the anchor for this component.
-      PotentialArchetype *anchor;
+      UnresolvedType anchor;
 
       /// The (best) requirement source within the component that makes the
       /// potential archetypes in this component equivalent to the concrete
@@ -223,15 +226,13 @@
     /// archetype in this equivalence class to a concrete type along with
     /// that concrete type as written.
     Optional<ConcreteConstraint>
-    findAnyConcreteConstraintAsWritten(
-                              PotentialArchetype *preferredPA = nullptr) const;
+    findAnyConcreteConstraintAsWritten(Type preferredType = Type()) const;
 
     /// Find a source of the superclass constraint in this equivalence class
     /// that has a type equivalence to \c superclass, along with that
     /// superclass type as written.
     Optional<ConcreteConstraint>
-    findAnySuperclassConstraintAsWritten(
-                              PotentialArchetype *preferredPA = nullptr) const;
+    findAnySuperclassConstraintAsWritten(Type preferredType = Type()) const;
 
     /// Determine whether conformance to the given protocol is satisfied by
     /// a superclass requirement.
@@ -267,8 +268,8 @@
 
     /// The cached archetype anchor.
     struct {
-      /// The cached archetype anchor itself.
-      PotentialArchetype *anchor = nullptr;
+      /// The cached anchor itself.
+      Type anchor;
 
       /// The number of members of the equivalence class when the archetype
       /// anchor was cached.
@@ -339,7 +340,7 @@
   /// as appropriate based on \c unresolvedHandling.
   ConstraintResult handleUnresolvedRequirement(RequirementKind kind,
                                    UnresolvedType lhs,
-                                   RequirementRHS rhs,
+                                   UnresolvedRequirementRHS rhs,
                                    FloatingRequirementSource source,
                                    EquivalenceClass *unresolvedEquivClass,
                                    UnresolvedHandlingKind unresolvedHandling);
@@ -536,13 +537,14 @@
   ///
   /// \param f A function object that will be passed each requirement
   /// and requirement source.
-  void enumerateRequirements(llvm::function_ref<
+  void enumerateRequirements(
+                    ArrayRef<GenericTypeParamType *> genericParams,
+                    llvm::function_ref<
                       void (RequirementKind kind,
-                            PotentialArchetype *archetype,
+                            Type type,
                             RequirementRHS constraint,
                             const RequirementSource *source)> f);
 
-public:
   /// Retrieve the generic parameters used to describe the generic
   /// signature being built.
   ArrayRef<GenericTypeParamType *> getGenericParams() const;
@@ -727,30 +729,36 @@
   /// class of the given potential archetype.
   void checkConcreteTypeConstraints(
                             ArrayRef<GenericTypeParamType *> genericParams,
-                            PotentialArchetype *pa);
+                            EquivalenceClass *equivClass);
 
   /// Check the superclass constraints within the equivalence
   /// class of the given potential archetype.
   void checkSuperclassConstraints(
                             ArrayRef<GenericTypeParamType *> genericParams,
-                            PotentialArchetype *pa);
+                            EquivalenceClass *equivClass);
 
   /// Check conformance constraints within the equivalence class of the
   /// given potential archetype.
   void checkConformanceConstraints(
                             ArrayRef<GenericTypeParamType *> genericParams,
-                            PotentialArchetype *pa);
+                            EquivalenceClass *equivClass);
 
   /// Check layout constraints within the equivalence class of the given
   /// potential archetype.
   void checkLayoutConstraints(ArrayRef<GenericTypeParamType *> genericParams,
-                              PotentialArchetype *pa);
+                              EquivalenceClass *equivClass);
 
   /// Check same-type constraints within the equivalence class of the
   /// given potential archetype.
   void checkSameTypeConstraints(
                             ArrayRef<GenericTypeParamType *> genericParams,
-                            PotentialArchetype *pa);
+                            EquivalenceClass *equivClass);
+
+  /// Realize a potential archetype for the given type.
+  ///
+  /// The resolved archetype will be written back into the unresolved type,
+  /// to make the next resolution more efficient.
+  PotentialArchetype *realizePotentialArchetype(UnresolvedType &type);
 
 public:
   /// \brief Try to resolve the equivalence class of the given type.
@@ -1656,20 +1664,6 @@
                                        const_cast<PotentialArchetype *>(this));
   }
 
-  /// \brief Retrieve the potential archetype to be used as the anchor for
-  /// potential archetype computations.
-  PotentialArchetype *getArchetypeAnchor(GenericSignatureBuilder &builder);
-
-  /// \brief Retrieve (or create) a nested type that is the current best
-  /// nested archetype anchor (locally) with the given name.
-  ///
-  /// When called on the archetype anchor, this will produce the named
-  /// archetype anchor.
-  PotentialArchetype *getNestedArchetypeAnchor(
-                       Identifier name,
-                       GenericSignatureBuilder &builder,
-                       ArchetypeResolutionKind kind);
-
   /// Update the named nested type when we know this type conforms to the given
   /// protocol.
   ///
@@ -1727,7 +1721,7 @@
 
   Kind kind;
   UnresolvedType lhs;
-  RequirementRHS rhs;
+  UnresolvedRequirementRHS rhs;
   FloatingRequirementSource source;
 
   /// Dump a debugging representation of this delayed requirement class.
diff --git a/include/swift/AST/SILOptions.h b/include/swift/AST/SILOptions.h
index 21326c3..bbd37b9 100644
--- a/include/swift/AST/SILOptions.h
+++ b/include/swift/AST/SILOptions.h
@@ -32,6 +32,12 @@
   /// Controls the aggressiveness of the performance inliner.
   int InlineThreshold = -1;
 
+  /// Controls the aggressiveness of the performance inliner for Osize.
+  int CallerBaseBenefitReductionFactor = 2;
+
+  /// Controls the aggressiveness of the loop unroller.
+  int UnrollThreshold = 250;
+
   /// The number of threads for multi-threaded code generation.
   int NumThreads = 0;
   
@@ -150,6 +156,10 @@
   /// \brief Enable large loadable types IRGen pass.
   bool EnableLargeLoadableTypes = true;
 
+  /// The name of the file to which the backend should save YAML optimization
+  /// records.
+  std::string OptRecordFile;
+
   SILOptions() {}
 
   /// Return a hash code of any components from these options that should
diff --git a/include/swift/Driver/Types.def b/include/swift/Driver/Types.def
index 14c69b4..3d29dcc 100644
--- a/include/swift/Driver/Types.def
+++ b/include/swift/Driver/Types.def
@@ -61,6 +61,7 @@
 TYPE("tbd",             TBD,                "tbd",             "")
 TYPE("module-trace",    ModuleTrace,        "trace.json",      "")
 TYPE("index-data",      IndexData,          "",                "")
+TYPE("opt-record",      OptRecord,          "opt.yaml",        "")
 
 // Misc types
 TYPE("pcm",             ClangModuleFile,    "pcm",             "")
diff --git a/include/swift/Option/FrontendOptions.td b/include/swift/Option/FrontendOptions.td
index f3fbf3d..018ec22 100644
--- a/include/swift/Option/FrontendOptions.td
+++ b/include/swift/Option/FrontendOptions.td
@@ -369,6 +369,16 @@
   MetaVarName<"<50>">,
   HelpText<"Controls the aggressiveness of performance inlining">;
 
+def sil_inline_caller_benefit_reduction_factor : Separate<["-"], "sil-inline-caller-benefit-reduction-factor">,
+  MetaVarName<"<2>">,
+  HelpText<"Controls the aggressiveness of performance inlining in -Osize "
+          "mode by reducing the base benefits of a caller (lower value "
+          "permits more inlining!)">;
+
+def sil_unroll_threshold : Separate<["-"], "sil-unroll-threshold">,
+  MetaVarName<"<250>">,
+  HelpText<"Controls the aggressiveness of loop unrolling">;
+
 def sil_merge_partial_modules : Flag<["-"], "sil-merge-partial-modules">,
   HelpText<"Merge SIL from all partial swiftmodules into the final module">;
 
diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td
index 3013666..f6178af 100644
--- a/include/swift/Option/Options.td
+++ b/include/swift/Option/Options.td
@@ -331,6 +331,13 @@
   HelpText<"Report missed transformations by optimization passes whose "
            "name matches the given POSIX regular expression">;
 
+def save_optimization_record : Flag<["-"], "save-optimization-record">,
+  Flags<[FrontendOption]>, HelpText<"Generate a YAML optimization record file">;
+def save_optimization_record_path :
+  Separate<["-"], "save-optimization-record-path">,
+  Flags<[FrontendOption]>,
+  HelpText<"Specify the file name of any generated YAML optimization record">;
+
 // Platform options.
 def enable_app_extension : Flag<["-"], "application-extension">,
   Flags<[FrontendOption, NoInteractiveOption]>,
diff --git a/include/swift/Runtime/RuntimeFunctions.def b/include/swift/Runtime/RuntimeFunctions.def
index f1dd504..4183f1b 100644
--- a/include/swift/Runtime/RuntimeFunctions.def
+++ b/include/swift/Runtime/RuntimeFunctions.def
@@ -142,13 +142,13 @@
          ATTRS(NoUnwind))
 
 // void swift_errorInMain(error *ptr);
-FUNCTION(ErrorInMain, swift_errorInMain, DefaultCC,
+FUNCTION(ErrorInMain, swift_errorInMain, SwiftCC,
          RETURNS(VoidTy),
          ARGS(ErrorPtrTy),
          ATTRS(NoUnwind))
 
 // void swift_unexpectedError(error *ptr);
-FUNCTION(UnexpectedError, swift_unexpectedError, DefaultCC,
+FUNCTION(UnexpectedError, swift_unexpectedError, SwiftCC,
          RETURNS(VoidTy),
          ARGS(ErrorPtrTy),
          ATTRS(NoUnwind, NoReturn))
diff --git a/include/swift/SIL/OptimizationRemark.h b/include/swift/SIL/OptimizationRemark.h
index b18a783..d19d923 100644
--- a/include/swift/SIL/OptimizationRemark.h
+++ b/include/swift/SIL/OptimizationRemark.h
@@ -20,12 +20,13 @@
 #define SWIFT_SIL_OPTIMIZATIONREMARKEMITTER_H
 
 #include "swift/Basic/SourceLoc.h"
+#include "swift/SIL/SILBasicBlock.h"
 #include "swift/SIL/SILInstruction.h"
+#include "swift/SIL/SILModule.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace swift {
 
-class ASTContext;
 class SILFunction;
 
 namespace OptRemark {
@@ -60,6 +61,9 @@
   /// Arguments collected via the streaming interface.
   SmallVector<Argument, 4> Args;
 
+  /// The name of the pass generating the remark.
+  StringRef PassName;
+
   /// Textual identifier for the remark (single-word, camel-case). Can be used
   /// by external tools reading the YAML output file for optimization remarks to
   /// identify the remark.
@@ -68,9 +72,13 @@
   /// Source location for the diagnostics.
   SourceLoc Location;
 
+  /// The function for the diagnostics.
+  SILFunction *Function;
+
 protected:
   Remark(StringRef Identifier, SILInstruction &I)
-      : Identifier(Identifier), Location(I.getLoc().getSourceLoc()) {}
+      : Identifier(Identifier), Location(I.getLoc().getSourceLoc()),
+        Function(I.getParent()->getParent()) {}
 
 public:
   DerivedT &operator<<(StringRef S) {
@@ -83,8 +91,15 @@
     return *static_cast<DerivedT *>(this);
   }
 
+  StringRef getPassName() const { return PassName; }
+  StringRef getIdentifier() const { return Identifier; }
+  SILFunction *getFunction() const { return Function; }
   SourceLoc getLocation() const { return Location; }
   std::string getMsg() const;
+  Remark<DerivedT> &getRemark() { return *this; }
+  SmallVector<Argument, 4> &getArgs() { return Args; }
+
+  void setPassName(StringRef PN) { PassName = PN; }
 };
 
 /// Remark to report a successful optimization.
@@ -99,7 +114,7 @@
 /// Used to emit the remarks.  Passes reporting remarks should create an
 /// instance of this.
 class Emitter {
-  ASTContext &Ctx;
+  SILModule &Module;
   std::string PassName;
   bool PassedEnabled;
   bool MissedEnabled;
@@ -110,7 +125,7 @@
   template <typename RemarkT> bool isEnabled();
 
 public:
-  Emitter(StringRef PassName, ASTContext &Ctx);
+  Emitter(StringRef PassName, SILModule &M);
 
   /// \brief Take a lambda that returns a remark which will be emitted.  The
   /// lambda is not evaluated unless remarks are enabled.  Second argument is
@@ -119,8 +134,9 @@
   void emit(T RemarkBuilder, decltype(RemarkBuilder()) * = nullptr) {
     using RemarkT = decltype(RemarkBuilder());
     // Avoid building the remark unless remarks are enabled.
-    if (isEnabled<RemarkT>()) {
+    if (isEnabled<RemarkT>() || Module.getOptRecordStream()) {
       auto R = RemarkBuilder();
+      R.setPassName(PassName);
       emit(R);
     }
   }
diff --git a/include/swift/SIL/SILInstruction.h b/include/swift/SIL/SILInstruction.h
index 66a314a..5610ab7 100644
--- a/include/swift/SIL/SILInstruction.h
+++ b/include/swift/SIL/SILInstruction.h
@@ -355,17 +355,6 @@
     return SILInstructionKind(SILNode::getKind());
   }
 
-  SILNode *getCanonicalSILNodeInObject() {
-    assert(isRepresentativeSILNodeInObject() &&
-           "the SILInstruction subobject is always canonical");
-    return this;
-  }
-  const SILNode *getCanonicalSILNodeInObject() const {
-    assert(isRepresentativeSILNodeInObject() &&
-           "the SILInstruction subobject is always canonical");
-    return this;
-  }
-
   const SILBasicBlock *getParent() const { return ParentBB; }
   SILBasicBlock *getParent() { return ParentBB; }
 
@@ -412,6 +401,11 @@
   /// with the parwise-corresponding results of the given instruction.
   void replaceAllUsesPairwiseWith(SILInstruction *other);
 
+  /// \brief Replace all uses of all results of this instruction with the
+  /// parwise-corresponding results of the passed in array.
+  void
+  replaceAllUsesPairwiseWith(const llvm::SmallVectorImpl<SILValue> &NewValues);
+
   /// \brief Are there uses of any of the results of this instruction?
   bool hasUsesOfAnyResult() const {
     for (auto result : getResults()) {
@@ -670,9 +664,6 @@
       : SILInstruction(kind, loc),
         ValueBase(ValueKind(kind), type, IsRepresentative::No) {}
 
-  using SILInstruction::getFunction;
-  using SILInstruction::getModule;
-  using SILInstruction::getKind;
   using SILInstruction::operator new;
   using SILInstruction::dumpInContext;
   using SILInstruction::print;
@@ -680,6 +671,12 @@
 
   // Redeclare because lldb currently doesn't know about using-declarations
   void dump() const;
+  SILFunction *getFunction() { return SILInstruction::getFunction(); }
+  const SILFunction *getFunction() const {
+    return SILInstruction::getFunction();
+  }
+  SILModule &getModule() const { return SILInstruction::getModule(); }
+  SILInstructionKind getKind() const { return SILInstruction::getKind(); }
 
   void operator delete(void *Ptr, size_t) SWIFT_DELETE_OPERATOR_DELETED
 
@@ -687,17 +684,6 @@
     return ValueBase::getKind();
   }
 
-  SILNode *getCanonicalSILNodeInObject() {
-    assert(SILInstruction::isRepresentativeSILNodeInObject() &&
-           "the SILInstruction subobject is always canonical");
-    return static_cast<SILInstruction*>(this);
-  }
-  const SILNode *getCanonicalSILNodeInObject() const {
-    assert(SILInstruction::isRepresentativeSILNodeInObject() &&
-           "the SILInstruction subobject is always canonical");
-    return static_cast<const SILInstruction*>(this);
-  }
-
   SingleValueInstruction *clone(SILInstruction *insertPt = nullptr) {
     return cast<SingleValueInstruction>(SILInstruction::clone(insertPt));
   }
@@ -771,16 +757,15 @@
     return const_cast<MultipleValueInstructionResult *>(this)->getParent();
   }
 
-  unsigned getIndex() const;
+  unsigned getIndex() const {
+    return unsigned((getSubclassData() >> IndexBitOffset) & IndexMask);
+  }
 
   /// Get the ownership kind assigned to this result by its parent.
   ///
   /// This is stored in the bottom 3 bits of ValueBase's subclass data.
   ValueOwnershipKind getOwnershipKind() const;
 
-  SILNode *getCanonicalSILNodeInObject();
-  const SILNode *getCanonicalSILNodeInObject() const;
-
   static bool classof(const SILInstruction *) = delete;
   static bool classof(const SILUndef *) = delete;
   static bool classof(const SILArgument *) = delete;
@@ -906,6 +891,13 @@
     if (!NumResults)
       return;
     auto *DataPtr = this->template getTrailingObjects<DerivedResult>();
+    // We call the DerivedResult destructors to ensure that:
+    //
+    // 1. If our derived results have any stored data that need to be cleaned
+    // up, we clean them up. *NOTE* Today, no results have this property.
+    // 2. In ~ValueBase, we validate via an assert that a ValueBase no longer
+    // has any uses when it is being destroyed. Rather than re-implement that in
+    // result, we get that for free.
     for (unsigned i : range(NumResults))
       DataPtr[i].~DerivedResult();
   }
diff --git a/include/swift/SIL/SILModule.h b/include/swift/SIL/SILModule.h
index c7d37c8..16981d6 100644
--- a/include/swift/SIL/SILModule.h
+++ b/include/swift/SIL/SILModule.h
@@ -46,6 +46,12 @@
 #include "llvm/Support/raw_ostream.h"
 #include <functional>
 
+namespace llvm {
+namespace yaml {
+class Output;
+} // end namespace yaml
+} // end namespace llvm
+
 namespace swift {
   class AnyFunctionType;
   class ASTContext;
@@ -178,6 +184,14 @@
   // The list of SILCoverageMaps in the module.
   CoverageMapListType coverageMaps;
 
+  /// This is the underlying raw stream of OptRecordStream.
+  ///
+  /// It is also owned by SILModule in order to keep their lifetime in sync.
+  std::unique_ptr<llvm::raw_ostream> OptRecordRawStream;
+
+  /// If non-null, the YAML file where remarks should be recorded.
+  std::unique_ptr<llvm::yaml::Output> OptRecordStream;
+
   /// This is a cache of intrinsic Function declarations to numeric ID mappings.
   llvm::DenseMap<Identifier, IntrinsicInfo> IntrinsicIDCache;
 
@@ -448,7 +462,11 @@
   }
   iterator_range<coverage_map_const_iterator> getCoverageMaps() const {
     return {coverageMaps.begin(), coverageMaps.end()};
- }
+  }
+
+  llvm::yaml::Output *getOptRecordStream() { return OptRecordStream.get(); }
+  void setOptRecordStream(std::unique_ptr<llvm::yaml::Output> &&Stream,
+                          std::unique_ptr<llvm::raw_ostream> &&RawStream);
 
   /// Look for a global variable by name.
   ///
diff --git a/include/swift/SIL/SILNode.h b/include/swift/SIL/SILNode.h
index ae3a019..8b383c8 100644
--- a/include/swift/SIL/SILNode.h
+++ b/include/swift/SIL/SILNode.h
@@ -81,9 +81,9 @@
 /// These precautions only apply to SILNode* and not its subclasses.
 ///
 /// - There may have multiple SILNode* values that refer to the same
-///   instruction.  Data structures and algorithms that rely on
-///   uniqueness of a SILNode* should generally make sure that they're
-///   working with the canonical SILNode*; see getCanonicalSILNodeInObject().
+///   instruction.  Data structures and algorithms that rely on uniqueness of a
+///   SILNode* should generally make sure that they're working with the
+///   representative SILNode*; see getRepresentativeSILNodeInObject().
 ///
 /// - Do not use builtin C++ casts to downcast a SILNode*.  A static_cast
 ///   from SILNode* to SILInstruction* only works if the referenced
@@ -97,10 +97,12 @@
   /// static assertion purposes.
   static constexpr unsigned NumTotalSILNodeBits = 64;
 
-protected:
+private:
   static constexpr unsigned NumKindBits = NumSILNodeKindBits;
   static constexpr unsigned NumStorageLocBits = 1;
   static constexpr unsigned NumIsRepresentativeBits = 1;
+
+protected:
   static constexpr unsigned NumSubclassDataBits =
       NumTotalSILNodeBits - NumKindBits - NumStorageLocBits -
       NumIsRepresentativeBits;
@@ -113,9 +115,9 @@
   };
 
 private:
-  const unsigned Kind : NumKindBits;
-  const unsigned StorageLoc : NumStorageLocBits;
-  const unsigned IsRepresentativeNode : NumIsRepresentativeBits;
+  const uint64_t Kind : NumKindBits;
+  const uint64_t StorageLoc : NumStorageLocBits;
+  const uint64_t IsRepresentativeNode : NumIsRepresentativeBits;
   uint64_t SubclassData : NumSubclassDataBits;
 
   SILNodeStorageLocation getStorageLoc() const {
@@ -140,7 +142,7 @@
 
 public:
   /// Does the given kind of node inherit from multiple multiple SILNode base
-  /// classes.
+  /// classes?
   ///
   /// This enables one to know if their is a diamond in the inheritence
   /// hierarchy for this SILNode.
@@ -151,10 +153,10 @@
            kind <= SILNodeKind::Last_SingleValueInstruction;
   }
 
-  /// Is this SILNode the canonical SILNode subobject in this object?
+  /// Is this SILNode the representative SILNode subobject in this object?
   bool isRepresentativeSILNodeInObject() const { return IsRepresentativeNode; }
 
-  /// Return a pointer to the canonical SILNode subobject in this object.
+  /// Return a pointer to the representative SILNode subobject in this object.
   SILNode *getRepresentativeSILNodeInObject() {
     if (isRepresentativeSILNodeInObject())
       return this;
@@ -172,9 +174,7 @@
     return SILNodeKind(Kind);
   }
 
-  /// Return the SILNodeKind of this node's canonical SILNode.
-  ///
-  /// TODO: Find a better name for this.
+  /// Return the SILNodeKind of this node's representative SILNode.
   SILNodeKind getKindOfRepresentativeSILNodeInObject() const {
     return getRepresentativeSILNodeInObject()->getKind();
   }
diff --git a/include/swift/SIL/SILWitnessTable.h b/include/swift/SIL/SILWitnessTable.h
index 9d6c75f..0fe98f9 100644
--- a/include/swift/SIL/SILWitnessTable.h
+++ b/include/swift/SIL/SILWitnessTable.h
@@ -272,8 +272,7 @@
                            IsSerialized_t isSerialized);
 
   // Whether a conformance should be serialized.
-  static bool conformanceIsSerialized(ProtocolConformance *conformance,
-                                      ResilienceStrategy strategy);
+  static bool conformanceIsSerialized(ProtocolConformance *conformance);
 
   /// Print the witness table.
   void print(llvm::raw_ostream &OS, bool Verbose = false) const;
diff --git a/include/swift/SIL/TypeLowering.h b/include/swift/SIL/TypeLowering.h
index 7f1904c..84376c5 100644
--- a/include/swift/SIL/TypeLowering.h
+++ b/include/swift/SIL/TypeLowering.h
@@ -531,9 +531,9 @@
 
   llvm::SmallVector<DependentTypeState, 1> DependentTypes;
 
-  llvm::DenseMap<SILDeclRef, SILConstantInfo> ConstantTypes;
+  llvm::DenseMap<SILDeclRef, SILConstantInfo *> ConstantTypes;
   
-  llvm::DenseMap<OverrideKey, SILConstantInfo> ConstantOverrideTypes;
+  llvm::DenseMap<OverrideKey, SILConstantInfo *> ConstantOverrideTypes;
 
   llvm::DenseMap<AnyFunctionRef, CaptureInfo> LoweredCaptures;
 
diff --git a/include/swift/SILOptimizer/Utils/SCCVisitor.h b/include/swift/SILOptimizer/Utils/SCCVisitor.h
index 34bf648..c0f2b4f 100644
--- a/include/swift/SILOptimizer/Utils/SCCVisitor.h
+++ b/include/swift/SILOptimizer/Utils/SCCVisitor.h
@@ -161,7 +161,7 @@
   }
 
   void maybeDFS(SILInstruction *inst) {
-    (void) maybeDFSCanonicalNode(inst->getCanonicalSILNodeInObject());
+    (void) maybeDFSCanonicalNode(inst->getRepresentativeSILNodeInObject());
   }
 
   /// Continue a DFS from the given node, finding the strongly
diff --git a/include/swift/Syntax/RawSyntax.h b/include/swift/Syntax/RawSyntax.h
index de18be0..e79e188 100644
--- a/include/swift/Syntax/RawSyntax.h
+++ b/include/swift/Syntax/RawSyntax.h
@@ -240,42 +240,24 @@
   }
 
   /// Returns true if this raw syntax node is some kind of declaration.
-  bool isDecl() const {
-    return Kind >= SyntaxKind::First_Decl && Kind <= SyntaxKind::Last_Decl;
-  }
+  bool isDecl() const { return isDeclKind(Kind); }
 
   /// Returns true if this raw syntax node is some kind of type syntax.
-  bool isType() const {
-    return Kind >= SyntaxKind::First_Type && Kind <= SyntaxKind::Last_Type;
-  }
+  bool isType() const { return isTypeKind(Kind); }
 
   /// Returns true if this raw syntax node is some kind of statement.
-  bool isStmt() const {
-    return Kind >= SyntaxKind::First_Stmt && Kind <= SyntaxKind::Last_Stmt;
-  }
+  bool isStmt() const { return isStmtKind(Kind); }
 
   /// Returns true if this raw syntax node is some kind of expression.
-  bool isExpr() const {
-    return Kind >= SyntaxKind::First_Expr && Kind <= SyntaxKind::Last_Expr;
-  }
+  bool isExpr() const { return isExprKind(Kind); }
 
   /// Returns true if this raw syntax node is some kind of pattern.
-  bool isPattern() const {
-    return Kind >= SyntaxKind::First_Pattern &&
-           Kind <= SyntaxKind::Last_Pattern;
-  }
+  bool isPattern() const { return isPatternKind(Kind); }
 
   /// Return true if this raw syntax node is a token.
-  bool isToken() const {
-    return Kind == SyntaxKind::Token;
-  }
+  bool isToken() const { return isTokenKind(Kind); }
 
-  bool isUnknown() const {
-    return Kind == SyntaxKind::Unknown ||
-           Kind == SyntaxKind::UnknownDecl ||
-           Kind == SyntaxKind::UnknownExpr ||
-           Kind == SyntaxKind::UnknownStmt;
-  }
+  bool isUnknown() const { return isUnknownKind(Kind); }
 
   /// Get the absolute position of this raw syntax: its offset, line,
   /// and column.
diff --git a/include/swift/Syntax/SyntaxKind.h.gyb b/include/swift/Syntax/SyntaxKind.h.gyb
index 8880250..dff3204 100644
--- a/include/swift/Syntax/SyntaxKind.h.gyb
+++ b/include/swift/Syntax/SyntaxKind.h.gyb
@@ -50,6 +50,19 @@
 /// Whether this kind is a syntax collection.
 bool isCollectionKind(SyntaxKind Kind);
 
+bool isDeclKind(SyntaxKind Kind);
+
+bool isTypeKind(SyntaxKind Kind);
+
+bool isStmtKind(SyntaxKind Kind);
+
+bool isExprKind(SyntaxKind Kind);
+
+bool isPatternKind(SyntaxKind Kind);
+
+bool isTokenKind(SyntaxKind Kind);
+
+bool isUnknownKind(SyntaxKind Kind);
 } // end namespace syntax
 
 namespace json {
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 8aefea5..ac5aba6 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -2874,7 +2874,7 @@
     if (auto objcAttr = conflicts[0]->getAttrs().getAttribute<ObjCAttr>())
       hasExplicitObjCAttribute = !objcAttr->isImplicit();
     if (!hasExplicitObjCAttribute)
-      Diags.diagnose(conflicts[0], diag::optional_req_near_match_nonobjc, true)
+      Diags.diagnose(conflicts[0], diag::req_near_match_nonobjc, true)
         .fixItInsert(
           conflicts[0]->getAttributeInsertionLoc(/*forModifier=*/false),
           "@nonobjc ");
diff --git a/lib/AST/ASTVerifier.cpp b/lib/AST/ASTVerifier.cpp
index dc4cd51..cd864b4 100644
--- a/lib/AST/ASTVerifier.cpp
+++ b/lib/AST/ASTVerifier.cpp
@@ -2097,10 +2097,17 @@
                  "Storage overrides but setter does not");
         if (ASD->getMaterializeForSetFunc() &&
             baseASD->getMaterializeForSetFunc() &&
-            baseASD->isSetterAccessibleFrom(ASD->getDeclContext()))
-          assert(ASD->getMaterializeForSetFunc()->getOverriddenDecl() ==
-                 baseASD->getMaterializeForSetFunc() &&
-                 "Storage override but materializeForSet does not");
+            baseASD->isSetterAccessibleFrom(ASD->getDeclContext())) {
+          if (baseASD->getMaterializeForSetFunc()->hasForcedStaticDispatch()) {
+            assert(ASD->getMaterializeForSetFunc()->getOverriddenDecl() == nullptr
+                   && "Forced static dispatch materializeForSet should not be "
+                   "overridden");
+          } else {
+            assert(ASD->getMaterializeForSetFunc()->getOverriddenDecl() ==
+                   baseASD->getMaterializeForSetFunc() &&
+                   "Storage override but materializeForSet does not");
+          }
+        }
       } else {
         if (ASD->getGetter())
           assert(!ASD->getGetter()->getOverriddenDecl() &&
diff --git a/lib/AST/ASTWalker.cpp b/lib/AST/ASTWalker.cpp
index 78a2088..87a506b 100644
--- a/lib/AST/ASTWalker.cpp
+++ b/lib/AST/ASTWalker.cpp
@@ -137,6 +137,12 @@
       if (doIt(Inherit))
         return true;
     }
+    if (auto *Where = ED->getTrailingWhereClause()) {
+      for(auto &Req: Where->getRequirements()) {
+        if (doIt(Req))
+          return true;
+      }
+    }
     for (Decl *M : ED->getMembers()) {
       if (doIt(M))
         return true;
@@ -212,25 +218,23 @@
   }
 
   bool visitNominalTypeDecl(NominalTypeDecl *NTD) {
-    if (NTD->getGenericParams() &&
-        Walker.shouldWalkIntoGenericParams()) {
+    bool WalkGenerics = NTD->getGenericParams() &&
+        Walker.shouldWalkIntoGenericParams();
+
+    if (WalkGenerics) {
       // Visit generic params
       for (auto GP : NTD->getGenericParams()->getParams()) {
         if (doIt(GP))
           return true;
       }
-      // Visit param conformance
-      for (auto &Req : NTD->getGenericParams()->getRequirements()) {
-        if (doIt(Req))
-          return true;
-      }
     }
 
     for (auto &Inherit : NTD->getInherited()) {
       if (doIt(Inherit))
         return true;
     }
-    
+
+    // Visit requirements
     if (auto *Protocol = dyn_cast<ProtocolDecl>(NTD)) {
       if (auto *WhereClause = Protocol->getTrailingWhereClause()) {
         for (auto &Req: WhereClause->getRequirements()) {
@@ -239,6 +243,12 @@
         }
       }
     }
+    if (WalkGenerics) {
+      for (auto &Req: NTD->getGenericParams()->getRequirements()) {
+        if (doIt(Req))
+          return true;
+      }
+    }
     
     for (Decl *Member : NTD->getMembers())
       if (doIt(Member))
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 6a079db..7551830 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -3401,7 +3401,7 @@
 }
 
 GenericParamList *ProtocolDecl::createGenericParams(DeclContext *dc) {
-  auto *outerGenericParams = dc->getParent()->getGenericParamsOfContext();
+  auto *outerGenericParams = getParent()->getGenericParamsOfContext();
 
   // The generic parameter 'Self'.
   auto &ctx = getASTContext();
diff --git a/lib/AST/GenericSignature.cpp b/lib/AST/GenericSignature.cpp
index e4e89e9..2b31ca1 100644
--- a/lib/AST/GenericSignature.cpp
+++ b/lib/AST/GenericSignature.cpp
@@ -975,6 +975,16 @@
       return;
     }
 
+    // If we have a superclass or concrete requirement, the conformance
+    // we need is stored in it.
+    if (source->kind == RequirementSource::Superclass ||
+        source->kind == RequirementSource::Concrete) {
+      auto conformance = source->getProtocolConformance();
+      assert(conformance.getRequirement() == conformingProto);
+      path.path.push_back({source->getAffectedType(), conformingProto});
+      return;
+    }
+
     // If we still have a parent, keep going.
     if (source->parent) {
       buildPath(reqs, source->parent, conformingProto, rootType,
diff --git a/lib/AST/GenericSignatureBuilder.cpp b/lib/AST/GenericSignatureBuilder.cpp
index 4a48432..0ce322a 100644
--- a/lib/AST/GenericSignatureBuilder.cpp
+++ b/lib/AST/GenericSignatureBuilder.cpp
@@ -61,6 +61,8 @@
   typedef EquivalenceClass::DerivedSameTypeComponent DerivedSameTypeComponent;
   typedef GenericSignatureBuilder::DelayedRequirement DelayedRequirement;
   typedef GenericSignatureBuilder::ResolvedType ResolvedType;
+  typedef GenericSignatureBuilder::UnresolvedType GSBUnresolvedType;
+  typedef GenericSignatureBuilder::RequirementRHS RequirementRHS;
 } // end anonymous namespace
 
 namespace llvm {
@@ -391,6 +393,20 @@
   };
 } // end namespace llvm
 
+namespace {
+  /// Retrieve the type described by the given unresolved tyoe.
+  Type getUnresolvedType(GSBUnresolvedType type,
+                         ArrayRef<GenericTypeParamType *> genericParams) {
+    if (auto concrete = type.dyn_cast<Type>())
+      return concrete;
+
+    if (auto pa = type.dyn_cast<PotentialArchetype *>())
+      return pa->getDependentType(genericParams);
+
+    return Type();
+  }
+}
+
 #pragma mark Requirement sources
 
 #ifndef NDEBUG
@@ -1681,8 +1697,7 @@
 }
 
 Optional<ConcreteConstraint>
-EquivalenceClass::findAnyConcreteConstraintAsWritten(
-                                      PotentialArchetype *preferredPA) const {
+EquivalenceClass::findAnyConcreteConstraintAsWritten(Type preferredType) const {
   // If we don't have a concrete type, there's no source.
   if (!concreteType) return None;
 
@@ -1691,7 +1706,8 @@
   for (const auto &constraint : concreteTypeConstraints) {
     if (constraint.source->getLoc().isValid()) {
       result = constraint;
-      if (!preferredPA || constraint.isSubjectEqualTo(preferredPA))
+      if (!preferredType ||
+          constraint.getSubjectDependentType({ })->isEqual(preferredType))
         return result;
     }
   }
@@ -1701,7 +1717,7 @@
 
 Optional<ConcreteConstraint>
 EquivalenceClass::findAnySuperclassConstraintAsWritten(
-                                      PotentialArchetype *preferredPA) const {
+                                                   Type preferredType) const {
   // If we don't have a superclass, there's no source.
   if (!superclass) return None;
 
@@ -1712,7 +1728,8 @@
         constraint.value->isEqual(superclass)) {
       result = constraint;
 
-      if (!preferredPA || constraint.isSubjectEqualTo(preferredPA))
+      if (!preferredType ||
+          constraint.getSubjectDependentType({ })->isEqual(preferredType))
         return result;
     }
   }
@@ -1915,11 +1932,108 @@
   return populateResult((nestedTypeNameCache[name] = std::move(entry)));
 }
 
+/// Determine whether any part of this potential archetype's path to the
+/// root contains the given equivalence class.
+static bool pathContainsEquivalenceClass(GenericSignatureBuilder &builder,
+                                         PotentialArchetype *pa,
+                                         EquivalenceClass *equivClass) {
+  // Chase the potential archetype up to the root.
+  for (; pa; pa = pa->getParent()) {
+    // Check whether this potential archetype is in the given equivalence
+    // class.
+    if (pa->getOrCreateEquivalenceClass(builder) == equivClass)
+      return true;
+  }
+
+  return false;
+}
+
 Type EquivalenceClass::getAnchor(
                             GenericSignatureBuilder &builder,
                             ArrayRef<GenericTypeParamType *> genericParams) {
-  auto anchorPA = members.front()->getArchetypeAnchor(builder);
-  return anchorPA->getDependentType(genericParams);
+  // Check whether the cache is valid.
+  if (archetypeAnchorCache.anchor &&
+      archetypeAnchorCache.numMembers == members.size()) {
+    ++NumArchetypeAnchorCacheHits;
+
+    // Reparent the anchor using genericParams.
+    return archetypeAnchorCache.anchor.subst(
+             [&](SubstitutableType *dependentType) {
+               if (auto gp = dyn_cast<GenericTypeParamType>(dependentType)) {
+                 unsigned index =
+                   GenericParamKey(gp).findIndexIn(genericParams);
+                 return Type(genericParams[index]);
+               }
+
+               return Type(dependentType);
+             },
+             MakeAbstractConformanceForGenericType());
+  }
+
+  // Map the members of this equivalence class to the best associated type
+  // within that equivalence class.
+  llvm::SmallDenseMap<EquivalenceClass *, AssociatedTypeDecl *> nestedTypes;
+
+  PotentialArchetype *bestGenericParam = nullptr;
+  for (auto member : members) {
+    // If the member is a generic parameter, keep the best generic parameter.
+    if (member->isGenericParam()) {
+      if (!bestGenericParam ||
+          compareDependentTypes(&member, &bestGenericParam) < 0)
+        bestGenericParam = member;
+      continue;
+    }
+
+    // If we saw a generic parameter, ignore any nested types.
+    if (bestGenericParam) continue;
+
+    // If the nested type doesn't have an associated type, skip it.
+    auto assocType = member->getResolvedAssociatedType();
+    if (!assocType) continue;
+
+    // Dig out the equivalence class of the parent.
+    auto parentEquivClass =
+      member->getParent()->getOrCreateEquivalenceClass(builder);
+
+    // If the path from this member to the root contains this equivalence
+    // class, it cannot be part of the anchor.
+    if (pathContainsEquivalenceClass(builder, member->getParent(), this))
+      continue;
+
+    // Take the best associated type for this equivalence class.
+    assocType = assocType->getAssociatedTypeAnchor();
+    auto &bestAssocType = nestedTypes[parentEquivClass];
+    if (!bestAssocType ||
+        compareAssociatedTypes(assocType, bestAssocType) < 0)
+      bestAssocType = assocType;
+  }
+
+  // If we found a generic parameter, return that.
+  if (bestGenericParam)
+    return bestGenericParam->getDependentType(genericParams);
+
+  // Determine the best anchor among the parent equivalence classes.
+  Type bestParentAnchor;
+  AssociatedTypeDecl *bestAssocType = nullptr;
+  std::pair<EquivalenceClass *, Identifier> bestNestedType;
+  for (const auto &nestedType : nestedTypes) {
+    auto parentAnchor = nestedType.first->getAnchor(builder, genericParams);
+    if (!bestParentAnchor ||
+        compareDependentTypes(parentAnchor, bestParentAnchor) < 0) {
+      bestParentAnchor = parentAnchor;
+      bestAssocType = nestedType.second;
+    }
+  }
+
+  // Form the anchor type.
+  Type anchorType = DependentMemberType::get(bestParentAnchor, bestAssocType);
+
+  // Record the cache miss and update the cache.
+  ++NumArchetypeAnchorCacheMisses;
+  archetypeAnchorCache.anchor = anchorType;
+  archetypeAnchorCache.numMembers = members.size();
+
+  return anchorType;
 }
 
 Type EquivalenceClass::getTypeInContext(GenericSignatureBuilder &builder,
@@ -2157,7 +2271,7 @@
 ConstraintResult GenericSignatureBuilder::handleUnresolvedRequirement(
                                    RequirementKind kind,
                                    UnresolvedType lhs,
-                                   RequirementRHS rhs,
+                                   UnresolvedRequirementRHS rhs,
                                    FloatingRequirementSource source,
                                    EquivalenceClass *unresolvedEquivClass,
                                    UnresolvedHandlingKind unresolvedHandling) {
@@ -2272,7 +2386,7 @@
   // appropriately.
   const RequirementSource *superclassSource;
   if (auto writtenSource =
-        equivClass->findAnySuperclassConstraintAsWritten(nullptr))
+        equivClass->findAnySuperclassConstraintAsWritten())
     superclassSource = writtenSource->source;
   else
     superclassSource = equivClass->superclassConstraints.front().source;
@@ -2287,22 +2401,8 @@
 /// Realize a potential archetype for this type parameter.
 PotentialArchetype *ResolvedType::realizePotentialArchetype(
                                            GenericSignatureBuilder &builder) {
-  if (auto pa = getPotentialArchetypeIfKnown())
-    return pa;
-
-  // Resolve the potential archetype now.
-  Type type = this->type.get<Type>();
-  assert(type->isTypeParameter());
-  auto pa =
-    builder.maybeResolveEquivalenceClass(type,
-                                         ArchetypeResolutionKind::WellFormed,
-                                         /*wantExactPotentialArchetype=*/true)
-      .getPotentialArchetypeIfKnown();
-  assert(pa && "Not a resolvable type!");
-
-  // Cache the potential archetype, now that it's been realized.
-  this->type = pa;
-  return pa;
+  // Realize and cache the potential archetype.
+  return builder.realizePotentialArchetype(type);
 }
 
 Type ResolvedType::getDependentType(GenericSignatureBuilder &builder) const {
@@ -2328,7 +2428,8 @@
 
   // Dig out the associated type.
   AssociatedTypeDecl *assocType = nullptr;
-  if (auto depMemTy = nested.getDependentType(builder)->getAs<DependentMemberType>())
+  if (auto depMemTy =
+        nested.getDependentType(builder)->getAs<DependentMemberType>())
     assocType = depMemTy->getAssocType();
 
   if (!assocType) return;
@@ -2546,60 +2647,6 @@
   llvm_unreachable("potential archetype total order failure");
 }
 
-PotentialArchetype *PotentialArchetype::getArchetypeAnchor(
-                                           GenericSignatureBuilder &builder) {
-  // Find the best archetype within this equivalence class.
-  PotentialArchetype *rep = getRepresentative();
-  PotentialArchetype *anchor;
-  if (auto parent = getParent()) {
-    // For a nested type, retrieve the parent archetype anchor first.
-    auto parentAnchor = parent->getArchetypeAnchor(builder);
-    assert(parentAnchor->getNestingDepth() <= parent->getNestingDepth());
-    anchor = parentAnchor->getNestedArchetypeAnchor(
-                                  getNestedName(), builder,
-                                  ArchetypeResolutionKind::CompleteWellFormed);
-
-    // FIXME: Hack for cases where we couldn't resolve the nested type.
-    if (!anchor)
-      anchor = rep;
-  } else {
-    anchor = rep;
-  }
-
-  auto equivClass = rep->getEquivalenceClassIfPresent();
-  if (!equivClass) return anchor;
-
-  // Check whether
-  if (equivClass->archetypeAnchorCache.anchor &&
-      equivClass->archetypeAnchorCache.numMembers
-        == equivClass->members.size()) {
-    ++NumArchetypeAnchorCacheHits;
-    return equivClass->archetypeAnchorCache.anchor;
-  }
-
-  // Find the best type within this equivalence class.
-  for (auto pa : equivClass->members) {
-    if (compareDependentTypes(&pa, &anchor) < 0)
-      anchor = pa;
-  }
-
-#if SWIFT_GSB_EXPENSIVE_ASSERTIONS
-  // Make sure that we did, in fact, get one that is better than all others.
-  for (auto pa : equivClass->members) {
-    assert((pa == anchor || compareDependentTypes(&anchor, &pa) < 0) &&
-           compareDependentTypes(&pa, &anchor) >= 0 &&
-           "archetype anchor isn't a total order");
-  }
-#endif
-
-  // Record the cache miss and update the cache.
-  ++NumArchetypeAnchorCacheMisses;
-  equivClass->archetypeAnchorCache.anchor = anchor;
-  equivClass->archetypeAnchorCache.numMembers = equivClass->members.size();
-
-  return anchor;
-}
-
 namespace {
   /// Function object used to suppress conflict diagnoses when we know we'll
   /// see them again later.
@@ -2667,32 +2714,6 @@
          SameTypeConflictCheckedLater());
 }
 
-PotentialArchetype *PotentialArchetype::getNestedArchetypeAnchor(
-                                           Identifier name,
-                                           GenericSignatureBuilder &builder,
-                                           ArchetypeResolutionKind kind) {
-  SmallVector<TypeDecl *, 4> concreteDecls;
-  auto bestType =
-    getOrCreateEquivalenceClass(builder)->lookupNestedType(builder, name,
-                                                           &concreteDecls);
-
-  // We didn't find any type with this name.
-  if (!bestType) return nullptr;
-
-  // Resolve the nested type.
-  auto resultPA = updateNestedTypeForConformance(builder, bestType, kind);
-
-  // Update for all of the concrete decls with this name, which will introduce
-  // various same-type constraints.
-  for (auto concreteDecl : concreteDecls) {
-    (void)updateNestedTypeForConformance(builder, concreteDecl,
-                                         ArchetypeResolutionKind::WellFormed);
-  }
-
-  return resultPA;
-}
-
-
 PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
                                               GenericSignatureBuilder &builder,
                                               TypeDecl *type,
@@ -3091,6 +3112,20 @@
   });
 }
 
+PotentialArchetype *GenericSignatureBuilder::realizePotentialArchetype(
+                                                     UnresolvedType &type) {
+  if (auto pa = type.dyn_cast<PotentialArchetype *>())
+    return pa;
+
+  auto pa = maybeResolveEquivalenceClass(type.get<Type>(),
+                                         ArchetypeResolutionKind::WellFormed,
+                                         /*wantExactPotentialArchetype=*/true)
+    .getPotentialArchetypeIfKnown();
+  if (pa) type = pa;
+
+  return pa;
+}
+
 ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass(
                                     Type type,
                                     ArchetypeResolutionKind resolutionKind,
@@ -3119,11 +3154,14 @@
     // Find the nested type declaration for this.
     auto baseEquivClass = resolvedBase.getEquivalenceClass(*this);
     TypeDecl *nestedTypeDecl;
+    SmallVector<TypeDecl *, 4> concreteDecls;
     if (auto assocType = depMemTy->getAssocType()) {
       nestedTypeDecl = assocType;
     } else {
       nestedTypeDecl =
-        baseEquivClass->lookupNestedType(*this, depMemTy->getName());
+        baseEquivClass->lookupNestedType(*this, depMemTy->getName(),
+                                         &concreteDecls);
+
       if (!nestedTypeDecl) {
         return ResolvedType::forUnresolved(baseEquivClass);
       }
@@ -3146,6 +3184,15 @@
     if (!nestedPA)
       return ResolvedType::forUnresolved(baseEquivClass);
 
+    if (resolutionKind != ArchetypeResolutionKind::AlreadyKnown) {
+      // Update for all of the concrete decls with this name, which will
+      // introduce various same-type constraints.
+      for (auto concreteDecl : concreteDecls) {
+        (void)basePA->updateNestedTypeForConformance(*this, concreteDecl,
+                                                     resolutionKind);
+      }
+    }
+
     // If base resolved to the anchor, then the nested potential archetype
     // we found is the resolved potential archetype. Return it directly,
     // so it doesn't need to be resolved again.
@@ -3497,7 +3544,9 @@
 
       bool shouldWarnAboutRedeclaration =
         source->kind == RequirementSource::RequirementSignatureSelf &&
-        assocTypeDecl->getDefaultDefinitionLoc().isNull();
+        assocTypeDecl->getDefaultDefinitionLoc().isNull() &&
+        (!assocTypeDecl->getInherited().empty() ||
+         assocTypeDecl->getTrailingWhereClause());
       for (auto inheritedType : knownInherited->second) {
         // If we have inherited associated type...
         if (auto inheritedAssocTypeDecl =
@@ -3784,8 +3833,8 @@
 }
 
 /// Map an unresolved type to a requirement right-hand-side.
-static GenericSignatureBuilder::RequirementRHS
-toRequirementRHS(GenericSignatureBuilder::UnresolvedType unresolved) {
+static GenericSignatureBuilder::UnresolvedRequirementRHS
+toUnresolvedRequirementRHS(GenericSignatureBuilder::UnresolvedType unresolved) {
   if (auto pa = unresolved.dyn_cast<PotentialArchetype *>())
     return pa;
 
@@ -3801,7 +3850,7 @@
   if (!resolvedConstraint) {
     return handleUnresolvedRequirement(
                              RequirementKind::Conformance, subject,
-                             toRequirementRHS(constraint), source,
+                             toUnresolvedRequirementRHS(constraint), source,
                              resolvedConstraint.getUnresolvedEquivClass(),
                              unresolvedHandling);
   }
@@ -4034,7 +4083,8 @@
   if (equivClass2 && equivClass2->superclass) {
     const RequirementSource *source2;
     if (auto existingSource2 =
-          equivClass2->findAnySuperclassConstraintAsWritten(OrigT2))
+          equivClass2->findAnySuperclassConstraintAsWritten(
+            OrigT2->getDependentType(getGenericParams())))
       source2 = existingSource2->source;
     else
       source2 = equivClass2->superclassConstraints.front().source;
@@ -4213,7 +4263,8 @@
   auto resolved1 = resolve(paOrT1, source);
   if (!resolved1) {
     return handleUnresolvedRequirement(RequirementKind::SameType, paOrT1,
-                                       toRequirementRHS(paOrT2), source,
+                                       toUnresolvedRequirementRHS(paOrT2),
+                                       source,
                                        resolved1.getUnresolvedEquivClass(),
                                        unresolvedHandling);
   }
@@ -4221,7 +4272,8 @@
   auto resolved2 = resolve(paOrT2, source);
   if (!resolved2) {
     return handleUnresolvedRequirement(RequirementKind::SameType, paOrT1,
-                                       toRequirementRHS(paOrT2), source,
+                                       toUnresolvedRequirementRHS(paOrT2),
+                                       source,
                                        resolved2.getUnresolvedEquivClass(),
                                        unresolvedHandling);
   }
@@ -4796,8 +4848,6 @@
   // Check for recursive or conflicting same-type bindings and superclass
   // constraints.
   for (auto &equivClass : Impl->EquivalenceClasses) {
-    auto archetype = equivClass.members.front()->getRepresentative();
-
     if (equivClass.concreteType) {
       // Check for recursive same-type bindings.
       if (isRecursiveConcreteType(&equivClass, /*isSuperclass=*/false)) {
@@ -4807,13 +4857,13 @@
 
           Diags.diagnose(constraint->source->getLoc(),
                          diag::recursive_same_type_constraint,
-                         archetype->getDependentType(genericParams),
+                         constraint->getSubjectDependentType(genericParams),
                          constraint->value);
         }
 
         equivClass.recursiveConcreteType = true;
       } else {
-        checkConcreteTypeConstraints(genericParams, archetype);
+        checkConcreteTypeConstraints(genericParams, &equivClass);
       }
     }
 
@@ -4831,12 +4881,12 @@
 
         equivClass.recursiveSuperclassType = true;
       } else {
-        checkSuperclassConstraints(genericParams, archetype);
+        checkSuperclassConstraints(genericParams, &equivClass);
       }
     }
 
-    checkConformanceConstraints(genericParams, archetype);
-    checkLayoutConstraints(genericParams, archetype);
+    checkConformanceConstraints(genericParams, &equivClass);
+    checkLayoutConstraints(genericParams, &equivClass);
   };
 
   // FIXME: Expand all conformance requirements. This is expensive :(
@@ -4845,10 +4895,9 @@
   }
 
   // Check same-type constraints.
-  for (const auto &equivClass : Impl->EquivalenceClasses) {
-    checkSameTypeConstraints(genericParams,
-                             equivClass.members[0]->getRepresentative());
-  };
+  for (auto &equivClass : Impl->EquivalenceClasses) {
+    checkSameTypeConstraints(genericParams, &equivClass);
+  }
 
   // Check for generic parameters which have been made concrete or equated
   // with each other.
@@ -4926,7 +4975,7 @@
 
 /// Turn a requirement right-hand side into an unresolved type.
 static GenericSignatureBuilder::UnresolvedType asUnresolvedType(
-                                GenericSignatureBuilder::RequirementRHS rhs) {
+                        GenericSignatureBuilder::UnresolvedRequirementRHS rhs) {
   if (auto pa = rhs.dyn_cast<PotentialArchetype *>())
     return GenericSignatureBuilder::UnresolvedType(pa);
 
@@ -5289,11 +5338,7 @@
 
 void GenericSignatureBuilder::checkConformanceConstraints(
                           ArrayRef<GenericTypeParamType *> genericParams,
-                          PotentialArchetype *pa) {
-  auto equivClass = pa->getEquivalenceClassIfPresent();
-  if (!equivClass || equivClass->conformsTo.empty())
-    return;
-
+                          EquivalenceClass *equivClass) {
   for (auto &entry : equivClass->conformsTo) {
     // Remove self-derived constraints.
     assert(!entry.second.empty() && "No constraints to work with?");
@@ -5341,7 +5386,8 @@
 namespace swift {
   bool operator<(const DerivedSameTypeComponent &lhs,
                  const DerivedSameTypeComponent &rhs) {
-    return compareDependentTypes(&lhs.anchor, &rhs.anchor) < 0;
+    return compareDependentTypes(getUnresolvedType(lhs.anchor, { }),
+                                 getUnresolvedType(rhs.anchor, { })) < 0;
   }
 } // namespace swift
 
@@ -5477,7 +5523,9 @@
     componentOf[depType] = componentIndex;
 
     // If this is a better anchor, record it.
-    if (compareDependentTypes(&pa, &components[componentIndex].anchor) < 0)
+    if (compareDependentTypes(
+                depType,
+                getUnresolvedType(components[componentIndex].anchor, { })) < 0)
       components[componentIndex].anchor = pa;
   }
 
@@ -5794,7 +5842,9 @@
       auto &newComponent = newComponents[newRepresentativeIndex];
 
       // If the old component has a better anchor, keep it.
-      if (compareDependentTypes(&oldComponent.anchor, &newComponent.anchor) < 0)
+      if (compareDependentTypes(
+                            getUnresolvedType(oldComponent.anchor, { }),
+                            getUnresolvedType(newComponent.anchor, { })) < 0)
         newComponent.anchor = oldComponent.anchor;
 
       // If the old component has a better concrete type source, keep it.
@@ -5816,9 +5866,8 @@
 
 void GenericSignatureBuilder::checkSameTypeConstraints(
                           ArrayRef<GenericTypeParamType *> genericParams,
-                          PotentialArchetype *pa) {
-  auto equivClass = pa->getEquivalenceClassIfPresent();
-  if (!equivClass || !equivClass->derivedSameTypeComponents.empty())
+                          EquivalenceClass *equivClass) {
+  if (!equivClass->derivedSameTypeComponents.empty())
     return;
 
   bool anyDerivedViaConcrete = false;
@@ -6020,10 +6069,7 @@
 
 void GenericSignatureBuilder::checkConcreteTypeConstraints(
                                  ArrayRef<GenericTypeParamType *> genericParams,
-                                 PotentialArchetype *representative) {
-  auto equivClass = representative->getOrCreateEquivalenceClass(*this);
-  assert(equivClass->concreteType && "No concrete type to check");
-
+                                 EquivalenceClass *equivClass) {
   checkConstraintList<Type>(
     genericParams, equivClass->concreteTypeConstraints,
     [&](const ConcreteConstraint &constraint) {
@@ -6057,8 +6103,7 @@
 
 void GenericSignatureBuilder::checkSuperclassConstraints(
                                  ArrayRef<GenericTypeParamType *> genericParams,
-                                 PotentialArchetype *representative) {
-  auto equivClass = representative->getOrCreateEquivalenceClass(*this);
+                                 EquivalenceClass *equivClass) {
   assert(equivClass->superclass && "No superclass constraint?");
 
   // FIXME: We should be substituting in the canonical type in context so
@@ -6146,9 +6191,8 @@
 
 void GenericSignatureBuilder::checkLayoutConstraints(
                                 ArrayRef<GenericTypeParamType *> genericParams,
-                                PotentialArchetype *pa) {
-  auto equivClass = pa->getEquivalenceClassIfPresent();
-  if (!equivClass || !equivClass->layout) return;
+                                EquivalenceClass *equivClass) {
+  if (!equivClass->layout) return;
 
   checkConstraintList<LayoutConstraint>(
     genericParams, equivClass->layoutConstraints,
@@ -6186,98 +6230,103 @@
 
     return bestSource;
   }
+
+  using SameTypeComponentRef = std::pair<EquivalenceClass *, unsigned>;
+
 } // end anonymous namespace
 
-void GenericSignatureBuilder::enumerateRequirements(llvm::function_ref<
+static int compareSameTypeComponents(const SameTypeComponentRef *lhsPtr,
+                                     const SameTypeComponentRef *rhsPtr){
+  Type lhsType = getUnresolvedType(
+      lhsPtr->first->derivedSameTypeComponents[lhsPtr->second].anchor,
+      { });
+  Type rhsType = getUnresolvedType(
+      rhsPtr->first->derivedSameTypeComponents[rhsPtr->second].anchor,
+      { });
+
+  return compareDependentTypes(lhsType, rhsType);
+}
+
+void GenericSignatureBuilder::enumerateRequirements(
+                   ArrayRef<GenericTypeParamType *> genericParams,
+                   llvm::function_ref<
                      void (RequirementKind kind,
-                           PotentialArchetype *archetype,
-                           GenericSignatureBuilder::RequirementRHS constraint,
+                           Type type,
+                           RequirementRHS constraint,
                            const RequirementSource *source)> f) {
-  // Collect all archetypes.
-  SmallVector<PotentialArchetype *, 8> archetypes;
+  // Collect all of the subject types that will be involved in constraints.
+  SmallVector<SameTypeComponentRef, 8> subjects;
   for (auto &equivClass : Impl->EquivalenceClasses) {
     if (equivClass.derivedSameTypeComponents.empty()) {
-      checkSameTypeConstraints(getGenericParams(),
-                               equivClass.members.front()->getRepresentative());
+      checkSameTypeConstraints(getGenericParams(), &equivClass);
     }
 
-    for (const auto &component : equivClass.derivedSameTypeComponents) {
-      archetypes.push_back(component.anchor);
-    }
+    for (unsigned i : indices(equivClass.derivedSameTypeComponents))
+      subjects.push_back({&equivClass, i});
   }
 
-  // Sort the archetypes in canonical order.
-  llvm::array_pod_sort(archetypes.begin(), archetypes.end(),
-                       compareDependentTypes);
+  // Sort the subject types in canonical order.
+  llvm::array_pod_sort(subjects.begin(), subjects.end(),
+                       compareSameTypeComponents);
 
-  auto genericParams = getGenericParams();
-  for (auto *archetype : archetypes) {
-    // Check whether this archetype is one of the anchors within its
-    // connected component. If so, we may need to emit a same-type constraint.
-    //
-    // FIXME: O(n) in the number of implied connected components within the
-    // equivalence class. The equivalence class should be small, but...
-    auto equivClass = archetype->getOrCreateEquivalenceClass(*this);
+  for (const auto &subject : subjects) {
+    // Dig out the subject type and its corresponding component.
+    auto equivClass = subject.first;
+    auto &component = equivClass->derivedSameTypeComponents[subject.second];
+    Type subjectType = getUnresolvedType(component.anchor, genericParams);
 
-    assert(!equivClass->derivedSameTypeComponents.empty() &&
-           "Didn't compute derived same-type components?");
-    auto knownAnchor =
-      std::find_if(equivClass->derivedSameTypeComponents.begin(),
-                   equivClass->derivedSameTypeComponents.end(),
-                   [&](const DerivedSameTypeComponent &component) {
-                     return component.anchor == archetype;
-                   });
+    // If this equivalence class is bound to a concrete type, equate the
+    // anchor with a concrete type.
+    if (Type concreteType = equivClass->concreteType) {
+      // If the parent of this anchor is also a concrete type, don't
+      // create a requirement.
+      if (!subjectType->is<GenericTypeParamType>() &&
+          maybeResolveEquivalenceClass(
+            subjectType->castTo<DependentMemberType>()->getBase(),
+            ArchetypeResolutionKind::WellFormed,
+            /*wantExactPotentialArchetype=*/false)
+            .getEquivalenceClass(*this)->concreteType)
+        continue;
+
+      auto source =
+        component.concreteTypeSource
+          ? component.concreteTypeSource
+          : RequirementSource::forAbstract(*this, subjectType);
+
+      // Drop recursive and invalid concrete-type constraints.
+      if (equivClass->recursiveConcreteType ||
+          equivClass->invalidConcreteType)
+        continue;
+
+      f(RequirementKind::SameType, subjectType, concreteType, source);
+      continue;
+    }
+
     std::function<void()> deferredSameTypeRequirement;
 
-    if (knownAnchor != equivClass->derivedSameTypeComponents.end()) {
-      // If this equivalence class is bound to a concrete type, equate the
-      // anchor with a concrete type.
-      if (Type concreteType = equivClass->concreteType) {
-        // If the parent of this anchor is also a concrete type, don't
-        // create a requirement.
-        if (!archetype->isGenericParam() &&
-            archetype->getParent()->isConcreteType())
-          continue;
-
-        auto source =
-          knownAnchor->concreteTypeSource
-            ? knownAnchor->concreteTypeSource
-            : RequirementSource::forAbstract(*this,
-                             archetype->getDependentType(getGenericParams()));
-
-        // Drop recursive and invalid concrete-type constraints.
-        if (equivClass->recursiveConcreteType ||
-            equivClass->invalidConcreteType)
-          continue;
-
-        f(RequirementKind::SameType, archetype, concreteType, source);
-        continue;
-      }
-
-      // If we're at the last anchor in the component, do nothing;
-      auto nextAnchor = knownAnchor;
-      ++nextAnchor;
-      if (nextAnchor != equivClass->derivedSameTypeComponents.end() /* &&
-          !equivClass->areAllRequirementsDerived()*/) {
-        // Form a same-type constraint from this anchor within the component
-        // to the next.
-        // FIXME: Distinguish between explicit and inferred here?
-        auto otherPA = nextAnchor->anchor;
-        deferredSameTypeRequirement =
-          [&f, archetype, otherPA, this, genericParams] {
-            f(RequirementKind::SameType, archetype, otherPA,
-              RequirementSource::forAbstract(
-                                     *this,
-                                     archetype->getDependentType(genericParams)));
-          };
-      }
+    // If we're at the last anchor in the component, do nothing;
+    if (subject.second + 1 != equivClass->derivedSameTypeComponents.size()) {
+      // Form a same-type constraint from this anchor within the component
+      // to the next.
+      // FIXME: Distinguish between explicit and inferred here?
+      auto &nextComponent =
+        equivClass->derivedSameTypeComponents[subject.second + 1];
+      Type otherSubjectType =
+        getUnresolvedType(nextComponent.anchor, genericParams);
+      deferredSameTypeRequirement =
+        [&f, subjectType, otherSubjectType, this, genericParams] {
+          f(RequirementKind::SameType, subjectType, otherSubjectType,
+            RequirementSource::forAbstract(*this, otherSubjectType));
+        };
     }
+
     SWIFT_DEFER {
       if (deferredSameTypeRequirement) deferredSameTypeRequirement();
     };
 
-    // If this is not the archetype anchor, we're done.
-    if (archetype != archetype->getArchetypeAnchor(*this))
+    // If this is not the first component anchor in its equivalence class,
+    // we're done.
+    if (subject.second > 0)
       continue;
 
     // If we have a superclass, produce a superclass requirement
@@ -6289,12 +6338,9 @@
           });
 
       if (!bestSource)
-        bestSource =
-          RequirementSource::forAbstract(
-                                 *this,
-                                 archetype->getDependentType(genericParams));
+        bestSource = RequirementSource::forAbstract(*this, subjectType);
 
-      f(RequirementKind::Superclass, archetype, equivClass->superclass,
+      f(RequirementKind::Superclass, subjectType, equivClass->superclass,
         *bestSource);
     }
 
@@ -6306,12 +6352,9 @@
                             return layout == equivClass->layout;
                           });
       if (!bestSource)
-        bestSource =
-          RequirementSource::forAbstract(
-                                   *this,
-                                   archetype->getDependentType(genericParams));
+        bestSource = RequirementSource::forAbstract(*this, subjectType);
 
-      f(RequirementKind::Layout, archetype, equivClass->layout, *bestSource);
+      f(RequirementKind::Layout, subjectType, equivClass->layout, *bestSource);
     }
 
     // Enumerate conformance requirements.
@@ -6339,7 +6382,7 @@
     // Enumerate the conformance requirements.
     for (auto proto : protocols) {
       assert(protocolSources.count(proto) == 1 && "Missing conformance?");
-      f(RequirementKind::Conformance, archetype, 
+      f(RequirementKind::Conformance, subjectType,
         proto->getDeclaredInterfaceType(),
         protocolSources.find(proto)->second);
     }
@@ -6352,29 +6395,30 @@
 
 void GenericSignatureBuilder::dump(llvm::raw_ostream &out) {
   out << "Requirements:";
-  enumerateRequirements([&](RequirementKind kind,
-                            PotentialArchetype *archetype,
-                            GenericSignatureBuilder::RequirementRHS constraint,
+  enumerateRequirements(getGenericParams(),
+                        [&](RequirementKind kind,
+                            Type type,
+                            RequirementRHS constraint,
                             const RequirementSource *source) {
     switch (kind) {
     case RequirementKind::Conformance:
     case RequirementKind::Superclass:
       out << "\n  ";
-      out << archetype->getDebugName() << " : " 
+      out << type.getString() << " : "
           << constraint.get<Type>().getString() << " [";
       source->print(out, &Context.SourceMgr);
       out << "]";
       break;
     case RequirementKind::Layout:
       out << "\n  ";
-      out << archetype->getDebugName() << " : "
+      out << type.getString() << " : "
           << constraint.get<LayoutConstraint>().getString() << " [";
       source->print(out, &Context.SourceMgr);
       out << "]";
       break;
     case RequirementKind::SameType:
       out << "\n  ";
-      out << archetype->getDebugName() << " == " ;
+      out << type.getString() << " == " ;
       if (auto secondType = constraint.dyn_cast<Type>()) {
         out << secondType.getString();
       } else {
@@ -6410,9 +6454,11 @@
 static void collectRequirements(GenericSignatureBuilder &builder,
                                 ArrayRef<GenericTypeParamType *> params,
                                 SmallVectorImpl<Requirement> &requirements) {
-  builder.enumerateRequirements([&](RequirementKind kind,
-          GenericSignatureBuilder::PotentialArchetype *archetype,
-          GenericSignatureBuilder::RequirementRHS type,
+  builder.enumerateRequirements(
+      params,
+      [&](RequirementKind kind,
+          Type depTy,
+          RequirementRHS type,
           const RequirementSource *source) {
     // Filter out derived requirements... except for concrete-type requirements
     // on generic parameters. The exception is due to the canonicalization of
@@ -6420,31 +6466,26 @@
     // they have been mapped to a concrete type.
     if (source->isDerivedRequirement() &&
         !(kind == RequirementKind::SameType &&
-          archetype->isGenericParam() &&
+          depTy->is<GenericTypeParamType>() &&
           type.is<Type>()))
       return;
 
-    auto depTy = archetype->getDependentType(params);
-
     if (depTy->hasError())
       return;
 
     Type repTy;
     if (auto concreteTy = type.dyn_cast<Type>()) {
-      // Maybe we were equated to a concrete type...
+      // Maybe we were equated to a concrete or dependent type...
       repTy = concreteTy;
 
       // Drop requirements involving concrete types containing
       // unresolved associated types.
       if (repTy->findUnresolvedDependentMemberType())
         return;
-    } else if (auto layoutConstraint = type.dyn_cast<LayoutConstraint>()) {
+    } else {
+      auto layoutConstraint = type.get<LayoutConstraint>();
       requirements.push_back(Requirement(kind, depTy, layoutConstraint));
       return;
-    } else {
-      // ...or to a dependent type.
-      repTy = type.get<GenericSignatureBuilder::PotentialArchetype *>()
-          ->getDependentType(params);
     }
 
     if (repTy->hasError())
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index a72b63a..1844f1f 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -1453,6 +1453,7 @@
       case types::TY_ImportedModules:
       case types::TY_TBD:
       case types::TY_ModuleTrace:
+      case types::TY_OptRecord:
         // We could in theory handle assembly or LLVM input, but let's not.
         // FIXME: What about LTO?
         Diags.diagnose(SourceLoc(), diag::error_unexpected_input_file,
@@ -2236,6 +2237,19 @@
     }
   }
 
+  if (C.getArgs().hasArg(options::OPT_save_optimization_record,
+                         options::OPT_save_optimization_record_path)) {
+    if (OI.CompilerMode == OutputInfo::Mode::SingleCompile) {
+      auto filename = *getOutputFilenameFromPathArgOrAsTopLevel(
+          OI, C.getArgs(), options::OPT_save_optimization_record_path,
+          types::TY_OptRecord, /*TreatAsTopLevelOutput=*/true, "opt.yaml", Buf);
+
+      Output->setAdditionalOutputForType(types::TY_OptRecord, filename);
+    } else
+      // FIXME: We should use the OutputMap in this case.
+      Diags.diagnose({}, diag::warn_opt_remark_disabled);
+  }
+
   // Choose the Objective-C header output path.
   if ((isa<MergeModuleJobAction>(JA) ||
        (isa<CompileJobAction>(JA) &&
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index bca1dfc..f5c638e 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -272,6 +272,7 @@
     case types::TY_SwiftDeps:
     case types::TY_ModuleTrace:
     case types::TY_TBD:
+    case types::TY_OptRecord:
       llvm_unreachable("Output type can never be primary output.");
     case types::TY_INVALID:
       llvm_unreachable("Invalid type ID");
@@ -448,6 +449,13 @@
     Arguments.push_back(TBDPath.c_str());
   }
 
+  const std::string &OptRecordPath =
+      context.Output.getAdditionalOutputForType(types::TY_OptRecord);
+  if (!OptRecordPath.empty()) {
+    Arguments.push_back("-save-optimization-record-path");
+    Arguments.push_back(OptRecordPath.c_str());
+  }
+
   if (context.Args.hasArg(options::OPT_migrate_keep_objc_visibility)) {
     Arguments.push_back("-migrate-keep-objc-visibility");
   }
@@ -586,6 +594,7 @@
     case types::TY_SwiftDeps:
     case types::TY_Remapping:
     case types::TY_ModuleTrace:
+    case types::TY_OptRecord:
       llvm_unreachable("Output type can never be primary output.");
     case types::TY_INVALID:
       llvm_unreachable("Invalid type ID");
diff --git a/lib/Driver/Types.cpp b/lib/Driver/Types.cpp
index d0b60bc..d69378e 100644
--- a/lib/Driver/Types.cpp
+++ b/lib/Driver/Types.cpp
@@ -77,6 +77,7 @@
   case types::TY_ImportedModules:
   case types::TY_TBD:
   case types::TY_ModuleTrace:
+  case types::TY_OptRecord:
     return true;
   case types::TY_Image:
   case types::TY_Object:
@@ -131,6 +132,7 @@
   case types::TY_Remapping:
   case types::TY_IndexData:
   case types::TY_ModuleTrace:
+  case types::TY_OptRecord:
     return false;
   case types::TY_INVALID:
     llvm_unreachable("Invalid type ID.");
@@ -169,6 +171,7 @@
   case types::TY_Remapping:
   case types::TY_IndexData:
   case types::TY_ModuleTrace:
+  case types::TY_OptRecord:
     return false;
   case types::TY_INVALID:
     llvm_unreachable("Invalid type ID.");
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 692ae17..8d88e15 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -1188,6 +1188,20 @@
       return true;
     }
   }
+  if (const Arg *A = Args.getLastArg(OPT_sil_inline_caller_benefit_reduction_factor)) {
+    if (StringRef(A->getValue()).getAsInteger(10, Opts.CallerBaseBenefitReductionFactor)) {
+      Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
+                     A->getAsString(Args), A->getValue());
+      return true;
+    }
+  }
+  if (const Arg *A = Args.getLastArg(OPT_sil_unroll_threshold)) {
+    if (StringRef(A->getValue()).getAsInteger(10, Opts.UnrollThreshold)) {
+      Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
+                     A->getAsString(Args), A->getValue());
+      return true;
+    }
+  }
   if (const Arg *A = Args.getLastArg(OPT_num_threads)) {
     if (StringRef(A->getValue()).getAsInteger(10, Opts.NumThreads)) {
       Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
@@ -1305,6 +1319,9 @@
       !Args.hasArg(OPT_disable_mandatory_semantic_arc_opts);
   Opts.EnableLargeLoadableTypes |= Args.hasArg(OPT_enable_large_loadable_types);
 
+  if (const Arg *A = Args.getLastArg(OPT_save_optimization_record_path))
+    Opts.OptRecordFile = A->getValue();
+
   if (Args.hasArg(OPT_debug_on_sil)) {
     // Derive the name of the SIL file for debugging from
     // the regular outputfile.
diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp
index 644294f..fba8441 100644
--- a/lib/FrontendTool/FrontendTool.cpp
+++ b/lib/FrontendTool/FrontendTool.cpp
@@ -75,6 +75,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/Timer.h"
+#include "llvm/Support/YAMLTraits.h"
 #include "llvm/Target/TargetMachine.h"
 
 #include <memory>
@@ -507,6 +508,21 @@
   C.NumSILOptGlobalVariables = Module.getSILGlobalList().size();
 }
 
+static std::unique_ptr<llvm::raw_fd_ostream>
+createOptRecordFile(StringRef Filename, DiagnosticEngine &DE) {
+  if (Filename.empty())
+    return nullptr;
+
+  std::error_code EC;
+  auto File = llvm::make_unique<llvm::raw_fd_ostream>(Filename, EC,
+                                                      llvm::sys::fs::F_None);
+  if (EC) {
+    DE.diagnose(SourceLoc(), diag::cannot_open_file, Filename, EC.message());
+    return nullptr;
+  }
+  return File;
+}
+
 /// Performs the compile requested by the user.
 /// \param Instance Will be reset after performIRGeneration when the verifier
 ///                 mode is NoVerify and there were no errors.
@@ -748,9 +764,9 @@
     return Context.hadError();
   }
 
+  const auto &SILOpts = Invocation.getSILOptions();
   if (!opts.TBDPath.empty()) {
-    const auto &silOpts = Invocation.getSILOptions();
-    auto hasMultipleIRGenThreads = silOpts.NumThreads > 1;
+    auto hasMultipleIRGenThreads = SILOpts.NumThreads > 1;
     auto installName = opts.TBDInstallName.empty()
                            ? "lib" + Invocation.getModuleName().str() + ".dylib"
                            : opts.TBDInstallName;
@@ -825,6 +841,13 @@
     return Context.hadError();
   }
 
+  std::unique_ptr<llvm::raw_fd_ostream> OptRecordFile =
+      createOptRecordFile(SILOpts.OptRecordFile, Instance.getDiags());
+  if (OptRecordFile)
+    SM->setOptRecordStream(llvm::make_unique<llvm::yaml::Output>(
+                               *OptRecordFile, &Instance.getSourceMgr()),
+                           std::move(OptRecordFile));
+
   // Perform "stable" optimizations that are invariant across compiler versions.
   if (Action == FrontendOptions::MergeModules) {
     // Don't run diagnostic passes at all.
@@ -1059,8 +1082,8 @@
         !astGuaranteedToCorrespondToSIL)
       break;
 
-    const auto &silOpts = Invocation.getSILOptions();
-    auto hasMultipleIRGenThreads = silOpts.NumThreads > 1;
+    const auto &SILOpts = Invocation.getSILOptions();
+    auto hasMultipleIRGenThreads = SILOpts.NumThreads > 1;
     bool error;
     if (PrimarySourceFile)
       error = validateTBD(PrimarySourceFile, *IRModule, hasMultipleIRGenThreads,
diff --git a/lib/IRGen/GenBuiltin.cpp b/lib/IRGen/GenBuiltin.cpp
index d8ea216..d34a0a1 100644
--- a/lib/IRGen/GenBuiltin.cpp
+++ b/lib/IRGen/GenBuiltin.cpp
@@ -271,14 +271,14 @@
     return out.add(v); \
   }
 
-#define BUILTIN_RUNTIME_CALL(id, name, attrs) \
-  if (Builtin.ID == BuiltinValueKind::id) { \
-    llvm::CallInst *call = IGF.Builder.CreateCall(IGF.IGM.get##id##Fn(),  \
-                           args.claimNext()); \
-    call->setCallingConv(IGF.IGM.DefaultCC); \
-    call->setDoesNotThrow(); \
-    return out.add(call); \
- }
+#define BUILTIN_RUNTIME_CALL(id, name, attrs)                                  \
+  if (Builtin.ID == BuiltinValueKind::id) {                                    \
+    auto *fn = cast<llvm::Function>(IGF.IGM.get##id##Fn());                    \
+    llvm::CallInst *call = IGF.Builder.CreateCall(fn, args.claimNext());       \
+    call->setCallingConv(fn->getCallingConv());                                \
+    call->setAttributes(fn->getAttributes());                                  \
+    return out.add(call);                                                      \
+  }
 
 #define BUILTIN_BINARY_OPERATION_WITH_OVERFLOW(id, name, uncheckedID, attrs, overload) \
 if (Builtin.ID == BuiltinValueKind::id) { \
diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp
index 7072d75..e12ce75 100644
--- a/lib/IRGen/GenCall.cpp
+++ b/lib/IRGen/GenCall.cpp
@@ -938,13 +938,16 @@
         break;
       }
 
-      // If the coercion type is a struct, we need to expand it.
-      auto type = AI.getCoerceToType();
-      if (auto expandedType = dyn_cast<llvm::StructType>(type)) {
-        for (size_t j = 0, e = expandedType->getNumElements(); j != e; ++j)
-          ParamIRTypes.push_back(expandedType->getElementType(j));
+      // If the coercion type is a struct which can be flattened, we need to
+      // expand it.
+      auto *coercedTy = AI.getCoerceToType();
+      if (AI.isDirect() && AI.getCanBeFlattened() &&
+          isa<llvm::StructType>(coercedTy)) {
+        const auto *ST = cast<llvm::StructType>(coercedTy);
+        for (unsigned EI : range(ST->getNumElements()))
+          ParamIRTypes.push_back(ST->getElementType(EI));
       } else {
-        ParamIRTypes.push_back(type);
+        ParamIRTypes.push_back(coercedTy);
       }
       break;
     }
@@ -1685,18 +1688,24 @@
 }
 
 static void emitDirectExternalArgument(IRGenFunction &IGF, SILType argType,
-                                       llvm::Type *toTy, Explosion &in,
-                                       Explosion &out) {
+                                       const clang::CodeGen::ABIArgInfo &AI,
+                                       Explosion &in, Explosion &out) {
+  bool IsDirectFlattened = AI.isDirect() && AI.getCanBeFlattened();
+  bool IsIndirect = !AI.isDirect();
+
   // If we're supposed to pass directly as a struct type, that
   // really means expanding out as multiple arguments.
-  ArrayRef<llvm::Type *> expandedTys = expandScalarOrStructTypeToArray(toTy);
+  llvm::Type *coercedTy = AI.getCoerceToType();
+  ArrayRef<llvm::Type *> expandedTys =
+      expandScalarOrStructTypeToArray(coercedTy);
 
   auto &argTI = cast<LoadableTypeInfo>(IGF.getTypeInfo(argType));
   auto inputSchema = argTI.getSchema();
 
   // Check to see if we can pairwise coerce Swift's exploded scalars
   // to Clang's expanded elements.
-  if (canCoerceToSchema(IGF.IGM, expandedTys, inputSchema)) {
+  if ((IsDirectFlattened || IsIndirect) &&
+      canCoerceToSchema(IGF.IGM, expandedTys, inputSchema)) {
     for (auto outputTy : expandedTys) {
       llvm::Value *arg = in.claimNext();
       if (arg->getType() != outputTy)
@@ -1710,7 +1719,7 @@
   Address temporary;
   Size tempSize;
   std::tie(temporary, tempSize) =
-      allocateForCoercion(IGF, argTI.getStorageType(), toTy, "coerced-arg");
+      allocateForCoercion(IGF, argTI.getStorageType(), coercedTy, "coerced-arg");
   IGF.Builder.CreateLifetimeStart(temporary, tempSize);
 
   // Store to a temporary.
@@ -1720,19 +1729,19 @@
 
   // Bitcast the temporary to the expected type.
   Address coercedAddr =
-    IGF.Builder.CreateBitCast(temporary, toTy->getPointerTo());
+      IGF.Builder.CreateBitCast(temporary, coercedTy->getPointerTo());
 
-  // Project out individual elements if necessary.
-  if (auto expansionTy = dyn_cast<llvm::StructType>(toTy)) {
-    auto layout = IGF.IGM.DataLayout.getStructLayout(expansionTy);
-    for (unsigned i = 0, e = expansionTy->getNumElements(); i != e; ++i) {
-      auto fieldOffset = Size(layout->getElementOffset(i));
-      auto fieldAddr = IGF.Builder.CreateStructGEP(coercedAddr, i, fieldOffset);
-      out.add(IGF.Builder.CreateLoad(fieldAddr));
+  if (IsDirectFlattened && isa<llvm::StructType>(coercedTy)) {
+    // Project out individual elements if necessary.
+    auto *ST = cast<llvm::StructType>(coercedTy);
+    const auto *layout = IGF.IGM.DataLayout.getStructLayout(ST);
+    for (unsigned EI : range(ST->getNumElements())) {
+      auto offset = Size(layout->getElementOffset(EI));
+      auto address = IGF.Builder.CreateStructGEP(coercedAddr, EI, offset);
+      out.add(IGF.Builder.CreateLoad(address));
     }
-
-  // Otherwise, collect the single scalar.
   } else {
+    // Otherwise, collect the single scalar.
     out.add(IGF.Builder.CreateLoad(coercedAddr));
   }
 
@@ -1880,7 +1889,7 @@
         break;
       }
 
-      emitDirectExternalArgument(IGF, paramType, toTy, in, out);
+      emitDirectExternalArgument(IGF, paramType, AI, in, out);
       break;
     }
     case clang::CodeGen::ABIArgInfo::Indirect: {
@@ -1960,24 +1969,24 @@
 }
 
 /// Emit a direct parameter that was passed under a C-based CC.
-static void emitDirectForeignParameter(IRGenFunction &IGF,
-                                       Explosion &in,
-                                       llvm::Type *coercionTy,
-                                       Explosion &out,
-                                       SILType paramType,
+static void emitDirectForeignParameter(IRGenFunction &IGF, Explosion &in,
+                                       const clang::CodeGen::ABIArgInfo &AI,
+                                       Explosion &out, SILType paramType,
                                        const LoadableTypeInfo &paramTI) {
   // The ABI IR types for the entrypoint might differ from the
   // Swift IR types for the body of the function.
 
-  ArrayRef<llvm::Type*> expandedTys;
-  if (auto expansionTy = dyn_cast<llvm::StructType>(coercionTy)) {
-    expandedTys = makeArrayRef(expansionTy->element_begin(),
-                               expansionTy->getNumElements());
+  llvm::Type *coercionTy = AI.getCoerceToType();
 
-  // Fast-path a really common case.  This check assumes that either
-  // the storage type of a type is an llvm::StructType or it has a
-  // single-element explosion.
+  ArrayRef<llvm::Type*> expandedTys;
+  if (AI.isDirect() && AI.getCanBeFlattened() &&
+      isa<llvm::StructType>(coercionTy)) {
+    const auto *ST = cast<llvm::StructType>(coercionTy);
+    expandedTys = makeArrayRef(ST->element_begin(), ST->getNumElements());
   } else if (coercionTy == paramTI.getStorageType()) {
+    // Fast-path a really common case.  This check assumes that either
+    // the storage type of a type is an llvm::StructType or it has a
+    // single-element explosion.
     out.add(in.claimNext());
     return;
   } else {
@@ -2060,11 +2069,10 @@
 
   switch (AI.getKind()) {
   case clang::CodeGen::ABIArgInfo::Extend:
-  case clang::CodeGen::ABIArgInfo::Direct: {
-    emitDirectForeignParameter(IGF, params, AI.getCoerceToType(),
-                               paramExplosion, paramTy, paramTI);
+  case clang::CodeGen::ABIArgInfo::Direct:
+    emitDirectForeignParameter(IGF, params, AI, paramExplosion, paramTy,
+                               paramTI);
     return;
-  }
   case clang::CodeGen::ABIArgInfo::Indirect: {
     Address address = paramTI.getAddressForPointer(params.claimNext());
     paramTI.loadAsTake(IGF, address, paramExplosion);
diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp
index 59ce9d0..b931047 100644
--- a/lib/IRGen/IRGenModule.cpp
+++ b/lib/IRGen/IRGenModule.cpp
@@ -845,7 +845,7 @@
     Attrs.addAttribute("target-features", allFeatures);
   }
   if (IRGen.Opts.OptimizeForSize)
-    Attrs.addAttribute(llvm::Attribute::OptimizeForSize);
+    Attrs.addAttribute(llvm::Attribute::MinSize);
 }
 
 llvm::AttributeList IRGenModule::constructInitialAttributes() {
diff --git a/lib/SIL/OptimizationRemark.cpp b/lib/SIL/OptimizationRemark.cpp
index 7147554..87f8b26 100644
--- a/lib/SIL/OptimizationRemark.cpp
+++ b/lib/SIL/OptimizationRemark.cpp
@@ -17,11 +17,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "swift/SIL/OptimizationRemark.h"
-#include "swift/AST/ASTContext.h"
 #include "swift/AST/DiagnosticEngine.h"
 #include "swift/AST/DiagnosticsSIL.h"
-#include "swift/SIL/SILFunction.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace swift;
@@ -57,25 +56,93 @@
   return OS.str();
 }
 
-Emitter::Emitter(StringRef PassName, ASTContext &Ctx)
-    : Ctx(Ctx), PassName(PassName),
+Emitter::Emitter(StringRef PassName, SILModule &M)
+    : Module(M), PassName(PassName),
       PassedEnabled(
-          Ctx.LangOpts.OptimizationRemarkPassedPattern &&
-          Ctx.LangOpts.OptimizationRemarkPassedPattern->match(PassName)),
+          M.getASTContext().LangOpts.OptimizationRemarkPassedPattern &&
+          M.getASTContext().LangOpts.OptimizationRemarkPassedPattern->match(
+              PassName)),
       MissedEnabled(
-          Ctx.LangOpts.OptimizationRemarkMissedPattern &&
-          Ctx.LangOpts.OptimizationRemarkMissedPattern->match(PassName)) {}
+          M.getASTContext().LangOpts.OptimizationRemarkMissedPattern &&
+          M.getASTContext().LangOpts.OptimizationRemarkMissedPattern->match(
+              PassName)) {}
 
 template <typename RemarkT, typename... ArgTypes>
-static void emitRemark(ASTContext &Ctx, const RemarkT &R,
-                       Diag<ArgTypes...> ID) {
-  Ctx.Diags.diagnose(R.getLocation(), ID, R.getMsg());
+static void emitRemark(SILModule &Module, const Remark<RemarkT> &R,
+                       Diag<ArgTypes...> ID, bool DiagEnabled) {
+  if (auto *Out = Module.getOptRecordStream())
+    // YAMLTraits takes a non-const reference even when outputting.
+    *Out << const_cast<Remark<RemarkT> &>(R);
+  if (DiagEnabled)
+    Module.getASTContext().Diags.diagnose(R.getLocation(), ID, R.getMsg());
 }
 
 void Emitter::emit(const RemarkPassed &R) {
-  emitRemark(Ctx, R, diag::opt_remark_passed);
+  emitRemark(Module, R, diag::opt_remark_passed, isEnabled<RemarkPassed>());
 }
 
 void Emitter::emit(const RemarkMissed &R) {
-  emitRemark(Ctx, R, diag::opt_remark_missed);
+  emitRemark(Module, R, diag::opt_remark_missed, isEnabled<RemarkMissed>());
 }
+
+namespace llvm {
+namespace yaml {
+
+template <typename KindT> struct MappingTraits<Remark<KindT>> {
+  static void mapping(llvm::yaml::IO &io, Remark<KindT> &R) {
+    assert(io.outputting() && "input not implemented");
+
+    if (io.mapTag("!Passed", std::is_same<KindT, RemarkPassed>::value))
+      ;
+    else if (io.mapTag("!Missed", std::is_same<KindT, RemarkMissed>::value))
+      ;
+    else
+      llvm_unreachable("Unknown remark type");
+
+    // The attributes are read-only for now since we're only support outputting
+    // them.
+    StringRef PassName = R.getPassName();
+    io.mapRequired("Pass", PassName);
+    StringRef Id = R.getIdentifier();
+    io.mapRequired("Name", Id);
+
+    SourceLoc Loc = R.getLocation();
+    if (!io.outputting() || Loc.isValid())
+      io.mapOptional("DebugLoc", Loc);
+
+    StringRef FN = R.getFunction()->getName();
+    io.mapRequired("Function", FN);
+    io.mapOptional("Args", R.getArgs());
+  }
+};
+
+template <> struct MappingTraits<SourceLoc> {
+  static void mapping(IO &io, SourceLoc &Loc) {
+    assert(io.outputting() && "input not yet implemented");
+
+    SourceManager *SM = static_cast<SourceManager *>(io.getContext());
+    unsigned BufferID = SM->findBufferContainingLoc(Loc);
+    StringRef File = SM->getIdentifierForBuffer(BufferID);
+    unsigned Line, Col;
+    std::tie(Line, Col) = SM->getLineAndColumn(Loc, BufferID);
+
+    io.mapRequired("File", File);
+    io.mapRequired("Line", Line);
+    io.mapRequired("Column", Col);
+  }
+};
+
+// Implement this as a mapping for now to get proper quotation for the value.
+template <> struct MappingTraits<OptRemark::Argument> {
+  static void mapping(IO &io, OptRemark::Argument &A) {
+    assert(io.outputting() && "input not yet implemented");
+    io.mapRequired(A.Key.data(), A.Val);
+    if (A.Loc.isValid())
+      io.mapOptional("DebugLoc", A.Loc);
+  }
+};
+
+} // end namespace yaml
+} // end namespace llvm
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(OptRemark::Argument)
diff --git a/lib/SIL/SILFunctionType.cpp b/lib/SIL/SILFunctionType.cpp
index eec64f7..3acbc1c 100644
--- a/lib/SIL/SILFunctionType.cpp
+++ b/lib/SIL/SILFunctionType.cpp
@@ -1924,7 +1924,7 @@
 const SILConstantInfo &TypeConverter::getConstantInfo(SILDeclRef constant) {
   auto found = ConstantTypes.find(constant);
   if (found != ConstantTypes.end())
-    return found->second;
+    return *found->second;
 
   // First, get a function type for the constant.  This creates the
   // right type for a getter or setter.
@@ -1956,14 +1956,17 @@
         silFnType.print(llvm::dbgs());
         llvm::dbgs() << "\n");
 
-  auto result = ConstantTypes.try_emplace(constant,
-                                          formalInterfaceType,
-                                          bridgedTypes.Pattern,
-                                          loweredInterfaceType,
-                                          silFnType,
-                                          genericEnv);
-  assert(result.second);
-  return result.first->second;
+  auto resultBuf = M.allocate(sizeof(SILConstantInfo),
+                              alignof(SILConstantInfo));
+
+  auto result = ::new (resultBuf) SILConstantInfo{formalInterfaceType,
+                                                  bridgedTypes.Pattern,
+                                                  loweredInterfaceType,
+                                                  silFnType,
+                                                  genericEnv};
+  auto inserted = ConstantTypes.insert({constant, result});
+  assert(inserted.second);
+  return *result;
 }
 
 /// Returns the SILParameterInfo for the given declaration's `self` parameter.
@@ -2092,7 +2095,7 @@
 
   auto found = ConstantOverrideTypes.find({derived, base});
   if (found != ConstantOverrideTypes.end())
-    return found->second;
+    return *found->second;
 
   assert(requiresNewVTableEntry(base) && "base must not be an override");
 
@@ -2146,14 +2149,18 @@
                                                derived);
 
   // Build the SILConstantInfo and cache it.
-  auto result = ConstantOverrideTypes.try_emplace({derived, base},
+  auto resultBuf = M.allocate(sizeof(SILConstantInfo),
+                              alignof(SILConstantInfo));
+  auto result = ::new (resultBuf) SILConstantInfo{
     derivedInterfaceTy,
     bridgedTypes.Pattern,
     overrideLoweredInterfaceTy,
     fnTy,
-    derivedInfo.GenericEnv);
-  assert(result.second);
-  return result.first->second;
+    derivedInfo.GenericEnv};
+  
+  auto inserted = ConstantOverrideTypes.insert({{derived, base}, result});
+  assert(inserted.second);
+  return *result;
 }
 
 namespace {
diff --git a/lib/SIL/SILInstruction.cpp b/lib/SIL/SILInstruction.cpp
index fdbc84fd..589b5c1 100644
--- a/lib/SIL/SILInstruction.cpp
+++ b/lib/SIL/SILInstruction.cpp
@@ -255,6 +255,27 @@
   }
 }
 
+void SILInstruction::replaceAllUsesPairwiseWith(
+    const llvm::SmallVectorImpl<SILValue> &NewValues) {
+  auto Results = getResults();
+
+  // If we don't have any results, fast-path out without asking the other
+  // instruction for its results.
+  if (Results.empty()) {
+    assert(NewValues.empty());
+    return;
+  }
+
+  // Replace values with the corresponding values of the list. Make sure they
+  // are all the same type.
+  assert(Results.size() == NewValues.size());
+  for (unsigned i : indices(Results)) {
+    assert(Results[i]->getType() == NewValues[i]->getType() &&
+           "Can only replace results with new values of the same type");
+    Results[i]->replaceAllUsesWith(NewValues[i]);
+  }
+}
+
 namespace {
 class InstructionDestroyer
     : public SILInstructionVisitor<InstructionDestroyer> {
@@ -1365,10 +1386,6 @@
   setSubclassData(NewData);
 }
 
-unsigned MultipleValueInstructionResult::getIndex() const {
-  return unsigned((getSubclassData() >> IndexBitOffset) & IndexMask);
-}
-
 void MultipleValueInstructionResult::setIndex(unsigned NewIndex) {
   // We only take the last 3 bytes for simplicity. If more bits are needed at
   // some point, we can take 5 bits we are burning here and combine them with
diff --git a/lib/SIL/SILModule.cpp b/lib/SIL/SILModule.cpp
index cbef5b8..56ea768 100644
--- a/lib/SIL/SILModule.cpp
+++ b/lib/SIL/SILModule.cpp
@@ -27,6 +27,7 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/YAMLTraits.h"
 #include <functional>
 using namespace swift;
 using namespace Lowering;
@@ -781,3 +782,9 @@
   setSerialized();
 }
 
+void SILModule::setOptRecordStream(
+    std::unique_ptr<llvm::yaml::Output> &&Stream,
+    std::unique_ptr<llvm::raw_ostream> &&RawStream) {
+  OptRecordStream = std::move(Stream);
+  OptRecordRawStream = std::move(RawStream);
+}
diff --git a/lib/SIL/SILOwnershipVerifier.cpp b/lib/SIL/SILOwnershipVerifier.cpp
index e699e2b..8372dce 100644
--- a/lib/SIL/SILOwnershipVerifier.cpp
+++ b/lib/SIL/SILOwnershipVerifier.cpp
@@ -596,6 +596,7 @@
   }
 ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP_OR_METATYPE(MustBeLive, ClassMethod)
 ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP_OR_METATYPE(MustBeLive, ObjCMethod)
+ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP_OR_METATYPE(MustBeLive, ObjCSuperMethod)
 #undef ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP_OR_METATYPE
 
 // Trivial if trivial typed, otherwise must accept owned?
@@ -608,7 +609,6 @@
     return {compatible, UseLifetimeConstraint::USE_LIFETIME_CONSTRAINT};       \
   }
 ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(MustBeLive, SuperMethod)
-ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(MustBeLive, ObjCSuperMethod)
 ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(MustBeLive, BridgeObjectToWord)
 ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(MustBeLive, CopyBlock)
 ACCEPTS_ANY_NONTRIVIAL_OWNERSHIP(MustBeLive, OpenExistentialBox)
diff --git a/lib/SIL/SILWitnessTable.cpp b/lib/SIL/SILWitnessTable.cpp
index 7374be5..4e0728e 100644
--- a/lib/SIL/SILWitnessTable.cpp
+++ b/lib/SIL/SILWitnessTable.cpp
@@ -158,8 +158,7 @@
   return Mod.getASTContext().getIdentifier(Name);
 }
 
-bool SILWitnessTable::conformanceIsSerialized(ProtocolConformance *conformance,
-                                              ResilienceStrategy strategy) {
+bool SILWitnessTable::conformanceIsSerialized(ProtocolConformance *conformance) {
   // Serialize witness tables for conformances synthesized by
   // the ClangImporter.
   if (isa<ClangModuleUnit>(conformance->getDeclContext()->getModuleScopeContext()))
diff --git a/lib/SILGen/ArgumentSource.cpp b/lib/SILGen/ArgumentSource.cpp
index 1ed7c72..5661f17 100644
--- a/lib/SILGen/ArgumentSource.cpp
+++ b/lib/SILGen/ArgumentSource.cpp
@@ -59,8 +59,26 @@
     Storage.get<RValueStorage>(StoredKind).Value.rewriteType(newType);
     return;
   case Kind::Expr:
-    Expr *expr = Storage.get<Expr*>(StoredKind);
-    if (expr->getType()->isEqual(newType)) return;
+    Expr *&expr = Storage.get<Expr*>(StoredKind);
+    CanType oldType = expr->getType()->getCanonicalType();
+
+    // Usually nothing is required.
+    if (oldType == newType) return;
+
+    // Sometimes we need to wrap the expression in a single-element tuple.
+    // This is only necessary because we don't break down the argument list
+    // when dealing with SILGenApply.
+    if (auto newTuple = dyn_cast<TupleType>(newType)) {
+      if (newTuple->getNumElements() == 1 &&
+          newTuple.getElementType(0) == oldType) {
+        expr = TupleExpr::create(newType->getASTContext(),
+                                 SourceLoc(), expr, {}, {}, SourceLoc(),
+                                 /*trailing closure*/ false,
+                                 /*implicit*/ true, newType);
+        return;
+      }
+    }
+
     llvm_unreachable("unimplemented! hope it doesn't happen");
   }
   llvm_unreachable("bad kind");
diff --git a/lib/SILGen/SILGenBridging.cpp b/lib/SILGen/SILGenBridging.cpp
index e0c933f..f3a4cc2 100644
--- a/lib/SILGen/SILGenBridging.cpp
+++ b/lib/SILGen/SILGenBridging.cpp
@@ -138,8 +138,7 @@
   if (witnessConv.isSILIndirect(witnessConv.getParameters()[0])
       && !swiftValue.getType().isAddress()) {
     auto tmp = SGF.emitTemporaryAllocation(loc, swiftValue.getType());
-    SGF.B.emitStoreValueOperation(loc, swiftValue.getValue(), tmp,
-                                  StoreOwnershipQualifier::Init);
+    SGF.B.createStoreBorrowOrTrivial(loc, swiftValue.borrow(SGF, loc), tmp);
     swiftValue = ManagedValue::forUnmanaged(tmp);
   }
 
diff --git a/lib/SILGen/SILGenBuilder.cpp b/lib/SILGen/SILGenBuilder.cpp
index 4411825..0512eb1 100644
--- a/lib/SILGen/SILGenBuilder.cpp
+++ b/lib/SILGen/SILGenBuilder.cpp
@@ -714,6 +714,23 @@
   return ManagedValue::forUnmanaged(v);
 }
 
+void SILGenBuilder::createStoreBorrow(SILLocation loc, ManagedValue value,
+                                      SILValue address) {
+  assert(value.getOwnershipKind() == ValueOwnershipKind::Guaranteed);
+  createStoreBorrow(loc, value.getValue(), address);
+}
+
+void SILGenBuilder::createStoreBorrowOrTrivial(SILLocation loc,
+                                               ManagedValue value,
+                                               SILValue address) {
+  if (value.getOwnershipKind() == ValueOwnershipKind::Trivial) {
+    createStore(loc, value, address, StoreOwnershipQualifier::Trivial);
+    return;
+  }
+
+  createStoreBorrow(loc, value, address);
+}
+
 //===----------------------------------------------------------------------===//
 //                            Switch Enum Builder
 //===----------------------------------------------------------------------===//
diff --git a/lib/SILGen/SILGenBuilder.h b/lib/SILGen/SILGenBuilder.h
index 29ddeac..120387f 100644
--- a/lib/SILGen/SILGenBuilder.h
+++ b/lib/SILGen/SILGenBuilder.h
@@ -206,6 +206,14 @@
   ManagedValue createLoadBorrow(SILLocation loc, ManagedValue base);
   ManagedValue createFormalAccessLoadBorrow(SILLocation loc, ManagedValue base);
 
+  using SILBuilder::createStoreBorrow;
+  void createStoreBorrow(SILLocation loc, ManagedValue value, SILValue address);
+
+  /// Create a store_borrow if we have a non-trivial value and a store [trivial]
+  /// otherwise.
+  void createStoreBorrowOrTrivial(SILLocation loc, ManagedValue value,
+                                  SILValue address);
+
   /// Prepares a buffer to receive the result of an expression, either using the
   /// 'emit into' initialization buffer if available, or allocating a temporary
   /// allocation if not. After the buffer has been prepared, the rvalueEmitter
diff --git a/lib/SILGen/SILGenType.cpp b/lib/SILGen/SILGenType.cpp
index c148189..ce8f9b6 100644
--- a/lib/SILGen/SILGenType.cpp
+++ b/lib/SILGen/SILGenType.cpp
@@ -381,8 +381,7 @@
     Serialized = IsNotSerialized;
 
     // ... or if the conformance itself thinks it should be.
-    if (SILWitnessTable::conformanceIsSerialized(
-            Conformance, SGM.M.getSwiftModule()->getResilienceStrategy()))
+    if (SILWitnessTable::conformanceIsSerialized(Conformance))
       Serialized = IsSerialized;
 
     // Not all protocols use witness tables; in this case we just skip
diff --git a/lib/SILOptimizer/Analysis/MemoryBehavior.cpp b/lib/SILOptimizer/Analysis/MemoryBehavior.cpp
index 4bc2fa0..7253f72 100644
--- a/lib/SILOptimizer/Analysis/MemoryBehavior.cpp
+++ b/lib/SILOptimizer/Analysis/MemoryBehavior.cpp
@@ -357,7 +357,7 @@
                                                     SILValue V2,
                                                     RetainObserveKind M) {
   size_t idx1 =
-    MemoryBehaviorNodeToIndex.getIndex(V1->getCanonicalSILNodeInObject());
+    MemoryBehaviorNodeToIndex.getIndex(V1->getRepresentativeSILNodeInObject());
   assert(idx1 != std::numeric_limits<size_t>::max() &&
          "~0 index reserved for empty/tombstone keys");
   size_t idx2 = MemoryBehaviorNodeToIndex.getIndex(
diff --git a/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp b/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp
index 8162028..18fee20 100644
--- a/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp
+++ b/lib/SILOptimizer/IPO/DeadFunctionElimination.cpp
@@ -223,15 +223,22 @@
         auto id = component.getComputedPropertyId();
         switch (id.getKind()) {
         case KeyPathPatternComponent::ComputedPropertyId::DeclRef: {
-          auto decl = cast<AbstractFunctionDecl>(id.getDeclRef().getDecl());
-          if (auto clas = dyn_cast<ClassDecl>(decl->getDeclContext())) {
-            ensureAliveClassMethod(getMethodInfo(decl, /*witness*/ false),
-                                   dyn_cast<FuncDecl>(decl),
-                                   clas);
-          } else if (isa<ProtocolDecl>(decl->getDeclContext())) {
-            ensureAliveProtocolMethod(getMethodInfo(decl, /*witness*/ true));
+          auto declRef = id.getDeclRef();
+          if (declRef.isForeign) {
+            // Nothing to do here: foreign functions aren't ours to be deleting.
+            // (And even if they were, they're ObjC-dispatched and thus anchored
+            // already: see isAnchorFunction)
           } else {
-            llvm_unreachable("key path keyed by a non-class, non-protocol method");
+            auto decl = cast<AbstractFunctionDecl>(declRef.getDecl());
+            if (auto clas = dyn_cast<ClassDecl>(decl->getDeclContext())) {
+              ensureAliveClassMethod(getMethodInfo(decl, /*witness*/ false),
+                                     dyn_cast<FuncDecl>(decl),
+                                     clas);
+            } else if (isa<ProtocolDecl>(decl->getDeclContext())) {
+              ensureAliveProtocolMethod(getMethodInfo(decl, /*witness*/ true));
+            } else {
+              llvm_unreachable("key path keyed by a non-class, non-protocol method");
+            }
           }
           break;
         }
diff --git a/lib/SILOptimizer/IPO/GlobalOpt.cpp b/lib/SILOptimizer/IPO/GlobalOpt.cpp
index 423922d..6f39a33 100644
--- a/lib/SILOptimizer/IPO/GlobalOpt.cpp
+++ b/lib/SILOptimizer/IPO/GlobalOpt.cpp
@@ -108,7 +108,9 @@
   bool handleTailAddr(int TailIdx, SILInstruction *I,
                       llvm::SmallVectorImpl<StoreInst *> &TailStores);
 
-  void optimizeObjectAllocation(AllocRefInst *ARI);
+  void
+  optimizeObjectAllocation(AllocRefInst *ARI,
+                           llvm::SmallVector<SILInstruction *, 4> &ToRemove);
   void replaceFindStringCall(ApplyInst *FindStringCall);
 
   SILGlobalVariable *getVariableOfGlobalInit(SILFunction *AddrF);
@@ -1218,7 +1220,8 @@
 ///     func getarray() -> [Int] {
 ///       return [1, 2, 3]
 ///     }
-void SILGlobalOpt::optimizeObjectAllocation(AllocRefInst *ARI) {
+void SILGlobalOpt::optimizeObjectAllocation(
+    AllocRefInst *ARI, llvm::SmallVector<SILInstruction *, 4> &ToRemove) {
 
   if (ARI->isObjC())
     return;
@@ -1270,6 +1273,10 @@
   DEBUG(llvm::dbgs() << "Outline global variable in " <<
         ARI->getFunction()->getName() << '\n');
 
+  assert(Cl->hasFixedLayout(Module->getSwiftModule(),
+                            ResilienceExpansion::Minimal) &&
+    "constructor call of resilient class should prevent static allocation");
+
   // Create a name for the outlined global variable.
   GlobalVariableMangler Mangler;
   std::string GlobName =
@@ -1296,14 +1303,14 @@
     assert(MemberStore);
     ObjectArgs.push_back(Cloner.clone(
                            cast<SingleValueInstruction>(MemberStore->getSrc())));
-    MemberStore->eraseFromParent();
+    ToRemove.push_back(MemberStore);
   }
   // Create the initializers for the tail elements.
   unsigned NumBaseElements = ObjectArgs.size();
   for (StoreInst *TailStore : TailStores) {
     ObjectArgs.push_back(Cloner.clone(
                            cast<SingleValueInstruction>(TailStore->getSrc())));
-    TailStore->eraseFromParent();
+    ToRemove.push_back(TailStore);
   }
   // Create the initializer for the object itself.
   SILBuilder StaticInitBuilder(Glob);
@@ -1314,12 +1321,13 @@
   SILBuilder B(ARI);
   GlobalValueInst *GVI = B.createGlobalValue(ARI->getLoc(), Glob);
   B.createStrongRetain(ARI->getLoc(), GVI, B.getDefaultAtomicity());
-  while (!ARI->use_empty()) {
-    Operand *Use = *ARI->use_begin();
+  llvm::SmallVector<Operand *, 8> Worklist(ARI->use_begin(), ARI->use_end());
+  while (!Worklist.empty()) {
+    auto *Use = Worklist.pop_back_val();
     SILInstruction *User = Use->getUser();
     switch (User->getKind()) {
       case SILInstructionKind::DeallocRefInst:
-        User->eraseFromParent();
+        ToRemove.push_back(User);
         break;
       default:
         Use->set(GVI);
@@ -1332,8 +1340,7 @@
     replaceFindStringCall(FindStringCall);
   }
 
-  ARI->eraseFromParent();
-
+  ToRemove.push_back(ARI);
   HasChanged = true;
 }
 
@@ -1366,6 +1373,9 @@
   if (!cacheDecl)
     return;
 
+  assert(cacheDecl->hasFixedLayout(Module->getSwiftModule(),
+                                   ResilienceExpansion::Minimal));
+
   SILType wordTy = cacheType.getFieldType(
                             cacheDecl->getStoredProperties().front(), *Module);
 
@@ -1456,6 +1466,15 @@
     for (auto &BB : F) {
       bool IsCold = ColdBlocks.isCold(&BB);
       auto Iter = BB.begin();
+
+      // We can't remove instructions willy-nilly as we iterate because
+      // that might cause a pointer to the next instruction to become
+      // garbage, causing iterator invalidations (and crashes).
+      // Instead, we collect in a list the instructions we want to remove
+      // and erase the BB they belong to at the end of the loop, once we're
+      // sure it's safe to do so.
+      llvm::SmallVector<SILInstruction *, 4> ToRemove;
+
       while (Iter != BB.end()) {
         SILInstruction *I = &*Iter;
         Iter++;
@@ -1473,10 +1492,12 @@
             // for serializable functions.
             // TODO: We may do the optimization _after_ serialization in the
             // pass pipeline.
-            optimizeObjectAllocation(ARI);
+            optimizeObjectAllocation(ARI, ToRemove);
           }
         }
       }
+      for (auto *I : ToRemove)
+        I->eraseFromParent();
     }
   }
 
diff --git a/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp b/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp
index dd43738..e231f12 100644
--- a/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp
+++ b/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp
@@ -29,7 +29,6 @@
 using llvm::DenseMap;
 using llvm::MapVector;
 
-static const uint64_t SILLoopUnrollThreshold = 250;
 
 namespace {
 
@@ -187,6 +186,9 @@
   // It is used to estimate the cost of the callee
   // inside a loop.
   const uint64_t InsnsPerBB = 4;
+  // Use command-line threshold for unrolling.
+  const uint64_t SILLoopUnrollThreshold = Loop->getBlocks().empty() ? 0 : 
+    (Loop->getBlocks())[0]->getParent()->getModule().getOptions().UnrollThreshold;
   for (auto *BB : Loop->getBlocks()) {
     for (auto &Inst : *BB) {
       if (!Loop->canDuplicate(&Inst))
diff --git a/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp b/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp
index 0613f31..6df2adb 100644
--- a/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp
+++ b/lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp
@@ -419,8 +419,7 @@
     }
 
     // Stores *to* the allocation are writes.
-    if ((isa<StoreInst>(User) || isa<AssignInst>(User)) &&
-        UI->getOperandNumber() == 1) {
+    if (isa<StoreInst>(User) && UI->getOperandNumber() == 1) {
       if (PointeeType.is<TupleType>()) {
         UsesToScalarize.push_back(User);
         continue;
@@ -431,8 +430,6 @@
       DIUseKind Kind;
       if (InStructSubElement)
         Kind = DIUseKind::PartialStore;
-      else if (isa<AssignInst>(User))
-        Kind = DIUseKind::InitOrAssign;
       else if (PointeeType.isTrivial(User->getModule()))
         Kind = DIUseKind::InitOrAssign;
       else
@@ -632,17 +629,6 @@
         continue;
       }
 
-      // Scalarize AssignInst
-      if (auto *AI = dyn_cast<AssignInst>(User)) {
-        SILBuilderWithScope B(User, AI);
-        getScalarizedElements(AI->getOperand(0), ElementTmps, AI->getLoc(), B);
-
-        for (unsigned i = 0, e = ElementAddrs.size(); i != e; ++i)
-          B.createAssign(AI->getLoc(), ElementTmps[i], ElementAddrs[i]);
-        AI->eraseFromParent();
-        continue;
-      }
-      
       // Scalarize StoreInst
       if (auto *SI = dyn_cast<StoreInst>(User)) {
         SILBuilderWithScope B(User, SI);
diff --git a/lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp b/lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp
index 0eba2c4..15f1745 100644
--- a/lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp
+++ b/lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp
@@ -147,7 +147,7 @@
 
 /// Given an aggregate value and an access path, extract the value indicated by
 /// the path.
-static SILValue ExtractSubElement(SILValue Val, unsigned SubElementNumber,
+static SILValue extractSubElement(SILValue Val, unsigned SubElementNumber,
                                   SILBuilder &B, SILLocation Loc) {
   SILType ValTy = Val->getType();
   
@@ -159,7 +159,7 @@
       unsigned NumSubElt = getNumSubElements(EltTy, B.getModule());
       if (SubElementNumber < NumSubElt) {
         Val = B.emitTupleExtract(Loc, Val, EltNo, EltTy);
-        return ExtractSubElement(Val, SubElementNumber, B, Loc);
+        return extractSubElement(Val, SubElementNumber, B, Loc);
       }
       
       SubElementNumber -= NumSubElt;
@@ -176,7 +176,7 @@
       
       if (SubElementNumber < NumSubElt) {
         Val = B.emitStructExtract(Loc, Val, D);
-        return ExtractSubElement(Val, SubElementNumber, B, Loc);
+        return extractSubElement(Val, SubElementNumber, B, Loc);
       }
       
       SubElementNumber -= NumSubElt;
@@ -324,7 +324,7 @@
                       SmallVectorImpl<std::pair<SILValue, unsigned>> &Result,
                       llvm::SmallBitVector &ConflictingValues) {
   // Handle store and assign.
-  if (isa<StoreInst>(Inst) || isa<AssignInst>(Inst)) {
+  if (isa<StoreInst>(Inst)) {
     unsigned StartSubElt = computeSubelement(Inst->getOperand(1), TheMemory);
     assert(StartSubElt != ~0U && "Store within enum projection not handled");
     SILType ValTy = Inst->getOperand(0)->getType();
@@ -513,11 +513,10 @@
 /// AggregateAvailableValues - Given a bunch of primitive subelement values,
 /// build out the right aggregate type (LoadTy) by emitting tuple and struct
 /// instructions as necessary.
-static SILValue
-AggregateAvailableValues(SILInstruction *Inst, SILType LoadTy,
-                         SILValue Address,
-                         ArrayRef<std::pair<SILValue, unsigned>> AvailableValues,
-                         unsigned FirstElt) {
+static SILValue aggregateAvailableValues(
+    SILInstruction *Inst, SILType LoadTy, SILValue Address,
+    ArrayRef<std::pair<SILValue, unsigned>> AvailableValues,
+    unsigned FirstElt) {
   assert(LoadTy.isObject());
   SILModule &M = Inst->getModule();
   
@@ -559,8 +558,8 @@
       if (anyMissing(FirstElt, NumSubElt, AvailableValues))
         EltAddr = B.createTupleElementAddr(Inst->getLoc(), Address, EltNo,
                                            EltTy.getAddressType());
-      
-      ResultElts.push_back(AggregateAvailableValues(Inst, EltTy, EltAddr,
+
+      ResultElts.push_back(aggregateAvailableValues(Inst, EltTy, EltAddr,
                                                     AvailableValues, FirstElt));
       FirstElt += NumSubElt;
     }
@@ -582,8 +581,8 @@
       if (anyMissing(FirstElt, NumSubElt, AvailableValues))
         EltAddr = B.createStructElementAddr(Inst->getLoc(), Address, FD,
                                             EltTy.getAddressType());
-      
-      ResultElts.push_back(AggregateAvailableValues(Inst, EltTy, EltAddr,
+
+      ResultElts.push_back(aggregateAvailableValues(Inst, EltTy, EltAddr,
                                                     AvailableValues, FirstElt));
       FirstElt += NumSubElt;
     }
@@ -597,7 +596,7 @@
     return B.createLoad(Inst->getLoc(), Address,
                         LoadOwnershipQualifier::Unqualified);
 
-  SILValue EltVal = ExtractSubElement(Val.first, Val.second, B, Inst->getLoc());
+  SILValue EltVal = extractSubElement(Val.first, Val.second, B, Inst->getLoc());
   // It must be the same type as LoadTy if available.
   assert(EltVal->getType() == LoadTy &&
          "Subelement types mismatch");
@@ -692,9 +691,9 @@
   // type as the load did, and emit smaller) loads for any subelements that were
   // not available.
   auto Load = cast<LoadInst>(Inst);
-  auto NewVal = AggregateAvailableValues(Load, LoadTy, Load->getOperand(),
+  auto NewVal = aggregateAvailableValues(Load, LoadTy, Load->getOperand(),
                                          AvailableValues, FirstElt);
-  
+
   ++NumLoadPromoted;
   
   // Simply replace the load.
@@ -757,8 +756,8 @@
   // type as the load did, and emit smaller) loads for any subelements that were
   // not available.
   auto NewVal =
-  AggregateAvailableValues(DAI, LoadTy, Address, AvailableValues, FirstElt);
-  
+      aggregateAvailableValues(DAI, LoadTy, Address, AvailableValues, FirstElt);
+
   ++NumDestroyAddrPromoted;
   
   DEBUG(llvm::dbgs() << "  *** Promoting destroy_addr: " << *DAI << "\n");
diff --git a/lib/SILOptimizer/Transforms/OwnershipModelEliminator.cpp b/lib/SILOptimizer/Transforms/OwnershipModelEliminator.cpp
index 55e41a1..20df3d3 100644
--- a/lib/SILOptimizer/Transforms/OwnershipModelEliminator.cpp
+++ b/lib/SILOptimizer/Transforms/OwnershipModelEliminator.cpp
@@ -23,10 +23,11 @@
 //===----------------------------------------------------------------------===//
 
 #define DEBUG_TYPE "sil-ownership-model-eliminator"
-#include "swift/SILOptimizer/PassManager/Transforms.h"
+#include "swift/SIL/Projection.h"
 #include "swift/SIL/SILBuilder.h"
 #include "swift/SIL/SILFunction.h"
 #include "swift/SIL/SILVisitor.h"
+#include "swift/SILOptimizer/PassManager/Transforms.h"
 
 using namespace swift;
 
@@ -83,6 +84,8 @@
   bool visitUnmanagedAutoreleaseValueInst(UnmanagedAutoreleaseValueInst *UAVI);
   bool visitCheckedCastBranchInst(CheckedCastBranchInst *CBI);
   bool visitSwitchEnumInst(SwitchEnumInst *SWI);
+  bool visitDestructureStructInst(DestructureStructInst *DSI);
+  bool visitDestructureTupleInst(DestructureTupleInst *DTI);
 };
 
 } // end anonymous namespace
@@ -249,6 +252,42 @@
   return true;
 }
 
+static void splitDestructure(SILBuilder &B, SILInstruction *I, SILValue Op) {
+  assert((isa<DestructureStructInst>(I) || isa<DestructureTupleInst>(I)) &&
+         "Only destructure operations can be passed to splitDestructure");
+
+  SILModule &M = I->getModule();
+  SILLocation Loc = I->getLoc();
+  SILType OpType = Op->getType();
+
+  llvm::SmallVector<Projection, 8> Projections;
+  Projection::getFirstLevelProjections(OpType, M, Projections);
+  assert(Projections.size() == I->getNumResults());
+
+  llvm::SmallVector<SILValue, 8> NewValues;
+  for (unsigned i : indices(Projections)) {
+    const auto &Proj = Projections[i];
+    NewValues.push_back(Proj.createObjectProjection(B, Loc, Op).get());
+    assert(NewValues.back()->getType() == I->getResults()[i]->getType() &&
+           "Expected created projections and results to be the same types");
+  }
+
+  I->replaceAllUsesPairwiseWith(NewValues);
+  I->eraseFromParent();
+}
+
+bool OwnershipModelEliminatorVisitor::visitDestructureStructInst(
+    DestructureStructInst *DSI) {
+  splitDestructure(B, DSI, DSI->getOperand());
+  return true;
+}
+
+bool OwnershipModelEliminatorVisitor::visitDestructureTupleInst(
+    DestructureTupleInst *DTI) {
+  splitDestructure(B, DTI, DTI->getOperand());
+  return true;
+}
+
 //===----------------------------------------------------------------------===//
 //                           Top Level Entry Point
 //===----------------------------------------------------------------------===//
diff --git a/lib/SILOptimizer/Transforms/PerformanceInliner.cpp b/lib/SILOptimizer/Transforms/PerformanceInliner.cpp
index b0075f6..8190a3e 100644
--- a/lib/SILOptimizer/Transforms/PerformanceInliner.cpp
+++ b/lib/SILOptimizer/Transforms/PerformanceInliner.cpp
@@ -256,7 +256,9 @@
         return false;
     }
 
-    BaseBenefit = BaseBenefit / 2;
+    // Use command line option to control inlining in Osize mode.
+    const uint64_t CallerBaseBenefitReductionFactor = AI.getFunction()->getModule().getOptions().CallerBaseBenefitReductionFactor;
+    BaseBenefit = BaseBenefit / CallerBaseBenefitReductionFactor;
   }
 
   // It is always OK to inline a simple call.
@@ -897,8 +899,7 @@
     DominanceAnalysis *DA = PM->getAnalysis<DominanceAnalysis>();
     SILLoopAnalysis *LA = PM->getAnalysis<SILLoopAnalysis>();
     SideEffectAnalysis *SEA = PM->getAnalysis<SideEffectAnalysis>();
-    OptRemark::Emitter ORE(DEBUG_TYPE,
-                           getFunction()->getModule().getASTContext());
+    OptRemark::Emitter ORE(DEBUG_TYPE, getFunction()->getModule());
 
     if (getOptions().InlineThreshold == 0) {
       return;
diff --git a/lib/Sema/CodeSynthesis.cpp b/lib/Sema/CodeSynthesis.cpp
index 261ada8..3e45117 100644
--- a/lib/Sema/CodeSynthesis.cpp
+++ b/lib/Sema/CodeSynthesis.cpp
@@ -857,6 +857,7 @@
     // materializeForSet either.
     auto *baseMFS = baseASD->getMaterializeForSetFunc();
     if (baseMFS != nullptr &&
+        !baseMFS->hasForcedStaticDispatch() &&
         baseASD->isSetterAccessibleFrom(storage->getDeclContext())) {
       materializeForSet->setOverriddenDecl(baseMFS);
     }
diff --git a/lib/Sema/TypeCheckConstraints.cpp b/lib/Sema/TypeCheckConstraints.cpp
index 6715f8b..68d90dd 100644
--- a/lib/Sema/TypeCheckConstraints.cpp
+++ b/lib/Sema/TypeCheckConstraints.cpp
@@ -1012,6 +1012,7 @@
   options |= TR_AllowUnspecifiedTypes;
   options |= TR_AllowUnboundGenerics;
   options |= TR_InExpression;
+  options |= TR_AllowIUO;
   bool hadParameterError = false;
 
   GenericTypeToArchetypeResolver resolver(closure);
diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp
index 0023391..73d54ed 100644
--- a/lib/Sema/TypeCheckDecl.cpp
+++ b/lib/Sema/TypeCheckDecl.cpp
@@ -1118,6 +1118,8 @@
   // top-level variables in a script file are accessible from other files,
   // even though the PBD is inside a TopLevelCodeDecl.
   TypeResolutionOptions options = TR_InExpression;
+
+  options |= TR_AllowIUO;
   if (binding->getInit(entryNumber)) {
     // If we have an initializer, we can also have unknown types.
     options |= TR_AllowUnspecifiedTypes;
@@ -2717,7 +2719,7 @@
 
       // Suggest '@nonobjc' to suppress this error, and not try to
       // infer @objc for anything.
-      tc.diagnose(decl, diag::optional_req_near_match_nonobjc, true)
+      tc.diagnose(decl, diag::req_near_match_nonobjc, true)
         .fixItInsert(decl->getAttributeInsertionLoc(false), "@nonobjc ");
       break;
     }
@@ -4246,10 +4248,14 @@
     GenericTypeToArchetypeResolver resolver(SD);
 
     bool isInvalid = TC.validateType(SD->getElementTypeLoc(), SD,
-                                     TypeResolutionOptions(),
+                                     TR_AllowIUO,
                                      &resolver);
+    TypeResolutionOptions options;
+    options |= TR_SubscriptParameters;
+    options |= TR_AllowIUO;
+
     isInvalid |= TC.typeCheckParameterList(SD->getIndices(), SD,
-                                           TR_SubscriptParameters,
+                                           options,
                                            resolver);
 
     if (isInvalid || SD->isInvalid()) {
@@ -4786,9 +4792,8 @@
                              GenericTypeResolver &resolver) {
     bool hadError = false;
     for (auto paramList : fd->getParameterLists()) {
-      hadError |= TC.typeCheckParameterList(paramList, fd,
-                                            TypeResolutionOptions(),
-                                            resolver);
+      hadError |=
+          TC.typeCheckParameterList(paramList, fd, TR_AllowIUO, resolver);
     }
 
     return hadError;
@@ -4799,9 +4804,10 @@
 
     bool badType = false;
     if (!FD->getBodyResultTypeLoc().isNull()) {
-      TypeResolutionOptions options;
+      TypeResolutionOptions options = TR_AllowIUO;
       if (FD->hasDynamicSelf())
         options |= TR_DynamicSelfResult;
+
       if (TC.validateType(FD->getBodyResultTypeLoc(), FD, options,
                           &resolver)) {
         badType = true;
@@ -6705,6 +6711,13 @@
             !baseASD->isSetterAccessibleFrom(overridingASD->getDeclContext()))
           return;
 
+        // A materializeForSet for an override of storage with a
+        // forced static dispatch materializeForSet is not itself an
+        // override.
+        if (kind == AccessorKind::IsMaterializeForSet &&
+            baseAccessor->hasForcedStaticDispatch())
+          return;
+
         // FIXME: Egregious hack to set an 'override' attribute.
         if (!overridingAccessor->getAttrs().hasAttribute<OverrideAttr>()) {
           auto loc = overridingASD->getOverrideLoc();
@@ -8157,6 +8170,14 @@
     return;
   }
 
+  // If the nominal type has a generic signature that we didn't otherwise
+  // handle yet, use it directly.
+  if (auto genericSig = nominal->getGenericSignature()) {
+    auto genericEnv = genericSig->createGenericEnvironment();
+    ext->setGenericEnvironment(genericEnv);
+    return;
+  }
+
   assert(extendedType->is<NominalType>());
 }
 
diff --git a/lib/Sema/TypeCheckGeneric.cpp b/lib/Sema/TypeCheckGeneric.cpp
index 7aca106..4fb3087 100644
--- a/lib/Sema/TypeCheckGeneric.cpp
+++ b/lib/Sema/TypeCheckGeneric.cpp
@@ -457,7 +457,7 @@
   // Check the parameter patterns.
   for (auto params : func->getParameterLists()) {
     // Check the pattern.
-    if (tc.typeCheckParameterList(params, func, TypeResolutionOptions(),
+    if (tc.typeCheckParameterList(params, func, TR_AllowIUO,
                                   resolver))
       badType = true;
 
@@ -472,7 +472,7 @@
   if (auto fn = dyn_cast<FuncDecl>(func)) {
     if (!fn->getBodyResultTypeLoc().isNull()) {
       // Check the result type of the function.
-      TypeResolutionOptions options;
+      TypeResolutionOptions options = TR_AllowIUO;
       if (fn->hasDynamicSelf())
         options |= TR_DynamicSelfResult;
 
@@ -949,8 +949,12 @@
   // Check the indices.
   auto params = subscript->getIndices();
 
+  TypeResolutionOptions options;
+  options |= TR_SubscriptParameters;
+  options |= TR_AllowIUO;
+
   badType |= tc.typeCheckParameterList(params, subscript,
-                                       TR_SubscriptParameters,
+                                       options,
                                        resolver);
 
   // Infer requirements from the pattern.
diff --git a/lib/Sema/TypeCheckPattern.cpp b/lib/Sema/TypeCheckPattern.cpp
index debb18a..3a93cad 100644
--- a/lib/Sema/TypeCheckPattern.cpp
+++ b/lib/Sema/TypeCheckPattern.cpp
@@ -1321,8 +1321,9 @@
       }
       // Otherwise, if the type is an unbound generic of the context type, use
       // the context type to resolve the parameters.
-      else if (parentTy->is<UnboundGenericType>()) {
-        if (parentTy->getAnyNominal() == type->getAnyNominal()) {
+      else if (parentTy->hasUnboundGenericType()) {
+        if (parentTy->is<UnboundGenericType>() &&
+            parentTy->getAnyNominal() == type->getAnyNominal()) {
           enumTy = type;
         } else {
           diagnose(EEP->getLoc(), diag::ambiguous_enum_pattern_type,
diff --git a/lib/Sema/TypeCheckProtocol.cpp b/lib/Sema/TypeCheckProtocol.cpp
index 2395802..e86a809 100644
--- a/lib/Sema/TypeCheckProtocol.cpp
+++ b/lib/Sema/TypeCheckProtocol.cpp
@@ -2063,6 +2063,7 @@
     llvm::SmallVector<ConformanceChecker, 4> AllUsedCheckers;
     llvm::SmallVector<NormalProtocolConformance*, 4> AllConformances;
     llvm::SetVector<ValueDecl*> MissingWitnesses;
+    llvm::SmallPtrSet<ValueDecl *, 8> CoveredMembers;
 
     /// Check one conformance.
     ProtocolConformance * checkIndividualConformance(
@@ -2083,6 +2084,11 @@
       return llvm::makeArrayRef(UnsatisfiedReqs);
     }
 
+    /// Whether this member is "covered" by one of the conformances.
+    bool isCoveredMember(ValueDecl *member) const {
+      return CoveredMembers.count(member) > 0;
+    }
+
     /// Check all conformances and emit diagnosis globally.
     void checkAllConformances();
   };
@@ -2092,11 +2098,24 @@
     if (conformance->isInvalid()) return false;
     if (isa<TypeDecl>(req)) return false;
 
+    auto witness = conformance->hasWitness(req)
+      ? conformance->getWitness(req, nullptr).getDecl()
+      : nullptr;
+
     // An optional requirement might not have a witness...
-    if (!conformance->hasWitness(req) ||
-        !conformance->getWitness(req, nullptr).getDecl())
+    if (!witness)
       return req->getAttrs().hasAttribute<OptionalAttr>();
 
+    // If the witness lands within the declaration context of the conformance,
+    // record it as a "covered" member.
+    if (witness->getDeclContext() == conformance->getDeclContext())
+      CoveredMembers.insert(witness);
+
+    // The witness might come from a protocol or protocol extension.
+    if (witness->getDeclContext()
+          ->getAsProtocolOrProtocolExtensionContext())
+      return true;
+
     return false;
   }
 
@@ -5535,7 +5554,7 @@
           // If the requirement is optional, @nonobjc suppresses the
           // diagnostic.
           if (isOptional) {
-            TC.diagnose(witness, diag::optional_req_near_match_nonobjc, false)
+            TC.diagnose(witness, diag::req_near_match_nonobjc, false)
               .fixItInsert(witness->getAttributeInsertionLoc(false),
                            "@nonobjc ");
           }
@@ -6213,11 +6232,14 @@
   DeclName reqName = req->getFullName();
   DeclName witnessName = witness->getFullName();
 
-  // Apply the omit-needless-words heuristics to both names.
-  if (auto adjustedReqName = ::omitNeedlessWords(tc, req))
-    reqName = *adjustedReqName;
-  if (auto adjustedWitnessName = ::omitNeedlessWords(tc, witness))
-    witnessName = *adjustedWitnessName;
+  // For @objc protocols, apply the omit-needless-words heuristics to
+  // both names.
+  if (cast<ProtocolDecl>(req->getDeclContext())->isObjC()) {
+    if (auto adjustedReqName = ::omitNeedlessWords(tc, req))
+      reqName = *adjustedReqName;
+    if (auto adjustedWitnessName = ::omitNeedlessWords(tc, witness))
+      witnessName = *adjustedWitnessName;
+  }
 
   return scorePotentiallyMatchingNames(reqName, witnessName, isa<FuncDecl>(req),
                                        limit);
@@ -6317,19 +6339,40 @@
   return length;
 }
 
+/// Determine whether a particular declaration is generic.
+static bool isGeneric(ValueDecl *decl) {
+  if (auto func = dyn_cast<AbstractFunctionDecl>(decl))
+    return func->isGeneric();
+  if (auto subscript = dyn_cast<SubscriptDecl>(decl))
+    return subscript->isGeneric();
+  return false;
+}
+
 /// Determine whether we should warn about the given witness being a close
 /// match for the given optional requirement.
-static bool shouldWarnAboutPotentialWitness(ValueDecl *req,
-                                            ValueDecl *witness,
-                                            AccessLevel access,
-                                            unsigned score) {
+static bool shouldWarnAboutPotentialWitness(
+                                      MultiConformanceChecker &groupChecker,
+                                      ValueDecl *req,
+                                      ValueDecl *witness,
+                                      AccessLevel access,
+                                      unsigned score) {
+  // If the witness is covered, don't warn about it.
+  if (groupChecker.isCoveredMember(witness))
+    return false;
+
   // If the warning couldn't be suppressed, don't warn.
   if (!canSuppressPotentialWitnessWarningWithMovement(req, witness) &&
       !canSuppressPotentialWitnessWarningWithNonObjC(req, witness))
     return false;
 
-  // If the potential witness is already marked @nonobjc, don't warn.
-  if (witness->getAttrs().hasAttribute<NonObjCAttr>())
+  // If the potential witness for an @objc requirement is already
+  // marked @nonobjc, don't warn.
+  if (req->isObjC() && witness->getAttrs().hasAttribute<NonObjCAttr>())
+    return false;
+
+  // If the witness is generic and requirement is not, or vice-versa,
+  // don't warn.
+  if (isGeneric(req) != isGeneric(witness))
     return false;
 
   // Don't warn if the potential witness has been explicitly given less
@@ -6360,9 +6403,10 @@
   auto proto = cast<ProtocolDecl>(req->getDeclContext());
 
   // Primary warning.
-  tc.diagnose(witness, diag::optional_req_near_match,
+  tc.diagnose(witness, diag::req_near_match,
               witness->getDescriptiveKind(),
               witness->getFullName(),
+              req->getAttrs().hasAttribute<OptionalAttr>(),
               req->getFullName(),
               proto->getFullName());
 
@@ -6385,21 +6429,21 @@
   // If moving the declaration can help, suggest that.
   if (auto move
         = canSuppressPotentialWitnessWarningWithMovement(req, witness)) {
-    tc.diagnose(witness, diag::optional_req_near_match_move,
+    tc.diagnose(witness, diag::req_near_match_move,
                 witness->getFullName(), static_cast<unsigned>(*move));
   }
 
   // If adding 'private', 'fileprivate', or 'internal' can help, suggest that.
   if (access > AccessLevel::FilePrivate &&
       !witness->getAttrs().hasAttribute<AccessControlAttr>()) {
-    tc.diagnose(witness, diag::optional_req_near_match_access,
+    tc.diagnose(witness, diag::req_near_match_access,
                 witness->getFullName(), access)
       .fixItInsert(witness->getAttributeInsertionLoc(true), "private ");
   }
 
   // If adding @nonobjc can help, suggest that.
   if (canSuppressPotentialWitnessWarningWithNonObjC(req, witness)) {
-    tc.diagnose(witness, diag::optional_req_near_match_nonobjc, false)
+    tc.diagnose(witness, diag::req_near_match_nonobjc, false)
       .fixItInsert(witness->getAttributeInsertionLoc(false), "@nonobjc ");
   }
 
@@ -6439,7 +6483,8 @@
 
 /// Infer the attribute tostatic-initialize the Objective-C metadata for the
 /// given class, if needed.
-static void inferStaticInitializeObjCMetadata(ClassDecl *classDecl) {
+static void inferStaticInitializeObjCMetadata(TypeChecker &tc,
+                                              ClassDecl *classDecl) {
   // If we already have the attribute, there's nothing to do.
   if (classDecl->getAttrs().hasAttribute<StaticInitializeObjCMetadataAttr>())
     return;
@@ -6451,6 +6496,22 @@
     return;
   }
 
+  // If this class isn't always available on the deployment target, don't
+  // mark it as statically initialized.
+  // FIXME: This is a workaround. The proper solution is for IRGen to
+  // only statically initializae the Objective-C metadata when running on
+  // a new-enough OS.
+  if (auto sourceFile = classDecl->getParentSourceFile()) {
+    AvailabilityContext availableInfo = AvailabilityContext::alwaysAvailable();
+    for (Decl *enclosingDecl = classDecl; enclosingDecl;
+         enclosingDecl = enclosingDecl->getDeclContext()
+                           ->getInnermostDeclarationDeclContext()) {
+      if (!tc.isDeclAvailable(enclosingDecl, SourceLoc(), sourceFile,
+                              availableInfo))
+        return;
+    }
+  }
+
   // Infer @_staticInitializeObjCMetadata.
   ASTContext &ctx = classDecl->getASTContext();
   classDecl->getAttrs().add(
@@ -6568,7 +6629,7 @@
         }
 
         // Infer @_staticInitializeObjCMetadata if needed.
-        inferStaticInitializeObjCMetadata(classDecl);
+        inferStaticInitializeObjCMetadata(*this, classDecl);
       }
     }
 
@@ -6630,8 +6691,8 @@
 
         bool valueIsType = isa<TypeDecl>(value);
         for (auto requirement
-              : diag.Protocol->lookupDirect(value->getFullName(),
-                                            /*ignoreNewExtensions=*/true)) {
+                : diag.Protocol->lookupDirect(value->getFullName(),
+                                              /*ignoreNewExtensions=*/true)) {
           auto requirementIsType = isa<TypeDecl>(requirement);
           if (valueIsType != requirementIsType)
             continue;
@@ -6725,8 +6786,8 @@
             bestOptionalReqs.begin(),
             bestOptionalReqs.end(),
             [&](ValueDecl *req) {
-              return !shouldWarnAboutPotentialWitness(req, value, defaultAccess,
-                                                      bestScore);
+              return !shouldWarnAboutPotentialWitness(groupChecker, req, value,
+                                                      defaultAccess, bestScore);
             }),
           bestOptionalReqs.end());
       }
@@ -6747,7 +6808,7 @@
         assert(diagnosed && "Failed to find conformance to diagnose?");
         (void)diagnosed;
 
-        // Remove this optional requirement from the list. We don't want to
+        // Remove this requirement from the list. We don't want to
         // complain about it twice.
         unsatisfiedReqs.erase(std::find(unsatisfiedReqs.begin(),
                                         unsatisfiedReqs.end(),
diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp
index fd97d7c..72005aa 100644
--- a/lib/Sema/TypeCheckType.cpp
+++ b/lib/Sema/TypeCheckType.cpp
@@ -1180,6 +1180,63 @@
     return ErrorType::get(TC.Context);
   }
 
+  // Emit a warning about directly spelling
+  // ImplicitlyUnwrappedOptional rather than using a trailing '!'.
+  auto *IUODecl = TC.Context.getImplicitlyUnwrappedOptionalDecl();
+  if (currentDecl == IUODecl) {
+    if (options.contains(TR_AllowIUO)) {
+      if (isa<GenericIdentTypeRepr>(comp)) {
+        auto *genericTyR = cast<GenericIdentTypeRepr>(comp);
+        assert(genericTyR->getGenericArgs().size() == 1);
+        auto *genericArgTyR = genericTyR->getGenericArgs()[0];
+
+        Diagnostic diag = diag::implicitly_unwrapped_optional_spelling_deprecated_with_fixit;
+
+        // For Swift 5 and later, spelling the full name is an error.
+        if (TC.Context.isSwiftVersionAtLeast(5))
+          diag = diag::implicitly_unwrapped_optional_spelling_error_with_fixit;
+
+        TC.diagnose(comp->getStartLoc(), diag)
+          .fixItRemoveChars(
+              genericTyR->getStartLoc(),
+              genericTyR->getAngleBrackets().Start.getAdvancedLoc(1))
+          .fixItInsertAfter(genericArgTyR->getEndLoc(), "!")
+          .fixItRemoveChars(
+              genericTyR->getAngleBrackets().End,
+              genericTyR->getAngleBrackets().End.getAdvancedLoc(1));
+      } else {
+        Diagnostic diag = diag::implicitly_unwrapped_optional_spelling_deprecated;
+
+        // For Swift 5 and later, spelling the full name is an error.
+        if (TC.Context.isSwiftVersionAtLeast(5))
+          diag = diag::implicitly_unwrapped_optional_spelling_error;
+
+        TC.diagnose(comp->getStartLoc(), diag);
+      }
+    } else if (TC.Context.isSwiftVersionAtLeast(5)) {
+      if (isa<GenericIdentTypeRepr>(comp)) {
+        auto *genericTyR = cast<GenericIdentTypeRepr>(comp);
+        assert(genericTyR->getGenericArgs().size() == 1);
+        auto *genericArgTyR = genericTyR->getGenericArgs()[0];
+
+        TC.diagnose(comp->getStartLoc(), diag::iuo_in_illegal_position)
+          .fixItRemoveChars(
+              genericTyR->getStartLoc(),
+              genericTyR->getAngleBrackets().Start.getAdvancedLoc(1))
+          .fixItInsertAfter(genericArgTyR->getEndLoc(), "?")
+          .fixItRemoveChars(
+              genericTyR->getAngleBrackets().End,
+              genericTyR->getAngleBrackets().End.getAdvancedLoc(1));
+      } else {
+        TC.diagnose(comp->getStartLoc(), diag::iuo_in_illegal_position);
+      }
+    } else {
+      // Pre-Swift-5 warning for spelling ImplicitlyUnwrappedOptional
+      // in places we shouldn't even allow it.
+      TC.diagnose(comp->getStartLoc(), diag::implicitly_unwrapped_optional_spelling_deprecated);
+    }
+  }
+
   // If we found nothing, complain and give ourselves a chance to recover.
   if (current.isNull()) {
     // If we're not allowed to complain or we couldn't fix the
@@ -1582,8 +1639,12 @@
     Context.Stats->getFrontendCounters().NumTypesValidated++;
 
   if (Loc.getType().isNull()) {
-    // Raise error if we parse an IUO type in an illegal position.
-    checkForIllegalIUOs(*this, Loc.getTypeRepr(), options);
+    // Swift version < 5? Use the old "illegal IUO" check for
+    // backwards compatibiliy.
+    if (!Context.isSwiftVersionAtLeast(5)) {
+      // Raise error if we parse an IUO type in an illegal position.
+      checkForIllegalIUOs(*this, Loc.getTypeRepr(), options);
+    }
 
     auto type = resolveType(Loc.getTypeRepr(), DC, options, resolver,
                             unsatisfiedDependency);
@@ -2716,6 +2777,14 @@
   auto elementOptions = withoutContext(options, true);
   elementOptions |= TR_ImmediateOptionalTypeArgument;
 
+  // Swift version >= 5? Use the newer check for IUOs appearing in
+  // illegal positions.
+  if (TC.Context.isSwiftVersionAtLeast(5) &&
+      !elementOptions.contains(TR_AllowIUO)) {
+    TC.diagnose(repr->getStartLoc(), diag::iuo_in_illegal_position)
+      .fixItReplace(repr->getExclamationLoc(), "?");
+  }
+
   // The T in T! is a generic type argument and therefore always an AST type.
   // FIXME: diagnose non-materializability of element type!
   Type baseTy = resolveType(repr->getBase(), elementOptions);
diff --git a/lib/Sema/TypeChecker.h b/lib/Sema/TypeChecker.h
index ba2e86b..7942dc3 100644
--- a/lib/Sema/TypeChecker.h
+++ b/lib/Sema/TypeChecker.h
@@ -536,6 +536,9 @@
 
   /// Whether we are checking the parameter list of a subscript.
   TR_SubscriptParameters = 0x2000000,
+
+  /// Is it okay to resolve an IUO sigil ("!") here?
+  TR_AllowIUO = 0x4000000,
 };
 
 /// Option set describing how type resolution should work.
diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp
index 77750af..e40ef87 100644
--- a/lib/Serialization/Deserialization.cpp
+++ b/lib/Serialization/Deserialization.cpp
@@ -760,6 +760,10 @@
       break;
   }
 
+  // Don't create empty generic parameter lists.
+  if (params.empty())
+    return nullptr;
+
   auto paramList = GenericParamList::create(getContext(), SourceLoc(),
                                             params, SourceLoc(), { },
                                             SourceLoc());
diff --git a/lib/Serialization/SerializeSIL.cpp b/lib/Serialization/SerializeSIL.cpp
index 384f779..237f38f 100644
--- a/lib/Serialization/SerializeSIL.cpp
+++ b/lib/Serialization/SerializeSIL.cpp
@@ -2297,7 +2297,8 @@
 
   // Write out fragile WitnessTables.
   for (const SILWitnessTable &wt : SILMod->getWitnessTables()) {
-    if (wt.getConformance()->getDeclContext()->isChildContextOf(assocDC))
+    if ((ShouldSerializeAll || wt.isSerialized()) &&
+        wt.getConformance()->getDeclContext()->isChildContextOf(assocDC))
       writeSILWitnessTable(wt);
   }
 
diff --git a/lib/Syntax/SyntaxKind.cpp.gyb b/lib/Syntax/SyntaxKind.cpp.gyb
index 0af2116..17d52c0 100644
--- a/lib/Syntax/SyntaxKind.cpp.gyb
+++ b/lib/Syntax/SyntaxKind.cpp.gyb
@@ -51,5 +51,36 @@
   }
 }
 
+bool isDeclKind(SyntaxKind Kind) {
+  return Kind >= SyntaxKind::First_Decl && Kind <= SyntaxKind::Last_Decl;
+}
+
+bool isTypeKind(SyntaxKind Kind) {
+  return Kind >= SyntaxKind::First_Type && Kind <= SyntaxKind::Last_Type;
+}
+
+bool isStmtKind(SyntaxKind Kind) {
+  return Kind >= SyntaxKind::First_Stmt && Kind <= SyntaxKind::Last_Stmt;
+}
+
+bool isExprKind(SyntaxKind Kind) {
+  return Kind >= SyntaxKind::First_Expr && Kind <= SyntaxKind::Last_Expr;
+}
+
+bool isPatternKind(SyntaxKind Kind) {
+  return Kind >= SyntaxKind::First_Pattern &&
+         Kind <= SyntaxKind::Last_Pattern;
+}
+
+bool isTokenKind(SyntaxKind Kind) {
+  return Kind == SyntaxKind::Token;
+}
+
+bool isUnknownKind(SyntaxKind Kind) {
+  return Kind == SyntaxKind::Unknown ||
+         Kind == SyntaxKind::UnknownDecl ||
+         Kind == SyntaxKind::UnknownExpr ||
+         Kind == SyntaxKind::UnknownStmt;
+}
 } // end namespace syntax
 } // end namespace swift
diff --git a/lib/TBDGen/TBDGen.cpp b/lib/TBDGen/TBDGen.cpp
index 1089960..46f8bbc 100644
--- a/lib/TBDGen/TBDGen.cpp
+++ b/lib/TBDGen/TBDGen.cpp
@@ -109,7 +109,7 @@
     // sometimes witness thunks need to be manually made public.
 
     auto conformanceIsFixed = SILWitnessTable::conformanceIsSerialized(
-        normalConformance, SwiftModule->getResilienceStrategy());
+        normalConformance);
     auto addSymbolIfNecessary = [&](ValueDecl *valueReq,
                                     SILLinkage witnessLinkage) {
       if (conformanceIsFixed &&
diff --git a/stdlib/public/SwiftShims/RefCount.h b/stdlib/public/SwiftShims/RefCount.h
index 75d3bc5..211de02 100644
--- a/stdlib/public/SwiftShims/RefCount.h
+++ b/stdlib/public/SwiftShims/RefCount.h
@@ -736,7 +736,7 @@
 #if __POINTER_WIDTH__ == 32
   // FIXME: hack - something somewhere is assuming a 3-word header on 32-bit
   // See also other fixmes marked "small header for 32-bit"
-  uintptr_t unused SWIFT_ATTRIBUTE_UNAVAILABLE;
+  uintptr_t : 32;
 #endif
 
   // Out-of-line slow paths.
@@ -772,11 +772,7 @@
   
   // Refcount of a new object is 1.
   constexpr RefCounts(Initialized_t)
-    : refCounts(RefCountBits(0, 1))
-#if __POINTER_WIDTH__ == 32 && !__has_attribute(unavailable)
-      , unused(0)
-#endif
-  { }
+    : refCounts(RefCountBits(0, 1)) {}
 
   void init() {
     refCounts.store(RefCountBits(0, 1), std::memory_order_relaxed);
diff --git a/stdlib/public/SwiftShims/Visibility.h b/stdlib/public/SwiftShims/Visibility.h
index 1d36a44..ee99c63 100644
--- a/stdlib/public/SwiftShims/Visibility.h
+++ b/stdlib/public/SwiftShims/Visibility.h
@@ -91,9 +91,9 @@
 # define SWIFT_EXPORT_ATTRIBUTE __attribute__((__visibility__("default")))
 #endif
 
-#else
+#else  // FIXME: this #else should be some sort of #elif Windows
 # if defined(__CYGWIN__)
-#  define SWIFT_RUNTIME_EXPORT
+#  define SWIFT_EXPORT_ATTRIBUTE
 # else
 #  if defined(swiftCore_EXPORTS)
 #   define SWIFT_EXPORT_ATTRIBUTE __declspec(dllexport)
@@ -116,4 +116,5 @@
 /// resilience we may be able to make this hidden.
 #define SWIFT_RUNTIME_STDLIB_INTERFACE SWIFT_RUNTIME_EXPORT
 
+// SWIFT_STDLIB_SHIMS_VISIBILITY_H
 #endif
diff --git a/stdlib/public/core/RangeReplaceableCollection.swift.gyb b/stdlib/public/core/RangeReplaceableCollection.swift.gyb
index eda9d20..fd539dd 100644
--- a/stdlib/public/core/RangeReplaceableCollection.swift.gyb
+++ b/stdlib/public/core/RangeReplaceableCollection.swift.gyb
@@ -354,6 +354,9 @@
   mutating func removeAll(keepingCapacity keepCapacity: Bool /*= false*/)
 
   // FIXME(ABI): Associated type inference requires this.
+  subscript(bounds: Index) -> Element { get }
+
+  // FIXME(ABI): Associated type inference requires this.
   subscript(bounds: Range<Index>) -> SubSequence { get }
 }
 
diff --git a/stdlib/public/core/Shims.swift b/stdlib/public/core/Shims.swift
index 4596d47..3b453a1 100644
--- a/stdlib/public/core/Shims.swift
+++ b/stdlib/public/core/Shims.swift
@@ -29,6 +29,7 @@
 /// A dummy value to be used as the target for `mutationsPtr` in fast
 /// enumeration implementations.
 @_versioned // FIXME(sil-serialize-all)
+@_fixed_layout
 internal var _fastEnumerationStorageMutationsTarget: CUnsignedLong = 0
 
 /// A dummy pointer to be used as `mutationsPtr` in fast enumeration
@@ -36,6 +37,8 @@
 @_inlineable // FIXME(sil-serialize-all)
 public // SPI(Foundation)
 var _fastEnumerationStorageMutationsPtr: UnsafeMutablePointer<CUnsignedLong> {
+  // Note that either _fastEnumerationStorageMutationsPtr should be
+  // @_fixed_layout, or this function should not be @_inlineable.
   return UnsafeMutablePointer(
       Builtin.addressof(&_fastEnumerationStorageMutationsTarget))
 }
diff --git a/stdlib/public/core/StringSwitch.swift b/stdlib/public/core/StringSwitch.swift
index b1e90c8..d35b107 100644
--- a/stdlib/public/core/StringSwitch.swift
+++ b/stdlib/public/core/StringSwitch.swift
@@ -32,6 +32,7 @@
   return -1
 }
 
+@_fixed_layout // needs known size for static allocation
 public // used by COMPILER_INTRINSIC
 struct _OpaqueStringSwitchCache {
   var a: Builtin.Word
diff --git a/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb b/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb
index 74f658c..50f7456 100644
--- a/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb
+++ b/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb
@@ -467,7 +467,7 @@
       _debugPrecondition(bounds.upperBound <= endIndex)
       _debugPrecondition(bounds.count == newValue.count)
 
-      if newValue.count > 0 {
+      if !newValue.isEmpty {
         (baseAddress! + bounds.lowerBound).copyBytes(
           from: newValue.base.baseAddress! + newValue.startIndex,
           count: newValue.count)
diff --git a/stdlib/public/runtime/ErrorObject.h b/stdlib/public/runtime/ErrorObject.h
index 74c4774..f023a5e 100644
--- a/stdlib/public/runtime/ErrorObject.h
+++ b/stdlib/public/runtime/ErrorObject.h
@@ -208,6 +208,8 @@
 void swift_errorInMain(SwiftError *object);
 SWIFT_RUNTIME_EXPORT
 void swift_willThrow(SwiftError *object);
+
+SWIFT_CC(swift)
 SWIFT_RUNTIME_EXPORT LLVM_ATTRIBUTE_NORETURN
 void swift_unexpectedError(SwiftError *object);
 
diff --git a/stdlib/public/runtime/ImageInspectionELF.cpp b/stdlib/public/runtime/ImageInspectionELF.cpp
index 7d89704..2fd9bef 100644
--- a/stdlib/public/runtime/ImageInspectionELF.cpp
+++ b/stdlib/public/runtime/ImageInspectionELF.cpp
@@ -27,7 +27,7 @@
 #include <link.h>
 #include <string.h>
 
-#if defined(__ANDROID__)
+#if defined(__ANDROID__) || defined(__FreeBSD__)
 #include "llvm/ADT/StringRef.h"
 #endif
 
@@ -72,9 +72,14 @@
   SectionInfo sectionInfo = { 0, nullptr };
   void *handle = dlopen(imageName, RTLD_LAZY | RTLD_NOLOAD);
   if (!handle) {
-#ifdef __ANDROID__
+#if defined(__ANDROID__) || defined(__FreeBSD__)
+#if defined(__ANDROID__)
+    const char *systemPath = "/system/lib";
+#elif defined(__FreeBSD__)
+    const char *systemPath = "/libexec";
+#endif
     llvm::StringRef imagePath = llvm::StringRef(imageName);
-    if (imagePath.startswith("/system/lib") ||
+    if (imagePath.startswith(systemPath) ||
         (imageName && !imagePath.endswith(".so"))) {
       return sectionInfo;
     }
diff --git a/test/Constraints/generic_overload.swift b/test/Constraints/generic_overload.swift
index c300c62..12451b3 100644
--- a/test/Constraints/generic_overload.swift
+++ b/test/Constraints/generic_overload.swift
@@ -1,7 +1,7 @@
 // RUN: %target-typecheck-verify-swift
 
-protocol P1 { associatedtype Assoc } // expected-note{{declared here}}
-protocol P2 : P1 { associatedtype Assoc } // expected-warning{{redeclaration of associated type}}
+protocol P1 { associatedtype Assoc }
+protocol P2 : P1 { associatedtype Assoc }
 protocol P3 { }
 
 struct X1 : P1 { typealias Assoc = X3 }
diff --git a/test/Constraints/patterns.swift b/test/Constraints/patterns.swift
index f024d23..b56e228 100644
--- a/test/Constraints/patterns.swift
+++ b/test/Constraints/patterns.swift
@@ -336,3 +336,19 @@
     break;
   }
 }
+
+
+// SR-6100
+struct One<Two> {
+    public enum E: Error {
+        // if you remove associated value, everything works
+        case SomeError(String)
+    }
+}
+
+func testOne() {
+  do {
+  } catch let error { // expected-warning{{'catch' block is unreachable because no errors are thrown in 'do' block}}
+    if case One.E.SomeError = error {} // expected-error{{generic enum type 'One.E' is ambiguous without explicit generic parameters when matching value of type 'Error'}}
+  }
+}
diff --git a/test/Driver/opt-record.swift b/test/Driver/opt-record.swift
new file mode 100644
index 0000000..823f519
--- /dev/null
+++ b/test/Driver/opt-record.swift
@@ -0,0 +1,43 @@
+// RUN: %empty-directory(%t)
+// RUN: %target-swiftc_driver -O -wmo -save-optimization-record %s -module-name optrecordmod -o %t/opt-record 2>&1 | %FileCheck -allow-empty %s
+// RUN: %FileCheck -check-prefix=YAML %s < %t/optrecordmod.opt.yaml
+// RUN: %target-swiftc_driver -O -wmo -save-optimization-record-path %t/specified.opt.yaml %s -module-name optrecordmod -o %t/opt-record 2>&1 | %FileCheck -allow-empty %s
+// RUN: %FileCheck -check-prefix=YAML %s < %t/specified.opt.yaml
+
+// CHECK-NOT: remark
+
+var a: Int = 1
+
+func foo() {
+  a = 2
+}
+
+public func bar() {
+  // YAML:      --- !Passed
+  // YAML-NEXT: Pass:            sil-inliner
+  // YAML-NEXT: Name:            Inlined
+  // YAML-NEXT: DebugLoc:
+  // YAML-NEXT:   File:            {{.*}}opt-record.swift
+  // YAML-NEXT:   Line:            42
+  // YAML-NEXT:   Column:          3
+  // YAML-NEXT: Function:        _T012optrecordmod3baryyF
+  // YAML-NEXT: Args:
+  // YAML-NEXT:   - Callee:          _T012optrecordmod3fooyyF
+  // YAML-NEXT:     DebugLoc:
+  // YAML-NEXT:       File:            {{.*}}opt-record.swift
+  // YAML-NEXT:       Line:            11
+  // YAML-NEXT:       Column:          6
+  // YAML-NEXT:   - String:          ' inlined into '
+  // YAML-NEXT:   - Caller:          _T012optrecordmod3baryyF
+  // YAML-NEXT:     DebugLoc:
+  // YAML-NEXT:       File:            {{.*}}opt-record.swift
+  // YAML-NEXT:       Line:            15
+  // YAML-NEXT:       Column:          13
+  // YAML-NEXT:   - String:          ' (cost = '
+  // YAML-NEXT:   - Cost:            '{{.*}}'
+  // YAML-NEXT:   - String:          ', benefit = '
+  // YAML-NEXT:   - Benefit:         '{{.*}}'
+  // YAML-NEXT:   - String:          ')'
+  // YAML-NEXT: ...
+  foo()
+}
diff --git a/test/Frontend/sil-merge-partial-modules.swift b/test/Frontend/sil-merge-partial-modules.swift
index 630ae29..2fb01dc 100644
--- a/test/Frontend/sil-merge-partial-modules.swift
+++ b/test/Frontend/sil-merge-partial-modules.swift
@@ -72,6 +72,6 @@
 
 // NEGATIVE-NOT: sil {{.*}}internalFunction
 
-// NEGATIVE: sil_witness_table {{.*}}Circle: Shape
+// NEGATIVE-NOT: sil_witness_table {{.*}}Circle: Shape
 
 // NEGATIVE-NOT: sil_vtable
diff --git a/test/Generics/associated_type_where_clause.swift b/test/Generics/associated_type_where_clause.swift
index 5c936e1..a342e62 100644
--- a/test/Generics/associated_type_where_clause.swift
+++ b/test/Generics/associated_type_where_clause.swift
@@ -138,16 +138,16 @@
 
 // Lookup of same-named associated types aren't ambiguous in this context.
 protocol P1 {
-  associatedtype A // expected-note 2{{declared here}}
+  associatedtype A
 }
 
 protocol P2: P1 {
-  associatedtype A // expected-warning{{redeclaration of associated type}}
+  associatedtype A
   associatedtype B where A == B
 }
 
 protocol P3: P1 {
-  associatedtype A // expected-warning{{redeclaration of associated type}}
+  associatedtype A
 }
 
 protocol P4 {
diff --git a/test/Generics/canonicalization.swift b/test/Generics/canonicalization.swift
index 8f262ed..256ea96 100644
--- a/test/Generics/canonicalization.swift
+++ b/test/Generics/canonicalization.swift
@@ -4,11 +4,11 @@
 protocol P0 { }
 
 protocol P {
-  associatedtype A // expected-note{{declared here}}
+  associatedtype A
 }
 
 protocol Q : P {
-  associatedtype A // expected-warning{{redeclaration of associated type 'A' from protocol 'P' is better expressed as a 'where' clause on the protocol}}
+  associatedtype A
 }
 
 func f<T>(t: T) where T : P, T : Q, T.A : P0 { } // expected-note{{'f(t:)' previously declared here}}
diff --git a/test/Generics/protocol_requirement_signatures.swift b/test/Generics/protocol_requirement_signatures.swift
index 676b1bf..8b65d7a 100644
--- a/test/Generics/protocol_requirement_signatures.swift
+++ b/test/Generics/protocol_requirement_signatures.swift
@@ -22,7 +22,7 @@
 // CHECK-NEXT: Requirement signature: <Self where Self.X : P1>
 // CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.X : P1>
 protocol Q1 {
-    associatedtype X: P1 // expected-note 2{{declared here}}
+    associatedtype X: P1 // expected-note {{declared here}}
 }
 
 // inheritance
@@ -36,7 +36,7 @@
 // CHECK-NEXT: Requirement signature: <Self where Self : Q1>
 // CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0 : Q1>
 protocol Q3: Q1 {
-    associatedtype X // expected-warning{{redeclaration of associated type 'X'}}
+    associatedtype X
 }
 
 // inheritance adding a new conformance
diff --git a/test/Generics/requirement_inference.swift b/test/Generics/requirement_inference.swift
index b86e80f..bf6bfa2 100644
--- a/test/Generics/requirement_inference.swift
+++ b/test/Generics/requirement_inference.swift
@@ -139,13 +139,13 @@
 }
 
 protocol P8 {
-  associatedtype A // expected-note{{'A' declared here}}
-  associatedtype B // expected-note{{'B' declared here}}
+  associatedtype A
+  associatedtype B
 }
 
 protocol P9 : P8 {
-  associatedtype A // expected-warning{{redeclaration of associated type 'A' from protocol 'P8' is better expressed as a 'where' clause on the protocol}}
-  associatedtype B // expected-warning{{redeclaration of associated type 'B' from protocol 'P8' is better expressed as a 'where' clause on the protocol}}
+  associatedtype A
+  associatedtype B
 }
 
 protocol P10 {
@@ -295,8 +295,8 @@
 // CHECK: Canonical generic signature: <τ_0_0 where τ_0_0 : P22>
 // CHECK: Protocol requirement signature:
 // CHECK: .P22@
-// CHECK-NEXT: Requirement signature: <Self where Self.B : P20, Self.A == X20<Self.B>>
-// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.B : P20, τ_0_0.A == X20<τ_0_0.B>>
+// CHECK-NEXT: Requirement signature: <Self where Self.A == X20<Self.B>, Self.B : P20>
+// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.A == X20<τ_0_0.B>, τ_0_0.B : P20>
 protocol P22 {
   associatedtype A
   associatedtype B where A == X20<B>
@@ -306,8 +306,8 @@
 // CHECK: Canonical generic signature: <τ_0_0 where τ_0_0 : P23>
 // CHECK: Protocol requirement signature:
 // CHECK: .P23@
-// CHECK-NEXT: Requirement signature: <Self where Self.B : P20, Self.A == X20<Self.B>>
-// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.B : P20, τ_0_0.A == X20<τ_0_0.B>>
+// CHECK-NEXT: Requirement signature: <Self where Self.A == X20<Self.B>, Self.B : P20>
+// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.A == X20<τ_0_0.B>, τ_0_0.B : P20>
 protocol P23 {
   associatedtype A
   associatedtype B: P20
@@ -323,16 +323,16 @@
 }
 
 // CHECK-LABEL: .P25a@
-// CHECK-NEXT: Requirement signature: <Self where Self.B : P20, Self.A == X24<Self.B>>
-// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.B : P20, τ_0_0.A == X24<τ_0_0.B>>
+// CHECK-NEXT: Requirement signature: <Self where Self.A == X24<Self.B>, Self.B : P20>
+// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.A == X24<τ_0_0.B>, τ_0_0.B : P20>
 protocol P25a {
   associatedtype A: P24 // expected-warning{{redundant conformance constraint 'Self.A': 'P24'}}
   associatedtype B where A == X24<B> // expected-note{{conformance constraint 'Self.A': 'P24' implied here}}
 }
 
 // CHECK-LABEL: .P25b@
-// CHECK-NEXT: Requirement signature: <Self where Self.B : P20, Self.A == X24<Self.B>>
-// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.B : P20, τ_0_0.A == X24<τ_0_0.B>>
+// CHECK-NEXT: Requirement signature: <Self where Self.A == X24<Self.B>, Self.B : P20>
+// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.A == X24<τ_0_0.B>, τ_0_0.B : P20>
 protocol P25b {
   associatedtype A
   associatedtype B where A == X24<B>
@@ -353,16 +353,16 @@
 }
 
 // CHECK-LABEL: .P27a@
-// CHECK-NEXT: Requirement signature: <Self where Self.B : X3, Self.A == X26<Self.B>>
-// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.B : X3, τ_0_0.A == X26<τ_0_0.B>>
+// CHECK-NEXT: Requirement signature: <Self where Self.A == X26<Self.B>, Self.B : X3>
+// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.A == X26<τ_0_0.B>, τ_0_0.B : X3>
 protocol P27a {
   associatedtype A: P26 // expected-warning{{redundant conformance constraint 'Self.A': 'P26'}}
   associatedtype B where A == X26<B> // expected-note{{conformance constraint 'Self.A': 'P26' implied here}}
 }
 
 // CHECK-LABEL: .P27b@
-// CHECK-NEXT: Requirement signature: <Self where Self.B : X3, Self.A == X26<Self.B>>
-// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.B : X3, τ_0_0.A == X26<τ_0_0.B>>
+// CHECK-NEXT: Requirement signature: <Self where Self.A == X26<Self.B>, Self.B : X3>
+// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.A == X26<τ_0_0.B>, τ_0_0.B : X3>
 protocol P27b {
   associatedtype A
   associatedtype B where A == X26<B>
diff --git a/test/IDE/complete_associated_types.swift b/test/IDE/complete_associated_types.swift
index 79a6af9..fad21e7 100644
--- a/test/IDE/complete_associated_types.swift
+++ b/test/IDE/complete_associated_types.swift
@@ -32,8 +32,8 @@
   associatedtype FooBaseDefaultedTypeB = Int
   associatedtype FooBaseDefaultedTypeC = Int
 
-  associatedtype DeducedTypeCommonA // expected-note{{declared here}}
-  associatedtype DeducedTypeCommonB // expected-note{{declared here}}
+  associatedtype DeducedTypeCommonA
+  associatedtype DeducedTypeCommonB
   associatedtype DeducedTypeCommonC
   associatedtype DeducedTypeCommonD
   func deduceCommonA() -> DeducedTypeCommonA
@@ -57,8 +57,8 @@
 
   associatedtype FooBaseDefaultedTypeB = Double
 
-  associatedtype DeducedTypeCommonA // expected-warning{{redeclaration of associated type}}
-  associatedtype DeducedTypeCommonB // expected-warning{{redeclaration of associated type}}
+  associatedtype DeducedTypeCommonA
+  associatedtype DeducedTypeCommonB
   func deduceCommonA() -> DeducedTypeCommonA
   func deduceCommonB() -> DeducedTypeCommonB
 
@@ -79,7 +79,7 @@
   associatedtype DefaultedTypeCommonA = Int
   associatedtype DefaultedTypeCommonC = Int
 
-  associatedtype DeducedTypeCommonA // expected-note{{'DeducedTypeCommonA' declared here}}
+  associatedtype DeducedTypeCommonA
   associatedtype DeducedTypeCommonC
   func deduceCommonA() -> DeducedTypeCommonA
   func deduceCommonC() -> DeducedTypeCommonC
@@ -102,7 +102,7 @@
   associatedtype DefaultedTypeCommonA = Int
   associatedtype DefaultedTypeCommonD = Int
 
-  associatedtype DeducedTypeCommonA // expected-warning{{redeclaration of associated type}}
+  associatedtype DeducedTypeCommonA
   associatedtype DeducedTypeCommonD
   func deduceCommonA() -> DeducedTypeCommonA
   func deduceCommonD() -> DeducedTypeCommonD
diff --git a/test/IRGen/Inputs/usr/include/SRoA.h b/test/IRGen/Inputs/usr/include/SRoA.h
new file mode 100644
index 0000000..e838c0f
--- /dev/null
+++ b/test/IRGen/Inputs/usr/include/SRoA.h
@@ -0,0 +1,8 @@
+
+typedef struct S {
+  float f;
+  float g;
+} S;
+
+void f(S);
+
diff --git a/test/IRGen/Inputs/usr/include/module.map b/test/IRGen/Inputs/usr/include/module.map
index befdc45..44fdc95 100644
--- a/test/IRGen/Inputs/usr/include/module.map
+++ b/test/IRGen/Inputs/usr/include/module.map
@@ -1,4 +1,11 @@
-module gizmo { header "Gizmo.h" }
+
+module gizmo {
+  header "Gizmo.h"
+}
+
+module SRoA {
+  header "SRoA.h"
+}
 
 module ObjectiveC {
   header "BridgeTestObjectiveC.h"
diff --git a/test/IRGen/builtins.swift b/test/IRGen/builtins.swift
index 6e02601..bca276d 100644
--- a/test/IRGen/builtins.swift
+++ b/test/IRGen/builtins.swift
@@ -11,6 +11,8 @@
 typealias Int = Builtin.Int32
 typealias Bool = Builtin.Int1
 
+// CHECK: call swiftcc void @swift_errorInMain(
+
 infix operator * {
   associativity left
   precedence 200
@@ -838,5 +840,22 @@
   Builtin.atomicstore_seqcst_volatile_FPIEEE32(p, d)
 }
 
+func createInt(_ fn: () -> ()) throws {}
+// CHECK-LABEL: define {{.*}}testForceTry
+// CHECK: call swiftcc void @swift_unexpectedError(%swift.error*
+func testForceTry(_ fn: () -> ()) {
+  try! createInt(fn)
+}
+
+// CHECK-LABEL: declare swiftcc void @swift_unexpectedError(%swift.error*
+
+enum MyError : Error {
+  case A, B
+}
+
+throw MyError.A
+
+
+
 // CHECK: ![[R]] = !{i64 0, i64 9223372036854775807}
 
diff --git a/test/IRGen/c_layout.sil b/test/IRGen/c_layout.sil
index 250e18f..0455530 100644
--- a/test/IRGen/c_layout.sil
+++ b/test/IRGen/c_layout.sil
@@ -126,11 +126,11 @@
 }
 
 // CHECK-x86_64-LABEL: define{{( protected)?}} swiftcc void @testIntegerExtension
-// CHECK-x86_64:         call signext i8 @chareth(i8 signext %0)
-// CHECK-x86_64:         call signext i8 @signedChareth(i8 signext %1)
-// CHECK-x86_64:         call zeroext i8 @unsignedChareth(i8 zeroext %2)
-// CHECK-x86_64:         call signext i16 @eatMyShorts(i16 signext %3)
-// CHECK-x86_64:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext %4)
+// CHECK-x86_64:         call signext i8 @chareth(i8 signext
+// CHECK-x86_64:         call signext i8 @signedChareth(i8 signext
+// CHECK-x86_64:         call zeroext i8 @unsignedChareth(i8 zeroext
+// CHECK-x86_64:         call signext i16 @eatMyShorts(i16 signext
+// CHECK-x86_64:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext
 // CHECK-x86_64:         call i32 @ints(i32 %5)
 // CHECK-x86_64:         call i32 @unsigneds(i32 %6)
 // CHECK-x86_64-LABEL: declare signext i8 @chareth(i8 signext)
@@ -142,11 +142,11 @@
 // CHECK-x86_64-LABEL: declare i32 @unsigneds(i32)
 
 // CHECK-i386-LABEL: define{{( protected)?}} swiftcc void @testIntegerExtension
-// CHECK-i386:         call signext i8 @chareth(i8 signext %0)
-// CHECK-i386:         call signext i8 @signedChareth(i8 signext %1)
-// CHECK-i386:         call zeroext i8 @unsignedChareth(i8 zeroext %2)
-// CHECK-i386:         call signext i16 @eatMyShorts(i16 signext %3)
-// CHECK-i386:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext %4)
+// CHECK-i386:         call signext i8 @chareth(i8 signext
+// CHECK-i386:         call signext i8 @signedChareth(i8 signext
+// CHECK-i386:         call zeroext i8 @unsignedChareth(i8 zeroext
+// CHECK-i386:         call signext i16 @eatMyShorts(i16 signext
+// CHECK-i386:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext
 // CHECK-i386:         call i32 @ints(i32 %5)
 // CHECK-i386:         call i32 @unsigneds(i32 %6)
 // CHECK-i386-LABEL: declare signext i8 @chareth(i8 signext)
@@ -158,11 +158,11 @@
 // CHECK-i386-LABEL: declare i32 @unsigneds(i32)
 
 // CHECK-armv7-LABEL: define{{( protected)?}} swiftcc void @testIntegerExtension
-// CHECK-armv7:         call signext i8 @chareth(i8 signext %0)
-// CHECK-armv7:         call signext i8 @signedChareth(i8 signext %1)
-// CHECK-armv7:         call zeroext i8 @unsignedChareth(i8 zeroext %2)
-// CHECK-armv7:         call signext i16 @eatMyShorts(i16 signext %3)
-// CHECK-armv7:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext %4)
+// CHECK-armv7:         call signext i8 @chareth(i8 signext
+// CHECK-armv7:         call signext i8 @signedChareth(i8 signext
+// CHECK-armv7:         call zeroext i8 @unsignedChareth(i8 zeroext
+// CHECK-armv7:         call signext i16 @eatMyShorts(i16 signext
+// CHECK-armv7:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext
 // CHECK-armv7:         call i32 @ints(i32 %5)
 // CHECK-armv7:         call i32 @unsigneds(i32 %6)
 // CHECK-armv7-LABEL: declare signext i8 @chareth(i8 signext)
@@ -174,11 +174,11 @@
 // CHECK-armv7-LABEL: declare i32 @unsigneds(i32)
 
 // CHECK-armv7s-LABEL: define{{( protected)?}} swiftcc void @testIntegerExtension
-// CHECK-armv7s:         call signext i8 @chareth(i8 signext %0)
-// CHECK-armv7s:         call signext i8 @signedChareth(i8 signext %1)
-// CHECK-armv7s:         call zeroext i8 @unsignedChareth(i8 zeroext %2)
-// CHECK-armv7s:         call signext i16 @eatMyShorts(i16 signext %3)
-// CHECK-armv7s:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext %4)
+// CHECK-armv7s:         call signext i8 @chareth(i8 signext
+// CHECK-armv7s:         call signext i8 @signedChareth(i8 signext
+// CHECK-armv7s:         call zeroext i8 @unsignedChareth(i8 zeroext
+// CHECK-armv7s:         call signext i16 @eatMyShorts(i16 signext
+// CHECK-armv7s:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext
 // CHECK-armv7s:         call i32 @ints(i32 %5)
 // CHECK-armv7s:         call i32 @unsigneds(i32 %6)
 // CHECK-armv7s-LABEL: declare signext i8 @chareth(i8 signext)
@@ -190,11 +190,11 @@
 // CHECK-armv7s-LABEL: declare i32 @unsigneds(i32)
 
 // CHECK-armv7k-LABEL: define{{( protected)?}} swiftcc void @testIntegerExtension
-// CHECK-armv7k:         call signext i8 @chareth(i8 signext %0)
-// CHECK-armv7k:         call signext i8 @signedChareth(i8 signext %1)
-// CHECK-armv7k:         call zeroext i8 @unsignedChareth(i8 zeroext %2)
-// CHECK-armv7k:         call signext i16 @eatMyShorts(i16 signext %3)
-// CHECK-armv7k:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext %4)
+// CHECK-armv7k:         call signext i8 @chareth(i8 signext
+// CHECK-armv7k:         call signext i8 @signedChareth(i8 signext
+// CHECK-armv7k:         call zeroext i8 @unsignedChareth(i8 zeroext
+// CHECK-armv7k:         call signext i16 @eatMyShorts(i16 signext
+// CHECK-armv7k:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext
 // CHECK-armv7k:         call i32 @ints(i32 %5)
 // CHECK-armv7k:         call i32 @unsigneds(i32 %6)
 // CHECK-armv7k-LABEL: declare signext i8 @chareth(i8 signext)
@@ -206,11 +206,11 @@
 // CHECK-armv7k-LABEL: declare i32 @unsigneds(i32)
 
 // CHECK-arm64-LABEL: define{{( protected)?}} swiftcc void @testIntegerExtension
-// CHECK-arm64:         call signext i8 @chareth(i8 signext %0)
-// CHECK-arm64:         call signext i8 @signedChareth(i8 signext %1)
-// CHECK-arm64:         call zeroext i8 @unsignedChareth(i8 zeroext %2)
-// CHECK-arm64:         call signext i16 @eatMyShorts(i16 signext %3)
-// CHECK-arm64:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext %4)
+// CHECK-arm64:         call signext i8 @chareth(i8 signext
+// CHECK-arm64:         call signext i8 @signedChareth(i8 signext
+// CHECK-arm64:         call zeroext i8 @unsignedChareth(i8 zeroext
+// CHECK-arm64:         call signext i16 @eatMyShorts(i16 signext
+// CHECK-arm64:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext
 // CHECK-arm64:         call i32 @ints(i32 %5)
 // CHECK-arm64:         call i32 @unsigneds(i32 %6)
 // CHECK-arm64-LABEL: declare signext i8 @chareth(i8 signext)
@@ -238,11 +238,11 @@
 // CHECK-aarch64-LABEL: declare i32 @unsigneds(i32)
 
 // CHECK-powerpc64-LABEL: define{{( protected)?}} swiftcc void @testIntegerExtension
-// CHECK-powerpc64:         call zeroext i8 @chareth(i8 zeroext %0)
-// CHECK-powerpc64:         call zeroext i8 @signedChareth(i8 zeroext %1)
-// CHECK-powerpc64:         call zeroext i8 @unsignedChareth(i8 zeroext %2)
-// CHECK-powerpc64:         call signext i16 @eatMyShorts(i16 signext %3)
-// CHECK-powerpc64:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext %4)
+// CHECK-powerpc64:         call zeroext i8 @chareth(i8 zeroext
+// CHECK-powerpc64:         call zeroext i8 @signedChareth(i8 zeroext
+// CHECK-powerpc64:         call zeroext i8 @unsignedChareth(i8 zeroext
+// CHECK-powerpc64:         call signext i16 @eatMyShorts(i16 signext
+// CHECK-powerpc64:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext
 // CHECK-powerpc64:         call signext i32 @ints(i32 signext %5)
 // CHECK-powerpc64:         call zeroext i32 @unsigneds(i32 zeroext %6)
 // CHECK-powerpc64-LABEL: declare zeroext i8 @chareth(i8 zeroext)
@@ -254,11 +254,11 @@
 // CHECK-powerpc64-LABEL: declare zeroext i32 @unsigneds(i32 zeroext)
 
 // CHECK-powerpc64le-LABEL: define{{( protected)?}} swiftcc void @testIntegerExtension
-// CHECK-powerpc64le:         call zeroext i8 @chareth(i8 zeroext %0)
-// CHECK-powerpc64le:         call zeroext i8 @signedChareth(i8 zeroext %1)
-// CHECK-powerpc64le:         call zeroext i8 @unsignedChareth(i8 zeroext %2)
-// CHECK-powerpc64le:         call signext i16 @eatMyShorts(i16 signext %3)
-// CHECK-powerpc64le:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext %4)
+// CHECK-powerpc64le:         call zeroext i8 @chareth(i8 zeroext
+// CHECK-powerpc64le:         call zeroext i8 @signedChareth(i8 zeroext
+// CHECK-powerpc64le:         call zeroext i8 @unsignedChareth(i8 zeroext
+// CHECK-powerpc64le:         call signext i16 @eatMyShorts(i16 signext
+// CHECK-powerpc64le:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext
 // CHECK-powerpc64le:         call signext i32 @ints(i32 signext %5)
 // CHECK-powerpc64le:         call zeroext i32 @unsigneds(i32 zeroext %6)
 // CHECK-powerpc64le-LABEL: declare zeroext i8 @chareth(i8 zeroext)
@@ -270,11 +270,11 @@
 // CHECK-powerpc64le-LABEL: declare zeroext i32 @unsigneds(i32 zeroext)
 
 // CHECK-s390x-LABEL: define{{( protected)?}} swiftcc void @testIntegerExtension
-// CHECK-s390x:         call zeroext i8 @chareth(i8 zeroext %0)
-// CHECK-s390x:         call zeroext i8 @signedChareth(i8 zeroext %1)
-// CHECK-s390x:         call zeroext i8 @unsignedChareth(i8 zeroext %2)
-// CHECK-s390x:         call signext i16 @eatMyShorts(i16 signext %3)
-// CHECK-s390x:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext %4)
+// CHECK-s390x:         call zeroext i8 @chareth(i8 zeroext
+// CHECK-s390x:         call zeroext i8 @signedChareth(i8 zeroext
+// CHECK-s390x:         call zeroext i8 @unsignedChareth(i8 zeroext
+// CHECK-s390x:         call signext i16 @eatMyShorts(i16 signext
+// CHECK-s390x:         call zeroext i16 @eatMyUnsignedShorts(i16 zeroext
 // CHECK-s390x:         call signext i32 @ints(i32 signext %5)
 // CHECK-s390x:         call zeroext i32 @unsigneds(i32 zeroext %6)
 // CHECK-s390x-LABEL: declare zeroext i8 @chareth(i8 zeroext)
diff --git a/test/IRGen/optimize_for_size.sil b/test/IRGen/optimize_for_size.sil
index c116b44..32cfa3f 100644
--- a/test/IRGen/optimize_for_size.sil
+++ b/test/IRGen/optimize_for_size.sil
@@ -13,4 +13,4 @@
 }
 
 // O-NOT: attributes #0 = {{{.*}}optsize
-// CHECK: attributes #0 = {{{.*}}optsize
+// CHECK: attributes #0 = {{{.*}}minsize
diff --git a/test/IRGen/unexploded-calls.swift b/test/IRGen/unexploded-calls.swift
new file mode 100644
index 0000000..e9046f4
--- /dev/null
+++ b/test/IRGen/unexploded-calls.swift
@@ -0,0 +1,34 @@
+// RUN: %swift -target thumbv7-unknown-windows-msvc -parse-stdlib -parse-as-library -I %S/Inputs/usr/include -module-name Swift -S -emit-ir -o - %s | %FileCheck %s
+// RUN: %swift -target thumbv7-unknown-linux-gnueabihf -parse-stdlib -parse-as-library -I %S/Inputs/usr/include -module-name Swift -S -emit-ir -o - %s | %FileCheck %s
+// RUN: %swift -target thumbv7-unknown-linux-gnueabi -Xcc -mfloat-abi=hard -parse-stdlib -parse-as-library -I %S/Inputs/usr/include -module-name Swift -S -emit-ir -o - %s | %FileCheck %s
+
+// REQUIRES: CODEGENERATOR=ARM
+
+struct Float {
+  let _value: Builtin.FPIEEE32
+}
+
+typealias CFloat = Float
+typealias Void = ()
+
+import SRoA
+
+public func g(_ s : S) {
+  return f(s)
+}
+
+// CHECK: define {{.*}}swiftcc void @_T0s1gySC1SVF(float, float) {{.*}}{
+// CHECK: entry:
+// CHECK:   [[ALLOCA:%[-._0-9a-zA-Z]+]] = alloca %TSC1SV, align 4
+// CHECK:   %2 = bitcast %TSC1SV* [[ALLOCA]] to i8*
+// CHECK:   [[ALLOCA]].f = getelementptr inbounds %TSC1SV, %TSC1SV* [[ALLOCA]], i32 0, i32 0
+// CHECK:   [[ALLOCA]].f._value = getelementptr inbounds %TSf, %TSf* [[ALLOCA]].f, i32 0, i32 0
+// CHECK:   store float %0, float* [[ALLOCA]].f._value, align 4
+// CHECK:   [[ALLOCA]].g = getelementptr inbounds %TSC1SV, %TSC1SV* [[ALLOCA]], i32 0, i32 1
+// CHECK:   [[ALLOCA]].g._value = getelementptr inbounds %TSf, %TSf* [[ALLOCA]].g, i32 0, i32 0
+// CHECK:   store float %1, float* [[ALLOCA]].g._value, align 4
+// CHECK:   %3 = bitcast %TSC1SV* [[ALLOCA]] to %struct.S*
+// CHECK:   %4 = load %struct.S, %struct.S* %3, align 4
+// CHECK:   call void @f(%struct.S %4)
+// CHECK: }
+
diff --git a/test/Index/roles.swift b/test/Index/roles.swift
index 76fe95a..8c8acaf 100644
--- a/test/Index/roles.swift
+++ b/test/Index/roles.swift
@@ -313,6 +313,12 @@
   func foo() -> Int { return 1 }
 }
 
+protocol ExtendMe {}
+protocol Whatever {}
+// CHECK: [[@LINE-1]]:10 | protocol/Swift | Whatever | [[Whatever_USR:.*]] | Def | rel: 0
+extension ExtendMe where Self: Whatever {}
+// CHECK: [[@LINE-1]]:32 | protocol/Swift | Whatever | [[Whatever_USR]] | Ref | rel: 0
+
 var anInstance = AClass(x: 1)
 // CHECK: [[@LINE-1]]:18 | class/Swift | AClass | s:14swift_ide_test6AClassC | Ref | rel: 0
 // CHECK: [[@LINE-2]]:18 | constructor/Swift | init(x:) | s:14swift_ide_test6AClassCACSi1x_tcfc | Ref,Call | rel: 0
diff --git a/test/Parse/errors.swift b/test/Parse/errors.swift
index 8fb0ecf..628ae9d 100644
--- a/test/Parse/errors.swift
+++ b/test/Parse/errors.swift
@@ -4,8 +4,8 @@
   case Foo, Bar, Baz
   case CarriesInt(Int)
 
-  var domain: String { return "" }
-  var code: Int { return 0 }
+  var _domain: String { return "" }
+  var _code: Int { return 0 }
 }
 
 func opaque_error() -> Error { return MSV.Foo }
diff --git a/test/SIL/Serialization/witness_tables.sil b/test/SIL/Serialization/witness_tables.sil
index bedac29..d8e8e61 100644
--- a/test/SIL/Serialization/witness_tables.sil
+++ b/test/SIL/Serialization/witness_tables.sil
@@ -73,14 +73,6 @@
   associated_type_protocol (AssocWithReqt: AssocReqt): ConformingAssoc: AssocReqt module witness_tables
 }
 
-// CHECK-LABEL: sil_witness_table InheritedConformance2: InheritedProtocol1 module witness_tables
-// CHECK-NOT: }
-sil_witness_table InheritedConformance2: InheritedProtocol1 module witness_tables
-// CHECK-LABEL: sil_witness_table InheritedConformance2: AnyProtocol module witness_tables
-// CHECK-NOT: }
-sil_witness_table InheritedConformance2: AnyProtocol module witness_tables
-
-
 protocol Proto {
 	func abc()
 }
diff --git a/test/SIL/ownership-verifier/objc_use_verifier.sil b/test/SIL/ownership-verifier/objc_use_verifier.sil
index 01d725b..c6621af 100644
--- a/test/SIL/ownership-verifier/objc_use_verifier.sil
+++ b/test/SIL/ownership-verifier/objc_use_verifier.sil
@@ -13,3 +13,19 @@
   return %1 : $Protocol
 }
 
+
+@objc class Gizmo {
+  init()
+  static func runce()
+}
+class Hoozit : Gizmo {
+  override init()
+}
+
+sil hidden @test_objc_super_method : $@convention(method) (@thick Hoozit.Type) -> () {
+bb0(%0 : @trivial $@thick Hoozit.Type):
+  %2 = upcast %0 : $@thick Hoozit.Type to $@thick Gizmo.Type
+  %3 = objc_super_method %0 : $@thick Hoozit.Type, #Gizmo.runce!1.foreign : (Gizmo.Type) -> () -> (), $@convention(objc_method) (@objc_metatype Gizmo.Type) -> ()
+  %4 = tuple()
+  return %4 : $()
+}
diff --git a/test/SILGen/Inputs/usr/include/BridgeTestFoundation.h b/test/SILGen/Inputs/usr/include/BridgeTestFoundation.h
index c09b5da..fc360c6 100644
--- a/test/SILGen/Inputs/usr/include/BridgeTestFoundation.h
+++ b/test/SILGen/Inputs/usr/include/BridgeTestFoundation.h
@@ -89,3 +89,7 @@
 void noescapeBlockAlias(__attribute__((noescape)) dispatch_block_t block);
 void noescapeNonnullBlockAlias(__attribute__((noescape)) _Nonnull dispatch_block_t block);
 void escapeBlockAlias(dispatch_block_t block);
+
+@interface ObjectWithSplitProperty : NSObject
+@property (nonatomic, setter=private_setFlagForSomething:) BOOL flagForSomething;
+@end
diff --git a/test/SILGen/closures.swift b/test/SILGen/closures.swift
index 62071c6..3ed9217 100644
--- a/test/SILGen/closures.swift
+++ b/test/SILGen/closures.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -parse-stdlib -parse-as-library -emit-silgen %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -parse-stdlib -parse-as-library -emit-silgen %s | %FileCheck %s
 
 import Swift
 
@@ -27,7 +27,7 @@
 // CHECK-LABEL: sil hidden @_T08closures17read_only_captureS2iF : $@convention(thin) (Int) -> Int {
 func read_only_capture(_ x: Int) -> Int {
   var x = x
-  // CHECK: bb0([[X:%[0-9]+]] : $Int):
+  // CHECK: bb0([[X:%[0-9]+]] : @trivial $Int):
   // CHECK:   [[XBOX:%[0-9]+]] = alloc_box ${ var Int }
   // SEMANTIC ARC TODO: This is incorrect. We need to do the project_box on the copy.
   // CHECK:   [[PROJECT:%.*]] = project_box [[XBOX]]
@@ -49,7 +49,7 @@
 // CHECK:   } // end sil function '_T08closures17read_only_captureS2iF'
 
 // CHECK: sil private @[[CAP_NAME]]
-// CHECK: bb0([[XBOX:%[0-9]+]] : ${ var Int }):
+// CHECK: bb0([[XBOX:%[0-9]+]] : @owned ${ var Int }):
 // CHECK: [[XADDR:%[0-9]+]] = project_box [[XBOX]]
 // CHECK: [[ACCESS:%.*]] = begin_access [read] [unknown] [[XADDR]] : $*Int
 // CHECK: [[X:%[0-9]+]] = load [trivial] [[ACCESS]]
@@ -61,7 +61,7 @@
 // CHECK-LABEL: sil hidden @_T08closures16write_to_captureS2iF : $@convention(thin) (Int) -> Int {
 func write_to_capture(_ x: Int) -> Int {
   var x = x
-  // CHECK: bb0([[X:%[0-9]+]] : $Int):
+  // CHECK: bb0([[X:%[0-9]+]] : @trivial $Int):
   // CHECK:   [[XBOX:%[0-9]+]] = alloc_box ${ var Int }
   // CHECK:   [[XBOX_PB:%.*]] = project_box [[XBOX]]
   // CHECK:   store [[X]] to [trivial] [[XBOX_PB]]
@@ -94,7 +94,7 @@
 // CHECK:  } // end sil function '_T08closures16write_to_captureS2iF'
 
 // CHECK: sil private @[[SCRIB_NAME]]
-// CHECK: bb0([[XBOX:%[0-9]+]] : ${ var Int }):
+// CHECK: bb0([[XBOX:%[0-9]+]] : @owned ${ var Int }):
 // CHECK:   [[XADDR:%[0-9]+]] = project_box [[XBOX]]
 // CHECK:   [[ACCESS:%.*]] = begin_access [modify] [unknown] [[XADDR]] : $*Int
 // CHECK:   assign {{%[0-9]+}} to [[ACCESS]]
@@ -120,7 +120,7 @@
 
 // CHECK-LABEL: sil hidden @_T08closures18capture_local_funcSiycycSiF : $@convention(thin) (Int) -> @owned @callee_owned () -> @owned @callee_owned () -> Int {
 func capture_local_func(_ x: Int) -> () -> () -> Int {
-  // CHECK: bb0([[ARG:%.*]] : $Int):
+  // CHECK: bb0([[ARG:%.*]] : @trivial $Int):
   var x = x
   // CHECK:   [[XBOX:%[0-9]+]] = alloc_box ${ var Int }
   // CHECK:   [[XBOX_PB:%.*]] = project_box [[XBOX]]
@@ -142,10 +142,10 @@
 // CHECK: } // end sil function '_T08closures18capture_local_funcSiycycSiF'
 
 // CHECK: sil private @[[ALEPH_NAME:_T08closures18capture_local_funcSiycycSiF5alephL_SiyF]] : $@convention(thin) (@owned { var Int }) -> Int {
-// CHECK: bb0([[XBOX:%[0-9]+]] : ${ var Int }):
+// CHECK: bb0([[XBOX:%[0-9]+]] : @owned ${ var Int }):
 
 // CHECK: sil private @[[BETH_NAME]] : $@convention(thin) (@owned { var Int }) -> @owned @callee_owned () -> Int {
-// CHECK: bb0([[XBOX:%[0-9]+]] : ${ var Int }):
+// CHECK: bb0([[XBOX:%[0-9]+]] : @owned ${ var Int }):
 // CHECK:   [[XBOX_PB:%.*]] = project_box [[XBOX]]
 // CHECK:   [[ALEPH_REF:%[0-9]+]] = function_ref @[[ALEPH_NAME]] : $@convention(thin) (@owned { var Int }) -> Int
 // CHECK:   [[XBOX_COPY:%.*]] = copy_value [[XBOX]]
@@ -159,7 +159,7 @@
 // CHECK-LABEL: sil hidden @_T08closures22anon_read_only_capture{{[_0-9a-zA-Z]*}}F
 func anon_read_only_capture(_ x: Int) -> Int {
   var x = x
-  // CHECK: bb0([[X:%[0-9]+]] : $Int):
+  // CHECK: bb0([[X:%[0-9]+]] : @trivial $Int):
   // CHECK: [[XBOX:%[0-9]+]] = alloc_box ${ var Int }
   // CHECK: [[PB:%.*]] = project_box [[XBOX]]
 
@@ -173,7 +173,7 @@
   // CHECK: return [[RET]]
 }
 // CHECK: sil private @[[CLOSURE_NAME]]
-// CHECK: bb0([[XADDR:%[0-9]+]] : $*Int):
+// CHECK: bb0([[XADDR:%[0-9]+]] : @trivial $*Int):
 // CHECK: [[ACCESS:%.*]] = begin_access [read] [unknown] [[XADDR]] : $*Int
 // CHECK: [[X:%[0-9]+]] = load [trivial] [[ACCESS]]
 // CHECK: return [[X]]
@@ -181,7 +181,7 @@
 // CHECK-LABEL: sil hidden @_T08closures21small_closure_capture{{[_0-9a-zA-Z]*}}F
 func small_closure_capture(_ x: Int) -> Int {
   var x = x
-  // CHECK: bb0([[X:%[0-9]+]] : $Int):
+  // CHECK: bb0([[X:%[0-9]+]] : @trivial $Int):
   // CHECK: [[XBOX:%[0-9]+]] = alloc_box ${ var Int }
   // CHECK: [[PB:%.*]] = project_box [[XBOX]]
 
@@ -195,7 +195,7 @@
   // CHECK: return [[RET]]
 }
 // CHECK: sil private @[[CLOSURE_NAME]]
-// CHECK: bb0([[XADDR:%[0-9]+]] : $*Int):
+// CHECK: bb0([[XADDR:%[0-9]+]] : @trivial $*Int):
 // CHECK: [[ACCESS:%.*]] = begin_access [read] [unknown] [[XADDR]] : $*Int
 // CHECK: [[X:%[0-9]+]] = load [trivial] [[ACCESS]]
 // CHECK: return [[X]]
@@ -234,13 +234,13 @@
   return { $0 }
 }
 // CHECK: sil private @[[CLOSURE_NAME]] : $@convention(thin) (Int) -> Int
-// CHECK: bb0([[YARG:%[0-9]+]] : $Int):
+// CHECK: bb0([[YARG:%[0-9]+]] : @trivial $Int):
 
 // CHECK-LABEL: sil hidden @_T08closures17uncaptured_locals{{[_0-9a-zA-Z]*}}F :
 func uncaptured_locals(_ x: Int) -> (Int, Int) {
   var x = x
   // -- locals without captures are stack-allocated
-  // CHECK: bb0([[XARG:%[0-9]+]] : $Int):
+  // CHECK: bb0([[XARG:%[0-9]+]] : @trivial $Int):
   // CHECK:   [[XADDR:%[0-9]+]] = alloc_box ${ var Int }
   // CHECK:   [[PB:%.*]] = project_box [[XADDR]]
   // CHECK:   store [[XARG]] to [trivial] [[PB]]
@@ -293,7 +293,7 @@
 }
 
 // CHECK-LABEL: sil private @_T08closures20generateWithConstantyAA17SomeSpecificClassCFAA0eG0CycfU_ : $@convention(thin) (@owned SomeSpecificClass) -> @owned SomeClass {
-// CHECK: bb0([[T0:%.*]] : $SomeSpecificClass):
+// CHECK: bb0([[T0:%.*]] : @owned $SomeSpecificClass):
 // CHECK:   debug_value [[T0]] : $SomeSpecificClass, let, name "x", argno 1
 // CHECK:   [[BORROWED_T0:%.*]] = begin_borrow [[T0]]
 // CHECK:   [[T0_COPY:%.*]] = copy_value [[BORROWED_T0]]
@@ -314,7 +314,7 @@
   var foo : () -> SelfCapturedInInit
 
   // CHECK-LABEL: sil hidden @_T08closures18SelfCapturedInInitC{{[_0-9a-zA-Z]*}}fc : $@convention(method) (@owned SelfCapturedInInit) -> @owned SelfCapturedInInit {
-  // CHECK: bb0([[SELF:%.*]] : $SelfCapturedInInit):
+  // CHECK: bb0([[SELF:%.*]] : @owned $SelfCapturedInInit):
   //
   // First create our initial value for self.
   // CHECK:   [[SELF_BOX:%.*]] = alloc_box ${ var SelfCapturedInInit }, let, name "self"
@@ -379,7 +379,7 @@
 // The let property needs to be captured into a temporary stack slot so that it
 // is loadable even though we capture the value.
 // CHECK-LABEL: sil private @_T08closures18closeOverLetLValueyyFSiycfU_ : $@convention(thin) (@owned ClassWithIntProperty) -> Int {
-// CHECK: bb0([[ARG:%.*]] : $ClassWithIntProperty):
+// CHECK: bb0([[ARG:%.*]] : @owned $ClassWithIntProperty):
 // CHECK:   [[TMP_CLASS_ADDR:%.*]] = alloc_stack $ClassWithIntProperty, let, name "a", argno 1
 // CHECK:   store [[ARG]] to [init] [[TMP_CLASS_ADDR]] : $*ClassWithIntProperty
 // CHECK:   [[LOADED_CLASS:%.*]] = load [copy] [[TMP_CLASS_ADDR]] : $*ClassWithIntProperty
@@ -412,13 +412,13 @@
 // Check that the address of self is passed in, but not the refcount pointer.
 
 // CHECK-LABEL: sil hidden @_T08closures24StructWithMutatingMethodV08mutatingE0{{[_0-9a-zA-Z]*}}F
-// CHECK: bb0(%0 : $*StructWithMutatingMethod):
+// CHECK: bb0(%0 : @trivial $*StructWithMutatingMethod):
 // CHECK: [[CLOSURE:%[0-9]+]] = function_ref @_T08closures24StructWithMutatingMethodV08mutatingE0{{.*}} : $@convention(thin) (@inout_aliasable StructWithMutatingMethod) -> Int
 // CHECK: partial_apply [[CLOSURE]](%0) : $@convention(thin) (@inout_aliasable StructWithMutatingMethod) -> Int
 
 // Check that the closure body only takes the pointer.
 // CHECK-LABEL: sil private @_T08closures24StructWithMutatingMethodV08mutatingE0{{.*}} : $@convention(thin) (@inout_aliasable StructWithMutatingMethod) -> Int {
-// CHECK:       bb0(%0 : $*StructWithMutatingMethod):
+// CHECK:       bb0(%0 : @trivial $*StructWithMutatingMethod):
 
 class SuperBase {
   func boom() {}
@@ -427,14 +427,14 @@
   override func boom() {}
 
   // CHECK-LABEL: sil hidden @_T08closures8SuperSubC1ayyF : $@convention(method) (@guaranteed SuperSub) -> () {
-  // CHECK: bb0([[SELF:%.*]] : $SuperSub):
+  // CHECK: bb0([[SELF:%.*]] : @guaranteed $SuperSub):
   // CHECK:   [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK:   [[INNER:%.*]] = function_ref @[[INNER_FUNC_1:_T08closures8SuperSubC1a[_0-9a-zA-Z]*]] : $@convention(thin) (@owned SuperSub) -> ()
   // CHECK:   apply [[INNER]]([[SELF_COPY]])
   // CHECK: } // end sil function '_T08closures8SuperSubC1ayyF'
   func a() {
     // CHECK: sil private @[[INNER_FUNC_1]] : $@convention(thin) (@owned SuperSub) -> () {
-    // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+    // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
     // CHECK:   [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
     // CHECK:   [[CLASS_METHOD:%.*]] = class_method [[BORROWED_ARG]] : $SuperSub, #SuperSub.boom!1
     // CHECK:   = apply [[CLASS_METHOD]]([[BORROWED_ARG]])
@@ -443,7 +443,8 @@
     // CHECK:   [[ARG_COPY:%.*]] = copy_value [[BORROWED_ARG]]
     // CHECK:   [[ARG_COPY_SUPER:%.*]] = upcast [[ARG_COPY]] : $SuperSub to $SuperBase
     // CHECK:   [[SUPER_METHOD:%[0-9]+]] = function_ref @_T08closures9SuperBaseC4boomyyF : $@convention(method) (@guaranteed SuperBase) -> ()
-    // CHECK:   = apply [[SUPER_METHOD]]([[ARG_COPY_SUPER]])
+    // CHECK:   [[BORROWED_ARG_COPY_SUPER:%.*]] = begin_borrow [[ARG_COPY_SUPER]]
+    // CHECK:   = apply [[SUPER_METHOD]]([[BORROWED_ARG_COPY_SUPER]])
     // CHECK:   destroy_value [[ARG_COPY_SUPER]]
     // CHECK:   end_borrow [[BORROWED_ARG]] from [[ARG]]
     // CHECK:   destroy_value [[ARG]]
@@ -456,14 +457,14 @@
   }
 
   // CHECK-LABEL: sil hidden @_T08closures8SuperSubC1byyF : $@convention(method) (@guaranteed SuperSub) -> () {
-  // CHECK: bb0([[SELF:%.*]] : $SuperSub):
+  // CHECK: bb0([[SELF:%.*]] : @guaranteed $SuperSub):
   // CHECK:   [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK:   [[INNER:%.*]] = function_ref @[[INNER_FUNC_1:_T08closures8SuperSubC1b[_0-9a-zA-Z]*]] : $@convention(thin) (@owned SuperSub) -> ()
   // CHECK:   = apply [[INNER]]([[SELF_COPY]])
   // CHECK: } // end sil function '_T08closures8SuperSubC1byyF'
   func b() {
     // CHECK: sil private @[[INNER_FUNC_1]] : $@convention(thin) (@owned SuperSub) -> () {
-    // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+    // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
     // CHECK:   [[ARG_COPY:%.*]] = copy_value [[ARG]]
     // CHECK:   [[INNER:%.*]] = function_ref @[[INNER_FUNC_2:_T08closures8SuperSubC1b.*]] : $@convention(thin) (@owned SuperSub) -> ()
     // CHECK:   = apply [[INNER]]([[ARG_COPY]])
@@ -471,7 +472,7 @@
     // CHECK: } // end sil function '[[INNER_FUNC_1]]'
     func b1() {
       // CHECK: sil private @[[INNER_FUNC_2]] : $@convention(thin) (@owned SuperSub) -> () {
-      // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+      // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
       // CHECK:   [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
       // CHECK:   [[CLASS_METHOD:%.*]] = class_method [[BORROWED_ARG]] : $SuperSub, #SuperSub.boom!1
       // CHECK:   = apply [[CLASS_METHOD]]([[BORROWED_ARG]]) : $@convention(method) (@guaranteed SuperSub) -> ()
@@ -480,7 +481,8 @@
       // CHECK:   [[ARG_COPY:%.*]] = copy_value [[BORROWED_ARG]]
       // CHECK:   [[ARG_COPY_SUPER:%.*]] = upcast [[ARG_COPY]] : $SuperSub to $SuperBase
       // CHECK:   [[SUPER_METHOD:%.*]] = function_ref @_T08closures9SuperBaseC4boomyyF : $@convention(method) (@guaranteed SuperBase) -> ()
-      // CHECK:   = apply [[SUPER_METHOD]]([[ARG_COPY_SUPER]]) : $@convention(method) (@guaranteed SuperBase)
+      // CHECK:   [[BORROWED_ARG_COPY_SUPER:%.*]] = begin_borrow [[ARG_COPY_SUPER]]
+      // CHECK:   = apply [[SUPER_METHOD]]([[BORROWED_ARG_COPY_SUPER]]) : $@convention(method) (@guaranteed SuperBase)
       // CHECK:   destroy_value [[ARG_COPY_SUPER]]
       // CHECK:   end_borrow [[BORROWED_ARG]] from [[ARG]]
       // CHECK:   destroy_value [[ARG]]
@@ -495,7 +497,7 @@
   }
 
   // CHECK-LABEL: sil hidden @_T08closures8SuperSubC1cyyF : $@convention(method) (@guaranteed SuperSub) -> () {
-  // CHECK: bb0([[SELF:%.*]] : $SuperSub):
+  // CHECK: bb0([[SELF:%.*]] : @guaranteed $SuperSub):
   // CHECK:   [[INNER:%.*]] = function_ref @[[INNER_FUNC_1:_T08closures8SuperSubC1c[_0-9a-zA-Z]*]] : $@convention(thin) (@owned SuperSub) -> ()
   // CHECK:   [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK:   [[PA:%.*]] = partial_apply [[INNER]]([[SELF_COPY]])
@@ -507,7 +509,7 @@
   // CHECK: } // end sil function '_T08closures8SuperSubC1cyyF'
   func c() {
     // CHECK: sil private @[[INNER_FUNC_1]] : $@convention(thin) (@owned SuperSub) -> ()
-    // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+    // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
     // CHECK:   [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
     // CHECK:   [[CLASS_METHOD:%.*]] = class_method [[BORROWED_ARG]] : $SuperSub, #SuperSub.boom!1
     // CHECK:   = apply [[CLASS_METHOD]]([[BORROWED_ARG]]) : $@convention(method) (@guaranteed SuperSub) -> ()
@@ -516,7 +518,8 @@
     // CHECK:   [[ARG_COPY:%.*]] = copy_value [[BORROWED_ARG]]
     // CHECK:   [[ARG_COPY_SUPER:%.*]] = upcast [[ARG_COPY]] : $SuperSub to $SuperBase
     // CHECK:   [[SUPER_METHOD:%[0-9]+]] = function_ref @_T08closures9SuperBaseC4boomyyF : $@convention(method) (@guaranteed SuperBase) -> ()
-    // CHECK:   = apply [[SUPER_METHOD]]([[ARG_COPY_SUPER]])
+    // CHECK:   [[BORROWED_ARG_COPY_SUPER:%.*]] = begin_borrow [[ARG_COPY_SUPER]]
+    // CHECK:   = apply [[SUPER_METHOD]]([[BORROWED_ARG_COPY_SUPER]])
     // CHECK:   destroy_value [[ARG_COPY_SUPER]]
     // CHECK:   end_borrow [[BORROWED_ARG]] from [[ARG]]
     // CHECK:   destroy_value [[ARG]]
@@ -529,7 +532,7 @@
   }
 
   // CHECK-LABEL: sil hidden @_T08closures8SuperSubC1dyyF : $@convention(method) (@guaranteed SuperSub) -> () {
-  // CHECK: bb0([[SELF:%.*]] : $SuperSub):
+  // CHECK: bb0([[SELF:%.*]] : @guaranteed $SuperSub):
   // CHECK:   [[INNER:%.*]] = function_ref @[[INNER_FUNC_1:_T08closures8SuperSubC1d[_0-9a-zA-Z]*]] : $@convention(thin) (@owned SuperSub) -> ()
   // CHECK:   [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK:   [[PA:%.*]] = partial_apply [[INNER]]([[SELF_COPY]])
@@ -541,7 +544,7 @@
   // CHECK: } // end sil function '_T08closures8SuperSubC1dyyF'
   func d() {
     // CHECK: sil private @[[INNER_FUNC_1]] : $@convention(thin) (@owned SuperSub) -> () {
-    // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+    // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
     // CHECK:   [[ARG_COPY:%.*]] = copy_value [[ARG]]
     // CHECK:   [[INNER:%.*]] = function_ref @[[INNER_FUNC_2:_T08closures8SuperSubC1d.*]] : $@convention(thin) (@owned SuperSub) -> ()
     // CHECK:   = apply [[INNER]]([[ARG_COPY]])
@@ -549,12 +552,13 @@
     // CHECK: } // end sil function '[[INNER_FUNC_1]]'
     let d1 = { () -> Void in
       // CHECK: sil private @[[INNER_FUNC_2]] : $@convention(thin) (@owned SuperSub) -> () {
-      // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+      // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
       // CHECK:   [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
       // CHECK:   [[ARG_COPY:%.*]] = copy_value [[BORROWED_ARG]]
       // CHECK:   [[ARG_COPY_SUPER:%.*]] = upcast [[ARG_COPY]] : $SuperSub to $SuperBase
       // CHECK:   [[SUPER_METHOD:%.*]] = function_ref @_T08closures9SuperBaseC4boomyyF : $@convention(method) (@guaranteed SuperBase) -> ()
-      // CHECK:   = apply [[SUPER_METHOD]]([[ARG_COPY_SUPER]])
+      // CHECK:   [[BORROWED_ARG_COPY_SUPER:%.*]] = begin_borrow [[ARG_COPY_SUPER]]
+      // CHECK:   = apply [[SUPER_METHOD]]([[BORROWED_ARG_COPY_SUPER]])
       // CHECK:   destroy_value [[ARG_COPY_SUPER]]
       // CHECK:   end_borrow [[BORROWED_ARG]] from [[ARG]]
       // CHECK:   destroy_value [[ARG]]
@@ -568,14 +572,14 @@
   }
 
   // CHECK-LABEL: sil hidden @_T08closures8SuperSubC1eyyF : $@convention(method) (@guaranteed SuperSub) -> () {
-  // CHECK: bb0([[SELF:%.*]] : $SuperSub):
+  // CHECK: bb0([[SELF:%.*]] : @guaranteed $SuperSub):
   // CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK: [[INNER:%.*]] = function_ref @[[INNER_FUNC_NAME1:_T08closures8SuperSubC1e[_0-9a-zA-Z]*]] : $@convention(thin)
   // CHECK: = apply [[INNER]]([[SELF_COPY]])
   // CHECK: } // end sil function '_T08closures8SuperSubC1eyyF'
   func e() {
     // CHECK: sil private @[[INNER_FUNC_NAME1]] : $@convention(thin)
-    // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+    // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
     // CHECK:   [[INNER:%.*]] = function_ref @[[INNER_FUNC_NAME2:_T08closures8SuperSubC1e.*]] : $@convention(thin)
     // CHECK:   [[ARG_COPY:%.*]] = copy_value [[ARG]]
     // CHECK:   [[PA:%.*]] = partial_apply [[INNER]]([[ARG_COPY]])
@@ -588,12 +592,13 @@
     // CHECK: } // end sil function '[[INNER_FUNC_NAME1]]'
     func e1() {
       // CHECK: sil private @[[INNER_FUNC_NAME2]] : $@convention(thin)
-      // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+      // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
       // CHECK:   [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
       // CHECK:   [[ARG_COPY:%.*]] = copy_value [[BORROWED_ARG]]
       // CHECK:   [[ARG_COPY_SUPERCAST:%.*]] = upcast [[ARG_COPY]] : $SuperSub to $SuperBase
       // CHECK:   [[SUPER_METHOD:%.*]] = function_ref @_T08closures9SuperBaseC4boomyyF : $@convention(method) (@guaranteed SuperBase) -> ()
-      // CHECK:   = apply [[SUPER_METHOD]]([[ARG_COPY_SUPERCAST]])
+      // CHECK:   [[BORROWED_ARG_COPY_SUPERCAST:%.*]] = begin_borrow [[ARG_COPY_SUPERCAST]]
+      // CHECK:   = apply [[SUPER_METHOD]]([[BORROWED_ARG_COPY_SUPERCAST]])
       // CHECK:   destroy_value [[ARG_COPY_SUPERCAST]]
       // CHECK:   end_borrow [[BORROWED_ARG]] from [[ARG]]
       // CHECK:   destroy_value [[ARG]]
@@ -608,7 +613,7 @@
   }
 
   // CHECK-LABEL: sil hidden @_T08closures8SuperSubC1fyyF : $@convention(method) (@guaranteed SuperSub) -> () {
-  // CHECK: bb0([[SELF:%.*]] : $SuperSub):
+  // CHECK: bb0([[SELF:%.*]] : @guaranteed $SuperSub):
   // CHECK:   [[INNER:%.*]] = function_ref @[[INNER_FUNC_1:_T08closures8SuperSubC1fyyFyycfU_]] : $@convention(thin) (@owned SuperSub) -> ()
   // CHECK:   [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK:   [[PA:%.*]] = partial_apply [[INNER]]([[SELF_COPY]])
@@ -616,7 +621,7 @@
   // CHECK: } // end sil function '_T08closures8SuperSubC1fyyF'
   func f() {
     // CHECK: sil private @[[INNER_FUNC_1]] : $@convention(thin) (@owned SuperSub) -> () {
-    // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+    // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
     // CHECK:   [[TRY_APPLY_AUTOCLOSURE:%.*]] = function_ref @_T0s2qqoixxSg_xyKXKtKlF : $@convention(thin) <τ_0_0> (@in Optional<τ_0_0>, @owned @noescape @callee_owned () -> (@out τ_0_0, @error Error)) -> (@out τ_0_0, @error Error)
     // CHECK:   [[INNER:%.*]] = function_ref @[[INNER_FUNC_2:_T08closures8SuperSubC1fyyFyycfU_yyKXKfu_]] : $@convention(thin) (@owned SuperSub) -> @error Error
     // CHECK:   [[ARG_COPY:%.*]] = copy_value [[ARG]]
@@ -630,12 +635,13 @@
     // CHECK: } // end sil function '[[INNER_FUNC_1]]'
     let f1 = {
       // CHECK: sil private [transparent] @[[INNER_FUNC_2]]
-      // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+      // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
       // CHECK:   [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
       // CHECK:   [[ARG_COPY:%.*]] = copy_value [[BORROWED_ARG]]
       // CHECK:   [[ARG_COPY_SUPER:%.*]] = upcast [[ARG_COPY]] : $SuperSub to $SuperBase
       // CHECK:   [[SUPER_METHOD:%.*]] = function_ref @_T08closures9SuperBaseC4boomyyF : $@convention(method) (@guaranteed SuperBase) -> ()
-      // CHECK:   = apply [[SUPER_METHOD]]([[ARG_COPY_SUPER]]) : $@convention(method) (@guaranteed SuperBase) -> ()
+      // CHECK:   [[BORROWED_ARG_COPY_SUPER:%.*]] = begin_borrow [[ARG_COPY_SUPER]]
+      // CHECK:   = apply [[SUPER_METHOD]]([[BORROWED_ARG_COPY_SUPER]]) : $@convention(method) (@guaranteed SuperBase) -> ()
       // CHECK:   destroy_value [[ARG_COPY_SUPER]]
       // CHECK:   end_borrow [[BORROWED_ARG]] from [[ARG]]
       // CHECK:   destroy_value [[ARG]]
@@ -645,14 +651,14 @@
   }
 
   // CHECK-LABEL: sil hidden @_T08closures8SuperSubC1gyyF : $@convention(method) (@guaranteed SuperSub) -> () {
-  // CHECK: bb0([[SELF:%.*]] : $SuperSub):
+  // CHECK: bb0([[SELF:%.*]] : @guaranteed $SuperSub):
   // CHECK:   [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK:   [[INNER:%.*]] = function_ref @[[INNER_FUNC_1:_T08closures8SuperSubC1g[_0-9a-zA-Z]*]] : $@convention(thin) (@owned SuperSub) -> ()
   // CHECK:   = apply [[INNER]]([[SELF_COPY]])
   // CHECK: } // end sil function '_T08closures8SuperSubC1gyyF'
   func g() {
     // CHECK: sil private @[[INNER_FUNC_1]] : $@convention(thin) (@owned SuperSub) -> ()
-    // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+    // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
     // CHECK:   [[TRY_APPLY_FUNC:%.*]] = function_ref @_T0s2qqoixxSg_xyKXKtKlF : $@convention(thin) <τ_0_0> (@in Optional<τ_0_0>, @owned @noescape @callee_owned () -> (@out τ_0_0, @error Error)) -> (@out τ_0_0, @error Error)
     // CHECK:   [[INNER:%.*]] = function_ref @[[INNER_FUNC_2:_T08closures8SuperSubC1g.*]] : $@convention(thin) (@owned SuperSub) -> @error Error
     // CHECK:   [[ARG_COPY:%.*]] = copy_value [[ARG]]
@@ -666,12 +672,13 @@
     // CHECK: } // end sil function '[[INNER_FUNC_1]]'
     func g1() {
       // CHECK: sil private [transparent] @[[INNER_FUNC_2]] : $@convention(thin) (@owned SuperSub) -> @error Error {
-      // CHECK: bb0([[ARG:%.*]] : $SuperSub):
+      // CHECK: bb0([[ARG:%.*]] : @owned $SuperSub):
       // CHECK:   [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
       // CHECK:   [[ARG_COPY:%.*]] = copy_value [[BORROWED_ARG]]
       // CHECK:   [[ARG_COPY_SUPER:%.*]] = upcast [[ARG_COPY]] : $SuperSub to $SuperBase
       // CHECK:   [[SUPER_METHOD:%.*]] = function_ref @_T08closures9SuperBaseC4boomyyF : $@convention(method) (@guaranteed SuperBase) -> ()
-      // CHECK:   = apply [[SUPER_METHOD]]([[ARG_COPY_SUPER]])
+      // CHECK:   [[BORROWED_ARG_COPY_SUPER:%.*]] = begin_borrow [[ARG_COPY_SUPER]]
+      // CHECK:   = apply [[SUPER_METHOD]]([[BORROWED_ARG_COPY_SUPER]])
       // CHECK:   destroy_value [[ARG_COPY_SUPER]]
       // CHECK:   end_borrow [[BORROWED_ARG]] from [[ARG]]
       // CHECK:   destroy_value [[ARG]]
@@ -684,7 +691,7 @@
 
 // CHECK-LABEL: sil hidden @_T08closures24UnownedSelfNestedCaptureC06nestedE0{{[_0-9a-zA-Z]*}}F : $@convention(method) (@guaranteed UnownedSelfNestedCapture) -> ()
 // -- We enter with an assumed strong +1.
-// CHECK:  bb0([[SELF:%.*]] : $UnownedSelfNestedCapture):
+// CHECK:  bb0([[SELF:%.*]] : @guaranteed $UnownedSelfNestedCapture):
 // CHECK:         [[OUTER_SELF_CAPTURE:%.*]] = alloc_box ${ var @sil_unowned UnownedSelfNestedCapture }
 // CHECK:         [[PB:%.*]] = project_box [[OUTER_SELF_CAPTURE]]
 // -- strong +2
@@ -722,7 +729,7 @@
 // -- outer closure
 // -- strong +0, unowned +1
 // CHECK: sil private @[[OUTER_CLOSURE_FUN:_T08closures24UnownedSelfNestedCaptureC06nestedE0yyFACycycfU_]] : $@convention(thin) (@owned @sil_unowned UnownedSelfNestedCapture) -> @owned @callee_owned () -> @owned UnownedSelfNestedCapture {
-// CHECK: bb0([[CAPTURED_SELF:%.*]] : $@sil_unowned UnownedSelfNestedCapture):
+// CHECK: bb0([[CAPTURED_SELF:%.*]] : @owned $@sil_unowned UnownedSelfNestedCapture):
 // -- strong +0, unowned +2
 // CHECK:         [[CAPTURED_SELF_COPY:%.*]] = copy_value [[CAPTURED_SELF]] :
 // -- closure takes ownership of unowned ref
@@ -735,7 +742,7 @@
 // -- inner closure
 // -- strong +0, unowned +1
 // CHECK: sil private @[[INNER_CLOSURE_FUN:_T08closures24UnownedSelfNestedCaptureC06nestedE0yyFACycycfU_ACycfU_]] : $@convention(thin) (@owned @sil_unowned UnownedSelfNestedCapture) -> @owned UnownedSelfNestedCapture {
-// CHECK: bb0([[CAPTURED_SELF:%.*]] : $@sil_unowned UnownedSelfNestedCapture):
+// CHECK: bb0([[CAPTURED_SELF:%.*]] : @owned $@sil_unowned UnownedSelfNestedCapture):
 // -- strong +1, unowned +1
 // CHECK:         [[SELF:%.*]] = copy_unowned_value [[CAPTURED_SELF:%.*]] :
 // -- strong +1, unowned +0 (claimed by return)
@@ -756,12 +763,13 @@
 }
 
 // CHECK-LABEL: sil private @_T08closures14GenericDerivedC4swimyyFyycfU_ : $@convention(thin) <Ocean> (@owned GenericDerived<Ocean>) -> ()
-// CHECK: bb0([[ARG:%.*]] : $GenericDerived<Ocean>):
+// CHECK: bb0([[ARG:%.*]] : @owned $GenericDerived<Ocean>):
 // CHECK:   [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
 // CHECK:   [[ARG_COPY:%.*]] = copy_value [[BORROWED_ARG]]
 // CHECK:   [[ARG_COPY_SUPER:%.*]] = upcast [[ARG_COPY]] : $GenericDerived<Ocean> to $ConcreteBase
 // CHECK:   [[METHOD:%.*]] = function_ref @_T08closures12ConcreteBaseC4swimyyF
-// CHECK:   apply [[METHOD]]([[ARG_COPY_SUPER]]) : $@convention(method) (@guaranteed ConcreteBase) -> ()
+// CHECK:   [[BORROWED_ARG_COPY_SUPER:%.*]] = begin_borrow [[ARG_COPY_SUPER]]
+// CHECK:   apply [[METHOD]]([[BORROWED_ARG_COPY_SUPER]]) : $@convention(method) (@guaranteed ConcreteBase) -> ()
 // CHECK:   destroy_value [[ARG_COPY_SUPER]]
 // CHECK:   end_borrow [[BORROWED_ARG]] from [[ARG]]
 // CHECK:   destroy_value [[ARG]]
diff --git a/test/SILGen/metatype_object_conversion.swift b/test/SILGen/metatype_object_conversion.swift
index c40a43c..adb2b21 100644
--- a/test/SILGen/metatype_object_conversion.swift
+++ b/test/SILGen/metatype_object_conversion.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-silgen -sdk %S/Inputs -I %S/Inputs -enable-source-import %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen -sdk %S/Inputs -I %S/Inputs -enable-source-import %s | %FileCheck %s
 
 // REQUIRES: objc_interop
 
@@ -12,7 +12,7 @@
 
 // CHECK-LABEL: sil hidden @_T026metatype_object_conversion0A8ToObjectyXlAA1CCmF 
 func metatypeToObject(_ x: C.Type) -> AnyObject {
-  // CHECK: bb0([[THICK:%.*]] : $@thick C.Type):
+  // CHECK: bb0([[THICK:%.*]] : @trivial $@thick C.Type):
   // CHECK:   [[OBJC:%.*]] = thick_to_objc_metatype [[THICK]]
   // CHECK:   [[OBJECT:%.*]] = objc_metatype_to_object [[OBJC]]
   // CHECK:   return [[OBJECT]]
@@ -21,7 +21,7 @@
 
 // CHECK-LABEL: sil hidden @_T026metatype_object_conversion27existentialMetatypeToObjectyXlAA2CP_pXpF
 func existentialMetatypeToObject(_ x: CP.Type) -> AnyObject {
-  // CHECK: bb0([[THICK:%.*]] : $@thick CP.Type):
+  // CHECK: bb0([[THICK:%.*]] : @trivial $@thick CP.Type):
   // CHECK:   [[OBJC:%.*]] = thick_to_objc_metatype [[THICK]]
   // CHECK:   [[OBJECT:%.*]] = objc_existential_metatype_to_object [[OBJC]]
   // CHECK:   return [[OBJECT]]
diff --git a/test/SILGen/nested_generics.swift b/test/SILGen/nested_generics.swift
index f17e34e..7bc201f 100644
--- a/test/SILGen/nested_generics.swift
+++ b/test/SILGen/nested_generics.swift
@@ -1,7 +1,7 @@
-// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-silgen  -parse-as-library %s | %FileCheck %s
-// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-sil -parse-as-library %s > /dev/null
-// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-sil -O -parse-as-library %s > /dev/null
-// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-ir -parse-as-library %s > /dev/null
+// RUN: %target-swift-frontend -enable-sil-ownership -Xllvm -sil-full-demangle -emit-silgen  -parse-as-library %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -Xllvm -sil-full-demangle -emit-sil -parse-as-library %s > /dev/null
+// RUN: %target-swift-frontend -enable-sil-ownership -Xllvm -sil-full-demangle -emit-sil -O -parse-as-library %s > /dev/null
+// RUN: %target-swift-frontend -enable-sil-ownership -Xllvm -sil-full-demangle -emit-ir -parse-as-library %s > /dev/null
 
 // TODO:
 // - test generated SIL -- mostly we're just testing mangling here
@@ -226,7 +226,7 @@
 // CHECK-LABEL: sil shared [transparent] [serializable] [reabstraction_thunk] @_T015nested_generics6PizzasV7NewYorkCyAA6PepperV_GAA7HotDogsC8AmericanVIexxd_AhLIexxr_TR : $@convention(thin) (@owned Pizzas<Pepper>.NewYork, @owned @callee_owned (@owned Pizzas<Pepper>.NewYork) -> HotDogs.American) -> @out HotDogs.American
 
 // CHECK-LABEL: sil private [transparent] [thunk] @_T015nested_generics9OuterRingC05InnerD0Cyx_qd__GAA30ProtocolWithGenericRequirementA2aGP6method1TQz_1UQzqd__tAK1t_AM1uqd__1vtlFTW : $@convention(witness_method) <τ_0_0><τ_1_0><τ_2_0> (@in τ_0_0, @in τ_1_0, @in τ_2_0, @in_guaranteed OuterRing<τ_0_0>.InnerRing<τ_1_0>) -> (@out τ_0_0, @out τ_1_0, @out τ_2_0) {
-// CHECK: bb0([[T:%[0-9]+]] : $*τ_0_0, [[U:%[0-9]+]] : $*τ_1_0, [[V:%[0-9]+]] : $*τ_2_0, [[TOut:%[0-9]+]] : $*τ_0_0, [[UOut:%[0-9]+]] : $*τ_1_0, [[VOut:%[0-9]+]] : $*τ_2_0, [[SELF:%[0-9]+]] : $*OuterRing<τ_0_0>.InnerRing<τ_1_0>):
+// CHECK: bb0([[T:%[0-9]+]] : @trivial $*τ_0_0, [[U:%[0-9]+]] : @trivial $*τ_1_0, [[V:%[0-9]+]] : @trivial $*τ_2_0, [[TOut:%[0-9]+]] : @trivial $*τ_0_0, [[UOut:%[0-9]+]] : @trivial $*τ_1_0, [[VOut:%[0-9]+]] : @trivial $*τ_2_0, [[SELF:%[0-9]+]] : @trivial $*OuterRing<τ_0_0>.InnerRing<τ_1_0>):
 // CHECK:   [[SELF_COPY:%[0-9]+]] = alloc_stack $OuterRing<τ_0_0>.InnerRing<τ_1_0>
 // CHECK:   copy_addr [[SELF]] to [initialization] [[SELF_COPY]] : $*OuterRing<τ_0_0>.InnerRing<τ_1_0>
 // CHECK:   [[SELF_COPY_VAL:%[0-9]+]] = load [take] [[SELF_COPY]] : $*OuterRing<τ_0_0>.InnerRing<τ_1_0>
diff --git a/test/SILGen/nsmanaged-witness.swift b/test/SILGen/nsmanaged-witness.swift
index 033d50c..5b269cc 100644
--- a/test/SILGen/nsmanaged-witness.swift
+++ b/test/SILGen/nsmanaged-witness.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -sdk %S/Inputs %s -I %S/Inputs -enable-source-import -emit-silgen | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -sdk %S/Inputs %s -I %S/Inputs -enable-source-import -emit-silgen | %FileCheck %s
 
 // REQUIRES: objc_interop
 
diff --git a/test/SILGen/objc_bridging_any.swift b/test/SILGen/objc_bridging_any.swift
index b0996ea..d32606b 100644
--- a/test/SILGen/objc_bridging_any.swift
+++ b/test/SILGen/objc_bridging_any.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -Xllvm -sil-print-debuginfo -emit-silgen %s | %FileCheck %s
+// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -Xllvm -sil-print-debuginfo -emit-silgen -enable-sil-ownership %s | %FileCheck %s
 // REQUIRES: objc_interop
 
 import Foundation
@@ -24,7 +24,7 @@
                            optionalA: String?,
                            optionalB: NSString?,
                            optionalC: Any?) {
-  // CHECK: bb0([[SELF:%.*]] : $NSIdLover,
+  // CHECK: bb0([[SELF:%.*]] : @owned $NSIdLover,
   // CHECK:   debug_value [[STRING:%.*]] : $String
   // CHECK:   debug_value [[NSSTRING:%.*]] : $NSString
   // CHECK:   debug_value [[OBJECT:%.*]] : $AnyObject
@@ -184,7 +184,8 @@
   // CHECK:   [[OPT_STRING_COPY:%.*]] = copy_value [[BORROWED_OPT_STRING]]
   // CHECK:   [[BRIDGE_OPTIONAL:%.*]] = function_ref @_T0Sq19_bridgeToObjectiveCyXlyF
   // CHECK:   [[TMP:%.*]] = alloc_stack $Optional<String>
-  // CHECK:   store [[OPT_STRING_COPY]] to [init] [[TMP]]
+  // CHECK:   [[BORROWED_OPT_STRING_COPY:%.*]] = begin_borrow [[OPT_STRING_COPY]]
+  // CHECK:   store_borrow [[BORROWED_OPT_STRING_COPY]] to [[TMP]]
   // CHECK:   [[ANYOBJECT:%.*]] = apply [[BRIDGE_OPTIONAL]]<String>([[TMP]])
   // CHECK:   end_borrow [[BORROWED_OPT_STRING]] from [[OPT_STRING]]
   // CHECK:   apply [[METHOD]]([[ANYOBJECT]], [[BORROWED_SELF]])
@@ -197,7 +198,8 @@
   // CHECK:   [[OPT_NSSTRING_COPY:%.*]] = copy_value [[BORROWED_OPT_NSSTRING]]
   // CHECK:   [[BRIDGE_OPTIONAL:%.*]] = function_ref @_T0Sq19_bridgeToObjectiveCyXlyF
   // CHECK:   [[TMP:%.*]] = alloc_stack $Optional<NSString>
-  // CHECK:   store [[OPT_NSSTRING_COPY]] to [init] [[TMP]]
+  // CHECK:   [[BORROWED_OPT_NSSTRING_COPY:%.*]] = begin_borrow [[OPT_NSSTRING_COPY]]
+  // CHECK:   store_borrow [[BORROWED_OPT_NSSTRING_COPY]] to [[TMP]]
   // CHECK:   [[ANYOBJECT:%.*]] = apply [[BRIDGE_OPTIONAL]]<NSString>([[TMP]])
   // CHECK:   end_borrow [[BORROWED_OPT_NSSTRING]] from [[OPT_NSSTRING]]
   // CHECK:   apply [[METHOD]]([[ANYOBJECT]], [[BORROWED_SELF]])
@@ -260,7 +262,7 @@
                                    optOptB: NSString??,
                                    optOptC: Any??)
 {
-  // CHECK: bb0([[SELF:%.*]] : $NSIdLover,
+  // CHECK: bb0([[SELF:%.*]] : @owned $NSIdLover,
   // CHECK: [[STRING:%.*]] : $String,
   // CHECK: [[NSSTRING:%.*]] : $NSString
   // CHECK: [[OBJECT:%.*]] : $AnyObject
@@ -431,7 +433,7 @@
   // CHECK: [[OPT_STRING_COPY:%.*]] = copy_value [[BORROWED_OPT_STRING]]
   // CHECK: switch_enum [[OPT_STRING_COPY]] : $Optional<String>, case #Optional.some!enumelt.1: [[SOME_BB:bb[0-9]+]], case #Optional.none!enumelt: [[NONE_BB:bb[0-9]+]]
   //
-  // CHECK: [[SOME_BB]]([[STRING_DATA:%.*]] : $String):
+  // CHECK: [[SOME_BB]]([[STRING_DATA:%.*]] : @owned $String):
   // CHECK:   [[BRIDGE_STRING:%.*]] = function_ref @_T0SS10FoundationE19_bridgeToObjectiveCSo8NSStringCyF
   // CHECK:   [[BORROWED_STRING_DATA:%.*]] = begin_borrow [[STRING_DATA]]
   // CHECK:   [[BRIDGED:%.*]] = apply [[BRIDGE_STRING]]([[BORROWED_STRING_DATA]])
@@ -445,7 +447,7 @@
   // CHECK:   [[OPT_NONE:%.*]] = enum $Optional<AnyObject>, #Optional.none!enumelt
   // CHECK:   br [[JOIN]]([[OPT_NONE]]
   //
-  // CHECK: [[JOIN]]([[PHI:%.*]] : $Optional<AnyObject>):
+  // CHECK: [[JOIN]]([[PHI:%.*]] : @owned $Optional<AnyObject>):
   // CHECK:   end_borrow [[BORROWED_OPT_STRING]] from [[OPT_STRING]]
   // CHECK:   apply [[METHOD]]([[PHI]], [[BORROWED_SELF]])
   // CHECK:   destroy_value [[PHI]]
@@ -494,7 +496,7 @@
   // CHECK: } // end sil function '_T017objc_bridging_any12SwiftIdLoverC18methodReturningAnyypyF'
 
   // CHECK-LABEL: sil hidden [thunk] @_T017objc_bridging_any12SwiftIdLoverC18methodReturningAnyypyFTo : $@convention(objc_method) (SwiftIdLover) -> @autoreleased AnyObject {
-  // CHECK: bb0([[SELF:%[0-9]+]] : $SwiftIdLover):
+  // CHECK: bb0([[SELF:%[0-9]+]] : @unowned $SwiftIdLover):
   // CHECK:   [[NATIVE_RESULT:%.*]] = alloc_stack $Any
   // CHECK:   [[SELF_COPY:%.*]] = copy_value [[SELF]] : $SwiftIdLover
   // CHECK:   [[BORROWED_SELF_COPY:%.*]] = begin_borrow [[SELF_COPY]]
@@ -517,7 +519,7 @@
 
   @objc func methodTakingAny(a: Any) {}
   // CHECK-LABEL: sil hidden [thunk] @_T017objc_bridging_any12SwiftIdLoverC15methodTakingAnyyyp1a_tFTo : $@convention(objc_method) (AnyObject, SwiftIdLover) -> ()
-  // CHECK:     bb0([[ARG:%.*]] : $AnyObject, [[SELF:%.*]] : $SwiftIdLover):
+  // CHECK:     bb0([[ARG:%.*]] : @unowned $AnyObject, [[SELF:%.*]] : @unowned $SwiftIdLover):
   // CHECK-NEXT:  [[ARG_COPY:%.*]] = copy_value [[ARG]]
   // CHECK-NEXT:  [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK-NEXT:  [[OPENED_SELF:%.*]] = open_existential_ref [[ARG_COPY]]
@@ -541,7 +543,7 @@
   // CHECK-LABEL: sil hidden @_T017objc_bridging_any12SwiftIdLoverC017methodTakingBlockH3AnyyyypcF : $@convention(method) (@owned @noescape @callee_owned (@in Any) -> (), @guaranteed SwiftIdLover) -> ()
 
   // CHECK-LABEL: sil hidden [thunk] @_T017objc_bridging_any12SwiftIdLoverC017methodTakingBlockH3AnyyyypcFTo : $@convention(objc_method) (@convention(block) @noescape (AnyObject) -> (), SwiftIdLover) -> ()
-  // CHECK:    bb0([[BLOCK:%.*]] : $@convention(block) @noescape (AnyObject) -> (), [[SELF:%.*]] : $SwiftIdLover):
+  // CHECK:    bb0([[BLOCK:%.*]] : @unowned $@convention(block) @noescape (AnyObject) -> (), [[SELF:%.*]] : @unowned $SwiftIdLover):
   // CHECK-NEXT:  [[BLOCK_COPY:%.*]] = copy_block [[BLOCK]]
   // CHECK-NEXT:  [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK:       [[THUNK_FN:%.*]] = function_ref @_T0yXlIyBy_ypIxi_TR
@@ -556,7 +558,7 @@
   // CHECK-NEXT:  return [[RESULT]]
 
   // CHECK-LABEL: sil shared [transparent] [serializable] [reabstraction_thunk] @_T0yXlIyBy_ypIxi_TR
-  // CHECK:     bb0([[ANY:%.*]] : $*Any, [[BLOCK:%.*]] : $@convention(block) @noescape (AnyObject) -> ()):
+  // CHECK:     bb0([[ANY:%.*]] : @trivial $*Any, [[BLOCK:%.*]] : @owned $@convention(block) @noescape (AnyObject) -> ()):
   // CHECK-NEXT:  [[OPENED_ANY:%.*]] = open_existential_addr immutable_access [[ANY]] : $*Any to $*[[OPENED_TYPE:@opened.*Any]],
 	// CHECK:   [[TMP:%.*]] = alloc_stack
   // CHECK:   copy_addr [[OPENED_ANY]] to [initialization] [[TMP]]
@@ -576,7 +578,7 @@
   // CHECK-LABEL: sil hidden @_T017objc_bridging_any12SwiftIdLoverC29methodReturningBlockTakingAnyyypcyF : $@convention(method) (@guaranteed SwiftIdLover) -> @owned @callee_owned (@in Any) -> ()
 
   // CHECK-LABEL: sil hidden [thunk] @_T017objc_bridging_any12SwiftIdLoverC29methodReturningBlockTakingAnyyypcyFTo : $@convention(objc_method) (SwiftIdLover) -> @autoreleased @convention(block) (AnyObject) -> ()
-  // CHECK:     bb0([[SELF:%.*]] : $SwiftIdLover):
+  // CHECK:     bb0([[SELF:%.*]] : @unowned $SwiftIdLover):
   // CHECK-NEXT:  [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK-NEXT:  [[BORROWED_SELF_COPY:%.*]] = begin_borrow [[SELF_COPY]]
   // CHECK-NEXT:  // function_ref
@@ -595,7 +597,7 @@
   // CHECK-NEXT:  return [[BLOCK]]
 
   // CHECK-LABEL: sil shared [transparent] [serializable] [reabstraction_thunk] @_T0ypIexi_yXlIeyBy_TR : $@convention(c) (@inout_aliasable @block_storage @callee_owned (@in Any) -> (), AnyObject) -> ()
-  // CHECK:     bb0([[BLOCK_STORAGE:%.*]] : $*@block_storage @callee_owned (@in Any) -> (), [[ANY:%.*]] : $AnyObject):
+  // CHECK:     bb0([[BLOCK_STORAGE:%.*]] : @trivial $*@block_storage @callee_owned (@in Any) -> (), [[ANY:%.*]] : @unowned $AnyObject):
   // CHECK-NEXT:  [[BLOCK_STORAGE_ADDR:%.*]] = project_block_storage [[BLOCK_STORAGE]]
   // CHECK-NEXT:  [[FUNCTION:%.*]] = load [copy] [[BLOCK_STORAGE_ADDR]]
   // CHECK-NEXT:  [[ANY_COPY:%.*]] = copy_value [[ANY]]
@@ -615,7 +617,7 @@
   // CHECK-LABEL: sil hidden @_T017objc_bridging_any12SwiftIdLoverC29methodTakingBlockReturningAnyyypycF : $@convention(method) (@owned @noescape @callee_owned () -> @out Any, @guaranteed SwiftIdLover) -> () {
 
   // CHECK-LABEL: sil hidden [thunk] @_T017objc_bridging_any12SwiftIdLoverC29methodTakingBlockReturningAnyyypycFTo : $@convention(objc_method) (@convention(block) @noescape () -> @autoreleased AnyObject, SwiftIdLover) -> ()
-  // CHECK:     bb0([[BLOCK:%.*]] : $@convention(block) @noescape () -> @autoreleased AnyObject, [[ANY:%.*]] : $SwiftIdLover):
+  // CHECK:     bb0([[BLOCK:%.*]] : @unowned $@convention(block) @noescape () -> @autoreleased AnyObject, [[ANY:%.*]] : @unowned $SwiftIdLover):
   // CHECK-NEXT:  [[BLOCK_COPY:%.*]] = copy_block [[BLOCK]]
   // CHECK-NEXT:  [[ANY_COPY:%.*]] = copy_value [[ANY]]
   // CHECK-NEXT:  // function_ref
@@ -631,7 +633,7 @@
   // CHECK-NEXT:  return [[RESULT]]
 
   // CHECK-LABEL: sil shared [transparent] [serializable] [reabstraction_thunk] @_T0yXlIyBa_ypIxr_TR : $@convention(thin) (@owned @convention(block) @noescape () -> @autoreleased AnyObject) -> @out Any
-  // CHECK:     bb0([[ANY_ADDR:%.*]] : $*Any, [[BLOCK:%.*]] : $@convention(block) @noescape () -> @autoreleased AnyObject):
+  // CHECK:     bb0([[ANY_ADDR:%.*]] : @trivial $*Any, [[BLOCK:%.*]] : @owned $@convention(block) @noescape () -> @autoreleased AnyObject):
   // CHECK-NEXT:  [[BRIDGED:%.*]] = apply [[BLOCK]]()
   // CHECK-NEXT:  [[OPTIONAL:%.*]] = unchecked_ref_cast [[BRIDGED]]
   // CHECK-NEXT:  // function_ref
@@ -648,7 +650,7 @@
   // CHECK-LABEL: sil hidden @_T017objc_bridging_any12SwiftIdLoverC020methodReturningBlockH3AnyypycyF : $@convention(method) (@guaranteed SwiftIdLover) -> @owned @callee_owned () -> @out Any
 
   // CHECK-LABEL: sil hidden [thunk] @_T017objc_bridging_any12SwiftIdLoverC020methodReturningBlockH3AnyypycyFTo : $@convention(objc_method) (SwiftIdLover) -> @autoreleased @convention(block) () -> @autoreleased AnyObject
-  // CHECK:     bb0([[SELF:%.*]] : $SwiftIdLover):
+  // CHECK:     bb0([[SELF:%.*]] : @unowned $SwiftIdLover):
   // CHECK-NEXT:  [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK-NEXT:  [[BORROWED_SELF_COPY:%.*]] = begin_borrow [[SELF_COPY]]
   // CHECK-NEXT:  // function_ref
@@ -668,7 +670,7 @@
   // CHECK-NEXT:  return [[BLOCK]]
 
   // CHECK-LABEL: sil shared [transparent] [serializable] [reabstraction_thunk] @_T0ypIexr_yXlIeyBa_TR : $@convention(c) (@inout_aliasable @block_storage @callee_owned () -> @out Any) -> @autoreleased AnyObject
-  // CHECK:     bb0(%0 : $*@block_storage @callee_owned () -> @out Any):
+  // CHECK:     bb0(%0 : @trivial $*@block_storage @callee_owned () -> @out Any):
   // CHECK-NEXT:  [[BLOCK_STORAGE_ADDR:%.*]] = project_block_storage %0
   // CHECK-NEXT:  [[FUNCTION:%.*]] = load [copy] [[BLOCK_STORAGE_ADDR]]
   // CHECK-NEXT:  [[RESULT:%.*]] = alloc_stack $Any
@@ -713,7 +715,7 @@
 extension GenericClass {
   // CHECK-LABEL: sil hidden @_T0So12GenericClassC17objc_bridging_anyE23pseudogenericAnyErasureypx1x_tF :
   func pseudogenericAnyErasure(x: T) -> Any {
-    // CHECK: bb0([[ANY_OUT:%.*]] : $*Any, [[ARG:%.*]] : $T, [[SELF:%.*]] : $GenericClass<T>
+    // CHECK: bb0([[ANY_OUT:%.*]] : @trivial $*Any, [[ARG:%.*]] : @owned $T, [[SELF:%.*]] : @guaranteed $GenericClass<T>
     // CHECK:   [[ANY_BUF:%.*]] = init_existential_addr [[ANY_OUT]] : $*Any, $AnyObject
     // CHECK:   [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
     // CHECK:   [[ARG_COPY:%.*]] = copy_value [[BORROWED_ARG]]
diff --git a/test/SILGen/objc_extensions.swift b/test/SILGen/objc_extensions.swift
index 5b6a6db..df804d8 100644
--- a/test/SILGen/objc_extensions.swift
+++ b/test/SILGen/objc_extensions.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-silgen -sdk %S/Inputs/ -I %S/Inputs -enable-source-import %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen -sdk %S/Inputs/ -I %S/Inputs -enable-source-import %s | %FileCheck %s
 
 // REQUIRES: objc_interop
 
@@ -16,7 +16,7 @@
     // Make sure that we are generating the @objc thunk and are calling the actual method.
     //
     // CHECK-LABEL: sil hidden [thunk] @_T015objc_extensions3SubC4propSQySSGvgTo : $@convention(objc_method) (Sub) -> @autoreleased Optional<NSString> {
-    // CHECK: bb0([[SELF:%.*]] : $Sub):
+    // CHECK: bb0([[SELF:%.*]] : @unowned $Sub):
     // CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]]
     // CHECK: [[BORROWED_SELF_COPY:%.*]] = begin_borrow [[SELF_COPY]]
     // CHECK: [[GETTER_FUNC:%.*]] = function_ref @_T015objc_extensions3SubC4propSQySSGvg : $@convention(method) (@guaranteed Sub) -> @owned Optional<String>
@@ -27,7 +27,7 @@
 
     // Then check the body of the getter calls the super_method.
     // CHECK-LABEL: sil hidden @_T015objc_extensions3SubC4propSQySSGvg : $@convention(method) (@guaranteed Sub) -> @owned Optional<String> {
-    // CHECK: bb0([[SELF:%.*]] : $Sub):
+    // CHECK: bb0([[SELF:%.*]] : @guaranteed $Sub):
     // CHECK: [[SELF_COPY:%.*]] = copy_value [[SELF]]
     // CHECK: [[SELF_COPY_CAST:%.*]] = upcast [[SELF_COPY]] : $Sub to $Base
     // CHECK: [[BORROWED_SELF_COPY_CAST:%.*]] = begin_borrow [[SELF_COPY_CAST]]
@@ -42,13 +42,13 @@
     // Then check the setter @objc thunk.
     //
     // CHECK-LABEL: sil hidden [thunk] @_T015objc_extensions3SubC4propSQySSGvsTo : $@convention(objc_method) (Optional<NSString>, Sub) -> () {
-    // CHECK: bb0([[NEW_VALUE:%.*]] : $Optional<NSString>, [[SELF:%.*]] : $Sub):
+    // CHECK: bb0([[NEW_VALUE:%.*]] : @unowned $Optional<NSString>, [[SELF:%.*]] : @unowned $Sub):
     // CHECK:   [[NEW_VALUE_COPY:%.*]] = copy_value [[NEW_VALUE]]
     // CHECK:   [[SELF_COPY:%.*]] = copy_value [[SELF]] : $Sub
     // CHECK:   switch_enum [[NEW_VALUE_COPY]] : $Optional<NSString>, case #Optional.some!enumelt.1: [[SUCC_BB:bb[0-9]+]], case #Optional.none!enumelt: [[FAIL_BB:bb[0-9]+]]
-    // CHECK: [[SUCC_BB]]([[STR:%.*]] : $NSString):
+    // CHECK: [[SUCC_BB]]([[STR:%.*]] : @owned $NSString):
     // CHECK: [[FAIL_BB]]:
-    // CHECK: bb3([[BRIDGED_NEW_VALUE:%.*]] : $Optional<String>):
+    // CHECK: bb3([[BRIDGED_NEW_VALUE:%.*]] : @owned $Optional<String>):
     // CHECK:   [[BORROWED_SELF_COPY:%.*]] = begin_borrow [[SELF_COPY]]
     // CHECK:   [[NORMAL_FUNC:%.*]] = function_ref @_T015objc_extensions3SubC4propSQySSGvs : $@convention(method) (@owned Optional<String>, @guaranteed Sub) -> ()
     // CHECK:   apply [[NORMAL_FUNC]]([[BRIDGED_NEW_VALUE]], [[BORROWED_SELF_COPY]])
@@ -61,7 +61,7 @@
     // CHECK-LABEL: sil hidden @_T015objc_extensions3SubC4propSQySSGvs : $@convention(method) (@owned Optional<String>, @guaranteed Sub) -> () {
 
     // First we get the old value.
-    // CHECK: bb0([[NEW_VALUE:%.*]] : $Optional<String>, [[SELF:%.*]] : $Sub):
+    // CHECK: bb0([[NEW_VALUE:%.*]] : @owned $Optional<String>, [[SELF:%.*]] : @guaranteed $Sub):
     // CHECK:   [[SELF_COPY:%.*]] = copy_value [[SELF]]
     // CHECK:   [[UPCAST_SELF_COPY:%.*]] = upcast [[SELF_COPY]] : $Sub to $Base
     // CHECK:   [[BORROWED_UPCAST_SELF_COPY:%.*]] = begin_borrow [[UPCAST_SELF_COPY]]
@@ -70,7 +70,7 @@
     // CHECK:   end_borrow [[BORROWED_UPCAST_SELF_COPY]] from [[UPCAST_SELF_COPY]]
     // CHECK:   [[OLD_NSSTRING:%.*]] = apply [[GET_SUPER_METHOD]]([[UPCAST_SELF_COPY]])
 
-    // CHECK: bb3([[OLD_NSSTRING_BRIDGED:%.*]] : $Optional<String>):
+    // CHECK: bb3([[OLD_NSSTRING_BRIDGED:%.*]] : @owned $Optional<String>):
     // This next line is completely not needed. But we are emitting it now.
     // CHECK:   destroy_value [[UPCAST_SELF_COPY]]
     // CHECK:   [[SELF_COPY:%.*]] = copy_value [[SELF]]
@@ -83,8 +83,8 @@
     // CHECK:   [[NEW_VALUE_COPY:%.*]] = copy_value [[BORROWED_NEW_VALUE]]
     // CHECK:   switch_enum [[NEW_VALUE_COPY]] : $Optional<String>, case #Optional.some!enumelt.1: [[SOME_BB:bb[0-9]+]], case #Optional.none!enumelt: [[NONE_BB:bb[0-9]+]]
     //
-    // CHECK: bb4([[OLD_STRING:%.*]] : $String):
-    // CHECK: bb6([[BRIDGED_NEW_STRING:%.*]] : $Optional<NSString>):
+    // CHECK: bb4([[OLD_STRING:%.*]] : @owned $String):
+    // CHECK: bb6([[BRIDGED_NEW_STRING:%.*]] : @owned $Optional<NSString>):
     // CHECK:    end_borrow [[BORROWED_NEW_VALUE]]
     // CHECK:    apply [[SET_SUPER_METHOD]]([[BRIDGED_NEW_STRING]], [[UPCAST_SELF_COPY]])
     // CHECK:    destroy_value [[BRIDGED_NEW_STRING]]
@@ -109,7 +109,7 @@
 
 // CHECK-LABEL: sil hidden @_T015objc_extensions20testOverridePropertyyAA3SubCF
 func testOverrideProperty(_ obj: Sub) {
-  // CHECK: bb0([[ARG:%.*]] : $Sub):
+  // CHECK: bb0([[ARG:%.*]] : @owned $Sub):
   // CHECK: [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
   // CHECK: = objc_method [[BORROWED_ARG]] : $Sub, #Sub.prop!setter.1.foreign : (Sub) -> (String!) -> ()
   obj.prop = "abc"
@@ -121,7 +121,7 @@
 // CHECK:         function_ref @_T015objc_extensions3SubC3fooyyFTD
 // CHECK: } // end sil function '_T015objc_extensions3SubC3fooyyFTc'
 // CHECK:       sil shared [transparent] [serializable] [thunk] @_T015objc_extensions3SubC3fooyyFTD
-// CHECK:       bb0([[SELF:%.*]] : $Sub):
+// CHECK:       bb0([[SELF:%.*]] : @guaranteed $Sub):
 // CHECK:         [[SELF_COPY:%.*]] = copy_value [[SELF]]
 // CHECK:         objc_method [[SELF_COPY]] : $Sub, #Sub.foo!1.foreign
 // CHECK: } // end sil function '_T015objc_extensions3SubC3fooyyFTD'
@@ -137,8 +137,8 @@
 }
 
 class SubSub : Sub {
-  // CHECK-LABEL: sil hidden @_T015objc_extensions03SubC0C14objCBaseMethodyyF
-  // CHECK: bb0([[SELF:%.*]] : $SubSub):
+  // CHECK-LABEL: sil hidden @_T015objc_extensions03SubC0C14objCBaseMethodyyF :
+  // CHECK: bb0([[SELF:%.*]] : @guaranteed $SubSub):
   // CHECK:   [[SELF_COPY:%.*]] = copy_value [[SELF]]
   // CHECK:   [[UPCAST_SELF_COPY:%.*]] = upcast [[SELF_COPY]] : $SubSub to $Sub
   // CHECK:   [[BORROWED_UPCAST_SELF_COPY:%.*]] = begin_borrow [[UPCAST_SELF_COPY]]
@@ -153,7 +153,7 @@
 
 extension SubSub {
   // CHECK-LABEL: sil hidden @_T015objc_extensions03SubC0C9otherPropSSvs
-  // CHECK: bb0([[NEW_VALUE:%.*]] : $String, [[SELF:%.*]] : $SubSub):
+  // CHECK: bb0([[NEW_VALUE:%.*]] : @owned $String, [[SELF:%.*]] : @guaranteed $SubSub):
   // CHECK:   [[SELF_COPY_1:%.*]] = copy_value [[SELF]]
   // CHECK:   [[UPCAST_SELF_COPY_1:%.*]] = upcast [[SELF_COPY_1]] : $SubSub to $Sub
   // CHECK:   [[BORROWED_UPCAST_SELF_COPY_1:%.*]] = begin_borrow [[UPCAST_SELF_COPY_1]]
diff --git a/test/SILGen/objc_implicitly_unwrapped_optional.swift b/test/SILGen/objc_implicitly_unwrapped_optional.swift
index 06832be..f0806bc 100644
--- a/test/SILGen/objc_implicitly_unwrapped_optional.swift
+++ b/test/SILGen/objc_implicitly_unwrapped_optional.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil -assert-config Release %s | %FileCheck %s
+// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-sil-ownership -emit-sil -assert-config Release %s | %FileCheck %s
 
 // REQUIRES: objc_interop
 
diff --git a/test/SILGen/objc_keypath.swift b/test/SILGen/objc_keypath.swift
index 59a6a39..705503d 100644
--- a/test/SILGen/objc_keypath.swift
+++ b/test/SILGen/objc_keypath.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-sil -sdk %S/Inputs -I %S/Inputs -enable-source-import %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-sil -sdk %S/Inputs -I %S/Inputs -enable-source-import %s | %FileCheck %s
 
 // REQUIRES: objc_interop
 
diff --git a/test/SILGen/objc_properties.swift b/test/SILGen/objc_properties.swift
index 0362be4..941fbb5 100644
--- a/test/SILGen/objc_properties.swift
+++ b/test/SILGen/objc_properties.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend %s -emit-silgen -emit-verbose-sil -sdk %S/Inputs -I %S/Inputs -enable-source-import | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership %s -emit-silgen -emit-verbose-sil -sdk %S/Inputs -I %S/Inputs -enable-source-import | %FileCheck %s
 
 // REQUIRES: objc_interop
 
@@ -34,8 +34,8 @@
   // rdar://15858869 - However, direct access only applies to (implicit or
   // explicit) 'self' ivar references, not ALL ivar refs.
   // CHECK-LABEL: sil hidden @_T015objc_properties1AC{{[_0-9a-zA-Z]*}}fc
-  // CHECK: bb0(%0 : $A, %1 : $Int, %2 : $A):
-  // CHECK: [[SELF:%[0-9]+]] = mark_uninitialized [rootself] %2 : $A
+  // CHECK: bb0(%0 : @owned $A, %1 : @trivial $Int, [[OLD_SELF:%.*]] : @owned $A):
+  // CHECK: [[SELF:%[0-9]+]] = mark_uninitialized [rootself] [[OLD_SELF]] : $A
   init(other : A, x : Int) {
     // CHECK: [[BORROWED_SELF:%.*]] = begin_borrow [[SELF]]
     // CHECK: [[SELF_A:%[0-9]+]] = ref_element_addr [[BORROWED_SELF]] : $A, #A.prop
@@ -104,7 +104,7 @@
 // Test the @NSCopying attribute.
 class TestNSCopying {
   // CHECK-LABEL: sil hidden [transparent] @_T015objc_properties13TestNSCopyingC8propertySo8NSStringCvs : $@convention(method) (@owned NSString, @guaranteed TestNSCopying) -> ()
-  // CHECK: bb0([[ARG0:%.*]] : $NSString, [[ARG1:%.*]] : $TestNSCopying):
+  // CHECK: bb0([[ARG0:%.*]] : @owned $NSString, [[ARG1:%.*]] : @guaranteed $TestNSCopying):
   // CHECK:   [[BORROWED_ARG0:%.*]] = begin_borrow [[ARG0]]
   // CHECK:   objc_method [[BORROWED_ARG0]] : $NSString, #NSString.copy!1.foreign
   @NSCopying var property : NSString
@@ -158,7 +158,7 @@
 
 class HasUnmanaged : NSObject {
   // CHECK-LABEL: sil hidden [thunk] @_T015objc_properties12HasUnmanagedC3refs0D0VyyXlGSgvgTo
-  // CHECK: bb0([[CLS:%.*]] : $HasUnmanaged):
+  // CHECK: bb0([[CLS:%.*]] : @unowned $HasUnmanaged):
   // CHECK:     [[CLS_COPY:%.*]] = copy_value [[CLS]]
   // CHECK:     [[BORROWED_CLS_COPY:%.*]] = begin_borrow [[CLS_COPY]]
   // CHECK:     [[NATIVE:%.+]] = function_ref @_T015objc_properties12HasUnmanagedC3refs0D0VyyXlGSgvg
@@ -171,7 +171,7 @@
   // CHECK: } // end sil function '_T015objc_properties12HasUnmanagedC3refs0D0VyyXlGSgvgTo'
 
   // CHECK-LABEL: sil hidden [thunk] @_T015objc_properties12HasUnmanagedC3refs0D0VyyXlGSgvsTo
-  // CHECK: bb0([[NEW_VALUE:%.*]] : $Optional<Unmanaged<AnyObject>>, [[SELF:%.*]] : $HasUnmanaged):
+  // CHECK: bb0([[NEW_VALUE:%.*]] : @trivial $Optional<Unmanaged<AnyObject>>, [[SELF:%.*]] : @unowned $HasUnmanaged):
   // CHECK-NEXT: [[SELF_COPY:%.*]] = copy_value [[SELF]] : $HasUnmanaged
   // CHECK-NEXT: [[BORROWED_SELF_COPY:%.*]] = begin_borrow [[SELF_COPY]]
   // CHECK-NEXT: // function_ref
@@ -195,7 +195,7 @@
   }
 
   // CHECK-LABEL: sil hidden @_T015objc_properties016NonObjCClassWithD9CPropertyC11usePropertyyyF : $@convention(method) (@guaranteed NonObjCClassWithObjCProperty) -> () {
-  // CHECK: bb0([[ARG:%.*]] : $NonObjCClassWithObjCProperty):
+  // CHECK: bb0([[ARG:%.*]] : @guaranteed $NonObjCClassWithObjCProperty):
   // CHECK: [[MATERIALIZE_FOR_SET:%.*]] = class_method [[ARG]] : $NonObjCClassWithObjCProperty, #NonObjCClassWithObjCProperty.property!materializeForSet.1
   // CHECK: [[TUPLE:%.*]] = apply [[MATERIALIZE_FOR_SET]]({{.*}}, {{.*}}, [[ARG]])
   // CHECK: [[RAW_POINTER:%.*]] = tuple_extract [[TUPLE]] : $(Builtin.RawPointer, Optional<Builtin.RawPointer>), 0
@@ -248,3 +248,11 @@
 // CHECK-LABEL: sil hidden @_T015objc_properties15HasLazyPropertyC6windowSo8NSObjectCSgvg : $@convention(method) (@guaranteed HasLazyProperty) -> @owned Optional<NSObject> {
 // CHECK: class_method %0 : $HasLazyProperty, #HasLazyProperty.instanceMethod!1 : (HasLazyProperty) -> () -> NSObject?
 // CHECK: return
+
+//   The way we import this setter splits the name into the parameter list,
+//   which can cause fits for SILGenApply the way it's currently implemented.
+// CHECK-LABEL: sil hidden @_T015objc_properties26testPropSetWithPreposition
+func testPropSetWithPreposition(object: ObjectWithSplitProperty?) {
+  // CHECK: #ObjectWithSplitProperty.flagForSomething!setter.1.foreign : (ObjectWithSplitProperty) -> (Bool) -> (), $@convention(objc_method) ({{Bool|ObjCBool}}, ObjectWithSplitProperty) -> ()
+  object?.flagForSomething = false
+}
diff --git a/test/SILGen/objc_selector.swift b/test/SILGen/objc_selector.swift
index 5aaed94..b71459d 100644
--- a/test/SILGen/objc_selector.swift
+++ b/test/SILGen/objc_selector.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-sil -sdk %S/Inputs -I %S/Inputs -enable-source-import %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-sil -sdk %S/Inputs -I %S/Inputs -enable-source-import %s | %FileCheck %s
 
 // REQUIRES: objc_interop
 
diff --git a/test/SILGen/objc_subscript.swift b/test/SILGen/objc_subscript.swift
index 60bae15..2bb11c5 100644
--- a/test/SILGen/objc_subscript.swift
+++ b/test/SILGen/objc_subscript.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend %s -emit-silgen -emit-verbose-sil -disable-objc-attr-requires-foundation-module | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership %s -emit-silgen -emit-verbose-sil -disable-objc-attr-requires-foundation-module | %FileCheck %s
 
 // REQUIRES: objc_interop
 
diff --git a/test/SILGen/objc_super.swift b/test/SILGen/objc_super.swift
index c86ca7f..a95b11c 100644
--- a/test/SILGen/objc_super.swift
+++ b/test/SILGen/objc_super.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -emit-silgen | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -emit-silgen | %FileCheck %s
 
 // REQUIRES: objc_interop
 
diff --git a/test/SILGen/property_abstraction.swift b/test/SILGen/property_abstraction.swift
index 9aefe3f..943313e 100644
--- a/test/SILGen/property_abstraction.swift
+++ b/test/SILGen/property_abstraction.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen %s | %FileCheck %s
 
 struct Int {
   mutating func foo() {}
@@ -11,7 +11,7 @@
 }
 
 // CHECK-LABEL: sil hidden @_T020property_abstraction4getF{{[_0-9a-zA-Z]*}}Foo{{.*}}F : $@convention(thin) (@owned Foo<Int, Int>) -> @owned @callee_owned (Int) -> Int {
-// CHECK:       bb0([[X_ORIG:%.*]] : $Foo<Int, Int>):
+// CHECK:       bb0([[X_ORIG:%.*]] : @owned $Foo<Int, Int>):
 // CHECK:         [[BORROWED_X_ORIG:%.*]] = begin_borrow [[X_ORIG]] : $Foo<Int, Int>
 // CHECK:         [[F_ORIG:%.*]] = struct_extract [[BORROWED_X_ORIG]] : $Foo<Int, Int>, #Foo.f
 // CHECK:         [[F_ORIG_COPY:%.*]] = copy_value [[F_ORIG]]
@@ -37,7 +37,7 @@
 func inOutFunc(_ f: inout ((Int) -> Int)) { }
 
 // CHECK-LABEL: sil hidden @_T020property_abstraction6inOutF{{[_0-9a-zA-Z]*}}F : 
-// CHECK: bb0([[ARG:%.*]] : $Foo<Int, Int>):
+// CHECK: bb0([[ARG:%.*]] : @owned $Foo<Int, Int>):
 // CHECK:   [[XBOX:%.*]] = alloc_box ${ var Foo<Int, Int> }, var, name "x"
 // CHECK:   [[XBOX_PB:%.*]] = project_box [[XBOX]] : ${ var Foo<Int, Int> }, 0
 // CHECK:   [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
@@ -83,7 +83,7 @@
 }
 
 // CHECK-LABEL: sil hidden @_T020property_abstraction34getAddressOnlyReabstractedProperty{{[_0-9a-zA-Z]*}}F : $@convention(thin) (@in AddressOnlyLet<Int>) -> @owned @callee_owned (Int) -> Int
-// CHECK: bb0([[ARG:%.*]] : $*AddressOnlyLet<Int>):
+// CHECK: bb0([[ARG:%.*]] : @trivial $*AddressOnlyLet<Int>):
 // CHECK:   [[CLOSURE_ADDR:%.*]] = struct_element_addr {{%.*}} : $*AddressOnlyLet<Int>, #AddressOnlyLet.f
 // CHECK:   [[CLOSURE_ORIG:%.*]] = load [copy] [[CLOSURE_ADDR]]
 // CHECK:   [[REABSTRACT:%.*]] = function_ref
@@ -139,7 +139,7 @@
   factory.builder = { return MyClass() }
 }
 // CHECK: sil hidden @_T020property_abstraction10setBuilder{{[_0-9a-zA-Z]*}}F : $@convention(thin) <F where F : Factory, F.Product == MyClass> (@inout F) -> ()
-// CHECK: bb0(%0 : $*F):
+// CHECK: bb0(%0 : @trivial $*F):
 // CHECK:   [[SETTER:%.*]] = witness_method $F, #Factory.builder!setter.1
 // CHECK:   [[F0:%.*]] = function_ref @_T020property_abstraction10setBuilder{{[_0-9a-zA-Z]*}} : $@convention(thin) () -> @owned MyClass
 // CHECK:   [[F1:%.*]] = thin_to_thick_function [[F0]]
diff --git a/test/SILGen/rethrows.swift b/test/SILGen/rethrows.swift
index f99812b..671d37d 100644
--- a/test/SILGen/rethrows.swift
+++ b/test/SILGen/rethrows.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-sil -verify %s | %FileCheck %s
 
 @discardableResult
 func rethrower(_ fn: () throws -> Int) rethrows -> Int {
diff --git a/test/SILGen/unmanaged.swift b/test/SILGen/unmanaged.swift
index 0993a01..684dd2d 100644
--- a/test/SILGen/unmanaged.swift
+++ b/test/SILGen/unmanaged.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-sil %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-sil %s | %FileCheck %s
 
 class C {}
 
diff --git a/test/SILGen/unreachable_code.swift b/test/SILGen/unreachable_code.swift
index c4c7333..3048d71 100644
--- a/test/SILGen/unreachable_code.swift
+++ b/test/SILGen/unreachable_code.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-sil %s -o /dev/null -verify
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-sil %s -o /dev/null -verify
 
 func testUnreachableAfterReturn() -> Int {
   var x: Int = 3
diff --git a/test/SILGen/vtable_thunks_reabstraction.swift b/test/SILGen/vtable_thunks_reabstraction.swift
index d53c519..4b368f1 100644
--- a/test/SILGen/vtable_thunks_reabstraction.swift
+++ b/test/SILGen/vtable_thunks_reabstraction.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen %s | %FileCheck %s
 
 struct S {}
 class B {}
diff --git a/test/SILGen/vtables.swift b/test/SILGen/vtables.swift
index a53e97b..20ef3ed 100644
--- a/test/SILGen/vtables.swift
+++ b/test/SILGen/vtables.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen %s | %FileCheck %s
 
 // Test for compilation order independence
 class C : B {
diff --git a/test/SILGen/vtables_objc.swift b/test/SILGen/vtables_objc.swift
index 010b2e7..b1dc2d4 100644
--- a/test/SILGen/vtables_objc.swift
+++ b/test/SILGen/vtables_objc.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -sdk %S/Inputs -emit-silgen -I %S/Inputs -enable-source-import %s -disable-objc-attr-requires-foundation-module | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -sdk %S/Inputs -emit-silgen -I %S/Inputs -enable-source-import %s -disable-objc-attr-requires-foundation-module | %FileCheck %s
 
 // REQUIRES: objc_interop
 
diff --git a/test/SILGen/weak_multiple_modules.swift b/test/SILGen/weak_multiple_modules.swift
index 6f0593b..d95d334 100644
--- a/test/SILGen/weak_multiple_modules.swift
+++ b/test/SILGen/weak_multiple_modules.swift
@@ -1,6 +1,6 @@
 // RUN: %empty-directory(%t)
 // RUN: %target-swift-frontend -emit-module -emit-module-path=%t/weak_other.swiftmodule -module-name=weak_other %S/Inputs/weak_other.swift
-// RUN: %target-swift-frontend -I %t -emit-silgen %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
+// RUN: %target-swift-frontend -I %t -emit-silgen -enable-sil-ownership %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
 
 import weak_other
 
diff --git a/test/SILGen/witness-init-requirement-with-base-class-init.swift b/test/SILGen/witness-init-requirement-with-base-class-init.swift
index 38288d9..8fa46e4 100644
--- a/test/SILGen/witness-init-requirement-with-base-class-init.swift
+++ b/test/SILGen/witness-init-requirement-with-base-class-init.swift
@@ -1,5 +1,5 @@
-// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
-// RUN: %target-swift-frontend -emit-sil -verify %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-sil -verify %s
 
 protocol BestFriend: class {
   init()
diff --git a/test/SILGen/witnesses_canonical.swift b/test/SILGen/witnesses_canonical.swift
index 620c66d..8c1fca5 100644
--- a/test/SILGen/witnesses_canonical.swift
+++ b/test/SILGen/witnesses_canonical.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen %s | %FileCheck %s
 
 // rdar://problem/20714534 -- we need to canonicalize an associated type's
 // protocols when emitting witness method table for a conformance.
diff --git a/test/SILGen/witnesses_inheritance.swift b/test/SILGen/witnesses_inheritance.swift
index e478953..7c43bf8 100644
--- a/test/SILGen/witnesses_inheritance.swift
+++ b/test/SILGen/witnesses_inheritance.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen %s | %FileCheck %s
 
 protocol Fooable {
   func foo()
diff --git a/test/SILGen/witnesses_refinement.swift b/test/SILGen/witnesses_refinement.swift
index 2bbe412..907e6b4 100644
--- a/test/SILGen/witnesses_refinement.swift
+++ b/test/SILGen/witnesses_refinement.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen %s | %FileCheck %s
 
 protocol Saturable: Comparable {
   func saturated(max: Self) -> Self
diff --git a/test/SILGen/writeback.swift b/test/SILGen/writeback.swift
index 5bc17f3..1232bc6 100644
--- a/test/SILGen/writeback.swift
+++ b/test/SILGen/writeback.swift
@@ -1,4 +1,4 @@
-// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -emit-silgen %s | %FileCheck %s
+// RUN: %target-swift-frontend -enable-sil-ownership -Xllvm -sil-full-demangle -emit-silgen %s | %FileCheck %s
 
 struct Foo {
   mutating           // used to test writeback.
diff --git a/test/SILGen/writeback_conflict_diagnostics.swift b/test/SILGen/writeback_conflict_diagnostics.swift
index 6fb8dae..053daac 100644
--- a/test/SILGen/writeback_conflict_diagnostics.swift
+++ b/test/SILGen/writeback_conflict_diagnostics.swift
@@ -1,5 +1,5 @@
-// RUN: %target-swift-frontend %s -o /dev/null -emit-silgen -verify
-// RUN: %target-swift-frontend -enforce-exclusivity=checked %s -o /dev/null -emit-silgen -verify
+// RUN: %target-swift-frontend -enable-sil-ownership %s -o /dev/null -emit-silgen -verify
+// RUN: %target-swift-frontend -enable-sil-ownership -enforce-exclusivity=checked %s -o /dev/null -emit-silgen -verify
 
 struct MutatorStruct {
   mutating func f(_ x : inout MutatorStruct) {}
diff --git a/test/SILOptimizer/Inputs/keypaths_objc.h b/test/SILOptimizer/Inputs/keypaths_objc.h
new file mode 100644
index 0000000..f1a379b
--- /dev/null
+++ b/test/SILOptimizer/Inputs/keypaths_objc.h
@@ -0,0 +1,14 @@
+@import Foundation;
+
+@interface ObjCFoo
+
+@property(readonly) NSString *_Nonnull objcProp;
+
+@end
+
+
+@interface ObjCFoo (Extras)
+
+@property(readonly) NSString *_Nonnull objcExtraProp;
+
+@end
diff --git a/test/SILOptimizer/bridged_casts_folding.swift b/test/SILOptimizer/bridged_casts_folding.swift
index 25f5f12..ccd0ab6 100644
--- a/test/SILOptimizer/bridged_casts_folding.swift
+++ b/test/SILOptimizer/bridged_casts_folding.swift
@@ -2,9 +2,6 @@
 
 // REQUIRES: objc_interop
 
-// FIXME: https://bugs.swift.org/browse/SR-2808
-// XFAIL: resilient_stdlib
-
 // Check that casts between bridged types are replaced by more 
 // efficient code sequences.
 // 
diff --git a/test/SILOptimizer/cast_folding_no_bridging.sil b/test/SILOptimizer/cast_folding_no_bridging.sil
index 47dffe2..88c00cf 100644
--- a/test/SILOptimizer/cast_folding_no_bridging.sil
+++ b/test/SILOptimizer/cast_folding_no_bridging.sil
@@ -1,9 +1,6 @@
 // RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -O -emit-sil %s | %FileCheck %s
 // REQUIRES: objc_interop
 
-// FIXME: https://bugs.swift.org/browse/SR-2808
-// XFAIL: resilient_stdlib
-
 // We want to check that casts between two types which are both Swift types or
 // both are ObjC types are not optimized by the cast optimizer into casts
 // to/from ObjC.
diff --git a/test/SILOptimizer/dead_func_objc_extension_keypath.swift b/test/SILOptimizer/dead_func_objc_extension_keypath.swift
new file mode 100644
index 0000000..ca04f4c
--- /dev/null
+++ b/test/SILOptimizer/dead_func_objc_extension_keypath.swift
@@ -0,0 +1,7 @@
+// RUN: %target-swift-frontend %s -O -emit-sil -import-objc-header %S/Inputs/keypaths_objc.h
+// REQUIRES: objc_interop
+
+import Foundation
+public func test_nocrash_rdar34913689() {
+  _ = \ObjCFoo.objcExtraProp
+}
diff --git a/test/SILOptimizer/globalopt-iter.sil b/test/SILOptimizer/globalopt-iter.sil
new file mode 100644
index 0000000..1be24b1
--- /dev/null
+++ b/test/SILOptimizer/globalopt-iter.sil
@@ -0,0 +1,22 @@
+// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -global-opt | %FileCheck %s
+
+
+import Builtin
+import Swift
+class B { }
+class E : B { }
+
+// CHECK: sil @patatino : $@convention(thin) () -> () {
+// CHECK: bb0:
+// CHECK:  %0 = global_value @patatinoTv_ : $B             // user: %1
+// CHECK:  strong_retain %0 : $B                           // id: %1
+// CHECK: %2 = tuple ()                                   // user: %3
+// CHECK: return %2 : $()                                 // id: %3
+// CHECK: }
+
+sil @patatino : $@convention(thin) () -> () {
+  %1 = alloc_ref [stack] $B
+  dealloc_ref [stack] %1 : $B
+  %45 = tuple ()
+  return %45 : $()
+}
diff --git a/test/SILOptimizer/inliner_coldblocks.sil b/test/SILOptimizer/inliner_coldblocks.sil
index a627c37..18ec8a5 100644
--- a/test/SILOptimizer/inliner_coldblocks.sil
+++ b/test/SILOptimizer/inliner_coldblocks.sil
@@ -2,9 +2,12 @@
 // RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -inline -sil-remarks=sil-inliner -o %t.sil 2>&1 | %FileCheck -check-prefix=REMARKS_PASSED %s
 // RUN: %FileCheck %s < %t.sil
 // RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -inline -sil-remarks-missed=sil-inliner -o /dev/null 2>&1 | %FileCheck -check-prefix=REMARKS_MISSED %s
+// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -inline -save-optimization-record-path %t.yaml -o /dev/null 2>&1 | %FileCheck -allow-empty -check-prefix=NO_REMARKS %s
+// RUN: %FileCheck -check-prefix=YAML %s < %t.yaml
 
 // REMARKS_PASSED-NOT: remark:
 // REMARKS_MISSED-NOT: remark:
+// NO_REMARKS-NOT: remark:
 
 sil_stage canonical
 
@@ -190,7 +193,33 @@
   %c30 = builtin "assert_configuration"() : $Builtin.Int32
 
   %f = function_ref @update_global: $@convention(thin) () -> ()
-  // REMARKS_PASSED: inliner_coldblocks.sil:194:3: remark: update_global inlined into regular_large_callee (cost = {{.*}}, benefit = {{.*}})
+  // REMARKS_PASSED: inliner_coldblocks.sil:223:3: remark: update_global inlined into regular_large_callee (cost = {{.*}}, benefit = {{.*}})
+  // YAML:      --- !Passed
+  // YAML-NEXT: Pass:            sil-inliner
+  // YAML-NEXT: Name:            Inlined
+  // YAML-NEXT: DebugLoc:
+  // YAML-NEXT:   File:            {{.*}}inliner_coldblocks.sil
+  // YAML-NEXT:   Line:            223
+  // YAML-NEXT:   Column:          3
+  // YAML-NEXT: Function:        regular_large_callee
+  // YAML-NEXT: Args:
+  // YAML-NEXT:   - Callee:          update_global
+  // YAML-NEXT:     DebugLoc:
+  // YAML-NEXT:       File:            {{.*}}inliner_coldblocks.sil
+  // YAML-NEXT:       Line:            20
+  // YAML-NEXT:       Column:          6
+  // YAML-NEXT:   - String:          ' inlined into '
+  // YAML-NEXT:   - Caller:          regular_large_callee
+  // YAML-NEXT:     DebugLoc:
+  // YAML-NEXT:       File:            {{.*}}inliner_coldblocks.sil
+  // YAML-NEXT:       Line:            162
+  // YAML-NEXT:       Column:          6
+  // YAML-NEXT:   - String:          ' (cost = '
+  // YAML-NEXT:   - Cost:            '{{.*}}'
+  // YAML-NEXT:   - String:          ', benefit = '
+  // YAML-NEXT:   - Benefit:         '{{.*}}'
+  // YAML-NEXT:   - String:          ')'
+  // YAML-NEXT: ...
   apply %f() : $@convention(thin) () -> ()
 
   %r = tuple ()
@@ -204,7 +233,22 @@
 sil @dont_inline_regular_large_callee : $@convention(thin) () -> () {
 bb0:
   %f = function_ref @regular_large_callee : $@convention(thin) () -> ()
-  // REMARKS_MISSED: inliner_coldblocks.sil:208:8: remark: Not profitable to inline (cost = {{.*}}, benefit = {{.*}})
+  // REMARKS_MISSED: inliner_coldblocks.sil:252:8: remark: Not profitable to inline (cost = {{.*}}, benefit = {{.*}})
+  // YAML:      --- !Missed
+  // YAML-NEXT: Pass:            sil-inliner
+  // YAML-NEXT: Name:            NoInlinedCost
+  // YAML-NEXT: DebugLoc:
+  // YAML-NEXT:   File:            {{.*}}inliner_coldblocks.sil
+  // YAML-NEXT:   Line:            252
+  // YAML-NEXT:   Column:          8
+  // YAML-NEXT: Function:        dont_inline_regular_large_callee
+  // YAML-NEXT: Args:
+  // YAML-NEXT:   - String:          'Not profitable to inline (cost = '
+  // YAML-NEXT:   - Cost:            '{{.*}}'
+  // YAML-NEXT:   - String:          ', benefit = '
+  // YAML-NEXT:   - Benefit:         '{{.*}}'
+  // YAML-NEXT:   - String:          ')'
+  // YAML-NEXT: ...
   %a = apply %f() : $@convention(thin) () -> ()
   %r = tuple ()
   return %r : $()
diff --git a/test/SILOptimizer/ownership_model_eliminator.sil b/test/SILOptimizer/ownership_model_eliminator.sil
index 3d7fefd..acd3d16 100644
--- a/test/SILOptimizer/ownership_model_eliminator.sil
+++ b/test/SILOptimizer/ownership_model_eliminator.sil
@@ -229,3 +229,54 @@
   %9999 = tuple()
   return %9999 : $()
 }
+
+class TestArrayStorage {
+  @sil_stored var count: Builtin.Int32
+  init()
+}
+
+struct TestArray {
+  var storage : TestArrayStorage
+}
+
+struct TestArray2 {
+  var storage : TestArrayStorage
+  var someValue : Builtin.Int32
+  var storage2 : TestArrayStorage
+}
+
+// CHECK-LABEL: sil @test_destructure_struct_tuple : $@convention(thin) (@owned (Builtin.NativeObject, Builtin.Int32), @owned TestArray2) -> @owned (Builtin.NativeObject, Builtin.Int32, TestArrayStorage, Builtin.Int32, TestArrayStorage) {
+// CHECK: bb0([[TUPLE:%.*]] : $(Builtin.NativeObject, Builtin.Int32), [[STRUCT:%.*]] : $TestArray2):
+// CHECK:   [[TUP_ELT_0:%.*]] = tuple_extract [[TUPLE]] : $(Builtin.NativeObject, Builtin.Int32), 0
+// CHECK:   [[TUP_ELT_1:%.*]] = tuple_extract [[TUPLE]] : $(Builtin.NativeObject, Builtin.Int32), 1
+// CHECK:   [[STRUCT_FIELD_0:%.*]] = struct_extract [[STRUCT]] : $TestArray2, #TestArray2.storage
+// CHECK:   [[STRUCT_FIELD_1:%.*]] = struct_extract [[STRUCT]] : $TestArray2, #TestArray2.someValue
+// CHECK:   [[STRUCT_FIELD_2:%.*]] = struct_extract [[STRUCT]] : $TestArray2, #TestArray2.storage2
+// CHECK:   [[RESULT:%.*]] = tuple ([[TUP_ELT_0]] : {{.*}}, [[TUP_ELT_1]] : {{.*}}, [[STRUCT_FIELD_0]] : {{.*}}, [[STRUCT_FIELD_1]] : {{.*}}, [[STRUCT_FIELD_2]] : {{.*}})
+// CHECK:   return [[RESULT]]
+// CHECK: } // end sil function 'test_destructure_struct_tuple'
+sil @test_destructure_struct_tuple : $@convention(thin) (@owned (Builtin.NativeObject, Builtin.Int32), @owned TestArray2) -> @owned (Builtin.NativeObject, Builtin.Int32, TestArrayStorage, Builtin.Int32, TestArrayStorage) {
+bb0(%0 : @owned $(Builtin.NativeObject, Builtin.Int32), %1 : @owned $TestArray2):
+  (%2, %3) = destructure_tuple %0 : $(Builtin.NativeObject, Builtin.Int32)
+  (%4, %5, %6) = destructure_struct %1 : $TestArray2
+  %7 = tuple(%2 : $Builtin.NativeObject, %3 : $Builtin.Int32, %4 : $TestArrayStorage, %5 : $Builtin.Int32, %6 : $TestArrayStorage)
+  return %7 : $(Builtin.NativeObject, Builtin.Int32, TestArrayStorage, Builtin.Int32, TestArrayStorage)
+}
+
+struct EmptyStruct {}
+
+// We should completely eliminate the destructures here since the relevant
+// aggregates are empty.
+//
+// CHECK-LABEL: sil @test_empty_destructure : $@convention(thin) () -> () {
+// CHECK-NOT: destructure_struct
+// CHECK-NOT: destructure_tuple
+// CHECK: } // end sil function 'test_empty_destructure'
+sil @test_empty_destructure : $@convention(thin) () -> () {
+bb0:
+  %0 = struct $EmptyStruct()
+  () = destructure_struct %0 : $EmptyStruct
+  %1 = tuple()
+  () = destructure_tuple %1 : $()
+  return %1 : $()
+}
diff --git a/test/SILOptimizer/predictable_memopt.sil b/test/SILOptimizer/predictable_memopt.sil
index f798389..4e2ccdf 100644
--- a/test/SILOptimizer/predictable_memopt.sil
+++ b/test/SILOptimizer/predictable_memopt.sil
@@ -327,7 +327,7 @@
   %9 = apply %f() : $@convention(thin) () -> @owned SomeClass
   // CHECK: [[CVAL:%[0-9]+]] = apply
 
-  assign %9 to %3 : $*SomeClass
+  store %9 to %3 : $*SomeClass
   destroy_addr %3 : $*SomeClass
   dealloc_stack %3 : $*SomeClass
   %15 = tuple ()
diff --git a/test/SILOptimizer/prespecialize.swift b/test/SILOptimizer/prespecialize.swift
index b8d0c00..bddb2b9 100644
--- a/test/SILOptimizer/prespecialize.swift
+++ b/test/SILOptimizer/prespecialize.swift
@@ -2,9 +2,6 @@
 
 // REQUIRES: optimized_stdlib
 
-// FIXME: https://bugs.swift.org/browse/SR-2808
-// XFAIL: resilient_stdlib
-
 // Check that pre-specialization works at -Onone.
 // This test requires the standard library to be compiled with pre-specializations!
 
diff --git a/test/Sema/diag_deprecated_iuo.swift b/test/Sema/diag_deprecated_iuo.swift
new file mode 100644
index 0000000..6fc6525
--- /dev/null
+++ b/test/Sema/diag_deprecated_iuo.swift
@@ -0,0 +1,45 @@
+// RUN: %target-typecheck-verify-swift
+
+let _: ImplicitlyUnwrappedOptional<Int> = 1 // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{8-36=}}{{39-39=!}}{{39-40=}}
+let _: ImplicitlyUnwrappedOptional = 1 // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated}}
+
+extension ImplicitlyUnwrappedOptional {} // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated}}
+
+func function(
+  _: ImplicitlyUnwrappedOptional<Int> // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{6-34=}}{{37-37=!}}{{37-38=}}
+) -> ImplicitlyUnwrappedOptional<Int> { // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{6-34=}}{{37-37=!}}{{37-38=}}
+  return 1
+}
+
+func genericFunction<T>(
+  iuo: ImplicitlyUnwrappedOptional<T> // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{8-36=}}{{37-37=!}}{{37-38=}}
+) -> ImplicitlyUnwrappedOptional<T> { // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{6-34=}}{{35-35=!}}{{35-36=}}
+  return iuo
+}
+
+protocol P {
+  associatedtype T
+  associatedtype U
+}
+
+struct S : P {
+  typealias T = ImplicitlyUnwrappedOptional<Int> // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated}}
+  typealias U = Optional<ImplicitlyUnwrappedOptional<Int>> // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated}}
+
+  subscript (
+    index: ImplicitlyUnwrappedOptional<Int> // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{12-40=}}{{43-43=!}}{{43-44=}}
+  )     -> ImplicitlyUnwrappedOptional<Int> { // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{12-40=}}{{43-43=!}}{{43-44=}}
+    return index
+  }
+}
+
+func generic<T : P>(_: T) where T.T == ImplicitlyUnwrappedOptional<Int> { } // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated}}
+func genericOptIUO<T : P>(_: T) where T.U == Optional<ImplicitlyUnwrappedOptional<Int>> {} // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated}}
+
+func testClosure() -> Int {
+  return {
+    (i: ImplicitlyUnwrappedOptional<Int>) // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{9-37=}}{{40-40=!}}{{40-41=}}
+     -> ImplicitlyUnwrappedOptional<Int> in // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated}}
+    return i
+  }(1)
+}
diff --git a/test/Sema/diag_erroneous_iuo.swift b/test/Sema/diag_erroneous_iuo.swift
new file mode 100644
index 0000000..b2df2c2
--- /dev/null
+++ b/test/Sema/diag_erroneous_iuo.swift
@@ -0,0 +1,60 @@
+// RUN: %target-typecheck-verify-swift -swift-version 5
+
+let _: ImplicitlyUnwrappedOptional<Int> = 1 // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{8-36=}}{{39-39=!}}{{39-40=}}
+let _: ImplicitlyUnwrappedOptional = 1 // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' in unsupported; use an explicit type followed by '!'}}
+
+extension ImplicitlyUnwrappedOptional {} // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+
+func function(
+  _: ImplicitlyUnwrappedOptional<Int> // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{6-34=}}{{37-37=!}}{{37-38=}}
+) -> ImplicitlyUnwrappedOptional<Int> { // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{6-34=}}{{37-37=!}}{{37-38=}}
+  return 1
+}
+
+func genericFunction<T>(
+  iuo: ImplicitlyUnwrappedOptional<T> // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{8-36=}}{{37-37=!}}{{37-38=}}
+) -> ImplicitlyUnwrappedOptional<T> { // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{6-34=}}{{35-35=!}}{{35-36=}}
+  return iuo
+}
+
+protocol P {
+  associatedtype T
+  associatedtype U
+}
+
+struct S : P {
+  typealias T = ImplicitlyUnwrappedOptional<Int> // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+  typealias U = Optional<ImplicitlyUnwrappedOptional<Int>> // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+
+  subscript (
+    index: ImplicitlyUnwrappedOptional<Int> // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{12-40=}}{{43-43=!}}{{43-44=}}
+  )     -> ImplicitlyUnwrappedOptional<Int> { // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{12-40=}}{{43-43=!}}{{43-44=}}
+    return index
+  }
+}
+
+func generic<T : P>(_: T) where T.T == ImplicitlyUnwrappedOptional<Int> { } // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+func genericOptIUO<T : P>(_: T) where T.U == Optional<ImplicitlyUnwrappedOptional<Int>> {} // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+
+func testClosure() -> Int {
+  return {
+    (i: ImplicitlyUnwrappedOptional<Int>) // expected-error {{the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name}}{{9-37=}}{{40-40=!}}{{40-41=}}
+     -> ImplicitlyUnwrappedOptional<Int> in // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+    return i
+  }(1)
+}
+
+_ = Array<Int!>() // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+_ = [Int!]() // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+_ = Optional<Int!>(nil) // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+_ = Int!?(0) // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+_ = (
+  Int!, // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+  Float!, // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+  String! // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+)(1, 2.0, "3")
+
+struct Generic<T, U, C> {}
+_ = Generic<Int!, // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+            Float!, // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
+            String!>() // expected-error {{implicitly unwrapped optionals are only allowed at top level and as function results}}
diff --git a/test/Serialization/Inputs/def_basic.sil b/test/Serialization/Inputs/def_basic.sil
index e0559ff..8701d1b 100644
--- a/test/Serialization/Inputs/def_basic.sil
+++ b/test/Serialization/Inputs/def_basic.sil
@@ -1319,10 +1319,10 @@
 }
 
 
-// CHECK-LABEL: sil_witness_table public_external ConformingAssoc: AssocReqt module
+// CHECK-LABEL: sil_witness_table public_external [serialized] ConformingAssoc: AssocReqt module
 // CHECK: #AssocReqt.requiredMethod!1: {{.*}} : @_TTWV14witness_tables15ConformingAssocS_9AssocReqtS_FS1_14requiredMethodU_fRQPS1_FT_T_
 // CHECK: }
-sil_witness_table ConformingAssoc: AssocReqt module def_basic {
+sil_witness_table [serialized] ConformingAssoc: AssocReqt module def_basic {
   method #AssocReqt.requiredMethod!1: @_TTWV14witness_tables15ConformingAssocS_9AssocReqtS_FS1_14requiredMethodU_fRQPS1_FT_T_
 }
 
@@ -1345,18 +1345,18 @@
   func inheritedMethod()
 }
 
-// CHECK-LABEL: sil_witness_table public_external InheritedConformance: InheritedProtocol1 module
+// CHECK-LABEL: sil_witness_table public_external [serialized] InheritedConformance: InheritedProtocol1 module
 // CHECK: base_protocol AnyProtocol: InheritedConformance: AnyProtocol module
 // CHECK: }
-sil_witness_table InheritedConformance: InheritedProtocol1 module witness_tables {
+sil_witness_table [serialized] InheritedConformance: InheritedProtocol1 module witness_tables {
   base_protocol AnyProtocol: InheritedConformance: AnyProtocol module witness_tables
 }
 
-// CHECK-LABEL: sil_witness_table public_external InheritedConformance: AnyProtocol module
+// CHECK-LABEL: sil_witness_table public_external [serialized] InheritedConformance: AnyProtocol module
 // CHECK: associated_type AssocType: SomeAssoc
 // CHECK: associated_type_protocol (AssocWithReqt: AssocReqt): ConformingAssoc: AssocReqt module
 // CHECK: }
-sil_witness_table InheritedConformance: AnyProtocol module witness_tables {
+sil_witness_table [serialized] InheritedConformance: AnyProtocol module witness_tables {
   associated_type AssocType: SomeAssoc
   associated_type_protocol (AssocWithReqt: AssocReqt): ConformingAssoc: AssocReqt module witness_tables
 }
diff --git a/test/SourceKit/DocSupport/doc_swift_module.swift.response b/test/SourceKit/DocSupport/doc_swift_module.swift.response
index ea22b0d..4683135 100644
--- a/test/SourceKit/DocSupport/doc_swift_module.swift.response
+++ b/test/SourceKit/DocSupport/doc_swift_module.swift.response
@@ -1039,7 +1039,7 @@
     key.length: 4
   },
   {
-    key.kind: source.lang.swift.syntaxtype.identifier,
+    key.kind: source.lang.swift.syntaxtype.typeidentifier,
     key.offset: 1207,
     key.length: 7
   },
diff --git a/test/SourceKit/Refactoring/find-rename-ranges/rename-layer.expected b/test/SourceKit/Refactoring/find-rename-ranges/rename-layer.expected
new file mode 100644
index 0000000..c321138
--- /dev/null
+++ b/test/SourceKit/Refactoring/find-rename-ranges/rename-layer.expected
@@ -0,0 +1,8 @@
+source.edit.kind.active:
+  77:10-77:15 source.refactoring.range.kind.basename
+source.edit.kind.active:
+  80:27-80:32 source.refactoring.range.kind.basename
+source.edit.kind.active:
+  80:37-80:42 source.refactoring.range.kind.basename
+source.edit.kind.active:
+  80:45-80:50 source.refactoring.range.kind.basename
diff --git a/test/SourceKit/Refactoring/syntactic-rename.swift b/test/SourceKit/Refactoring/syntactic-rename.swift
index 447bc0a..4d870e6 100644
--- a/test/SourceKit/Refactoring/syntactic-rename.swift
+++ b/test/SourceKit/Refactoring/syntactic-rename.swift
@@ -74,6 +74,13 @@
 
 _ = Memberwise2(m: Memberwise1(x: 1), n: Memberwise1.init(x: 2))
 
+protocol Layer {
+  associatedtype Content
+}
+struct MultiPaneLayout<A: Layer, B: Layer>: Layer where A.Content == B.Content{
+  typealias Content = Int
+}
+
 // RUN: rm -rf %t.result && mkdir -p %t.result
 // RUN: %sourcekitd-test -req=syntactic-rename -rename-spec %S/syntactic-rename/x.in.json %s >> %t.result/x.expected
 // RUN: diff -u %S/syntactic-rename/x.expected %t.result/x.expected
@@ -94,6 +101,8 @@
 // RUN: not %sourcekitd-test -req=syntactic-rename -rename-spec %S/syntactic-rename/invalid.in.json %s
 // RUN: %sourcekitd-test -req=syntactic-rename -rename-spec %S/syntactic-rename/rename-memberwise.in.json %s >> %t.result/rename-memberwise.expected
 // RUN: diff -u %S/syntactic-rename/rename-memberwise.expected %t.result/rename-memberwise.expected
+// RUN: %sourcekitd-test -req=syntactic-rename -rename-spec %S/syntactic-rename/rename-layer.in.json %s >> %t.result/rename-layer.expected
+// RUN: diff -u %S/syntactic-rename/rename-layer.expected %t.result/rename-layer.expected
 
 // RUN: rm -rf %t.ranges && mkdir -p %t.ranges
 // RUN: %sourcekitd-test -req=find-rename-ranges -rename-spec %S/syntactic-rename/x.in.json %s >> %t.ranges/x.expected
@@ -112,3 +121,5 @@
 // RUN: diff -u %S/syntactic-rename/enum_case.expected %t.result/enum_case.expected
 // RUN: %sourcekitd-test -req=find-rename-ranges -rename-spec %S/syntactic-rename/rename-memberwise.in.json %s >> %t.ranges/rename-memberwise.expected
 // RUN: diff -u %S/find-rename-ranges/rename-memberwise.expected %t.ranges/rename-memberwise.expected
+// RUN: %sourcekitd-test -req=find-rename-ranges -rename-spec %S/syntactic-rename/rename-layer.in.json %s >> %t.ranges/rename-layer.expected
+// RUN: diff -u %S/find-rename-ranges/rename-layer.expected %t.ranges/rename-layer.expected
diff --git a/test/SourceKit/Refactoring/syntactic-rename/rename-layer.expected b/test/SourceKit/Refactoring/syntactic-rename/rename-layer.expected
new file mode 100644
index 0000000..8cfa08d
--- /dev/null
+++ b/test/SourceKit/Refactoring/syntactic-rename/rename-layer.expected
@@ -0,0 +1,8 @@
+source.edit.kind.active:
+  77:10-77:15 "NewLayer"
+source.edit.kind.active:
+  80:27-80:32 "NewLayer"
+source.edit.kind.active:
+  80:37-80:42 "NewLayer"
+source.edit.kind.active:
+  80:45-80:50 "NewLayer"
diff --git a/test/SourceKit/Refactoring/syntactic-rename/rename-layer.in.json b/test/SourceKit/Refactoring/syntactic-rename/rename-layer.in.json
new file mode 100644
index 0000000..d5a3305
--- /dev/null
+++ b/test/SourceKit/Refactoring/syntactic-rename/rename-layer.in.json
@@ -0,0 +1,30 @@
+[
+  {
+    "key.name": "Layer",
+    "key.newname": "NewLayer",
+    "key.is_function_like": 0,
+    "key.is_non_protocol_type": 0,
+    "key.locations": [
+      {
+        "key.line": 77,
+        "key.column": 10,
+        "key.nametype": source.syntacticrename.definition
+      },
+      {
+        "key.line": 80,
+        "key.column": 27,
+        "key.nametype": source.syntacticrename.reference
+      },
+      {
+        "key.line": 80,
+        "key.column": 37,
+        "key.nametype": source.syntacticrename.reference
+      },
+      {
+        "key.line": 80,
+        "key.column": 45,
+        "key.nametype": source.syntacticrename.reference
+      }
+    ]
+  }
+]
diff --git a/test/attr/attr_autoclosure.swift b/test/attr/attr_autoclosure.swift
index 4b85666..ecf4236 100644
--- a/test/attr/attr_autoclosure.swift
+++ b/test/attr/attr_autoclosure.swift
@@ -42,10 +42,10 @@
 }
 
 protocol P1 {
-  associatedtype Element // expected-note{{declared here}}
+  associatedtype Element
 }
 protocol P2 : P1 {
-  associatedtype Element // expected-warning{{redeclaration of associated type 'Element'}}
+  associatedtype Element
 }
 
 func overloadedEach<O: P1>(_ source: O, _ closure: @escaping () -> ()) {
diff --git a/test/attr/attr_escaping.swift b/test/attr/attr_escaping.swift
index 863fa30..4b7892a 100644
--- a/test/attr/attr_escaping.swift
+++ b/test/attr/attr_escaping.swift
@@ -121,7 +121,7 @@
   func setIUOClosure(_ fn: () -> Void) { // expected-note {{parameter 'fn' is implicitly non-escaping}} {{28-28=@escaping }}
     iuoClosure = fn // expected-error{{assigning non-escaping parameter 'fn' to an @escaping closure}}
   }
-  var iuoClosureExplicit: ImplicitlyUnwrappedOptional<() -> Void>
+  var iuoClosureExplicit: ImplicitlyUnwrappedOptional<() -> Void> // expected-warning {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}
   func setExplicitIUOClosure(_ fn: () -> Void) { // expected-note {{parameter 'fn' is implicitly non-escaping}} {{36-36=@escaping }}
     iuoClosureExplicit = fn // expected-error{{assigning non-escaping parameter 'fn' to an @escaping closure}}
   }
diff --git a/test/attr/attr_noescape.swift b/test/attr/attr_noescape.swift
index 6f29afa..4ed3535 100644
--- a/test/attr/attr_noescape.swift
+++ b/test/attr/attr_noescape.swift
@@ -183,10 +183,10 @@
 
 
 protocol P1 {
-  associatedtype Element // expected-note{{declared here}}
+  associatedtype Element
 }
 protocol P2 : P1 {
-  associatedtype Element // expected-warning{{redeclaration of associated type 'Element'}}
+  associatedtype Element
 }
 
 func overloadedEach<O: P1, T>(_ source: O, _ transform: @escaping (O.Element) -> (), _: T) {}
diff --git a/test/decl/class/override.swift b/test/decl/class/override.swift
index 565f865..77ce63f 100644
--- a/test/decl/class/override.swift
+++ b/test/decl/class/override.swift
@@ -221,8 +221,10 @@
   // expected-note@-1 {{remove '!' to make the parameter required}} {{36-37=}}
   // expected-note@-2 {{add parentheses to silence this warning}} {{27-27=(}} {{37-37=)}}
 
-  override func oneB(x: ImplicitlyUnwrappedOptional<AnyObject>) {}  // expected-warning {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'ImplicitlyUnwrappedOptional<AnyObject>'}}
-  // expected-note@-1 {{add parentheses to silence this warning}} {{25-25=(}} {{63-63=)}}
+  override func oneB(x: ImplicitlyUnwrappedOptional<AnyObject>) {}
+  // expected-warning@-1 {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name}}{{25-53=}}{{62-62=!}}{{62-63=}}
+  // expected-warning@-2 {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'ImplicitlyUnwrappedOptional<AnyObject>'}}
+  // expected-note@-3 {{add parentheses to silence this warning}} {{25-25=(}} {{63-63=)}}
 
   override func oneC(_: AnyObject!) {} // expected-warning {{overriding instance method parameter of type 'AnyObject' with implicitly unwrapped optional type 'AnyObject!'}}
   // expected-note@-1 {{remove '!' to make the parameter required}} {{34-35=}}
diff --git a/test/decl/ext/protocol.swift b/test/decl/ext/protocol.swift
index 73e3ac4..117a0b5 100644
--- a/test/decl/ext/protocol.swift
+++ b/test/decl/ext/protocol.swift
@@ -510,7 +510,7 @@
 protocol PConforms8 {
   associatedtype Assoc
 
-  func method() -> Assoc
+  func method() -> Assoc // expected-note{{requirement 'method()' declared here}}
   var property: Assoc { get }
   subscript (i: Assoc) -> Assoc { get }
 }
@@ -535,7 +535,10 @@
 }
 
 struct SConforms8c : PConforms8 { 
-  func method() -> String { return "" }
+  func method() -> String { return "" } // expected-warning{{instance method 'method()' nearly matches defaulted requirement 'method()' of protocol 'PConforms8'}}
+  // expected-note@-1{{candidate has non-matching type '() -> String' [with Assoc = Int]}}
+  // expected-note@-2{{move 'method()' to an extension to silence this warning}}
+  // expected-note@-3{{make 'method()' private to silence this warning}}
 }
 
 func testSConforms8c() {
diff --git a/test/decl/protocol/conforms/nscoding_availability_osx.swift b/test/decl/protocol/conforms/nscoding_availability_osx.swift
new file mode 100644
index 0000000..b9720cd
--- /dev/null
+++ b/test/decl/protocol/conforms/nscoding_availability_osx.swift
@@ -0,0 +1,22 @@
+// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -target x86_64-apple-macosx10.11 -verify
+
+// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -parse-as-library -swift-version 4 %s -target x86_64-apple-macosx10.11 -dump-ast 2> %t.ast
+// RUN: %FileCheck %s < %t.ast
+
+// REQUIRES: objc_interop
+// REQUIRES: OS=macosx
+
+import Foundation
+
+// Nested classes that aren't available in our deployment target.
+@available(OSX 10.12, *)
+class CodingI : NSObject, NSCoding {
+  required init(coder: NSCoder) { }
+  func encode(coder: NSCoder) { }
+}
+
+@available(OSX 10.12, *)
+class OuterCodingJ {
+  // CHECK-NOT: class_decl "NestedJ"{{.*}}@_staticInitializeObjCMetadata
+  class NestedJ : CodingI { }
+}
diff --git a/test/decl/protocol/indirectly_recursive_requirement.swift b/test/decl/protocol/indirectly_recursive_requirement.swift
index 90f0c7a..5c40a24 100644
--- a/test/decl/protocol/indirectly_recursive_requirement.swift
+++ b/test/decl/protocol/indirectly_recursive_requirement.swift
@@ -5,7 +5,7 @@
 }
 
 protocol _ForwardIndex  {
-  associatedtype Distance  = MyInt // expected-note{{declared here}}
+  associatedtype Distance  = MyInt
 }
 
 protocol ForwardIndex : _ForwardIndex {
@@ -19,7 +19,7 @@
 }
 
 protocol _RandomAccessIndex : _BidirectionalIndex {
-  associatedtype Distance // expected-warning{{redeclaration of associated type 'Distance}}
+  associatedtype Distance
 }
 
 protocol RandomAccessIndex 
diff --git a/test/multifile/class-layout/final-stored-property/library.swift b/test/multifile/class-layout/final-stored-property/Inputs/library.swift
similarity index 84%
rename from test/multifile/class-layout/final-stored-property/library.swift
rename to test/multifile/class-layout/final-stored-property/Inputs/library.swift
index 687a15f..2e67157 100644
--- a/test/multifile/class-layout/final-stored-property/library.swift
+++ b/test/multifile/class-layout/final-stored-property/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 final class Burger {
   let onions: Bool = true
   let cheeseSlices: Int = 0
diff --git a/test/multifile/class-layout/final-stored-property/main.swift b/test/multifile/class-layout/final-stored-property/main.swift
index afceade..c45e982 100644
--- a/test/multifile/class-layout/final-stored-property/main.swift
+++ b/test/multifile/class-layout/final-stored-property/main.swift
@@ -1,7 +1,5 @@
-// RUN: %target-build-swift %S/library.swift %S/main.swift
-// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
-
-// REQUIRES: executable_test
+// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
+// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
 
 func meltCheese(_ burger: Burger) -> Int {
   return burger.cheeseSlices
diff --git a/test/multifile/constant-struct-with-padding/Other.swift b/test/multifile/constant-struct-with-padding/Inputs/other.swift
similarity index 88%
rename from test/multifile/constant-struct-with-padding/Other.swift
rename to test/multifile/constant-struct-with-padding/Inputs/other.swift
index bbab75c..704be3b 100644
--- a/test/multifile/constant-struct-with-padding/Other.swift
+++ b/test/multifile/constant-struct-with-padding/Inputs/other.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 struct t {
   var a = false // (or e.g. var a: Int32 = 0)
   var b = 0.0 // (or e.g. var b: Int64 = 0)
diff --git a/test/multifile/constant-struct-with-padding/main.swift b/test/multifile/constant-struct-with-padding/main.swift
index 22bc152..3f7d5d9 100644
--- a/test/multifile/constant-struct-with-padding/main.swift
+++ b/test/multifile/constant-struct-with-padding/main.swift
@@ -1,5 +1,5 @@
 // RUN: %empty-directory(%t)
 
-// RUN: %target-build-swift -O -whole-module-optimization %S/main.swift %S/Other.swift
+// RUN: %target-build-swift -O -whole-module-optimization %S/main.swift %S/Inputs/other.swift
 
 print( g.a )
diff --git a/test/multifile/constant-tuple-with-padding/Other.swift b/test/multifile/constant-tuple-with-padding/Inputs/other.swift
similarity index 60%
rename from test/multifile/constant-tuple-with-padding/Other.swift
rename to test/multifile/constant-tuple-with-padding/Inputs/other.swift
index dd0dd03..9b48c3d 100644
--- a/test/multifile/constant-tuple-with-padding/Other.swift
+++ b/test/multifile/constant-tuple-with-padding/Inputs/other.swift
@@ -1,3 +1 @@
-// RUN: true
-
 var g = (false, 0.0)
diff --git a/test/multifile/constant-tuple-with-padding/main.swift b/test/multifile/constant-tuple-with-padding/main.swift
index c05a46b..9eb64dd 100644
--- a/test/multifile/constant-tuple-with-padding/main.swift
+++ b/test/multifile/constant-tuple-with-padding/main.swift
@@ -1,5 +1,5 @@
 // RUN: %empty-directory(%t)
 
-// RUN: %target-build-swift -O -whole-module-optimization %S/main.swift %S/Other.swift
+// RUN: %target-build-swift -O -whole-module-optimization %S/main.swift %S/Inputs/other.swift
 
 print( g.0 )
diff --git a/test/multifile/error-type/imported/library.swift b/test/multifile/error-type/imported/Inputs/library.swift
similarity index 76%
rename from test/multifile/error-type/imported/library.swift
rename to test/multifile/error-type/imported/Inputs/library.swift
index e228152..f0955e2 100644
--- a/test/multifile/error-type/imported/library.swift
+++ b/test/multifile/error-type/imported/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 public func go() throws {
   throw AXError(0)
 }
diff --git a/test/multifile/error-type/imported/objc_enum_errortype.h b/test/multifile/error-type/imported/Inputs/objc_enum_errortype.h
similarity index 100%
rename from test/multifile/error-type/imported/objc_enum_errortype.h
rename to test/multifile/error-type/imported/Inputs/objc_enum_errortype.h
diff --git a/test/multifile/error-type/imported/main.swift b/test/multifile/error-type/imported/main.swift
index 29d20c1..e4a07bb 100644
--- a/test/multifile/error-type/imported/main.swift
+++ b/test/multifile/error-type/imported/main.swift
@@ -1,4 +1,4 @@
-// RUN: %target-build-swift -module-name objc_enum_errortype -emit-library %S/main.swift %S/library.swift -import-objc-header %S/objc_enum_errortype.h
+// RUN: %target-build-swift -module-name objc_enum_errortype -emit-library %S/main.swift %S/Inputs/library.swift -import-objc-header %S/Inputs/objc_enum_errortype.h
 
 // REQUIRES: objc_interop
 
diff --git a/test/multifile/error-type/one-module/library.swift b/test/multifile/error-type/one-module/Inputs/library.swift
similarity index 79%
rename from test/multifile/error-type/one-module/library.swift
rename to test/multifile/error-type/one-module/Inputs/library.swift
index 75d1068..2842df3 100644
--- a/test/multifile/error-type/one-module/library.swift
+++ b/test/multifile/error-type/one-module/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 enum NuclearMeltdown {
   case Critical
   case Mild
diff --git a/test/multifile/error-type/one-module/main.swift b/test/multifile/error-type/one-module/main.swift
index 383fe63..a7de192 100644
--- a/test/multifile/error-type/one-module/main.swift
+++ b/test/multifile/error-type/one-module/main.swift
@@ -1,8 +1,6 @@
 // Try with and without whole module optimization
 
-// RUN: %target-build-swift %S/library.swift %S/main.swift
-// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
-
-// REQUIRES: executable_test
+// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
+// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
 
 extension NuclearMeltdown : Error {}
diff --git a/test/multifile/error-type/two-modules/library.swift b/test/multifile/error-type/two-modules/Inputs/library.swift
similarity index 80%
rename from test/multifile/error-type/two-modules/library.swift
rename to test/multifile/error-type/two-modules/Inputs/library.swift
index 76cd46c..2f3a2dd 100644
--- a/test/multifile/error-type/two-modules/library.swift
+++ b/test/multifile/error-type/two-modules/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 public enum NuclearMeltdown {
   case Critical
   case Mild
diff --git a/test/multifile/error-type/two-modules/main.swift b/test/multifile/error-type/two-modules/main.swift
index 4a68233..3a2c36a 100644
--- a/test/multifile/error-type/two-modules/main.swift
+++ b/test/multifile/error-type/two-modules/main.swift
@@ -1,12 +1,10 @@
 // RUN: %empty-directory(%t)
 
 // RUN: %empty-directory(%t/linker)
-// RUN: %target-build-swift -emit-module -c %S/library.swift -o %t/linker/library.o
-// RUN: %target-build-swift -emit-library -c %S/library.swift -o %t/linker/library.o
+// RUN: %target-build-swift -emit-module -c %S/Inputs/library.swift -o %t/linker/library.o
+// RUN: %target-build-swift -emit-library -c %S/Inputs/library.swift -o %t/linker/library.o
 // RUN: %target-build-swift %S/main.swift %t/linker/library.o -I %t/linker/ -L %t/linker/ -o %t/linker/main
 
-// REQUIRES: executable_test
-
 import library
 
 extension NuclearMeltdown : Error {}
diff --git a/test/multifile/extensions/two-modules/library.swift b/test/multifile/extensions/two-modules/Inputs/library.swift
similarity index 86%
rename from test/multifile/extensions/two-modules/library.swift
rename to test/multifile/extensions/two-modules/Inputs/library.swift
index e9223e1..6cbaf24 100644
--- a/test/multifile/extensions/two-modules/library.swift
+++ b/test/multifile/extensions/two-modules/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 public struct Point {
   public let x: Int
   public let y: Int
diff --git a/test/multifile/extensions/two-modules/main.swift b/test/multifile/extensions/two-modules/main.swift
index 524cf20..4c9e90d 100644
--- a/test/multifile/extensions/two-modules/main.swift
+++ b/test/multifile/extensions/two-modules/main.swift
@@ -1,14 +1,12 @@
 // RUN: %empty-directory(%t)
 
 // RUN: mkdir -p %t/onone %t/wmo
-// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -module-name=library -emit-library %S/library.swift -o %t/onone/library.%target-dylib-extension
+// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -module-name=library -emit-library %S/Inputs/library.swift -o %t/onone/library.%target-dylib-extension
 // RUN: %target-build-swift %S/main.swift %t/onone/library.%target-dylib-extension -I %t/onone/ -o %t/onone/main
 
-// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -module-name=library -emit-library -O -wmo %S/library.swift -o %t/wmo/library.%target-dylib-extension
+// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -module-name=library -emit-library -O -wmo %S/Inputs/library.swift -o %t/wmo/library.%target-dylib-extension
 // RUN: %target-build-swift %S/main.swift %t/wmo/library.%target-dylib-extension -I %t/wmo/ -o %t/wmo/main
 
-// REQUIRES: executable_test
-
 import library
 
 extension Point {
diff --git a/test/multifile/imported-conformance/option-set/library.swift b/test/multifile/imported-conformance/option-set/Inputs/library.swift
similarity index 93%
rename from test/multifile/imported-conformance/option-set/library.swift
rename to test/multifile/imported-conformance/option-set/Inputs/library.swift
index d0894c2..158fc8e 100644
--- a/test/multifile/imported-conformance/option-set/library.swift
+++ b/test/multifile/imported-conformance/option-set/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 import Foundation
 
 @inline(__always)
diff --git a/test/multifile/imported-conformance/option-set/main.swift b/test/multifile/imported-conformance/option-set/main.swift
index fa06202..32db519 100644
--- a/test/multifile/imported-conformance/option-set/main.swift
+++ b/test/multifile/imported-conformance/option-set/main.swift
@@ -1,10 +1,9 @@
 // RUN: %empty-directory(%t)
 
 // RUN: %empty-directory(%t/linker)
-// RUN: %target-build-swift -emit-module -emit-library %S/library.swift -o %t/linker/liblibrary.%target-dylib-extension -emit-module-path %t/linker/library.swiftmodule -module-name library
+// RUN: %target-build-swift -emit-module -emit-library %S/Inputs/library.swift -o %t/linker/liblibrary.%target-dylib-extension -emit-module-path %t/linker/library.swiftmodule -module-name library
 // RUN: %target-build-swift %S/main.swift -I %t/linker/ -L %t/linker/ -llibrary -o %t/linker/main
 
-// REQUIRES: executable_test
 // REQUIRES: objc_interop
 
 import Foundation
diff --git a/test/multifile/synthesized-accessors/materialize-for-set-1/Inputs/counter.h b/test/multifile/synthesized-accessors/materialize-for-set-1/Inputs/counter.h
new file mode 100644
index 0000000..930dc7b
--- /dev/null
+++ b/test/multifile/synthesized-accessors/materialize-for-set-1/Inputs/counter.h
@@ -0,0 +1,5 @@
+#import <Foundation/Foundation.h>
+
+@interface Counter : NSObject
+@property(readwrite) int value;
+@end
diff --git a/test/multifile/synthesized-accessors/materialize-for-set-1/Inputs/library.swift b/test/multifile/synthesized-accessors/materialize-for-set-1/Inputs/library.swift
new file mode 100644
index 0000000..9211695
--- /dev/null
+++ b/test/multifile/synthesized-accessors/materialize-for-set-1/Inputs/library.swift
@@ -0,0 +1,12 @@
+import Foundation
+import CounterFramework
+
+public protocol CounterProtocol {
+  var value: Int32 { get set }
+}
+
+extension Counter : CounterProtocol {}
+
+open class MyCounter : Counter {
+  open override var value: Int32 { didSet { } }
+}
diff --git a/test/multifile/synthesized-accessors/materialize-for-set-1/Inputs/module.map b/test/multifile/synthesized-accessors/materialize-for-set-1/Inputs/module.map
new file mode 100644
index 0000000..ac68c70
--- /dev/null
+++ b/test/multifile/synthesized-accessors/materialize-for-set-1/Inputs/module.map
@@ -0,0 +1,4 @@
+module CounterFramework {
+  header "counter.h"
+  export *
+}
diff --git a/test/multifile/synthesized-accessors/materialize-for-set-1/main.swift b/test/multifile/synthesized-accessors/materialize-for-set-1/main.swift
new file mode 100644
index 0000000..7944043
--- /dev/null
+++ b/test/multifile/synthesized-accessors/materialize-for-set-1/main.swift
@@ -0,0 +1,17 @@
+// RUN: %empty-directory(%t)
+
+// RUN: mkdir -p %t/onone %t/wmo
+// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -I %S/Inputs/ -module-name=library %S/Inputs/library.swift
+// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/onone/ -emit-ir > /dev/null
+
+// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -I %S/Inputs/ -module-name=library -wmo %S/Inputs/library.swift
+// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/wmo/ -emit-ir > /dev/null
+
+// REQUIRES: objc_interop
+
+import Foundation
+import library
+
+class CustomCounter : MyCounter {
+  override var value: Int32 { didSet { } }
+}
diff --git a/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/counter.h b/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/counter.h
new file mode 100644
index 0000000..930dc7b
--- /dev/null
+++ b/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/counter.h
@@ -0,0 +1,5 @@
+#import <Foundation/Foundation.h>
+
+@interface Counter : NSObject
+@property(readwrite) int value;
+@end
diff --git a/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/library1.swift b/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/library1.swift
new file mode 100644
index 0000000..7a2041c
--- /dev/null
+++ b/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/library1.swift
@@ -0,0 +1,8 @@
+import Foundation
+import CounterFramework
+
+public protocol CounterProtocol {
+  var value: Int32 { get set }
+}
+
+extension Counter : CounterProtocol {}
diff --git a/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/library2.swift b/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/library2.swift
new file mode 100644
index 0000000..7ac2f8c
--- /dev/null
+++ b/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/library2.swift
@@ -0,0 +1,6 @@
+import Foundation
+import CounterFramework
+
+open class MyCounter : Counter {
+  open override var value: Int32 { didSet { } }
+}
diff --git a/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/module.map b/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/module.map
new file mode 100644
index 0000000..ac68c70
--- /dev/null
+++ b/test/multifile/synthesized-accessors/materialize-for-set-2/Inputs/module.map
@@ -0,0 +1,4 @@
+module CounterFramework {
+  header "counter.h"
+  export *
+}
diff --git a/test/multifile/synthesized-accessors/materialize-for-set-2/main.swift b/test/multifile/synthesized-accessors/materialize-for-set-2/main.swift
new file mode 100644
index 0000000..a9d3ddc
--- /dev/null
+++ b/test/multifile/synthesized-accessors/materialize-for-set-2/main.swift
@@ -0,0 +1,17 @@
+// RUN: %empty-directory(%t)
+
+// RUN: mkdir -p %t/onone %t/wmo
+// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -I %S/Inputs/ -module-name=library %S/Inputs/library1.swift %S/Inputs/library2.swift
+// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/onone/ -emit-ir > /dev/null
+
+// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -I %S/Inputs/ -module-name=library -wmo %S/Inputs/library1.swift %S/Inputs/library2.swift
+// RUN: %target-build-swift %S/main.swift -I %S/Inputs/ -I %t/wmo/ -emit-ir > /dev/null
+
+// REQUIRES: objc_interop
+
+import Foundation
+import library
+
+class CustomCounter : MyCounter {
+  override var value: Int32 { didSet { } }
+}
diff --git a/test/multifile/synthesized-accessors/one-module-imported/library.swift b/test/multifile/synthesized-accessors/one-module-imported/Inputs/library.swift
similarity index 95%
rename from test/multifile/synthesized-accessors/one-module-imported/library.swift
rename to test/multifile/synthesized-accessors/one-module-imported/Inputs/library.swift
index 5ed3ccc..38b47a0 100644
--- a/test/multifile/synthesized-accessors/one-module-imported/library.swift
+++ b/test/multifile/synthesized-accessors/one-module-imported/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 import CoreGraphics
 
 // Case 1 - witness is imported accessor
diff --git a/test/multifile/synthesized-accessors/one-module-imported/main.swift b/test/multifile/synthesized-accessors/one-module-imported/main.swift
index 237e114..99b7ccf 100644
--- a/test/multifile/synthesized-accessors/one-module-imported/main.swift
+++ b/test/multifile/synthesized-accessors/one-module-imported/main.swift
@@ -1,9 +1,8 @@
 // Try with and without whole module optimization
 
-// RUN: %target-build-swift %S/library.swift %S/main.swift
-// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
+// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
+// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
 
-// REQUIRES: executable_test
 // REQUIRES: objc_interop
 
 import CoreGraphics
diff --git a/test/multifile/synthesized-accessors/one-module-internal/library.swift b/test/multifile/synthesized-accessors/one-module-internal/Inputs/library.swift
similarity index 96%
rename from test/multifile/synthesized-accessors/one-module-internal/library.swift
rename to test/multifile/synthesized-accessors/one-module-internal/Inputs/library.swift
index 9a9ab77..b0672e6 100644
--- a/test/multifile/synthesized-accessors/one-module-internal/library.swift
+++ b/test/multifile/synthesized-accessors/one-module-internal/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 struct FishAndChips {
   var costPounds: Float
   var costEuros: Float {
diff --git a/test/multifile/synthesized-accessors/one-module-internal/main.swift b/test/multifile/synthesized-accessors/one-module-internal/main.swift
index d9c16a5..1d54852 100644
--- a/test/multifile/synthesized-accessors/one-module-internal/main.swift
+++ b/test/multifile/synthesized-accessors/one-module-internal/main.swift
@@ -1,9 +1,7 @@
 // Try with and without whole module optimization
 
-// RUN: %target-build-swift %S/library.swift %S/main.swift
-// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
-
-// REQUIRES: executable_test
+// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
+// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
 
 protocol Takeaway {
   var costPounds: Float { get set }
diff --git a/test/multifile/synthesized-accessors/one-module-public/library.swift b/test/multifile/synthesized-accessors/one-module-public/Inputs/library.swift
similarity index 96%
rename from test/multifile/synthesized-accessors/one-module-public/library.swift
rename to test/multifile/synthesized-accessors/one-module-public/Inputs/library.swift
index c6c187c..094309c 100644
--- a/test/multifile/synthesized-accessors/one-module-public/library.swift
+++ b/test/multifile/synthesized-accessors/one-module-public/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 public struct FishAndChips {
   public var costPounds: Float
   public var costEuros: Float {
diff --git a/test/multifile/synthesized-accessors/one-module-public/main.swift b/test/multifile/synthesized-accessors/one-module-public/main.swift
index d9c16a5..1d54852 100644
--- a/test/multifile/synthesized-accessors/one-module-public/main.swift
+++ b/test/multifile/synthesized-accessors/one-module-public/main.swift
@@ -1,9 +1,7 @@
 // Try with and without whole module optimization
 
-// RUN: %target-build-swift %S/library.swift %S/main.swift
-// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
-
-// REQUIRES: executable_test
+// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
+// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
 
 protocol Takeaway {
   var costPounds: Float { get set }
diff --git a/test/multifile/synthesized-accessors/two-modules-imported/library.swift b/test/multifile/synthesized-accessors/two-modules-imported/Inputs/library.swift
similarity index 92%
rename from test/multifile/synthesized-accessors/two-modules-imported/library.swift
rename to test/multifile/synthesized-accessors/two-modules-imported/Inputs/library.swift
index c362f2d..c5b1255 100644
--- a/test/multifile/synthesized-accessors/two-modules-imported/library.swift
+++ b/test/multifile/synthesized-accessors/two-modules-imported/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 import CoreGraphics
 
 public protocol OtherPoint {
diff --git a/test/multifile/synthesized-accessors/two-modules-imported/main.swift b/test/multifile/synthesized-accessors/two-modules-imported/main.swift
index f6c391f..2167beb 100644
--- a/test/multifile/synthesized-accessors/two-modules-imported/main.swift
+++ b/test/multifile/synthesized-accessors/two-modules-imported/main.swift
@@ -1,9 +1,8 @@
 // Try with and without whole module optimization
 
-// RUN: %target-build-swift %S/library.swift %S/main.swift
-// RUN: %target-build-swift -whole-module-optimization %S/library.swift %S/main.swift
+// RUN: %target-build-swift %S/Inputs/library.swift %S/main.swift
+// RUN: %target-build-swift -whole-module-optimization %S/Inputs/library.swift %S/main.swift
 
-// REQUIRES: executable_test
 // REQUIRES: objc_interop
 
 import CoreGraphics
diff --git a/test/multifile/synthesized-accessors/two-modules/library.swift b/test/multifile/synthesized-accessors/two-modules/Inputs/library.swift
similarity index 97%
rename from test/multifile/synthesized-accessors/two-modules/library.swift
rename to test/multifile/synthesized-accessors/two-modules/Inputs/library.swift
index ebd0748..d1baac1 100644
--- a/test/multifile/synthesized-accessors/two-modules/library.swift
+++ b/test/multifile/synthesized-accessors/two-modules/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 #if _runtime(_ObjC)
 import Foundation
 #endif
diff --git a/test/multifile/synthesized-accessors/two-modules/main.swift b/test/multifile/synthesized-accessors/two-modules/main.swift
index 38cb615..cfe9089 100644
--- a/test/multifile/synthesized-accessors/two-modules/main.swift
+++ b/test/multifile/synthesized-accessors/two-modules/main.swift
@@ -1,14 +1,12 @@
 // RUN: %empty-directory(%t)
 
 // RUN: mkdir -p %t/onone %t/wmo
-// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -module-name=library -emit-library %S/library.swift -o %t/onone/library.%target-dylib-extension
+// RUN: %target-build-swift -emit-module -emit-module-path %t/onone/library.swiftmodule -module-name=library -emit-library %S/Inputs/library.swift -o %t/onone/library.%target-dylib-extension
 // RUN: %target-build-swift %S/main.swift %t/onone/library.%target-dylib-extension -I %t/onone/ -o %t/onone/main
 
-// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -module-name=library -emit-library -O -wmo %S/library.swift -o %t/wmo/library.%target-dylib-extension
+// RUN: %target-build-swift -emit-module -emit-module-path %t/wmo/library.swiftmodule -module-name=library -emit-library -O -wmo %S/Inputs/library.swift -o %t/wmo/library.%target-dylib-extension
 // RUN: %target-build-swift %S/main.swift %t/wmo/library.%target-dylib-extension -I %t/wmo/ -o %t/wmo/main
 
-// REQUIRES: executable_test
-
 import library
 
 protocol Takeaway {
diff --git a/test/multifile/typealias/one-module/library.swift b/test/multifile/typealias/one-module/Inputs/library.swift
similarity index 89%
rename from test/multifile/typealias/one-module/library.swift
rename to test/multifile/typealias/one-module/Inputs/library.swift
index 7785da5..756a569 100644
--- a/test/multifile/typealias/one-module/library.swift
+++ b/test/multifile/typealias/one-module/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 public enum Result<T, U>
 {
     case success(T)
diff --git a/test/multifile/typealias/one-module/main.swift b/test/multifile/typealias/one-module/main.swift
index 1adcd71..73ca7b4 100644
--- a/test/multifile/typealias/one-module/main.swift
+++ b/test/multifile/typealias/one-module/main.swift
@@ -1,9 +1,7 @@
 // RUN: %empty-directory(%t)
 
-// RUN: %target-build-swift %S/main.swift %S/library.swift
-// RUN: %target-build-swift -g %S/main.swift %S/library.swift
-
-// REQUIRES: executable_test
+// RUN: %target-build-swift %S/main.swift %S/Inputs/library.swift
+// RUN: %target-build-swift -g %S/main.swift %S/Inputs/library.swift
 
 func testFunction<T>(withCompletion completion: (Result<T, Error>) -> Void) { }
 testFunction { (result: GenericResult<Int>) in }
diff --git a/test/multifile/typealias/one-module/library.swift b/test/multifile/typealias/two-modules/Inputs/library.swift
similarity index 89%
copy from test/multifile/typealias/one-module/library.swift
copy to test/multifile/typealias/two-modules/Inputs/library.swift
index 7785da5..756a569 100644
--- a/test/multifile/typealias/one-module/library.swift
+++ b/test/multifile/typealias/two-modules/Inputs/library.swift
@@ -1,5 +1,3 @@
-// RUN: true
-
 public enum Result<T, U>
 {
     case success(T)
diff --git a/test/multifile/typealias/two-modules/library.swift b/test/multifile/typealias/two-modules/library.swift
deleted file mode 100644
index 7785da5..0000000
--- a/test/multifile/typealias/two-modules/library.swift
+++ /dev/null
@@ -1,9 +0,0 @@
-// RUN: true
-
-public enum Result<T, U>
-{
-    case success(T)
-    case failure(U)
-}
-
-public typealias GenericResult<T> = Result<T, Error>
diff --git a/test/multifile/typealias/two-modules/main.swift b/test/multifile/typealias/two-modules/main.swift
index 5d69887..bcab552 100644
--- a/test/multifile/typealias/two-modules/main.swift
+++ b/test/multifile/typealias/two-modules/main.swift
@@ -1,16 +1,14 @@
 // RUN: %empty-directory(%t)
 
 // RUN: %empty-directory(%t/linker)
-// RUN: %target-build-swift -emit-module -c %S/library.swift -o %t/linker/library.o
-// RUN: %target-build-swift -emit-library -c %S/library.swift -o %t/linker/library.o
+// RUN: %target-build-swift -emit-module -c %S/Inputs/library.swift -o %t/linker/library.o
+// RUN: %target-build-swift -emit-library -c %S/Inputs/library.swift -o %t/linker/library.o
 // RUN: %target-build-swift %S/main.swift %t/linker/library.o -I %t/linker/ -L %t/linker/ -o %t/linker/main
 
-// RUN: %target-build-swift -g -emit-module -c %S/library.swift -o %t/linker/library.o
-// RUN: %target-build-swift -g -emit-library -c %S/library.swift -o %t/linker/library.o
+// RUN: %target-build-swift -g -emit-module -c %S/Inputs/library.swift -o %t/linker/library.o
+// RUN: %target-build-swift -g -emit-library -c %S/Inputs/library.swift -o %t/linker/library.o
 // RUN: %target-build-swift -g %S/main.swift %t/linker/library.o -I %t/linker/ -L %t/linker/ -o %t/linker/main
 
-// REQUIRES: executable_test
-
 import library
 
 func testFunction<T>(withCompletion completion: (Result<T, Error>) -> Void) { }
diff --git a/test/stdlib/RangeTraps.swift b/test/stdlib/RangeTraps.swift
index 865f940..51bde98 100644
--- a/test/stdlib/RangeTraps.swift
+++ b/test/stdlib/RangeTraps.swift
@@ -16,8 +16,6 @@
 // RUN: %target-run %t/a.out_Debug
 // RUN: %target-run %t/a.out_Release
 // REQUIRES: executable_test
-// CountablePartialRangeFrom fails in resilient mode. <rdar://problem/31909976>
-// XFAIL: resilient_stdlib
 
 
 import StdlibUnittest
diff --git a/test/stmt/errors.swift b/test/stmt/errors.swift
index 02051ce..688f15e 100644
--- a/test/stmt/errors.swift
+++ b/test/stmt/errors.swift
@@ -2,8 +2,8 @@
 enum MSV : Error {
   case Foo, Bar, Baz
 
-  var domain: String { return "" }
-  var code: Int { return 0 }
+  var _domain: String { return "" }
+  var _code: Int { return 0 }
 }
 
 func a() {}
diff --git a/tools/sil-opt/SILOpt.cpp b/tools/sil-opt/SILOpt.cpp
index eac4a27..845fc1d 100644
--- a/tools/sil-opt/SILOpt.cpp
+++ b/tools/sil-opt/SILOpt.cpp
@@ -40,6 +40,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/YAMLTraits.h"
 #include <cstdio>
 using namespace swift;
 
@@ -230,6 +231,11 @@
              "the given regular expression"),
     cl::Hidden);
 
+static cl::opt<std::string>
+    RemarksFilename("save-optimization-record-path",
+                    cl::desc("YAML output filename for pass remarks"),
+                    cl::value_desc("filename"));
+
 static void runCommandLineSelectedPasses(SILModule *Module,
                                          irgen::IRGenModule *IRGenMod) {
   SILPassManager PM(Module, IRGenMod);
@@ -419,6 +425,21 @@
   if (CI.getSILModule())
     CI.getSILModule()->setSerializeSILAction([]{});
 
+  std::unique_ptr<llvm::raw_fd_ostream> OptRecordFile;
+  if (RemarksFilename != "") {
+    std::error_code EC;
+    OptRecordFile = llvm::make_unique<llvm::raw_fd_ostream>(
+        RemarksFilename, EC, llvm::sys::fs::F_None);
+    if (EC) {
+      llvm::errs() << EC.message() << '\n';
+      return 1;
+    }
+    CI.getSILModule()->setOptRecordStream(
+        llvm::make_unique<llvm::yaml::Output>(*OptRecordFile,
+                                              &CI.getSourceMgr()),
+        std::move(OptRecordFile));
+  }
+
   if (OptimizationGroup == OptGroup::Diagnostics) {
     runSILDiagnosticPasses(*CI.getSILModule());
   } else if (OptimizationGroup == OptGroup::Performance) {
diff --git a/utils/build-script-impl b/utils/build-script-impl
index 70f214c..ff0bbb2 100755
--- a/utils/build-script-impl
+++ b/utils/build-script-impl
@@ -3444,8 +3444,8 @@
           with_pushd "${host_install_destdir}" \
               call tar -c -z -f "${package_for_host}" "${TOOLCHAIN_PREFIX/#\/}"
         else
-            # tar on OS X doesn't support --owner/--group.
-            if [[ "$(uname -s)" == "Darwin" ]] ; then
+            # BSD tar doesn't support --owner/--group.
+            if [[ "$(uname -s)" == "Darwin" || "$(uname -s)" == "FreeBSD" ]] ; then
                 with_pushd "${host_install_destdir}" \
                     tar -c -z -f "${package_for_host}" "${host_install_prefix/#\/}"
             else
diff --git a/utils/sil-mode.el b/utils/sil-mode.el
index 70fb8e9..b57fefc 100644
--- a/utils/sil-mode.el
+++ b/utils/sil-mode.el
@@ -111,7 +111,8 @@
                   'words) . font-lock-keyword-face)
    ;; Metatypes
    `(,(regexp-opt '("metatype" "value_metatype"
-                    "existential_metatype" "init_existential_metatype")
+                    "existential_metatype" "init_existential_metatype"
+                    "objc_protocol")
                   'words) . font-lock-keyword-face)
    ;; Aggregate Types
    `(,(regexp-opt '("retain_value" "release_value_addr" "release_value"
diff --git a/utils/vim/syntax/sil.vim b/utils/vim/syntax/sil.vim
index b54e434..c5553e3 100644
--- a/utils/vim/syntax/sil.vim
+++ b/utils/vim/syntax/sil.vim
@@ -5,6 +5,33 @@
     finish
 endif
 
+syn keyword silStage skipwhite nextgroup=silStages
+      \ sil_stage
+syn keyword silStages
+      \ canonical
+      \ raw
+
+syn match silIdentifier skipwhite
+      \ /@\<[A-Za-z_0-9]\+\>/
+
+syn match silConvention skipwhite
+      \ /$\?@convention/
+syn region silConvention contained contains=silConventions
+      \ start="@convention(" end=")"
+syn keyword silConventions
+      \ block
+      \ c
+      \ method
+      \ objc_method
+      \ thick
+      \ thin
+      \ witness_method
+
+syn match silFunctionType skipwhite
+      \ /@\(\<autoreleased\>\|\<callee_guaranteed\>\|\<callee_owned\>\|\<error\>\|\<guaranteed\>\|\<in\>\|\<in_constant\>\|\<in_guaranteed\>\|\<inout\>\|\<inout_aliasable\>\|\<noescape\>\|\<out\>\|\<owned\>\)/
+syn match silMetatypeType skipwhite
+      \ /@\(\<thick\>\|\<thin\>\|\<objc\>\)/
+
 syn keyword swiftImport import skipwhite nextgroup=swiftImportModule
 syn match swiftImportModule /\<[A-Za-z_][A-Za-z_0-9]*\>/ contained nextgroup=swiftImportComponent
 syn match swiftImportComponent /\.\<[A-Za-z_][A-Za-z_0-9]*\>/ contained nextgroup=swiftImportComponent
@@ -67,7 +94,7 @@
 hi def link swiftImport Include
 hi def link swiftImportModule Title
 hi def link swiftImportComponent Identifier
-hi def link swiftApplyKeyword ModeMsg
+hi def link swiftApplyKeyword Statement
 hi def link swiftKeyword Statement
 hi def link swiftTypeDefinition Define
 hi def link swiftTypeName Type
@@ -97,4 +124,13 @@
 hi def link swiftLabel Label
 hi def link swiftNew Operator
 
+hi def link silStage Special
+hi def link silStages Type
+hi def link silConvention Special
+hi def link silConventionParameter Special
+hi def link silConventions Type
+hi def link silIdentifier Identifier
+hi def link silFunctionType Special
+hi def link silMetatypeType Special
+
 let b:current_syntax = "sil"
diff --git a/validation-test/Sema/type_checker_crashers_fixed/rdar28048391.swift b/validation-test/Sema/type_checker_crashers_fixed/rdar28048391.swift
index 5dc135f..224a6df 100644
--- a/validation-test/Sema/type_checker_crashers_fixed/rdar28048391.swift
+++ b/validation-test/Sema/type_checker_crashers_fixed/rdar28048391.swift
@@ -12,3 +12,4 @@
 }
 
 extension ImplicitlyUnwrappedOptional : rdar28048391 { }
+// expected-warning@-1 {{the spelling 'ImplicitlyUnwrappedOptional' is deprecated}}
diff --git a/validation-test/Sema/type_checker_perf/slow/rdar35213699.swift b/validation-test/Sema/type_checker_perf/slow/rdar35213699.swift
new file mode 100644
index 0000000..3f40370
--- /dev/null
+++ b/validation-test/Sema/type_checker_perf/slow/rdar35213699.swift
@@ -0,0 +1,8 @@
+// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
+// REQUIRES: tools-release,no_asserts
+
+func test() {
+  let x: UInt = 1 * 2 + 3 * 4 + 5 * 6 + 7 * 8 + 9 * 10 + 11 * 12 + 13 * 14
+  // expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
+}
+
diff --git a/validation-test/compiler_crashers_2_fixed/0075-rdar30248571.swift b/validation-test/compiler_crashers_2_fixed/0075-rdar30248571.swift
index e0d33be..967d912 100644
--- a/validation-test/compiler_crashers_2_fixed/0075-rdar30248571.swift
+++ b/validation-test/compiler_crashers_2_fixed/0075-rdar30248571.swift
@@ -1,5 +1,5 @@
 // RUN: %target-swift-frontend %s -typecheck
-// FIXME: %target-swift-frontend %s -emit-ir -- see https://github.com/apple/swift/pull/7414
+// RUN: %target-swift-frontend %s -emit-ir -o /dev/null
 
 protocol P {
   associatedtype A
diff --git a/validation-test/compiler_crashers_2_fixed/0128-rdar35088384.swift b/validation-test/compiler_crashers_2_fixed/0128-rdar35088384.swift
new file mode 100644
index 0000000..72fdd31
--- /dev/null
+++ b/validation-test/compiler_crashers_2_fixed/0128-rdar35088384.swift
@@ -0,0 +1,12 @@
+// RUN: %swift-target-frontend -typecheck -verify %s
+
+protocol Command {}
+
+struct A : Command {}
+struct B : Command {}
+
+// This used to crash in Xcode 9 GM, and fails with a diagnostic in more
+// recent swift-4.0-branch builds, because we incorrectly infer the type
+// of the array literal as [Any].
+
+let a = Array<Command.Type>([A.self, B.self])
diff --git a/validation-test/compiler_crashers_2_fixed/0129-rdar35019075.swift b/validation-test/compiler_crashers_2_fixed/0129-rdar35019075.swift
new file mode 100644
index 0000000..ae35eef
--- /dev/null
+++ b/validation-test/compiler_crashers_2_fixed/0129-rdar35019075.swift
@@ -0,0 +1,43 @@
+// RUN: not %target-swift-frontend %s -typecheck
+
+enum SortOrder {
+    case ascending
+    case equal
+    case descending
+}
+
+struct SortedArray<Element> {
+    var contents = [Element]()
+    let compare: (Element, Element) -> SortOrder
+
+    init(_ comparator: @escaping (Element, Element) -> SortOrder) {
+        compare = comparator
+    }
+
+    mutating func add(_ element: Element) {
+
+    }
+}
+
+extension SortedArray where Element: Comparable {
+    init() {
+        compare = { a, b in
+            if a < b { return .ascending }
+            else if a > b { return .descending }
+            else { return .equal }
+        }
+    }
+
+    init<S: Sequence>(_ sequence: S) where S.Iterator.Element == Element {
+        self.init()
+
+        for element in sequence {
+            add(element)
+        }
+    }
+}
+
+extension SortedArray: Sequence {
+    typealias Iterator = IndexingIterator
+
+}
diff --git a/validation-test/compiler_crashers/28803-swift-typebase-getdesugaredtype.swift b/validation-test/compiler_crashers_fixed/28803-swift-typebase-getdesugaredtype.swift
similarity index 87%
rename from validation-test/compiler_crashers/28803-swift-typebase-getdesugaredtype.swift
rename to validation-test/compiler_crashers_fixed/28803-swift-typebase-getdesugaredtype.swift
index 4511df4..4ae3193 100644
--- a/validation-test/compiler_crashers/28803-swift-typebase-getdesugaredtype.swift
+++ b/validation-test/compiler_crashers_fixed/28803-swift-typebase-getdesugaredtype.swift
@@ -5,6 +5,6 @@
 // See https://swift.org/LICENSE.txt for license information
 // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
 
-// RUN: not --crash %target-swift-frontend %s -emit-ir
+// RUN: not %target-swift-frontend %s -emit-ir
 protocol P{typealias a:Collection
 typealias a=(t:Self.a
diff --git a/validation-test/compiler_crashers/28819-formextensioninterfacetype-swift-type-swift-genericparamlist.swift b/validation-test/compiler_crashers_fixed/28819-formextensioninterfacetype-swift-type-swift-genericparamlist.swift
similarity index 87%
rename from validation-test/compiler_crashers/28819-formextensioninterfacetype-swift-type-swift-genericparamlist.swift
rename to validation-test/compiler_crashers_fixed/28819-formextensioninterfacetype-swift-type-swift-genericparamlist.swift
index 2b015fa..9d62d8f 100644
--- a/validation-test/compiler_crashers/28819-formextensioninterfacetype-swift-type-swift-genericparamlist.swift
+++ b/validation-test/compiler_crashers_fixed/28819-formextensioninterfacetype-swift-type-swift-genericparamlist.swift
@@ -5,5 +5,5 @@
 // See https://swift.org/LICENSE.txt for license information
 // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
 
-// RUN: not --crash %target-swift-frontend %s -emit-ir
+// RUN: not %target-swift-frontend %s -emit-ir
 class a<a{protocol b}extension a.b
diff --git a/validation-test/compiler_crashers/28830-formextensioninterfacetype-swift-type-swift-genericparamlist.swift b/validation-test/compiler_crashers_fixed/28830-formextensioninterfacetype-swift-type-swift-genericparamlist.swift
similarity index 87%
rename from validation-test/compiler_crashers/28830-formextensioninterfacetype-swift-type-swift-genericparamlist.swift
rename to validation-test/compiler_crashers_fixed/28830-formextensioninterfacetype-swift-type-swift-genericparamlist.swift
index aad1964..a9fbd25 100644
--- a/validation-test/compiler_crashers/28830-formextensioninterfacetype-swift-type-swift-genericparamlist.swift
+++ b/validation-test/compiler_crashers_fixed/28830-formextensioninterfacetype-swift-type-swift-genericparamlist.swift
@@ -5,5 +5,5 @@
 // See https://swift.org/LICENSE.txt for license information
 // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
 
-// RUN: not --crash %target-swift-frontend %s -emit-ir
+// RUN: not %target-swift-frontend %s -emit-ir
 protocol P{protocol a:P}extension P.a.a
diff --git a/validation-test/compiler_crashers/28846-swift-typebase-getdesugaredtype.swift b/validation-test/compiler_crashers_fixed/28846-swift-typebase-getdesugaredtype.swift
similarity index 87%
rename from validation-test/compiler_crashers/28846-swift-typebase-getdesugaredtype.swift
rename to validation-test/compiler_crashers_fixed/28846-swift-typebase-getdesugaredtype.swift
index 56eb011..c70c62f 100644
--- a/validation-test/compiler_crashers/28846-swift-typebase-getdesugaredtype.swift
+++ b/validation-test/compiler_crashers_fixed/28846-swift-typebase-getdesugaredtype.swift
@@ -5,5 +5,5 @@
 // See https://swift.org/LICENSE.txt for license information
 // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
 
-// RUN: not --crash %target-swift-frontend %s -emit-ir
+// RUN: not %target-swift-frontend %s -emit-ir
 protocol A{typealias a:A=a{}typealias a=Self.a
diff --git a/validation-test/compiler_crashers/28848-iscanonicaltypeincontext-result-builder.swift b/validation-test/compiler_crashers_fixed/28848-iscanonicaltypeincontext-result-builder.swift
similarity index 88%
rename from validation-test/compiler_crashers/28848-iscanonicaltypeincontext-result-builder.swift
rename to validation-test/compiler_crashers_fixed/28848-iscanonicaltypeincontext-result-builder.swift
index 72c53f2..504f8d5 100644
--- a/validation-test/compiler_crashers/28848-iscanonicaltypeincontext-result-builder.swift
+++ b/validation-test/compiler_crashers_fixed/28848-iscanonicaltypeincontext-result-builder.swift
@@ -6,5 +6,5 @@
 // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
 
 // REQUIRES: asserts
-// RUN: not --crash %target-swift-frontend %s -emit-ir
+// RUN: not %target-swift-frontend %s -emit-ir
 protocol P{typealias a{}func a:a.a{}class a{{}protocol 0
diff --git a/validation-test/compiler_crashers/28851-hasconformanceinsignature-inprotocol-getrequirementsignature-subjecttype-conform.swift b/validation-test/compiler_crashers_fixed/28851-hasconformanceinsignature-inprotocol-getrequirementsignature-subjecttype-conform.swift
similarity index 88%
rename from validation-test/compiler_crashers/28851-hasconformanceinsignature-inprotocol-getrequirementsignature-subjecttype-conform.swift
rename to validation-test/compiler_crashers_fixed/28851-hasconformanceinsignature-inprotocol-getrequirementsignature-subjecttype-conform.swift
index 0e26155..350c824 100644
--- a/validation-test/compiler_crashers/28851-hasconformanceinsignature-inprotocol-getrequirementsignature-subjecttype-conform.swift
+++ b/validation-test/compiler_crashers_fixed/28851-hasconformanceinsignature-inprotocol-getrequirementsignature-subjecttype-conform.swift
@@ -6,5 +6,5 @@
 // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
 
 // REQUIRES: asserts
-// RUN: not --crash %target-swift-frontend %s -emit-ir
+// RUN: not %target-swift-frontend %s -emit-ir
 protocol A:a{{}typealias a=a{}func a{}typealias a}class a:A{func a
diff --git a/validation-test/compiler_crashers/28864-bool-typesig-bool-extensionsig-unexpected-generic-ness-mismatch-on-conformance.swift b/validation-test/compiler_crashers_fixed/28864-bool-typesig-bool-extensionsig-unexpected-generic-ness-mismatch-on-conformance.swift
similarity index 88%
rename from validation-test/compiler_crashers/28864-bool-typesig-bool-extensionsig-unexpected-generic-ness-mismatch-on-conformance.swift
rename to validation-test/compiler_crashers_fixed/28864-bool-typesig-bool-extensionsig-unexpected-generic-ness-mismatch-on-conformance.swift
index ea97cf1..40f673d 100644
--- a/validation-test/compiler_crashers/28864-bool-typesig-bool-extensionsig-unexpected-generic-ness-mismatch-on-conformance.swift
+++ b/validation-test/compiler_crashers_fixed/28864-bool-typesig-bool-extensionsig-unexpected-generic-ness-mismatch-on-conformance.swift
@@ -6,6 +6,6 @@
 // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
 
 // REQUIRES: asserts
-// RUN: not --crash %target-swift-frontend %s -emit-ir
+// RUN: not %target-swift-frontend %s -emit-ir
 protocol P{class a}protocol A:P
 extension P.a:A