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

std: Redesign Duration, implementing RFC 1040 #24920

Merged
merged 1 commit into from May 14, 2015

Conversation

alexcrichton
Copy link
Member

This commit is an implementation of RFC 1040 which is a redesign of the
currently-unstable Duration type. The API of the type has been scaled back to
be more conservative and it also no longer supports negative durations.

The inner duration module of the time module has now been hidden (as
Duration is reexported) and the feature name for this type has changed from
std_misc to duration. All APIs accepting durations have also been audited to
take a more flavorful feature name instead of std_misc.

Closes #24874

@rust-highfive
Copy link
Collaborator

r? @pcwalton

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

r? @aturon

cc @wycats

The only "surprise" I had during the implementation was the naming of the methods here and there. Abbreviating "seconds" as "secs" didn't feel super rustic to me, but typing millis/nanos felt much better than milliseconds/nanoseconds. Overall I didn't feel too strongly either way!

@rust-highfive rust-highfive assigned aturon and unassigned pcwalton Apr 29, 2015
@alexcrichton alexcrichton force-pushed the duration branch 4 times, most recently from c0d3aa8 to 260ce79 Compare April 29, 2015 00:53
let seconds = self.secs;
let millis = self.nanos / NANOS_PER_MILLI;
let nanos = self.nanos % NANOS_PER_MILLI;
match (seconds, millis, nanos) {
Copy link
Member

Choose a reason for hiding this comment

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

What's the motivation for this sort of 'complicated' formatting rather than something like, say, 1234.00000567s?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not particularly wed to this format, but it's what was specified in the RFC (as a starting point). I also had some reservations and wouldn't mind changing it to be only numeric as well.

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 also have mixed feelings about this actually looking at this code (I should have raised this with the RFC). I think that automatically figuring out whether to use seconds, millis, or nanos is a good idea, but I don't understand the motivation for XX seconds and XX nanoseconds.

@bors
Copy link
Contributor

bors commented Apr 29, 2015

☔ The latest upstream changes (presumably #24888) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Apr 30, 2015

☔ The latest upstream changes (presumably #24967) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -57,25 +57,20 @@ impl Condvar {
// https://github.com/llvm-mirror/libcxx/blob/release_35/src/condition_variable.cpp#L46
// https://github.com/llvm-mirror/libcxx/blob/release_35/include/__mutex_base#L367
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
if dur <= Duration::zero() {
Copy link
Member

Choose a reason for hiding this comment

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

This changes the behavior for a zero duration; intended?

@aturon
Copy link
Member

aturon commented May 4, 2015

@alexcrichton Ok, I've done a preliminary pass. Looks nice a simple. I raised a few concerns (most of which, to be honest, I should have raised on the RFC).

@alexcrichton
Copy link
Member Author

Ok I have updated some feedback and discussion with @aturon:

  • Platforms now round up the duration instead of rounding down if they do not support nanosecond precision.
  • The Display implementation has become a little less wordy
  • Duration::nanos was renamed to Duration::extra_nanos. An alternative would be one method accessor returning (u64, u32), but it's unclear what the name for this accessor would be.
  • Arithmetic on Duration is now always checked.

re-r? @aturon

@alexcrichton alexcrichton force-pushed the duration branch 2 times, most recently from 2fe4199 to f143b01 Compare May 7, 2015 21:57
return Thread::yield_now()
}
let seconds = dur.num_seconds();
let ns = dur - Duration::seconds(seconds);
let mut ts = libc::timespec {
Copy link
Member

Choose a reason for hiding this comment

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

There should exist From<Duration> for libc::timespec in liblibc instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately this can't be provided in liblibc because Duration doesn't exist by that point and due to the in-tree liblibc being different from the out-of-tree liblibc it unfortunately also wouldn't work to provide this in the standard library as well.

@alexcrichton
Copy link
Member Author

Thanks for taking a look @nagisa!

@aturon
Copy link
Member

aturon commented May 13, 2015

@bors: r+

@bors
Copy link
Contributor

bors commented May 13, 2015

📌 Commit 086fddc has been approved by aturon

@aturon
Copy link
Member

aturon commented May 13, 2015

Thanks @alexcrichton!

@bors
Copy link
Contributor

bors commented May 13, 2015

⌛ Testing commit 086fddc with merge 9eb94a8...

@bors
Copy link
Contributor

bors commented May 13, 2015

💔 Test failed - auto-mac-64-nopt-t

@Manishearth
Copy link
Member

failures:

---- sync::condvar::tests::wait_timeout_with stdout ----
    thread 'sync::condvar::tests::wait_timeout_with' panicked at 'overflow when subtracting durations', /Users/rustbuild/src/rust-buildbot/slave/auto-mac-64-nopt-t/build/src/libcore/option.rs:330



failures:
    sync::condvar::tests::wait_timeout_with

@alexcrichton alexcrichton force-pushed the duration branch 2 times, most recently from cd06e02 to 38cfc7a Compare May 13, 2015 23:11
@alexcrichton
Copy link
Member Author

@bors: r=aturon 38cfc7a

@bors
Copy link
Contributor

bors commented May 13, 2015

⌛ Testing commit 38cfc7a with merge 9b165c0...

@bors
Copy link
Contributor

bors commented May 14, 2015

💔 Test failed - auto-win-64-opt

This commit is an implementation of [RFC 1040][rfc] which is a redesign of the
currently-unstable `Duration` type. The API of the type has been scaled back to
be more conservative and it also no longer supports negative durations.

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1040-duration-reform.md

The inner `duration` module of the `time` module has now been hidden (as
`Duration` is reexported) and the feature name for this type has changed from
`std_misc` to `duration`. All APIs accepting durations have also been audited to
take a more flavorful feature name instead of `std_misc`.

Closes rust-lang#24874
@alexcrichton
Copy link
Member Author

@bors: r=aturon 556e76b

@bors
Copy link
Contributor

bors commented May 14, 2015

⌛ Testing commit 556e76b with merge 0755c09...

@bors
Copy link
Contributor

bors commented May 14, 2015

💔 Test failed - auto-linux-32-nopt-t

@alexcrichton
Copy link
Member Author

@bors: retry

On Wed, May 13, 2015 at 8:36 PM, bors notifications@github.com wrote:

[image: 💔] Test failed - auto-linux-32-nopt-t
http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/4942


Reply to this email directly or view it on GitHub
#24920 (comment).

@bors
Copy link
Contributor

bors commented May 14, 2015

⌛ Testing commit 556e76b with merge dd4dad8...

bors added a commit that referenced this pull request May 14, 2015
This commit is an implementation of [RFC 1040][rfc] which is a redesign of the
currently-unstable `Duration` type. The API of the type has been scaled back to
be more conservative and it also no longer supports negative durations.

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1040-duration-reform.md

The inner `duration` module of the `time` module has now been hidden (as
`Duration` is reexported) and the feature name for this type has changed from
`std_misc` to `duration`. All APIs accepting durations have also been audited to
take a more flavorful feature name instead of `std_misc`.

Closes #24874
@bors bors merged commit 556e76b into rust-lang:master May 14, 2015
zmbush added a commit to zmbush/megaprompt that referenced this pull request May 18, 2015
@alexcrichton alexcrichton deleted the duration branch August 17, 2015 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking issue for Duration Reform (RFC 1040)
8 participants