-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Outline panicking code for RefCell::borrow
and RefCell::borrow_mut
#115491
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
Do you have a demonstration of this improving code size? |
Here's an example function: fn test(a: &RefCell<usize>) {
*a.borrow_mut() = 0xF00D;
} Before: panic_test::test:
sub rsp, 56
cmp qword ptr [rcx], 0
jne .LBB5_1
mov qword ptr [rcx + 8], 61453
mov qword ptr [rcx], 0
add rsp, 56
ret
.LBB5_1:
lea rax, [rip + __unnamed_10]
mov qword ptr [rsp + 32], rax
lea rcx, [rip + __unnamed_11]
lea r9, [rip + __unnamed_12]
lea r8, [rsp + 55]
mov edx, 16
call core::result::unwrap_failed
ud2 After: panic_test::test:
sub rsp, 40
cmp qword ptr [rcx], 0
jne .LBB6_2
mov qword ptr [rcx + 8], 61453
mov qword ptr [rcx], 0
add rsp, 40
ret
.LBB6_2:
lea rcx, [rip + __unnamed_5]
call core::cell::panic_already_borrowed
ud2 |
@bors r+ |
#[track_caller] | ||
#[cold] | ||
fn panic_already_borrowed(err: BorrowMutError) -> ! { | ||
panic!("already borrowed: {:?}", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this will print on release "already borrowed: BorrowMutError" instead of "already borrowed", which is useless.
Next one similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's done to match the existing output. BorrowMutError
may also contain the location of the original borrower.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=4db78fa88be92de81e74933887a7a140
Oh, my bad, with this pr and previously that code outputs "already borrowed: BorrowMutError".
Sad to not to have test coverage. Can you add tests with panic outputs?
Can this be simple strings like "already borrowed" instead? If user wants more info from error he will use try_borrow/try_borrow_mut instead of borrow/borrow_mut, that fn should be as slim as possible (but that cold code anyway, except pulling debug impl for error). And location available only via debug_refcell
which require rebuild std anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make sense to me to use simpler strings with debug_refcell
disabled.
@bors r- Good catch. r=me with those nits fixed |
@bors r+ since it sounds like this isn't a change in behavior |
☀️ Test successful - checks-actions |
Finished benchmarking commit (abfc6c4): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 628.382s -> 628.522s (0.02%) |
bitmaps and cargo opt incr-unchanged kinda look noisy atm |
@rustbot label: +perf-regression-triaged |
See rust-lang#115491. https://godbolt.org/z/MTsz87jGj shows a reduction of the code size for TLS accesses.
See rust-lang#115491 for prior related modifications. https://godbolt.org/z/MTsz87jGj shows a reduction of the code size for TLS accesses.
Outline panicking code for `LocalKey::with` See rust-lang#115491 for prior related modifications. https://godbolt.org/z/MTsz87jGj shows a reduction of the code size for TLS accesses.
Outline panicking code for `LocalKey::with` See rust-lang#115491 for prior related modifications. https://godbolt.org/z/MTsz87jGj shows a reduction of the code size for TLS accesses.
Outline panicking code for `LocalKey::with` See rust-lang/rust#115491 for prior related modifications. https://godbolt.org/z/MTsz87jGj shows a reduction of the code size for TLS accesses.
Outline panicking code for `LocalKey::with` See rust-lang/rust#115491 for prior related modifications. https://godbolt.org/z/MTsz87jGj shows a reduction of the code size for TLS accesses.
This outlines panicking code for
RefCell::borrow
andRefCell::borrow_mut
to reduce code size.