-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add Duration from nanos u128 #139243
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
base: master
Are you sure you want to change the base?
Add Duration from nanos u128 #139243
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thanks for taking this over! r? libs |
Happy to take this up. noted. |
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…r-errors handle specialization in the new trait solver fixes rust-lang/trait-system-refactor-initiative#187 also fixes the regression in `plonky2_field` from rust-lang/trait-system-refactor-initiative#188 cc rust-lang#111994 r? ```@compiler-errors```
stall generator witness obligations: add regression test fixes rust-lang/trait-system-refactor-initiative#180 r? ```@compiler-errors```
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#139865 (Stabilize proc_macro::Span::{start,end,line,column}.) - rust-lang#140086 (If creating a temporary directory fails with permission denied then retry with backoff) - rust-lang#140216 (Document that "extern blocks must be unsafe" in Rust 2024) - rust-lang#140253 (Add XtensaAsmPrinter) - rust-lang#140272 (Improve error message for `||` (or) in let chains) - rust-lang#140305 (Track per-obligation recursion depth only if there is inference in the new solver) - rust-lang#140306 (handle specialization in the new trait solver) - rust-lang#140308 (stall generator witness obligations: add regression test) r? `@ghost` `@rustbot` modify labels: rollup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation and docs look good to me, left a few small comments about adding backticks around code types. However, this needs some tests. Could you update library/coretests/tests/time.rs
to include from_nanos_u128
everywhere that from_nanos
is tested? Also make sure some large values are tested, and one or two #[should_panic]
tests for the overflow.
@@ -308,6 +307,39 @@ impl Duration { | |||
Duration { secs, nanos: subsec_nanos } | |||
} | |||
|
|||
/// Creates a new Duration from the specified number of nanoseconds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Creates a new Duration from the specified number of nanoseconds. | |
/// Creates a new `Duration` from the specified number of nanoseconds. |
/// | ||
/// # Panics | ||
/// | ||
/// Panics if the given number of nanoseconds is greater than what Duration can handle, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Panics if the given number of nanoseconds is greater than what Duration can handle, | |
/// Panics if the given number of nanoseconds is greater than what `Duration` can handle, |
/// | ||
/// Panics if the given number of nanoseconds is greater than what Duration can handle, | ||
/// which is `(u64::MAX * NANOS_PER_SEC) + NANOS_PER_SEC - 1` | ||
/// Use this function if you need to specify time greater than what can fit in u64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Use this function if you need to specify time greater than what can fit in u64 | |
/// Use this function if you need to specify time greater than what can fit in `u64` |
@@ -1,5 +1,4 @@ | |||
#![stable(feature = "duration_core", since = "1.25.0")] | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a spurious removal
Also fyi - pedantically, there is no need to preserve the messages unless they are still meaningful. It's best if the message describes the contained change, it's not really useful to rust's forever history that you had "dummy commit" and "remove parentheses" at some point :) |
noted. |
@omanirudh are you able to do the updates to get this over the line? Mostly just test updates and a few nits. |
Hey Trevor, thanks for bringing this to my attention.
I am caught up in my day job. I need time until Thursday morning (Eastern).
I would really love to do this and make my first OSS contribution.
Also I am tied up so if it doesn't happen by this time. I will move on and
close the pull request to keep it open for others.
All of this assuming there is time until then.
In case this isn't the case. Please feel free to assign this to
someone more immediately available.
…On Tue, Jun 10, 2025 at 2:34 AM Trevor Gross ***@***.***> wrote:
*tgross35* left a comment (rust-lang/rust#139243)
<#139243 (comment)>
@omanirudh <https://github.com/omanirudh> are you able to do the updates
to get this over the line? Mostly just test updates and a few nits.
—
Reply to this email directly, view it on GitHub
<#139243 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BPJEXXJ2Y4MX6VI72O5MUCD3CXZEDAVCNFSM6AAAAAB2I6KI7OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNJXGAZDSOJTGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
It's not a problem! This is open source, there are no deadlines 🙂 we just try to make sure changes that are pretty close to done don't fall off the map. |
Awesome! Here's one cheer to make this happen soon.
…On Tue, Jun 10, 2025 at 8:36 AM Trevor Gross ***@***.***> wrote:
*tgross35* left a comment (rust-lang/rust#139243)
<#139243 (comment)>
It's not a problem! This is open source, there are no deadlines 🙂 we just
try to make sure changes that are pretty close to done don't fall off the
map.
—
Reply to this email directly, view it on GitHub
<#139243 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BPJEXXOWEXYCEW77O4VZ7CT3CZDVFAVCNFSM6AAAAAB2I6KI7OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNJXGU2TAOBWG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in exhaustiveness checking cc @Nadrieril Some changes occurred in coverage instrumentation. cc @Zalathar Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in match checking cc @Nadrieril Some changes occurred to the CTFE machinery These commits modify the If this was unintentional then you should revert the changes before this PR is merged. Some changes occurred in match lowering cc @Nadrieril Some changes occurred in compiler/rustc_codegen_llvm/src/builder/autodiff.rs cc @ZuseZ4 Some changes occurred in compiler/rustc_passes/src/check_attr.rs Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred in compiler/rustc_codegen_gcc
cc @davidtwco, @compiler-errors, @TaKO8Ki Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs cc @ZuseZ4 Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt changes to the core type system Some changes occurred in compiler/rustc_sanitizers cc @rcvalle These commits modify compiler targets. HIR ty lowering was modified cc @fmease Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred in compiler/rustc_attr_data_structures Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter |
|
@omanirudh it looks like you wound up with bad commit history somehow. You should be able to fix this by rebasing your branch, check out https://rustc-dev-guide.rust-lang.org/git.html#rebasing |
What does this PR do?
This draft PR adds the
Duration::from_nanos_u128
function to handle durations that exceed the range ofu64
, allowing for time spans greater than ~584 years.Motivation
The current
Duration
API does not support creating durations from nanoseconds represented asu128
. This addition addresses that limitation.Tracking Issue
Fixes #139201
Details
Introduced
Duration::from_nanos_u128
as aconst fn
similar to other functions in the file.Ensured safety by validating the nanoseconds before using
unsafe
code.To do : complete the documentation and examples for the new function.
r? @RalfJung