Skip to content
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

replace manual time convertions with std ones, comptime time format parsing #132521

Merged
merged 2 commits into from
Nov 4, 2024

Conversation

klensy
Copy link
Contributor

@klensy klensy commented Nov 2, 2024

First commit replaces few manual time conversions with std ones, second makes parsing of time format at compiletime.

@rustbot
Copy link
Collaborator

rustbot commented Nov 2, 2024

r? @nnethercote

rustbot has assigned @nnethercote.
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

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 2, 2024
let micros = duration.as_secs() * 1_000_000 + (duration.subsec_nanos() as u64) / 1000;
let micros: u64 = duration.as_micros().try_into().unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made conversions explicitly fallible here and other places.

Copy link
Member

Choose a reason for hiding this comment

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

Why are we using u64 here? to_base_fixed_len seems to support u128 too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

    println!("{}", 1234567_u64.to_base_fixed_len(CASE_INSENSITIVE));
    println!("{}", 1234567_u128.to_base_fixed_len(CASE_INSENSITIVE));

will give

000000000qglj
000000000000000000000qglj

so this will change timestamp part of filename making it longer, idk if that needed?

Copy link
Member

Choose a reason for hiding this comment

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

hm... i guess if we never expect it to overflow u64 in practice then it's fine. 2^64 microseconds seems to be 584 thousand years...

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Maybe we can clean this up further by using u128?

let micros = duration.as_secs() * 1_000_000 + (duration.subsec_nanos() as u64) / 1000;
let micros: u64 = duration.as_micros().try_into().unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Why are we using u64 here? to_base_fixed_len seems to support u128 too.

}

let micros_since_unix_epoch = micros_since_unix_epoch.unwrap();
let micros_since_unix_epoch = match u64::from_str_radix(s, INT_ENCODE_BASE as u32) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use u128 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is deserialize part of timestamp_to_string <--> string_to_timestamp, so depends on previous one encoding.

compiler/rustc_query_system/src/dep_graph/graph.rs Outdated Show resolved Hide resolved
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 3, 2024

📌 Commit bc1d8e7 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors 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 Nov 3, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Nov 3, 2024
replace manual time convertions with std ones, comptime time format parsing

First commit replaces few manual time conversions with std ones, second makes parsing of time format at compiletime.
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 4, 2024
…kingjubilee

Rollup of 6 pull requests

Successful merges:

 - rust-lang#126136 (Call the target libdir target libdir)
 - rust-lang#132516 (Add bad-reg inline assembly ui test for RISC-V and s390x)
 - rust-lang#132521 (replace manual time convertions with std ones, comptime time format parsing)
 - rust-lang#132560 (Remove outdated tidy license fixmes)
 - rust-lang#132563 (Modify `NonZero` documentation to reference the underlying integer type)
 - rust-lang#132574 (compiler: Directly use rustc_abi almost everywhere)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3285d12 into rust-lang:master Nov 4, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 4, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 4, 2024
Rollup merge of rust-lang#132521 - klensy:times, r=compiler-errors

replace manual time convertions with std ones, comptime time format parsing

First commit replaces few manual time conversions with std ones, second makes parsing of time format at compiletime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants