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

Wrap write_bytes in a function. Move docs #57997

Merged
merged 1 commit into from
Feb 22, 2019
Merged

Wrap write_bytes in a function. Move docs #57997

merged 1 commit into from
Feb 22, 2019

Conversation

nitnelave
Copy link
Contributor

This will allow us to add debug assertions.
See issue #53871.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @KodrAus (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 30, 2019
@nitnelave
Copy link
Contributor Author

r? @RalfJung

@rust-highfive rust-highfive assigned RalfJung and unassigned KodrAus Jan 30, 2019
///
/// // Now the box is fine
/// assert_eq!(*v, 42);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
Copy link
Member

@RalfJung RalfJung Jan 30, 2019

Choose a reason for hiding this comment

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

This should then also be removed, I think.

EDIT: Uh, never mind. This is public.

Copy link
Member

Choose a reason for hiding this comment

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

Oh never mind. I did not know the functions in this module are pub. What the heck, why do we have public intrinsics?!?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I was surprised about when writing the wrapper :D

@RalfJung
Copy link
Member

Cc @rust-lang/libs Please advise: we'd like to replace ptr::write_bytes (currently a reexport) by a function so that we can add some debug assertions in there (see #53871). However, I just realized that the following compiles on stable:

fn main() {
    let mut x = 2;
    unsafe {
        core::intrinsics::write_bytes(&mut x, 0, 1);
    }
}

That's quite bad, obviously, because it allows direct access to the intrinsic. I am seriously surprised that anything in intrinsics got stabilized.

So we could either move this one intrinsic to a submodule, meaning core::intrinsics::write_bytes would not actually be an intrinsic, or we could replace the reexport by a wrapper function, meaning core::intrinsics::write_bytes and core::ptr::write_bytes would not be the same operation. Which do you prefer?

@SimonSapin
Copy link
Contributor

That core::intrinsics::write_bytes works on Stable is a bug: #15702. I think we have precedent declaring this kind of bug not covered by the stability promise.

In fact I’d be in favor of actively unstabilizing everything in core::intrinsics, and replacing reexports by stable #[inline] wrapper functions.

@nitnelave
Copy link
Contributor Author

I added the #[inline] annotation, but I'm leaving the destabilization of core::intrinsics for another issue.

@alexcrichton
Copy link
Member

Wrapping raw intrinsics in new functions has historically caused a noticeable impact to compile times. I'd recommend holding off on landing a PR that wraps everything until we have a perf run at least to evaluate the impact.

@nitnelave
Copy link
Contributor Author

@alexcrichton That's okay with me. How do I trigger a perf run? Or is it just going to come eventually from the CI?

@alexcrichton
Copy link
Member

Oh triggering a perf run currently is still pretty manual. @nitnelave do you want to wrap a few more functions or just this one? Afterwards it's just @bors: try, wait for that, then @rustc-perf ...

@RalfJung
Copy link
Member

RalfJung commented Jan 30, 2019

I added the #[inline] annotation, but I'm leaving the destabilization of core::intrinsics for another issue.

What do we gain from separating this?

Anyway this PR currently removes the doc comment from a public stable function, I don't think that's a good idea (don't we have a lint against undocumented functions?).

That core::intrinsics::write_bytes works on Stable is a bug: #15702.

Hm, I don't see the connection to that issue. write_bytes is actively marked as stable in the intrinsics module, so it is not surprising that it is stable, is it?

EDIT: Oh, I @alexcrichton wrote "The intrinsics module is unstable but the function is stable because it's reexported in std::ptr". I thought we could attach a stability attribute to the reexport, but that doesn't seem to work then.

In fact I’d be in favor of actively unstabilizing everything in core::intrinsics, and replacing reexports by stable #[inline] wrapper functions.

Ah, that's great! I think it is impossible for transmute, but I suggest we do that here at least for the pointer methods.

@nitnelave
Copy link
Contributor Author

I guess we'll eventually also wrap copy and copy_nonoverlapping, so I might as well do it all in one go.

@RalfJung
Copy link
Member

Yes please do. That'll also make the perf impact bigger (if it exists) and hence easier to measure.

I'd even use #[inline(always)], and that has been necessary before, but it is worth trying without always first (I think @nnethercote prefers it that way).

@RalfJung
Copy link
Member

Thanks! Let's see what the timing says.

@bors try

@bors
Copy link
Contributor

bors commented Jan 30, 2019

⌛ Trying commit 1c8b67b with merge 4f8466b...

bors added a commit that referenced this pull request Jan 30, 2019
Wrap write_bytes in a function. Move docs

This will allow us to add debug assertions.
See issue #53871.
@SimonSapin
Copy link
Contributor

write_bytes is actively marked as stable in the intrinsics module, so it is not surprising that it is stable, is it?

Yes, but going "through" an unstable module in a path such as core::intrinsics::write_bytes should not be allowed on stable. In other words, the only difference on the stable channel between an unstable module and a non-existing module should be the contents of error messages.

@nitnelave
Copy link
Contributor Author

@rustc-perf

@nitnelave
Copy link
Contributor Author

I'm trying to run a benchmark, how do I trigger that? @RalfJung

@tesuji
Copy link
Contributor

tesuji commented Feb 4, 2019

@nitnelave Try @rust-timer build 4f8466b.
Edit:

  • But why do you need to do a benchmark? I don't think this PR has much performance impact.
  • You must have enough permission to run rust-timer.

@rust-timer
Copy link
Collaborator

Insufficient permissions to issue commands to rust-timer.

1 similar comment
@rust-timer
Copy link
Collaborator

Insufficient permissions to issue commands to rust-timer.

@nitnelave
Copy link
Contributor Author

  • But why do you need to do a benchmark? I don't think this PR has much performance impact.

It shouldn't, but we're trying to assess that, see #57997 (comment)

  • You must have enough permission to run rust-timer.

Who does? Who can I ask?

@tesuji
Copy link
Contributor

tesuji commented Feb 4, 2019

It shouldn't, but we're trying to assess that, see #57997 (comment)

Ah, yeah!

Who does? Who can I ask?

If you're not in the whitelist and try to run the timer, the timer will complain.

I will try to cc @RalfJung .

@RalfJung
Copy link
Member

RalfJung commented Feb 4, 2019

@rust-timer build 4f8466b

@rust-timer
Copy link
Collaborator

Success: Queued 4f8466b with parent 43b4c4a, comparison URL.

@bors
Copy link
Contributor

bors commented Feb 15, 2019

💔 Test failed - checks-travis

@rust-highfive
Copy link
Collaborator

Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@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 Feb 15, 2019
@pietroalbini
Copy link
Member

@bors retry -- apparently we can't clone the repo anymore on macOS

@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 Feb 15, 2019
@pietroalbini

This comment has been minimized.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Feb 17, 2019
Wrap write_bytes in a function. Move docs

This will allow us to add debug assertions.
See issue rust-lang#53871.
Centril added a commit to Centril/rust that referenced this pull request Feb 20, 2019
Wrap write_bytes in a function. Move docs

This will allow us to add debug assertions.
See issue rust-lang#53871.
@bors
Copy link
Contributor

bors commented Feb 22, 2019

⌛ Testing commit 26bd433 with merge e1c6d00...

bors added a commit that referenced this pull request Feb 22, 2019
Wrap write_bytes in a function. Move docs

This will allow us to add debug assertions.
See issue #53871.
@bors
Copy link
Contributor

bors commented Feb 22, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: RalfJung
Pushing e1c6d00 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 22, 2019
@bors
Copy link
Contributor

bors commented Feb 22, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: RalfJung
Pushing e1c6d00 to master...

@bors bors merged commit 26bd433 into rust-lang:master Feb 22, 2019
@nitnelave
Copy link
Contributor Author

Yay! \o\ \o\ /o/ /o/

suemto pushed a commit to mwcproject/rust-secp256k1-zkp that referenced this pull request Oct 28, 2020
The interface, though marked stable, is actually not.
See rust-lang/rust#57997.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2021
directly expose copy and copy_nonoverlapping intrinsics

This effectively un-does rust-lang#57997. That should help with `ptr::read` codegen in debug builds (and any other of these low-level functions that bottoms out at `copy`/`copy_nonoverlapping`), where the wrapper function will not get inlined. See the discussion in rust-lang#80290 and rust-lang#81163.

Cc `@bjorn3` `@therealprof`
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Feb 25, 2021
directly expose copy and copy_nonoverlapping intrinsics

This effectively un-does rust-lang/rust#57997. That should help with `ptr::read` codegen in debug builds (and any other of these low-level functions that bottoms out at `copy`/`copy_nonoverlapping`), where the wrapper function will not get inlined. See the discussion in rust-lang/rust#80290 and rust-lang/rust#81163.

Cc `@bjorn3` `@therealprof`
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.