Merge pull request #22282 from apple/5.0-add-libcxx-and-clang-tools-extra

[update-checkout] Add support to clone libcxx and clang-tools-extra f…
diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def
index f82a655..1a1bc227 100644
--- a/include/swift/AST/DiagnosticsSema.def
+++ b/include/swift/AST/DiagnosticsSema.def
@@ -2824,7 +2824,7 @@
 
 ERROR(failed_to_produce_diagnostic,Fatal,
       "failed to produce diagnostic for expression; "
-      "please file a bug report with your project", ())
+      "please file a bug report", ())
 
 
 ERROR(missing_protocol,none,
diff --git a/lib/IDE/Formatting.cpp b/lib/IDE/Formatting.cpp
index 5df9045..b4c9cf2 100644
--- a/lib/IDE/Formatting.cpp
+++ b/lib/IDE/Formatting.cpp
@@ -575,8 +575,12 @@
       };
 
       if (auto AE = dyn_cast_or_null<ApplyExpr>(Node.dyn_cast<Expr *>())) {
-        collect(AE->getArg());
-        return;
+        // PrefixUnaryExpr shouldn't be syntacticly considered as a funtion call
+        // for sibling alignment.
+        if (!isa<PrefixUnaryExpr>(AE)) {
+          collect(AE->getArg());
+          return;
+        }
       }
 
       if (auto PE = dyn_cast_or_null<ParenExpr>(Node.dyn_cast<Expr *>())) {
diff --git a/lib/IRGen/GenEnum.cpp b/lib/IRGen/GenEnum.cpp
index 72c78a0..cccb841 100644
--- a/lib/IRGen/GenEnum.cpp
+++ b/lib/IRGen/GenEnum.cpp
@@ -4785,7 +4785,11 @@
         Address payloadAddr = projectPayload(IGF, enumAddr);
         auto payload = EnumPayload::load(IGF, payloadAddr, PayloadSchema);
         
-        auto spareBitMask = ~PayloadTagBits.asAPInt();
+        // We need to mask not only the payload tag bits, but all spare bits,
+        // because the other spare bits may be used to tag a single-payload
+        // enum containing this enum as a payload. Single payload layout
+        // unfortunately assumes that tagging the payload case is a no-op.
+        auto spareBitMask = ~CommonSpareBits.asAPInt();
         APInt tagBitMask
           = interleaveSpareBits(IGF.IGM, PayloadTagBits, PayloadTagBits.size(),
                                 spareTagBits, 0);
@@ -4823,7 +4827,11 @@
         auto payload = EnumPayload::load(IGF, payloadAddr, PayloadSchema);
 
         // Mask off the spare bits.
-        auto spareBitMask = ~PayloadTagBits.asAPInt();
+        // We need to mask not only the payload tag bits, but all spare bits,
+        // because the other spare bits may be used to tag a single-payload
+        // enum containing this enum as a payload. Single payload layout
+        // unfortunately assumes that tagging the payload case is a no-op.
+        auto spareBitMask = ~CommonSpareBits.asAPInt();
         payload.emitApplyAndMask(IGF, spareBitMask);
 
         // Store the tag into the spare bits.
diff --git a/lib/Sema/CSSolver.cpp b/lib/Sema/CSSolver.cpp
index 2690758..9260942 100644
--- a/lib/Sema/CSSolver.cpp
+++ b/lib/Sema/CSSolver.cpp
@@ -1956,9 +1956,10 @@
   // disjunctions that we may not be able to short-circuit, allowing
   // us to eliminate behavior that is exponential in the number of
   // operators in the expression.
-  if (getASTContext().isSwiftVersionAtLeast(5))
+  if (TC.getLangOpts().SolverEnableOperatorDesignatedTypes) {
     if (auto *disjunction = selectApplyDisjunction())
       return disjunction;
+  }
 
   if (auto *disjunction = selectBestBindingDisjunction(*this, disjunctions))
     return disjunction;
diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp
index 8670909..eb86deb 100644
--- a/lib/Sema/TypeCheckType.cpp
+++ b/lib/Sema/TypeCheckType.cpp
@@ -2144,6 +2144,13 @@
   if (!ty) ty = resolveType(repr, instanceOptions);
   if (!ty || ty->hasError()) return ty;
 
+  // Type aliases inside protocols are not yet resolved in the structural
+  // stage of type resolution
+  if (ty->is<DependentMemberType>() &&
+      resolution.getStage() == TypeResolutionStage::Structural) {
+    return ty;
+  }
+
   // Handle @escaping
   if (hasFunctionAttr && ty->is<FunctionType>()) {
     if (attrs.has(TAK_escaping)) {
diff --git a/stdlib/public/SDK/Foundation/NSString.swift b/stdlib/public/SDK/Foundation/NSString.swift
index 8aacff0..a97deca 100644
--- a/stdlib/public/SDK/Foundation/NSString.swift
+++ b/stdlib/public/SDK/Foundation/NSString.swift
@@ -16,12 +16,6 @@
 // Strings
 //===----------------------------------------------------------------------===//
 
-@available(*, unavailable, message: "Please use String or NSString")
-public class NSSimpleCString {}
-
-@available(*, unavailable, message: "Please use String or NSString")
-public class NSConstantString {}
-
 extension NSString : ExpressibleByStringLiteral {
   /// Create an instance initialized to `value`.
   public required convenience init(stringLiteral value: StaticString) {
diff --git a/stdlib/public/SDK/SceneKit/SceneKit.swift.gyb b/stdlib/public/SDK/SceneKit/SceneKit.swift.gyb
index dfa349e..04d8eec 100644
--- a/stdlib/public/SDK/SceneKit/SceneKit.swift.gyb
+++ b/stdlib/public/SDK/SceneKit/SceneKit.swift.gyb
@@ -179,21 +179,15 @@
 extension SCNGeometrySource {
   @nonobjc
   public convenience init(vertices: [SCNVector3]) {
-    fatalError()
-    // FIXME: <rdar://problem/43534146>
-    // self.init(__vertices: vertices, count: vertices.count)
+    self.init(__vertices: vertices, count: vertices.count)
   }
   @nonobjc
   public convenience init(normals: [SCNVector3]) {
-    fatalError()
-    // FIXME: <rdar://problem/43534146>
-    // self.init(__normals: normals, count: normals.count)
+    self.init(__normals: normals, count: normals.count)
   }
   @nonobjc
   public convenience init(textureCoordinates: [CGPoint]) {
-    fatalError()
-    // FIXME: <rdar://problem/43534146>
-    // self.init(__textureCoordinates: textureCoordinates, count: textureCoordinates.count)
+    self.init(__textureCoordinates: textureCoordinates, count: textureCoordinates.count)
   }
 }
 
diff --git a/test/IRGen/enum_value_semantics.sil b/test/IRGen/enum_value_semantics.sil
index 027b094..cb7fb92 100644
--- a/test/IRGen/enum_value_semantics.sil
+++ b/test/IRGen/enum_value_semantics.sil
@@ -570,8 +570,8 @@
 // CHECK-NEXT: [[SECOND_ADDR:%.*]] = getelementptr inbounds { i64, i64 }, { i64, i64 }* [[PAYLOAD]], i32 0, i32 1
 // CHECK-NEXT: [[SECOND:%.*]] = load i64, i64* [[SECOND_ADDR]], align 8
 
-//   -- Mask off spare bits in the payload               -- 0x3fffffffffffffff
-// CHECK-NEXT: [[SECOND_PROJ:%.*]] = and i64 [[SECOND]], 4611686018427387903
+//   -- Mask off spare bits in the payload               -- 0x00fffffffffffff8
+// CHECK-NEXT: [[SECOND_PROJ:%.*]] = and i64 [[SECOND]], 72057594037927928
 
 //   -- Store the low bits of the tag in the spare bits of the payload
 // CHECK-NEXT: [[TAG:%.*]] = zext i32 [[TAG_TMP]] to i64
diff --git a/test/Interpreter/SDK/FoundationDiagnostics.swift b/test/Interpreter/SDK/FoundationDiagnostics.swift
index fcda9b2..fbfc17f 100644
--- a/test/Interpreter/SDK/FoundationDiagnostics.swift
+++ b/test/Interpreter/SDK/FoundationDiagnostics.swift
@@ -4,11 +4,6 @@
 
 import Foundation
 
-func useUnavailable() {
-  var a = NSSimpleCString() // expected-error {{'NSSimpleCString' is unavailable}}
-  var b = NSConstantString() // expected-error {{'NSConstantString' is unavailable}}
-}
-
 func encode(_ string: String) {
   _ = string.cString(using: NSUTF8StringEncoding) // expected-error {{'NSUTF8StringEncoding' has been renamed to 'String.Encoding.utf8'}} {{29-49=String.Encoding.utf8}}
   let _: NSStringEncoding? = nil // expected-error {{'NSStringEncoding' has been renamed to 'String.Encoding'}} {{10-26=String.Encoding}}
diff --git a/test/Sema/rdar38885760.swift b/test/Sema/rdar38885760.swift
index fe2945e..2cc2445 100644
--- a/test/Sema/rdar38885760.swift
+++ b/test/Sema/rdar38885760.swift
@@ -3,7 +3,7 @@
 // RUN: not %target-swift-frontend -typecheck %s -parse-stdlib 2>%t/fallback_diagnostic.txt
 // RUN: %FileCheck %s --check-prefix FALLBACK-DIAGNOSTIC <%t/fallback_diagnostic.txt
 //
-// FALLBACK-DIAGNOSTIC: error: failed to produce diagnostic for expression; please file a bug report with your project
+// FALLBACK-DIAGNOSTIC: error: failed to produce diagnostic for expression; please file a bug report
 
 import Swift
 
diff --git a/test/SourceKit/CodeFormat/indent-if.swift b/test/SourceKit/CodeFormat/indent-if.swift
new file mode 100644
index 0000000..de41a7d
--- /dev/null
+++ b/test/SourceKit/CodeFormat/indent-if.swift
@@ -0,0 +1,22 @@
+if condition,
+        !condition,
+         condition,
+    condition,
+    !condition,
+              condition {
+}
+
+
+// RUN: %sourcekitd-test -req=format -line=2 -length=1 %s >%t.response
+// RUN: %sourcekitd-test -req=format -line=3 -length=1 %s >>%t.response
+// RUN: %sourcekitd-test -req=format -line=4 -length=1 %s >>%t.response
+// RUN: %sourcekitd-test -req=format -line=5 -length=1 %s >>%t.response
+// RUN: %sourcekitd-test -req=format -line=6 -length=1 %s >>%t.response
+
+// RUN: %FileCheck --strict-whitespace %s <%t.response
+
+// CHECK: key.sourcetext: "    !condition,"
+// CHECK: key.sourcetext: "    condition,"
+// CHECK: key.sourcetext: "    condition,"
+// CHECK: key.sourcetext: "    !condition,"
+// CHECK: key.sourcetext: "    condition {"
diff --git a/test/attr/attr_escaping.swift b/test/attr/attr_escaping.swift
index 047ee09..9c62c45 100644
--- a/test/attr/attr_escaping.swift
+++ b/test/attr/attr_escaping.swift
@@ -217,3 +217,16 @@
     })()
   }
 }
+
+// https://bugs.swift.org/browse/SR-9760
+protocol SR_9760 {
+  typealias F = () -> Void
+  typealias G<T> = (T) -> Void
+  func foo<T>(_: T, _: @escaping F) // Ok
+  func bar<T>(_: @escaping G<T>) // Ok
+}
+
+extension SR_9760 {
+  func fiz<T>(_: T, _: @escaping F) {} // Ok
+  func baz<T>(_: @escaping G<T>) {} // Ok
+}
diff --git a/validation-test/Sema/type_checker_perf/fast/rdar47492691.swift b/validation-test/Sema/type_checker_perf/fast/rdar47492691.swift
new file mode 100644
index 0000000..fd6246f
--- /dev/null
+++ b/validation-test/Sema/type_checker_perf/fast/rdar47492691.swift
@@ -0,0 +1,9 @@
+// RUN: %target-typecheck-verify-swift
+// REQUIRES: objc_interop
+
+import CoreGraphics
+import simd
+
+func test(foo: CGFloat, bar: CGFloat) {
+  _ = CGRect(x: 0.0 + 1.0, y: 0.0 + foo, width: 3.0 - 1 - 1 - 1.0, height: bar)
+}
diff --git a/validation-test/stdlib/SceneKit.swift b/validation-test/stdlib/SceneKit.swift
index 007edec..7ac2955 100644
--- a/validation-test/stdlib/SceneKit.swift
+++ b/validation-test/stdlib/SceneKit.swift
@@ -132,9 +132,7 @@
     expectEqual(1, element.bytesPerIndex)
   }
 
-  SceneKitTests.test("SCNGeometrySource.init(vertices:)")
-    .skip(.always("rdar://problem/43534146"))
-    .code {
+  SceneKitTests.test("SCNGeometrySource.init(vertices:)") {
     let source = SCNGeometrySource(vertices: [SCNVector3(1, 2, 3),
                                               SCNVector3(4, 5, 6)])
 
@@ -148,9 +146,7 @@
     expectEqual(positions[4], 5)
   }
 
-  SceneKitTests.test("SCNGeometrySource.init(normals:)")
-    .skip(.always("rdar://problem/43534146"))
-    .code {
+  SceneKitTests.test("SCNGeometrySource.init(normals:)") {
     let source = SCNGeometrySource(normals: [SCNVector3(1, 2, 3),
                                              SCNVector3(4, 5, 6)])
 
@@ -164,9 +160,7 @@
     expectEqual(normals[4], 5)
   }
 
-  SceneKitTests.test("SCNGeometrySource.init(textureCoordinates:)")
-    .skip(.always("rdar://problem/43534146"))
-    .code {
+  SceneKitTests.test("SCNGeometrySource.init(textureCoordinates:)") {
     let source = SCNGeometrySource(textureCoordinates: [CGPoint(x: 1, y: 2),
                                                         CGPoint(x: 4, y: 5)])