-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Deduplicate panic_fmt #88860
Deduplicate panic_fmt #88860
Conversation
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
library/std/src/panic.rs
Outdated
$crate::rt::begin_panic_fmt(&$crate::const_format_args!($fmt, $($arg)+)) | ||
$crate::rt::begin_panic_fmt($crate::const_format_args!($fmt, $($arg)+)) |
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.
Why?
Ahh, begin_panic_fmt
get params by reference, when panic_fmt
takes by value. It's actually interesting to change panic_fmt to get it by reference too, as reference should be shorter than Arguments
struct.
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's an existing inconsistency between libcore and libstd API. The inconsistency actually makes the compiler/rustc_const_eval/src/const_eval/machine.rs
's begin_panic_fmt
-> const_panic_fmt
replacement unsound (but since const panic doesn't allow arguments today this unsound path is never hit).
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.
Ahh,
begin_panic_fmt
get params by reference, whenpanic_fmt
takes by value. It's actually interesting to change panic_fmt to get it by reference too, as reference should be shorter thatArguments
struct.
I actually don't think there'll be any meaningful difference. Size of Arguments
would make it be passed by reference anyway.
Plus, many existing methods like write_fmt
by value and Arguments
is Copy so I think it's actually good to take it by value for consistency.
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.
print-type-size type: `std::fmt::Arguments`: 48 bytes, alignment: 8 bytes
print-type-size field `.pieces`: 16 bytes
print-type-size field `.fmt`: 16 bytes
print-type-size field `.args`: 16 bytes
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.
What are you suggesting by listing the numbers? As I've said, the size of Arguments
(is larger than 2 usize) would make it be passed by reference. So codegen will behave exactly the same with or without the &
(https://godbolt.org/z/h69MKjdsn), and for semantics and consistency it should be Arguments
rather than &Arguments
.
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.
Sorry, i didn't knew that there some optimization that pass big Copy types by ref even if i explicitly pass it by value.
Value passed into PanicInfo::internal_constructor
by Option
'ing reference anyway, so there is no sense to copying it before that. (this comment about pub fn panic_fmt(fmt: fmt::Arguments<'_>) -> !
)
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.
Tried to check that in small example, looks like parameter really isn't copied in panic_fmt
(didn't checked this in stdlib). I remember that i played somewhere with fmt::Arguments and saw needless copying in stdlib.
☔ The latest upstream changes (presumably #89047) made this pull request unmergeable. Please resolve the merge conflicts. |
@rustbot label: +T-libs |
Thanks! @bors r+ |
📌 Commit 5636a13 has been approved by |
Note that clippy also has a reference to begin_panic_fmt that can be removed. |
Deduplicate panic_fmt std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.
Done |
This comment has been minimized.
This comment has been minimized.
(I haven't looked at the failure above in detail yet, but note that |
It seems that clippy is already sort of broken without my changes. |
Hmm, this lint is introduced after this PR is submitted.. Need a rebase to find out.. |
std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.
Yeah, clippy tends to depend heavily on the exact details of the std macros to recognize them, and doesn't seem to recognize core's macros. Rust 2021 uses core::panic with std as well, which clippy doesn't understand. Every time we change the panic macro in std, clippy breaks. We should probably do something about that. |
I'm guessing that it trips on the |
https://github.com/rust-lang/rust-clippy/blob/389a74b31aabca4aac3289763eeb2eccedd1b988/clippy_utils/src/higher.rs#L717 -- That's a very detailed assumption about what it expands to 🙃. So |
@bors r+ |
📌 Commit 7bd93df has been approved by |
Rollup of 10 pull requests Successful merges: - rust-lang#86479 (Automatic exponential formatting in Debug) - rust-lang#87404 (Add support for artifact size profiling) - rust-lang#87769 (Alloc features cleanup) - rust-lang#88789 (remove unnecessary bound on Zip specialization impl) - rust-lang#88860 (Deduplicate panic_fmt) - rust-lang#90009 (Make more `From` impls `const` (libcore)) - rust-lang#90018 (Fix rustdoc UI for very long type names) - rust-lang#90025 (Revert rust-lang#86011 to fix an incorrect bound check) - rust-lang#90036 (Remove border-bottom from most docblocks.) - rust-lang#90060 (Update RELEASES.md) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Deduplicate panic_fmt std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.
Fix manual_assert and match_wild_err_arm for `#![no_std]` and Rust 2021 Rust 2015 `std::panic!` has a wrapping block while `core::panic!` and Rust 2021 `std::panic!` does not. See rust-lang/rust#88919 for details. Note that the test won't pass until clippy changes in rust-lang/rust#88860 is synced. --- changelog: Fix [`manual_assert`] and [`match_wild_err_arm`] for `#![no_std]` and Rust 2021. Fixes #7723
std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.