@@ -2252,7 +2252,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
2252
2252
dtor") ; }
2253
2253
} ;
2254
2254
trans_class_dtor ( ccx, * pt, dtor. node . body ,
2255
- dtor. node . id , psubsts, some ( hash_id) , parent_id, s )
2255
+ dtor. node . id , psubsts, some ( hash_id) , parent_id)
2256
2256
}
2257
2257
// Ugh -- but this ensures any new variants won't be forgotten
2258
2258
ast_map:: node_expr( * ) { ccx. tcx . sess . bug ( "Can't monomorphize an expr" ) }
@@ -4887,9 +4887,8 @@ fn trans_class_ctor(ccx: @crate_ctxt, path: path, decl: ast::fn_decl,
4887
4887
fn trans_class_dtor ( ccx : @crate_ctxt , path : path ,
4888
4888
body : ast:: blk ,
4889
4889
dtor_id : ast:: node_id , substs : option < param_substs > ,
4890
- hash_id : option < mono_id > , parent_id : ast:: def_id ,
4891
- // mangled exported name for dtor
4892
- s : str ) -> ValueRef {
4890
+ hash_id : option < mono_id > , parent_id : ast:: def_id )
4891
+ -> ValueRef {
4893
4892
let tcx = ccx. tcx ;
4894
4893
/* Look up the parent class's def_id */
4895
4894
let mut class_ty = ty:: lookup_item_type ( tcx, parent_id) . ty ;
@@ -4903,6 +4902,7 @@ fn trans_class_dtor(ccx: @crate_ctxt, path: path,
4903
4902
let lldty = T_fn ( [ T_ptr ( type_of ( ccx, ty:: mk_nil ( tcx) ) ) ,
4904
4903
T_ptr ( type_of ( ccx, class_ty) ) ] ,
4905
4904
llvm:: LLVMVoidType ( ) ) ;
4905
+ let s = get_dtor_symbol ( ccx, path, dtor_id) ;
4906
4906
/* Register the dtor as a function. It has external linkage */
4907
4907
let lldecl = decl_internal_cdecl_fn ( ccx. llmod , s, lldty) ;
4908
4908
lib:: llvm:: SetLinkage ( lldecl, lib:: llvm:: ExternalLinkage ) ;
@@ -4912,9 +4912,7 @@ fn trans_class_dtor(ccx: @crate_ctxt, path: path,
4912
4912
option:: iter ( hash_id) { |h_id|
4913
4913
ccx. monomorphized . insert ( h_id, lldecl) ;
4914
4914
}
4915
- /* Register the symbol for the dtor, and generate the code for its
4916
- body */
4917
- ccx. item_symbols . insert ( dtor_id, s) ;
4915
+ /* Translate the dtor body */
4918
4916
trans_fn ( ccx, path, ast_util:: dtor_dec ( ) ,
4919
4917
body, lldecl, impl_self ( class_ty) , substs, dtor_id) ;
4920
4918
lldecl
@@ -4997,11 +4995,8 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
4997
4995
get_item_val ( ccx, ctor. node . id ) , psubsts,
4998
4996
ctor. node . id , local_def ( item. id ) , ctor. span ) ;
4999
4997
option:: iter ( m_dtor) { |dtor|
5000
- let s = mangle_exported_name ( ccx, * path +
5001
- [ path_name ( ccx. names ( "dtor" ) ) ] ,
5002
- ty:: node_id_to_type ( ccx. tcx , dtor. node . id ) ) ;
5003
4998
trans_class_dtor ( ccx, * path, dtor. node . body ,
5004
- dtor. node . id , none, none, local_def ( item. id ) , s ) ;
4999
+ dtor. node . id , none, none, local_def ( item. id ) ) ;
5005
5000
} ;
5006
5001
}
5007
5002
// If there are ty params, the ctor will get monomorphized
@@ -5162,8 +5157,21 @@ fn item_path(ccx: @crate_ctxt, i: @ast::item) -> path {
5162
5157
} + [ path_name ( i. ident ) ]
5163
5158
}
5164
5159
5160
+ /* If there's already a symbol for the dtor with <id>, return it;
5161
+ otherwise, create one and register it, returning it as well */
5162
+ fn get_dtor_symbol ( ccx : @crate_ctxt , path : path , id : ast:: node_id ) -> str {
5163
+ alt ccx. item_symbols . find ( id) {
5164
+ some ( s) { s }
5165
+ none {
5166
+ let s = mangle_exported_name ( ccx, path +
5167
+ [ path_name ( ccx. names ( "dtor" ) ) ] , ty:: node_id_to_type ( ccx. tcx , id) ) ;
5168
+ ccx. item_symbols . insert ( id, s) ;
5169
+ s
5170
+ }
5171
+ }
5172
+ }
5173
+
5165
5174
fn get_item_val ( ccx : @crate_ctxt , id : ast:: node_id ) -> ValueRef {
5166
- #debug ( "get_item_val: %d" , id) ;
5167
5175
let tcx = ccx. tcx ;
5168
5176
alt ccx. item_vals . find ( id) {
5169
5177
some ( v) { v }
@@ -5242,11 +5250,8 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
5242
5250
let lldty = T_fn ( [ T_ptr ( type_of ( ccx, ty:: mk_nil ( tcx) ) ) ,
5243
5251
T_ptr ( type_of ( ccx, class_ty) ) ] ,
5244
5252
llvm:: LLVMVoidType ( ) ) ;
5245
- /* The symbol for the dtor should have already been registered */
5246
- let s: str = alt ccx. item_symbols . find ( id) {
5247
- some ( s) { s }
5248
- none { ccx. sess . bug ( "in get_item_val, dtor is unbound" ) ; }
5249
- } ;
5253
+ let s = get_dtor_symbol ( ccx, * pt, dt. node . id ) ;
5254
+
5250
5255
/* Make the declaration for the dtor */
5251
5256
let llfn = decl_internal_cdecl_fn ( ccx. llmod , s, lldty) ;
5252
5257
lib:: llvm:: SetLinkage ( llfn, lib:: llvm:: ExternalLinkage ) ;
0 commit comments