Skip to content

[6.2][Concurrency] Add Hashable conformance to Async(Throwing)Stream.Continuation #81064

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
Apr 25, 2025
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
16 changes: 16 additions & 0 deletions stdlib/public/Concurrency/AsyncStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,22 @@ extension AsyncStream: @unchecked Sendable where Element: Sendable { }
@available(SwiftStdlib 5.1, *)
extension AsyncStream.Continuation.YieldResult: Sendable where Element: Sendable { }

@available(SwiftStdlib 6.2, *)
extension AsyncStream.Continuation: Hashable {
@available(SwiftStdlib 6.2, *)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these all be @inlinable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public func hash(into hasher: inout Hasher) {
return hasher.combine(ObjectIdentifier(storage))
}
@available(SwiftStdlib 6.2, *)
public var hashValue: Int {
return _hashValue(for: self)
}
@available(SwiftStdlib 6.2, *)
public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.storage === rhs.storage
}
}

#else
@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
Expand Down
16 changes: 16 additions & 0 deletions stdlib/public/Concurrency/AsyncThrowingStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,22 @@ extension AsyncThrowingStream: @unchecked Sendable where Element: Sendable { }
@available(SwiftStdlib 5.1, *)
extension AsyncThrowingStream.Continuation.YieldResult: Sendable where Element: Sendable { }

@available(SwiftStdlib 6.2, *)
extension AsyncThrowingStream.Continuation: Hashable {
@available(SwiftStdlib 6.2, *)
public func hash(into hasher: inout Hasher) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here

return hasher.combine(ObjectIdentifier(storage))
}
@available(SwiftStdlib 6.2, *)
public var hashValue: Int {
return _hashValue(for: self)
}
@available(SwiftStdlib 6.2, *)
public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.storage === rhs.storage
}
}

#else
@available(SwiftStdlib 5.1, *)
@available(*, unavailable, message: "Unavailable in task-to-thread concurrency model")
Expand Down
18 changes: 18 additions & 0 deletions test/Concurrency/Runtime/async_stream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,24 @@ class NotSendable {}
expectTrue(expectation.fulfilled)
}

tests.test("continuation equality") {
let (_, continuation1) = AsyncStream<Int>.makeStream()
let (_, continuation2) = AsyncStream<Int>.makeStream()
expectTrue(continuation1 == continuation1)
expectTrue(continuation1 != continuation2)
expectTrue(continuation1.hashValue == continuation1.hashValue)
expectTrue(continuation1.hashValue != continuation2.hashValue)
}

tests.test("throwing continuation equality") {
let (_, continuation1) = AsyncThrowingStream<Int, Error>.makeStream()
let (_, continuation2) = AsyncThrowingStream<Int, Error>.makeStream()
expectTrue(continuation1 == continuation1)
expectTrue(continuation1 != continuation2)
expectTrue(continuation1.hashValue == continuation1.hashValue)
expectTrue(continuation1.hashValue != continuation2.hashValue)
}

// MARK: - Multiple consumers

tests.test("finish behavior with multiple consumers") {
Expand Down
12 changes: 12 additions & 0 deletions test/abi/Inputs/macOS/arm64/concurrency/baseline
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,18 @@ _$sScS12ContinuationV15BufferingPolicyO15bufferingOldestyADyx__GSicAFmlFWC
_$sScS12ContinuationV15BufferingPolicyO9unboundedyADyx__GAFmlFWC
_$sScS12ContinuationV15BufferingPolicyOMa
_$sScS12ContinuationV15BufferingPolicyOMn
_$sScS12ContinuationV2eeoiySbAByx_G_ADtFZ
_$sScS12ContinuationV4hash4intoys6HasherVz_tF
_$sScS12ContinuationV5yield4withAB11YieldResultOyx__Gs0E0Oyxs5NeverOG_tF
_$sScS12ContinuationV5yieldAB11YieldResultOyyt__GyytRszlF
_$sScS12ContinuationV5yieldyAB11YieldResultOyx__GxnF
_$sScS12ContinuationV6finishyyF
_$sScS12ContinuationV9hashValueSivg
_$sScS12ContinuationV9hashValueSivpMV
_$sScS12ContinuationVMa
_$sScS12ContinuationVMn
_$sScS12ContinuationVyx_GSHsMc
_$sScS12ContinuationVyx_GSQsMc
_$sScS17makeAsyncIteratorScS0C0Vyx_GyF
_$sScS8IteratorV4nextxSgyYaF
_$sScS8IteratorV4nextxSgyYaFTu
Expand Down Expand Up @@ -359,12 +365,18 @@ _$sScs12ContinuationV15BufferingPolicyO15bufferingOldestyADyxq___GSicAFms5ErrorR
_$sScs12ContinuationV15BufferingPolicyO9unboundedyADyxq___GAFms5ErrorR_r0_lFWC
_$sScs12ContinuationV15BufferingPolicyOMa
_$sScs12ContinuationV15BufferingPolicyOMn
_$sScs12ContinuationV2eeoiySbAByxq__G_ADtFZ
_$sScs12ContinuationV4hash4intoys6HasherVz_tF
_$sScs12ContinuationV5yield4withAB11YieldResultOyxs5Error_p__Gs0E0OyxsAG_pG_tsAG_pRs_rlF
_$sScs12ContinuationV5yieldAB11YieldResultOyytq___GyytRszrlF
_$sScs12ContinuationV5yieldyAB11YieldResultOyxq___GxnF
_$sScs12ContinuationV6finish8throwingyq_Sgn_tF
_$sScs12ContinuationV9hashValueSivg
_$sScs12ContinuationV9hashValueSivpMV
_$sScs12ContinuationVMa
_$sScs12ContinuationVMn
_$sScs12ContinuationVyxq__GSHsMc
_$sScs12ContinuationVyxq__GSQsMc
_$sScs17makeAsyncIteratorScs0C0Vyxq__GyF
_$sScs8IteratorV4nextxSgyYaKF
_$sScs8IteratorV4nextxSgyYaKFTu
Expand Down
12 changes: 12 additions & 0 deletions test/abi/Inputs/macOS/arm64/concurrency/baseline-asserts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,18 @@ _$sScS12ContinuationV15BufferingPolicyO15bufferingOldestyADyx__GSicAFmlFWC
_$sScS12ContinuationV15BufferingPolicyO9unboundedyADyx__GAFmlFWC
_$sScS12ContinuationV15BufferingPolicyOMa
_$sScS12ContinuationV15BufferingPolicyOMn
_$sScS12ContinuationV2eeoiySbAByx_G_ADtFZ
_$sScS12ContinuationV4hash4intoys6HasherVz_tF
_$sScS12ContinuationV5yield4withAB11YieldResultOyx__Gs0E0Oyxs5NeverOG_tF
_$sScS12ContinuationV5yieldAB11YieldResultOyyt__GyytRszlF
_$sScS12ContinuationV5yieldyAB11YieldResultOyx__GxnF
_$sScS12ContinuationV6finishyyF
_$sScS12ContinuationV9hashValueSivg
_$sScS12ContinuationV9hashValueSivpMV
_$sScS12ContinuationVMa
_$sScS12ContinuationVMn
_$sScS12ContinuationVyx_GSHsMc
_$sScS12ContinuationVyx_GSQsMc
_$sScS17makeAsyncIteratorScS0C0Vyx_GyF
_$sScS8IteratorV4nextxSgyYaF
_$sScS8IteratorV4nextxSgyYaFTu
Expand Down Expand Up @@ -359,12 +365,18 @@ _$sScs12ContinuationV15BufferingPolicyO15bufferingOldestyADyxq___GSicAFms5ErrorR
_$sScs12ContinuationV15BufferingPolicyO9unboundedyADyxq___GAFms5ErrorR_r0_lFWC
_$sScs12ContinuationV15BufferingPolicyOMa
_$sScs12ContinuationV15BufferingPolicyOMn
_$sScs12ContinuationV2eeoiySbAByxq__G_ADtFZ
_$sScs12ContinuationV4hash4intoys6HasherVz_tF
_$sScs12ContinuationV5yield4withAB11YieldResultOyxs5Error_p__Gs0E0OyxsAG_pG_tsAG_pRs_rlF
_$sScs12ContinuationV5yieldAB11YieldResultOyytq___GyytRszrlF
_$sScs12ContinuationV5yieldyAB11YieldResultOyxq___GxnF
_$sScs12ContinuationV6finish8throwingyq_Sgn_tF
_$sScs12ContinuationV9hashValueSivg
_$sScs12ContinuationV9hashValueSivpMV
_$sScs12ContinuationVMa
_$sScs12ContinuationVMn
_$sScs12ContinuationVyxq__GSHsMc
_$sScs12ContinuationVyxq__GSQsMc
_$sScs17makeAsyncIteratorScs0C0Vyxq__GyF
_$sScs8IteratorV4nextxSgyYaKF
_$sScs8IteratorV4nextxSgyYaKFTu
Expand Down
12 changes: 12 additions & 0 deletions test/abi/Inputs/macOS/x86_64/concurrency/baseline
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,18 @@ _$sScS12ContinuationV15BufferingPolicyO15bufferingOldestyADyx__GSicAFmlFWC
_$sScS12ContinuationV15BufferingPolicyO9unboundedyADyx__GAFmlFWC
_$sScS12ContinuationV15BufferingPolicyOMa
_$sScS12ContinuationV15BufferingPolicyOMn
_$sScS12ContinuationV2eeoiySbAByx_G_ADtFZ
_$sScS12ContinuationV4hash4intoys6HasherVz_tF
_$sScS12ContinuationV5yield4withAB11YieldResultOyx__Gs0E0Oyxs5NeverOG_tF
_$sScS12ContinuationV5yieldAB11YieldResultOyyt__GyytRszlF
_$sScS12ContinuationV5yieldyAB11YieldResultOyx__GxnF
_$sScS12ContinuationV6finishyyF
_$sScS12ContinuationV9hashValueSivg
_$sScS12ContinuationV9hashValueSivpMV
_$sScS12ContinuationVMa
_$sScS12ContinuationVMn
_$sScS12ContinuationVyx_GSHsMc
_$sScS12ContinuationVyx_GSQsMc
_$sScS17makeAsyncIteratorScS0C0Vyx_GyF
_$sScS8IteratorV4nextxSgyYaF
_$sScS8IteratorV4nextxSgyYaFTu
Expand Down Expand Up @@ -359,12 +365,18 @@ _$sScs12ContinuationV15BufferingPolicyO15bufferingOldestyADyxq___GSicAFms5ErrorR
_$sScs12ContinuationV15BufferingPolicyO9unboundedyADyxq___GAFms5ErrorR_r0_lFWC
_$sScs12ContinuationV15BufferingPolicyOMa
_$sScs12ContinuationV15BufferingPolicyOMn
_$sScs12ContinuationV2eeoiySbAByxq__G_ADtFZ
_$sScs12ContinuationV4hash4intoys6HasherVz_tF
_$sScs12ContinuationV5yield4withAB11YieldResultOyxs5Error_p__Gs0E0OyxsAG_pG_tsAG_pRs_rlF
_$sScs12ContinuationV5yieldAB11YieldResultOyytq___GyytRszrlF
_$sScs12ContinuationV5yieldyAB11YieldResultOyxq___GxnF
_$sScs12ContinuationV6finish8throwingyq_Sgn_tF
_$sScs12ContinuationV9hashValueSivg
_$sScs12ContinuationV9hashValueSivpMV
_$sScs12ContinuationVMa
_$sScs12ContinuationVMn
_$sScs12ContinuationVyxq__GSHsMc
_$sScs12ContinuationVyxq__GSQsMc
_$sScs17makeAsyncIteratorScs0C0Vyxq__GyF
_$sScs8IteratorV4nextxSgyYaKF
_$sScs8IteratorV4nextxSgyYaKFTu
Expand Down
12 changes: 12 additions & 0 deletions test/abi/Inputs/macOS/x86_64/concurrency/baseline-asserts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,18 @@ _$sScS12ContinuationV15BufferingPolicyO15bufferingOldestyADyx__GSicAFmlFWC
_$sScS12ContinuationV15BufferingPolicyO9unboundedyADyx__GAFmlFWC
_$sScS12ContinuationV15BufferingPolicyOMa
_$sScS12ContinuationV15BufferingPolicyOMn
_$sScS12ContinuationV2eeoiySbAByx_G_ADtFZ
_$sScS12ContinuationV4hash4intoys6HasherVz_tF
_$sScS12ContinuationV5yield4withAB11YieldResultOyx__Gs0E0Oyxs5NeverOG_tF
_$sScS12ContinuationV5yieldAB11YieldResultOyyt__GyytRszlF
_$sScS12ContinuationV5yieldyAB11YieldResultOyx__GxnF
_$sScS12ContinuationV6finishyyF
_$sScS12ContinuationV9hashValueSivg
_$sScS12ContinuationV9hashValueSivpMV
_$sScS12ContinuationVMa
_$sScS12ContinuationVMn
_$sScS12ContinuationVyx_GSHsMc
_$sScS12ContinuationVyx_GSQsMc
_$sScS17makeAsyncIteratorScS0C0Vyx_GyF
_$sScS8IteratorV4nextxSgyYaF
_$sScS8IteratorV4nextxSgyYaFTu
Expand Down Expand Up @@ -359,12 +365,18 @@ _$sScs12ContinuationV15BufferingPolicyO15bufferingOldestyADyxq___GSicAFms5ErrorR
_$sScs12ContinuationV15BufferingPolicyO9unboundedyADyxq___GAFms5ErrorR_r0_lFWC
_$sScs12ContinuationV15BufferingPolicyOMa
_$sScs12ContinuationV15BufferingPolicyOMn
_$sScs12ContinuationV2eeoiySbAByxq__G_ADtFZ
_$sScs12ContinuationV4hash4intoys6HasherVz_tF
_$sScs12ContinuationV5yield4withAB11YieldResultOyxs5Error_p__Gs0E0OyxsAG_pG_tsAG_pRs_rlF
_$sScs12ContinuationV5yieldAB11YieldResultOyytq___GyytRszrlF
_$sScs12ContinuationV5yieldyAB11YieldResultOyxq___GxnF
_$sScs12ContinuationV6finish8throwingyq_Sgn_tF
_$sScs12ContinuationV9hashValueSivg
_$sScs12ContinuationV9hashValueSivpMV
_$sScs12ContinuationVMa
_$sScs12ContinuationVMn
_$sScs12ContinuationVyxq__GSHsMc
_$sScs12ContinuationVyxq__GSQsMc
_$sScs17makeAsyncIteratorScs0C0Vyxq__GyF
_$sScs8IteratorV4nextxSgyYaKF
_$sScs8IteratorV4nextxSgyYaKFTu
Expand Down