Skip to content

Commit 180e235

Browse files
committed
fix performance regression from invalid IR
Monomorphize's normalization results in a 2% decrease in non-optimized code size for libstd, so there's a negligible cost to removing it. This also fixes several visit glue bugs because normalize wasn't considering the differences in visit glue between types. Closes #8720
1 parent 2c0f9bd commit 180e235

File tree

2 files changed

+3
-68
lines changed

2 files changed

+3
-68
lines changed

src/librustc/middle/trans/monomorphize.rs

+2-67
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ use middle::trans::type_of;
2626
use middle::trans::type_use;
2727
use middle::trans::intrinsic;
2828
use middle::ty;
29-
use middle::ty::{FnSig};
3029
use middle::typeck;
3130
use util::ppaux::{Repr,ty_to_str};
3231

3332
use syntax::ast;
3433
use syntax::ast_map;
3534
use syntax::ast_map::path_name;
3635
use syntax::ast_util::local_def;
37-
use syntax::opt_vec;
38-
use syntax::abi::AbiSet;
3936

4037
pub fn monomorphic_fn(ccx: @mut CrateContext,
4138
fn_id: ast::def_id,
@@ -61,17 +58,10 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
6158
let _icx = push_ctxt("monomorphic_fn");
6259
let mut must_cast = false;
6360

64-
let do_normalize = |t: &ty::t| {
65-
match normalize_for_monomorphization(ccx.tcx, *t) {
66-
Some(t) => { must_cast = true; t }
67-
None => *t
68-
}
69-
};
70-
7161
let psubsts = @param_substs {
72-
tys: real_substs.tps.map(|x| do_normalize(x)),
62+
tys: real_substs.tps.to_owned(),
7363
vtables: vtables,
74-
self_ty: real_substs.self_ty.map(|x| do_normalize(x)),
64+
self_ty: real_substs.self_ty.clone(),
7565
self_vtables: self_vtables
7666
};
7767

@@ -305,61 +295,6 @@ pub fn monomorphic_fn(ccx: @mut CrateContext,
305295
(lldecl, must_cast)
306296
}
307297

308-
pub fn normalize_for_monomorphization(tcx: ty::ctxt,
309-
ty: ty::t) -> Option<ty::t> {
310-
// FIXME[mono] could do this recursively. is that worthwhile? (#2529)
311-
return match ty::get(ty).sty {
312-
ty::ty_box(*) => {
313-
Some(ty::mk_opaque_box(tcx))
314-
}
315-
ty::ty_bare_fn(_) => {
316-
Some(ty::mk_bare_fn(
317-
tcx,
318-
ty::BareFnTy {
319-
purity: ast::impure_fn,
320-
abis: AbiSet::Rust(),
321-
sig: FnSig {bound_lifetime_names: opt_vec::Empty,
322-
inputs: ~[],
323-
output: ty::mk_nil()}}))
324-
}
325-
ty::ty_closure(ref fty) => {
326-
Some(normalized_closure_ty(tcx, fty.sigil))
327-
}
328-
ty::ty_trait(_, _, ref store, _, _) => {
329-
let sigil = match *store {
330-
ty::UniqTraitStore => ast::OwnedSigil,
331-
ty::BoxTraitStore => ast::ManagedSigil,
332-
ty::RegionTraitStore(_) => ast::BorrowedSigil,
333-
};
334-
335-
// Traits have the same runtime representation as closures.
336-
Some(normalized_closure_ty(tcx, sigil))
337-
}
338-
ty::ty_ptr(_) => {
339-
Some(ty::mk_uint())
340-
}
341-
_ => {
342-
None
343-
}
344-
};
345-
346-
fn normalized_closure_ty(tcx: ty::ctxt,
347-
sigil: ast::Sigil) -> ty::t
348-
{
349-
ty::mk_closure(
350-
tcx,
351-
ty::ClosureTy {
352-
purity: ast::impure_fn,
353-
sigil: sigil,
354-
onceness: ast::Many,
355-
region: ty::re_static,
356-
bounds: ty::EmptyBuiltinBounds(),
357-
sig: ty::FnSig {bound_lifetime_names: opt_vec::Empty,
358-
inputs: ~[],
359-
output: ty::mk_nil()}})
360-
}
361-
}
362-
363298
pub fn make_mono_id(ccx: @mut CrateContext,
364299
item: ast::def_id,
365300
substs: &param_substs,

src/libstd/repr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ fn test_repr() {
590590
exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\"");
591591

592592
exact_test(&(@10), "@10");
593-
exact_test(&(@mut 10), "@10"); // FIXME: #4210: incorrect
593+
exact_test(&(@mut 10), "@mut 10");
594594
exact_test(&((@mut 10, 2)), "(@mut 10, 2)");
595595
exact_test(&(~10), "~10");
596596
exact_test(&(&10), "&10");

0 commit comments

Comments
 (0)