Skip to content

Commit 637addd

Browse files
committed
rustc: de-@ trans::tydesc_info.
1 parent 3508891 commit 637addd

File tree

5 files changed

+18
-26
lines changed

5 files changed

+18
-26
lines changed

src/librustc/middle/trans/base.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,17 @@ pub fn malloc_raw_dyn_managed<'a>(
399399

400400
// Type descriptor and type glue stuff
401401

402-
pub fn get_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
402+
pub fn get_tydesc(ccx: &CrateContext, t: ty::t) -> Rc<tydesc_info> {
403403
match ccx.tydescs.borrow().find(&t) {
404-
Some(&inf) => return inf,
404+
Some(inf) => return inf.clone(),
405405
_ => { }
406406
}
407407

408408
ccx.stats.n_static_tydescs.set(ccx.stats.n_static_tydescs.get() + 1u);
409-
let inf = glue::declare_tydesc(ccx, t);
409+
let inf = Rc::new(glue::declare_tydesc(ccx, t));
410410

411-
ccx.tydescs.borrow_mut().insert(t, inf);
412-
return inf;
411+
ccx.tydescs.borrow_mut().insert(t, inf.clone());
412+
inf
413413
}
414414

415415
#[allow(dead_code)] // useful

src/librustc/middle/trans/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct CrateContext {
6464
pub item_symbols: RefCell<NodeMap<~str>>,
6565
pub link_meta: LinkMeta,
6666
pub drop_glues: RefCell<HashMap<ty::t, ValueRef>>,
67-
pub tydescs: RefCell<HashMap<ty::t, @tydesc_info>>,
67+
pub tydescs: RefCell<HashMap<ty::t, Rc<tydesc_info>>>,
6868
/// Set when running emit_tydescs to enforce that no more tydescs are
6969
/// created.
7070
pub finished_tydescs: Cell<bool>,

src/librustc/middle/trans/glue.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -145,39 +145,34 @@ pub fn get_drop_glue(ccx: &CrateContext, t: ty::t) -> ValueRef {
145145
glue
146146
}
147147

148-
pub fn lazily_emit_visit_glue(ccx: &CrateContext, ti: @tydesc_info) {
148+
pub fn lazily_emit_visit_glue(ccx: &CrateContext, ti: &tydesc_info) -> ValueRef {
149149
let _icx = push_ctxt("lazily_emit_visit_glue");
150150

151151
let llfnty = Type::glue_fn(ccx, type_of(ccx, ti.ty).ptr_to());
152152

153153
match ti.visit_glue.get() {
154-
Some(_) => (),
154+
Some(visit_glue) => visit_glue,
155155
None => {
156156
debug!("+++ lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_str(ccx.tcx(), ti.ty));
157157
let glue_fn = declare_generic_glue(ccx, ti.ty, llfnty, "visit");
158158
ti.visit_glue.set(Some(glue_fn));
159159
make_generic_glue(ccx, ti.ty, glue_fn, make_visit_glue, "visit");
160160
debug!("--- lazily_emit_tydesc_glue VISIT {}", ppaux::ty_to_str(ccx.tcx(), ti.ty));
161+
glue_fn
161162
}
162163
}
163164
}
164165

165166
// See [Note-arg-mode]
166167
pub fn call_visit_glue(bcx: &Block, v: ValueRef, tydesc: ValueRef,
167-
static_ti: Option<@tydesc_info>) {
168+
static_ti: Option<&tydesc_info>) {
168169
let _icx = push_ctxt("call_tydesc_glue_full");
169170
let ccx = bcx.ccx();
170171
// NB: Don't short-circuit even if this block is unreachable because
171172
// GC-based cleanup needs to the see that the roots are live.
172173
if bcx.unreachable.get() && !ccx.sess().no_landing_pads() { return; }
173174

174-
let static_glue_fn = match static_ti {
175-
None => None,
176-
Some(sti) => {
177-
lazily_emit_visit_glue(ccx, sti);
178-
sti.visit_glue.get()
179-
}
180-
};
175+
let static_glue_fn = static_ti.map(|sti| lazily_emit_visit_glue(ccx, sti));
181176

182177
// When static type info is available, avoid casting to a generic pointer.
183178
let llrawptr = if static_glue_fn.is_none() {
@@ -404,7 +399,7 @@ fn incr_refcnt_of_boxed<'a>(bcx: &'a Block<'a>,
404399

405400

406401
// Generates the declaration for (but doesn't emit) a type descriptor.
407-
pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
402+
pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> tydesc_info {
408403
// If emit_tydescs already ran, then we shouldn't be creating any new
409404
// tydescs.
410405
assert!(!ccx.finished_tydescs.get());
@@ -430,16 +425,15 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
430425
let ty_name = token::intern_and_get_ident(ppaux::ty_to_str(ccx.tcx(), t));
431426
let ty_name = C_str_slice(ccx, ty_name);
432427

433-
let inf = @tydesc_info {
428+
debug!("--- declare_tydesc {}", ppaux::ty_to_str(ccx.tcx(), t));
429+
tydesc_info {
434430
ty: t,
435431
tydesc: gvar,
436432
size: llsize,
437433
align: llalign,
438434
name: ty_name,
439435
visit_glue: Cell::new(None),
440-
};
441-
debug!("--- declare_tydesc {}", ppaux::ty_to_str(ccx.tcx(), t));
442-
return inf;
436+
}
443437
}
444438

445439
fn declare_generic_glue(ccx: &CrateContext, t: ty::t, llfnty: Type,
@@ -491,9 +485,7 @@ pub fn emit_tydescs(ccx: &CrateContext) {
491485
// As of this point, allow no more tydescs to be created.
492486
ccx.finished_tydescs.set(true);
493487
let glue_fn_ty = Type::generic_glue_fn(ccx).ptr_to();
494-
for (_, &val) in ccx.tydescs.borrow().iter() {
495-
let ti = val;
496-
488+
for (_, ti) in ccx.tydescs.borrow().iter() {
497489
// Each of the glue functions needs to be cast to a generic type
498490
// before being put into the tydesc because we only have a singleton
499491
// tydesc type. Then we'll recast each function to its real type when

src/librustc/middle/trans/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pub fn trans_intrinsic(ccx: &CrateContext,
328328
"get_tydesc" => {
329329
let tp_ty = *substs.tys.get(0);
330330
let static_ti = get_tydesc(ccx, tp_ty);
331-
glue::lazily_emit_visit_glue(ccx, static_ti);
331+
glue::lazily_emit_visit_glue(ccx, &*static_ti);
332332

333333
// FIXME (#3730): ideally this shouldn't need a cast,
334334
// but there's a circularity between translating rust types to llvm

src/librustc/middle/trans/reflect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'a, 'b> Reflector<'a, 'b> {
7676
pub fn c_tydesc(&mut self, t: ty::t) -> ValueRef {
7777
let bcx = self.bcx;
7878
let static_ti = get_tydesc(bcx.ccx(), t);
79-
glue::lazily_emit_visit_glue(bcx.ccx(), static_ti);
79+
glue::lazily_emit_visit_glue(bcx.ccx(), &*static_ti);
8080
PointerCast(bcx, static_ti.tydesc, self.tydesc_ty.ptr_to())
8181
}
8282

0 commit comments

Comments
 (0)