@@ -203,28 +203,28 @@ pub fn decl_internal_cdecl_fn(llmod: ModuleRef, name: &str, ty: Type) -> ValueRe
203
203
return llfn;
204
204
}
205
205
206
- pub fn get_extern_fn ( externs : & mut ExternMap , llmod : ModuleRef , name : & str ,
206
+ pub fn get_extern_fn ( externs : & mut ExternMap , llmod : ModuleRef , name : @ str ,
207
207
cc : lib:: llvm:: CallConv , ty : Type ) -> ValueRef {
208
- match externs. find_equiv ( & name) {
209
- Some ( n) => return * n,
208
+ match externs. find_copy ( & name) {
209
+ Some ( n) => return n,
210
210
None => ( )
211
211
}
212
212
let f = decl_fn ( llmod, name, cc, ty) ;
213
- externs. insert ( name. to_owned ( ) , f) ;
213
+ externs. insert ( name, f) ;
214
214
return f;
215
215
}
216
216
217
217
pub fn get_extern_const ( externs : & mut ExternMap , llmod : ModuleRef ,
218
- name : & str , ty : Type ) -> ValueRef {
219
- match externs. find_equiv ( & name) {
220
- Some ( n) => return * n,
218
+ name : @ str , ty : Type ) -> ValueRef {
219
+ match externs. find_copy ( & name) {
220
+ Some ( n) => return n,
221
221
None => ( )
222
222
}
223
223
unsafe {
224
224
let c = do name. with_c_str |buf| {
225
225
llvm:: LLVMAddGlobal ( llmod, ty. to_ref ( ) , buf)
226
226
} ;
227
- externs. insert ( name. to_owned ( ) , c) ;
227
+ externs. insert ( name, c) ;
228
228
return c;
229
229
}
230
230
}
@@ -511,6 +511,7 @@ pub fn get_res_dtor(ccx: @mut CrateContext,
511
511
None ,
512
512
ty:: lookup_item_type ( tcx, parent_id) . ty ) ;
513
513
let llty = type_of_dtor ( ccx, class_ty) ;
514
+ let name = name. to_managed ( ) ; // :-(
514
515
get_extern_fn ( & mut ccx. externs ,
515
516
ccx. llmod ,
516
517
name,
@@ -797,13 +798,13 @@ pub fn fail_if_zero(cx: @mut Block, span: span, divrem: ast::binop,
797
798
}
798
799
}
799
800
800
- pub fn null_env_ptr(ccx: &CrateContext ) -> ValueRef {
801
- C_null(Type::opaque_box(ccx).ptr_to())
801
+ pub fn null_env_ptr(bcx: @mut Block ) -> ValueRef {
802
+ C_null(Type::opaque_box(bcx. ccx() ).ptr_to())
802
803
}
803
804
804
805
pub fn trans_external_path(ccx: &mut CrateContext, did: ast::def_id, t: ty::t)
805
806
-> ValueRef {
806
- let name = csearch::get_symbol(ccx.sess.cstore, did);
807
+ let name = csearch::get_symbol(ccx.sess.cstore, did).to_managed(); // Sad
807
808
match ty::get(t).sty {
808
809
ty::ty_bare_fn(_) | ty::ty_closure(_) => {
809
810
let llty = type_of_fn_from_ty(ccx, t);
@@ -1571,7 +1572,7 @@ pub fn mk_return_basic_block(llfn: ValueRef) -> BasicBlockRef {
1571
1572
// slot where the return value of the function must go.
1572
1573
pub fn make_return_pointer(fcx: @mut FunctionContext, output_type: ty::t) -> ValueRef {
1573
1574
unsafe {
1574
- if type_of::return_uses_outptr (fcx.ccx.tcx, output_type) {
1575
+ if !ty::type_is_immediate (fcx.ccx.tcx, output_type) {
1575
1576
llvm::LLVMGetParam(fcx.llfn, 0)
1576
1577
} else {
1577
1578
let lloutputtype = type_of::type_of(fcx.ccx, output_type);
@@ -1611,7 +1612,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
1611
1612
ty:: subst_tps ( ccx. tcx , substs. tys , substs. self_ty , output_type)
1612
1613
}
1613
1614
} ;
1614
- let uses_outptr = type_of :: return_uses_outptr ( ccx. tcx , substd_output_type) ;
1615
+ let is_immediate = ty :: type_is_immediate ( ccx. tcx , substd_output_type) ;
1615
1616
let fcx = @mut FunctionContext {
1616
1617
llfn : llfndecl,
1617
1618
llenv : unsafe {
@@ -1623,7 +1624,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
1623
1624
llreturn : None ,
1624
1625
llself : None ,
1625
1626
personality : None ,
1626
- caller_expects_out_pointer : uses_outptr ,
1627
+ has_immediate_return_value : is_immediate ,
1627
1628
llargs : @mut HashMap :: new ( ) ,
1628
1629
lllocals : @mut HashMap :: new ( ) ,
1629
1630
llupvars : @mut HashMap :: new ( ) ,
@@ -1646,15 +1647,8 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
1646
1647
fcx. alloca_insert_pt = Some ( llvm:: LLVMGetFirstInstruction ( entry_bcx. llbb ) ) ;
1647
1648
}
1648
1649
1649
- if !ty:: type_is_voidish ( substd_output_type) {
1650
- // If the function returns nil/bot, there is no real return
1651
- // value, so do not set `llretptr`.
1652
- if !skip_retptr || uses_outptr {
1653
- // Otherwise, we normally allocate the llretptr, unless we
1654
- // have been instructed to skip it for immediate return
1655
- // values.
1656
- fcx. llretptr = Some ( make_return_pointer ( fcx, substd_output_type) ) ;
1657
- }
1650
+ if !ty:: type_is_nil ( substd_output_type) && !( is_immediate && skip_retptr) {
1651
+ fcx. llretptr = Some ( make_return_pointer ( fcx, substd_output_type) ) ;
1658
1652
}
1659
1653
fcx
1660
1654
}
@@ -1802,7 +1796,7 @@ pub fn finish_fn(fcx: @mut FunctionContext, last_bcx: @mut Block) {
1802
1796
// Builds the return block for a function.
1803
1797
pub fn build_return_block ( fcx : & FunctionContext , ret_cx : @mut Block ) {
1804
1798
// Return the value if this function immediate; otherwise, return void.
1805
- if fcx. llretptr . is_none ( ) || fcx. caller_expects_out_pointer {
1799
+ if fcx. llretptr . is_none ( ) || ! fcx. has_immediate_return_value {
1806
1800
return RetVoid ( ret_cx) ;
1807
1801
}
1808
1802
@@ -1888,7 +1882,9 @@ pub fn trans_closure(ccx: @mut CrateContext,
1888
1882
// translation calls that don't have a return value (trans_crate,
1889
1883
// trans_mod, trans_item, et cetera) and those that do
1890
1884
// (trans_block, trans_expr, et cetera).
1891
- if body. expr . is_none ( ) || ty:: type_is_voidish ( block_ty) {
1885
+ if body. expr . is_none ( ) || ty:: type_is_bot ( block_ty) ||
1886
+ ty:: type_is_nil ( block_ty)
1887
+ {
1892
1888
bcx = controlflow:: trans_block ( bcx, body, expr:: Ignore ) ;
1893
1889
} else {
1894
1890
let dest = expr:: SaveIn ( fcx. llretptr . unwrap ( ) ) ;
@@ -2133,14 +2129,13 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
2133
2129
ast:: item_fn( ref decl, purity, _abis, ref generics, ref body) => {
2134
2130
if purity == ast:: extern_fn {
2135
2131
let llfndecl = get_item_val ( ccx, item. id ) ;
2136
- foreign:: trans_rust_fn_with_foreign_abi (
2137
- ccx,
2138
- & vec:: append ( ( * path) . clone ( ) ,
2139
- [ path_name ( item. ident ) ] ) ,
2140
- decl,
2141
- body,
2142
- llfndecl,
2143
- item. id ) ;
2132
+ foreign:: trans_foreign_fn ( ccx,
2133
+ vec:: append ( ( * path) . clone ( ) ,
2134
+ [ path_name ( item. ident ) ] ) ,
2135
+ decl,
2136
+ body,
2137
+ llfndecl,
2138
+ item. id ) ;
2144
2139
} else if !generics. is_type_parameterized ( ) {
2145
2140
let llfndecl = get_item_val ( ccx, item. id ) ;
2146
2141
trans_fn ( ccx,
@@ -2201,7 +2196,7 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
2201
2196
}
2202
2197
} ,
2203
2198
ast:: item_foreign_mod( ref foreign_mod) => {
2204
- foreign:: trans_foreign_mod ( ccx, foreign_mod) ;
2199
+ foreign:: trans_foreign_mod ( ccx, path , foreign_mod) ;
2205
2200
}
2206
2201
ast:: item_struct( struct_def, ref generics) => {
2207
2202
if !generics. is_type_parameterized ( ) {
@@ -2296,15 +2291,16 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
2296
2291
2297
2292
fn create_main ( ccx : @mut CrateContext , main_llfn : ValueRef ) -> ValueRef {
2298
2293
let nt = ty:: mk_nil ( ) ;
2299
- let llfty = type_of_rust_fn ( ccx, [ ] , nt) ;
2294
+
2295
+ let llfty = type_of_fn ( ccx, [ ] , nt) ;
2300
2296
let llfdecl = decl_fn ( ccx. llmod , "_rust_main" ,
2301
2297
lib:: llvm:: CCallConv , llfty) ;
2302
2298
2303
2299
let fcx = new_fn_ctxt ( ccx, ~[ ] , llfdecl, nt, None ) ;
2304
2300
2305
2301
// the args vector built in create_entry_fn will need
2306
2302
// be updated if this assertion starts to fail.
2307
- assert ! ( ! fcx. caller_expects_out_pointer ) ;
2303
+ assert ! ( fcx. has_immediate_return_value ) ;
2308
2304
2309
2305
let bcx = fcx. entry_bcx . unwrap ( ) ;
2310
2306
// Call main.
@@ -2467,10 +2463,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
2467
2463
let llfn = if purity != ast:: extern_fn {
2468
2464
register_fn ( ccx, i. span , sym, i. id , ty)
2469
2465
} else {
2470
- foreign:: register_rust_fn_with_foreign_abi ( ccx,
2471
- i. span ,
2472
- sym,
2473
- i. id )
2466
+ foreign:: register_foreign_fn ( ccx, i. span , sym, i. id )
2474
2467
} ;
2475
2468
set_inline_hint_if_appr ( i. attrs , llfn) ;
2476
2469
llfn
@@ -2516,7 +2509,9 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
2516
2509
match ni. node {
2517
2510
ast:: foreign_item_fn( * ) => {
2518
2511
let path = vec:: append ( ( * pth) . clone ( ) , [ path_name ( ni. ident ) ] ) ;
2519
- foreign:: register_foreign_item_fn ( ccx, abis, & path, ni) ;
2512
+ let sym = exported_name ( ccx, path, ty, ni. attrs ) ;
2513
+
2514
+ register_fn ( ccx, ni. span , sym, ni. id , ty)
2520
2515
}
2521
2516
ast:: foreign_item_static( * ) => {
2522
2517
let ident = token:: ident_to_str ( & ni. ident ) ;
0 commit comments