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

Moves test::black_box to core::hint and fix black_box on wasm32 and asm.js #59336

Merged
merged 8 commits into from
Mar 28, 2019

Conversation

gnzlbg
Copy link
Contributor

@gnzlbg gnzlbg commented Mar 21, 2019

This changes removes a cyclic dependency between the "test" and "libtest"
crates, where "libtest" depends on "test" for "black_box", but "test" depends on
"libtest" for everything else.

I've chosen the "hint" module because there seems to be enough consensus in the
discussion of RFC2360 that this module is where such an intrinsic would belong,
but this PR does not implement that RFC! If that RFC ever gets merged, the API, docs,
etc. of this API will need to change. This PR just move the implementation of the
already existing API.

For backwards compatibility reasons I've chosen to also keep the "test" feature
gate for these instead of adding a new feature gate. If we change the feature
gate, we'll potentially all benchmarks, and while that's something that we could
do, it seems unnecessary to do that now - if RFC2360 gets merged, we'll need to
do that anyways. Backwards compatibility is also why we continue to re-export
"black_box" from the "test" crate.

This PR also fixes black_box on the wasm32 target, which now supports inline assembly, and uses volatile loads on the asm.js target.

r? @Amanieu (cc @rust-lang/libs)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 21, 2019
@SimonSapin
Copy link
Contributor

This removes #[inline(never)] which seems significant. Is that deliberate?

Can you say more about what are what you call the "test" and "libtest" crate? In my mind these names refer to the same things. (Like we sometimes say std or libstd.)

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Mar 21, 2019

@SimonSapin note that only the implementation for some targets was #[inline(never)] before (the dummy implementation - the one using asm! does not need it). That's preserved here AFAICT.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Mar 21, 2019

The test crate is rust-lang/rust/src/libtest, the libtest crate is rust-lang/libtest.

@SimonSapin
Copy link
Contributor

Is there discussion you could link to (an rfc?) about why libtest exists and how it interacts with the other crate?

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Mar 21, 2019

The only RFC is custom test frameworks. There is an internals thread about the two crates: https://internals.rust-lang.org/t/a-path-forward-towards-re-usable-libtest-functionality-custom-test-frameworks-and-a-stable-bench-macro/9139

src/libcore/hint.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Mar 23, 2019

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

This changes removes a cyclic dependency between the "test" and "libtest"
crates, where "libtest" depends on "test" for "black_box", but "test" depends on
"libtest" for everything else.

I've chosen the "hint" module because there seems to be enough consensus in the
discussion of RFC2360 that this module is where such an intrinsic would belong,
but this PR does not implement that RFC! (note: if that RFC ever gets merged,
the API, docs, etc. of this API will need to change).

For backwards compatibility reasons I've chosen to also keep the "test" feature
gate for these instead of adding a new feature gate. If we change the feature
gate, we'll potentially all benchmarks, and while that's something that we could
do, it seems unnecessary to do that now - if RFC2360 gets merged, we'll need to
do that anyways.
@gnzlbg
Copy link
Contributor Author

gnzlbg commented Mar 25, 2019

Updated and rebased.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Mar 25, 2019

📌 Commit cfa76c4 has been approved by alexcrichton

@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 Mar 25, 2019
@gnzlbg gnzlbg changed the title Moves test::black_box to core::hint Moves test::black_box to core::hint and fix black_box on wasm32 and asm.js Mar 25, 2019
@gnzlbg
Copy link
Contributor Author

gnzlbg commented Mar 25, 2019

@alexcrichton LLVM now supports inline assembly for wasm32, so I've moved the implementation of wasm32 to also use inline assembly here, and changed the PR name and description to reflect the changes.

This means that only the asm.js targets do something different here. This PR changes that to use a volatile read, which, as opposed to using #[inline(never)], at least does not get optimized away, but as @SimonSapin argues, this might be more expensive than necessary.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Mar 25, 2019

📌 Commit 24db517 has been approved by alexcrichton

Centril added a commit to Centril/rust that referenced this pull request Mar 26, 2019
Moves test::black_box to core::hint and fix black_box on wasm32 and asm.js

This changes removes a cyclic dependency between the "test" and "libtest"
crates, where "libtest" depends on "test" for "black_box", but "test" depends on
"libtest" for everything else.

I've chosen the "hint" module because there seems to be enough consensus in the
discussion of RFC2360 that this module is where such an intrinsic would belong,
but this PR does not implement that RFC! If that RFC ever gets merged, the API, docs,
etc. of this API will need to change. This PR just move the implementation of the
already existing API.

For backwards compatibility reasons I've chosen to also keep the "test" feature
gate for these instead of adding a new feature gate. If we change the feature
gate, we'll potentially all benchmarks, and while that's something that we could
do, it seems unnecessary to do that now - if RFC2360 gets merged, we'll need to
do that anyways. Backwards compatibility is also why we continue to re-export
"black_box" from the "test" crate.

This PR also fixes black_box on the wasm32 target, which now supports inline assembly, and uses volatile loads on the asm.js target.

r? @Amanieu (cc @rust-lang/libs)
Centril added a commit to Centril/rust that referenced this pull request Mar 26, 2019
Moves test::black_box to core::hint and fix black_box on wasm32 and asm.js

This changes removes a cyclic dependency between the "test" and "libtest"
crates, where "libtest" depends on "test" for "black_box", but "test" depends on
"libtest" for everything else.

I've chosen the "hint" module because there seems to be enough consensus in the
discussion of RFC2360 that this module is where such an intrinsic would belong,
but this PR does not implement that RFC! If that RFC ever gets merged, the API, docs,
etc. of this API will need to change. This PR just move the implementation of the
already existing API.

For backwards compatibility reasons I've chosen to also keep the "test" feature
gate for these instead of adding a new feature gate. If we change the feature
gate, we'll potentially all benchmarks, and while that's something that we could
do, it seems unnecessary to do that now - if RFC2360 gets merged, we'll need to
do that anyways. Backwards compatibility is also why we continue to re-export
"black_box" from the "test" crate.

This PR also fixes black_box on the wasm32 target, which now supports inline assembly, and uses volatile loads on the asm.js target.

r? @Amanieu (cc @rust-lang/libs)
@Centril
Copy link
Contributor

Centril commented Mar 26, 2019

Failed in #59431 (comment), @bors r-

crate::mem::forget(dummy);
ret
}
}
Copy link
Member

Choose a reason for hiding this comment

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

To simplify the #[cfg] here, perhaps this could be:

pub fn black_box<T>(dummy: T) -> {
    #[cfg(supports_asm)]
    {
        unsafe { asm!(...); }
        return dummy;
    }
    unsafe {
        let ret = read_volatile(...);
        ...;
    }
}

Maybe with an #[allow(unreachable_code)] or something like that to pacify the linter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The last commit adds cfg_if! to the internal_macros.rs and uses it here. I find this looks infinitely better with cfg_if! than with any of the other options, and I suppose we could access it from core::arch as well.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Mar 26, 2019

📌 Commit 0c127e8 has been approved by alexcrichton

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 26, 2019
@Centril
Copy link
Contributor

Centril commented Mar 27, 2019

To unblock #59440, @bors p=1

@bors
Copy link
Contributor

bors commented Mar 27, 2019

⌛ Testing commit 0c127e8 with merge 791242c16e3847a81bea38e2c80948930c5b4dbf...

@bors
Copy link
Contributor

bors commented Mar 27, 2019

💥 Test timed out

@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 Mar 27, 2019
@Centril
Copy link
Contributor

Centril commented Mar 27, 2019

@bors retry

@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 Mar 27, 2019
@bors
Copy link
Contributor

bors commented Mar 27, 2019

⌛ Testing commit 0c127e8 with merge 35d3949f6bb2e8be93c49a1c8be1aa1c421b2a4a...

@bors
Copy link
Contributor

bors commented Mar 28, 2019

💥 Test timed out

@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 Mar 28, 2019
@kennytm
Copy link
Member

kennytm commented Mar 28, 2019

@bors retry

@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 Mar 28, 2019
bors added a commit that referenced this pull request Mar 28, 2019
Moves test::black_box to core::hint and fix black_box on wasm32 and asm.js

This changes removes a cyclic dependency between the "test" and "libtest"
crates, where "libtest" depends on "test" for "black_box", but "test" depends on
"libtest" for everything else.

I've chosen the "hint" module because there seems to be enough consensus in the
discussion of RFC2360 that this module is where such an intrinsic would belong,
but this PR does not implement that RFC! If that RFC ever gets merged, the API, docs,
etc. of this API will need to change. This PR just move the implementation of the
already existing API.

For backwards compatibility reasons I've chosen to also keep the "test" feature
gate for these instead of adding a new feature gate. If we change the feature
gate, we'll potentially all benchmarks, and while that's something that we could
do, it seems unnecessary to do that now - if RFC2360 gets merged, we'll need to
do that anyways. Backwards compatibility is also why we continue to re-export
"black_box" from the "test" crate.

This PR also fixes black_box on the wasm32 target, which now supports inline assembly, and uses volatile loads on the asm.js target.

r? @Amanieu (cc @rust-lang/libs)
@bors
Copy link
Contributor

bors commented Mar 28, 2019

⌛ Testing commit 0c127e8 with merge 6bfe4b7...

@bors
Copy link
Contributor

bors commented Mar 28, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: alexcrichton
Pushing 6bfe4b7 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 28, 2019
@bors bors merged commit 0c127e8 into rust-lang:master Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

8 participants