Skip to content

Commit

Permalink
Rollup merge of rust-lang#58802 - nnethercote:inline-record_layout, r…
Browse files Browse the repository at this point in the history
…=oli-obk

Ensure `record_layout_for_printing()` is inlined.

This reduces instruction counts for the `ctfe-stress-2` benchmark by
about 1%.

r? @oli-obk
  • Loading branch information
kennytm committed Mar 2, 2019
2 parents 4aebce5 + fbdece4 commit 8bdd948
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/librustc/ty/layout.rs
Expand Up @@ -1176,25 +1176,27 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {

/// This is invoked by the `layout_raw` query to record the final
/// layout of each type.
#[inline]
#[inline(always)]
fn record_layout_for_printing(&self, layout: TyLayout<'tcx>) {
// If we are running with `-Zprint-type-sizes`, record layouts for
// dumping later. Ignore layouts that are done with non-empty
// environments or non-monomorphic layouts, as the user only wants
// to see the stuff resulting from the final codegen session.
// If we are running with `-Zprint-type-sizes`, maybe record layouts
// for dumping later.
if self.tcx.sess.opts.debugging_opts.print_type_sizes {
self.record_layout_for_printing_outlined(layout)
}
}

fn record_layout_for_printing_outlined(&self, layout: TyLayout<'tcx>) {
// Ignore layouts that are done with non-empty environments or
// non-monomorphic layouts, as the user only wants to see the stuff
// resulting from the final codegen session.
if
!self.tcx.sess.opts.debugging_opts.print_type_sizes ||
layout.ty.has_param_types() ||
layout.ty.has_self_ty() ||
!self.param_env.caller_bounds.is_empty()
{
return;
}

self.record_layout_for_printing_outlined(layout)
}

fn record_layout_for_printing_outlined(&self, layout: TyLayout<'tcx>) {
// (delay format until we actually need it)
let record = |kind, packed, opt_discr_size, variants| {
let type_desc = format!("{:?}", layout.ty);
Expand Down

0 comments on commit 8bdd948

Please sign in to comment.