Skip to content

windows/time: avoid being too close to 0#156177

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
RalfJung:windows-time-epoch
May 7, 2026
Merged

windows/time: avoid being too close to 0#156177
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
RalfJung:windows-time-epoch

Conversation

@RalfJung
Copy link
Copy Markdown
Member

@RalfJung RalfJung commented May 5, 2026

Fixes #156142 (but only for Windows -- should we still track it for non-tier-1-platforms?)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 5, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 5, 2026

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, jhpratt, nia-e

@RalfJung RalfJung force-pushed the windows-time-epoch branch from 99d0aef to a07a3b1 Compare May 5, 2026 06:44
// We can add an arbitrary offset to shift the epoch of this clock. We do that to avoid
// being too close to 0 which would lead to underflow when computing times in the past. Also
// see <https://github.com/rust-lang/rust/issues/156142>.
let instant_nsec = instant_nsec + (u64::MAX / 4);
Copy link
Copy Markdown
Contributor

@tbu- tbu- May 6, 2026

Choose a reason for hiding this comment

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

Would be nicer to use a signed type for storing the nanoseconds, otherwise we have this useless addition on every Instant::now.

Using a signed type would make this essentially free.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We use Duration so using anything singed would be a major refactor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We would need to make something more or less equivalent to a SignedDuration type if we want to share it between different implementations of Instant. It's a shame we can't just wrap the value of perf_counter::now() but Instant is required to have nanosecond permissions so that's right out.

@ChrisDenton
Copy link
Copy Markdown
Member

I'll admit I don't exactly love this but it addresses the issue for now so...

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 7, 2026

📌 Commit a07a3b1 has been approved by ChrisDenton

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 7, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request May 7, 2026
…isDenton

windows/time: avoid being too close to 0

Fixes rust-lang#156142 (but only for Windows -- should we still track it for non-tier-1-platforms?)
rust-bors Bot pushed a commit that referenced this pull request May 7, 2026
Rollup of 14 pull requests

Successful merges:

 - #146273 (lint ImproperCTypes: refactor linting architecture (part 2))
 - #149509 (Lint unused pub items in binary crates)
 - #156173 (Fewer global node_id_to_def_id lookups)
 - #156177 (windows/time: avoid being too close to 0)
 - #155961 (Deny warnings in the test for crates that are available on stable)
 - #155981 (Use special DefIds for aliases)
 - #156109 (Migrate libraries from ptr::slice_from_raw_parts to .cast_slice)
 - #156130 (Fold/visit tweaks)
 - #156131 (Metadata macro/query cleanups)
 - #156202 (llvm: Use correct type for splat mask)
 - #156227 (Add Trusty OS to the generic error implementation.)
 - #156237 (compiletest: prevent directives from having multiple revisions)
 - #156241 (Move tests coercion)
 - #156258 (Document wasi-sdk minimum versions for WASI targets)
rust-bors Bot pushed a commit that referenced this pull request May 7, 2026
Rollup of 12 pull requests

Successful merges:

 - #156173 (Fewer global node_id_to_def_id lookups)
 - #156177 (windows/time: avoid being too close to 0)
 - #155961 (Deny warnings in the test for crates that are available on stable)
 - #155981 (Use special DefIds for aliases)
 - #156130 (Fold/visit tweaks)
 - #156131 (Metadata macro/query cleanups)
 - #156202 (llvm: Use correct type for splat mask)
 - #156223 (Refactor `Type::size` field to `TypeId::size` method for `type_info`)
 - #156227 (Add Trusty OS to the generic error implementation.)
 - #156237 (compiletest: prevent directives from having multiple revisions)
 - #156241 (Move tests coercion)
 - #156258 (Document wasi-sdk minimum versions for WASI targets)
rust-bors Bot pushed a commit that referenced this pull request May 7, 2026
Rollup of 12 pull requests

Successful merges:

 - #156173 (Fewer global node_id_to_def_id lookups)
 - #156177 (windows/time: avoid being too close to 0)
 - #155961 (Deny warnings in the test for crates that are available on stable)
 - #155981 (Use special DefIds for aliases)
 - #156130 (Fold/visit tweaks)
 - #156131 (Metadata macro/query cleanups)
 - #156202 (llvm: Use correct type for splat mask)
 - #156223 (Refactor `Type::size` field to `TypeId::size` method for `type_info`)
 - #156227 (Add Trusty OS to the generic error implementation.)
 - #156237 (compiletest: prevent directives from having multiple revisions)
 - #156241 (Move tests coercion)
 - #156258 (Document wasi-sdk minimum versions for WASI targets)
@rust-bors rust-bors Bot merged commit 746ea54 into rust-lang:main May 7, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone May 7, 2026
rust-timer added a commit that referenced this pull request May 7, 2026
Rollup merge of #156177 - RalfJung:windows-time-epoch, r=ChrisDenton

windows/time: avoid being too close to 0

Fixes #156142 (but only for Windows -- should we still track it for non-tier-1-platforms?)
@RalfJung RalfJung deleted the windows-time-epoch branch May 9, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] computing an Instant from before program startup might panic

5 participants