Skip to content

Commit 5e7e07a

Browse files
Add Instant monotonicity section
1 parent 623ec6a commit 5e7e07a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

posts/2022-04-07-Rust-1.60.0.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,32 @@ In this example, enabling the serde feature will enable the serde dependency. It
124124

125125
Incremental compilation is re-enabled for the 1.60 release. The Rust team continues to work on fixing bugs in incremental, but no problems causing widespread breakage are known at this time, so we have chosen to reenable incremental compilation. Additionally, the compiler team is continuing to work on long-term strategy to avoid future problems of this kind. That process is in relatively early days, so we don't have anything to share yet on that front.
126126

127+
### `Instant` monotonicity guarantees
128+
129+
On all platforms `Instant` will try to use an OS API that guarantees monotonic
130+
behavior if available (which is the case on all tier 1 platforms). In practice
131+
such guarantees are -- under rare circumstances -- broken by hardware,
132+
virtualization or operating system bugs. To work around these bugs and platforms
133+
not offering monotonic clocks `Instant::duration_since`, `Instant::elapsed` and
134+
`Instant::sub` saturate to zero. In older Rust versions this lead to a panic
135+
instead. `Instant::checked_duration_since` can be used to detect and handle
136+
situations where monotonicity is violated, or `Instant`s are subtracted in the
137+
wrong order.
138+
139+
This workaround obscures programming errors where earlier and later instants are
140+
accidentally swapped. For this reason future Rust versions may reintroduce
141+
panics in at least those cases.
142+
143+
Prior to 1.60, the monotonicity guarantees were provided through mutexes or
144+
atomics in std, which can introduce large performance overheads to
145+
`Instant::now()`. Additionally, the panicking behavior meant that Rust software
146+
could panic in a subset of environments, which was largely undesirable, as the
147+
authors of that software may not be in a place to upgrade the operating system,
148+
hardware, or virtualization system they are running on. Further, introducing
149+
unexpected panics into these environments make Rust software less reliable and
150+
portable, which is of higher concern than exposing typically uninteresting
151+
platform bugs to end users.
152+
127153
### Stabilized APIs
128154

129155
The following methods and trait implementations are now stabilized:

0 commit comments

Comments
 (0)