Skip to content

Commit 863369e

Browse files
committed
librustc: Only emit visitor glue if it's necessary.
500K to 600K shaved off librustc.
1 parent cf34f9f commit 863369e

File tree

8 files changed

+44
-3
lines changed

8 files changed

+44
-3
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub fn malloc_raw_dyn(bcx: block,
290290

291291
// Get the tydesc for the body:
292292
let static_ti = get_tydesc(ccx, t);
293-
glue::lazily_emit_all_tydesc_glue(ccx, static_ti);
293+
glue::lazily_emit_most_tydesc_glue(ccx, static_ti);
294294

295295
// Allocate space:
296296
let tydesc = PointerCast(bcx, static_ti.tydesc, T_ptr(T_i8()));

src/librustc/middle/trans/foreign.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,16 @@ pub fn trans_intrinsic(ccx: @CrateContext,
724724
fcx.llretptr.get());
725725
}
726726
~"get_tydesc" => {
727+
let tp_ty = substs.tys[0];
728+
let static_ti = get_tydesc(ccx, tp_ty);
729+
glue::lazily_emit_most_tydesc_glue(ccx, static_ti);
730+
731+
// FIXME (#3727): change this to T_ptr(ccx.tydesc_ty) when the
732+
// core::sys copy of the get_tydesc interface dies off.
733+
let td = PointerCast(bcx, static_ti.tydesc, T_ptr(T_nil()));
734+
Store(bcx, td, fcx.llretptr.get());
735+
}
736+
~"get_tydesc_for_visiting" => {
727737
let tp_ty = substs.tys[0];
728738
let static_ti = get_tydesc(ccx, tp_ty);
729739
glue::lazily_emit_all_tydesc_glue(ccx, static_ti);

src/librustc/middle/trans/glue.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ pub fn free_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> block {
153153
}
154154
}
155155

156+
/// Emits all tydesc glue except for visitor glue.
157+
pub fn lazily_emit_most_tydesc_glue(ccx: @CrateContext,
158+
static_ti: @mut tydesc_info) {
159+
lazily_emit_tydesc_glue(ccx, abi::tydesc_field_take_glue, static_ti);
160+
lazily_emit_tydesc_glue(ccx, abi::tydesc_field_drop_glue, static_ti);
161+
lazily_emit_tydesc_glue(ccx, abi::tydesc_field_free_glue, static_ti);
162+
}
163+
164+
/// Emits all tydesc glue, including visitor glue.
156165
pub fn lazily_emit_all_tydesc_glue(ccx: @CrateContext,
157166
static_ti: @mut tydesc_info) {
158167
lazily_emit_tydesc_glue(ccx, abi::tydesc_field_take_glue, static_ti);

src/librustc/middle/trans/meth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ pub fn make_impl_vtable(ccx: @CrateContext,
864864

865865
// Generate a type descriptor for the vtable.
866866
let tydesc = get_tydesc(ccx, self_ty);
867-
glue::lazily_emit_all_tydesc_glue(ccx, tydesc);
867+
glue::lazily_emit_most_tydesc_glue(ccx, tydesc);
868868

869869
make_vtable(ccx, tydesc, methods)
870870
}

src/librustc/middle/trans/type_use.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
121121
~"uninit" | ~"init" | ~"transmute" | ~"move_val" |
122122
~"move_val_init" => use_repr,
123123

124-
~"get_tydesc" | ~"needs_drop" => use_tydesc,
124+
~"get_tydesc" | ~"get_tydesc_for_visiting" |
125+
~"needs_drop" => use_tydesc,
125126

126127
~"atomic_cxchg" | ~"atomic_cxchg_acq"|
127128
~"atomic_cxchg_rel"| ~"atomic_load" |

src/librustc/middle/typeck/check/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,6 +3508,10 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
35083508
// FIXME (#3730): return *intrinsic::tydesc, not *()
35093509
(1u, ~[], ty::mk_nil_ptr(ccx.tcx))
35103510
}
3511+
~"get_tydesc_for_visiting" => {
3512+
// FIXME (#3730): return *intrinsic::tydesc, not *()
3513+
(1u, ~[], ty::mk_nil_ptr(ccx.tcx))
3514+
}
35113515
~"visit_tydesc" => {
35123516
let tydesc_name = special_idents::tydesc;
35133517
assert!(tcx.intrinsic_defs.contains_key(&tydesc_name));

src/libstd/repr.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use reflect;
2727
use reflect::{MovePtr, align};
2828
use str::StrSlice;
2929
use to_str::ToStr;
30+
use unstable::intrinsics;
3031
use vec::raw::{VecRepr, SliceRepr};
3132
use vec;
3233
use vec::{OwnedVector, UnboxedVecRepr};
@@ -570,6 +571,7 @@ impl TyVisitor for ReprVisitor {
570571
fn visit_closure_ptr(&self, _ck: uint) -> bool { true }
571572
}
572573

574+
#[cfg(stage0)]
573575
pub fn write_repr<T>(writer: @Writer, object: &T) {
574576
unsafe {
575577
let ptr = ptr::to_unsafe_ptr(object) as *c_void;
@@ -580,6 +582,18 @@ pub fn write_repr<T>(writer: @Writer, object: &T) {
580582
}
581583
}
582584

585+
#[cfg(not(stage0))]
586+
pub fn write_repr<T>(writer: @Writer, object: &T) {
587+
unsafe {
588+
let ptr = ptr::to_unsafe_ptr(object) as *c_void;
589+
let tydesc: *intrinsic::TyDesc =
590+
transmute(intrinsics::get_tydesc_for_visiting::<T>());
591+
let u = ReprVisitor(ptr, writer);
592+
let v = reflect::MovePtrAdaptor(u);
593+
visit_tydesc(tydesc, @v as @TyVisitor)
594+
}
595+
}
596+
583597
#[cfg(test)]
584598
struct P {a: int, b: float}
585599

src/libstd/unstable/intrinsics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ pub extern "rust-intrinsic" {
122122
// and TyVisitor which are in librustc
123123
//fn visit_tydesc(++td: *TyDesc, &&tv: TyVisitor) -> ();
124124

125+
#[cfg(not(stage0))]
126+
pub fn get_tydesc_for_visiting<T>() -> *();
127+
125128
pub fn frame_address(f: &once fn(*u8));
126129

127130
/// Get the address of the `__morestack` stack growth function.

0 commit comments

Comments
 (0)