[stdlib] Migrate stdlib tests of Swift 3 (#17427)

* First sweep of Swift 3 stdlib test upgrades

* Review feedback

* Remove a handful more #if >=4.0

* Fix up Dictionary tests
diff --git a/benchmark/single-source/ByteSwap.swift b/benchmark/single-source/ByteSwap.swift
index 3fab1ed..1b9f341 100644
--- a/benchmark/single-source/ByteSwap.swift
+++ b/benchmark/single-source/ByteSwap.swift
@@ -24,7 +24,6 @@
 // a naive O(n) implementation of byteswap.
 @inline(never)
 func byteswap_n(_ a: UInt64) -> UInt64 {
-#if swift(>=4)
   return ((a & 0x00000000000000FF) &<< 56) |
          ((a & 0x000000000000FF00) &<< 40) |
          ((a & 0x0000000000FF0000) &<< 24) |
@@ -33,16 +32,6 @@
          ((a & 0x0000FF0000000000) &>> 24) |
          ((a & 0x00FF000000000000) &>> 40) |
          ((a & 0xFF00000000000000) &>> 56)
-#else
-  return ((a & 0x00000000000000FF) << 56) |
-         ((a & 0x000000000000FF00) << 40) |
-         ((a & 0x0000000000FF0000) << 24) |
-         ((a & 0x00000000FF000000) <<  8) |
-         ((a & 0x000000FF00000000) >>  8) |
-         ((a & 0x0000FF0000000000) >> 24) |
-         ((a & 0x00FF000000000000) >> 40) |
-         ((a & 0xFF00000000000000) >> 56)
-#endif
 }
 
 // a O(logn) implementation of byteswap.
diff --git a/stdlib/private/StdlibUnittest/StdlibUnittest.swift b/stdlib/private/StdlibUnittest/StdlibUnittest.swift
index 7da5971..3615155 100644
--- a/stdlib/private/StdlibUnittest/StdlibUnittest.swift
+++ b/stdlib/private/StdlibUnittest/StdlibUnittest.swift
@@ -3010,8 +3010,8 @@
   }
 }
 
-public func expectEqualUnicodeScalars(
-  _ expected: [UInt32], _ actual: String,
+public func expectEqualUnicodeScalars<S: StringProtocol>(
+  _ expected: [UInt32], _ actual: S,
   _ message: @autoclosure () -> String = "",
   stackTrace: SourceLocStack = SourceLocStack(),
   showFrame: Bool = true,
diff --git a/test/stdlib/Dispatch.swift b/test/stdlib/Dispatch.swift
index 20acd23..88517d6 100644
--- a/test/stdlib/Dispatch.swift
+++ b/test/stdlib/Dispatch.swift
@@ -1,9 +1,7 @@
 // RUN: %empty-directory(%t)
-// RUN: %target-build-swift %s -o %t/a.out_swift3 -swift-version 3
-// RUN: %target-build-swift %s -o %t/a.out_swift4 -swift-version 4
+// RUN: %target-build-swift %s -o %t/a.out
 //
-// RUN: %target-run %t/a.out_swift3
-// RUN: %target-run %t/a.out_swift4
+// RUN: %target-run %t/a.out
 // REQUIRES: executable_test
 
 // REQUIRES: objc_interop
@@ -40,7 +38,7 @@
 }
 
 DispatchAPI.test("Dispatch sync return value") {
-  let value = 24;
+  let value = 24
   let q = DispatchQueue(label: "Test")
   let result = q.sync() { return 24 }
   expectEqual(value, result)
@@ -516,14 +514,8 @@
 
 DispatchAPI.test("DispatchIO.initRelativePath") {
 	let q = DispatchQueue(label: "initRelativePath queue")
-#if swift(>=4.0)
 	let chan = DispatchIO(type: .random, path: "_REL_PATH_", oflag: O_RDONLY, mode: 0, queue: q, cleanupHandler: { (error) in })
 	expectEqual(chan, nil)
-#else
-	expectCrashLater()
-	let chan = DispatchIO(type: .random, path: "_REL_PATH_", oflag: O_RDONLY, mode: 0, queue: q, cleanupHandler: { (error) in })
-	chan.setInterval(interval: .seconds(1)) // Dereference of unexpected nil should crash
-#endif
 }
 
 if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
@@ -595,11 +587,9 @@
 	expectTrue(t == t) // This would crash.
 }
 
-#if swift(>=4.0)
 DispatchAPI.test("DispatchTimeInterval.never.equals") {
 	expectTrue(DispatchTimeInterval.never == DispatchTimeInterval.never)
 	expectTrue(DispatchTimeInterval.seconds(10) != DispatchTimeInterval.never);
 	expectTrue(DispatchTimeInterval.never != DispatchTimeInterval.seconds(10));
 	expectTrue(DispatchTimeInterval.seconds(10) == DispatchTimeInterval.seconds(10));
 }
-#endif
diff --git a/test/stdlib/Inputs/DictionaryKeyValueTypesObjC.swift b/test/stdlib/Inputs/DictionaryKeyValueTypesObjC.swift
index 9e3797e..ac05457 100644
--- a/test/stdlib/Inputs/DictionaryKeyValueTypesObjC.swift
+++ b/test/stdlib/Inputs/DictionaryKeyValueTypesObjC.swift
@@ -475,8 +475,7 @@
   d[TestObjCKeyTy(20)] = TestObjCValueTy(1020)
   d[TestObjCKeyTy(30)] = TestObjCValueTy(1030)
 
-  let bridged =
-    unsafeBitCast(convertDictionaryToNSDictionary(d), to: NSDictionary.self)
+  let bridged = convertDictionaryToNSDictionary(d)
 
   assert(isNativeNSDictionary(bridged))
 
@@ -486,8 +485,7 @@
 func getBridgedEmptyNSDictionary() -> NSDictionary {
   let d = Dictionary<TestObjCKeyTy, TestObjCValueTy>()
 
-  let bridged =
-    unsafeBitCast(convertDictionaryToNSDictionary(d), to: NSDictionary.self)
+  let bridged = convertDictionaryToNSDictionary(d)
   assert(isNativeNSDictionary(bridged))
 
   return bridged
@@ -874,8 +872,7 @@
   for i in 0..<3 {
     var actualContents = [ExpectedDictionaryElement]()
     let sink: (AnyObjectTuple2) -> Void = {
-      pair in
-      let (key, value) = pair
+      let (key, value) = $0
       actualContents.append(ExpectedDictionaryElement(
         key: convertKey(key),
         value: convertValue(value),
diff --git a/test/stdlib/IntegerCompatibility.swift b/test/stdlib/IntegerCompatibility.swift
index 7eb0949..db935bc 100644
--- a/test/stdlib/IntegerCompatibility.swift
+++ b/test/stdlib/IntegerCompatibility.swift
@@ -1,9 +1,7 @@
-// RUN: %target-build-swift %s -swift-version 3 -typecheck
 // RUN: %target-build-swift %s -swift-version 4 -typecheck
 
 
 func byteswap_n(_ a: UInt64) -> UInt64 {
-#if swift(>=4)
   return ((a & 0x00000000000000FF) &<< 56) |
          ((a & 0x000000000000FF00) &<< 40) |
          ((a & 0x0000000000FF0000) &<< 24) |
@@ -12,22 +10,11 @@
          ((a & 0x0000FF0000000000) &>> 24) |
          ((a & 0x00FF000000000000) &>> 40) |
          ((a & 0xFF00000000000000) &>> 56)
-#else
-  return ((a & 0x00000000000000FF) << 56) |
-         ((a & 0x000000000000FF00) << 40) |
-         ((a & 0x0000000000FF0000) << 24) |
-         ((a & 0x00000000FF000000) <<  8) |
-         ((a & 0x000000FF00000000) >>  8) |
-         ((a & 0x0000FF0000000000) >> 24) |
-         ((a & 0x00FF000000000000) >> 40) |
-         ((a & 0xFF00000000000000) >> 56)
-#endif
 }
 
 
 // expression should not be too complex
 func radar31845712(_ i: Int, _ buffer: [UInt8]) {
-#if swift(>=4)
   _ =  UInt64(buffer[i])
     | (UInt64(buffer[i + 1]) &<< 8)
     | (UInt64(buffer[i + 2]) &<< 16)
@@ -36,16 +23,6 @@
     | (UInt64(buffer[i + 5]) &<< 40)
     | (UInt64(buffer[i + 6]) &<< 48)
     | (UInt64(buffer[i + 7]) &<< 56)
-#else
-  _ =  UInt64(buffer[i])
-    | (UInt64(buffer[i + 1]) << 8)
-    | (UInt64(buffer[i + 2]) << 16)
-    | (UInt64(buffer[i + 3]) << 24)
-    | (UInt64(buffer[i + 4]) << 32)
-    | (UInt64(buffer[i + 5]) << 40)
-    | (UInt64(buffer[i + 6]) << 48)
-    | (UInt64(buffer[i + 7]) << 56)
-#endif
 }
 
 // expression should not be too complex
@@ -54,17 +31,10 @@
     var val: UInt32 = input
     return withUnsafePointer(to: &val) { (ptr: UnsafePointer<UInt32>) -> UInt32 in
       return ptr.withMemoryRebound(to: UInt8.self, capacity: 4) { data in
-#if swift(>=4)
         return (UInt32(data[3]) &<< 0) |
                (UInt32(data[2]) &<< 8) |
                (UInt32(data[1]) &<< 16) |
                (UInt32(data[0]) &<< 24)
-#else
-        return (UInt32(data[3]) << 0) |
-               (UInt32(data[2]) << 8) |
-               (UInt32(data[1]) << 16) |
-               (UInt32(data[0]) << 24)
-#endif
       }
     }
   }
@@ -74,11 +44,9 @@
   _ = (i64 >> 8) & 0xFF
 }
 
-#if swift(>=4)
 func negativeShift(_ u8: UInt8) {
   _ = (u8 << -1)
 }
-#endif
 
 func sr5176(description: String = "unambiguous Int32.init(bitPattern:)") {
   _ = Int32(bitPattern: 0) // should compile without ambiguity
diff --git a/test/stdlib/IntegerDiagnostics.swift b/test/stdlib/IntegerDiagnostics.swift
index ba529e1..cdb0cd4 100644
--- a/test/stdlib/IntegerDiagnostics.swift
+++ b/test/stdlib/IntegerDiagnostics.swift
@@ -1,4 +1,3 @@
-// RUN: %target-typecheck-verify-swift -swift-version 3
 // RUN: %target-typecheck-verify-swift -swift-version 4
 
 func signedBitPattern() {
diff --git a/test/stdlib/LazyCollectionPlus.swift b/test/stdlib/LazyCollectionPlus.swift
deleted file mode 100644
index 8dbd6a1..0000000
--- a/test/stdlib/LazyCollectionPlus.swift
+++ /dev/null
@@ -1,17 +0,0 @@
-// RUN: %empty-directory(%t)
-// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
-// REQUIRES: executable_test
-
-import StdlibUnittest
-
-var tests = TestSuite("LazyCollectionPlus")
-
-tests.test("NoAmbiguity") {
-  let d: [String: Int] = ["" : 0]
-  let xs = d.values.map { $0 }
-  let ys = d.values.map { $0 + 42 }
-  let actual = xs + ys // this line should compile without ambiguity
-  expectEqualSequence([0, 42], actual)
-}
-
-runAllTests()
diff --git a/test/stdlib/LazySlice.swift b/test/stdlib/LazySlice.swift
index 75f383e..e81ea7b 100644
--- a/test/stdlib/LazySlice.swift
+++ b/test/stdlib/LazySlice.swift
@@ -1,5 +1,5 @@
 // RUN: %empty-directory(%t)
-// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
+// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
 // REQUIRES: executable_test
 
 import StdlibUnittest
@@ -10,9 +10,8 @@
   let a = [1,2,3].lazy
   let b = a[...]
   var c = b.filter { $0 == 0 }
-  // NOTE, this test will fail once lazy collectionness becomes a conditiona
-  // conformance, and will need updating to be a LazyBidirectional thingy
-  expectType(LazyFilterBidirectionalCollection<Slice<LazyRandomAccessCollection<[Int]>>>.self, &c)
+
+  expectType(LazyFilterCollection<Slice<LazyCollection<[Int]>>>.self, &c)
 }
 
 runAllTests()
diff --git a/test/stdlib/MapFilterLayerFoldingCompatibilty.swift b/test/stdlib/MapFilterLayerFoldingCompatibilty.swift
index 9b982b5..1c01e17 100644
--- a/test/stdlib/MapFilterLayerFoldingCompatibilty.swift
+++ b/test/stdlib/MapFilterLayerFoldingCompatibilty.swift
@@ -1,5 +1,4 @@
 // RUN: %empty-directory(%t)
-// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
 // RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
 // RUN: %target-build-swift %s -o %t/a.out5 -swift-version 5 && %target-run %t/a.out5
 // REQUIRES: executable_test
diff --git a/test/stdlib/MixedTypeArithmeticsDiagnostics4.swift b/test/stdlib/MixedTypeArithmeticsDiagnostics4.swift
deleted file mode 100644
index 9024ac2..0000000
--- a/test/stdlib/MixedTypeArithmeticsDiagnostics4.swift
+++ /dev/null
@@ -1,41 +0,0 @@
-//===--- MixedTypeArithmeticsDiagnostics4.swift ---------------------------===//
-//
-// This source file is part of the Swift.org open source project
-//
-// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
-// Licensed under Apache License v2.0 with Runtime Library Exception
-//
-// See https://swift.org/LICENSE.txt for license information
-// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
-//
-//===----------------------------------------------------------------------===//
-// RUN: %target-typecheck-verify-swift -swift-version 4
-
-
-func mixedTypeArithemtics() {
-  _ = (42 as Int64) + (0 as Int) // expected-error {{'+' is unavailable}}
-
-  do {
-    var x = Int8()
-    x += (42 as Int) // expected-error {{'+=' is unavailable}}
-  }
-
-  _ = (42 as Int32) - (0 as Int) // expected-error {{'-' is unavailable}}
-
-  do {
-    var x = Int16()
-    x -= (42 as Int) // expected-error {{'-=' is unavailable}}
-  }
-
-  // With Int on both sides should NOT result in warning
-  do {
-    var x = Int()
-    x += (42 as Int)
-  }
-}
-
-func radar31909031() {
-  let x = UInt64()
-  let y = UInt64()
-  _ = (x - y) < UInt64(42) // should not produce a mixed-type warning
-}
diff --git a/test/stdlib/RangeReplaceableFilterCompatibility.swift b/test/stdlib/RangeReplaceableFilterCompatibility.swift
index 87e2647..0425fb1 100644
--- a/test/stdlib/RangeReplaceableFilterCompatibility.swift
+++ b/test/stdlib/RangeReplaceableFilterCompatibility.swift
@@ -1,5 +1,4 @@
 // RUN: %empty-directory(%t)
-// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
 // RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
 
 // REQUIRES: executable_test
@@ -10,11 +9,7 @@
 
 tests.test("String.filter return type") {
   var filtered = "Hello, World".filter { $0 < "A" }
-#if swift(>=4)
   expectType(String.self, &filtered)
-#else
-  expectType([Character].self, &filtered)
-#endif
 }
 
 tests.test("Array.filter return type") {
diff --git a/test/stdlib/ReverseCompatibility.swift b/test/stdlib/ReverseCompatibility.swift
index a748142..5b5846b 100644
--- a/test/stdlib/ReverseCompatibility.swift
+++ b/test/stdlib/ReverseCompatibility.swift
@@ -1,5 +1,4 @@
 // RUN: %empty-directory(%t)
-// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
 // RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
 // RUN: %target-build-swift %s -o %t/a.out5 -swift-version 5 && %target-run %t/a.out5
 // REQUIRES: executable_test
diff --git a/test/stdlib/StringCompatibility.swift b/test/stdlib/StringCompatibility.swift
index 1251d25..e9a5e0c 100644
--- a/test/stdlib/StringCompatibility.swift
+++ b/test/stdlib/StringCompatibility.swift
@@ -1,5 +1,4 @@
 // RUN: %empty-directory(%t)
-// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
 // RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
 
 // REQUIRES: executable_test
@@ -172,87 +171,12 @@
 }
 //===----------------------------------------------------------------------===//
 
-#if swift(>=4)
-
 public typealias ExpectedConcreteSlice = Substring
 public typealias ExpectedStringFromString = String
 let swift = 4
 
-#else
-
-public typealias ExpectedConcreteSlice = String
-public typealias ExpectedStringFromString = String?
-let swift = 3
-
-#endif
-
 var Tests = TestSuite("StringCompatibility")
 
-#if !swift(>=4) && _runtime(_ObjC)
-import Foundation
-
-Tests.test("String/Legacy/UTF16View.Index/StrideableAPIs") {
-  let i = String.UTF16View.Index(0)
-  expectEqual(0, i.distance(to: i))
-  expectEqual(0, i.distance(to: i.samePosition(in: "")))
-  expectEqual(i, i.advanced(by: 0))
-}
-
-Tests.test("String/Legacy/UTF16View/OptionalIndices") {
-  let s = "somethingToTest".utf16
-  let i = s.startIndex
-  let j = Optional(i)
-  expectEqual(s.index(after: i), s.index(after: j))
-  expectEqual(s.index(i, offsetBy: 2), s.index(j, offsetBy: 2))
-  expectEqual(
-    s.distance(from: i, to: s.endIndex),
-    s.distance(from: j, to: s.endIndex))
-  expectEqual(
-    s.distance(from: i, to: s.endIndex),
-    s.distance(from: j, to: Optional(s.endIndex)))
-  expectEqual(
-    s.distance(from: i, to: s.endIndex),
-    s.distance(from: i, to: Optional(s.endIndex)))
-  expectEqual(s[i], s[j])
-}
-
-Tests.test("String/Legacy/UTF8View/OptionalIndices") {
-  let s = "somethingToTest".utf8
-  let i = s.startIndex
-  let j = Optional(i)
-  expectEqual(s.index(after: i), s.index(after: j))
-  expectEqual(s.index(i, offsetBy: 2), s.index(j, offsetBy: 2))
-  expectEqual(
-    s.distance(from: i, to: s.endIndex),
-    s.distance(from: j, to: s.endIndex))
-  expectEqual(
-    s.distance(from: i, to: s.endIndex),
-    s.distance(from: j, to: Optional(s.endIndex)))
-  expectEqual(
-    s.distance(from: i, to: s.endIndex),
-    s.distance(from: i, to: Optional(s.endIndex)))
-  expectEqual(s[i], s[j])
-}
-
-Tests.test("String/Legacy/UnicodeScalarView/OptionalIndices") {
-  let s = "somethingToTest".unicodeScalars
-  let i = s.startIndex
-  let j = Optional(i)
-  expectEqual(s.index(after: i), s.index(after: j))
-  expectEqual(s.index(i, offsetBy: 2), s.index(j, offsetBy: 2))
-  expectEqual(
-    s.distance(from: i, to: s.endIndex),
-    s.distance(from: j, to: s.endIndex))
-  expectEqual(
-    s.distance(from: i, to: s.endIndex),
-    s.distance(from: j, to: Optional(s.endIndex)))
-  expectEqual(
-    s.distance(from: i, to: s.endIndex),
-    s.distance(from: i, to: Optional(s.endIndex)))
-  expectEqual(s[i], s[j])
-}
-#endif
-
 Tests.test("String/Range/Slice/ExpectedType/\(swift)") {
   var s = "hello world"
   var sub = s[s.startIndex ..< s.endIndex]
@@ -339,11 +263,7 @@
   f(String.self)
 }
 
-#if swift(>=4)
 public typealias ExpectedUTF8ViewSlice = String.UTF8View.SubSequence
-#else
-public typealias ExpectedUTF8ViewSlice = String.UTF8View
-#endif
 
 Tests.test("UTF8ViewSlicing") {
   let s = "Hello, String.UTF8View slicing world!".utf8
@@ -352,27 +272,4 @@
   _ = s[s.startIndex..<s.endIndex] as String.UTF8View.SubSequence
 }
 
-#if !swift(>=4)
-Tests.test("LosslessStringConvertible/force unwrap/\(swift)") {
-  // Force unwrap should still work in Swift 3 mode
-  _ = String("")!
-}
-#endif
-
-#if !swift(>=4)
-Tests.test("popFirst") {
-  var str = "abcdef"
-  expectOptionalEqual("a", str.popFirst())
-  expectOptionalEqual("bcdef", str)
-  expectOptionalEqual("b", str.characters.popFirst())
-  expectOptionalEqual("cdef", str)
-  expectOptionalEqual("c", str.unicodeScalars.popFirst())
-  expectOptionalEqual("def", str)
-  expectOptionalEqual("d", str.popFirst())
-  expectOptionalEqual("e", str.popFirst())
-  expectOptionalEqual("f", str.popFirst())
-  expectNil(str.popFirst())
-}
-#endif
-
 runAllTests()
diff --git a/test/stdlib/StringFlatMap.swift b/test/stdlib/StringFlatMap.swift
index 8995398..832e855 100644
--- a/test/stdlib/StringFlatMap.swift
+++ b/test/stdlib/StringFlatMap.swift
@@ -1,38 +1,28 @@
 // RUN: %empty-directory(%t)
-// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
-// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
+// RUN: %target-build-swift %s -o %t/a.out && %target-run %t/a.out
 
 // REQUIRES: executable_test
 
 import StdlibUnittest
 
-#if swift(>=4)
 
 public typealias ExpectedResultType = [Character]
-let swiftVersion = "4"
-
-#else
-
-public typealias ExpectedResultType = [String]
-let swiftVersion = "3"
-
-#endif
 
 var Tests = TestSuite("StringFlatMap")
 
-Tests.test("DefaultReturnType/\(swiftVersion)") {
+Tests.test("DefaultReturnType") {
   var result = ["hello", "world"].flatMap { $0 }
   expectType(ExpectedResultType.self, &result)
 }
 
-Tests.test("ExplicitTypeContext/\(swiftVersion)") {
+Tests.test("ExplicitTypeContext") {
   expectEqualSequence(["hello", "world"],
     ["hello", "world"].flatMap { $0 } as [String])
   expectEqualSequence("helloworld".characters,
     ["hello", "world"].flatMap { $0 } as [Character])
 }
 
-Tests.test("inference/\(swiftVersion)") {
+Tests.test("inference") {
   let result = [1, 2].flatMap { x in
     if String(x) == "foo" {
       return "bar"
diff --git a/validation-test/stdlib/Dictionary.swift b/validation-test/stdlib/Dictionary.swift
index f802af7..5551463 100644
--- a/validation-test/stdlib/Dictionary.swift
+++ b/validation-test/stdlib/Dictionary.swift
@@ -3,9 +3,9 @@
 // RUN: %gyb %s -o %t/main.swift
 // RUN: if [ %target-runtime == "objc" ]; then \
 // RUN:   %target-clang -fobjc-arc %S/Inputs/SlurpFastEnumeration/SlurpFastEnumeration.m -c -o %t/SlurpFastEnumeration.o; \
-// RUN:   %line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift %t/main.swift -I %S/Inputs/SlurpFastEnumeration/ -Xlinker %t/SlurpFastEnumeration.o -o %t/Dictionary -Xfrontend -disable-access-control ; \
+// RUN:   %line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift %t/main.swift -I %S/Inputs/SlurpFastEnumeration/ -Xlinker %t/SlurpFastEnumeration.o -o %t/Dictionary -Xfrontend -disable-access-control; \
 // RUN: else \
-// RUN:   %line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %t/main.swift -o %t/Dictionary -Xfrontend -disable-access-control ; \
+// RUN:   %line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %t/main.swift -o %t/Dictionary -Xfrontend -disable-access-control; \
 // RUN: fi
 //
 // RUN: %line-directive %t/main.swift -- %target-run %t/Dictionary
@@ -97,7 +97,7 @@
 
 DictionaryTestSuite.test("COW.Smoke") {
   var d1 = Dictionary<TestKeyTy, TestValueTy>(minimumCapacity: 10)
-  var identity1 = d1._rawIdentifier()
+  let identity1 = d1._rawIdentifier()
 
   d1[TestKeyTy(10)] = TestValueTy(1010)
   d1[TestKeyTy(20)] = TestValueTy(1020)
@@ -154,10 +154,10 @@
 
 DictionaryTestSuite.test("COW.Fast.IndexesDontAffectUniquenessCheck") {
   var d = getCOWFastDictionary()
-  var identity1 = d._rawIdentifier()
+  let identity1 = d._rawIdentifier()
 
-  var startIndex = d.startIndex
-  var endIndex = d.endIndex
+  let startIndex = d.startIndex
+  let endIndex = d.endIndex
   assert(startIndex != endIndex)
   assert(startIndex < endIndex)
   assert(startIndex <= endIndex)
@@ -176,10 +176,10 @@
 
 DictionaryTestSuite.test("COW.Slow.IndexesDontAffectUniquenessCheck") {
   var d = getCOWSlowDictionary()
-  var identity1 = d._rawIdentifier()
+  let identity1 = d._rawIdentifier()
 
-  var startIndex = d.startIndex
-  var endIndex = d.endIndex
+  let startIndex = d.startIndex
+  let endIndex = d.endIndex
   assert(startIndex != endIndex)
   assert(startIndex < endIndex)
   assert(startIndex <= endIndex)
@@ -197,10 +197,10 @@
 
 
 DictionaryTestSuite.test("COW.Fast.SubscriptWithIndexDoesNotReallocate") {
-  var d = getCOWFastDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getCOWFastDictionary()
+  let identity1 = d._rawIdentifier()
 
-  var startIndex = d.startIndex
+  let startIndex = d.startIndex
   let empty = startIndex == d.endIndex
   assert((d.startIndex < d.endIndex) == !empty)
   assert(d.startIndex <= d.endIndex)
@@ -213,10 +213,10 @@
 }
 
 DictionaryTestSuite.test("COW.Slow.SubscriptWithIndexDoesNotReallocate") {
-  var d = getCOWSlowDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getCOWSlowDictionary()
+  let identity1 = d._rawIdentifier()
 
-  var startIndex = d.startIndex
+  let startIndex = d.startIndex
   let empty = startIndex == d.endIndex
   assert((d.startIndex < d.endIndex) == !empty)
   assert(d.startIndex <= d.endIndex)
@@ -232,7 +232,7 @@
 DictionaryTestSuite.test("COW.Fast.SubscriptWithKeyDoesNotReallocate")
   .code {
   var d = getCOWFastDictionary()
-  var identity1 = d._rawIdentifier()
+  let identity1 = d._rawIdentifier()
 
   assert(d[10]! == 1010)
   assert(identity1 == d._rawIdentifier())
@@ -288,7 +288,7 @@
   .code {
 
   var d = getCOWSlowDictionary()
-  var identity1 = d._rawIdentifier()
+  let identity1 = d._rawIdentifier()
 
   assert(d[TestKeyTy(10)]!.value == 1010)
   assert(identity1 == d._rawIdentifier())
@@ -345,7 +345,7 @@
 DictionaryTestSuite.test("COW.Fast.UpdateValueForKeyDoesNotReallocate") {
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     // Insert a new key-value pair.
     assert(d1.updateValue(2040, forKey: 40) == .none)
@@ -360,7 +360,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -390,7 +390,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -420,7 +420,7 @@
 DictionaryTestSuite.test("COW.Slow.AddDoesNotReallocate") {
   do {
     var d1 = getCOWSlowDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     // Insert a new key-value pair.
     assert(d1.updateValue(TestValueTy(2040), forKey: TestKeyTy(40)) == nil)
@@ -437,7 +437,7 @@
 
   do {
     var d1 = getCOWSlowDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -467,7 +467,7 @@
 
   do {
     var d1 = getCOWSlowDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -499,7 +499,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     // Merge some new values.
     d1.merge([(40, 2040), (50, 2050)]) { _, y in y }
@@ -531,7 +531,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -562,7 +562,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -590,7 +590,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -622,7 +622,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     // Merge some new values.
     d1.merge([40: 2040, 50: 2050]) { _, y in y }
@@ -654,7 +654,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -685,7 +685,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -713,7 +713,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -743,7 +743,7 @@
 DictionaryTestSuite.test("COW.Fast.DefaultedSubscriptDoesNotReallocate") {
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     // No mutation on access.
     assert(d1[10, default: 0] + 1 == 1011)
@@ -764,7 +764,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -791,7 +791,7 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
@@ -838,15 +838,15 @@
 }
 
 DictionaryTestSuite.test("COW.Fast.IndexForKeyDoesNotReallocate") {
-  var d = getCOWFastDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getCOWFastDictionary()
+  let identity1 = d._rawIdentifier()
 
   // Find an existing key.
   do {
-    var foundIndex1 = d.index(forKey: 10)!
+    let foundIndex1 = d.index(forKey: 10)!
     assert(identity1 == d._rawIdentifier())
 
-    var foundIndex2 = d.index(forKey: 10)!
+    let foundIndex2 = d.index(forKey: 10)!
     assert(foundIndex1 == foundIndex2)
 
     assert(d[foundIndex1].0 == 10)
@@ -856,13 +856,13 @@
 
   // Try to find a key that is not present.
   do {
-    var foundIndex1 = d.index(forKey: 1111)
+    let foundIndex1 = d.index(forKey: 1111)
     assert(foundIndex1 == nil)
     assert(identity1 == d._rawIdentifier())
   }
 
   do {
-    var d2: [MinimalHashableValue : OpaqueValue<Int>] = [:]
+    let d2: [MinimalHashableValue : OpaqueValue<Int>] = [:]
     MinimalHashableValue.timesEqualEqualWasCalled = 0
     MinimalHashableValue.timesHashIntoWasCalled = 0
     expectNil(d2.index(forKey: MinimalHashableValue(42)))
@@ -875,15 +875,15 @@
 }
 
 DictionaryTestSuite.test("COW.Slow.IndexForKeyDoesNotReallocate") {
-  var d = getCOWSlowDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getCOWSlowDictionary()
+  let identity1 = d._rawIdentifier()
 
   // Find an existing key.
   do {
-    var foundIndex1 = d.index(forKey: TestKeyTy(10))!
+    let foundIndex1 = d.index(forKey: TestKeyTy(10))!
     assert(identity1 == d._rawIdentifier())
 
-    var foundIndex2 = d.index(forKey: TestKeyTy(10))!
+    let foundIndex2 = d.index(forKey: TestKeyTy(10))!
     assert(foundIndex1 == foundIndex2)
 
     assert(d[foundIndex1].0 == TestKeyTy(10))
@@ -893,13 +893,13 @@
 
   // Try to find a key that is not present.
   do {
-    var foundIndex1 = d.index(forKey: TestKeyTy(1111))
+    let foundIndex1 = d.index(forKey: TestKeyTy(1111))
     assert(foundIndex1 == nil)
     assert(identity1 == d._rawIdentifier())
   }
 
   do {
-    var d2: [MinimalHashableClass : OpaqueValue<Int>] = [:]
+    let d2: [MinimalHashableClass : OpaqueValue<Int>] = [:]
     MinimalHashableClass.timesEqualEqualWasCalled = 0
     MinimalHashableClass.timesHashIntoWasCalled = 0
     expectNil(d2.index(forKey: MinimalHashableClass(42)))
@@ -916,7 +916,7 @@
   .code {
   do {
     var d = getCOWFastDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
 
     let foundIndex1 = d.index(forKey: 10)!
     assert(identity1 == d._rawIdentifier())
@@ -933,14 +933,14 @@
   }
 
   do {
-    var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let d1 = getCOWFastDictionary()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
     assert(identity1 == d2._rawIdentifier())
 
-    var foundIndex1 = d2.index(forKey: 10)!
+    let foundIndex1 = d2.index(forKey: 10)!
     assert(d2[foundIndex1].0 == 10)
     assert(d2[foundIndex1].1 == 1010)
     assert(identity1 == d1._rawIdentifier())
@@ -960,9 +960,9 @@
   .code {
   do {
     var d = getCOWSlowDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
 
-    var foundIndex1 = d.index(forKey: TestKeyTy(10))!
+    let foundIndex1 = d.index(forKey: TestKeyTy(10))!
     assert(identity1 == d._rawIdentifier())
 
     assert(d[foundIndex1].0 == TestKeyTy(10))
@@ -977,14 +977,14 @@
   }
 
   do {
-    var d1 = getCOWSlowDictionary()
-    var identity1 = d1._rawIdentifier()
+    let d1 = getCOWSlowDictionary()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(identity1 == d1._rawIdentifier())
     assert(identity1 == d2._rawIdentifier())
 
-    var foundIndex1 = d2.index(forKey: TestKeyTy(10))!
+    let foundIndex1 = d2.index(forKey: TestKeyTy(10))!
     assert(d2[foundIndex1].0 == TestKeyTy(10))
     assert(d2[foundIndex1].1.value == 1010)
 
@@ -1003,7 +1003,7 @@
   .code {
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var deleted = d1.removeValue(forKey: 0)
     assert(deleted == nil)
@@ -1018,8 +1018,8 @@
   }
 
   do {
-    var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let d1 = getCOWFastDictionary()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     var deleted = d2.removeValue(forKey: 0)
@@ -1042,7 +1042,7 @@
   .code {
   do {
     var d1 = getCOWSlowDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var deleted = d1.removeValue(forKey: TestKeyTy(0))
     assert(deleted == nil)
@@ -1057,8 +1057,8 @@
   }
 
   do {
-    var d1 = getCOWSlowDictionary()
-    var identity1 = d1._rawIdentifier()
+    let d1 = getCOWSlowDictionary()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     var deleted = d2.removeValue(forKey: TestKeyTy(0))
@@ -1088,7 +1088,7 @@
     d.removeAll()
     // We cannot assert that identity changed, since the new buffer of smaller
     // size can be allocated at the same address as the old one.
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(d.capacity < originalCapacity)
     assert(d.count == 0)
     assert(d[10] == nil)
@@ -1101,7 +1101,7 @@
 
   do {
     var d = getCOWFastDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     let originalCapacity = d.capacity
     assert(d.count == 3)
     assert(d[10]! == 1010)
@@ -1121,13 +1121,13 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
     assert(d1.count == 3)
     assert(d1[10]! == 1010)
 
     var d2 = d1
     d2.removeAll()
-    var identity2 = d2._rawIdentifier()
+    let identity2 = d2._rawIdentifier()
     assert(identity1 == d1._rawIdentifier())
     assert(identity2 != identity1)
     assert(d1.count == 3)
@@ -1142,14 +1142,14 @@
 
   do {
     var d1 = getCOWFastDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
     let originalCapacity = d1.capacity
     assert(d1.count == 3)
     assert(d1[10] == 1010)
 
     var d2 = d1
     d2.removeAll(keepingCapacity: true)
-    var identity2 = d2._rawIdentifier()
+    let identity2 = d2._rawIdentifier()
     assert(identity1 == d1._rawIdentifier())
     assert(identity2 != identity1)
     assert(d1.count == 3)
@@ -1174,7 +1174,7 @@
     d.removeAll()
     // We cannot assert that identity changed, since the new buffer of smaller
     // size can be allocated at the same address as the old one.
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(d.capacity < originalCapacity)
     assert(d.count == 0)
     assert(d[TestKeyTy(10)] == nil)
@@ -1187,7 +1187,7 @@
 
   do {
     var d = getCOWSlowDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     let originalCapacity = d.capacity
     assert(d.count == 3)
     assert(d[TestKeyTy(10)]!.value == 1010)
@@ -1207,13 +1207,13 @@
 
   do {
     var d1 = getCOWSlowDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
     assert(d1.count == 3)
     assert(d1[TestKeyTy(10)]!.value == 1010)
 
     var d2 = d1
     d2.removeAll()
-    var identity2 = d2._rawIdentifier()
+    let identity2 = d2._rawIdentifier()
     assert(identity1 == d1._rawIdentifier())
     assert(identity2 != identity1)
     assert(d1.count == 3)
@@ -1228,14 +1228,14 @@
 
   do {
     var d1 = getCOWSlowDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
     let originalCapacity = d1.capacity
     assert(d1.count == 3)
     assert(d1[TestKeyTy(10)]!.value == 1010)
 
     var d2 = d1
     d2.removeAll(keepingCapacity: true)
-    var identity2 = d2._rawIdentifier()
+    let identity2 = d2._rawIdentifier()
     assert(identity1 == d1._rawIdentifier())
     assert(identity2 != identity1)
     assert(d1.count == 3)
@@ -1252,16 +1252,16 @@
 
 
 DictionaryTestSuite.test("COW.Fast.CountDoesNotReallocate") {
-  var d = getCOWFastDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getCOWFastDictionary()
+  let identity1 = d._rawIdentifier()
 
   assert(d.count == 3)
   assert(identity1 == d._rawIdentifier())
 }
 
 DictionaryTestSuite.test("COW.Slow.CountDoesNotReallocate") {
-  var d = getCOWSlowDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getCOWSlowDictionary()
+  let identity1 = d._rawIdentifier()
 
   assert(d.count == 3)
   assert(identity1 == d._rawIdentifier())
@@ -1269,8 +1269,8 @@
 
 
 DictionaryTestSuite.test("COW.Fast.GenerateDoesNotReallocate") {
-  var d = getCOWFastDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getCOWFastDictionary()
+  let identity1 = d._rawIdentifier()
 
   var iter = d.makeIterator()
   var pairs = Array<(Int, Int)>()
@@ -1282,8 +1282,8 @@
 }
 
 DictionaryTestSuite.test("COW.Slow.GenerateDoesNotReallocate") {
-  var d = getCOWSlowDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getCOWSlowDictionary()
+  let identity1 = d._rawIdentifier()
 
   var iter = d.makeIterator()
   var pairs = Array<(Int, Int)>()
@@ -1296,11 +1296,11 @@
 
 
 DictionaryTestSuite.test("COW.Fast.EqualityTestDoesNotReallocate") {
-  var d1 = getCOWFastDictionary()
-  var identity1 = d1._rawIdentifier()
+  let d1 = getCOWFastDictionary()
+  let identity1 = d1._rawIdentifier()
 
   var d2 = getCOWFastDictionary()
-  var identity2 = d2._rawIdentifier()
+  let identity2 = d2._rawIdentifier()
 
   assert(d1 == d2)
   assert(identity1 == d1._rawIdentifier())
@@ -1313,11 +1313,11 @@
 }
 
 DictionaryTestSuite.test("COW.Slow.EqualityTestDoesNotReallocate") {
-  var d1 = getCOWSlowEquatableDictionary()
-  var identity1 = d1._rawIdentifier()
+  let d1 = getCOWSlowEquatableDictionary()
+  let identity1 = d1._rawIdentifier()
 
   var d2 = getCOWSlowEquatableDictionary()
-  var identity2 = d2._rawIdentifier()
+  let identity2 = d2._rawIdentifier()
 
   assert(d1 == d2)
   assert(identity1 == d1._rawIdentifier())
@@ -1335,7 +1335,7 @@
 
 DictionaryTestSuite.test("COW.Fast.ValuesAccessDoesNotReallocate") {
   var d1 = getCOWFastDictionary()
-  var identity1 = d1._rawIdentifier()
+  let identity1 = d1._rawIdentifier()
   
   assert([1010, 1020, 1030] == d1.values.sorted())
   assert(identity1 == d1._rawIdentifier())
@@ -1347,12 +1347,10 @@
   assert(d1.values[i] == 1010)
   assert(d1[i] == (10, 1010))
   
-#if swift(>=4.0)
   d2.values[i] += 1
   assert(d2.values[i] == 1011)
   assert(d2[10]! == 1011)
   assert(identity1 != d2._rawIdentifier())
-#endif
   
   assert(d1[10]! == 1010)
   assert(identity1 == d1._rawIdentifier())
@@ -1365,8 +1363,8 @@
 }
 
 DictionaryTestSuite.test("COW.Fast.KeysAccessDoesNotReallocate") {
-  var d1 = getCOWFastDictionary()
-  var identity1 = d1._rawIdentifier()
+  let d1 = getCOWFastDictionary()
+  let identity1 = d1._rawIdentifier()
   
   assert([10, 20, 30] == d1.keys.sorted())
 
@@ -1382,7 +1380,7 @@
   { $0 == $1 }
   
   do {
-    var d2: [MinimalHashableValue : Int] = [
+    let d2: [MinimalHashableValue : Int] = [
       MinimalHashableValue(10): 1010,
       MinimalHashableValue(20): 1020,
       MinimalHashableValue(30): 1030,
@@ -1411,9 +1409,7 @@
     // keys.firstIndex(of:) - O(1) bucket + linear search
     MinimalHashableValue.timesEqualEqualWasCalled = 0
     let l = d2.keys.firstIndex(of: lastKey)!
-#if swift(>=4.0)
     expectLE(MinimalHashableValue.timesEqualEqualWasCalled, 4)
-#endif
 
     expectEqual(j, k)
     expectEqual(k, l)
@@ -1447,28 +1443,28 @@
 }
 
 DictionaryTestSuite.test("deleteChainCollision") {
-  var k1 = TestKeyTy(value: 10, hashValue: 0)
-  var k2 = TestKeyTy(value: 20, hashValue: 0)
-  var k3 = TestKeyTy(value: 30, hashValue: 0)
+  let k1 = TestKeyTy(value: 10, hashValue: 0)
+  let k2 = TestKeyTy(value: 20, hashValue: 0)
+  let k3 = TestKeyTy(value: 30, hashValue: 0)
 
   helperDeleteThree(k1, k2, k3)
 }
 
 DictionaryTestSuite.test("deleteChainNoCollision") {
-  var k1 = TestKeyTy(value: 10, hashValue: 0)
-  var k2 = TestKeyTy(value: 20, hashValue: 1)
-  var k3 = TestKeyTy(value: 30, hashValue: 2)
+  let k1 = TestKeyTy(value: 10, hashValue: 0)
+  let k2 = TestKeyTy(value: 20, hashValue: 1)
+  let k3 = TestKeyTy(value: 30, hashValue: 2)
 
   helperDeleteThree(k1, k2, k3)
 }
 
 DictionaryTestSuite.test("deleteChainCollision2") {
-  var k1_0 = TestKeyTy(value: 10, hashValue: 0)
-  var k2_0 = TestKeyTy(value: 20, hashValue: 0)
-  var k3_2 = TestKeyTy(value: 30, hashValue: 2)
-  var k4_0 = TestKeyTy(value: 40, hashValue: 0)
-  var k5_2 = TestKeyTy(value: 50, hashValue: 2)
-  var k6_0 = TestKeyTy(value: 60, hashValue: 0)
+  let k1_0 = TestKeyTy(value: 10, hashValue: 0)
+  let k2_0 = TestKeyTy(value: 20, hashValue: 0)
+  let k3_2 = TestKeyTy(value: 30, hashValue: 2)
+  let k4_0 = TestKeyTy(value: 40, hashValue: 0)
+  let k5_2 = TestKeyTy(value: 50, hashValue: 2)
+  let k6_0 = TestKeyTy(value: 60, hashValue: 0)
 
   var d = Dictionary<TestKeyTy, TestValueTy>(minimumCapacity: 10)
 
@@ -1519,7 +1515,7 @@
   (collisionChains, chainOverlap) in
 
   func check(_ d: Dictionary<TestKeyTy, TestValueTy>) {
-    var keys = Array(d.keys)
+    let keys = Array(d.keys)
     for i in 0..<keys.count {
       for j in 0..<i {
         assert(keys[i] != keys[j])
@@ -1547,7 +1543,7 @@
   }
 
   var d = Dictionary<TestKeyTy, TestValueTy>(minimumCapacity: 30)
-  for i in 1..<300 {
+  for _ in 1..<300 {
     let key = getKey(uniformRandom(collisionChains * chainLength))
     if uniformRandom(chainLength * 2) == 0 {
       d[key] = nil
@@ -1622,13 +1618,13 @@
   }
   do {
     expectCrashLater()
-    var d = Dictionary(uniqueKeysWithValues: [(10, 1010), (20, 1020), (10, 2010)])
+    _ = Dictionary(uniqueKeysWithValues: [(10, 1010), (20, 1020), (10, 2010)])
   }
 }
 
 DictionaryTestSuite.test("init(_:uniquingKeysWith:)") {
   do {
-    var d = Dictionary(
+    let d = Dictionary(
       [(10, 1010), (20, 1020), (30, 1030), (10, 2010)], uniquingKeysWith: min)
     expectEqual(d.count, 3)
     expectEqual(d[10]!, 1010)
@@ -1637,7 +1633,7 @@
     expectNil(d[1111])
   }
   do {
-    var d = Dictionary(
+    let d = Dictionary(
       [(10, 1010), (20, 1020), (30, 1030), (10, 2010)] as [(Int, Int)],
       uniquingKeysWith: +)
     expectEqual(d.count, 3)
@@ -1647,7 +1643,7 @@
     expectNil(d[1111])
   }
   do {
-    var d = Dictionary([(10, 1010), (20, 1020), (30, 1030), (10, 2010)]) {
+    let d = Dictionary([(10, 1010), (20, 1020), (30, 1030), (10, 2010)]) {
       (a, b) in Int("\(a)\(b)")!
     }
     expectEqual(d.count, 3)
@@ -1657,13 +1653,13 @@
     expectNil(d[1111])
   }
   do {
-    var d = Dictionary([(10, 1010), (10, 2010), (10, 3010), (10, 4010)]) { $1 }
+    let d = Dictionary([(10, 1010), (10, 2010), (10, 3010), (10, 4010)]) { $1 }
     expectEqual(d.count, 1)
     expectEqual(d[10]!, 4010)
     expectNil(d[1111])
   }
   do {
-    var d = Dictionary(EmptyCollection<(Int, Int)>(), uniquingKeysWith: min)
+    let d = Dictionary(EmptyCollection<(Int, Int)>(), uniquingKeysWith: min)
     expectEqual(d.count, 0)
     expectNil(d[1111])
   }
@@ -1671,11 +1667,11 @@
   struct TE: Error {}
   do {
     // No duplicate keys, so no error thrown.
-    var d1 = try Dictionary([(10, 1), (20, 2), (30, 3)]) { _, _ in throw TE() }
+    let d1 = try Dictionary([(10, 1), (20, 2), (30, 3)]) { (_,_) in throw TE() }
     expectEqual(d1.count, 3)
     // Duplicate keys, should throw error.
-    var d2 = try Dictionary([(10, 1), (10, 2)]) { _, _ in throw TE() }
-    assertionFailure()
+    _ = try Dictionary([(10, 1), (10, 2)]) { (_,_) in throw TE() }
+    _ = assertionFailure()
   } catch {
     assert(error is TE)
   }
@@ -1704,12 +1700,12 @@
   expectEqual(d1.count, d2.count)
   expectEqual(d1.keys.first, d2.keys.first)
 
-  for (key, value) in d1 {
+  for (key, _) in d1 {
     expectEqual(String(d1[key]!), d2[key]!)
   }
 
   do {
-    var d3: [MinimalHashableValue : Int] = Dictionary(
+    let d3: [MinimalHashableValue : Int] = Dictionary(
       uniqueKeysWithValues: d1.lazy.map { (MinimalHashableValue($0), $1) })
     expectEqual(d3.count, 3)
     MinimalHashableValue.timesEqualEqualWasCalled = 0
@@ -1762,7 +1758,7 @@
 
   // Fill up to the limit, no reallocation.
   d1.merge(stride(from: 50, through: 240, by: 10).lazy.map { ($0, 1000 + $0) },
-    uniquingKeysWith: { _, _ in fatalError() })
+    uniquingKeysWith: { (_,_) in fatalError() })
   expectEqual(24, d1.count)
   expectEqual(24, d1.capacity)
   d1[250] = 1250
@@ -1979,13 +1975,12 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.DictionaryIsCopied") {
-  var (d, nsd) = getBridgedVerbatimDictionaryAndNSMutableDictionary()
-  var identity1 = d._rawIdentifier()
+  let (d, nsd) = getBridgedVerbatimDictionaryAndNSMutableDictionary()
   assert(isCocoaDictionary(d))
 
   // Find an existing key.
   do {
-    var kv = d[d.index(forKey: TestObjCKeyTy(10))!]
+    let kv = d[d.index(forKey: TestObjCKeyTy(10))!]
     assert(kv.0 == TestObjCKeyTy(10))
     assert((kv.1 as! TestObjCValueTy).value == 1010)
   }
@@ -1997,20 +1992,19 @@
 
   // Find an existing key, again.
   do {
-    var kv = d[d.index(forKey: TestObjCKeyTy(10))!]
+    let kv = d[d.index(forKey: TestObjCKeyTy(10))!]
     assert(kv.0 == TestObjCKeyTy(10))
     assert((kv.1 as! TestObjCValueTy).value == 1010)
   }
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.DictionaryIsCopied") {
-  var (d, nsd) = getBridgedNonverbatimDictionaryAndNSMutableDictionary()
-  var identity1 = d._rawIdentifier()
+  let (d, nsd) = getBridgedNonverbatimDictionaryAndNSMutableDictionary()
   assert(isNativeDictionary(d))
 
   // Find an existing key.
   do {
-    var kv = d[d.index(forKey: TestBridgedKeyTy(10))!]
+    let kv = d[d.index(forKey: TestBridgedKeyTy(10))!]
     assert(kv.0 == TestBridgedKeyTy(10))
     assert(kv.1.value == 1010)
   }
@@ -2022,7 +2016,7 @@
 
   // Find an existing key, again.
   do {
-    var kv = d[d.index(forKey: TestBridgedKeyTy(10))!]
+    let kv = d[d.index(forKey: TestBridgedKeyTy(10))!]
     assert(kv.0 == TestBridgedKeyTy(10))
     assert(kv.1.value == 1010)
   }
@@ -2030,13 +2024,13 @@
 
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.NSDictionaryIsRetained") {
-  var nsd: NSDictionary =
+  let nsd: NSDictionary =
     NSDictionary(dictionary:
       getAsNSDictionary([10: 1010, 20: 1020, 30: 1030]))
 
-  var d: [NSObject : AnyObject] = convertNSDictionaryToDictionary(nsd)
+  let d: [NSObject : AnyObject] = convertNSDictionaryToDictionary(nsd)
 
-  var bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
+  let bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
 
   expectEqual(
     unsafeBitCast(nsd, to: Int.self),
@@ -2048,14 +2042,14 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.NSDictionaryIsCopied") {
-  var nsd: NSDictionary =
+  let nsd: NSDictionary =
     NSDictionary(dictionary:
       getAsNSDictionary([10: 1010, 20: 1020, 30: 1030]))
 
-  var d: [TestBridgedKeyTy : TestBridgedValueTy] =
+  let d: [TestBridgedKeyTy : TestBridgedValueTy] =
     convertNSDictionaryToDictionary(nsd)
 
-  var bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
+  let bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
 
   expectNotEqual(
     unsafeBitCast(nsd, to: Int.self),
@@ -2068,19 +2062,19 @@
 
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.ImmutableDictionaryIsRetained") {
-  var nsd: NSDictionary = CustomImmutableNSDictionary(_privateInit: ())
+  let nsd: NSDictionary = CustomImmutableNSDictionary(_privateInit: ())
 
   CustomImmutableNSDictionary.timesCopyWithZoneWasCalled = 0
   CustomImmutableNSDictionary.timesObjectForKeyWasCalled = 0
   CustomImmutableNSDictionary.timesKeyEnumeratorWasCalled = 0
   CustomImmutableNSDictionary.timesCountWasCalled = 0
-  var d: [NSObject : AnyObject] = convertNSDictionaryToDictionary(nsd)
+  let d: [NSObject : AnyObject] = convertNSDictionaryToDictionary(nsd)
   expectEqual(1, CustomImmutableNSDictionary.timesCopyWithZoneWasCalled)
   expectEqual(0, CustomImmutableNSDictionary.timesObjectForKeyWasCalled)
   expectEqual(0, CustomImmutableNSDictionary.timesKeyEnumeratorWasCalled)
   expectEqual(0, CustomImmutableNSDictionary.timesCountWasCalled)
 
-  var bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
+  let bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
   expectEqual(
     unsafeBitCast(nsd, to: Int.self),
     unsafeBitCast(bridgedBack, to: Int.self))
@@ -2091,14 +2085,14 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.ImmutableDictionaryIsCopied") {
-  var nsd: NSDictionary = CustomImmutableNSDictionary(_privateInit: ())
+  let nsd: NSDictionary = CustomImmutableNSDictionary(_privateInit: ())
 
   CustomImmutableNSDictionary.timesCopyWithZoneWasCalled = 0
   CustomImmutableNSDictionary.timesObjectForKeyWasCalled = 0
   CustomImmutableNSDictionary.timesKeyEnumeratorWasCalled = 0
   CustomImmutableNSDictionary.timesCountWasCalled = 0
   TestBridgedValueTy.bridgeOperations = 0
-  var d: [TestBridgedKeyTy : TestBridgedValueTy] =
+  let d: [TestBridgedKeyTy : TestBridgedValueTy] =
     convertNSDictionaryToDictionary(nsd)
   expectEqual(0, CustomImmutableNSDictionary.timesCopyWithZoneWasCalled)
   expectEqual(3, CustomImmutableNSDictionary.timesObjectForKeyWasCalled)
@@ -2106,7 +2100,7 @@
   expectNotEqual(0, CustomImmutableNSDictionary.timesCountWasCalled)
   expectEqual(3, TestBridgedValueTy.bridgeOperations)
 
-  var bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
+  let bridgedBack: NSDictionary = convertDictionaryToNSDictionary(d)
   expectNotEqual(
     unsafeBitCast(nsd, to: Int.self),
     unsafeBitCast(bridgedBack, to: Int.self))
@@ -2118,8 +2112,8 @@
 
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.IndexForKey") {
-  var d = getBridgedVerbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedVerbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isCocoaDictionary(d))
 
   // Find an existing key.
@@ -2143,8 +2137,8 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.IndexForKey") {
-  var d = getBridgedNonverbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedNonverbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isNativeDictionary(d))
 
   // Find an existing key.
@@ -2168,12 +2162,12 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.SubscriptWithIndex") {
-  var d = getBridgedVerbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedVerbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isCocoaDictionary(d))
 
-  var startIndex = d.startIndex
-  var endIndex = d.endIndex
+  let startIndex = d.startIndex
+  let endIndex = d.endIndex
   assert(startIndex != endIndex)
   assert(startIndex < endIndex)
   assert(startIndex <= endIndex)
@@ -2183,7 +2177,7 @@
 
   var pairs = Array<(Int, Int)>()
   for i in d.indices {
-    var (key, value) = d[i]
+    let (key, value) = d[i]
     let kv = ((key as! TestObjCKeyTy).value, (value as! TestObjCValueTy).value)
     pairs += [kv]
   }
@@ -2196,12 +2190,12 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.SubscriptWithIndex") {
-  var d = getBridgedNonverbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedNonverbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isNativeDictionary(d))
 
-  var startIndex = d.startIndex
-  var endIndex = d.endIndex
+  let startIndex = d.startIndex
+  let endIndex = d.endIndex
   assert(startIndex != endIndex)
   assert(startIndex < endIndex)
   assert(startIndex <= endIndex)
@@ -2211,7 +2205,7 @@
 
   var pairs = Array<(Int, Int)>()
   for i in d.indices {
-    var (key, value) = d[i]
+    let (key, value) = d[i]
     let kv = (key.value, value.value)
     pairs += [kv]
   }
@@ -2224,12 +2218,12 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.SubscriptWithIndex_Empty") {
-  var d = getBridgedVerbatimDictionary([:])
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedVerbatimDictionary([:])
+  let identity1 = d._rawIdentifier()
   assert(isCocoaDictionary(d))
 
-  var startIndex = d.startIndex
-  var endIndex = d.endIndex
+  let startIndex = d.startIndex
+  let endIndex = d.endIndex
   assert(startIndex == endIndex)
   assert(!(startIndex < endIndex))
   assert(startIndex <= endIndex)
@@ -2243,12 +2237,12 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.SubscriptWithIndex_Empty") {
-  var d = getBridgedNonverbatimDictionary([:])
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedNonverbatimDictionary([:])
+  let identity1 = d._rawIdentifier()
   assert(isNativeDictionary(d))
 
-  var startIndex = d.startIndex
-  var endIndex = d.endIndex
+  let startIndex = d.startIndex
+  let endIndex = d.endIndex
   assert(startIndex == endIndex)
   assert(!(startIndex < endIndex))
   assert(startIndex <= endIndex)
@@ -2263,7 +2257,7 @@
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.SubscriptWithKey") {
   var d = getBridgedVerbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let identity1 = d._rawIdentifier()
   assert(isCocoaDictionary(d))
 
   // Read existing key-value pairs.
@@ -2280,7 +2274,7 @@
 
   // Insert a new key-value pair.
   d[TestObjCKeyTy(40)] = TestObjCValueTy(2040)
-  var identity2 = d._rawIdentifier()
+  let identity2 = d._rawIdentifier()
   assert(identity1 != identity2)
   assert(isNativeDictionary(d))
   assert(d.count == 4)
@@ -2318,7 +2312,7 @@
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.SubscriptWithKey") {
   var d = getBridgedNonverbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let identity1 = d._rawIdentifier()
   assert(isNativeDictionary(d))
 
   // Read existing key-value pairs.
@@ -2336,7 +2330,7 @@
   // Insert a new key-value pair.
   d[TestBridgedKeyTy(40)] = TestBridgedValueTy(2040)
 
-  var identity2 = d._rawIdentifier()
+  let identity2 = d._rawIdentifier()
   // Storage identity may or may not change depending on allocation behavior.
   // (d is eagerly bridged to a regular uniquely referenced native Dictionary.)
   //assert(identity1 != identity2)
@@ -2379,13 +2373,13 @@
   // Insert a new key-value pair.
   do {
     var d = getBridgedVerbatimDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(isCocoaDictionary(d))
 
-    var oldValue: AnyObject? =
+    let oldValue: AnyObject? =
         d.updateValue(TestObjCValueTy(2040), forKey: TestObjCKeyTy(40))
     assert(oldValue == nil)
-    var identity2 = d._rawIdentifier()
+    let identity2 = d._rawIdentifier()
     assert(identity1 != identity2)
     assert(isNativeDictionary(d))
     assert(d.count == 4)
@@ -2399,14 +2393,14 @@
   // Overwrite a value in existing binding.
   do {
     var d = getBridgedVerbatimDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(isCocoaDictionary(d))
 
-    var oldValue: AnyObject? =
+    let oldValue: AnyObject? =
         d.updateValue(TestObjCValueTy(2010), forKey: TestObjCKeyTy(10))
     assert((oldValue as! TestObjCValueTy).value == 1010)
 
-    var identity2 = d._rawIdentifier()
+    let identity2 = d._rawIdentifier()
     assert(identity1 != identity2)
     assert(isNativeDictionary(d))
     assert(d.count == 3)
@@ -2421,13 +2415,13 @@
   // Insert a new key-value pair.
   do {
     var d = getBridgedNonverbatimDictionary()
-    var identity1 = d._rawIdentifier()
+    // let identity1 = d._rawIdentifier()
     assert(isNativeDictionary(d))
 
-    var oldValue =
+    let oldValue =
         d.updateValue(TestBridgedValueTy(2040), forKey: TestBridgedKeyTy(40))
     assert(oldValue == nil)
-    var identity2 = d._rawIdentifier()
+    // let identity2 = d._rawIdentifier()
     // Storage identity may or may not change depending on allocation behavior.
     // (d is eagerly bridged to a regular uniquely referenced native Dictionary.)
     //assert(identity1 != identity2)
@@ -2443,14 +2437,14 @@
   // Overwrite a value in existing binding.
   do {
     var d = getBridgedNonverbatimDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(isNativeDictionary(d))
 
-    var oldValue =
+    let oldValue =
         d.updateValue(TestBridgedValueTy(2010), forKey: TestBridgedKeyTy(10))!
     assert(oldValue.value == 1010)
 
-    var identity2 = d._rawIdentifier()
+    let identity2 = d._rawIdentifier()
     assert(identity1 == identity2)
     assert(isNativeDictionary(d))
     assert(d.count == 3)
@@ -2464,7 +2458,7 @@
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.RemoveAt") {
   var d = getBridgedVerbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let identity1 = d._rawIdentifier()
   assert(isCocoaDictionary(d))
 
   let foundIndex1 = d.index(forKey: TestObjCKeyTy(10))!
@@ -2484,7 +2478,7 @@
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.RemoveAt")
   .code {
   var d = getBridgedNonverbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let identity1 = d._rawIdentifier()
   assert(isNativeDictionary(d))
 
   let foundIndex1 = d.index(forKey: TestBridgedKeyTy(10))!
@@ -2505,7 +2499,7 @@
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.RemoveValueForKey") {
   do {
     var d = getBridgedVerbatimDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(isCocoaDictionary(d))
 
     var deleted: AnyObject? = d.removeValue(forKey: TestObjCKeyTy(0))
@@ -2515,7 +2509,7 @@
 
     deleted = d.removeValue(forKey: TestObjCKeyTy(10))
     assert((deleted as! TestObjCValueTy).value == 1010)
-    var identity2 = d._rawIdentifier()
+    let identity2 = d._rawIdentifier()
     assert(identity1 != identity2)
     assert(isNativeDictionary(d))
     assert(d.count == 2)
@@ -2528,7 +2522,7 @@
 
   do {
     var d1 = getBridgedVerbatimDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(isCocoaDictionary(d1))
@@ -2543,7 +2537,7 @@
 
     deleted = d2.removeValue(forKey: TestObjCKeyTy(10))
     assert((deleted as! TestObjCValueTy).value == 1010)
-    var identity2 = d2._rawIdentifier()
+    let identity2 = d2._rawIdentifier()
     assert(identity1 != identity2)
     assert(isCocoaDictionary(d1))
     assert(isNativeDictionary(d2))
@@ -2565,7 +2559,7 @@
   .code {
   do {
     var d = getBridgedNonverbatimDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(isNativeDictionary(d))
 
     var deleted = d.removeValue(forKey: TestBridgedKeyTy(0))
@@ -2575,7 +2569,7 @@
 
     deleted = d.removeValue(forKey: TestBridgedKeyTy(10))
     assert(deleted!.value == 1010)
-    var identity2 = d._rawIdentifier()
+    let identity2 = d._rawIdentifier()
     assert(identity1 == identity2)
     assert(isNativeDictionary(d))
     assert(d.count == 2)
@@ -2588,7 +2582,7 @@
 
   do {
     var d1 = getBridgedNonverbatimDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
 
     var d2 = d1
     assert(isNativeDictionary(d1))
@@ -2603,7 +2597,7 @@
 
     deleted = d2.removeValue(forKey: TestBridgedKeyTy(10))
     assert(deleted!.value == 1010)
-    var identity2 = d2._rawIdentifier()
+    let identity2 = d2._rawIdentifier()
     assert(identity1 != identity2)
     assert(isNativeDictionary(d1))
     assert(isNativeDictionary(d2))
@@ -2625,7 +2619,7 @@
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.RemoveAll") {
   do {
     var d = getBridgedVerbatimDictionary([:])
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(isCocoaDictionary(d))
     assert(d.count == 0)
 
@@ -2636,7 +2630,7 @@
 
   do {
     var d = getBridgedVerbatimDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(isCocoaDictionary(d))
     let originalCapacity = d.count
     assert(d.count == 3)
@@ -2651,7 +2645,7 @@
 
   do {
     var d = getBridgedVerbatimDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(isCocoaDictionary(d))
     let originalCapacity = d.count
     assert(d.count == 3)
@@ -2666,7 +2660,7 @@
 
   do {
     var d1 = getBridgedVerbatimDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
     assert(isCocoaDictionary(d1))
     let originalCapacity = d1.count
     assert(d1.count == 3)
@@ -2674,7 +2668,7 @@
 
     var d2 = d1
     d2.removeAll()
-    var identity2 = d2._rawIdentifier()
+    let identity2 = d2._rawIdentifier()
     assert(identity1 == d1._rawIdentifier())
     assert(identity2 != identity1)
     assert(d1.count == 3)
@@ -2686,7 +2680,7 @@
 
   do {
     var d1 = getBridgedVerbatimDictionary()
-    var identity1 = d1._rawIdentifier()
+    let identity1 = d1._rawIdentifier()
     assert(isCocoaDictionary(d1))
     let originalCapacity = d1.count
     assert(d1.count == 3)
@@ -2694,7 +2688,7 @@
 
     var d2 = d1
     d2.removeAll(keepingCapacity: true)
-    var identity2 = d2._rawIdentifier()
+    let identity2 = d2._rawIdentifier()
     assert(identity1 == d1._rawIdentifier())
     assert(identity2 != identity1)
     assert(d1.count == 3)
@@ -2708,7 +2702,7 @@
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.RemoveAll") {
   do {
     var d = getBridgedNonverbatimDictionary([:])
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(isNativeDictionary(d))
     assert(d.count == 0)
 
@@ -2719,7 +2713,7 @@
 
   do {
     var d = getBridgedNonverbatimDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(isNativeDictionary(d))
     let originalCapacity = d.count
     assert(d.count == 3)
@@ -2734,7 +2728,7 @@
 
   do {
     var d = getBridgedNonverbatimDictionary()
-    var identity1 = d._rawIdentifier()
+    let identity1 = d._rawIdentifier()
     assert(isNativeDictionary(d))
     let originalCapacity = d.count
     assert(d.count == 3)
@@ -2748,8 +2742,8 @@
   }
 
   do {
-    var d1 = getBridgedNonverbatimDictionary()
-    var identity1 = d1._rawIdentifier()
+    let d1 = getBridgedNonverbatimDictionary()
+    let identity1 = d1._rawIdentifier()
     assert(isNativeDictionary(d1))
     let originalCapacity = d1.count
     assert(d1.count == 3)
@@ -2757,7 +2751,7 @@
 
     var d2 = d1
     d2.removeAll()
-    var identity2 = d2._rawIdentifier()
+    let identity2 = d2._rawIdentifier()
     assert(identity1 == d1._rawIdentifier())
     assert(identity2 != identity1)
     assert(d1.count == 3)
@@ -2768,8 +2762,8 @@
   }
 
   do {
-    var d1 = getBridgedNonverbatimDictionary()
-    var identity1 = d1._rawIdentifier()
+    let d1 = getBridgedNonverbatimDictionary()
+    let identity1 = d1._rawIdentifier()
     assert(isNativeDictionary(d1))
     let originalCapacity = d1.count
     assert(d1.count == 3)
@@ -2777,7 +2771,7 @@
 
     var d2 = d1
     d2.removeAll(keepingCapacity: true)
-    var identity2 = d2._rawIdentifier()
+    let identity2 = d2._rawIdentifier()
     assert(identity1 == d1._rawIdentifier())
     assert(identity2 != identity1)
     assert(d1.count == 3)
@@ -2790,8 +2784,8 @@
 
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.Count") {
-  var d = getBridgedVerbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedVerbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isCocoaDictionary(d))
 
   assert(d.count == 3)
@@ -2799,8 +2793,8 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.Count") {
-  var d = getBridgedNonverbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedNonverbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isNativeDictionary(d))
 
   assert(d.count == 3)
@@ -2809,8 +2803,8 @@
 
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.Generate") {
-  var d = getBridgedVerbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedVerbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isCocoaDictionary(d))
 
   var iter = d.makeIterator()
@@ -2827,8 +2821,8 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.Generate") {
-  var d = getBridgedNonverbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedNonverbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isNativeDictionary(d))
 
   var iter = d.makeIterator()
@@ -2845,8 +2839,8 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.Generate_Empty") {
-  var d = getBridgedVerbatimDictionary([:])
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedVerbatimDictionary([:])
+  let identity1 = d._rawIdentifier()
   assert(isCocoaDictionary(d))
 
   var iter = d.makeIterator()
@@ -2861,8 +2855,8 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.Generate_Empty") {
-  var d = getBridgedNonverbatimDictionary([:])
-  var identity1 = d._rawIdentifier()
+  let d = getBridgedNonverbatimDictionary([:])
+  let identity1 = d._rawIdentifier()
   assert(isNativeDictionary(d))
 
   var iter = d.makeIterator()
@@ -2878,8 +2872,8 @@
 
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.Generate_Huge") {
-  var d = getHugeBridgedVerbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getHugeBridgedVerbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isCocoaDictionary(d))
 
   var iter = d.makeIterator()
@@ -2900,8 +2894,8 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.Generate_Huge") {
-  var d = getHugeBridgedNonverbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getHugeBridgedNonverbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isNativeDictionary(d))
 
   var iter = d.makeIterator()
@@ -2927,8 +2921,8 @@
   // Add an autorelease pool because ParallelArrayDictionary autoreleases
   // values in objectForKey.
 
-  var d = getParallelArrayBridgedVerbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getParallelArrayBridgedVerbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isCocoaDictionary(d))
 
   var iter = d.makeIterator()
@@ -2937,7 +2931,7 @@
     let kv = ((key as! TestObjCKeyTy).value, (value as! TestObjCValueTy).value)
     pairs.append(kv)
   }
-  var expectedPairs = [ (10, 1111), (20, 1111), (30, 1111), (40, 1111) ]
+  let expectedPairs = [ (10, 1111), (20, 1111), (30, 1111), (40, 1111) ]
   assert(equalsUnordered(pairs, expectedPairs))
   assert(iter.next() == nil)
   assert(iter.next() == nil)
@@ -2951,8 +2945,8 @@
   // Add an autorelease pool because ParallelArrayDictionary autoreleases
   // values in objectForKey.
 
-  var d = getParallelArrayBridgedNonverbatimDictionary()
-  var identity1 = d._rawIdentifier()
+  let d = getParallelArrayBridgedNonverbatimDictionary()
+  let identity1 = d._rawIdentifier()
   assert(isNativeDictionary(d))
 
   var iter = d.makeIterator()
@@ -2961,7 +2955,7 @@
     let kv = (key.value, value.value)
     pairs.append(kv)
   }
-  var expectedPairs = [ (10, 1111), (20, 1111), (30, 1111), (40, 1111) ]
+  let expectedPairs = [ (10, 1111), (20, 1111), (30, 1111), (40, 1111) ]
   assert(equalsUnordered(pairs, expectedPairs))
   assert(iter.next() == nil)
   assert(iter.next() == nil)
@@ -2972,8 +2966,8 @@
 
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.EqualityTest_Empty") {
-  var d1 = getBridgedVerbatimEquatableDictionary([:])
-  var identity1 = d1._rawIdentifier()
+  let d1 = getBridgedVerbatimEquatableDictionary([:])
+  let identity1 = d1._rawIdentifier()
   assert(isCocoaDictionary(d1))
 
   var d2 = getBridgedVerbatimEquatableDictionary([:])
@@ -2998,12 +2992,12 @@
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.EqualityTest_Empty") {
-  var d1 = getBridgedNonverbatimEquatableDictionary([:])
-  var identity1 = d1._rawIdentifier()
+  let d1 = getBridgedNonverbatimEquatableDictionary([:])
+  let identity1 = d1._rawIdentifier()
   assert(isNativeDictionary(d1))
 
   var d2 = getBridgedNonverbatimEquatableDictionary([:])
-  var identity2 = d2._rawIdentifier()
+  let identity2 = d2._rawIdentifier()
   assert(isNativeDictionary(d2))
   assert(identity1 != identity2)
 
@@ -3111,7 +3105,7 @@
 
 
 DictionaryTestSuite.test("BridgedFromObjC.Verbatim.ArrayOfDictionaries") {
-  var nsa = NSMutableArray()
+  let nsa = NSMutableArray()
   for i in 0..<3 {
     nsa.add(
         getAsNSDictionary([10: 1010 + i, 20: 1020 + i, 30: 1030 + i]))
@@ -3119,20 +3113,20 @@
 
   var a = nsa as [AnyObject] as! [Dictionary<NSObject, AnyObject>]
   for i in 0..<3 {
-    var d = a[i]
+    let d = a[i]
     var iter = d.makeIterator()
     var pairs = Array<(Int, Int)>()
     while let (key, value) = iter.next() {
       let kv = ((key as! TestObjCKeyTy).value, (value as! TestObjCValueTy).value)
       pairs.append(kv)
     }
-    var expectedPairs = [ (10, 1010 + i), (20, 1020 + i), (30, 1030 + i) ]
+    let expectedPairs = [ (10, 1010 + i), (20, 1020 + i), (30, 1030 + i) ]
     assert(equalsUnordered(pairs, expectedPairs))
   }
 }
 
 DictionaryTestSuite.test("BridgedFromObjC.Nonverbatim.ArrayOfDictionaries") {
-  var nsa = NSMutableArray()
+  let nsa = NSMutableArray()
   for i in 0..<3 {
     nsa.add(
         getAsNSDictionary([10: 1010 + i, 20: 1020 + i, 30: 1030 + i]))
@@ -3140,14 +3134,14 @@
 
   var a = nsa as [AnyObject] as! [Dictionary<TestBridgedKeyTy, TestBridgedValueTy>]
   for i in 0..<3 {
-    var d = a[i]
+    let d = a[i]
     var iter = d.makeIterator()
     var pairs = Array<(Int, Int)>()
     while let (key, value) = iter.next() {
       let kv = (key.value, value.value)
       pairs.append(kv)
     }
-    var expectedPairs = [ (10, 1010 + i), (20, 1020 + i), (30, 1030 + i) ]
+    let expectedPairs = [ (10, 1010 + i), (20, 1020 + i), (30, 1030 + i) ]
     assert(equalsUnordered(pairs, expectedPairs))
   }
 }
@@ -3207,7 +3201,7 @@
   // for mismatched key types.
   expectNil(d.object(forKey: TestObjCInvalidKeyTy()))
 
-  for i in 0..<3 {
+  for _ in 0..<3 {
     expectEqual(idValue10, unsafeBitCast(
       d.object(forKey: TestObjCKeyTy(10)).map { $0 as AnyObject }, to: UInt.self))
 
@@ -3226,7 +3220,7 @@
 
   var capturedIdentityPairs = Array<(UInt, UInt)>()
 
-  for i in 0..<3 {
+  for _ in 0..<3 {
     let enumerator = d.keyEnumerator()
 
     var dataPairs = Array<(Int, Int)>()
@@ -3360,10 +3354,10 @@
   // then call getObjects:andKeys:count: via a shim in
   // StdlibUnittestFoundationExtras.
   typealias UnmanagedPointer = UnsafeMutablePointer<Unmanaged<AnyObject>>
-  var keys = UnmanagedPointer.allocate(capacity: storageSize)
-  keys.initialize(to: Unmanaged.passUnretained(canary), count: storageSize)
-  var values = UnmanagedPointer.allocate(capacity: storageSize)
-  values.initialize(to: Unmanaged.passUnretained(canary), count: storageSize)
+  let keys = UnmanagedPointer.allocate(capacity: storageSize)
+  keys.initialize(repeating: Unmanaged.passUnretained(canary), count: storageSize)
+  let values = UnmanagedPointer.allocate(capacity: storageSize)
+  values.initialize(repeating: Unmanaged.passUnretained(canary), count: storageSize)
   keys.withMemoryRebound(to: AnyObject.self, capacity: storageSize) { k in
     values.withMemoryRebound(to: AnyObject.self, capacity: storageSize) { v in
       dictionary.available_getObjects(
@@ -3656,7 +3650,6 @@
   d[TestObjCKeyTy(10)] = TestObjCValueTy(1010)
   d[TestObjCKeyTy(20)] = TestObjCValueTy(1020)
   d[TestObjCKeyTy(30)] = TestObjCValueTy(1030)
-  let nsd: NSDictionary = d as NSDictionary
 
   checkDictionaryFastEnumerationFromSwift(
     [ (10, 1010), (20, 1020), (30, 1030) ],
@@ -3767,7 +3760,7 @@
   d[TestBridgedKeyTy(30)] = TestBridgedValueTy(1030)
 
   do {
-    var dOO = d as! Dictionary<NSObject, AnyObject>
+    var dOO = d as Dictionary<NSObject, AnyObject>
 
     assert(dOO.count == 3)
     var v: AnyObject? = dOO[TestObjCKeyTy(10)]
@@ -3781,7 +3774,7 @@
   }
 
   do {
-    var dOV = d as! Dictionary<NSObject, TestBridgedValueTy>
+    var dOV = d as Dictionary<NSObject, TestBridgedValueTy>
 
     assert(dOV.count == 3)
     var v = dOV[TestObjCKeyTy(10)]
@@ -3879,7 +3872,7 @@
 
   // Unsuccessful downcast
   d["hello" as NSString] = 17 as NSNumber
-  if let dCC
+  if let _
        = _dictionaryDownCastConditional(d) as Dictionary<TestObjCKeyTy, TestObjCValueTy>? {
     assert(false)
   }
@@ -3908,7 +3901,7 @@
 
   // Unsuccessful downcast
   d["hello" as NSString] = 17 as NSNumber
-  if let dCC = d as? Dictionary<TestObjCKeyTy, TestObjCValueTy> {
+  if d is Dictionary<TestObjCKeyTy, TestObjCValueTy> {
     assert(false)
   }
 }
@@ -4071,15 +4064,15 @@
 
   // Unsuccessful downcasts
   d["hello" as NSString] = 17 as NSNumber
-  if let dCV
+  if let _
        = _dictionaryBridgeFromObjectiveCConditional(d) as Dictionary<TestObjCKeyTy, TestBridgedValueTy>?{
     assert(false)
   }
-  if let dVC
+  if let _
        = _dictionaryBridgeFromObjectiveCConditional(d) as Dictionary<TestBridgedKeyTy, TestObjCValueTy>?{
     assert(false)
   }
-  if let dVV
+  if let _
        = _dictionaryBridgeFromObjectiveCConditional(d) as Dictionary<TestBridgedKeyTy, TestBridgedValueTy>?{
     assert(false)
   }
@@ -4138,13 +4131,13 @@
 
   // Unsuccessful downcasts
   d["hello" as NSString] = 17 as NSNumber
-  if let dCV = d as? Dictionary<TestObjCKeyTy, TestBridgedValueTy> {
+  if d is Dictionary<TestObjCKeyTy, TestBridgedValueTy> {
     assert(false)
   }
-  if let dVC = d as? Dictionary<TestBridgedKeyTy, TestObjCValueTy> {
+  if d is Dictionary<TestBridgedKeyTy, TestObjCValueTy> {
     assert(false)
   }
-  if let dVV = d as? Dictionary<TestBridgedKeyTy, TestBridgedValueTy> {
+  if d is Dictionary<TestBridgedKeyTy, TestBridgedValueTy> {
     assert(false)
   }
 }
@@ -4167,11 +4160,11 @@
 
 DictionaryDerivedAPIs.test("isEmpty") {
   do {
-    var empty = Dictionary<Int, Int>()
+    let empty = Dictionary<Int, Int>()
     expectTrue(empty.isEmpty)
   }
   do {
-    var d = getDerivedAPIsDictionary()
+    let d = getDerivedAPIsDictionary()
     expectFalse(d.isEmpty)
   }
 }
@@ -4235,26 +4228,26 @@
 
 DictionaryDerivedAPIs.test("isEmpty/ImplementationIsCustomized") {
   do {
-    var d = getMockDictionaryWithCustomCount(count: 0)
+    let d = getMockDictionaryWithCustomCount(count: 0)
     MockDictionaryWithCustomCount.timesCountWasCalled = 0
     expectTrue(d.isEmpty)
     expectEqual(1, MockDictionaryWithCustomCount.timesCountWasCalled)
   }
   do {
-    var d = getMockDictionaryWithCustomCount(count: 0)
+    let d = getMockDictionaryWithCustomCount(count: 0)
     MockDictionaryWithCustomCount.timesCountWasCalled = 0
     expectTrue(callGenericIsEmpty(d))
     expectEqual(1, MockDictionaryWithCustomCount.timesCountWasCalled)
   }
 
   do {
-    var d = getMockDictionaryWithCustomCount(count: 4)
+    let d = getMockDictionaryWithCustomCount(count: 4)
     MockDictionaryWithCustomCount.timesCountWasCalled = 0
     expectFalse(d.isEmpty)
     expectEqual(1, MockDictionaryWithCustomCount.timesCountWasCalled)
   }
   do {
-    var d = getMockDictionaryWithCustomCount(count: 4)
+    let d = getMockDictionaryWithCustomCount(count: 4)
     MockDictionaryWithCustomCount.timesCountWasCalled = 0
     expectFalse(callGenericIsEmpty(d))
     expectEqual(1, MockDictionaryWithCustomCount.timesCountWasCalled)
@@ -4264,21 +4257,21 @@
 
 DictionaryDerivedAPIs.test("keys") {
   do {
-    var empty = Dictionary<Int, Int>()
-    var keys = Array(empty.keys)
+    let empty = Dictionary<Int, Int>()
+    let keys = Array(empty.keys)
     expectTrue(equalsUnordered(keys, []))
   }
   do {
-    var d = getDerivedAPIsDictionary()
-    var keys = Array(d.keys)
+    let d = getDerivedAPIsDictionary()
+    let keys = Array(d.keys)
     expectTrue(equalsUnordered(keys, [ 10, 20, 30 ]))
   }
 }
 
 DictionaryDerivedAPIs.test("values") {
   do {
-    var empty = Dictionary<Int, Int>()
-    var values = Array(empty.values)
+    let empty = Dictionary<Int, Int>()
+    let values = Array(empty.values)
     expectTrue(equalsUnordered(values, []))
   }
   do {
@@ -4352,7 +4345,7 @@
 }
 
 ObjCThunks.test("Array/Accept") {
-  var helper = ObjCThunksHelper()
+  let helper = ObjCThunksHelper()
 
   do {
     helper.acceptArrayBridgedVerbatim(
@@ -4368,7 +4361,7 @@
 }
 
 ObjCThunks.test("Array/Return") {
-  var helper = ObjCThunksHelper()
+  let helper = ObjCThunksHelper()
 
   do {
     let a = helper.returnArrayBridgedVerbatim()
@@ -4390,7 +4383,7 @@
 }
 
 ObjCThunks.test("Dictionary/Accept") {
-  var helper = ObjCThunksHelper()
+  let helper = ObjCThunksHelper()
 
   do {
     helper.acceptDictionaryBridgedVerbatim(
@@ -4411,7 +4404,7 @@
 }
 
 ObjCThunks.test("Dictionary/Return") {
-  var helper = ObjCThunksHelper()
+  let helper = ObjCThunksHelper()
 
   do {
     let d = helper.returnDictionaryBridgedVerbatim()
@@ -4445,7 +4438,7 @@
 
 DictionaryTestSuite.test("mutationDoesNotAffectIterator/subscript/store") {
   var dict = getDerivedAPIsDictionary()
-  var iter = dict.makeIterator()
+  let iter = dict.makeIterator()
   dict[10] = 1011
 
   expectEqualsUnordered(
@@ -4455,7 +4448,7 @@
 
 DictionaryTestSuite.test("mutationDoesNotAffectIterator/removeValueForKey,1") {
   var dict = getDerivedAPIsDictionary()
-  var iter = dict.makeIterator()
+  let iter = dict.makeIterator()
   expectOptionalEqual(1010, dict.removeValue(forKey: 10))
 
   expectEqualsUnordered(
@@ -4465,7 +4458,7 @@
 
 DictionaryTestSuite.test("mutationDoesNotAffectIterator/removeValueForKey,all") {
   var dict = getDerivedAPIsDictionary()
-  var iter = dict.makeIterator()
+  let iter = dict.makeIterator()
   expectOptionalEqual(1010, dict.removeValue(forKey: 10))
   expectOptionalEqual(1020, dict.removeValue(forKey: 20))
   expectOptionalEqual(1030, dict.removeValue(forKey: 30))
@@ -4478,7 +4471,7 @@
 DictionaryTestSuite.test(
   "mutationDoesNotAffectIterator/removeAll,keepingCapacity=false") {
   var dict = getDerivedAPIsDictionary()
-  var iter = dict.makeIterator()
+  let iter = dict.makeIterator()
   dict.removeAll(keepingCapacity: false)
 
   expectEqualsUnordered(
@@ -4489,7 +4482,7 @@
 DictionaryTestSuite.test(
   "mutationDoesNotAffectIterator/removeAll,keepingCapacity=true") {
   var dict = getDerivedAPIsDictionary()
-  var iter = dict.makeIterator()
+  let iter = dict.makeIterator()
   dict.removeAll(keepingCapacity: true)
 
   expectEqualsUnordered(
@@ -4573,13 +4566,13 @@
   // This test will only fail in address sanitizer.
   var dict = [0:10]
   do {
-    var bridged: NSDictionary = dict as NSDictionary
+    let bridged: NSDictionary = dict as NSDictionary
     expectEqual(10, bridged[0 as NSNumber] as! Int)
   }
 
   dict[0] = 11
   do {
-    var bridged: NSDictionary = dict as NSDictionary
+    let bridged: NSDictionary = dict as NSDictionary
     expectEqual(11, bridged[0 as NSNumber] as! Int)
   }
 }
@@ -4587,13 +4580,13 @@
 DictionaryTestSuite.test("getObjects:andKeys:count:") {
   let native = [1: "one", 2: "two"] as Dictionary<Int, String>
   let d = native as NSDictionary
-  var keys = UnsafeMutableBufferPointer(
+  let keys = UnsafeMutableBufferPointer(
     start: UnsafeMutablePointer<NSNumber>.allocate(capacity: 2), count: 2)
-  var values = UnsafeMutableBufferPointer(
+  let values = UnsafeMutableBufferPointer(
     start: UnsafeMutablePointer<NSString>.allocate(capacity: 2), count: 2)
-  var kp = AutoreleasingUnsafeMutablePointer<AnyObject?>(keys.baseAddress!)
-  var vp = AutoreleasingUnsafeMutablePointer<AnyObject?>(values.baseAddress!)
-  var null: AutoreleasingUnsafeMutablePointer<AnyObject?>?
+  let kp = AutoreleasingUnsafeMutablePointer<AnyObject?>(keys.baseAddress!)
+  let vp = AutoreleasingUnsafeMutablePointer<AnyObject?>(values.baseAddress!)
+  let null: AutoreleasingUnsafeMutablePointer<AnyObject?>? = nil
 
   let expectedKeys: [NSNumber]
   let expectedValues: [NSString]
diff --git a/validation-test/stdlib/String.swift b/validation-test/stdlib/String.swift
index e4060c7..2921ed9 100644
--- a/validation-test/stdlib/String.swift
+++ b/validation-test/stdlib/String.swift
@@ -10,6 +10,7 @@
 // RUN: %target-run %t/String
 // REQUIRES: executable_test
 // XFAIL: interpret
+// <rdar://problem/41372546> Migrate validation-test/stdlib/String.swift off Swift 3
 
 import StdlibUnittest
 import StdlibCollectionUnittest
diff --git a/validation-test/stdlib/XCTest.swift b/validation-test/stdlib/XCTest.swift
index 59d683e..b8494ab 100644
--- a/validation-test/stdlib/XCTest.swift
+++ b/validation-test/stdlib/XCTest.swift
@@ -1,6 +1,5 @@
 // RUN: rm -rf %t ; mkdir -p %t
-// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
-// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
+// RUN: %target-build-swift %s -o %t/a.out -swift-version 4 && %target-run %t/a.out
 
 // REQUIRES: executable_test
 // REQUIRES: objc_interop
@@ -23,33 +22,20 @@
 
 func execute(observers: [XCTestObservation] = [], _ run: () -> Void) {
   for observer in observers {
-#if swift(>=4.0)
     XCTestObservationCenter.shared.addTestObserver(observer)
-#else
-    XCTestObservationCenter.shared().addTestObserver(observer)
-#endif
-
   }
 
   run()
 
   for observer in observers {
-#if swift(>=4.0)
     XCTestObservationCenter.shared.removeTestObserver(observer)
-#else
-    XCTestObservationCenter.shared().removeTestObserver(observer)
-#endif
   }
 }
 
 class FailureDescriptionObserver: NSObject, XCTestObservation {
   var failureDescription: String?
 
-#if swift(>=4.0)
   typealias LineNumber=Int
-#else
-  typealias LineNumber=UInt
-#endif
 
   func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: LineNumber) {
     failureDescription = description
@@ -521,13 +507,8 @@
     XCTestTestSuite.test("XCUIElement/typeKey(_:modifierFlags:)") {
         class TypeKeyTestCase: XCTestCase {
             func testTypeKey() {
-                #if swift(>=4.0)
-                    XCUIApplication().typeKey("a", modifierFlags: [])
-                    XCUIApplication().typeKey(.delete, modifierFlags: [])
-                #else
-                    XCUIApplication().typeKey("a", modifierFlags: [])
-                    XCUIApplication().typeKey(XCUIKeyboardKeyDelete, modifierFlags: [])
-                #endif
+                XCUIApplication().typeKey("a", modifierFlags: [])
+                XCUIApplication().typeKey(.delete, modifierFlags: [])
             }
         }
     }