@@ -244,10 +244,9 @@ fn type_of_ty_param_kinds_and_ty(lcx: @local_ctxt, sp: span,
244
244
let cx = lcx. ccx ;
245
245
let t = tpt. ty ;
246
246
alt ty:: struct ( cx. tcx , t) {
247
- ty:: ty_fn ( _, _, _, _, _) {
247
+ ty:: ty_fn ( _, _, _, _, _) | ty :: ty_native_fn ( _ , _ , _ ) {
248
248
check returns_non_ty_var ( cx, t) ;
249
- let llfnty = type_of_fn_from_ty ( cx, sp, t, std:: vec:: len ( tpt. kinds ) ) ;
250
- ret T_fn_pair ( * cx, llfnty) ;
249
+ ret type_of_fn_from_ty ( cx, sp, t, std:: vec:: len ( tpt. kinds ) ) ;
251
250
}
252
251
_ {
253
252
// fall through
@@ -328,10 +327,9 @@ fn decl_fastcall_fn(llmod: ModuleRef, name: str, llty: TypeRef) -> ValueRef {
328
327
// not valid to simply declare a function as internal.
329
328
fn decl_internal_fastcall_fn ( llmod : ModuleRef , name : str , llty : TypeRef ) ->
330
329
ValueRef {
331
- let llfn = decl_fn ( llmod, name, lib :: llvm :: LLVMFastCallConv , llty) ;
330
+ let llfn = decl_fastcall_fn ( llmod, name, llty) ;
332
331
llvm:: LLVMSetLinkage ( llfn,
333
332
lib:: llvm:: LLVMInternalLinkage as llvm:: Linkage ) ;
334
- let _: ( ) = str:: as_buf ( "rust" , { |buf| llvm:: LLVMSetGC ( llfn, buf) } ) ;
335
333
ret llfn;
336
334
}
337
335
@@ -1418,12 +1416,8 @@ fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: ast::def_id,
1418
1416
let val = GEP_tup_like ( cx, tup_ty, rs, [ 0 , 1 ] ) ;
1419
1417
cx = val. bcx ;
1420
1418
// Find and call the actual destructor.
1421
- let dtor_pair = trans_common:: get_res_dtor ( ccx, cx. sp , did, inner_t) ;
1422
- let dtor_addr =
1423
- Load ( cx, GEP ( cx, dtor_pair, [ C_int ( 0 ) , C_int ( abi:: fn_field_code) ] ) ) ;
1424
- let dtor_env =
1425
- Load ( cx, GEP ( cx, dtor_pair, [ C_int ( 0 ) , C_int ( abi:: fn_field_box) ] ) ) ;
1426
- let args = [ cx. fcx . llretptr , cx. fcx . lltaskptr , dtor_env] ;
1419
+ let dtor_addr = trans_common:: get_res_dtor ( ccx, cx. sp , did, inner_t) ;
1420
+ let args = [ cx. fcx . llretptr , cx. fcx . lltaskptr , null_env_ptr ( cx) ] ;
1427
1421
for tp: ty:: t in tps {
1428
1422
let ti: option:: t < @tydesc_info > = none;
1429
1423
let td = get_tydesc ( cx, tp, false , tps_normal, ti) . result ;
@@ -2842,6 +2836,10 @@ type lval_maybe_callee = {bcx: @block_ctxt,
2842
2836
env: callee_env,
2843
2837
generic: option:: t<generic_info>} ;
2844
2838
2839
+ fn null_env_ptr ( bcx : @block_ctxt ) -> ValueRef {
2840
+ C_null ( T_opaque_closure_ptr ( * bcx_ccx ( bcx) ) )
2841
+ }
2842
+
2845
2843
fn lval_mem ( bcx : @block_ctxt , val : ValueRef ) -> lval_result {
2846
2844
ret { bcx : bcx, val : val, is_mem : true } ;
2847
2845
}
@@ -2866,8 +2864,8 @@ fn lval_static_fn(bcx: @block_ctxt, tpt: ty::ty_param_kinds_and_ty,
2866
2864
fn_id : ast:: def_id , id : ast:: node_id ) -> lval_maybe_callee {
2867
2865
let val = if fn_id. crate == ast:: local_crate {
2868
2866
// Internal reference.
2869
- assert ( bcx_ccx ( bcx) . fn_pairs . contains_key ( fn_id. node ) ) ;
2870
- bcx_ccx ( bcx) . fn_pairs . get ( fn_id. node )
2867
+ assert ( bcx_ccx ( bcx) . item_ids . contains_key ( fn_id. node ) ) ;
2868
+ bcx_ccx ( bcx) . item_ids . get ( fn_id. node )
2871
2869
} else {
2872
2870
// External reference.
2873
2871
trans_external_path ( bcx, fn_id, tpt)
@@ -2886,7 +2884,7 @@ fn lval_static_fn(bcx: @block_ctxt, tpt: ty::ty_param_kinds_and_ty,
2886
2884
}
2887
2885
gen = some ( { item_type: tpt. ty , static_tis: tis, tydescs: tydescs} ) ;
2888
2886
}
2889
- ret { bcx : bcx, val : val, is_mem : true , env : is_closure , generic : gen} ;
2887
+ ret { bcx : bcx, val : val, is_mem : true , env : null_env , generic : gen} ;
2890
2888
}
2891
2889
2892
2890
fn lookup_discriminant ( lcx : @local_ctxt , vid : ast:: def_id ) -> ValueRef {
@@ -3176,7 +3174,7 @@ fn maybe_add_env(bcx: @block_ctxt, c: lval_maybe_callee)
3176
3174
( c. is_mem , c. val )
3177
3175
} else {
3178
3176
let env = alt c. env {
3179
- null_env. { C_null ( T_opaque_closure_ptr ( * bcx_ccx ( bcx) ) ) }
3177
+ null_env. { null_env_ptr ( bcx) }
3180
3178
some_env ( e) { e }
3181
3179
} ;
3182
3180
let llfnty = llvm:: LLVMGetElementType ( val_ty ( c. val ) ) ;
@@ -3353,8 +3351,7 @@ fn trans_bind_thunk(cx: @local_ctxt, sp: span, incoming_fty: ty::t,
3353
3351
// out the pointer to the target function from the environment. The
3354
3352
// target function lives in the first binding spot.
3355
3353
let ( lltargetfn, lltargetenv, starting_idx) = alt target_fn {
3356
- some( fptr) {
3357
- ( fptr, C_null ( T_opaque_closure_ptr ( * bcx_ccx ( bcx) ) ) , 0 )
3354
+ some( fptr) { ( fptr, null_env_ptr ( bcx) , 0 )
3358
3355
}
3359
3356
none. {
3360
3357
// Silly check
@@ -3747,7 +3744,7 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
3747
3744
let faddr = f_res. val ;
3748
3745
let llenv;
3749
3746
alt f_res. env {
3750
- null_env. { llenv = C_null ( T_opaque_closure_ptr ( * bcx_ccx ( cx ) ) ) ; }
3747
+ null_env. { llenv = null_env_ptr ( cx ) ; }
3751
3748
some_env ( e) { llenv = e; }
3752
3749
is_closure. {
3753
3750
// It's a closure. Have to fetch the elements
@@ -4054,7 +4051,8 @@ fn trans_expr_out(cx: @block_ctxt, e: @ast::expr, output: out_method) ->
4054
4051
alt fn_res {
4055
4052
some( fn_pair) { fn_pair }
4056
4053
none. {
4057
- { fn_pair: create_fn_pair ( ccx, s, llfnty, llfn, false ) ,
4054
+ { fn_pair: create_real_fn_pair ( cx, llfnty, llfn,
4055
+ null_env_ptr ( cx) ) ,
4058
4056
bcx: cx}
4059
4057
}
4060
4058
} ;
@@ -5488,17 +5486,17 @@ fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef {
5488
5486
ret struct_elt ( llpairty, 0 u) ;
5489
5487
}
5490
5488
5491
- fn decl_fn_and_pair ( ccx : @crate_ctxt , sp : span , path : [ str ] , flav : str ,
5492
- ty_params : [ ast:: ty_param ] , node_id : ast:: node_id ) {
5489
+ fn register_fn ( ccx : @crate_ctxt , sp : span , path : [ str ] , flav : str ,
5490
+ ty_params : [ ast:: ty_param ] , node_id : ast:: node_id ) {
5493
5491
// FIXME: pull this out
5494
5492
let t = node_id_type ( ccx, node_id) ;
5495
5493
check returns_non_ty_var ( ccx, t) ;
5496
- decl_fn_and_pair_full ( ccx, sp, path, flav, ty_params, node_id, t) ;
5494
+ register_fn_full ( ccx, sp, path, flav, ty_params, node_id, t) ;
5497
5495
}
5498
5496
5499
- fn decl_fn_and_pair_full ( ccx : @crate_ctxt , sp : span , path : [ str ] , _flav : str ,
5500
- ty_params : [ ast:: ty_param ] , node_id : ast:: node_id ,
5501
- node_type : ty:: t )
5497
+ fn register_fn_full ( ccx : @crate_ctxt , sp : span , path : [ str ] , _flav : str ,
5498
+ ty_params : [ ast:: ty_param ] , node_id : ast:: node_id ,
5499
+ node_type : ty:: t )
5502
5500
: returns_non_ty_var ( ccx , node_type ) {
5503
5501
let path = path;
5504
5502
let llfty =
@@ -5510,14 +5508,12 @@ fn decl_fn_and_pair_full(ccx: @crate_ctxt, sp: span, path: [str], _flav: str,
5510
5508
ast_util:: ret_by_ref ( rs) , inputs, output,
5511
5509
vec:: len ( ty_params) ) ;
5512
5510
}
5513
- _ { ccx. sess . bug ( "decl_fn_and_pair (): fn item doesn't have fn type!" ) ; }
5511
+ _ { ccx. sess . bug ( "register_fn (): fn item doesn't have fn type!" ) ; }
5514
5512
}
5515
- let s: str = mangle_internal_name_by_path ( ccx, path) ;
5516
- let llfn: ValueRef = decl_internal_fastcall_fn ( ccx. llmod , s, llfty) ;
5517
- // Declare the global constant pair that points to it.
5518
-
5519
5513
let ps: str = mangle_exported_name ( ccx, path, node_type) ;
5520
- register_fn_pair ( ccx, ps, llfty, llfn, node_id) ;
5514
+ let llfn: ValueRef = decl_fastcall_fn ( ccx. llmod , ps, llfty) ;
5515
+ ccx. item_ids . insert ( node_id, llfn) ;
5516
+ ccx. item_symbols . insert ( node_id, ps) ;
5521
5517
5522
5518
let is_main: bool = is_main_name ( path) && !ccx. sess . get_opts ( ) . library ;
5523
5519
if is_main { create_main_wrapper ( ccx, sp, llfn, node_type) ; }
@@ -5580,28 +5576,6 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
5580
5576
}
5581
5577
}
5582
5578
5583
-
5584
- // Create a closure: a pair containing (1) a ValueRef, pointing to where the
5585
- // fn's definition is in the executable we're creating, and (2) a pointer to
5586
- // space for the function's environment.
5587
- fn create_fn_pair ( cx : @crate_ctxt , ps : str , llfnty : TypeRef , llfn : ValueRef ,
5588
- external : bool ) -> ValueRef {
5589
- let gvar =
5590
- str:: as_buf ( ps,
5591
- { |buf|
5592
- llvm:: LLVMAddGlobal ( cx. llmod , T_fn_pair ( * cx, llfnty) ,
5593
- buf)
5594
- } ) ;
5595
- let pair = C_struct ( [ llfn, C_null ( T_opaque_closure_ptr ( * cx) ) ] ) ;
5596
- llvm:: LLVMSetInitializer ( gvar, pair) ;
5597
- llvm:: LLVMSetGlobalConstant ( gvar, True ) ;
5598
- if !external {
5599
- llvm:: LLVMSetLinkage ( gvar,
5600
- lib:: llvm:: LLVMInternalLinkage as llvm:: Linkage ) ;
5601
- }
5602
- ret gvar;
5603
- }
5604
-
5605
5579
// Create a /real/ closure: this is like create_fn_pair, but creates a
5606
5580
// a fn value on the stack with a specified environment (which need not be
5607
5581
// on the stack).
@@ -5619,26 +5593,14 @@ fn create_real_fn_pair(cx: @block_ctxt, llfnty: TypeRef, llfn: ValueRef,
5619
5593
ret pair;
5620
5594
}
5621
5595
5622
- fn register_fn_pair ( cx : @crate_ctxt , ps : str , llfnty : TypeRef , llfn : ValueRef ,
5623
- id : ast:: node_id ) {
5624
- // FIXME: We should also hide the unexported pairs in crates.
5625
-
5626
- let gvar =
5627
- create_fn_pair ( cx, ps, llfnty, llfn, cx. sess . get_opts ( ) . library ) ;
5628
- cx. item_ids . insert ( id, llfn) ;
5629
- cx. item_symbols . insert ( id, ps) ;
5630
- cx. fn_pairs . insert ( id, gvar) ;
5631
- }
5632
-
5633
-
5634
5596
// Returns the number of type parameters that the given native function has.
5635
5597
fn native_fn_ty_param_count ( cx : @crate_ctxt , id : ast:: node_id ) -> uint {
5636
5598
let count;
5637
5599
let native_item =
5638
5600
alt cx. ast_map . find ( id) { some ( ast_map:: node_native_item ( i) ) { i } } ;
5639
5601
alt native_item. node {
5640
5602
ast:: native_item_ty. {
5641
- cx . sess . bug ( "decl_native_fn_and_pair (): native fn isn't \
5603
+ cx . sess . bug ( "register_native_fn (): native fn isn't \
5642
5604
actually a fn") ;
5643
5605
}
5644
5606
ast:: native_item_fn ( _, _, tps) {
@@ -5659,23 +5621,20 @@ fn native_fn_wrapper_type(cx: @crate_ctxt, sp: span, ty_param_count: uint,
5659
5621
}
5660
5622
}
5661
5623
5662
- fn decl_native_fn_and_pair ( ccx : @crate_ctxt , sp : span , path : [ str ] , name : str ,
5624
+ fn register_native_fn ( ccx : @crate_ctxt , sp : span , path : [ str ] , name : str ,
5663
5625
id : ast:: node_id ) {
5664
5626
let path = path;
5665
5627
let num_ty_param = native_fn_ty_param_count ( ccx, id) ;
5666
5628
// Declare the wrapper.
5667
5629
5668
5630
let t = node_id_type ( ccx, id) ;
5669
5631
let wrapper_type = native_fn_wrapper_type ( ccx, sp, num_ty_param, t) ;
5670
- let s: str = mangle_internal_name_by_path ( ccx, path) ;
5671
- let wrapper_fn: ValueRef =
5672
- decl_internal_fastcall_fn ( ccx. llmod , s, wrapper_type) ;
5673
- // Declare the global constant pair that points to it.
5674
-
5675
5632
let ps: str = mangle_exported_name ( ccx, path, node_id_type ( ccx, id) ) ;
5676
- register_fn_pair ( ccx, ps, wrapper_type, wrapper_fn, id) ;
5677
- // Build the wrapper.
5633
+ let wrapper_fn = decl_fastcall_fn ( ccx. llmod , ps, wrapper_type) ;
5634
+ ccx. item_ids . insert ( id, wrapper_fn) ;
5635
+ ccx. item_symbols . insert ( id, ps) ;
5678
5636
5637
+ // Build the wrapper.
5679
5638
let fcx = new_fn_ctxt ( new_local_ctxt ( ccx) , sp, wrapper_fn) ;
5680
5639
let bcx = new_top_block_ctxt ( fcx) ;
5681
5640
let lltop = bcx. llbb ;
@@ -5858,7 +5817,7 @@ fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, pt: [str],
5858
5817
alt i. node {
5859
5818
ast:: native_item_fn ( _, _, _) {
5860
5819
if !ccx. obj_methods . contains_key ( i. id ) {
5861
- decl_native_fn_and_pair ( ccx, i. span , pt, i. ident , i. id ) ;
5820
+ register_native_fn ( ccx, i. span , pt, i. ident , i. id ) ;
5862
5821
}
5863
5822
}
5864
5823
_ { }
@@ -5892,25 +5851,25 @@ fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, pt: [str], v: vt<[str]>) {
5892
5851
alt i. node {
5893
5852
ast:: item_fn ( f, tps) {
5894
5853
if !ccx. obj_methods . contains_key ( i. id ) {
5895
- decl_fn_and_pair ( ccx, i. span , new_pt, "fn" , tps, i. id ) ;
5854
+ register_fn ( ccx, i. span , new_pt, "fn" , tps, i. id ) ;
5896
5855
}
5897
5856
}
5898
5857
ast:: item_obj ( ob, tps, ctor_id) {
5899
- decl_fn_and_pair ( ccx, i. span , new_pt, "obj_ctor" , tps, ctor_id) ;
5858
+ register_fn ( ccx, i. span , new_pt, "obj_ctor" , tps, ctor_id) ;
5900
5859
for m: @ast:: method in ob. methods {
5901
5860
ccx. obj_methods . insert ( m. node . id , ( ) ) ;
5902
5861
}
5903
5862
}
5904
5863
ast:: item_res ( _, dtor_id, tps, ctor_id) {
5905
- decl_fn_and_pair ( ccx, i. span , new_pt, "res_ctor" , tps, ctor_id) ;
5864
+ register_fn ( ccx, i. span , new_pt, "res_ctor" , tps, ctor_id) ;
5906
5865
// Note that the destructor is associated with the item's id, not
5907
5866
// the dtor_id. This is a bit counter-intuitive, but simplifies
5908
5867
// ty_res, which would have to carry around two def_ids otherwise
5909
5868
// -- one to identify the type, and one to find the dtor symbol.
5910
5869
let t = node_id_type ( ccx, dtor_id) ;
5911
5870
// FIXME: how to get rid of this check?
5912
5871
check returns_non_ty_var ( ccx, t) ;
5913
- decl_fn_and_pair_full ( ccx, i. span , new_pt, "res_dtor" , tps, i. id , t) ;
5872
+ register_fn_full ( ccx, i. span , new_pt, "res_dtor" , tps, i. id , t) ;
5914
5873
}
5915
5874
_ { }
5916
5875
}
@@ -5935,8 +5894,8 @@ fn collect_tag_ctor(ccx: @crate_ctxt, i: @ast::item, pt: [str],
5935
5894
ast:: item_tag ( variants, tps) {
5936
5895
for variant: ast:: variant in variants {
5937
5896
if std:: vec:: len ( variant. node . args ) != 0 u {
5938
- decl_fn_and_pair ( ccx, i. span , new_pt + [ variant. node . name ] ,
5939
- "tag" , tps, variant. node . id ) ;
5897
+ register_fn ( ccx, i. span , new_pt + [ variant. node . name ] ,
5898
+ "tag" , tps, variant. node . id ) ;
5940
5899
}
5941
5900
}
5942
5901
}
@@ -6209,7 +6168,6 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
6209
6168
tag_sizes: tag_sizes,
6210
6169
discrims: new_int_hash :: < ValueRef > ( ) ,
6211
6170
discrim_symbols: new_int_hash :: < str > ( ) ,
6212
- fn_pairs: new_int_hash :: < ValueRef > ( ) ,
6213
6171
consts: new_int_hash :: < ValueRef > ( ) ,
6214
6172
obj_methods: new_int_hash :: < ( ) > ( ) ,
6215
6173
tydescs: tydescs,
0 commit comments