Skip to content

Commit eced501

Browse files
committed
allow generating drop glue without the TyDesc
Reflection is now the only user of type descriptors. Uses of drop glue no longer cause a type descriptor to be generated.
1 parent 940d1ae commit eced501

File tree

8 files changed

+216
-270
lines changed

8 files changed

+216
-270
lines changed

src/libarena/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ impl Arena {
214214
#[inline]
215215
fn alloc_pod<'a, T>(&'a mut self, op: || -> T) -> &'a T {
216216
unsafe {
217-
let tydesc = get_tydesc::<T>();
218-
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
217+
let ptr = self.alloc_pod_inner(mem::size_of::<T>(), mem::min_align_of::<T>());
219218
let ptr: *mut T = transmute(ptr);
220219
intrinsics::move_val_init(&mut (*ptr), op());
221220
return transmute(ptr);
@@ -272,7 +271,7 @@ impl Arena {
272271
unsafe {
273272
let tydesc = get_tydesc::<T>();
274273
let (ty_ptr, ptr) =
275-
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
274+
self.alloc_nonpod_inner(mem::size_of::<T>(), mem::min_align_of::<T>());
276275
let ty_ptr: *mut uint = transmute(ty_ptr);
277276
let ptr: *mut T = transmute(ptr);
278277
// Write in our tydesc along with a bit indicating that it

src/librustc/middle/trans/base.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,8 @@ pub fn malloc_raw_dyn<'a>(
376376
let llty = type_of(ccx, box_ptr_ty);
377377
let llalign = C_uint(ccx, llalign_of_min(ccx, llty) as uint);
378378

379-
// Get the tydesc for the body:
380-
let static_ti = get_tydesc(ccx, t);
381-
glue::lazily_emit_tydesc_glue(ccx, abi::tydesc_field_drop_glue, static_ti);
382-
383379
// Allocate space:
384-
let drop_glue = static_ti.drop_glue.get().unwrap();
380+
let drop_glue = glue::get_drop_glue(ccx, t);
385381
let r = callee::trans_lang_call(
386382
bcx,
387383
langcall,

src/librustc/middle/trans/common.rs

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ pub struct tydesc_info {
114114
size: ValueRef,
115115
align: ValueRef,
116116
name: ValueRef,
117-
drop_glue: Cell<Option<ValueRef>>,
118117
visit_glue: Cell<Option<ValueRef>>,
119118
}
120119

src/librustc/middle/trans/context.rs

+131-129
Original file line numberDiff line numberDiff line change
@@ -36,83 +36,84 @@ use syntax::ast;
3636
use syntax::parse::token::InternedString;
3737

3838
pub struct CrateContext {
39-
sess: session::Session,
40-
llmod: ModuleRef,
41-
llcx: ContextRef,
42-
metadata_llmod: ModuleRef,
43-
td: TargetData,
44-
tn: TypeNames,
45-
externs: RefCell<ExternMap>,
46-
intrinsics: HashMap<&'static str, ValueRef>,
47-
item_vals: RefCell<HashMap<ast::NodeId, ValueRef>>,
48-
exp_map2: resolve::ExportMap2,
49-
reachable: @RefCell<HashSet<ast::NodeId>>,
50-
item_symbols: RefCell<HashMap<ast::NodeId, ~str>>,
51-
link_meta: LinkMeta,
52-
tydescs: RefCell<HashMap<ty::t, @tydesc_info>>,
53-
// Set when running emit_tydescs to enforce that no more tydescs are
54-
// created.
55-
finished_tydescs: Cell<bool>,
56-
// Track mapping of external ids to local items imported for inlining
57-
external: RefCell<HashMap<ast::DefId, Option<ast::NodeId>>>,
58-
// Backwards version of the `external` map (inlined items to where they
59-
// came from)
60-
external_srcs: RefCell<HashMap<ast::NodeId, ast::DefId>>,
61-
// A set of static items which cannot be inlined into other crates. This
62-
// will pevent in IIItem() structures from being encoded into the metadata
63-
// that is generated
64-
non_inlineable_statics: RefCell<HashSet<ast::NodeId>>,
65-
// Cache instances of monomorphized functions
66-
monomorphized: RefCell<HashMap<mono_id, ValueRef>>,
67-
monomorphizing: RefCell<HashMap<ast::DefId, uint>>,
68-
// Cache generated vtables
69-
vtables: RefCell<HashMap<(ty::t, mono_id), ValueRef>>,
70-
// Cache of constant strings,
71-
const_cstr_cache: RefCell<HashMap<InternedString, ValueRef>>,
39+
sess: session::Session,
40+
llmod: ModuleRef,
41+
llcx: ContextRef,
42+
metadata_llmod: ModuleRef,
43+
td: TargetData,
44+
tn: TypeNames,
45+
externs: RefCell<ExternMap>,
46+
intrinsics: HashMap<&'static str, ValueRef>,
47+
item_vals: RefCell<HashMap<ast::NodeId, ValueRef>>,
48+
exp_map2: resolve::ExportMap2,
49+
reachable: @RefCell<HashSet<ast::NodeId>>,
50+
item_symbols: RefCell<HashMap<ast::NodeId, ~str>>,
51+
link_meta: LinkMeta,
52+
drop_glues: RefCell<HashMap<ty::t, ValueRef>>,
53+
tydescs: RefCell<HashMap<ty::t, @tydesc_info>>,
54+
// Set when running emit_tydescs to enforce that no more tydescs are
55+
// created.
56+
finished_tydescs: Cell<bool>,
57+
// Track mapping of external ids to local items imported for inlining
58+
external: RefCell<HashMap<ast::DefId, Option<ast::NodeId>>>,
59+
// Backwards version of the `external` map (inlined items to where they
60+
// came from)
61+
external_srcs: RefCell<HashMap<ast::NodeId, ast::DefId>>,
62+
// A set of static items which cannot be inlined into other crates. This
63+
// will pevent in IIItem() structures from being encoded into the metadata
64+
// that is generated
65+
non_inlineable_statics: RefCell<HashSet<ast::NodeId>>,
66+
// Cache instances of monomorphized functions
67+
monomorphized: RefCell<HashMap<mono_id, ValueRef>>,
68+
monomorphizing: RefCell<HashMap<ast::DefId, uint>>,
69+
// Cache generated vtables
70+
vtables: RefCell<HashMap<(ty::t, mono_id), ValueRef>>,
71+
// Cache of constant strings,
72+
const_cstr_cache: RefCell<HashMap<InternedString, ValueRef>>,
7273

73-
// Reverse-direction for const ptrs cast from globals.
74-
// Key is an int, cast from a ValueRef holding a *T,
75-
// Val is a ValueRef holding a *[T].
76-
//
77-
// Needed because LLVM loses pointer->pointee association
78-
// when we ptrcast, and we have to ptrcast during translation
79-
// of a [T] const because we form a slice, a [*T,int] pair, not
80-
// a pointer to an LLVM array type.
81-
const_globals: RefCell<HashMap<int, ValueRef>>,
74+
// Reverse-direction for const ptrs cast from globals.
75+
// Key is an int, cast from a ValueRef holding a *T,
76+
// Val is a ValueRef holding a *[T].
77+
//
78+
// Needed because LLVM loses pointer->pointee association
79+
// when we ptrcast, and we have to ptrcast during translation
80+
// of a [T] const because we form a slice, a [*T,int] pair, not
81+
// a pointer to an LLVM array type.
82+
const_globals: RefCell<HashMap<int, ValueRef>>,
8283

83-
// Cache of emitted const values
84-
const_values: RefCell<HashMap<ast::NodeId, ValueRef>>,
84+
// Cache of emitted const values
85+
const_values: RefCell<HashMap<ast::NodeId, ValueRef>>,
8586

86-
// Cache of external const values
87-
extern_const_values: RefCell<HashMap<ast::DefId, ValueRef>>,
87+
// Cache of external const values
88+
extern_const_values: RefCell<HashMap<ast::DefId, ValueRef>>,
8889

89-
impl_method_cache: RefCell<HashMap<(ast::DefId, ast::Name), ast::DefId>>,
90+
impl_method_cache: RefCell<HashMap<(ast::DefId, ast::Name), ast::DefId>>,
9091

91-
// Cache of closure wrappers for bare fn's.
92-
closure_bare_wrapper_cache: RefCell<HashMap<ValueRef, ValueRef>>,
92+
// Cache of closure wrappers for bare fn's.
93+
closure_bare_wrapper_cache: RefCell<HashMap<ValueRef, ValueRef>>,
9394

94-
module_data: RefCell<HashMap<~str, ValueRef>>,
95-
lltypes: RefCell<HashMap<ty::t, Type>>,
96-
llsizingtypes: RefCell<HashMap<ty::t, Type>>,
97-
adt_reprs: RefCell<HashMap<ty::t, @adt::Repr>>,
98-
symbol_hasher: RefCell<Sha256>,
99-
type_hashcodes: RefCell<HashMap<ty::t, ~str>>,
100-
all_llvm_symbols: RefCell<HashSet<~str>>,
101-
tcx: ty::ctxt,
102-
maps: astencode::Maps,
103-
stats: @Stats,
104-
tydesc_type: Type,
105-
int_type: Type,
106-
opaque_vec_type: Type,
107-
builder: BuilderRef_res,
108-
crate_map: ValueRef,
109-
crate_map_name: ~str,
110-
// Set when at least one function uses GC. Needed so that
111-
// decl_gc_metadata knows whether to link to the module metadata, which
112-
// is not emitted by LLVM's GC pass when no functions use GC.
113-
uses_gc: bool,
114-
dbg_cx: Option<debuginfo::CrateDebugContext>,
115-
do_not_commit_warning_issued: Cell<bool>,
95+
module_data: RefCell<HashMap<~str, ValueRef>>,
96+
lltypes: RefCell<HashMap<ty::t, Type>>,
97+
llsizingtypes: RefCell<HashMap<ty::t, Type>>,
98+
adt_reprs: RefCell<HashMap<ty::t, @adt::Repr>>,
99+
symbol_hasher: RefCell<Sha256>,
100+
type_hashcodes: RefCell<HashMap<ty::t, ~str>>,
101+
all_llvm_symbols: RefCell<HashSet<~str>>,
102+
tcx: ty::ctxt,
103+
maps: astencode::Maps,
104+
stats: @Stats,
105+
tydesc_type: Type,
106+
int_type: Type,
107+
opaque_vec_type: Type,
108+
builder: BuilderRef_res,
109+
crate_map: ValueRef,
110+
crate_map_name: ~str,
111+
// Set when at least one function uses GC. Needed so that
112+
// decl_gc_metadata knows whether to link to the module metadata, which
113+
// is not emitted by LLVM's GC pass when no functions use GC.
114+
uses_gc: bool,
115+
dbg_cx: Option<debuginfo::CrateDebugContext>,
116+
do_not_commit_warning_issued: Cell<bool>,
116117
}
117118

118119
impl CrateContext {
@@ -175,64 +176,65 @@ impl CrateContext {
175176
}
176177

177178
CrateContext {
178-
sess: sess,
179-
llmod: llmod,
180-
llcx: llcx,
181-
metadata_llmod: metadata_llmod,
182-
td: td,
183-
tn: tn,
184-
externs: RefCell::new(HashMap::new()),
185-
intrinsics: intrinsics,
186-
item_vals: RefCell::new(HashMap::new()),
187-
exp_map2: emap2,
188-
reachable: reachable,
189-
item_symbols: RefCell::new(HashMap::new()),
190-
link_meta: link_meta,
191-
tydescs: RefCell::new(HashMap::new()),
192-
finished_tydescs: Cell::new(false),
193-
external: RefCell::new(HashMap::new()),
194-
external_srcs: RefCell::new(HashMap::new()),
195-
non_inlineable_statics: RefCell::new(HashSet::new()),
196-
monomorphized: RefCell::new(HashMap::new()),
197-
monomorphizing: RefCell::new(HashMap::new()),
198-
vtables: RefCell::new(HashMap::new()),
199-
const_cstr_cache: RefCell::new(HashMap::new()),
200-
const_globals: RefCell::new(HashMap::new()),
201-
const_values: RefCell::new(HashMap::new()),
202-
extern_const_values: RefCell::new(HashMap::new()),
203-
impl_method_cache: RefCell::new(HashMap::new()),
204-
closure_bare_wrapper_cache: RefCell::new(HashMap::new()),
205-
module_data: RefCell::new(HashMap::new()),
206-
lltypes: RefCell::new(HashMap::new()),
207-
llsizingtypes: RefCell::new(HashMap::new()),
208-
adt_reprs: RefCell::new(HashMap::new()),
209-
symbol_hasher: RefCell::new(symbol_hasher),
210-
type_hashcodes: RefCell::new(HashMap::new()),
211-
all_llvm_symbols: RefCell::new(HashSet::new()),
212-
tcx: tcx,
213-
maps: maps,
214-
stats: @Stats {
215-
n_static_tydescs: Cell::new(0u),
216-
n_glues_created: Cell::new(0u),
217-
n_null_glues: Cell::new(0u),
218-
n_real_glues: Cell::new(0u),
219-
n_fns: Cell::new(0u),
220-
n_monos: Cell::new(0u),
221-
n_inlines: Cell::new(0u),
222-
n_closures: Cell::new(0u),
223-
n_llvm_insns: Cell::new(0u),
224-
llvm_insns: RefCell::new(HashMap::new()),
225-
fn_stats: RefCell::new(~[]),
226-
},
227-
tydesc_type: tydesc_type,
228-
int_type: int_type,
229-
opaque_vec_type: opaque_vec_type,
230-
builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)),
231-
crate_map: crate_map,
232-
crate_map_name: crate_map_name,
233-
uses_gc: false,
234-
dbg_cx: dbg_cx,
235-
do_not_commit_warning_issued: Cell::new(false),
179+
sess: sess,
180+
llmod: llmod,
181+
llcx: llcx,
182+
metadata_llmod: metadata_llmod,
183+
td: td,
184+
tn: tn,
185+
externs: RefCell::new(HashMap::new()),
186+
intrinsics: intrinsics,
187+
item_vals: RefCell::new(HashMap::new()),
188+
exp_map2: emap2,
189+
reachable: reachable,
190+
item_symbols: RefCell::new(HashMap::new()),
191+
link_meta: link_meta,
192+
drop_glues: RefCell::new(HashMap::new()),
193+
tydescs: RefCell::new(HashMap::new()),
194+
finished_tydescs: Cell::new(false),
195+
external: RefCell::new(HashMap::new()),
196+
external_srcs: RefCell::new(HashMap::new()),
197+
non_inlineable_statics: RefCell::new(HashSet::new()),
198+
monomorphized: RefCell::new(HashMap::new()),
199+
monomorphizing: RefCell::new(HashMap::new()),
200+
vtables: RefCell::new(HashMap::new()),
201+
const_cstr_cache: RefCell::new(HashMap::new()),
202+
const_globals: RefCell::new(HashMap::new()),
203+
const_values: RefCell::new(HashMap::new()),
204+
extern_const_values: RefCell::new(HashMap::new()),
205+
impl_method_cache: RefCell::new(HashMap::new()),
206+
closure_bare_wrapper_cache: RefCell::new(HashMap::new()),
207+
module_data: RefCell::new(HashMap::new()),
208+
lltypes: RefCell::new(HashMap::new()),
209+
llsizingtypes: RefCell::new(HashMap::new()),
210+
adt_reprs: RefCell::new(HashMap::new()),
211+
symbol_hasher: RefCell::new(symbol_hasher),
212+
type_hashcodes: RefCell::new(HashMap::new()),
213+
all_llvm_symbols: RefCell::new(HashSet::new()),
214+
tcx: tcx,
215+
maps: maps,
216+
stats: @Stats {
217+
n_static_tydescs: Cell::new(0u),
218+
n_glues_created: Cell::new(0u),
219+
n_null_glues: Cell::new(0u),
220+
n_real_glues: Cell::new(0u),
221+
n_fns: Cell::new(0u),
222+
n_monos: Cell::new(0u),
223+
n_inlines: Cell::new(0u),
224+
n_closures: Cell::new(0u),
225+
n_llvm_insns: Cell::new(0u),
226+
llvm_insns: RefCell::new(HashMap::new()),
227+
fn_stats: RefCell::new(~[]),
228+
},
229+
tydesc_type: tydesc_type,
230+
int_type: int_type,
231+
opaque_vec_type: opaque_vec_type,
232+
builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)),
233+
crate_map: crate_map,
234+
crate_map_name: crate_map_name,
235+
uses_gc: false,
236+
dbg_cx: dbg_cx,
237+
do_not_commit_warning_issued: Cell::new(false),
236238
}
237239
}
238240
}

0 commit comments

Comments
 (0)