@@ -2450,10 +2450,12 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
2450
2450
some ( val) { ret some ( val) ; }
2451
2451
none { }
2452
2452
}
2453
+
2453
2454
let tpt = ty:: lookup_item_type ( ccx. tcx , fn_id) ;
2454
2455
let mono_ty = ty:: substitute_type_params ( ccx. tcx , substs, tpt. ty ) ;
2455
2456
let llfty = type_of_fn_from_ty ( ccx, mono_ty, [ ] ) ;
2456
2457
let lldecl;
2458
+ let psubsts = some ( { tys: substs, dicts: dicts, bounds: tpt. bounds } ) ;
2457
2459
alt ccx. tcx . items . get ( fn_id. node ) {
2458
2460
ast_map:: node_item ( item, pt) {
2459
2461
let pt = * pt + [ path_name ( item. ident ) ] ;
@@ -2462,10 +2464,10 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
2462
2464
alt item. node {
2463
2465
ast:: item_fn ( decl, _, body) {
2464
2466
trans_fn ( ccx, pt, decl, body, lldecl, no_self, [ ] ,
2465
- some ( substs ) , fn_id. node ) ;
2467
+ psubsts , fn_id. node ) ;
2466
2468
}
2467
2469
ast:: item_res ( decl, _, _, _, ctor_id) {
2468
- trans_res_ctor ( ccx, pt, decl, ctor_id, [ ] , some ( substs ) , lldecl) ;
2470
+ trans_res_ctor ( ccx, pt, decl, ctor_id, [ ] , psubsts , lldecl) ;
2469
2471
}
2470
2472
_ { fail "Unexpected item type" ; }
2471
2473
}
@@ -2478,7 +2480,16 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
2478
2480
let this_tv = option:: get ( vec:: find ( * tvs, { |tv|
2479
2481
tv. id . node == fn_id. node } ) ) ;
2480
2482
trans_enum_variant ( ccx, enum_id. node , v, this_tv. disr_val ,
2481
- vec:: len ( * tvs) == 1 u, [ ] , some ( substs) , lldecl) ;
2483
+ vec:: len ( * tvs) == 1 u, [ ] , psubsts, lldecl) ;
2484
+ }
2485
+ ast_map:: node_method ( mth, impl_id, pt) {
2486
+ let pt = * pt + [ path_name ( mth. ident ) ] ;
2487
+ let s = mangle_exported_name ( ccx, pt, mono_ty) ;
2488
+ lldecl = decl_cdecl_fn ( ccx. llmod , s, llfty) ;
2489
+ let selfty = ty:: node_id_to_type ( ccx. tcx , impl_id) ;
2490
+ let selfty = ty:: substitute_type_params ( ccx. tcx , substs, selfty) ;
2491
+ trans_fn ( ccx, pt, mth. decl , mth. body , lldecl,
2492
+ impl_self ( selfty) , [ ] , psubsts, fn_id. node ) ;
2482
2493
}
2483
2494
ast_map:: node_native_item ( _, _) {
2484
2495
ret none;
@@ -2490,19 +2501,35 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
2490
2501
some ( val)
2491
2502
}
2492
2503
2493
- fn lval_static_fn ( bcx : @block_ctxt , fn_id : ast:: def_id , id : ast:: node_id )
2504
+ fn lval_static_fn ( bcx : @block_ctxt , fn_id : ast:: def_id , id : ast:: node_id ,
2505
+ substs : option < ( [ ty:: t ] , typeck:: dict_res ) > )
2494
2506
-> lval_maybe_callee {
2495
2507
let ccx = bcx_ccx ( bcx) ;
2496
2508
let tys = ty:: node_id_to_type_params ( ccx. tcx , id) ;
2497
2509
let tpt = ty:: lookup_item_type ( ccx. tcx , fn_id) ;
2498
- if ccx. sess . opts . monomorphize && vec:: len ( tys) > 0 u &&
2510
+ if ccx. sess . opts . monomorphize &&
2511
+ ( option:: is_some ( substs) || vec:: len ( tys) > 0 u) &&
2499
2512
fn_id. crate == ast:: local_crate &&
2500
- !vec:: any ( tys, { |t| ty:: type_has_params ( t) } ) &&
2501
- vec:: all ( * tpt. bounds , { |bs| vec:: all ( * bs, { |b|
2502
- alt b { ty : : bound_iface ( _) { false } _ { true } }
2503
- } ) } ) {
2504
- let dicts = ccx. dict_map . find ( id) ;
2505
- alt monomorphic_fn ( ccx, fn_id, tys, dicts) {
2513
+ !vec:: any ( tys, { |t| ty:: type_has_params ( t) } ) {
2514
+ let mono = alt substs {
2515
+ some( ( stys, dicts) ) {
2516
+ if ( vec:: len ( stys) + vec:: len ( stys) ) > 0 u {
2517
+ monomorphic_fn ( ccx, fn_id, stys + tys, some ( dicts) )
2518
+ } else { none }
2519
+ }
2520
+ none {
2521
+ alt ccx. dict_map . find ( id) {
2522
+ some ( dicts) {
2523
+ alt impl:: resolve_dicts_in_fn_ctxt ( bcx. fcx , dicts) {
2524
+ some ( dicts) { monomorphic_fn ( ccx, fn_id, tys, some ( dicts) ) }
2525
+ none { none }
2526
+ }
2527
+ }
2528
+ none { monomorphic_fn( ccx, fn_id, tys, none) }
2529
+ }
2530
+ }
2531
+ } ;
2532
+ alt mono {
2506
2533
some( { llfn, fty} ) {
2507
2534
ret { bcx : bcx, val : llfn,
2508
2535
kind : owned, env : null_env,
@@ -2601,12 +2628,12 @@ fn trans_var(cx: @block_ctxt, def: ast::def, id: ast::node_id)
2601
2628
let ccx = bcx_ccx ( cx) ;
2602
2629
alt def {
2603
2630
ast : : def_fn ( did, _) {
2604
- ret lval_static_fn ( cx, did, id) ;
2631
+ ret lval_static_fn ( cx, did, id, none ) ;
2605
2632
}
2606
2633
ast:: def_variant ( tid, vid) {
2607
2634
if vec:: len ( ty:: enum_variant_with_id ( ccx. tcx , tid, vid) . args ) > 0 u {
2608
2635
// N-ary variant.
2609
- ret lval_static_fn ( cx, vid, id) ;
2636
+ ret lval_static_fn ( cx, vid, id, none ) ;
2610
2637
} else {
2611
2638
// Nullary variant.
2612
2639
let enum_ty = ty:: node_id_to_type ( ccx. tcx , id) ;
@@ -4259,7 +4286,7 @@ fn mk_standard_basic_blocks(llfn: ValueRef) ->
4259
4286
// - trans_args
4260
4287
fn new_fn_ctxt_w_id ( ccx : @crate_ctxt , path : path ,
4261
4288
llfndecl : ValueRef , id : ast:: node_id ,
4262
- param_substs : option < [ ty :: t ] > ,
4289
+ param_substs : option < param_substs > ,
4263
4290
sp : option < span > ) -> @fn_ctxt {
4264
4291
let llbbs = mk_standard_basic_blocks ( llfndecl) ;
4265
4292
ret @{ llfn : llfndecl,
@@ -4405,7 +4432,7 @@ enum self_arg { impl_self(ty::t), no_self, }
4405
4432
fn trans_closure ( ccx : @crate_ctxt , path : path , decl : ast:: fn_decl ,
4406
4433
body : ast:: blk , llfndecl : ValueRef ,
4407
4434
ty_self : self_arg , ty_params : [ ast:: ty_param ] ,
4408
- param_substs : option < [ ty :: t ] > ,
4435
+ param_substs : option < param_substs > ,
4409
4436
id : ast:: node_id , maybe_load_env : fn ( @fn_ctxt ) ) {
4410
4437
set_uwtable ( llfndecl) ;
4411
4438
@@ -4421,14 +4448,6 @@ fn trans_closure(ccx: @crate_ctxt, path: path, decl: ast::fn_decl,
4421
4448
let block_ty = node_id_type ( bcx, body. node . id ) ;
4422
4449
4423
4450
let arg_tys = ty:: ty_fn_args ( node_id_type ( bcx, id) ) ;
4424
- alt param_substs {
4425
- some( ts) {
4426
- arg_tys = vec:: map ( arg_tys, { |a|
4427
- { mode: a. mode ,
4428
- ty: ty:: substitute_type_params ( fcx. ccx . tcx , ts, a. ty ) } } )
4429
- }
4430
- _ { }
4431
- }
4432
4451
bcx = copy_args_to_allocas ( fcx, bcx, decl. inputs , arg_tys) ;
4433
4452
4434
4453
maybe_load_env ( fcx) ;
@@ -4454,7 +4473,7 @@ fn trans_closure(ccx: @crate_ctxt, path: path, decl: ast::fn_decl,
4454
4473
// function.
4455
4474
fn trans_fn ( ccx : @crate_ctxt , path : path , decl : ast:: fn_decl ,
4456
4475
body : ast:: blk , llfndecl : ValueRef , ty_self : self_arg ,
4457
- ty_params : [ ast:: ty_param ] , param_substs : option < [ ty :: t ] > ,
4476
+ ty_params : [ ast:: ty_param ] , param_substs : option < param_substs > ,
4458
4477
id : ast:: node_id ) {
4459
4478
let do_time = ccx. sess . opts . stats ;
4460
4479
let start = if do_time { time:: get_time ( ) }
@@ -4473,7 +4492,7 @@ fn trans_fn(ccx: @crate_ctxt, path: path, decl: ast::fn_decl,
4473
4492
4474
4493
fn trans_res_ctor ( ccx : @crate_ctxt , path : path , dtor : ast:: fn_decl ,
4475
4494
ctor_id : ast:: node_id , ty_params : [ ast:: ty_param ] ,
4476
- param_substs : option < [ ty :: t ] > , llfndecl : ValueRef ) {
4495
+ param_substs : option < param_substs > , llfndecl : ValueRef ) {
4477
4496
// Create a function for the constructor
4478
4497
let fcx = new_fn_ctxt_w_id ( ccx, path, llfndecl, ctor_id,
4479
4498
param_substs, none) ;
@@ -4505,11 +4524,11 @@ fn trans_res_ctor(ccx: @crate_ctxt, path: path, dtor: ast::fn_decl,
4505
4524
}
4506
4525
4507
4526
4508
- fn trans_enum_variant ( ccx : @crate_ctxt ,
4509
- enum_id : ast:: node_id ,
4527
+ fn trans_enum_variant ( ccx : @crate_ctxt , enum_id : ast:: node_id ,
4510
4528
variant : ast:: variant , disr : int , is_degen : bool ,
4511
4529
ty_params : [ ast:: ty_param ] ,
4512
- param_substs : option < [ ty:: t ] > , llfndecl : ValueRef ) {
4530
+ param_substs : option < param_substs > ,
4531
+ llfndecl : ValueRef ) {
4513
4532
// Translate variant arguments to function arguments.
4514
4533
let fn_args = [ ] , i = 0 u;
4515
4534
for varg in variant. node . args {
@@ -4522,7 +4541,7 @@ fn trans_enum_variant(ccx: @crate_ctxt,
4522
4541
param_substs, none) ;
4523
4542
create_llargs_for_fn_args ( fcx, no_self, fn_args, ty_params) ;
4524
4543
let ty_param_substs = alt param_substs {
4525
- some( ts ) { ts }
4544
+ some( substs ) { substs . tys }
4526
4545
none {
4527
4546
let i = 0 u;
4528
4547
vec:: map ( ty_params, { |tp|
0 commit comments