@@ -1902,7 +1902,7 @@ fn trans_unary(bcx: @block_ctxt, op: ast::unop, e: @ast::expr,
1902
1902
alt bcx_ccx ( bcx) . method_map . find ( un_expr. id ) {
1903
1903
some ( origin) {
1904
1904
let callee_id = ast_util:: op_expr_callee_id ( un_expr) ;
1905
- let fty = ty :: node_id_to_type ( bcx_tcx ( bcx) , callee_id) ;
1905
+ let fty = node_id_type ( bcx, callee_id) ;
1906
1906
ret trans_call_inner ( bcx, fty, { |bcx|
1907
1907
impl:: trans_method_callee ( bcx, callee_id, e, origin)
1908
1908
} , [ ] , un_expr. id , dest) ;
@@ -2036,7 +2036,6 @@ fn trans_eager_binop(cx: @block_ctxt, op: ast::binop, lhs: ValueRef,
2036
2036
2037
2037
fn trans_assign_op ( bcx : @block_ctxt , ex : @ast:: expr , op : ast:: binop ,
2038
2038
dst : @ast:: expr , src : @ast:: expr ) -> @block_ctxt {
2039
- let tcx = bcx_tcx ( bcx) ;
2040
2039
let t = expr_ty ( bcx, src) ;
2041
2040
let lhs_res = trans_lval ( bcx, dst) ;
2042
2041
assert ( lhs_res. kind == owned) ;
@@ -2045,7 +2044,7 @@ fn trans_assign_op(bcx: @block_ctxt, ex: @ast::expr, op: ast::binop,
2045
2044
alt bcx_ccx( bcx) . method_map . find ( ex. id ) {
2046
2045
some ( origin) {
2047
2046
let callee_id = ast_util:: op_expr_callee_id ( ex) ;
2048
- let fty = ty :: node_id_to_type ( tcx , callee_id) ;
2047
+ let fty = node_id_type ( bcx , callee_id) ;
2049
2048
ret trans_call_inner ( bcx, fty, { |bcx|
2050
2049
// FIXME provide the already-computed address, not the expr
2051
2050
impl:: trans_method_callee ( bcx, callee_id, dst, origin)
@@ -2169,7 +2168,7 @@ fn trans_binary(bcx: @block_ctxt, op: ast::binop, lhs: @ast::expr,
2169
2168
alt bcx_ccx ( bcx) . method_map . find ( ex. id ) {
2170
2169
some ( origin) {
2171
2170
let callee_id = ast_util:: op_expr_callee_id ( ex) ;
2172
- let fty = ty :: node_id_to_type ( bcx_tcx ( bcx) , callee_id) ;
2171
+ let fty = node_id_type ( bcx, callee_id) ;
2173
2172
ret trans_call_inner ( bcx, fty, { |bcx|
2174
2173
impl:: trans_method_callee ( bcx, callee_id, lhs, origin)
2175
2174
} , [ rhs] , ex. id , dest) ;
@@ -2452,59 +2451,58 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
2452
2451
let tpt = ty:: lookup_item_type ( ccx. tcx , fn_id) ;
2453
2452
let mono_ty = ty:: substitute_type_params ( ccx. tcx , substs, tpt. ty ) ;
2454
2453
let llfty = type_of_fn_from_ty ( ccx, mono_ty, [ ] ) ;
2455
- let lldecl;
2454
+
2455
+ let map_node = ccx. tcx . items . get ( fn_id. node ) ;
2456
+ // Get the path so that we can create a symbol
2457
+ let ( pt, name) = alt map_node {
2458
+ ast_map : : node_item ( i, pt) { ( pt, i. ident ) }
2459
+ ast_map:: node_variant ( v, _, pt) { ( pt, v. node . name ) }
2460
+ ast_map:: node_method ( m, _, pt) { ( pt, m. ident ) }
2461
+ // We can't monomorphize native functions
2462
+ ast_map:: node_native_item ( _, _) { ret none; }
2463
+ _ { fail "Unexpected node type" ; }
2464
+ } ;
2465
+ let pt = * pt + [ path_name ( ccx. names ( name) ) ] ;
2466
+ let s = mangle_exported_name ( ccx, pt, mono_ty) ;
2467
+ let lldecl = decl_cdecl_fn ( ccx. llmod , s, llfty) ;
2468
+ ccx. monomorphized . insert ( hash_id, { llfn: lldecl, fty: mono_ty} ) ;
2469
+
2456
2470
let psubsts = some ( { tys: substs, dicts: dicts, bounds: tpt. bounds } ) ;
2457
- alt ccx. tcx . items . get ( fn_id. node ) {
2458
- ast_map:: node_item ( item, pt) {
2459
- let pt = * pt + [ path_name ( item. ident ) ] ;
2460
- let s = mangle_exported_name ( ccx, pt, mono_ty) ;
2461
- lldecl = decl_cdecl_fn ( ccx. llmod , s, llfty) ;
2462
- alt item. node {
2463
- ast:: item_fn ( decl, _, body) {
2464
- trans_fn ( ccx, pt, decl, body, lldecl, no_self, [ ] ,
2465
- psubsts, fn_id. node ) ;
2466
- }
2467
- ast:: item_res ( decl, _, _, _, ctor_id) {
2468
- trans_res_ctor ( ccx, pt, decl, ctor_id, [ ] , psubsts, lldecl) ;
2469
- }
2470
- _ { fail "Unexpected item type" ; }
2471
- }
2471
+ alt map_node {
2472
+ ast_map : : node_item( @{ node: ast:: item_fn ( decl, _, body) , _} , _) {
2473
+ trans_fn ( ccx, pt, decl, body, lldecl, no_self, [ ] ,
2474
+ psubsts, fn_id. node ) ;
2475
+ }
2476
+ ast_map:: node_item ( @{ node: ast:: item_res ( decl, _, _, _, _) , _} , _) {
2477
+ trans_res_ctor ( ccx, pt, decl, fn_id. node , [ ] , psubsts, lldecl) ;
2472
2478
}
2473
- ast_map:: node_variant ( v, enum_id, pt) {
2474
- let pt = * pt + [ path_name ( v. node . name ) ] ;
2475
- let s = mangle_exported_name ( ccx, pt, mono_ty) ;
2476
- lldecl = decl_cdecl_fn ( ccx. llmod , s, llfty) ;
2479
+ ast_map:: node_variant ( v, enum_id, _) {
2477
2480
let tvs = ty:: enum_variants ( ccx. tcx , enum_id) ;
2478
2481
let this_tv = option:: get ( vec:: find ( * tvs, { |tv|
2479
2482
tv. id . node == fn_id. node } ) ) ;
2480
2483
trans_enum_variant ( ccx, enum_id. node , v, this_tv. disr_val ,
2481
2484
vec:: len ( * tvs) == 1 u, [ ] , psubsts, lldecl) ;
2482
2485
}
2483
- ast_map:: node_method ( mth, impl_id, pt) {
2484
- let pt = * pt + [ path_name ( mth. ident ) ] ;
2485
- let s = mangle_exported_name ( ccx, pt, mono_ty) ;
2486
- lldecl = decl_cdecl_fn ( ccx. llmod , s, llfty) ;
2486
+ ast_map:: node_method ( mth, impl_id, _) {
2487
2487
let selfty = ty:: node_id_to_type ( ccx. tcx , impl_id) ;
2488
2488
let selfty = ty:: substitute_type_params ( ccx. tcx , substs, selfty) ;
2489
2489
trans_fn ( ccx, pt, mth. decl , mth. body , lldecl,
2490
2490
impl_self ( selfty) , [ ] , psubsts, fn_id. node ) ;
2491
2491
}
2492
- ast_map:: node_native_item ( _, _) {
2493
- ret none;
2494
- }
2495
- _ { fail "Unexpected node type" ; }
2492
+ _ { fail; }
2496
2493
}
2497
- let val = { llfn: lldecl, fty: mono_ty} ;
2498
- ccx. monomorphized . insert ( hash_id, val) ;
2499
- some ( val)
2494
+ some ( { llfn: lldecl, fty: mono_ty} )
2500
2495
}
2501
2496
2502
2497
fn lval_static_fn ( bcx : @block_ctxt , fn_id : ast:: def_id , id : ast:: node_id ,
2503
2498
substs : option < ( [ ty:: t ] , typeck:: dict_res ) > )
2504
2499
-> lval_maybe_callee {
2505
2500
let ccx = bcx_ccx ( bcx) ;
2506
- let tys = ty :: node_id_to_type_params ( ccx . tcx , id) ;
2501
+ let tys = node_id_type_params ( bcx , id) ;
2507
2502
let tpt = ty:: lookup_item_type ( ccx. tcx , fn_id) ;
2503
+ // The awkwardness below mostly stems from the fact that we're mixing
2504
+ // monomorphized and non-monomorphized functions at the moment. If
2505
+ // monomorphizing becomes the only approach, this'll be much simpler.
2508
2506
if ccx. sess . opts . monomorphize &&
2509
2507
( option:: is_some ( substs) || vec:: len ( tys) > 0 u) &&
2510
2508
fn_id. crate == ast:: local_crate &&
@@ -2634,7 +2632,7 @@ fn trans_var(cx: @block_ctxt, def: ast::def, id: ast::node_id)
2634
2632
ret lval_static_fn ( cx, vid, id, none) ;
2635
2633
} else {
2636
2634
// Nullary variant.
2637
- let enum_ty = ty :: node_id_to_type ( ccx . tcx , id) ;
2635
+ let enum_ty = node_id_type ( cx , id) ;
2638
2636
let alloc_result = alloc_ty ( cx, enum_ty) ;
2639
2637
let llenumblob = alloc_result. val ;
2640
2638
let llenumty = type_of_enum ( ccx, tid, enum_ty) ;
@@ -2652,7 +2650,7 @@ fn trans_var(cx: @block_ctxt, def: ast::def, id: ast::node_id)
2652
2650
assert ( ccx. consts . contains_key ( did. node ) ) ;
2653
2651
ret lval_no_env ( cx, ccx. consts . get ( did. node ) , owned) ;
2654
2652
} else {
2655
- let tp = ty :: node_id_to_type ( ccx . tcx , id) ;
2653
+ let tp = node_id_type ( cx , id) ;
2656
2654
let val = trans_external_path ( cx, did, { bounds: @[ ] , ty: tp} ) ;
2657
2655
ret lval_no_env ( cx, load_if_immediate ( cx, val, tp) , owned_imm) ;
2658
2656
}
@@ -3129,8 +3127,6 @@ fn trans_call_inner(in_cx: @block_ctxt, fn_expr_ty: ty::t,
3129
3127
// NB: 'f' isn't necessarily a function; it might be an entire self-call
3130
3128
// expression because of the hack that allows us to process self-calls
3131
3129
// with trans_call.
3132
- let tcx = bcx_tcx ( in_cx) ;
3133
-
3134
3130
let cx = new_scope_block_ctxt ( in_cx, "call" ) ;
3135
3131
Br ( in_cx, cx. llbb ) ;
3136
3132
let f_res = get_callee ( cx) ;
@@ -3157,7 +3153,7 @@ fn trans_call_inner(in_cx: @block_ctxt, fn_expr_ty: ty::t,
3157
3153
}
3158
3154
}
3159
3155
3160
- let ret_ty = ty :: node_id_to_type ( tcx , id) ;
3156
+ let ret_ty = node_id_type ( bcx , id) ;
3161
3157
let args_res =
3162
3158
trans_args ( bcx, llenv, f_res. generic , args, fn_expr_ty, dest) ;
3163
3159
bcx = args_res. bcx ;
@@ -3520,7 +3516,7 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
3520
3516
// If it is here, it's not an lval, so this is a user-defined index op
3521
3517
let origin = bcx_ccx ( bcx) . method_map . get ( e. id ) ;
3522
3518
let callee_id = ast_util:: op_expr_callee_id ( e) ;
3523
- let fty = ty :: node_id_to_type ( tcx , callee_id) ;
3519
+ let fty = node_id_type ( bcx , callee_id) ;
3524
3520
ret trans_call_inner ( bcx, fty, { |bcx|
3525
3521
impl:: trans_method_callee ( bcx, callee_id, base, origin)
3526
3522
} , [ idx] , e. id , dest) ;
0 commit comments