Skip to content

Commit 6a80196

Browse files
authored
Allow AsyncSequence operators to be inlined in their construction (#38310)
1 parent 3fe8b80 commit 6a80196

14 files changed

+54
-26
lines changed

stdlib/public/Concurrency/AsyncCompactMapSequence.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ extension AsyncSequence {
5656
/// An asynchronous sequence that maps a given closure over the asynchronous
5757
/// sequence’s elements, omitting results that don't return a value.
5858
@available(SwiftStdlib 5.5, *)
59+
@frozen
5960
public struct AsyncCompactMapSequence<Base: AsyncSequence, ElementOfResult> {
6061
@usableFromInline
6162
let base: Base
6263

6364
@usableFromInline
6465
let transform: (Base.Element) async -> ElementOfResult?
6566

66-
@usableFromInline
67+
@inlinable
6768
init(
6869
_ base: Base,
6970
transform: @escaping (Base.Element) async -> ElementOfResult?
@@ -84,6 +85,7 @@ extension AsyncCompactMapSequence: AsyncSequence {
8485
public typealias AsyncIterator = Iterator
8586

8687
/// The iterator that produces elements of the compact map sequence.
88+
@frozen
8789
public struct Iterator: AsyncIteratorProtocol {
8890
public typealias Element = ElementOfResult
8991

@@ -93,7 +95,7 @@ extension AsyncCompactMapSequence: AsyncSequence {
9395
@usableFromInline
9496
let transform: (Base.Element) async -> ElementOfResult?
9597

96-
@usableFromInline
98+
@inlinable
9799
init(
98100
_ baseIterator: Base.AsyncIterator,
99101
transform: @escaping (Base.Element) async -> ElementOfResult?

stdlib/public/Concurrency/AsyncDropFirstSequence.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ extension AsyncSequence {
4949
/// An asynchronous sequence which omits a specified number of elements from the
5050
/// base asynchronous sequence, then passes through all remaining elements.
5151
@available(SwiftStdlib 5.5, *)
52+
@frozen
5253
public struct AsyncDropFirstSequence<Base: AsyncSequence> {
5354
@usableFromInline
5455
let base: Base
5556

5657
@usableFromInline
5758
let count: Int
5859

59-
@usableFromInline
60+
@inlinable
6061
init(_ base: Base, dropping count: Int) {
6162
self.base = base
6263
self.count = count
@@ -74,14 +75,15 @@ extension AsyncDropFirstSequence: AsyncSequence {
7475
public typealias AsyncIterator = Iterator
7576

7677
/// The iterator that produces elements of the drop-first sequence.
78+
@frozen
7779
public struct Iterator: AsyncIteratorProtocol {
7880
@usableFromInline
7981
var baseIterator: Base.AsyncIterator
8082

8183
@usableFromInline
8284
var count: Int
8385

84-
@usableFromInline
86+
@inlinable
8587
init(_ baseIterator: Base.AsyncIterator, count: Int) {
8688
self.baseIterator = baseIterator
8789
self.count = count

stdlib/public/Concurrency/AsyncDropWhileSequence.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ extension AsyncSequence {
5353
/// given closure returns false, after which it passes through all remaining
5454
/// elements.
5555
@available(SwiftStdlib 5.5, *)
56+
@frozen
5657
public struct AsyncDropWhileSequence<Base: AsyncSequence> {
5758
@usableFromInline
5859
let base: Base
5960

6061
@usableFromInline
6162
let predicate: (Base.Element) async -> Bool
6263

63-
@usableFromInline
64+
@inlinable
6465
init(
6566
_ base: Base,
6667
predicate: @escaping (Base.Element) async -> Bool
@@ -82,14 +83,15 @@ extension AsyncDropWhileSequence: AsyncSequence {
8283
public typealias AsyncIterator = Iterator
8384

8485
/// The iterator that produces elements of the drop-while sequence.
86+
@frozen
8587
public struct Iterator: AsyncIteratorProtocol {
8688
@usableFromInline
8789
var baseIterator: Base.AsyncIterator
8890

8991
@usableFromInline
9092
var predicate: ((Base.Element) async -> Bool)?
9193

92-
@usableFromInline
94+
@inlinable
9395
init(
9496
_ baseIterator: Base.AsyncIterator,
9597
predicate: @escaping (Base.Element) async -> Bool

stdlib/public/Concurrency/AsyncFilterSequence.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ extension AsyncSequence {
4444
/// An asynchronous sequence that contains, in order, the elements of
4545
/// the base sequence that satisfy a given predicate.
4646
@available(SwiftStdlib 5.5, *)
47+
@frozen
4748
public struct AsyncFilterSequence<Base: AsyncSequence> {
4849
@usableFromInline
4950
let base: Base
5051

5152
@usableFromInline
5253
let isIncluded: (Element) async -> Bool
5354

54-
@usableFromInline
55+
@inlinable
5556
init(
5657
_ base: Base,
5758
isIncluded: @escaping (Base.Element) async -> Bool
@@ -72,14 +73,15 @@ extension AsyncFilterSequence: AsyncSequence {
7273
public typealias AsyncIterator = Iterator
7374

7475
/// The iterator that produces elements of the filter sequence.
76+
@frozen
7577
public struct Iterator: AsyncIteratorProtocol {
7678
@usableFromInline
7779
var baseIterator: Base.AsyncIterator
7880

7981
@usableFromInline
8082
let isIncluded: (Base.Element) async -> Bool
8183

82-
@usableFromInline
84+
@inlinable
8385
init(
8486
_ baseIterator: Base.AsyncIterator,
8587
isIncluded: @escaping (Base.Element) async -> Bool

stdlib/public/Concurrency/AsyncFlatMapSequence.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ extension AsyncSequence {
5050
/// An asynchronous sequence that concatenates the results of calling a given
5151
/// transformation with each element of this sequence.
5252
@available(SwiftStdlib 5.5, *)
53+
@frozen
5354
public struct AsyncFlatMapSequence<Base: AsyncSequence, SegmentOfResult: AsyncSequence> {
5455
@usableFromInline
5556
let base: Base
5657

5758
@usableFromInline
5859
let transform: (Base.Element) async -> SegmentOfResult
5960

60-
@usableFromInline
61+
@inlinable
6162
init(
6263
_ base: Base,
6364
transform: @escaping (Base.Element) async -> SegmentOfResult
@@ -78,6 +79,7 @@ extension AsyncFlatMapSequence: AsyncSequence {
7879
public typealias AsyncIterator = Iterator
7980

8081
/// The iterator that produces elements of the flat map sequence.
82+
@frozen
8183
public struct Iterator: AsyncIteratorProtocol {
8284
@usableFromInline
8385
var baseIterator: Base.AsyncIterator
@@ -91,7 +93,7 @@ extension AsyncFlatMapSequence: AsyncSequence {
9193
@usableFromInline
9294
var finished = false
9395

94-
@usableFromInline
96+
@inlinable
9597
init(
9698
_ baseIterator: Base.AsyncIterator,
9799
transform: @escaping (Base.Element) async -> SegmentOfResult

stdlib/public/Concurrency/AsyncMapSequence.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ extension AsyncSequence {
5454
/// An asynchronous sequence that maps the given closure over the asynchronous
5555
/// sequence’s elements.
5656
@available(SwiftStdlib 5.5, *)
57+
@frozen
5758
public struct AsyncMapSequence<Base: AsyncSequence, Transformed> {
5859
@usableFromInline
5960
let base: Base
6061

6162
@usableFromInline
6263
let transform: (Base.Element) async -> Transformed
6364

64-
@usableFromInline
65+
@inlinable
6566
init(
6667
_ base: Base,
6768
transform: @escaping (Base.Element) async -> Transformed
@@ -82,14 +83,15 @@ extension AsyncMapSequence: AsyncSequence {
8283
public typealias AsyncIterator = Iterator
8384

8485
/// The iterator that produces elements of the map sequence.
86+
@frozen
8587
public struct Iterator: AsyncIteratorProtocol {
8688
@usableFromInline
8789
var baseIterator: Base.AsyncIterator
8890

8991
@usableFromInline
9092
let transform: (Base.Element) async -> Transformed
9193

92-
@usableFromInline
94+
@inlinable
9395
init(
9496
_ baseIterator: Base.AsyncIterator,
9597
transform: @escaping (Base.Element) async -> Transformed

stdlib/public/Concurrency/AsyncPrefixSequence.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ extension AsyncSequence {
4949
/// An asynchronous sequence, up to a specified maximum length,
5050
/// containing the initial elements of a base asynchronous sequence.
5151
@available(SwiftStdlib 5.5, *)
52+
@frozen
5253
public struct AsyncPrefixSequence<Base: AsyncSequence> {
5354
@usableFromInline
5455
let base: Base
5556

5657
@usableFromInline
5758
let count: Int
5859

59-
@usableFromInline
60+
@inlinable
6061
init(_ base: Base, count: Int) {
6162
self.base = base
6263
self.count = count
@@ -74,14 +75,15 @@ extension AsyncPrefixSequence: AsyncSequence {
7475
public typealias AsyncIterator = Iterator
7576

7677
/// The iterator that produces elements of the prefix sequence.
78+
@frozen
7779
public struct Iterator: AsyncIteratorProtocol {
7880
@usableFromInline
7981
var baseIterator: Base.AsyncIterator
8082

8183
@usableFromInline
8284
var remaining: Int
8385

84-
@usableFromInline
86+
@inlinable
8587
init(_ baseIterator: Base.AsyncIterator, count: Int) {
8688
self.baseIterator = baseIterator
8789
self.remaining = count

stdlib/public/Concurrency/AsyncPrefixWhileSequence.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ extension AsyncSequence {
4949
/// An asynchronous sequence, containing the initial, consecutive
5050
/// elements of the base sequence that satisfy a given predicate.
5151
@available(SwiftStdlib 5.5, *)
52+
@frozen
5253
public struct AsyncPrefixWhileSequence<Base: AsyncSequence> {
5354
@usableFromInline
5455
let base: Base
5556

5657
@usableFromInline
5758
let predicate: (Base.Element) async -> Bool
5859

59-
@usableFromInline
60+
@inlinable
6061
init(
6162
_ base: Base,
6263
predicate: @escaping (Base.Element) async -> Bool
@@ -77,6 +78,7 @@ extension AsyncPrefixWhileSequence: AsyncSequence {
7778
public typealias AsyncIterator = Iterator
7879

7980
/// The iterator that produces elements of the prefix-while sequence.
81+
@frozen
8082
public struct Iterator: AsyncIteratorProtocol {
8183
@usableFromInline
8284
var predicateHasFailed = false
@@ -87,7 +89,7 @@ extension AsyncPrefixWhileSequence: AsyncSequence {
8789
@usableFromInline
8890
let predicate: (Base.Element) async -> Bool
8991

90-
@usableFromInline
92+
@inlinable
9193
init(
9294
_ baseIterator: Base.AsyncIterator,
9395
predicate: @escaping (Base.Element) async -> Bool

stdlib/public/Concurrency/AsyncThrowingCompactMapSequence.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,15 @@ extension AsyncSequence {
6868
/// An asynchronous sequence that maps an error-throwing closure over the base
6969
/// sequence’s elements, omitting results that don't return a value.
7070
@available(SwiftStdlib 5.5, *)
71+
@frozen
7172
public struct AsyncThrowingCompactMapSequence<Base: AsyncSequence, ElementOfResult> {
7273
@usableFromInline
7374
let base: Base
7475

7576
@usableFromInline
7677
let transform: (Base.Element) async throws -> ElementOfResult?
7778

78-
@usableFromInline
79+
@inlinable
7980
init(
8081
_ base: Base,
8182
transform: @escaping (Base.Element) async throws -> ElementOfResult?
@@ -96,6 +97,7 @@ extension AsyncThrowingCompactMapSequence: AsyncSequence {
9697
public typealias AsyncIterator = Iterator
9798

9899
/// The iterator that produces elements of the compact map sequence.
100+
@frozen
99101
public struct Iterator: AsyncIteratorProtocol {
100102
public typealias Element = ElementOfResult
101103

@@ -108,7 +110,7 @@ extension AsyncThrowingCompactMapSequence: AsyncSequence {
108110
@usableFromInline
109111
var finished = false
110112

111-
@usableFromInline
113+
@inlinable
112114
init(
113115
_ baseIterator: Base.AsyncIterator,
114116
transform: @escaping (Base.Element) async throws -> ElementOfResult?

stdlib/public/Concurrency/AsyncThrowingDropWhileSequence.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ extension AsyncSequence {
6666
/// given error-throwing closure returns false, after which it passes through
6767
/// all remaining elements.
6868
@available(SwiftStdlib 5.5, *)
69+
@frozen
6970
public struct AsyncThrowingDropWhileSequence<Base: AsyncSequence> {
7071
@usableFromInline
7172
let base: Base
7273

7374
@usableFromInline
7475
let predicate: (Base.Element) async throws -> Bool
7576

76-
@usableFromInline
77+
@inlinable
7778
init(
7879
_ base: Base,
7980
predicate: @escaping (Base.Element) async throws -> Bool
@@ -94,6 +95,7 @@ extension AsyncThrowingDropWhileSequence: AsyncSequence {
9495
public typealias AsyncIterator = Iterator
9596

9697
/// The iterator that produces elements of the drop-while sequence.
98+
@frozen
9799
public struct Iterator: AsyncIteratorProtocol {
98100
@usableFromInline
99101
var baseIterator: Base.AsyncIterator
@@ -107,7 +109,7 @@ extension AsyncThrowingDropWhileSequence: AsyncSequence {
107109
@usableFromInline
108110
var doneDropping = false
109111

110-
@usableFromInline
112+
@inlinable
111113
init(
112114
_ baseIterator: Base.AsyncIterator,
113115
predicate: @escaping (Base.Element) async throws -> Bool

stdlib/public/Concurrency/AsyncThrowingFilterSequence.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ extension AsyncSequence {
5656
/// An asynchronous sequence that contains, in order, the elements of
5757
/// the base sequence that satisfy the given error-throwing predicate.
5858
@available(SwiftStdlib 5.5, *)
59+
@frozen
5960
public struct AsyncThrowingFilterSequence<Base: AsyncSequence> {
6061
@usableFromInline
6162
let base: Base
6263

6364
@usableFromInline
6465
let isIncluded: (Element) async throws -> Bool
6566

66-
@usableFromInline
67+
@inlinable
6768
init(
6869
_ base: Base,
6970
isIncluded: @escaping (Base.Element) async throws -> Bool
@@ -84,6 +85,7 @@ extension AsyncThrowingFilterSequence: AsyncSequence {
8485
public typealias AsyncIterator = Iterator
8586

8687
/// The iterator that produces elements of the filter sequence.
88+
@frozen
8789
public struct Iterator: AsyncIteratorProtocol {
8890
@usableFromInline
8991
var baseIterator: Base.AsyncIterator
@@ -94,7 +96,7 @@ extension AsyncThrowingFilterSequence: AsyncSequence {
9496
@usableFromInline
9597
var finished = false
9698

97-
@usableFromInline
99+
@inlinable
98100
init(
99101
_ baseIterator: Base.AsyncIterator,
100102
isIncluded: @escaping (Base.Element) async throws -> Bool

stdlib/public/Concurrency/AsyncThrowingFlatMapSequence.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ extension AsyncSequence {
6464
/// An asynchronous sequence that concatenates the results of calling a given
6565
/// error-throwing transformation with each element of this sequence.
6666
@available(SwiftStdlib 5.5, *)
67+
@frozen
6768
public struct AsyncThrowingFlatMapSequence<Base: AsyncSequence, SegmentOfResult: AsyncSequence> {
6869
@usableFromInline
6970
let base: Base
@@ -92,6 +93,7 @@ extension AsyncThrowingFlatMapSequence: AsyncSequence {
9293
public typealias AsyncIterator = Iterator
9394

9495
/// The iterator that produces elements of the flat map sequence.
96+
@frozen
9597
public struct Iterator: AsyncIteratorProtocol {
9698
@usableFromInline
9799
var baseIterator: Base.AsyncIterator

0 commit comments

Comments
 (0)