@@ -865,7 +865,7 @@ fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id, substs: [ty::t])
865
865
maybe_instantiate_inline ( ccx, did)
866
866
} else { did } ;
867
867
assert did. crate == ast:: local_crate;
868
- option :: get ( monomorphic_fn ( ccx, did, substs, none) )
868
+ monomorphic_fn ( ccx, did, substs, none)
869
869
}
870
870
871
871
fn trans_res_drop ( bcx : block , rs : ValueRef , did : ast:: def_id ,
@@ -1951,8 +1951,7 @@ enum callee_env {
1951
1951
type lval_maybe_callee = { bcx : block ,
1952
1952
val: ValueRef ,
1953
1953
kind: lval_kind ,
1954
- env: callee_env ,
1955
- tds: option < [ ValueRef ] > } ;
1954
+ env: callee_env } ;
1956
1955
1957
1956
fn null_env_ptr ( bcx : block ) -> ValueRef {
1958
1957
C_null ( T_opaque_box_ptr ( bcx. ccx ( ) ) )
@@ -1971,20 +1970,21 @@ fn lval_temp(bcx: block, val: ValueRef) -> lval_result {
1971
1970
1972
1971
fn lval_no_env ( bcx : block , val : ValueRef , kind : lval_kind )
1973
1972
-> lval_maybe_callee {
1974
- ret { bcx : bcx, val : val, kind : kind, env : is_closure, tds : none } ;
1973
+ ret { bcx : bcx, val : val, kind : kind, env : is_closure} ;
1975
1974
}
1976
1975
1977
- fn trans_external_path ( cx : block , did : ast:: def_id ,
1978
- tpt : ty:: ty_param_bounds_and_ty ) -> ValueRef {
1979
- let ccx = cx. fcx . ccx ;
1976
+ fn trans_external_path ( ccx : @crate_ctxt , did : ast:: def_id , t : ty:: t )
1977
+ -> ValueRef {
1980
1978
let name = csearch:: get_symbol ( ccx. sess . cstore , did) ;
1981
- ret get_extern_const ( ccx. externs , ccx. llmod , name,
1982
- type_of_ty_param_bounds_and_ty ( ccx, tpt) ) ;
1979
+ let llty = alt ty:: get ( t) . struct {
1980
+ ty:: ty_fn ( _) { type_of_fn_from_ty ( ccx, t) }
1981
+ _ { type_of( ccx, t) }
1982
+ } ;
1983
+ ret get_extern_const ( ccx. externs , ccx. llmod , name, llty) ;
1983
1984
}
1984
1985
1985
1986
fn monomorphic_fn ( ccx : @crate_ctxt , fn_id : ast:: def_id , substs : [ ty:: t ] ,
1986
- vtables : option < typeck:: vtable_res > )
1987
- -> option < ValueRef > {
1987
+ vtables : option < typeck:: vtable_res > ) -> ValueRef {
1988
1988
let substs = vec:: map ( substs, { |t|
1989
1989
alt ty:: get ( t) . struct {
1990
1990
ty:: ty_box ( mt) { ty:: mk_opaque_box ( ccx. tcx ) }
@@ -1996,7 +1996,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
1996
1996
none { no_vts }
1997
1997
} } ;
1998
1998
alt ccx. monomorphized . find ( hash_id) {
1999
- some ( val) { ret some ( val) ; }
1999
+ some ( val) { ret val; }
2000
2000
none { }
2001
2001
}
2002
2002
@@ -2017,8 +2017,10 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
2017
2017
}
2018
2018
ast_map:: node_variant ( v, _, pt) { ( pt, v. node . name ) }
2019
2019
ast_map:: node_method ( m, _, pt) { ( pt, m. ident ) }
2020
- // We can't monomorphize native functions
2021
- ast_map:: node_native_item ( _, _, _) { ret none; }
2020
+ ast_map:: node_native_item ( _, _, _) {
2021
+ // Natives don't have to be monomorphized.
2022
+ ret get_item_val ( ccx, fn_id. node ) ;
2023
+ }
2022
2024
ast_map:: node_ctor ( i) {
2023
2025
alt check ccx. tcx . items . get ( i. id ) {
2024
2026
ast_map:: node_item ( i, pt) { ( pt, i. ident ) }
@@ -2027,7 +2029,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
2027
2029
_ { fail "unexpected node type" ; }
2028
2030
} ;
2029
2031
let mono_ty = ty:: substitute_type_params ( ccx. tcx , substs, item_ty) ;
2030
- let llfty = type_of_fn_from_ty ( ccx, mono_ty, 0 u ) ;
2032
+ let llfty = type_of_fn_from_ty ( ccx, mono_ty) ;
2031
2033
2032
2034
let pt = * pt + [ path_name ( ccx. names ( name) ) ] ;
2033
2035
let s = mangle_exported_name ( ccx, pt, mono_ty) ;
@@ -2071,7 +2073,7 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id, substs: [ty::t],
2071
2073
}
2072
2074
}
2073
2075
}
2074
- some ( lldecl)
2076
+ lldecl
2075
2077
}
2076
2078
2077
2079
fn maybe_instantiate_inline( ccx: @crate_ctxt, fn_id: ast:: def_id)
@@ -2142,39 +2144,18 @@ fn lval_static_fn(bcx: block, fn_id: ast::def_id, id: ast::node_id,
2142
2144
maybe_instantiate_inline ( ccx, fn_id)
2143
2145
} else { fn_id } ;
2144
2146
2145
- // The awkwardness below mostly stems from the fact that we're mixing
2146
- // monomorphized and non-monomorphized functions at the moment. If
2147
- // monomorphizing becomes the only approach, this'll be much simpler.
2148
2147
if fn_id. crate == ast:: local_crate {
2149
- let mono = alt substs {
2150
- some( ( stys, vtables) ) {
2151
- if stys. len ( ) > 0 u {
2152
- monomorphic_fn ( ccx, fn_id, stys, some ( vtables) )
2153
- } else { none }
2154
- }
2155
- none {
2156
- alt ccx. maps . vtable_map . find ( id) {
2157
- some ( vtables) {
2158
- let rvtables = impl:: resolve_vtables_in_fn_ctxt (
2159
- bcx. fcx , vtables) ;
2160
- monomorphic_fn ( ccx, fn_id, tys, some ( rvtables) )
2161
- }
2162
- none {
2163
- if tys. len ( ) == 0 u { none }
2164
- else { monomorphic_fn ( ccx, fn_id, tys, none) }
2165
- }
2166
- }
2167
- }
2148
+ let ( tys, vtables) = alt substs {
2149
+ some( ( tys, vts) ) { ( tys, some ( vts) ) }
2150
+ none { ( tys, option:: map ( ccx. maps . vtable_map . find ( id) , { |vts|
2151
+ impl:: resolve_vtables_in_fn_ctxt ( bcx. fcx , vts) } ) ) }
2168
2152
} ;
2169
- alt mono {
2170
- some ( llfn ) {
2171
- let cast = PointerCast ( bcx, llfn , T_ptr ( type_of_fn_from_ty (
2172
- ccx, node_id_type ( bcx, id) , 0 u ) ) ) ;
2153
+ if tys . len ( ) > 0 u {
2154
+ let val = monomorphic_fn ( ccx , fn_id , tys , vtables ) ;
2155
+ let cast = PointerCast ( bcx, val , T_ptr ( type_of_fn_from_ty (
2156
+ ccx, node_id_type ( bcx, id) ) ) ) ;
2173
2157
ret { bcx : bcx, val : cast,
2174
- kind : owned, env : null_env,
2175
- tds : none} ;
2176
- }
2177
- none { }
2158
+ kind : owned, env : null_env} ;
2178
2159
}
2179
2160
}
2180
2161
@@ -2183,8 +2164,14 @@ fn lval_static_fn(bcx: block, fn_id: ast::def_id, id: ast::node_id,
2183
2164
get_item_val ( ccx, fn_id. node )
2184
2165
} else {
2185
2166
// External reference.
2186
- trans_external_path ( bcx , fn_id, tpt)
2167
+ trans_external_path ( ccx , fn_id, tpt. ty )
2187
2168
} ;
2169
+ if tys. len ( ) > 0 u {
2170
+ // This is supposed to be an external native function.
2171
+ // Unfortunately, I found no easy/cheap way to assert that.
2172
+ val = PointerCast ( bcx, val, T_ptr ( type_of_fn_from_ty (
2173
+ ccx, node_id_type ( bcx, id) ) ) ) ;
2174
+ }
2188
2175
2189
2176
// FIXME: Need to support external crust functions
2190
2177
if fn_id. crate == ast:: local_crate {
@@ -2198,22 +2185,7 @@ fn lval_static_fn(bcx: block, fn_id: ast::def_id, id: ast::node_id,
2198
2185
}
2199
2186
}
2200
2187
2201
- let tds = none, bcx = bcx;
2202
- // FIXME[mono] ensure this is a native function
2203
- if tys. len ( ) > 0 u {
2204
- val = PointerCast ( bcx, val, T_ptr ( type_of_fn_from_ty (
2205
- ccx, node_id_type ( bcx, id) , tys. len ( ) ) ) ) ;
2206
- let tydescs = [ ] ;
2207
- for t in tys {
2208
- let ti = none;
2209
- let td = get_tydesc ( bcx, t, ti) ;
2210
- lazily_emit_all_tydesc_glue ( ccx, ti) ;
2211
- bcx = td. bcx ;
2212
- tydescs += [ td. val ] ;
2213
- }
2214
- tds = some ( tydescs) ;
2215
- }
2216
- ret { bcx : bcx, val : val, kind : owned, env : null_env, tds : tds} ;
2188
+ ret { bcx : bcx, val : val, kind : owned, env : null_env} ;
2217
2189
}
2218
2190
2219
2191
fn lookup_discriminant ( ccx : @crate_ctxt , vid : ast:: def_id ) -> ValueRef {
@@ -2313,7 +2285,7 @@ fn trans_var(cx: block, def: ast::def, id: ast::node_id, path: @ast::path)
2313
2285
ret lval_no_env ( cx, get_item_val ( ccx, did. node ) , owned) ;
2314
2286
} else {
2315
2287
let tp = node_id_type ( cx, id) ;
2316
- let val = trans_external_path ( cx , did, { bounds : @ [ ] , ty : tp } ) ;
2288
+ let val = trans_external_path ( ccx , did, tp ) ;
2317
2289
ret lval_no_env ( cx, load_if_immediate ( cx, val, tp) , owned_imm) ;
2318
2290
}
2319
2291
}
@@ -2466,8 +2438,7 @@ fn trans_lval(cx: block, e: @ast::expr) -> lval_result {
2466
2438
}
2467
2439
2468
2440
fn lval_maybe_callee_to_lval ( c : lval_maybe_callee , ty : ty:: t ) -> lval_result {
2469
- let must_bind = option:: is_some ( c. tds ) ||
2470
- alt c. env { self_env ( _, _) { true } _ { false } } ;
2441
+ let must_bind = alt c. env { self_env ( _, _) { true } _ { false } } ;
2471
2442
if must_bind {
2472
2443
let n_args = ty:: ty_fn_args ( ty) . len ( ) ;
2473
2444
let args = vec:: from_elem ( n_args, none) ;
@@ -2662,12 +2633,10 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr,
2662
2633
// - create_llargs_for_fn_args.
2663
2634
// - new_fn_ctxt
2664
2635
// - trans_args
2665
- fn trans_args ( cx : block , llenv : ValueRef ,
2666
- tds : option < [ ValueRef ] > , es : [ @ast:: expr ] , fn_ty : ty:: t ,
2667
- dest : dest )
2668
- -> { bcx : block,
2669
- args : [ ValueRef ] ,
2670
- retslot : ValueRef } {
2636
+ fn trans_args ( cx : block , llenv : ValueRef , es : [ @ast:: expr ] , fn_ty : ty:: t ,
2637
+ dest : dest ) -> { bcx : block,
2638
+ args : [ ValueRef ] ,
2639
+ retslot : ValueRef } {
2671
2640
2672
2641
let temp_cleanups = [ ] ;
2673
2642
let args = ty:: ty_fn_args ( fn_ty) ;
@@ -2701,12 +2670,6 @@ fn trans_args(cx: block, llenv: ValueRef,
2701
2670
// Arg 1: Env (closure-bindings / self value)
2702
2671
llargs += [ llenv] ;
2703
2672
2704
- // Args >2: ty_params ...
2705
- alt tds {
2706
- some( tds) { llargs += tds; }
2707
- none { }
2708
- }
2709
-
2710
2673
// ... then explicit args.
2711
2674
2712
2675
// First we figure out the caller's view of the types of the arguments.
@@ -2770,8 +2733,7 @@ fn trans_call_inner(in_cx: block, fn_expr_ty: ty::t,
2770
2733
} ;
2771
2734
2772
2735
let ret_ty = node_id_type ( bcx, id) ;
2773
- let args_res =
2774
- trans_args ( bcx, llenv, f_res. tds , args, fn_expr_ty, dest) ;
2736
+ let args_res = trans_args ( bcx, llenv, args, fn_expr_ty, dest) ;
2775
2737
bcx = args_res. bcx ;
2776
2738
let llargs = args_res. args ;
2777
2739
let llretslot = args_res. retslot ;
@@ -3883,7 +3845,7 @@ fn create_llargs_for_fn_args(cx: fn_ctxt,
3883
3845
args : [ ast:: arg ] ,
3884
3846
tps_bounds : [ ty:: param_bounds ] ) {
3885
3847
// Skip the implicit arguments 0, and 1.
3886
- let arg_n = first_tp_arg ;
3848
+ let arg_n = first_real_arg ;
3887
3849
alt ty_self {
3888
3850
impl_self( tt) {
3889
3851
cx. llself = some ( { v: cx. llenv , t: tt} ) ;
@@ -4417,11 +4379,9 @@ fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef {
4417
4379
}
4418
4380
4419
4381
fn register_fn ( ccx : @crate_ctxt , sp : span , path : path , flav : str ,
4420
- ty_params : [ ast:: ty_param ] , node_id : ast:: node_id )
4421
- -> ValueRef {
4382
+ node_id : ast:: node_id ) -> ValueRef {
4422
4383
let t = ty:: node_id_to_type ( ccx. tcx , node_id) ;
4423
- let bnds = param_bounds ( ccx, ty_params) ;
4424
- register_fn_full ( ccx, sp, path, flav, bnds, node_id, t)
4384
+ register_fn_full ( ccx, sp, path, flav, node_id, t)
4425
4385
}
4426
4386
4427
4387
fn param_bounds ( ccx : @crate_ctxt , tps : [ ast:: ty_param ] )
@@ -4430,9 +4390,8 @@ fn param_bounds(ccx: @crate_ctxt, tps: [ast::ty_param])
4430
4390
}
4431
4391
4432
4392
fn register_fn_full ( ccx : @crate_ctxt , sp : span , path : path , flav : str ,
4433
- bnds : [ ty:: param_bounds ] , node_id : ast:: node_id ,
4434
- node_type : ty:: t ) -> ValueRef {
4435
- let llfty = type_of_fn_from_ty ( ccx, node_type, bnds. len ( ) ) ;
4393
+ node_id : ast:: node_id , node_type : ty:: t ) -> ValueRef {
4394
+ let llfty = type_of_fn_from_ty ( ccx, node_type) ;
4436
4395
register_fn_fuller ( ccx, sp, path, flav, node_id, node_type,
4437
4396
lib:: llvm:: CCallConv , llfty)
4438
4397
}
@@ -4479,7 +4438,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
4479
4438
{ mode: ast:: expl ( ast:: by_val) ,
4480
4439
ty: ty:: mk_vec ( ccx. tcx , { ty: unit_ty, mutbl: ast:: m_imm} ) } ;
4481
4440
let nt = ty:: mk_nil ( ccx. tcx ) ;
4482
- let llfty = type_of_fn ( ccx, [ vecarg_ty] , nt, 0 u ) ;
4441
+ let llfty = type_of_fn ( ccx, [ vecarg_ty] , nt) ;
4483
4442
let llfdecl = decl_fn ( ccx. llmod , "_rust_main" ,
4484
4443
lib:: llvm:: CCallConv , llfty) ;
4485
4444
@@ -4575,34 +4534,32 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
4575
4534
ccx. item_symbols . insert ( i. id , s) ;
4576
4535
g
4577
4536
}
4578
- ast:: item_fn ( decl, tps , _) {
4537
+ ast:: item_fn ( decl, _ , _) {
4579
4538
let llfn = if decl. purity != ast:: crust_fn {
4580
- register_fn ( ccx, i. span , my_path, "fn" , tps , i. id )
4539
+ register_fn ( ccx, i. span , my_path, "fn" , i. id )
4581
4540
} else {
4582
4541
native:: register_crust_fn ( ccx, i. span , my_path, i. id )
4583
4542
} ;
4584
4543
set_inline_hint_if_appr ( i. attrs , llfn) ;
4585
4544
llfn
4586
4545
}
4587
- ast:: item_res ( _, tps , _, dtor_id, _) {
4546
+ ast:: item_res ( _, _ , _, dtor_id, _) {
4588
4547
// Note that the destructor is associated with the item's id,
4589
4548
// not the dtor_id. This is a bit counter-intuitive, but
4590
4549
// simplifies ty_res, which would have to carry around two
4591
4550
// def_ids otherwise -- one to identify the type, and one to
4592
4551
// find the dtor symbol.
4593
4552
let t = ty:: node_id_to_type ( ccx. tcx , dtor_id) ;
4594
4553
register_fn_full ( ccx, i. span , my_path + [ path_name ( "dtor" ) ] ,
4595
- "res_dtor" , param_bounds ( ccx , tps ) , i. id , t)
4554
+ "res_dtor" , i. id , t)
4596
4555
}
4597
4556
}
4598
4557
}
4599
4558
ast_map:: node_method ( m, impl_id, pth) {
4600
4559
let mty = ty:: node_id_to_type ( ccx. tcx , id) ;
4601
- let impl_tps = * ty:: lookup_item_type ( ccx. tcx , impl_id) . bounds ;
4602
4560
let pth = * pth + [ path_name ( int:: str ( impl_id. node ) ) ,
4603
4561
path_name ( m. ident ) ] ;
4604
4562
let llfn = register_fn_full ( ccx, m. span , pth, "impl_method" ,
4605
- impl_tps + param_bounds ( ccx, m. tps ) ,
4606
4563
id, mty) ;
4607
4564
set_inline_hint_if_appr ( m. attrs , llfn) ;
4608
4565
llfn
@@ -4612,24 +4569,24 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
4612
4569
}
4613
4570
ast_map:: node_ctor ( i) {
4614
4571
alt check i. node {
4615
- ast:: item_res ( _, tps , _, _, _) {
4572
+ ast:: item_res ( _, _ , _, _, _) {
4616
4573
let my_path = item_path ( ccx, i) ;
4617
4574
let llctor = register_fn ( ccx, i. span , my_path, "res_ctor" ,
4618
- tps , id) ;
4575
+ id) ;
4619
4576
set_inline_hint ( llctor) ;
4620
4577
llctor
4621
4578
}
4622
- ast:: item_class ( tps , _, ctor) {
4623
- register_fn ( ccx, i. span , item_path ( ccx, i) , "ctor" , tps , id)
4579
+ ast:: item_class ( _ , _, ctor) {
4580
+ register_fn ( ccx, i. span , item_path ( ccx, i) , "ctor" , id)
4624
4581
}
4625
4582
}
4626
4583
}
4627
4584
ast_map:: node_variant ( v, enm, pth) {
4628
4585
assert v. node . args . len ( ) != 0 u;
4629
4586
let pth = * pth + [ path_name ( enm. ident ) , path_name ( v. node . name ) ] ;
4630
4587
let llfn = alt check enm. node {
4631
- ast:: item_enum ( _, tps ) {
4632
- register_fn ( ccx, v. span , pth, "enum" , tps , id)
4588
+ ast:: item_enum ( _, _ ) {
4589
+ register_fn ( ccx, v. span , pth, "enum" , id)
4633
4590
}
4634
4591
} ;
4635
4592
set_inline_hint ( llfn) ;
0 commit comments