Skip to content

[stdlib][nfc] Inlineable audit #17379

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

Merged
merged 3 commits into from
Jul 6, 2018
Merged
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
8 changes: 4 additions & 4 deletions stdlib/public/core/Algorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/// - x: A value to compare.
/// - y: Another value to compare.
/// - Returns: The lesser of `x` and `y`. If `x` is equal to `y`, returns `x`.
@inlinable
@inlinable // protocol-only
public func min<T : Comparable>(_ x: T, _ y: T) -> T {
// In case `x == y` we pick `x`.
// This preserves any pre-existing order in case `T` has identity,
Expand All @@ -34,7 +34,7 @@ public func min<T : Comparable>(_ x: T, _ y: T) -> T {
/// - rest: Zero or more additional values.
/// - Returns: The least of all the arguments. If there are multiple equal
/// least arguments, the result is the first one.
@inlinable
@inlinable // protocol-only
public func min<T : Comparable>(_ x: T, _ y: T, _ z: T, _ rest: T...) -> T {
var minValue = min(min(x, y), z)
// In case `value == minValue`, we pick `minValue`. See min(_:_:).
Expand All @@ -50,7 +50,7 @@ public func min<T : Comparable>(_ x: T, _ y: T, _ z: T, _ rest: T...) -> T {
/// - x: A value to compare.
/// - y: Another value to compare.
/// - Returns: The greater of `x` and `y`. If `x` is equal to `y`, returns `y`.
@inlinable
@inlinable // protocol-only
public func max<T : Comparable>(_ x: T, _ y: T) -> T {
// In case `x == y`, we pick `y`. See min(_:_:).
return y >= x ? y : x
Expand All @@ -65,7 +65,7 @@ public func max<T : Comparable>(_ x: T, _ y: T) -> T {
/// - rest: Zero or more additional values.
/// - Returns: The greatest of all the arguments. If there are multiple equal
/// greatest arguments, the result is the last one.
@inlinable
@inlinable // protocol-only
public func max<T : Comparable>(_ x: T, _ y: T, _ z: T, _ rest: T...) -> T {
var maxValue = max(max(x, y), z)
// In case `value == maxValue`, we pick `value`. See min(_:_:).
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Assert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public func _debugPrecondition(
file: StaticString = #file, line: UInt = #line
) {
// Only check in debug mode.
if _isDebugAssertConfiguration() {
if _slowPath(_isDebugAssertConfiguration()) {
if !_branchHint(condition(), expected: true) {
_fatalErrorMessage("Fatal error", message, file: file, line: line,
flags: _fatalErrorFlags())
Expand All @@ -281,7 +281,7 @@ public func _debugPreconditionFailure(
_ message: StaticString = StaticString(),
file: StaticString = #file, line: UInt = #line
) -> Never {
if _isDebugAssertConfiguration() {
if _slowPath(_isDebugAssertConfiguration()) {
_precondition(false, message, file: file, line: line)
}
_conditionallyUnreachable()
Expand Down
18 changes: 9 additions & 9 deletions stdlib/public/core/BidirectionalCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ where SubSequence: BidirectionalCollection, Indices: BidirectionalCollection {
/// Default implementation for bidirectional collections.
extension BidirectionalCollection {

@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
@inline(__always)
public func formIndex(before i: inout Index) {
i = index(before: i)
}

@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public func index(_ i: Index, offsetBy n: Int) -> Index {
if n >= 0 {
return _advanceForward(i, by: n)
Expand All @@ -149,7 +149,7 @@ extension BidirectionalCollection {
return i
}

@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public func index(
_ i: Index, offsetBy n: Int, limitedBy limit: Index
) -> Index? {
Expand All @@ -166,7 +166,7 @@ extension BidirectionalCollection {
return i
}

@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public func distance(from start: Index, to end: Index) -> Int {
var start = start
var count = 0
Expand Down Expand Up @@ -199,7 +199,7 @@ extension BidirectionalCollection where SubSequence == Self {
/// or more elements; otherwise, `nil`.
///
/// - Complexity: O(1).
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public mutating func popLast() -> Element? {
guard !isEmpty else { return nil }
let element = last!
Expand All @@ -215,7 +215,7 @@ extension BidirectionalCollection where SubSequence == Self {
/// - Returns: The last element of the collection.
///
/// - Complexity: O(1)
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
@discardableResult
public mutating func removeLast() -> Element {
let element = last!
Expand All @@ -232,7 +232,7 @@ extension BidirectionalCollection where SubSequence == Self {
/// - Complexity: O(1) if the collection conforms to
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the length
/// of the collection.
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public mutating func removeLast(_ n: Int) {
if n == 0 { return }
_precondition(n >= 0, "Number of elements to remove should be non-negative")
Expand Down Expand Up @@ -260,7 +260,7 @@ extension BidirectionalCollection {
/// - Returns: A subsequence that leaves off `n` elements from the end.
///
/// - Complexity: O(*n*), where *n* is the number of elements to drop.
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public func dropLast(_ n: Int) -> SubSequence {
_precondition(
n >= 0, "Can't drop a negative number of elements from a collection")
Expand Down Expand Up @@ -289,7 +289,7 @@ extension BidirectionalCollection {
/// most `maxLength` elements.
///
/// - Complexity: O(*n*), where *n* is equal to `maxLength`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public func suffix(_ maxLength: Int) -> SubSequence {
_precondition(
maxLength >= 0,
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Builtin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func _canBeClass<T>(_: T.Type) -> Int8 {
/// - type: The type to cast `x` to. `type` and the type of `x` must have the
/// same size of memory representation and compatible memory layout.
/// - Returns: A new instance of type `U`, cast from `x`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // unsafe-performance
@_transparent
public func unsafeBitCast<T, U>(_ x: T, to type: U.Type) -> U {
_precondition(MemoryLayout<T>.size == MemoryLayout<U>.size,
Expand Down
10 changes: 5 additions & 5 deletions stdlib/public/core/ClosedRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extension ClosedRange {
}

extension ClosedRange: RangeExpression {
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public func relative<C: Collection>(to collection: C) -> Range<Bound>
where C.Index == Bound {
return Range(
Expand Down Expand Up @@ -330,7 +330,7 @@ extension Comparable {
/// - Parameters:
/// - minimum: The lower bound for the range.
/// - maximum: The upper bound for the range.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
@_transparent
public static func ... (minimum: Self, maximum: Self) -> ClosedRange<Self> {
_precondition(
Expand Down Expand Up @@ -362,7 +362,7 @@ extension Strideable where Stride: SignedInteger {
/// - Parameters:)`.
/// - minimum: The lower bound for the range.
/// - maximum: The upper bound for the range.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
@_transparent
public static func ... (minimum: Self, maximum: Self) -> ClosedRange<Self> {
// FIXME: swift-3-indexing-model: tests for traps.
Expand Down Expand Up @@ -404,7 +404,7 @@ extension ClosedRange: Hashable where Bound: Hashable {

extension ClosedRange : CustomStringConvertible {
/// A textual representation of the range.
@inlinable // FIXME(sil-serialize-all)...
@inlinable // trivial-implementation...
public var description: String {
return "\(lowerBound)...\(upperBound)"
}
Expand Down Expand Up @@ -444,7 +444,7 @@ extension ClosedRange {
///
/// - Parameter limits: The range to clamp the bounds of this range.
/// - Returns: A new range clamped to the bounds of `limits`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
@inline(__always)
public func clamped(to limits: ClosedRange) -> ClosedRange {
let lower =
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ extension Collection {
///
/// - Parameter i: A valid index of the collection. `i` must be less than
/// `endIndex`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
@inline(__always)
public func formIndex(after i: inout Index) {
i = index(after: i)
Expand Down Expand Up @@ -1094,7 +1094,7 @@ extension Collection {
/// `IndexingIterator<Self>`.
extension Collection where Iterator == IndexingIterator<Self> {
/// Returns an iterator over the elements of the collection.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
@inline(__always)
public func makeIterator() -> IndexingIterator<Self> {
return IndexingIterator(_elements: self)
Expand Down
28 changes: 14 additions & 14 deletions stdlib/public/core/CollectionOfOne.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
/// let toAdd = 100
/// let b = a + CollectionOfOne(toAdd)
/// // b == [1, 2, 3, 4, 100]
@_fixed_layout // FIXME(sil-serialize-all)
@_fixed_layout // trivial-implementation
public struct CollectionOfOne<Element> {
@usableFromInline // FIXME(sil-serialize-all)
@usableFromInline // trivial-implementation
internal var _element: Element

/// Creates an instance containing just the given element.
///
/// - Parameter element: The element to store in the collection.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public init(_ element: Element) {
self._element = element
}
Expand All @@ -39,14 +39,14 @@ extension CollectionOfOne {
/// An iterator that produces one or zero instances of an element.
///
/// `IteratorOverOne` is the iterator for the `CollectionOfOne` type.
@_fixed_layout // FIXME(sil-serialize-all)
@_fixed_layout // trivial-implementation
public struct Iterator {
@usableFromInline // FIXME(sil-serialize-all)
@usableFromInline // trivial-implementation
internal var _elements: Element?

/// Construct an instance that generates `_element!`, or an empty
/// sequence if `_element == nil`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public // @testable
init(_elements: Element?) {
self._elements = _elements
Expand All @@ -62,7 +62,7 @@ extension CollectionOfOne.Iterator: IteratorProtocol {
///
/// - Returns: The next element in the underlying sequence, if a next element
/// exists; otherwise, `nil`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public mutating func next() -> Element? {
let result = _elements
_elements = nil
Expand All @@ -88,7 +88,7 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
/// last valid subscript argument.
///
/// In a `CollectionOfOne` instance, `endIndex` is always `1`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public var endIndex: Index {
return 1
}
Expand All @@ -97,7 +97,7 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
///
/// - Parameter i: A valid index of the collection. `i` must be `0`.
/// - Returns: The index value immediately after `i`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public func index(after i: Index) -> Index {
_precondition(i == startIndex)
return 1
Expand All @@ -107,7 +107,7 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
///
/// - Parameter i: A valid index of the collection. `i` must be `1`.
/// - Returns: The index value immediately before `i`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public func index(before i: Index) -> Index {
_precondition(i == endIndex)
return 0
Expand All @@ -116,7 +116,7 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
/// Returns an iterator over the elements of this collection.
///
/// - Complexity: O(1)
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public func makeIterator() -> Iterator {
return Iterator(_elements: _element)
}
Expand All @@ -125,7 +125,7 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
///
/// - Parameter position: The position of the element to access. The only
/// valid position in a `CollectionOfOne` instance is `0`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public subscript(position: Int) -> Element {
get {
_precondition(position == 0, "Index out of range")
Expand All @@ -137,7 +137,7 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
}
}

@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public subscript(bounds: Range<Int>) -> SubSequence {
get {
_failEarlyRangeCheck(bounds, bounds: 0..<1)
Expand All @@ -152,7 +152,7 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
}

/// The number of elements in the collection, which is always one.
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public var count: Int {
return 1
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Equatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ extension Equatable {
/// - Parameters:
/// - lhs: A value to compare.
/// - rhs: Another value to compare.
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
@_transparent
public static func != (lhs: Self, rhs: Self) -> Bool {
return !(lhs == rhs)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Indices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ extension Collection where Indices == DefaultIndices<Self> {
/// i = c.index(after: i)
/// }
/// // c == MyFancyCollection([2, 4, 6, 8, 10])
@inlinable // FIXME(sil-serialize-all)
@inlinable // trivial-implementation
public var indices: DefaultIndices<Self> {
return DefaultIndices(
_elements: self,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/LazyCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public protocol LazyCollectionProtocol: Collection, LazySequenceProtocol {

extension LazyCollectionProtocol {
// Lazy things are already lazy
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public var lazy: LazyCollection<Elements> {
return elements.lazy
}
}

extension LazyCollectionProtocol where Elements: LazyCollectionProtocol {
// Lazy things are already lazy
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public var lazy: Elements {
return elements
}
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/LazySequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ public protocol LazySequenceProtocol : Sequence {
/// property is provided.
extension LazySequenceProtocol where Elements == Self {
/// Identical to `self`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public var elements: Self { return self }
}

extension LazySequenceProtocol {
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public var lazy: LazySequence<Elements> {
return elements.lazy
}
}

extension LazySequenceProtocol where Elements: LazySequenceProtocol {
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public var lazy: Elements {
return elements
}
Expand Down Expand Up @@ -202,7 +202,7 @@ extension Sequence {
/// A sequence containing the same elements as this sequence,
/// but on which some operations, such as `map` and `filter`, are
/// implemented lazily.
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public var lazy: LazySequence<Self> {
return LazySequence(_base: self)
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/RandomAccessCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ where Index : Strideable,
/// - Parameter i: A valid index of the collection. `i` must be greater than
/// `startIndex`.
/// - Returns: The index value immediately before `i`.
@inlinable // FIXME(sil-serialize-all)
@inlinable // protocol-only
public func index(before i: Index) -> Index {
let result = i.advanced(by: -1)
// FIXME: swift-3-indexing-model: tests for the trap.
Expand Down
Loading