Auto merge of #94131 - Mark-Simulacrum:fmt-string, r=oli-obk
Always format to internal String in FmtPrinter This avoids monomorphizing for different parameters, decreasing generic code instantiated downstream from rustc_middle -- locally seeing 7% unoptimized LLVM IR line wins on rustc_borrowck, for example. We likely can't/shouldn't get rid of the Result-ness on most functions, though some further cleanup avoiding fmt::Error where we now know it won't occur may be possible, though somewhat painful -- fmt::Write is a pretty annoying API to work with in practice when you're trying to use it infallibly.
This commit is contained in:
commit
4b043faba3
10 changed files with 84 additions and 80 deletions
|
@ -109,11 +109,11 @@ rustc_data_structures::static_assert_size!(ImmTy<'_>, 72);
|
|||
impl<Tag: Provenance> std::fmt::Display for ImmTy<'_, Tag> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
/// Helper function for printing a scalar to a FmtPrinter
|
||||
fn p<'a, 'tcx, F: std::fmt::Write, Tag: Provenance>(
|
||||
cx: FmtPrinter<'a, 'tcx, F>,
|
||||
fn p<'a, 'tcx, Tag: Provenance>(
|
||||
cx: FmtPrinter<'a, 'tcx>,
|
||||
s: ScalarMaybeUninit<Tag>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Result<FmtPrinter<'a, 'tcx, F>, std::fmt::Error> {
|
||||
) -> Result<FmtPrinter<'a, 'tcx>, std::fmt::Error> {
|
||||
match s {
|
||||
ScalarMaybeUninit::Scalar(Scalar::Int(int)) => {
|
||||
cx.pretty_print_const_scalar_int(int, ty, true)
|
||||
|
@ -138,8 +138,8 @@ impl<Tag: Provenance> std::fmt::Display for ImmTy<'_, Tag> {
|
|||
match self.imm {
|
||||
Immediate::Scalar(s) => {
|
||||
if let Some(ty) = tcx.lift(self.layout.ty) {
|
||||
let cx = FmtPrinter::new(tcx, f, Namespace::ValueNS);
|
||||
p(cx, s, ty)?;
|
||||
let cx = FmtPrinter::new(tcx, Namespace::ValueNS);
|
||||
f.write_str(&p(cx, s, ty)?.into_buffer())?;
|
||||
return Ok(());
|
||||
}
|
||||
write!(f, "{:x}: {}", s, self.layout.ty)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue