Skip to content

Allow AsyncSequence operators to be inlined in their construction #38310

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 1 commit into from
Jul 9, 2021
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
6 changes: 4 additions & 2 deletions stdlib/public/Concurrency/AsyncCompactMapSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ extension AsyncSequence {
/// An asynchronous sequence that maps a given closure over the asynchronous
/// sequence’s elements, omitting results that don't return a value.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncCompactMapSequence<Base: AsyncSequence, ElementOfResult> {
@usableFromInline
let base: Base

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

@usableFromInline
@inlinable
init(
_ base: Base,
transform: @escaping (Base.Element) async -> ElementOfResult?
Expand All @@ -84,6 +85,7 @@ extension AsyncCompactMapSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

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

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

@usableFromInline
@inlinable
init(
_ baseIterator: Base.AsyncIterator,
transform: @escaping (Base.Element) async -> ElementOfResult?
Expand Down
6 changes: 4 additions & 2 deletions stdlib/public/Concurrency/AsyncDropFirstSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ extension AsyncSequence {
/// An asynchronous sequence which omits a specified number of elements from the
/// base asynchronous sequence, then passes through all remaining elements.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncDropFirstSequence<Base: AsyncSequence> {
@usableFromInline
let base: Base

@usableFromInline
let count: Int

@usableFromInline
@inlinable
init(_ base: Base, dropping count: Int) {
self.base = base
self.count = count
Expand All @@ -74,14 +75,15 @@ extension AsyncDropFirstSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

/// The iterator that produces elements of the drop-first sequence.
@frozen
public struct Iterator: AsyncIteratorProtocol {
@usableFromInline
var baseIterator: Base.AsyncIterator

@usableFromInline
var count: Int

@usableFromInline
@inlinable
init(_ baseIterator: Base.AsyncIterator, count: Int) {
self.baseIterator = baseIterator
self.count = count
Expand Down
6 changes: 4 additions & 2 deletions stdlib/public/Concurrency/AsyncDropWhileSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ extension AsyncSequence {
/// given closure returns false, after which it passes through all remaining
/// elements.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncDropWhileSequence<Base: AsyncSequence> {
@usableFromInline
let base: Base

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

@usableFromInline
@inlinable
init(
_ base: Base,
predicate: @escaping (Base.Element) async -> Bool
Expand All @@ -82,14 +83,15 @@ extension AsyncDropWhileSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

/// The iterator that produces elements of the drop-while sequence.
@frozen
public struct Iterator: AsyncIteratorProtocol {
@usableFromInline
var baseIterator: Base.AsyncIterator

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

@usableFromInline
@inlinable
init(
_ baseIterator: Base.AsyncIterator,
predicate: @escaping (Base.Element) async -> Bool
Expand Down
6 changes: 4 additions & 2 deletions stdlib/public/Concurrency/AsyncFilterSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ extension AsyncSequence {
/// An asynchronous sequence that contains, in order, the elements of
/// the base sequence that satisfy a given predicate.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncFilterSequence<Base: AsyncSequence> {
@usableFromInline
let base: Base

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

@usableFromInline
@inlinable
init(
_ base: Base,
isIncluded: @escaping (Base.Element) async -> Bool
Expand All @@ -72,14 +73,15 @@ extension AsyncFilterSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

/// The iterator that produces elements of the filter sequence.
@frozen
public struct Iterator: AsyncIteratorProtocol {
@usableFromInline
var baseIterator: Base.AsyncIterator

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

@usableFromInline
@inlinable
init(
_ baseIterator: Base.AsyncIterator,
isIncluded: @escaping (Base.Element) async -> Bool
Expand Down
6 changes: 4 additions & 2 deletions stdlib/public/Concurrency/AsyncFlatMapSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ extension AsyncSequence {
/// An asynchronous sequence that concatenates the results of calling a given
/// transformation with each element of this sequence.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncFlatMapSequence<Base: AsyncSequence, SegmentOfResult: AsyncSequence> {
@usableFromInline
let base: Base

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

@usableFromInline
@inlinable
init(
_ base: Base,
transform: @escaping (Base.Element) async -> SegmentOfResult
Expand All @@ -78,6 +79,7 @@ extension AsyncFlatMapSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

/// The iterator that produces elements of the flat map sequence.
@frozen
public struct Iterator: AsyncIteratorProtocol {
@usableFromInline
var baseIterator: Base.AsyncIterator
Expand All @@ -91,7 +93,7 @@ extension AsyncFlatMapSequence: AsyncSequence {
@usableFromInline
var finished = false

@usableFromInline
@inlinable
init(
_ baseIterator: Base.AsyncIterator,
transform: @escaping (Base.Element) async -> SegmentOfResult
Expand Down
6 changes: 4 additions & 2 deletions stdlib/public/Concurrency/AsyncMapSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ extension AsyncSequence {
/// An asynchronous sequence that maps the given closure over the asynchronous
/// sequence’s elements.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncMapSequence<Base: AsyncSequence, Transformed> {
@usableFromInline
let base: Base

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

@usableFromInline
@inlinable
init(
_ base: Base,
transform: @escaping (Base.Element) async -> Transformed
Expand All @@ -82,14 +83,15 @@ extension AsyncMapSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

/// The iterator that produces elements of the map sequence.
@frozen
public struct Iterator: AsyncIteratorProtocol {
@usableFromInline
var baseIterator: Base.AsyncIterator

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

@usableFromInline
@inlinable
init(
_ baseIterator: Base.AsyncIterator,
transform: @escaping (Base.Element) async -> Transformed
Expand Down
6 changes: 4 additions & 2 deletions stdlib/public/Concurrency/AsyncPrefixSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ extension AsyncSequence {
/// An asynchronous sequence, up to a specified maximum length,
/// containing the initial elements of a base asynchronous sequence.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncPrefixSequence<Base: AsyncSequence> {
@usableFromInline
let base: Base

@usableFromInline
let count: Int

@usableFromInline
@inlinable
init(_ base: Base, count: Int) {
self.base = base
self.count = count
Expand All @@ -74,14 +75,15 @@ extension AsyncPrefixSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

/// The iterator that produces elements of the prefix sequence.
@frozen
public struct Iterator: AsyncIteratorProtocol {
@usableFromInline
var baseIterator: Base.AsyncIterator

@usableFromInline
var remaining: Int

@usableFromInline
@inlinable
init(_ baseIterator: Base.AsyncIterator, count: Int) {
self.baseIterator = baseIterator
self.remaining = count
Expand Down
6 changes: 4 additions & 2 deletions stdlib/public/Concurrency/AsyncPrefixWhileSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ extension AsyncSequence {
/// An asynchronous sequence, containing the initial, consecutive
/// elements of the base sequence that satisfy a given predicate.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncPrefixWhileSequence<Base: AsyncSequence> {
@usableFromInline
let base: Base

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

@usableFromInline
@inlinable
init(
_ base: Base,
predicate: @escaping (Base.Element) async -> Bool
Expand All @@ -77,6 +78,7 @@ extension AsyncPrefixWhileSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

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

@usableFromInline
@inlinable
init(
_ baseIterator: Base.AsyncIterator,
predicate: @escaping (Base.Element) async -> Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ extension AsyncSequence {
/// An asynchronous sequence that maps an error-throwing closure over the base
/// sequence’s elements, omitting results that don't return a value.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncThrowingCompactMapSequence<Base: AsyncSequence, ElementOfResult> {
@usableFromInline
let base: Base

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

@usableFromInline
@inlinable
init(
_ base: Base,
transform: @escaping (Base.Element) async throws -> ElementOfResult?
Expand All @@ -96,6 +97,7 @@ extension AsyncThrowingCompactMapSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

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

Expand All @@ -108,7 +110,7 @@ extension AsyncThrowingCompactMapSequence: AsyncSequence {
@usableFromInline
var finished = false

@usableFromInline
@inlinable
init(
_ baseIterator: Base.AsyncIterator,
transform: @escaping (Base.Element) async throws -> ElementOfResult?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ extension AsyncSequence {
/// given error-throwing closure returns false, after which it passes through
/// all remaining elements.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncThrowingDropWhileSequence<Base: AsyncSequence> {
@usableFromInline
let base: Base

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

@usableFromInline
@inlinable
init(
_ base: Base,
predicate: @escaping (Base.Element) async throws -> Bool
Expand All @@ -94,6 +95,7 @@ extension AsyncThrowingDropWhileSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

/// The iterator that produces elements of the drop-while sequence.
@frozen
public struct Iterator: AsyncIteratorProtocol {
@usableFromInline
var baseIterator: Base.AsyncIterator
Expand All @@ -107,7 +109,7 @@ extension AsyncThrowingDropWhileSequence: AsyncSequence {
@usableFromInline
var doneDropping = false

@usableFromInline
@inlinable
init(
_ baseIterator: Base.AsyncIterator,
predicate: @escaping (Base.Element) async throws -> Bool
Expand Down
6 changes: 4 additions & 2 deletions stdlib/public/Concurrency/AsyncThrowingFilterSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ extension AsyncSequence {
/// An asynchronous sequence that contains, in order, the elements of
/// the base sequence that satisfy the given error-throwing predicate.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncThrowingFilterSequence<Base: AsyncSequence> {
@usableFromInline
let base: Base

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

@usableFromInline
@inlinable
init(
_ base: Base,
isIncluded: @escaping (Base.Element) async throws -> Bool
Expand All @@ -84,6 +85,7 @@ extension AsyncThrowingFilterSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

/// The iterator that produces elements of the filter sequence.
@frozen
public struct Iterator: AsyncIteratorProtocol {
@usableFromInline
var baseIterator: Base.AsyncIterator
Expand All @@ -94,7 +96,7 @@ extension AsyncThrowingFilterSequence: AsyncSequence {
@usableFromInline
var finished = false

@usableFromInline
@inlinable
init(
_ baseIterator: Base.AsyncIterator,
isIncluded: @escaping (Base.Element) async throws -> Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ extension AsyncSequence {
/// An asynchronous sequence that concatenates the results of calling a given
/// error-throwing transformation with each element of this sequence.
@available(SwiftStdlib 5.5, *)
@frozen
public struct AsyncThrowingFlatMapSequence<Base: AsyncSequence, SegmentOfResult: AsyncSequence> {
@usableFromInline
let base: Base
Expand Down Expand Up @@ -92,6 +93,7 @@ extension AsyncThrowingFlatMapSequence: AsyncSequence {
public typealias AsyncIterator = Iterator

/// The iterator that produces elements of the flat map sequence.
@frozen
public struct Iterator: AsyncIteratorProtocol {
@usableFromInline
var baseIterator: Base.AsyncIterator
Expand Down
Loading