Skip to content

Commit f6c2caf

Browse files
committed
stdlib: Add @inlinable to @inline(__always) declarations
These should be audited since some might not actually need to be @inlinable, but for now: - Anything public and @inline(__always) is now also @inlinable - Anything @usableFromInline and @inline(__always) is now @inlinable
1 parent 3e864b2 commit f6c2caf

14 files changed

+45
-44
lines changed

Diff for: benchmark/utils/TestsUtils.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public func Random() -> Int64 {
221221
return lfsrRandomGenerator.randInt()
222222
}
223223

224-
@inline(__always)
224+
@inlinable @inline(__always)
225225
public func CheckResults(
226226
_ resultsMatch: Bool,
227227
file: StaticString = #file,

Diff for: stdlib/public/SDK/GLKit/GLKMath.swift.gyb

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// types.
2222

2323
// Do dirty pointer manipulations to index an opaque struct like an array.
24-
@inline(__always)
24+
@inlinable @inline(__always)
2525
public func _indexHomogeneousValue<TTT, T>(_ aggregate: UnsafePointer<TTT>,
2626
_ index: Int) -> T {
2727
return UnsafeRawPointer(aggregate).load(
@@ -31,7 +31,7 @@ public func _indexHomogeneousValue<TTT, T>(_ aggregate: UnsafePointer<TTT>,
3131
%{
3232
def defineSubscript(Type, limit):
3333
return """
34-
public subscript(i: Int) -> Float {{
34+
@inlinable public subscript(i: Int) -> Float {{
3535
@inline(__always)
3636
get {{
3737
precondition(i >= 0, "Negative {0} index out of range")

Diff for: stdlib/public/core/Array.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ extension Array {
384384
}
385385

386386
@_semantics("array.get_element")
387-
@inline(__always)
387+
@inlinable @inline(__always)
388388
public // @testable
389389
func _getElement(
390390
_ index: Int,
@@ -440,7 +440,7 @@ extension Array: _ArrayProtocol {
440440
@inlinable
441441
public // @testable
442442
var _owner: AnyObject? {
443-
@inline(__always)
443+
@inlinable @inline(__always)
444444
get {
445445
return _buffer.owner
446446
}
@@ -1447,7 +1447,7 @@ extension Array {
14471447
/// method's execution.
14481448
/// - Returns: The return value, if any, of the `body` closure parameter.
14491449
@_semantics("array.withUnsafeMutableBufferPointer")
1450-
@inline(__always) // Performance: This method should get inlined into the
1450+
@inlinable @inline(__always) // Performance: This method should get inlined into the
14511451
// caller such that we can combine the partial apply with the apply in this
14521452
// function saving on allocating a closure context. This becomes unnecessary
14531453
// once we allocate noescape closures on the stack.

Diff for: stdlib/public/core/ArrayShared.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct _DependenceToken {
2525
/// This function is referenced by the compiler to allocate array literals.
2626
///
2727
/// - Precondition: `storage` is `_ContiguousArrayStorage`.
28-
@inline(__always)
28+
@inlinable @inline(__always)
2929
public // COMPILER_INTRINSIC
3030
func _allocateUninitializedArray<Element>(_ builtinCount: Builtin.Word)
3131
-> (Array<Element>, Builtin.RawPointer) {

Diff for: stdlib/public/core/ArraySlice.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ extension ArraySlice {
202202
}
203203

204204
@_semantics("array.get_element")
205-
@inline(__always)
205+
@inlinable @inline(__always)
206206
public // @testable
207207
func _getElement(
208208
_ index: Int,
@@ -1192,7 +1192,7 @@ extension ArraySlice {
11921192
/// method's execution.
11931193
/// - Returns: The return value, if any, of the `body` closure parameter.
11941194
@_semantics("array.withUnsafeMutableBufferPointer")
1195-
@inline(__always) // Performance: This method should get inlined into the
1195+
@inlinable @inline(__always) // Performance: This method should get inlined into the
11961196
// caller such that we can combine the partial apply with the apply in this
11971197
// function saving on allocating a closure context. This becomes unnecessary
11981198
// once we allocate noescape closures on the stack.

Diff for: stdlib/public/core/ContiguousArray.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ extension ContiguousArray {
10411041
/// method's execution.
10421042
/// - Returns: The return value, if any, of the `body` closure parameter.
10431043
@_semantics("array.withUnsafeMutableBufferPointer")
1044-
@inline(__always) // Performance: This method should get inlined into the
1044+
@inlinable @inline(__always) // Performance: This method should get inlined into the
10451045
// caller such that we can combine the partial apply with the apply in this
10461046
// function saving on allocating a closure context. This becomes unnecessary
10471047
// once we allocate noescape closures on the stack.

Diff for: stdlib/public/core/FloatingPoint.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ extension FloatingPoint {
17221722
/// - If `x` is `leastNonzeroMagnitude`, then `x.nextDown` is `0.0`.
17231723
/// - If `x` is zero, then `x.nextDown` is `-leastNonzeroMagnitude`.
17241724
/// - If `x` is `-greatestFiniteMagnitude`, then `x.nextDown` is `-infinity`.
1725-
public var nextDown: Self {
1725+
@inlinable public var nextDown: Self {
17261726
@inline(__always)
17271727
get {
17281728
return -(-self).nextUp
@@ -1760,7 +1760,7 @@ extension FloatingPoint {
17601760
/// - Parameter other: The value to use when dividing this value.
17611761
/// - Returns: The remainder of this value divided by `other` using
17621762
/// truncating division.
1763-
@inline(__always)
1763+
@inlinable @inline(__always)
17641764
public func truncatingRemainder(dividingBy other: Self) -> Self {
17651765
var lhs = self
17661766
lhs.formTruncatingRemainder(dividingBy: other)
@@ -1799,7 +1799,7 @@ extension FloatingPoint {
17991799
///
18001800
/// - Parameter other: The value to use when dividing this value.
18011801
/// - Returns: The remainder of this value divided by `other`.
1802-
@inline(__always)
1802+
@inlinable @inline(__always)
18031803
public func remainder(dividingBy other: Self) -> Self {
18041804
var lhs = self
18051805
lhs.formRemainder(dividingBy: other)

Diff for: stdlib/public/core/FloatingPointTypes.swift.gyb

+18-18
Original file line numberDiff line numberDiff line change
@@ -175,24 +175,24 @@ extension ${Self}: BinaryFloatingPoint {
175175
}
176176
177177
// Implementation details.
178-
@usableFromInline
178+
@inlinable
179179
internal static var _infinityExponent: UInt {
180180
@inline(__always) get { return 1 &<< UInt(exponentBitCount) - 1 }
181181
}
182182
183-
@usableFromInline
183+
@inlinable
184184
internal static var _exponentBias: UInt {
185185
@inline(__always) get { return _infinityExponent &>> 1 }
186186
}
187187
188-
@usableFromInline
188+
@inlinable
189189
internal static var _significandMask: ${RawSignificand} {
190190
@inline(__always) get {
191191
return 1 &<< ${RawSignificand}(significandBitCount) - 1
192192
}
193193
}
194194
195-
@usableFromInline
195+
@inlinable
196196
internal static var _quietNaNMask: ${RawSignificand} {
197197
@inline(__always) get {
198198
return 1 &<< ${RawSignificand}(significandBitCount - 1)
@@ -1103,7 +1103,7 @@ extension ${Self}: BinaryFloatingPoint {
11031103
/// `formRemainder(dividingBy:)` method is always exact.
11041104
///
11051105
/// - Parameter other: The value to use when dividing this value.
1106-
@inline(__always)
1106+
@inlinable @inline(__always)
11071107
public mutating func formRemainder(dividingBy other: ${Self}) {
11081108
self = _stdlib_remainder${cFuncSuffix}(self, other)
11091109
}
@@ -1137,7 +1137,7 @@ extension ${Self}: BinaryFloatingPoint {
11371137
/// method is always exact.
11381138
///
11391139
/// - Parameter other: The value to use when dividing this value.
1140-
@inline(__always)
1140+
@inlinable @inline(__always)
11411141
public mutating func formTruncatingRemainder(dividingBy other: ${Self}) {
11421142
_value = Builtin.frem_FPIEEE${bits}(self._value, other._value)
11431143
}
@@ -1258,7 +1258,7 @@ extension ${Self}: BinaryFloatingPoint {
12581258
/// A *normal* value is a finite number that uses the full precision
12591259
/// available to values of a type. Zero is neither a normal nor a subnormal
12601260
/// number.
1261-
public var isNormal: Bool {
1261+
@inlinable public var isNormal: Bool {
12621262
@inline(__always)
12631263
get {
12641264
return exponentBitPattern > 0 && isFinite
@@ -1269,7 +1269,7 @@ extension ${Self}: BinaryFloatingPoint {
12691269
///
12701270
/// All values other than NaN and infinity are considered finite, whether
12711271
/// normal or subnormal.
1272-
public var isFinite: Bool {
1272+
@inlinable public var isFinite: Bool {
12731273
@inline(__always)
12741274
get {
12751275
return exponentBitPattern < ${Self}._infinityExponent
@@ -1285,7 +1285,7 @@ extension ${Self}: BinaryFloatingPoint {
12851285
/// let x = -0.0
12861286
/// x.isZero // true
12871287
/// x == 0.0 // true
1288-
public var isZero: Bool {
1288+
@inlinable public var isZero: Bool {
12891289
@inline(__always)
12901290
get {
12911291
return exponentBitPattern == 0 && significandBitPattern == 0
@@ -1301,7 +1301,7 @@ extension ${Self}: BinaryFloatingPoint {
13011301
/// Zero is neither a normal nor a subnormal number. Subnormal numbers are
13021302
/// often called *denormal* or *denormalized*---these are different names
13031303
/// for the same concept.
1304-
public var isSubnormal: Bool {
1304+
@inlinable public var isSubnormal: Bool {
13051305
@inline(__always)
13061306
get {
13071307
return exponentBitPattern == 0 && significandBitPattern != 0
@@ -1312,7 +1312,7 @@ extension ${Self}: BinaryFloatingPoint {
13121312
///
13131313
/// Note that `isFinite` and `isInfinite` do not form a dichotomy, because
13141314
/// they are not total: If `x` is `NaN`, then both properties are `false`.
1315-
public var isInfinite: Bool {
1315+
@inlinable public var isInfinite: Bool {
13161316
@inline(__always)
13171317
get {
13181318
return !isFinite && significandBitPattern == 0
@@ -1342,7 +1342,7 @@ extension ${Self}: BinaryFloatingPoint {
13421342
/// // Prints "true"
13431343
///
13441344
/// This property is `true` for both quiet and signaling NaNs.
1345-
public var isNaN: Bool {
1345+
@inlinable public var isNaN: Bool {
13461346
@inline(__always)
13471347
get {
13481348
return !isFinite && significandBitPattern != 0
@@ -1353,7 +1353,7 @@ extension ${Self}: BinaryFloatingPoint {
13531353
///
13541354
/// Signaling NaNs typically raise the Invalid flag when used in general
13551355
/// computing operations.
1356-
public var isSignalingNaN: Bool {
1356+
@inlinable public var isSignalingNaN: Bool {
13571357
@inline(__always)
13581358
get {
13591359
return isNaN && (significandBitPattern & ${Self}._quietNaNMask) == 0
@@ -1447,7 +1447,7 @@ extension ${Self}: BinaryFloatingPoint {
14471447
/// // x == 21.25
14481448
///
14491449
/// - Parameter value: The new floating-point value.
1450-
@inline(__always)
1450+
@inlinable @inline(__always)
14511451
public init(floatLiteral value: ${Self}) {
14521452
self = value
14531453
}
@@ -1590,7 +1590,7 @@ extension ${Self} {
15901590
/// // Use 'abs(_:)' instead of 'magnitude'
15911591
/// print("Missed the target by \(abs(margin)) meters.")
15921592
/// // Prints "Missed the target by 0.25 meters."
1593-
public var magnitude: ${Self} {
1593+
@inlinable public var magnitude: ${Self} {
15941594
@inline(__always)
15951595
get {
15961596
return ${Self}(Builtin.int_fabs_FPIEEE${bits}(_value))
@@ -1614,14 +1614,14 @@ extension ${Self} {
16141614

16151615
// We "shouldn't" need this, but the typechecker barfs on an expression
16161616
// in the test suite without it.
1617-
@inline(__always)
1617+
@inlinable @inline(__always)
16181618
public init(_ v: Int) {
16191619
_value = Builtin.sitofp_Int${word_bits}_FPIEEE${bits}(v._value)
16201620
}
16211621

16221622
// Fast-path for conversion when the source is representable as a 64-bit int,
16231623
// falling back on the generic _convert operation otherwise.
1624-
@inline(__always)
1624+
@inlinable @inline(__always)
16251625
public init<Source : BinaryInteger>(_ value: Source) {
16261626
if value.bitWidth <= ${word_bits} {
16271627
if Source.isSigned {
@@ -1666,7 +1666,7 @@ extension ${Self} {
16661666
/// // z.isNaN == true
16671667
///
16681668
/// - Parameter other: The value to use for the new instance.
1669-
@inline(__always)
1669+
@inlinable @inline(__always)
16701670
public init(_ other: ${That}) {
16711671
% if srcBits > bits:
16721672
_value = Builtin.fptrunc_FPIEEE${srcBits}_FPIEEE${bits}(other._value)

Diff for: stdlib/public/core/Integers.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,7 @@ extension FixedWidthInteger {
30493049
/// // 'y' has a binary representation of 11111111_11101011
30503050
///
30513051
/// - Parameter source: An integer to convert to this type.
3052-
@inline(__always)
3052+
@inlinable @inline(__always)
30533053
public init<T : BinaryInteger>(truncatingIfNeeded source: T) {
30543054
if Self.bitWidth <= Int.bitWidth {
30553055
self = Self(_truncatingBits: source._lowWord)
@@ -3290,15 +3290,15 @@ extension UnsignedInteger {
32903290
/// to find an absolute value. In addition, because `abs(_:)` always returns
32913291
/// a value of the same type, even in a generic context, using the function
32923292
/// instead of the `magnitude` property is encouraged.
3293-
public var magnitude: Self {
3293+
@inlinable public var magnitude: Self {
32943294
@inline(__always)
32953295
get { return self }
32963296
}
32973297

32983298
/// A Boolean value indicating whether this type is a signed integer type.
32993299
///
33003300
/// This property is always `false` for unsigned integer types.
3301-
public static var isSigned: Bool {
3301+
@inlinable public static var isSigned: Bool {
33023302
@inline(__always)
33033303
get { return false }
33043304
}
@@ -3325,7 +3325,7 @@ extension UnsignedInteger where Self : FixedWidthInteger {
33253325
/// - Parameter source: A value to convert to this type of integer. The value
33263326
/// passed as `source` must be representable in this type.
33273327
@_semantics("optimize.sil.specialize.generic.partial.never")
3328-
@inline(__always)
3328+
@inlinable @inline(__always)
33293329
public init<T : BinaryInteger>(_ source: T) {
33303330
// This check is potentially removable by the optimizer
33313331
if T.isSigned {
@@ -3355,7 +3355,7 @@ extension UnsignedInteger where Self : FixedWidthInteger {
33553355
///
33563356
/// - Parameter source: A value to convert to this type of integer.
33573357
@_semantics("optimize.sil.specialize.generic.partial.never")
3358-
@inline(__always)
3358+
@inlinable @inline(__always)
33593359
public init?<T : BinaryInteger>(exactly source: T) {
33603360
// This check is potentially removable by the optimizer
33613361
if T.isSigned && source < (0 as T) {
@@ -3399,7 +3399,7 @@ extension SignedInteger {
33993399
/// A Boolean value indicating whether this type is a signed integer type.
34003400
///
34013401
/// This property is always `true` for signed integer types.
3402-
public static var isSigned: Bool {
3402+
@inlinable public static var isSigned: Bool {
34033403
@inline(__always)
34043404
get { return true }
34053405
}
@@ -3426,7 +3426,7 @@ extension SignedInteger where Self : FixedWidthInteger {
34263426
/// - Parameter source: A value to convert to this type of integer. The value
34273427
/// passed as `source` must be representable in this type.
34283428
@_semantics("optimize.sil.specialize.generic.partial.never")
3429-
@inline(__always)
3429+
@inlinable @inline(__always)
34303430
public init<T : BinaryInteger>(_ source: T) {
34313431
// This check is potentially removable by the optimizer
34323432
if T.isSigned && source.bitWidth > Self.bitWidth {
@@ -3458,7 +3458,7 @@ extension SignedInteger where Self : FixedWidthInteger {
34583458
///
34593459
/// - Parameter source: A value to convert to this type of integer.
34603460
@_semantics("optimize.sil.specialize.generic.partial.never")
3461-
@inline(__always)
3461+
@inlinable @inline(__always)
34623462
public init?<T : BinaryInteger>(exactly source: T) {
34633463
// This check is potentially removable by the optimizer
34643464
if T.isSigned && source.bitWidth > Self.bitWidth && source < Self.min {

Diff for: stdlib/public/core/NativeDictionary.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ extension _NativeDictionary { // Low-level unchecked operations
121121
return _values[bucket.offset]
122122
}
123123

124-
@usableFromInline
124+
@inlinable
125125
@inline(__always)
126126
internal func uncheckedInitialize(
127127
at bucket: Bucket,
@@ -133,7 +133,7 @@ extension _NativeDictionary { // Low-level unchecked operations
133133
(_values + bucket.offset).initialize(to: value)
134134
}
135135

136-
@usableFromInline
136+
@inlinable
137137
@inline(__always)
138138
internal func uncheckedDestroy(at bucket: Bucket) {
139139
defer { _fixLifetime(self) }

Diff for: stdlib/public/core/SmallString.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ extension _SmallString: RandomAccessCollection, MutableCollection {
192192
}
193193
}
194194

195-
@usableFromInline // testable
195+
@inlinable // testable
196196
internal subscript(_ bounds: Range<Index>) -> SubSequence {
197197
@inline(__always) get {
198198
// TODO(String performance): In-vector-register operation

Diff for: stdlib/public/core/StringCharacterView.swift

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extension String: BidirectionalCollection {
5050
}
5151

5252
/// The number of characters in a string.
53+
@inlinable
5354
public var count: Int {
5455
@inline(__always) get {
5556
return distance(from: startIndex, to: endIndex)

Diff for: stdlib/public/core/StringGutsRangeReplaceable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension _StringGuts {
4040
}
4141
}
4242

43-
@usableFromInline // @testable
43+
@inlinable // @testable
4444
internal var isUniqueNative: Bool {
4545
@inline(__always) mutating get {
4646
// Note: mutating so that self is `inout`.

Diff for: stdlib/public/core/UnicodeHelpers.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ internal func _numUTF16CodeUnits(_ scalar: Unicode.Scalar) -> Int {
172172
// Scalar helpers
173173
//
174174
extension _StringGuts {
175-
@usableFromInline @inline(__always) // fast-path: fold common fastUTF8 check
175+
@inlinable @inline(__always) // fast-path: fold common fastUTF8 check
176176
internal func scalarAlign(_ idx: Index) -> Index {
177177
// TODO(String performance): isASCII check
178178

0 commit comments

Comments
 (0)