Skip to content

[Concurrency] An implementation of system epochs for continuous and suspending clocks #80409

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 5 commits into from
May 5, 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
8 changes: 8 additions & 0 deletions stdlib/public/Concurrency/ContinuousClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ extension ContinuousClock: Clock {
#endif
}

@available(SwiftStdlib 5.7, *)
@_unavailableInEmbedded
extension ContinuousClock {
@available(SwiftStdlib 5.7, *)
@_alwaysEmitIntoClient
public var systemEpoch: Instant { unsafeBitCast(Duration.seconds(0), to: Instant.self) }
}

@available(SwiftStdlib 5.7, *)
@_unavailableInEmbedded
extension ContinuousClock.Instant: InstantProtocol {
Expand Down
8 changes: 8 additions & 0 deletions stdlib/public/Concurrency/SuspendingClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ extension SuspendingClock: Clock {
#endif
}

@available(SwiftStdlib 5.7, *)
@_unavailableInEmbedded
extension SuspendingClock {
@available(SwiftStdlib 5.7, *)
@_alwaysEmitIntoClient
public var systemEpoch: Instant { unsafeBitCast(Duration.seconds(0), to: Instant.self) }
}

@available(SwiftStdlib 5.7, *)
@_unavailableInEmbedded
extension SuspendingClock.Instant: InstantProtocol {
Expand Down
7 changes: 7 additions & 0 deletions test/Concurrency/Runtime/clock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ import StdlibUnittest
}
}

tests.test("Ensure abi layout size of Instant") {
// If this test fails it means the ABI of ContinuousClock.Instant has been broken!
// it MUST be the same laoyut of that of Duration
expectEqual(MemoryLayout<ContinuousClock.Instant>.size, MemoryLayout<Duration>.size)
expectEqual(MemoryLayout<SuspendingClock.Instant>.size, MemoryLayout<Duration>.size)
}

await runAllTestsAsync()
}
}
6 changes: 5 additions & 1 deletion test/abi/macOS/arm64/concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ Added: _swift_task_dealloc_through
// SwiftSettings
Added: _$ss12SwiftSettingVsE16defaultIsolationyABScA_pXpSgFZ

// Clock systemEpochs
Added: _$ss15ContinuousClockV11systemEpochAB7InstantVvpMV
Added: _$ss15SuspendingClockV11systemEpochAB7InstantVvpMV

// Hashable for (Throwing)AsyncStream
Added: _$sScS12ContinuationV7storageScS8_StorageCyx_Gvg
Added: _$sScS12ContinuationV7storageScS8_StorageCyx_GvpMV
Expand All @@ -434,4 +438,4 @@ Added: _$sScs8_StorageCMn
Added: _$sScs8_StorageCMo
Added: _$sScs8_StorageCMu
Added: _$sScs8_StorageCfD
Added: _$sScs8_StorageCfd
Added: _$sScs8_StorageCfd
6 changes: 5 additions & 1 deletion test/abi/macOS/x86_64/concurrency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ Added: _swift_task_dealloc_through
// SwiftSettings
Added: _$ss12SwiftSettingVsE16defaultIsolationyABScA_pXpSgFZ

// Clock systemEpochs
Added: _$ss15ContinuousClockV11systemEpochAB7InstantVvpMV
Added: _$ss15SuspendingClockV11systemEpochAB7InstantVvpMV

// Hashable for (Throwing)AsyncStream
Added: _$sScS12ContinuationV7storageScS8_StorageCyx_Gvg
Added: _$sScS12ContinuationV7storageScS8_StorageCyx_GvpMV
Expand All @@ -434,4 +438,4 @@ Added: _$sScs8_StorageCMn
Added: _$sScs8_StorageCMo
Added: _$sScs8_StorageCMu
Added: _$sScs8_StorageCfD
Added: _$sScs8_StorageCfd
Added: _$sScs8_StorageCfd