-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Experiment: Make intrinsic::size_of(slice) saturate #95832
Conversation
r? @fee1-dead (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
Well I wrote that wrong and I don't know how to write it properly, especially given it compiles on my machine. I'll need to ask for help here 😅 |
r? @nikomatsakis for reassignment/guidance |
At a micro/assembly level, this changes getting the size of a slice from |
Hmm, I'm not sure what the problem is tbh -- seems like an LLVM problem. r? @bjorn3 -- I'm guessing you might have insight, or have a good idea who would! |
Maybe add an assert there instead. Alternatively we can say that given that the pointer part of the fat pointer returned by
This is not an LLVM problem. |
There's no unsoundness problem currently; we say that construction of the pointer is safe, and using it is not. This is reasonable, and fits the normal raw pointer semantics. The "problem" is a theoretical one: that (Any soundness issue is resulting from using This is, then, an attempt at an experiment to see the cost of making To be clear: I don't really expect this to merge, there's no need for it to merge, and there's no immediate benefit to this merging. Also, the original motivation for this PR (doing allocation work over pointee metadata) has disappeared (it's using Again, to reiterate: the goal is to enable std to eventually provide something like
This PR's point is to examine the cost of making this just (But, depending on how extern type is treated, it might need to be a separate function anyway. |
I don't think I can make a good decision on this. r? rust-lang/compiler |
@CAD97, can you fix the PR so that we can do a perf run? |
b6cbc08
to
e0dd13c
Compare
e0dd13c
to
5cd848c
Compare
Ok, I think I fixed the build errors, so this should be perf run capable now. |
Well nevermind, take two 😅 |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit ed3502f with merge 2410a27108a1d1203807aa16f689a9df484b43f1... |
☀️ Try build successful - checks-actions |
Queued 2410a27108a1d1203807aa16f689a9df484b43f1 with parent 7417110, future comparison URL. |
Finished benchmarking commit (2410a27108a1d1203807aa16f689a9df484b43f1): comparison url. Summary:
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Footnotes |
This answers the question at hand, and the original motivation for this experiment has faded, so I'm going to go ahead and just close this. I still think that a safe way to go from pointee metadata to |
Experiment to see how much of a perf impact this is.
Currently,
size_of_val
will wrap for a slice that is larger thanusize::MAX
. Constructing a pointer to such is stably safe viaptr::slice_from_raw_parts[_mut]
.I would like it to be possible to have a safe/checked version of
size_of_val_raw
, which returns roughlyOption<#[rustc_valid_scalar_range_start(0)] isize>
. The simple way to do so is to haveintrinsic::size_of
saturate, and then the safe wrapper can check for> isize::MAX
as the error condition.This PR is to check how expensive it would be to just always saturate the computation of a slice's size.
This PR does not address any of the other kinds of unsized types. Aggregate types will still potentially overflow, and it is still (AIUI) undecided whether the vtable part of pointer-to-dyn-trait is required to point to a valid vtable.