Skip to content

Commit df22c36

Browse files
[stdlib] Build the standard library as Swift 5 (#18121)
* Update std lib to Swift 5.0 * Disable Unicode.* warnings for now * Slow path to resiliently handle the case where an unknown rounding rule is passed * Remove resilience from Encoding/DecodingError (which should only happen on slow paths anyway) * internal typealiases now need @usableFromInline * Force inlining on Array._owner.get
1 parent c2f9a2a commit df22c36

File tree

8 files changed

+26
-23
lines changed

8 files changed

+26
-23
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ function(_compile_swift_files
257257
"-Xfrontend" "${GROUP_INFO_JSON_FILE}")
258258
endif()
259259

260-
# Force swift 4 compatibility mode for Standard Library.
260+
# Force swift 5 mode for Standard Library.
261261
if (SWIFTFILE_IS_STDLIB)
262-
list(APPEND swift_flags "-swift-version" "4")
262+
list(APPEND swift_flags "-swift-version" "5")
263263
endif()
264264

265265
# Force swift 4 compatibility mode for overlays.

stdlib/public/core/Array.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,10 @@ extension Array: RangeReplaceableCollection, ArrayProtocol {
962962
@inlinable
963963
public // @testable
964964
var _owner: AnyObject? {
965-
return _buffer.owner
965+
@inline(__always)
966+
get {
967+
return _buffer.owner
968+
}
966969
}
967970

968971
/// If the elements are stored contiguously, a pointer to the first

stdlib/public/core/Codable.swift.gyb

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,6 @@ public struct CodingUserInfoKey : RawRepresentable, Equatable, Hashable {
11161116
/// An error that occurs during the encoding of a value.
11171117
public enum EncodingError : Error {
11181118
/// The context in which the error occurred.
1119-
@_fixed_layout // FIXME(sil-serialize-all)
11201119
public struct Context {
11211120
/// The path of coding keys taken to get to the point of the failing encode
11221121
/// call.
@@ -1137,7 +1136,6 @@ public enum EncodingError : Error {
11371136
/// debugging purposes.
11381137
/// - parameter underlyingError: The underlying error which caused this
11391138
/// error, if any.
1140-
@inlinable // FIXME(sil-serialize-all)
11411139
public init(
11421140
codingPath: [CodingKey],
11431141
debugDescription: String,
@@ -1163,19 +1161,16 @@ public enum EncodingError : Error {
11631161
// access CustomNSError (which is defined in Foundation) from here, we can
11641162
// use the "hidden" entry points.
11651163

1166-
@inlinable // FIXME(sil-serialize-all)
11671164
public var _domain: String {
11681165
return "NSCocoaErrorDomain"
11691166
}
11701167

1171-
@inlinable // FIXME(sil-serialize-all)
11721168
public var _code: Int {
11731169
switch self {
1174-
case .invalidValue(_, _): return 4866
1170+
case .invalidValue: return 4866
11751171
}
11761172
}
11771173

1178-
@inlinable // FIXME(sil-serialize-all)
11791174
public var _userInfo: AnyObject? {
11801175
// The error dictionary must be returned as an AnyObject. We can do this
11811176
// only on platforms with bridging, unfortunately.
@@ -1204,7 +1199,6 @@ public enum EncodingError : Error {
12041199
/// An error that occurs during the decoding of a value.
12051200
public enum DecodingError : Error {
12061201
/// The context in which the error occurred.
1207-
@_fixed_layout // FIXME(sil-serialize-all)
12081202
public struct Context {
12091203
/// The path of coding keys taken to get to the point of the failing decode
12101204
/// call.
@@ -1225,7 +1219,6 @@ public enum DecodingError : Error {
12251219
/// debugging purposes.
12261220
/// - parameter underlyingError: The underlying error which caused this
12271221
/// error, if any.
1228-
@inlinable // FIXME(sil-serialize-all)
12291222
public init(
12301223
codingPath: [CodingKey],
12311224
debugDescription: String,
@@ -1270,22 +1263,17 @@ public enum DecodingError : Error {
12701263
// access CustomNSError (which is defined in Foundation) from here, we can
12711264
// use the "hidden" entry points.
12721265

1273-
@inlinable // FIXME(sil-serialize-all)
12741266
public var _domain: String {
12751267
return "NSCocoaErrorDomain"
12761268
}
12771269

1278-
@inlinable // FIXME(sil-serialize-all)
12791270
public var _code: Int {
12801271
switch self {
1281-
case .keyNotFound(_, _): fallthrough
1282-
case .valueNotFound(_, _): return 4865
1283-
case .typeMismatch(_, _): fallthrough
1284-
case .dataCorrupted(_): return 4864
1272+
case .keyNotFound, .valueNotFound: return 4865
1273+
case .typeMismatch, .dataCorrupted: return 4864
12851274
}
12861275
}
12871276

1288-
@inlinable // FIXME(sil-serialize-all)
12891277
public var _userInfo: AnyObject? {
12901278
// The error dictionary must be returned as an AnyObject. We can do this
12911279
// only on platforms with bridging, unfortunately.

stdlib/public/core/Dictionary.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4347,6 +4347,7 @@ extension Dictionary.Index {
43474347
#if _runtime(_ObjC)
43484348
@usableFromInline
43494349
final internal class _CocoaDictionaryIterator: IteratorProtocol {
4350+
@usableFromInline
43504351
internal typealias Element = (AnyObject, AnyObject)
43514352

43524353
// Cocoa Dictionary iterator has to be a class, otherwise we cannot

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,19 @@ extension ${Self}: BinaryFloatingPoint {
10171017
_value = Builtin.int_ceil_FPIEEE${bits}(_value)
10181018
case .down:
10191019
_value = Builtin.int_floor_FPIEEE${bits}(_value)
1020+
@unknown default:
1021+
self._roundSlowPath(rule)
10201022
}
10211023
}
1024+
1025+
// Slow path for new cases that might have been inlined into an old
1026+
// ABI-stable version of round(_:) called from a newer version. If this is
1027+
// the case, this non-inlinable function will call into the _newer_ version
1028+
// which _will_ support this rounding rule.
1029+
@usableFromInline
1030+
internal mutating func _roundSlowPath(_ rule: FloatingPointRoundingRule) {
1031+
self.round(rule)
1032+
}
10221033

10231034
/// Replaces this value with its additive inverse.
10241035
///

stdlib/public/core/MigrationSupport.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,13 @@ extension String.UTF8View {
688688
}
689689
}
690690

691-
@available(swift,deprecated: 5.0, renamed: "Unicode.UTF8")
691+
// @available(swift,deprecated: 5.0, renamed: "Unicode.UTF8")
692692
public typealias UTF8 = Unicode.UTF8
693-
@available(swift, deprecated: 5.0, renamed: "Unicode.UTF16")
693+
// @available(swift, deprecated: 5.0, renamed: "Unicode.UTF16")
694694
public typealias UTF16 = Unicode.UTF16
695-
@available(swift, deprecated: 5.0, renamed: "Unicode.UTF32")
695+
// @available(swift, deprecated: 5.0, renamed: "Unicode.UTF32")
696696
public typealias UTF32 = Unicode.UTF32
697-
@available(swift, obsoleted: 5.0, renamed: "Unicode.Scalar")
697+
// @available(swift, deprecated: 5.0, renamed: "Unicode.Scalar")
698698
public typealias UnicodeScalar = Unicode.Scalar
699699

700700

stdlib/public/core/Set.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,6 +3562,7 @@ extension Set.Index {
35623562
#if _runtime(_ObjC)
35633563
@usableFromInline
35643564
final internal class _CocoaSetIterator: IteratorProtocol {
3565+
@usableFromInline
35653566
internal typealias Element = AnyObject
35663567

35673568
// Cocoa Set iterator has to be a class, otherwise we cannot

stdlib/public/core/String.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,6 @@ extension String {
744744
}
745745

746746
@inlinable
747-
@usableFromInline
748747
static func _fromWellFormedUTF16CodeUnits<C : RandomAccessCollection>(
749748
_ input: C, repair: Bool = false
750749
) -> String where C.Element == UTF16.CodeUnit {

0 commit comments

Comments
 (0)