@@ -2304,14 +2304,14 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, real_substs: [ty::t],
2304
2304
}
2305
2305
}
2306
2306
ast_map:: node_dtor( _, dtor, _, pt) {
2307
- let parent_id = alt ty:: ty_to_def_id ( ty:: node_id_to_type ( ccx. tcx ,
2308
- dtor. node . self_id ) ) {
2309
- some ( did) { did }
2310
- none { ccx. sess . span_bug ( dtor. span , "Bad self ty in \
2307
+ let parent_id = alt ty:: ty_to_def_id ( ty:: node_id_to_type ( ccx. tcx ,
2308
+ dtor. node . self_id ) ) {
2309
+ some ( did) { did }
2310
+ none { ccx. sess . span_bug ( dtor. span , "Bad self ty in \
2311
2311
dtor") ; }
2312
- } ;
2313
- trans_class_dtor ( ccx, * pt, dtor. node . body ,
2314
- dtor. node . id , psubsts, some ( hash_id) , parent_id)
2312
+ } ;
2313
+ trans_class_dtor ( ccx, * pt, dtor. node . body ,
2314
+ dtor. node . id , psubsts, some ( hash_id) , parent_id)
2315
2315
}
2316
2316
// Ugh -- but this ensures any new variants won't be forgotten
2317
2317
ast_map:: node_expr( * ) { ccx. tcx . sess . bug ( "Can't monomorphize an expr" ) }
@@ -4930,15 +4930,15 @@ fn trans_class_ctor(ccx: @crate_ctxt, path: path, decl: ast::fn_decl,
4930
4930
}
4931
4931
4932
4932
fn trans_class_dtor ( ccx : @crate_ctxt , path : path ,
4933
- body : ast:: blk ,
4934
- dtor_id : ast :: node_id , substs : option < param_substs > ,
4935
- hash_id : option < mono_id > , parent_id : ast:: def_id )
4933
+ body : ast:: blk , dtor_id : ast :: node_id ,
4934
+ psubsts : option < param_substs > ,
4935
+ hash_id : option < mono_id > , parent_id : ast:: def_id )
4936
4936
-> ValueRef {
4937
4937
let tcx = ccx. tcx ;
4938
4938
/* Look up the parent class's def_id */
4939
4939
let mut class_ty = ty:: lookup_item_type ( tcx, parent_id) . ty ;
4940
4940
/* Substitute in the class type if necessary */
4941
- option:: iter ( substs ) { |ss|
4941
+ option:: iter ( psubsts ) { |ss|
4942
4942
class_ty = ty:: subst_tps ( tcx, ss. tys , class_ty) ;
4943
4943
}
4944
4944
@@ -4947,7 +4947,9 @@ fn trans_class_dtor(ccx: @crate_ctxt, path: path,
4947
4947
let lldty = T_fn ( [ T_ptr ( type_of ( ccx, ty:: mk_nil ( tcx) ) ) ,
4948
4948
T_ptr ( type_of ( ccx, class_ty) ) ] ,
4949
4949
llvm:: LLVMVoidType ( ) ) ;
4950
- let s = get_dtor_symbol ( ccx, path, dtor_id) ;
4950
+
4951
+ let s = get_dtor_symbol ( ccx, path, dtor_id, psubsts) ;
4952
+
4951
4953
/* Register the dtor as a function. It has external linkage */
4952
4954
let lldecl = decl_internal_cdecl_fn ( ccx. llmod , s, lldty) ;
4953
4955
lib:: llvm:: SetLinkage ( lldecl, lib:: llvm:: ExternalLinkage ) ;
@@ -4959,7 +4961,7 @@ fn trans_class_dtor(ccx: @crate_ctxt, path: path,
4959
4961
}
4960
4962
/* Translate the dtor body */
4961
4963
trans_fn ( ccx, path, ast_util:: dtor_dec ( ) ,
4962
- body, lldecl, impl_self ( class_ty) , substs , dtor_id) ;
4964
+ body, lldecl, impl_self ( class_ty) , psubsts , dtor_id) ;
4963
4965
lldecl
4964
4966
}
4965
4967
@@ -5196,16 +5198,34 @@ fn item_path(ccx: @crate_ctxt, i: @ast::item) -> path {
5196
5198
} + [ path_name ( i. ident ) ]
5197
5199
}
5198
5200
5199
- /* If there's already a symbol for the dtor with <id>, return it;
5200
- otherwise, create one and register it, returning it as well */
5201
- fn get_dtor_symbol ( ccx : @crate_ctxt , path : path , id : ast:: node_id ) -> str {
5201
+ /* If there's already a symbol for the dtor with <id> and substs <substs>,
5202
+ return it; otherwise, create one and register it, returning it as well */
5203
+ fn get_dtor_symbol ( ccx : @crate_ctxt , path : path , id : ast:: node_id ,
5204
+ substs : option < param_substs > ) -> str {
5205
+ let t = ty:: node_id_to_type ( ccx. tcx , id) ;
5202
5206
alt ccx. item_symbols . find ( id) {
5203
5207
some ( s) { s }
5208
+ none if is_none ( substs) {
5209
+ let s = mangle_exported_name ( ccx,
5210
+ path + [ path_name ( @ccx. names ( "dtor" ) ) ] ,
5211
+ t) ;
5212
+ ccx. item_symbols . insert ( id, s) ;
5213
+ s
5214
+ }
5204
5215
none {
5205
- let s = mangle_exported_name ( ccx, path +
5206
- [ path_name ( @ccx. names ( "dtor" ) ) ] , ty:: node_id_to_type ( ccx. tcx , id) ) ;
5207
- ccx. item_symbols . insert ( id, s) ;
5208
- s
5216
+ // Monomorphizing, so just make a symbol, don't add
5217
+ // this to item_symbols
5218
+ alt substs {
5219
+ some( ss) {
5220
+ let mono_ty = ty:: subst_tps ( ccx. tcx , ss. tys , t) ;
5221
+ mangle_exported_name ( ccx, path +
5222
+ [ path_name ( @ccx. names ( "dtor" ) ) ] , mono_ty)
5223
+ }
5224
+ none {
5225
+ ccx. sess . bug ( #fmt ( "get_dtor_symbol: not monomorphizing and \
5226
+ couldn't find a symbol for dtor %?", path) ) ;
5227
+ }
5228
+ }
5209
5229
}
5210
5230
}
5211
5231
}
@@ -5289,7 +5309,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
5289
5309
let lldty = T_fn ( [ T_ptr ( type_of ( ccx, ty:: mk_nil ( tcx) ) ) ,
5290
5310
T_ptr ( type_of ( ccx, class_ty) ) ] ,
5291
5311
llvm:: LLVMVoidType ( ) ) ;
5292
- let s = get_dtor_symbol ( ccx, * pt, dt. node . id ) ;
5312
+ let s = get_dtor_symbol ( ccx, * pt, dt. node . id , none ) ;
5293
5313
5294
5314
/* Make the declaration for the dtor */
5295
5315
let llfn = decl_internal_cdecl_fn ( ccx. llmod , s, lldty) ;
0 commit comments