@@ -83,7 +83,7 @@ fn type_of_explicit_args(cx: @crate_ctxt, sp: span, inputs: [ty::arg]) ->
83
83
// - trans_args
84
84
fn type_of_fn( cx : @crate_ctxt , sp : span ,
85
85
is_method : bool , inputs : [ ty:: arg ] ,
86
- output : ty:: t , ty_param_count : uint )
86
+ output : ty:: t , params : [ ty :: param_bounds ] )
87
87
: non_ty_var ( cx , output ) -> TypeRef {
88
88
let atys: [ TypeRef ] = [ ] ;
89
89
@@ -100,8 +100,10 @@ fn type_of_fn(cx: @crate_ctxt, sp: span,
100
100
101
101
// Args >2: ty params, if not acquired via capture...
102
102
if !is_method {
103
- let i = 0 u;
104
- while i < ty_param_count { atys += [ T_ptr ( cx. tydesc_type ) ] ; i += 1 u; }
103
+ // FIXME[impl] Also add args for the dicts
104
+ for _param in params {
105
+ atys += [ T_ptr ( cx. tydesc_type ) ] ;
106
+ }
105
107
}
106
108
// ... then explicit args.
107
109
atys += type_of_explicit_args ( cx, sp, inputs) ;
@@ -110,15 +112,15 @@ fn type_of_fn(cx: @crate_ctxt, sp: span,
110
112
111
113
// Given a function type and a count of ty params, construct an llvm type
112
114
fn type_of_fn_from_ty( cx : @crate_ctxt , sp : span , fty : ty:: t ,
113
- ty_param_count : uint )
115
+ param_bounds : [ ty :: param_bounds ] )
114
116
: returns_non_ty_var ( cx , fty ) -> TypeRef {
115
117
// FIXME: Check should be unnecessary, b/c it's implied
116
118
// by returns_non_ty_var(t). Make that a postcondition
117
119
// (see Issue #586)
118
120
let ret_ty = ty:: ty_fn_ret ( cx. tcx , fty) ;
119
121
check non_ty_var( cx, ret_ty) ;
120
122
ret type_of_fn( cx, sp, false , ty:: ty_fn_args ( cx. tcx , fty) ,
121
- ret_ty, ty_param_count ) ;
123
+ ret_ty, param_bounds ) ;
122
124
}
123
125
124
126
fn type_of_inner ( cx : @crate_ctxt , sp : span , t : ty:: t )
@@ -171,10 +173,10 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
171
173
ty:: ty_fn ( _) {
172
174
// FIXME: could be a constraint on ty_fn
173
175
check returns_non_ty_var ( cx, t) ;
174
- T_fn_pair ( cx, type_of_fn_from_ty ( cx, sp, t, 0 u ) )
176
+ T_fn_pair ( cx, type_of_fn_from_ty ( cx, sp, t, [ ] ) )
175
177
}
176
178
ty:: ty_native_fn ( args, out) {
177
- let nft = native_fn_wrapper_type ( cx, sp, 0 u , t) ;
179
+ let nft = native_fn_wrapper_type ( cx, sp, [ ] , t) ;
178
180
T_fn_pair ( cx, nft)
179
181
}
180
182
ty:: ty_obj ( meths) { cx. rust_object_type }
@@ -234,7 +236,7 @@ fn type_of_ty_param_bounds_and_ty(lcx: @local_ctxt, sp: span,
234
236
alt ty:: struct ( cx. tcx , t) {
235
237
ty:: ty_fn ( _) | ty:: ty_native_fn ( _, _) {
236
238
check returns_non_ty_var ( cx, t) ;
237
- ret type_of_fn_from_ty ( cx, sp, t, vec :: len ( tpt. bounds ) ) ;
239
+ ret type_of_fn_from_ty ( cx, sp, t, tpt. bounds ) ;
238
240
}
239
241
_ {
240
242
// fall through
@@ -2562,7 +2564,8 @@ fn trans_do_while(cx: @block_ctxt, body: ast::blk, cond: @ast::expr) ->
2562
2564
type generic_info =
2563
2565
{ item_type : ty:: t ,
2564
2566
static_tis : [ option:: t < @tydesc_info > ] ,
2565
- tydescs : [ ValueRef ] } ;
2567
+ tydescs : [ ValueRef ] ,
2568
+ param_bounds : [ ty:: param_bounds ] } ;
2566
2569
2567
2570
tag lval_kind {
2568
2571
temporary; //< Temporary value passed by value if of immediate type
@@ -2608,18 +2611,19 @@ fn trans_external_path(cx: @block_ctxt, did: ast::def_id,
2608
2611
2609
2612
fn lval_static_fn ( bcx : @block_ctxt , fn_id : ast:: def_id , id : ast:: node_id )
2610
2613
-> lval_maybe_callee {
2611
- let tpt = ty:: lookup_item_type ( bcx_tcx ( bcx) , fn_id) ;
2614
+ let ccx = bcx_ccx ( bcx) ;
2615
+ let tpt = ty:: lookup_item_type ( ccx. tcx , fn_id) ;
2612
2616
let val = if fn_id. crate == ast:: local_crate {
2613
2617
// Internal reference.
2614
- assert ( bcx_ccx ( bcx ) . item_ids . contains_key ( fn_id. node ) ) ;
2615
- bcx_ccx ( bcx ) . item_ids . get ( fn_id. node )
2618
+ assert ( ccx . item_ids . contains_key ( fn_id. node ) ) ;
2619
+ ccx . item_ids . get ( fn_id. node )
2616
2620
} else {
2617
2621
// External reference.
2618
2622
trans_external_path ( bcx, fn_id, tpt)
2619
2623
} ;
2620
- let tys = ty:: node_id_to_type_params ( bcx_tcx ( bcx ) , id) ;
2624
+ let tys = ty:: node_id_to_type_params ( ccx . tcx , id) ;
2621
2625
let gen = none, bcx = bcx;
2622
- if vec:: len :: < ty :: t > ( tys) != 0 u {
2626
+ if vec:: len ( tys) != 0 u {
2623
2627
let tydescs = [ ] , tis = [ ] ;
2624
2628
for t in tys {
2625
2629
// TODO: Doesn't always escape.
@@ -2629,7 +2633,11 @@ fn lval_static_fn(bcx: @block_ctxt, fn_id: ast::def_id, id: ast::node_id)
2629
2633
bcx = td. bcx ;
2630
2634
tydescs += [ td. val ] ;
2631
2635
}
2632
- gen = some ( { item_type: tpt. ty , static_tis: tis, tydescs: tydescs} ) ;
2636
+ let bounds = ty:: lookup_item_type ( ccx. tcx , fn_id) . bounds ;
2637
+ gen = some ( { item_type: tpt. ty ,
2638
+ static_tis: tis,
2639
+ tydescs: tydescs,
2640
+ param_bounds: bounds} ) ;
2633
2641
}
2634
2642
ret { bcx : bcx, val : val, kind : owned, env : null_env, generic : gen} ;
2635
2643
}
@@ -2767,7 +2775,7 @@ fn trans_object_field_inner(bcx: @block_ctxt, o: ValueRef,
2767
2775
check non_ty_var( ccx, ret_ty) ;
2768
2776
2769
2777
let ll_fn_ty = type_of_fn ( ccx, bcx. sp , true ,
2770
- ty:: ty_fn_args ( tcx, fn_ty) , ret_ty, 0 u ) ;
2778
+ ty:: ty_fn_args ( tcx, fn_ty) , ret_ty, [ ] ) ;
2771
2779
v = Load ( bcx, PointerCast ( bcx, v, T_ptr ( T_ptr ( ll_fn_ty) ) ) ) ;
2772
2780
ret { bcx : bcx, mthptr : v, objptr : o} ;
2773
2781
}
@@ -5084,13 +5092,17 @@ fn register_fn(ccx: @crate_ctxt, sp: span, path: [str], flav: str,
5084
5092
register_fn_full ( ccx, sp, path, flav, ty_params, node_id, t) ;
5085
5093
}
5086
5094
5095
+ fn param_bounds ( ccx : @crate_ctxt , tp : ast:: ty_param ) -> ty:: param_bounds {
5096
+ ccx. tcx . ty_param_bounds . get ( ast_util:: local_def ( tp. id ) )
5097
+ }
5098
+
5087
5099
fn register_fn_full( ccx : @crate_ctxt , sp : span , path : [ str ] , _flav : str ,
5088
- ty_params : [ ast:: ty_param ] , node_id : ast:: node_id ,
5100
+ tps : [ ast:: ty_param ] , node_id : ast:: node_id ,
5089
5101
node_type : ty:: t )
5090
5102
: returns_non_ty_var ( ccx , node_type ) {
5091
5103
let path = path;
5092
- let llfty =
5093
- type_of_fn_from_ty ( ccx , sp , node_type , vec:: len ( ty_params ) ) ;
5104
+ let llfty = type_of_fn_from_ty ( ccx , sp , node_type ,
5105
+ vec:: map ( tps , { |p| param_bounds ( ccx , p ) } ) ) ;
5094
5106
let ps: str = mangle_exported_name ( ccx, path, node_type) ;
5095
5107
let llfn: ValueRef = decl_cdecl_fn ( ccx. llmod , ps, llfty) ;
5096
5108
ccx. item_ids . insert ( node_id, llfn) ;
@@ -5128,7 +5140,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
5128
5140
let nt = ty:: mk_nil ( ccx. tcx ) ;
5129
5141
check non_ty_var( ccx, nt) ;
5130
5142
5131
- let llfty = type_of_fn ( ccx, sp, false , [ vecarg_ty] , nt, 0 u ) ;
5143
+ let llfty = type_of_fn ( ccx, sp, false , [ vecarg_ty] , nt, [ ] ) ;
5132
5144
let llfdecl = decl_fn ( ccx. llmod , "_rust_main" ,
5133
5145
lib:: llvm:: LLVMCCallConv , llfty) ;
5134
5146
@@ -5221,12 +5233,13 @@ fn native_fn_ty_param_count(cx: @crate_ctxt, id: ast::node_id) -> uint {
5221
5233
ret count;
5222
5234
}
5223
5235
5224
- fn native_fn_wrapper_type ( cx : @crate_ctxt , sp : span , ty_param_count : uint ,
5236
+ fn native_fn_wrapper_type ( cx : @crate_ctxt , sp : span ,
5237
+ param_bounds : [ ty:: param_bounds ] ,
5225
5238
x : ty:: t ) -> TypeRef {
5226
5239
alt ty:: struct ( cx. tcx , x) {
5227
5240
ty:: ty_native_fn ( args, out) {
5228
5241
check non_ty_var ( cx, out) ;
5229
- ret type_of_fn ( cx, sp, false , args, out, ty_param_count ) ;
5242
+ ret type_of_fn ( cx, sp, false , args, out, param_bounds ) ;
5230
5243
}
5231
5244
}
5232
5245
}
@@ -5273,10 +5286,10 @@ fn collect_native_item(ccx: @crate_ctxt,
5273
5286
ast : : native_abi_rust_intrinsic. {
5274
5287
// For intrinsics: link the function directly to the intrinsic
5275
5288
// function itself.
5276
- let num_ty_param = vec:: len ( tps) ;
5277
5289
check returns_non_ty_var ( ccx, node_type) ;
5278
- let fn_type = type_of_fn_from_ty ( ccx, sp, node_type,
5279
- num_ty_param) ;
5290
+ let fn_type = type_of_fn_from_ty (
5291
+ ccx, sp, node_type,
5292
+ vec:: map ( tps, { |p| param_bounds ( ccx, p) } ) ) ;
5280
5293
let ri_name = "rust_intrinsic_" + link_name ( i) ;
5281
5294
let llnativefn = get_extern_fn (
5282
5295
ccx. externs , ccx. llmod , ri_name,
0 commit comments