Skip to content

Commit 7516147

Browse files
committed
Shift operators to concrete Instant types to avoid complexity in solver resolution
1 parent 26233b0 commit 7516147

File tree

3 files changed

+95
-3
lines changed

3 files changed

+95
-3
lines changed

stdlib/public/Concurrency/ContinuousClock.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,44 @@ extension ContinuousClock.Instant: InstantProtocol {
9494
) -> Bool {
9595
return lhs._value < rhs._value
9696
}
97+
98+
@_alwaysEmitIntoClient
99+
@inlinable
100+
public static func + (
101+
_ lhs: ContinuousClock.Instant, _ rhs: Duration
102+
) -> ContinuousClock.Instant {
103+
lhs.advanced(by: rhs)
104+
}
105+
106+
@_alwaysEmitIntoClient
107+
@inlinable
108+
public static func += (
109+
_ lhs: inout ContinuousClock.Instant, _ rhs: Duration
110+
) {
111+
lhs = lhs.advanced(by: rhs)
112+
}
113+
114+
@_alwaysEmitIntoClient
115+
@inlinable
116+
public static func - (
117+
_ lhs: ContinuousClock.Instant, _ rhs: Duration
118+
) -> ContinuousClock.Instant {
119+
lhs.advanced(by: .zero - rhs)
120+
}
121+
122+
@_alwaysEmitIntoClient
123+
@inlinable
124+
public static func -= (
125+
_ lhs: inout ContinuousClock.Instant, _ rhs: Duration
126+
) {
127+
lhs = lhs.advanced(by: .zero - rhs)
128+
}
129+
130+
@_alwaysEmitIntoClient
131+
@inlinable
132+
public static func - (
133+
_ lhs: ContinuousClock.Instant, _ rhs: ContinuousClock.Instant
134+
) -> Duration {
135+
rhs.duration(to: lhs)
136+
}
97137
}

stdlib/public/Concurrency/SuspendingClock.swift

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension SuspendingClock: Clock {
4141
_getClockRes(
4242
seconds: &seconds,
4343
nanoseconds: &nanoseconds,
44-
clock: .continuous)
44+
clock: .suspending)
4545
return SuspendingClock.Instant(_value:
4646
.seconds(seconds) + .nanoseconds(nanoseconds))
4747
}
@@ -52,7 +52,7 @@ extension SuspendingClock: Clock {
5252
_getClockRes(
5353
seconds: &seconds,
5454
nanoseconds: &nanoseconds,
55-
clock: .continuous)
55+
clock: .suspending)
5656
return .seconds(seconds) + .nanoseconds(nanoseconds)
5757
}
5858

@@ -93,5 +93,45 @@ extension SuspendingClock.Instant: InstantProtocol {
9393
) -> Bool {
9494
return lhs._value < rhs._value
9595
}
96+
97+
@_alwaysEmitIntoClient
98+
@inlinable
99+
public static func + (
100+
_ lhs: SuspendingClock.Instant, _ rhs: Duration
101+
) -> SuspendingClock.Instant {
102+
lhs.advanced(by: rhs)
103+
}
104+
105+
@_alwaysEmitIntoClient
106+
@inlinable
107+
public static func += (
108+
_ lhs: inout SuspendingClock.Instant, _ rhs: Duration
109+
) {
110+
lhs = lhs.advanced(by: rhs)
111+
}
112+
113+
@_alwaysEmitIntoClient
114+
@inlinable
115+
public static func - (
116+
_ lhs: SuspendingClock.Instant, _ rhs: Duration
117+
) -> SuspendingClock.Instant {
118+
lhs.advanced(by: .zero - rhs)
119+
}
120+
121+
@_alwaysEmitIntoClient
122+
@inlinable
123+
public static func -= (
124+
_ lhs: inout SuspendingClock.Instant, _ rhs: Duration
125+
) {
126+
lhs = lhs.advanced(by: .zero - rhs)
127+
}
128+
129+
@_alwaysEmitIntoClient
130+
@inlinable
131+
public static func - (
132+
_ lhs: SuspendingClock.Instant, _ rhs: SuspendingClock.Instant
133+
) -> Duration {
134+
rhs.duration(to: lhs)
135+
}
96136
}
97137

stdlib/public/core/Instant.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,37 @@ public protocol InstantProtocol: Comparable, Hashable, Sendable {
1616
func duration(to other: Self) -> Interval
1717
}
1818

19+
/*
20+
disabled for now - this perturbs operator resolution
1921
extension InstantProtocol {
22+
@_alwaysEmitIntoClient
23+
@inlinable
2024
public static func + (_ lhs: Self, _ rhs: Interval) -> Self {
2125
lhs.advanced(by: rhs)
2226
}
2327

28+
@_alwaysEmitIntoClient
29+
@inlinable
2430
public static func += (_ lhs: inout Self, _ rhs: Interval) {
2531
lhs = lhs.advanced(by: rhs)
2632
}
2733

34+
@_alwaysEmitIntoClient
35+
@inlinable
2836
public static func - (_ lhs: Self, _ rhs: Interval) -> Self {
2937
lhs.advanced(by: .zero - rhs)
3038
}
3139

40+
@_alwaysEmitIntoClient
41+
@inlinable
3242
public static func -= (_ lhs: inout Self, _ rhs: Interval) {
3343
lhs = lhs.advanced(by: .zero - rhs)
3444
}
3545

46+
@_alwaysEmitIntoClient
47+
@inlinable
3648
public static func - (_ lhs: Self, _ rhs: Self) -> Interval {
3749
rhs.duration(to: lhs)
3850
}
3951
}
40-
52+
*/

0 commit comments

Comments
 (0)