Skip to content

[NOMERGE] Build the standard library in Swift 4 mode #10981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ function(_compile_swift_files
endif()
endif()

# Force swift 3 compatibility mode for Standard Library and overlay.
if (SWIFTFILE_IS_STDLIB OR SWIFTFILE_IS_SDK_OVERLAY)
list(APPEND swift_flags "-swift-version" "3")
if (SWIFTFILE_IS_STDLIB)
list(APPEND swift_flags "-swift-version" "4")
endif()

if(SWIFTFILE_IS_SDK_OVERLAY)
list(APPEND swift_flags "-swift-version" "3")
list(APPEND swift_flags "-autolink-force-load")
endif()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ self.test("\(testNamePrefix)._preprocessingPass/semantics") {
let s = makeWrappedSequence(test.sequence.map(OpaqueValue.init))
var wasInvoked = false
let result = s._preprocessingPass {
(sequence) -> OpaqueValue<Int> in
() -> OpaqueValue<Int> in
wasInvoked = true

expectEqualSequence(
Expand All @@ -1945,7 +1945,7 @@ self.test("\(testNamePrefix)._preprocessingPass/semantics") {
var result: OpaqueValue<Int>?
do {
result = try s._preprocessingPass {
_ -> OpaqueValue<Int> in
() -> OpaqueValue<Int> in
wasInvoked = true
throw TestError.error2
}
Expand Down
10 changes: 7 additions & 3 deletions stdlib/private/StdlibUnittest/StdlibCoreExtras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import Foundation
// useful in tests, and stdlib does not have such facilities yet.
//

func findSubstring(_ haystack: Substring, _ needle: String) -> String.Index? {
return findSubstring(String(haystack._ephemeralContent), needle)
}

func findSubstring(_ string: String, _ substring: String) -> String.Index? {
if substring.isEmpty {
return string.startIndex
Expand All @@ -48,7 +52,7 @@ func findSubstring(_ string: String, _ substring: String) -> String.Index? {
while true {
if needleIndex == needle.endIndex {
// if we hit the end of the search string, we found the needle
return matchStartIndex.samePosition(in: string)
return matchStartIndex
}
if matchIndex == haystack.endIndex {
// if we hit the end of the string before finding the end of the needle,
Expand Down Expand Up @@ -149,7 +153,7 @@ extension MutableCollection
var f = subrange.lowerBound
var l = index(before: subrange.upperBound)
while f < l {
swap(&self[f], &self[l])
swapAt(f, l)
formIndex(after: &f)
formIndex(before: &l)
}
Expand Down Expand Up @@ -195,7 +199,7 @@ extension MutableCollection
repeat {
formIndex(before: &j)
} while !(elementAtBeforeI < self[j])
swap(&self[beforeI], &self[j])
swapAt(beforeI, j)
_reverseSubrange(i..<endIndex)
return .success
}
Expand Down
28 changes: 11 additions & 17 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ struct _ParentProcess {
parameter: Int?
) -> (anyExpectFailed: Bool, seenExpectCrash: Bool,
status: ProcessTerminationStatus?,
crashStdout: [String], crashStderr: [String]) {
crashStdout: [Substring], crashStderr: [Substring]) {
if _pid == nil {
_spawnChild()
}
Expand All @@ -790,15 +790,15 @@ struct _ParentProcess {
var stderrSeenCrashDelimiter = false
var stdoutEnd = false
var stderrEnd = false
var capturedCrashStdout: [String] = []
var capturedCrashStderr: [String] = []
var capturedCrashStdout: [Substring] = []
var capturedCrashStderr: [Substring] = []
var anyExpectFailedInChild = false

func processLine(_ line: String, isStdout: Bool) -> (done: Bool, Void) {
var line = line
var line = line[...]
if let index = findSubstring(line, _stdlibUnittestStreamPrefix) {
let controlMessage =
line[index..<line.endIndex]._split(separator: ";")
line[index..<line.endIndex].split(separator: ";")
switch controlMessage[1] {
case "expectCrash":
if isStdout {
Expand Down Expand Up @@ -830,7 +830,7 @@ struct _ParentProcess {
if stderrSeenCrashDelimiter {
capturedCrashStderr.append(line)
if findSubstring(line, _crashedPrefix) != nil {
line = "OK: saw expected \"\(line.lowercased())\""
line = "OK: saw expected \"\(line.lowercased())\""[...]
}
}
}
Expand Down Expand Up @@ -937,8 +937,8 @@ struct _ParentProcess {

var expectCrash = false
var childTerminationStatus: ProcessTerminationStatus?
var crashStdout: [String] = []
var crashStderr: [String] = []
var crashStdout: [Substring] = []
var crashStderr: [Substring] = []
if _runTestsInProcess {
if t.stdinText != nil {
print("The test \(fullTestName) requires stdin input and can't be run in-process, marking as failed")
Expand Down Expand Up @@ -2380,11 +2380,11 @@ public func expectEqualsUnordered<
Expected.Iterator.Element == Actual.Iterator.Element {

let x: [Expected.Iterator.Element] =
expected.sorted(by: compose(compare, { $0.isLT() }))
expected.sorted { compare($0, $1).isLT() }
let y: [Actual.Iterator.Element] =
actual.sorted(by: compose(compare, { $0.isLT() }))
actual.sorted { compare($0, $1).isLT() }
expectEqualSequence(
x, y, ${trace}, sameValue: compose(compare, { $0.isEQ() }))
x, y, ${trace}, sameValue: { compare($0, $1).isEQ() })
}

public func expectEqualsUnordered<
Expand Down Expand Up @@ -2534,12 +2534,6 @@ public func expectEqualUnicodeScalars(
}
}

func compose<A, B, C>(_ f: @escaping (A) -> B, _ g: @escaping (B) -> C) -> (A) -> C {
return { a in
return g(f(a))
}
}

// ${'Local Variables'}:
// eval: (read-only-mode 1)
// End:
10 changes: 6 additions & 4 deletions stdlib/public/core/DoubleWidth.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,13 @@ public struct DoubleWidth<Base : FixedWidthInteger> :

lhs._storage.low >>= rhs._storage.low
if Base.bitWidth > rhs._storage.low {
lhs._storage.low |= Low(extendingOrTruncating: lhs._storage.high <<
numericCast(numericCast(Base.bitWidth) - rhs._storage.low))
lhs._storage.low |= Low(
extendingOrTruncating:
lhs._storage.high << (numericCast(Base.bitWidth) - rhs._storage.low))
} else {
lhs._storage.low |= Low(extendingOrTruncating: lhs._storage.high >>
numericCast(rhs._storage.low - numericCast(Base.bitWidth)))
lhs._storage.low |= Low(
extendingOrTruncating: lhs._storage.high >>
(rhs._storage.low - numericCast(Base.bitWidth)))
}
lhs._storage.high >>= High(extendingOrTruncating: rhs._storage.low)
}
Expand Down
38 changes: 19 additions & 19 deletions stdlib/public/core/ExistentialCollection.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -308,29 +308,29 @@ internal class _AnyRandomAccessCollectionBox<Element>
@_versioned
@_inlineable
internal func _index(
_ i: _AnyIndexBox, offsetBy n: IntMax
_ i: _AnyIndexBox, offsetBy n: Int64
) -> _AnyIndexBox {
_abstract()
}

@_versioned
@_inlineable
internal func _index(
_ i: _AnyIndexBox, offsetBy n: IntMax, limitedBy limit: _AnyIndexBox
_ i: _AnyIndexBox, offsetBy n: Int64, limitedBy limit: _AnyIndexBox
) -> _AnyIndexBox? {
_abstract()
}

@_versioned
@_inlineable
internal func _formIndex(_ i: inout _AnyIndexBox, offsetBy n: IntMax) {
internal func _formIndex(_ i: inout _AnyIndexBox, offsetBy n: Int64) {
_abstract()
}

@_versioned
@_inlineable
internal func _formIndex(
_ i: inout _AnyIndexBox, offsetBy n: IntMax, limitedBy limit: _AnyIndexBox
_ i: inout _AnyIndexBox, offsetBy n: Int64, limitedBy limit: _AnyIndexBox
) -> Bool {
_abstract()
}
Expand All @@ -339,7 +339,7 @@ internal class _AnyRandomAccessCollectionBox<Element>
@_inlineable
internal func _distance(
from start: _AnyIndexBox, to end: _AnyIndexBox
) -> IntMax {
) -> Int64 {
_abstract()
}

Expand All @@ -357,7 +357,7 @@ internal class _AnyRandomAccessCollectionBox<Element>
*/

@_versioned
internal var _count: IntMax { _abstract() }
internal var _count: Int64 { _abstract() }

// TODO: swift-3-indexing-model: forward the following methods.
/*
Expand Down Expand Up @@ -609,7 +609,7 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Elemen
@_versioned
@_inlineable
internal override func _index(
_ i: _AnyIndexBox, offsetBy n: IntMax
_ i: _AnyIndexBox, offsetBy n: Int64
) -> _AnyIndexBox {
return _IndexBox(_base: _base.index(_unbox(i), offsetBy: numericCast(n)))
}
Expand All @@ -618,7 +618,7 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Elemen
@_inlineable
internal override func _index(
_ i: _AnyIndexBox,
offsetBy n: IntMax,
offsetBy n: Int64,
limitedBy limit: _AnyIndexBox
) -> _AnyIndexBox? {
return _base.index(
Expand All @@ -631,7 +631,7 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Elemen
@_versioned
@_inlineable
internal override func _formIndex(
_ i: inout _AnyIndexBox, offsetBy n: IntMax
_ i: inout _AnyIndexBox, offsetBy n: Int64
) {
if let box = i as? _IndexBox<S.Index> {
return _base.formIndex(&box._base, offsetBy: numericCast(n))
Expand All @@ -642,7 +642,7 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Elemen
@_versioned
@_inlineable
internal override func _formIndex(
_ i: inout _AnyIndexBox, offsetBy n: IntMax, limitedBy limit: _AnyIndexBox
_ i: inout _AnyIndexBox, offsetBy n: Int64, limitedBy limit: _AnyIndexBox
) -> Bool {
if let box = i as? _IndexBox<S.Index> {
return _base.formIndex(
Expand All @@ -658,13 +658,13 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Elemen
internal override func _distance(
from start: _AnyIndexBox,
to end: _AnyIndexBox
) -> IntMax {
) -> Int64 {
return numericCast(_base.distance(from: _unbox(start), to: _unbox(end)))
}

@_versioned
@_inlineable
internal override var _count: IntMax {
internal override var _count: Int64 {
return numericCast(_base.count)
}

Expand Down Expand Up @@ -1079,7 +1079,7 @@ public struct ${Self}<Element>
% end

public typealias Index = AnyIndex
public typealias IndexDistance = IntMax
public typealias IndexDistance = Int64

/// The position of the first element in a non-empty collection.
///
Expand Down Expand Up @@ -1144,22 +1144,22 @@ public struct ${Self}<Element>
}

@_inlineable
public func index(_ i: AnyIndex, offsetBy n: IntMax) -> AnyIndex {
public func index(_ i: AnyIndex, offsetBy n: Int64) -> AnyIndex {
return AnyIndex(_box: _box._index(i._box, offsetBy: n))
}

@_inlineable
public func index(
_ i: AnyIndex,
offsetBy n: IntMax,
offsetBy n: Int64,
limitedBy limit: AnyIndex
) -> AnyIndex? {
return _box._index(i._box, offsetBy: n, limitedBy: limit._box)
.map { AnyIndex(_box:$0) }
}

@_inlineable
public func formIndex(_ i: inout AnyIndex, offsetBy n: IntMax) {
public func formIndex(_ i: inout AnyIndex, offsetBy n: Int64) {
if _isUnique(&i._box) {
return _box._formIndex(&i._box, offsetBy: n)
} else {
Expand All @@ -1170,7 +1170,7 @@ public struct ${Self}<Element>
@_inlineable
public func formIndex(
_ i: inout AnyIndex,
offsetBy n: IntMax,
offsetBy n: Int64,
limitedBy limit: AnyIndex
) -> Bool {
if _isUnique(&i._box) {
Expand All @@ -1185,7 +1185,7 @@ public struct ${Self}<Element>
}

@_inlineable
public func distance(from start: AnyIndex, to end: AnyIndex) -> IntMax {
public func distance(from start: AnyIndex, to end: AnyIndex) -> Int64 {
return _box._distance(from: start._box, to: end._box)
}

Expand All @@ -1199,7 +1199,7 @@ public struct ${Self}<Element>
% end
/// - Complexity: ${'O(1)' if Traversal == 'RandomAccess' else 'O(*n*)'}
@_inlineable
public var count: IntMax {
public var count: Int64 {
return _box._count
}

Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/HashedCollections.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1739,9 +1739,9 @@ public struct Dictionary<Key : Hashable, Value> :
self = Dictionary(minimumCapacity: keysAndValues.underestimatedCount)
// '_MergeError.keyCollision' is caught and handled with an appropriate
// error message one level down, inside _variantBuffer.merge(_:...).
try! _variantBuffer.merge(keysAndValues, uniquingKeysWith: { _ in
throw _MergeError.keyCollision
})
try! _variantBuffer.merge(
keysAndValues,
uniquingKeysWith: { _, _ in throw _MergeError.keyCollision})
}
}

Expand Down Expand Up @@ -5885,7 +5885,7 @@ extension ${Self} {
@_inlineable
@available(swift, obsoleted: 4.0)
public func filter(
_ isIncluded: (Element) throws -> Bool
_ isIncluded: (Element) throws -> Bool, obsoletedInSwift4: () = ()
) rethrows -> [Element] {
var result: [Element] = []
for x in self {
Expand Down
12 changes: 6 additions & 6 deletions stdlib/public/core/Integers.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ extension FixedWidthInteger {
///
/// [identity element]:http://en.wikipedia.org/wiki/Identity_element
/// [fixed point]:http://en.wikipedia.org/wiki/Fixed_point_(mathematics)
@available(swift, deprecated: 3.1, obsoleted: 4.0, message: "Use 0")
@available(swift, deprecated: 3.1, obsoleted: 4.1, message: "Use 0")
public static var allZeros: Self { return 0 }

@_inlineable
Expand Down Expand Up @@ -2933,7 +2933,7 @@ ${assignmentOperatorComment(x.operator, True)}
% end

@available(swift, obsoleted: 4.0, message: "Use initializers instead")
public func to${U}IntMax() -> ${U}IntMax {
public func to${U}IntMax() -> ${U}Int64 {
return numericCast(self)
}

Expand Down Expand Up @@ -3169,15 +3169,15 @@ extension SignedNumeric where Self : Comparable {
@available(swift, obsoleted: 4)
extension BinaryInteger {
@available(swift, obsoleted: 4)
public func toIntMax() -> IntMax {
return IntMax(self)
public func toIntMax() -> Int64 {
return Int64(self)
}
}

extension UnsignedInteger {
@available(swift, obsoleted: 4)
public func toUIntMax() -> UIntMax {
return UIntMax(self)
public func toUIntMax() -> UInt64 {
return UInt64(self)
}
}

Expand Down
Loading