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

rustbuild: Allow quick testing of libstd and libcore at stage0 #50466

Merged
merged 9 commits into from
May 6, 2018

Conversation

kennytm
Copy link
Member

@kennytm kennytm commented May 5, 2018

This PR implemented two features:

  1. Added a --no-doc flag to allow testing a crate without doc tests. In this mode, we don't need to build rustdoc, and thus we can skip building the stage2 compiler. (Ideally stage0 test should use the bootstrap rustdoc, but I don't want to mess up the core builder logic here)

  2. Moved all libcore tests externally and added a tidy test to ensure we don't accidentally add #[test] into libcore.

After this PR, one could run ./x.py test --stage 0 --no-doc src/libstd to test libstd without building the compiler, thus enables us to quickly test new library features.

kennytm and others added 7 commits May 6, 2018 01:27
This enables `./x.py test --stage 0 src/libstd --no-doc` and ensures the
stage2-rustc and rustdoc need to be built.
All other tests of libcore reside in the tests/ directory,
too. Apparently the tests of `time.rs` weren't run before, at
least not by `x.py test src/libcore`.
@rust-highfive
Copy link
Collaborator

r? @TimNN

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 5, 2018
@kennytm
Copy link
Member Author

kennytm commented May 5, 2018

cc @Zoxc #49119. I'm not sure what is your plan in that PR, but I'd like to ensure ./x.py test --stage 0 src/libstd remains available when the --stage flag is explicitly passed.

cc @LukasKalbertodt #50364. I've copy your two commits fixing libcore tests here.

@LukasKalbertodt
Copy link
Member

@kennytm Awesome! Related issue I opened a few days ago: #50367

@TimNN
Copy link
Contributor

TimNN commented May 5, 2018

This looks good to me, but I'm not familiar enough with rustbuild to properly review this, so

r? @Mark-Simulacrum

@retep998
Copy link
Member

retep998 commented May 5, 2018

Could the magic ./x.py test --stage 0 --no-doc src/libstd incantation be documented somewhere for easier reference?

@@ -50,6 +50,7 @@

// Since libcore defines many fundamental lang items, all tests live in a
// separate crate, libcoretest, to avoid bizarre issues.
#![cfg(not(test))]
Copy link
Member

Choose a reason for hiding this comment

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

This feels odd; presumably independent of whether we are running tests we would expect core to exist and define everything -- or am I misreading what this does?

Copy link
Member Author

@kennytm kennytm May 5, 2018

Choose a reason for hiding this comment

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

@Mark-Simulacrum

The problem is when we are testing the library, we will build an executable and link to libtest. Now, this executable defines some lang items, and at the same time libtest imports the non-testing libcore which also defines some lang items. This will cause the E0152 "duplicate lang item found" error. I'm not sure why this is not discovered before, maybe no one tried to ./x.py test src/libcore? 🙃

Reduced test case:

#![cfg(not(test))] // <-- comment out to cause E0152 when `cargo test`.

#![feature(no_core, lang_items)]
#![no_core]

/// ```
///                               
/// ```
#[lang = "sized"]
pub trait Sized {}

In cargo test, the doc tests are still discovered and executed even with this cfg. I assume this is the same for rustbuild, though if it turns out to be wrong we could change the cfg to any(dox, not(test)). Edit: Yes they are executed.

I've updated this comment to explain the attribute.

@@ -210,6 +210,16 @@ pub struct Compiler {
host: Interned<String>,
}

#[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum DocTestsOption {
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 rename this to DocTests? I think it might have uses outside just being passed on the command line...

@Mark-Simulacrum
Copy link
Member

Could the magic ./x.py test --stage 0 --no-doc src/libstd incantation be documented somewhere for easier reference?

This should probably go in the rustc-guide testing page.

@kennytm
Copy link
Member Author

kennytm commented May 5, 2018

@retep998 I've added it to src/bootstrap/README.md too.

@Mark-Simulacrum
Copy link
Member

I think I'm almost ready to sign off on this, but the problem I see with the cfg(not(test)) is that as far as I can tell, that should mean that the libcore we're testing isn't the one we just built -- that is, if I changed the core::cmp::max impl to always return A instead of running comparisons, I would still pass tests via ./x.py test --stage 0 --no-doc src/libcore. This is clearly not acceptable; could you verify if I'm correct about this assumption?

If I am, we might be able to work around this by making specifically the lang items defined by core #[cfg(not(test))], but I'm not sure how good of an idea that is.

@kennytm
Copy link
Member Author

kennytm commented May 5, 2018

@Mark-Simulacrum libcore will be tested through the library in src/libcore/tests/, which will link to the not(test) version of libcore.

I'm not going to modify core::cmp::max since this caused some strange memory errors, probably because the allocator used max 😅. I changed to_ascii_uppercase instead:

  1. Applying the diff
    diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs
    index 374adafef6..e7c7ed0ad6 100644
    --- a/src/libcore/char/methods.rs
    +++ b/src/libcore/char/methods.rs
    @@ -910,11 +910,7 @@ impl char {
        #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
        #[inline]
        pub fn to_ascii_uppercase(&self) -> char {
    -        if self.is_ascii() {
    -            (*self as u8).to_ascii_uppercase() as char
    -        } else {
    -            *self
    -        }
    +        '*'
        }
    
        /// Makes a copy of the value in its ASCII lower case equivalent.
  2. Execute ./x.py test --stage 0 -j3 --no-doc src/libcore/
        Finished dev [unoptimized] target(s) in 0.0 secs
    Building stage0 std artifacts (x86_64-apple-darwin -> x86_64-apple-darwin)
    Compiling core v0.0.0 (file:///$DIR/rust/src/libcore)
    
    ...
    
    Testing core stage0 (x86_64-apple-darwin -> x86_64-apple-darwin)
    Compiling libc v0.2.40
    Compiling rand v0.4.2
    Compiling core v0.0.0 (file:///$DIR/rust/src/libcore)
        Finished release [optimized] target(s) in 59.69 secs
        Running build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/deps/core-82cbac52c153f0e4
    
    running 786 tests
    test any::any_downcast_mut ... ok
    test any::any_downcast_ref ... ok
    test any::any_fixed_vec ... ok
    test any::any_owning ... ok
    test any::any_referenced ... ok
    test any::any_unsized ... ok
    test array::array_try_from ... ok
    test array::fixed_size_array ... ok
    test ascii::inference_works ... ok
    test ascii::test_is_ascii ... ok
    test ascii::test_is_ascii_alphabetic ... ok
    test ascii::test_is_ascii_alphanumeric ... ok
    test ascii::test_is_ascii_control ... ok
    test ascii::test_is_ascii_digit ... ok
    test ascii::test_eq_ignore_ascii_case ... ok
    test ascii::test_is_ascii_graphic ... ok
    test ascii::test_is_ascii_hexdigit ... ok
    test ascii::test_is_ascii_lowercase ... ok
    test ascii::test_is_ascii_punctuation ... ok
    test ascii::test_is_ascii_uppercase ... ok
    test ascii::test_is_ascii_whitespace ... ok
    test ascii::test_make_ascii_lower_case ... ok
    test ascii::test_make_ascii_upper_case ... FAILED
    test atomic::bool_ ... ok
    test atomic::bool_and ... ok
    test atomic::bool_nand ... ok
    
    ...
    
    failures:
    
    ---- ascii::test_make_ascii_upper_case stdout ----
        thread 'ascii::test_make_ascii_upper_case' panicked at 'assertion failed: `(left == right)`
    left: `'*'`,
    right: `'A'`', libcore/../libcore/tests/ascii.rs:93:5
    note: Run with `RUST_BACKTRACE=1` for a backtrace.
    
    
    failures:
        ascii::test_make_ascii_upper_case
    
    test result: FAILED. 783 passed; 1 failed; 2 ignored; 0 measured; 0 filtered out
    
    error: test failed, to rerun pass '--test coretests'
    

We see indeed it is testing the modified libcore.

@Mark-Simulacrum
Copy link
Member

That is surprising to me -- I thought that we linked against a library compiled with --cfg test. Though maybe that's the distinction between integration and non-integration tests.

However, since it does seem to work, @bors r+ -- can you make a PR or file an issue against rustc-guide too?

@rust-lang/libs -- this functionality is likely of interest and use to all of you

@bors
Copy link
Contributor

bors commented May 5, 2018

📌 Commit 05af55b has been approved by Mark-Simulacrum

@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 May 5, 2018
@bors
Copy link
Contributor

bors commented May 6, 2018

⌛ Testing commit 05af55b with merge 449c634747ab60600155dd81d728bc7f891a056c...

@bors
Copy link
Contributor

bors commented May 6, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 6, 2018
@kennytm
Copy link
Member Author

kennytm commented May 6, 2018

@bors retry

[00:52:03] error: Could not compile `cargo`.
[00:52:03] 
[00:52:03] Caused by:
[00:52:03]   process didn't exit successfully: `C:\projects\rust\build\bootstrap/debug/rustc --crate-name cargo tools\cargo\src/cargo/lib.rs --color always --error-format json --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=ff1a392da7815f09 -C extra-filename=-ff1a392da7815f09 --out-dir C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps --target x86_64-pc-windows-msvc -L dependency=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps -L dependency=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\release\deps --extern hex=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libhex-ffd7439a0363380c.rlib --extern filetime=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libfiletime-d953033b9cfdaeae.rlib --extern winapi=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libwinapi-aa52ebbc6d0991e9.rlib --extern crypto_hash=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libcrypto_hash-40c4fab9b4b7b20e.rlib --extern crates_io=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libcrates_io-72af42b8b8f13411.rlib --extern tempfile=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libtempfile-801831cfacfabbb2.rlib --extern fs2=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libfs2-3f6f2266a44720fa.rlib --extern flate2=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libflate2-3f42a75546aa5659.rlib --extern tar=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libtar-cc0ebcb78806862b.rlib --extern semver=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libsemver-325d1ba6e49fa23c.rlib --extern num_cpus=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libnum_cpus-e4a61b6250464e48.rlib --extern same_file=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libsame_file-f15454bd6ead1a71.rlib --extern num_traits=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libnum_traits-e0666b454259339c.rlib --extern serde_json=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libserde_json-3b3c7f48ef3db7df.rlib --extern env_logger=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libenv_logger-c4deb643733e5243.rlib --extern serde=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libserde-fdab64f98513f90c.rlib --extern lazycell=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\liblazycell-6667b5c9ebb61d16.rlib --extern atty=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libatty-cfa36609e00bad4c.rlib --extern clap=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libclap-7e3ff844454e44c9.rlib --extern serde_derive=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\release\deps\serde_derive-1e2188502da7e9f0.dll --extern toml=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libtoml-3311258f5e47c7f5.rlib --extern libc=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\liblibc-fa06c43e1f4e468b.rlib --extern jobserver=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libjobserver-78bdc1abae3e305c.rlib --extern miow=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libmiow-5459f5ecf303c848.rlib --extern shell_escape=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libshell_escape-f5d36bc27bf9a0e8.rlib --extern serde_ignored=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libserde_ignored-8e6b847922191edc.rlib --extern log=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\liblog-a758357654ea1651.rlib --extern termcolor=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libtermcolor-7e3c8c7952e24a08.rlib --extern lazy_static=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\liblazy_static-56230eaac815c346.rlib --extern home=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libhome-a607286d49354d62.rlib --extern failure=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libfailure-2032b606c44fcafa.rlib --extern git2=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libgit2-b10a6f23785e6e7a.rlib --extern ignore=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libignore-33d61b12b4d0aee9.rlib --extern crossbeam=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libcrossbeam-eda550f43b0659c9.rlib --extern glob=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libglob-f8f71eb20b001a94.rlib --extern libgit2_sys=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\liblibgit2_sys-1588b282ed3dfa25.rlib --extern git2_curl=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libgit2_curl-e6160a318d1ab485.rlib --extern url=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\liburl-d6e8656eb2fa755b.rlib --extern curl=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\deps\libcurl-1aa5ea2fc6912771.rlib -L native=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\build\curl-sys-60ad97fcb878aaf4\out/lib -L C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\build\libz-sys-14a7dd055bccaa47\out/lib -L native=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\lib\amd64 -L native=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\build\miniz-sys-ef1ee1498f4e8cc5\out -L native=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\build\libgit2-sys-17766325c3e0cf2c\out/lib -L native=C:\projects\rust\build\x86_64-pc-windows-msvc\stage2-tools\x86_64-pc-windows-msvc\release\build\libssh2-sys-d12f24c53165ddd2\out/lib` (exit code: 3221225477)
[00:52:03] warning: build failed, waiting for other jobs to finish...

@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 May 6, 2018
@bors
Copy link
Contributor

bors commented May 6, 2018

⌛ Testing commit 05af55b with merge 6f721f5...

bors added a commit that referenced this pull request May 6, 2018
…lacrum

rustbuild: Allow quick testing of libstd and libcore at stage0

This PR implemented two features:

1. Added a `--no-doc` flag to allow testing a crate *without* doc tests. In this mode, we don't need to build rustdoc, and thus we can skip building the stage2 compiler. (Ideally stage0 test should use the bootstrap rustdoc, but I don't want to mess up the core builder logic here)

2. Moved all libcore tests externally and added a tidy test to ensure we don't accidentally add `#[test]` into libcore.

After this PR, one could run `./x.py test --stage 0 --no-doc src/libstd` to test `libstd` without building the compiler, thus enables us to quickly test new library features.
@SimonSapin
Copy link
Contributor

Is this incompatible with #49119 ?

@Zoxc
Copy link
Contributor

Zoxc commented May 6, 2018

@SimonSapin It is not.

@SimonSapin
Copy link
Contributor

@Zoxc maybe not at first, but my understanding of #49119 is that std won’t be built with in stage0 anymore at least on CI, so we aren’t required to keep doing as much #[cfg(stage0)] gymnastics, so that configuration might stop compiling soon after. Or am I missing something?

@Zoxc
Copy link
Contributor

Zoxc commented May 6, 2018

@SimonSapin It still runs cargo check for libstd in stage0. If we want to remove cfg(stage0), we'll have to delay checking/testing to stage1.

@bors
Copy link
Contributor

bors commented May 6, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: Mark-Simulacrum
Pushing 6f721f5 to master...

@bors bors merged commit 05af55b into rust-lang:master May 6, 2018
@kennytm kennytm deleted the rustbuild-stage0-lib-test branch May 6, 2018 11:15
@kennytm kennytm mentioned this pull request May 6, 2018
@LukasKalbertodt
Copy link
Member

LukasKalbertodt commented May 6, 2018

I'm not sure if I should open a new issue for this: I tried the new command, and it didn't work for me in some situations.

When I execute ./x.py test --stage 0 --no-doc src/libcore the first time, everything works fine. If I then change tests in libcore/tests, only the tests are rebuild and everything works (awesome!). But if I change libcore directly, it tries to rebuild a few things and then has a problem with the crate rand:

$ ./x.py test --stage 0 --no-doc src/libcore --test-args time
Updating only changed submodules
Submodules updated in 0.02 seconds
    Finished dev [unoptimized] target(s) in 0.0 secs
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling core v0.0.0 (file:///home/lukas/dev/rust/src/libcore)
   Compiling compiler_builtins v0.0.0 (file:///home/lukas/dev/rust/src/rustc/compiler_builtins_shim)
   Compiling libc v0.0.0 (file:///home/lukas/dev/rust/src/rustc/libc_shim)
   Compiling alloc v0.0.0 (file:///home/lukas/dev/rust/src/liballoc)
   Compiling std_unicode v0.0.0 (file:///home/lukas/dev/rust/src/libstd_unicode)
   Compiling unwind v0.0.0 (file:///home/lukas/dev/rust/src/libunwind)
   Compiling alloc_system v0.0.0 (file:///home/lukas/dev/rust/src/liballoc_system)
   Compiling panic_abort v0.0.0 (file:///home/lukas/dev/rust/src/libpanic_abort)
   Compiling alloc_jemalloc v0.0.0 (file:///home/lukas/dev/rust/src/liballoc_jemalloc)
   Compiling rustc_lsan v0.0.0 (file:///home/lukas/dev/rust/src/librustc_lsan)
   Compiling panic_unwind v0.0.0 (file:///home/lukas/dev/rust/src/libpanic_unwind)
   Compiling rustc_asan v0.0.0 (file:///home/lukas/dev/rust/src/librustc_asan)
   Compiling rustc_msan v0.0.0 (file:///home/lukas/dev/rust/src/librustc_msan)
   Compiling rustc_tsan v0.0.0 (file:///home/lukas/dev/rust/src/librustc_tsan)
   Compiling std v0.0.0 (file:///home/lukas/dev/rust/src/libstd)
    Finished release [optimized] target(s) in 30.15 secs
Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 test artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling term v0.0.0 (file:///home/lukas/dev/rust/src/libterm)
   Compiling getopts v0.2.17
   Compiling test v0.0.0 (file:///home/lukas/dev/rust/src/libtest)
    Finished release [optimized] target(s) in 6.58 secs
Copying stage0 test from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Testing core stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling core v0.0.0 (file:///home/lukas/dev/rust/src/libcore)
error[E0460]: found possibly newer version of crate `std` which `rand` depends on
  --> libcore/../libcore/tests/lib.rs:53:1
   |
53 | extern crate rand;
   | ^^^^^^^^^^^^^^^^^^
   |
   = note: perhaps that crate needs to be recompiled?
   = note: the following crate versions were found:
           crate `std`: /home/lukas/dev/rust/build/x86_64-unknown-linux-gnu/stage0-std/x86_64-unknown-linux-gnu/release/deps/libstd-5f3a747b9ee6cbda.rlib
           crate `std`: /home/lukas/dev/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-5f3a747b9ee6cbda.rlib
           crate `std`: /home/lukas/dev/rust/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-5f3a747b9ee6cbda.so
           crate `std`: /home/lukas/dev/rust/build/x86_64-unknown-linux-gnu/stage0-std/x86_64-unknown-linux-gnu/release/deps/libstd-5f3a747b9ee6cbda.so
           crate `rand`: /home/lukas/dev/rust/build/x86_64-unknown-linux-gnu/stage0-std/x86_64-unknown-linux-gnu/release/deps/librand-89787ed220814c67.rlib

error: aborting due to previous error

For more information about this error, try `rustc --explain E0460`.
error: Could not compile `core`.
warning: build failed, waiting for other jobs to finish...
error: build failed


command did not execute successfully: "/home/lukas/dev/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "8" "--release" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/home/lukas/dev/rust/src/libstd/Cargo.toml" "--lib" "--bins" "--examples" "--tests" "--benches" "-p" "core" "--" "time"
expected success, got: exit code: 101


failed to run: /home/lukas/dev/rust/build/bootstrap/debug/bootstrap test --stage 0 --no-doc src/libcore --test-args time
Build completed unsuccessfully in 0:00:44

Note that I can simply run x.py clean && x.py test --stage 0 --no-doc src/libcore and everything works again (and it doesn't even takes that much longer). But I guess this rand problem shouldn't occur anyway? The problem always occurs when performing the steps as described above.

EDIT: But thanks for this! It saves me so much time already <3

@kennytm
Copy link
Member Author

kennytm commented May 6, 2018

@LukasKalbertodt Yes please file a new issue. As a workaround, you could just delete that librand-*.rlib and liblibc-*.rlib everytime.

@nikic
Copy link
Contributor

nikic commented May 6, 2018

I've just tried using this with src/liballoc and get:

   Compiling alloc v0.0.0 (file:///home/nikic/rust/src/liballoc)
error[E0152]: duplicate lang item found: `box_free`.
   --> liballoc/alloc.rs:158:1
    |
158 | / unsafe fn old_box_free<T: ?Sized>(ptr: *mut T) {
159 | |     box_free(Unique::new_unchecked(ptr))
160 | | }
    | |_^
    |
    = note: first defined in crate `alloc`.

error: aborting due to previous error

Is this expected to work only with core and std, but not alloc?

@kennytm
Copy link
Member Author

kennytm commented May 6, 2018

@nikic Sorry I hadn't tested liballoc 🙃 You could fix it by cfg'ing out the lang item

diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs
index f59c9f7fd6..7e31ee664c 100644
--- a/src/liballoc/alloc.rs
+++ b/src/liballoc/alloc.rs
@@ -152,7 +152,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
     }
 }
 
-#[cfg(stage0)]
+#[cfg(all(stage0, not(test)))]
 #[lang = "box_free"]
 #[inline]
 unsafe fn old_box_free<T: ?Sized>(ptr: *mut T) {

Since we will be releasing a new Rust version next week, this stage0 item will soon be removed, so I won't create a dedicated PR to fix it (maybe together with #50481 if the solution is found).

bors added a commit that referenced this pull request May 26, 2018
…=KodrAus

Improve `Debug` impl of `time::Duration`

Hi there!

For a long time now, I was getting annoyed by the derived `Debug` impl of `Duration`. Usually, I use `Duration` to either do quick'n'dirty benchmarking or measuring the time of some operation in general. The output of the derived Debug impl is hard to parse for humans: is { secs: 0, nanos: 968360102 } or { secs: 0, nanos 98507324 } longer?

So after running into the annoyance several times (sometimes building my own function to print the Duration properly), I decided to tackle this. Now the output looks like this:

```
Duration::new(1, 0)                 => 1s
Duration::new(1, 1)                 => 1.000000001s
Duration::new(1, 300)               => 1.0000003s
Duration::new(1, 4000)              => 1.000004s
Duration::new(1, 600000)            => 1.0006s
Duration::new(1, 7000000)           => 1.007s
Duration::new(0, 0)                 => 0ns
Duration::new(0, 1)                 => 1ns
Duration::new(0, 300)               => 300ns
Duration::new(0, 4001)              => 4.001µs
Duration::new(0, 600300)            => 600.3µs
Duration::new(0, 7000000)           => 7ms
```

Note that I implemented the formatting manually and didn't use floats. No information is "lost" when printing. So `Duration::new(123_456_789_000, 900_000_001)` prints as `123456789000.900000001s`.

~~This is not yet finished~~, but I wanted to open the PR now already in order to get some feedback (maybe everyone likes the derived impl).

### Still ToDo:

- [x] Respect precision ~~and width~~ parameter of the formatter (see [this comment](#50364 (comment)))

### Alternatives/Decisions

- Should large durations displayed in minutes, hours, days, ...? For now, I decided not to because the current formatting is close the how a `Duration` is stored. From this new `Debug` output, you can still easily see what the values of `secs` and `nanos` are. A formatting like `3h 27m 12s 9ms` might be more appropriate for a `Display` impl?
- Should this rather be a `Display` impl and should `Debug` be derived? Maybe this formatting is too fancy for `Debug`? In my opinion it's not and, as already mentioned, from the current format one can still very easily determine the values for `secs` and `nanos`.
- Whitespace between the number and the unit?

### Notes for reviewers

- ~~The combined diff sucks. Rather review both commits individually.~~
- ~~In the unit test, I am building my own type implementing `fmt::Write` to test the output. Maybe there is already something like that which I can use?~~
- My `Debug` impl block is marked as `#[stable(...)]`... but that's fine since the derived Debug impl was stable already, right?

---

~~Apart from the main change, I moved all `time` unit tests into the `tests` directory. All other `libcore` tests are there, so I guess it was simply an oversight. Prior to this change, the `time` tests weren't run, so I guess this is kind of a bug fix. If my `Debug` impl is rejected, I can of course just send the fix as PR.~~ (this was already merged in #50466)
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants