Skip to content

Commit 38bb78b

Browse files
committed
---
yaml --- r: 166778 b: refs/heads/master c: 7cd6bf6 h: refs/heads/master v: v3
1 parent 447aa34 commit 38bb78b

File tree

4 files changed

+118
-10
lines changed

4 files changed

+118
-10
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 25fb12b8a5411901675ede6b147bbc6c0b7437b7
2+
refs/heads/master: 7cd6bf67a2ccfe37912271f576ba2b1e1a568162
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 023dfb0c898d851dee6ace2f8339b73b5287136b
55
refs/heads/try: f5d619caf9f32458680fae55526b99582ca682dd

trunk/src/librustc/middle/ty.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,77 @@ bitflags! {
779779
}
780780
}
781781

782+
impl Copy for TypeFlags {}
783+
784+
macro_rules! sty_debug_print {
785+
($ctxt: expr, $($variant: ident),*) => {{
786+
// curious inner module to allow variant names to be used as
787+
// variable names.
788+
mod inner {
789+
use middle::ty;
790+
struct DebugStat {
791+
total: uint,
792+
region_infer: uint,
793+
ty_infer: uint,
794+
both_infer: uint,
795+
}
796+
797+
pub fn go(tcx: &ty::ctxt) {
798+
let mut total = DebugStat {
799+
total: 0,
800+
region_infer: 0, ty_infer: 0, both_infer: 0,
801+
};
802+
$(let mut $variant = total;)*
803+
804+
805+
for (_, t) in tcx.interner.borrow().iter() {
806+
let variant = match t.sty {
807+
ty::ty_bool | ty::ty_char | ty::ty_int(..) | ty::ty_uint(..) |
808+
ty::ty_float(..) | ty::ty_str => continue,
809+
ty::ty_err => /* unimportant */ continue,
810+
$(ty::$variant(..) => &mut $variant,)*
811+
};
812+
let region = t.flags.intersects(ty::HAS_RE_INFER);
813+
let ty = t.flags.intersects(ty::HAS_TY_INFER);
814+
815+
variant.total += 1;
816+
total.total += 1;
817+
if region { total.region_infer += 1; variant.region_infer += 1 }
818+
if ty { total.ty_infer += 1; variant.ty_infer += 1 }
819+
if region && ty { total.both_infer += 1; variant.both_infer += 1 }
820+
}
821+
println!("Ty interner total ty region both");
822+
$(println!(" {:18}: {uses:6} {usespc:4.1}%, \
823+
{ty:4.1}% {region:5.1}% {both:4.1}%",
824+
stringify!($variant),
825+
uses = $variant.total,
826+
usespc = $variant.total as f64 * 100.0 / total.total as f64,
827+
ty = $variant.ty_infer as f64 * 100.0 / total.total as f64,
828+
region = $variant.region_infer as f64 * 100.0 / total.total as f64,
829+
both = $variant.both_infer as f64 * 100.0 / total.total as f64);
830+
)*
831+
println!(" total {uses:6} \
832+
{ty:4.1}% {region:5.1}% {both:4.1}%",
833+
uses = total.total,
834+
ty = total.ty_infer as f64 * 100.0 / total.total as f64,
835+
region = total.region_infer as f64 * 100.0 / total.total as f64,
836+
both = total.both_infer as f64 * 100.0 / total.total as f64)
837+
}
838+
}
839+
840+
inner::go($ctxt)
841+
}}
842+
}
843+
844+
impl<'tcx> ctxt<'tcx> {
845+
pub fn print_debug_stats(&self) {
846+
sty_debug_print!(
847+
self,
848+
ty_enum, ty_uniq, ty_vec, ty_ptr, ty_rptr, ty_bare_fn, ty_closure, ty_trait,
849+
ty_struct, ty_unboxed_closure, ty_tup, ty_param, ty_open, ty_infer);
850+
}
851+
}
852+
782853
#[deriving(Show)]
783854
pub struct TyS<'tcx> {
784855
pub sty: sty<'tcx>,

trunk/src/librustc_driver/driver.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,20 @@ pub fn compile_input(sess: Session,
8282
let type_arena = TypedArena::new();
8383
let analysis = phase_3_run_analysis_passes(sess, ast_map, &type_arena, id);
8484
phase_save_analysis(&analysis.ty_cx.sess, analysis.ty_cx.map.krate(), &analysis, outdir);
85+
86+
if log_enabled!(::log::INFO) {
87+
println!("Pre-trans")
88+
analysis.ty_cx.print_debug_stats();
89+
}
90+
8591
if stop_after_phase_3(&analysis.ty_cx.sess) { return; }
8692
let (tcx, trans) = phase_4_translate_to_llvm(analysis);
8793

94+
if log_enabled!(::log::INFO) {
95+
println!("Post-trans")
96+
tcx.print_debug_stats();
97+
}
98+
8899
// Discard interned strings as they are no longer required.
89100
token::get_ident_interner().clear();
90101

trunk/src/librustc_trans/trans/base.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,14 +2125,20 @@ fn trans_enum_variant_or_tuple_like_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx
21252125
fn enum_variant_size_lint(ccx: &CrateContext, enum_def: &ast::EnumDef, sp: Span, id: ast::NodeId) {
21262126
let mut sizes = Vec::new(); // does no allocation if no pushes, thankfully
21272127

2128+
let print_info = log_enabled!(::log::INFO);
2129+
21282130
let levels = ccx.tcx().node_lint_levels.borrow();
21292131
let lint_id = lint::LintId::of(lint::builtin::VARIANT_SIZE_DIFFERENCES);
2130-
let lvlsrc = match levels.get(&(id, lint_id)) {
2131-
None | Some(&(lint::Allow, _)) => return,
2132-
Some(&lvlsrc) => lvlsrc,
2133-
};
2132+
let lvlsrc = levels.get(&(id, lint_id));
2133+
let is_allow = lvlsrc.map_or(true, |&(lvl, _)| lvl == lint::Allow);
2134+
2135+
if is_allow && !print_info {
2136+
// we're not interested in anything here
2137+
return
2138+
}
21342139

2135-
let avar = adt::represent_type(ccx, ty::node_id_to_type(ccx.tcx(), id));
2140+
let ty = ty::node_id_to_type(ccx.tcx(), id);
2141+
let avar = adt::represent_type(ccx, ty);
21362142
match *avar {
21372143
adt::General(_, ref variants, _) => {
21382144
for var in variants.iter() {
@@ -2158,13 +2164,29 @@ fn enum_variant_size_lint(ccx: &CrateContext, enum_def: &ast::EnumDef, sp: Span,
21582164
}
21592165
);
21602166

2167+
if print_info {
2168+
let llty = type_of::sizing_type_of(ccx, ty);
2169+
2170+
let sess = &ccx.tcx().sess;
2171+
sess.span_note(sp, &*format!("total size: {} bytes", llsize_of_real(ccx, llty)));
2172+
match *avar {
2173+
adt::General(..) => {
2174+
for (i, var) in enum_def.variants.iter().enumerate() {
2175+
ccx.tcx().sess.span_note(var.span,
2176+
&*format!("variant data: {} bytes", sizes[i]));
2177+
}
2178+
}
2179+
_ => {}
2180+
}
2181+
}
2182+
21612183
// we only warn if the largest variant is at least thrice as large as
21622184
// the second-largest.
2163-
if largest > slargest * 3 && slargest > 0 {
2185+
if !is_allow && largest > slargest * 3 && slargest > 0 {
21642186
// Use lint::raw_emit_lint rather than sess.add_lint because the lint-printing
21652187
// pass for the latter already ran.
21662188
lint::raw_emit_lint(&ccx.tcx().sess, lint::builtin::VARIANT_SIZE_DIFFERENCES,
2167-
lvlsrc, Some(sp),
2189+
*lvlsrc.unwrap(), Some(sp),
21682190
format!("enum variant is more than three times larger \
21692191
({} bytes) than the next largest (ignoring padding)",
21702192
largest)[]);
@@ -2332,8 +2354,12 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
23322354
ast::ItemMod(ref m) => {
23332355
trans_mod(&ccx.rotate(), m);
23342356
}
2335-
ast::ItemEnum(ref enum_definition, _) => {
2336-
enum_variant_size_lint(ccx, enum_definition, item.span, item.id);
2357+
ast::ItemEnum(ref enum_definition, ref gens) => {
2358+
if gens.ty_params.is_empty() {
2359+
// sizes only make sense for non-generic types
2360+
2361+
enum_variant_size_lint(ccx, enum_definition, item.span, item.id);
2362+
}
23372363
}
23382364
ast::ItemConst(_, ref expr) => {
23392365
// Recurse on the expression to catch items in blocks

0 commit comments

Comments
 (0)