Skip to content

Commit e3ee974

Browse files
committed
Revert "Issue rust-lang#3678: Remove wrappers and call foreign functions directly"
This reverts commit 303f650.
1 parent 5921432 commit e3ee974

28 files changed

+1559
-1690
lines changed

src/librustc/back/upcall.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use lib::llvm::{ModuleRef, ValueRef};
1616

1717
pub struct Upcalls {
1818
trace: ValueRef,
19+
call_shim_on_c_stack: ValueRef,
20+
call_shim_on_rust_stack: ValueRef,
1921
rust_personality: ValueRef,
2022
reset_stack_limit: ValueRef
2123
}
@@ -45,6 +47,9 @@ pub fn declare_upcalls(targ_cfg: @session::config, llmod: ModuleRef) -> @Upcalls
4547

4648
@Upcalls {
4749
trace: upcall!(fn trace(opaque_ptr, opaque_ptr, int_ty) -> Type::void()),
50+
call_shim_on_c_stack: upcall!(fn call_shim_on_c_stack(opaque_ptr, opaque_ptr) -> int_ty),
51+
call_shim_on_rust_stack:
52+
upcall!(fn call_shim_on_rust_stack(opaque_ptr, opaque_ptr) -> int_ty),
4853
rust_personality: upcall!(nothrow fn rust_personality -> Type::i32()),
4954
reset_stack_limit: upcall!(nothrow fn reset_stack_limit -> Type::void())
5055
}

src/librustc/driver/driver.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,6 @@ pub fn phase_3_run_analysis_passes(sess: Session,
265265
time(time_passes, ~"loop checking", ||
266266
middle::check_loop::check_crate(ty_cx, crate));
267267

268-
time(time_passes, ~"stack checking", ||
269-
middle::stack_check::stack_check_crate(ty_cx, crate));
270-
271268
let middle::moves::MoveMaps {moves_map, moved_variables_set,
272269
capture_map} =
273270
time(time_passes, ~"compute moves", ||

src/librustc/lib/llvm.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,11 +2246,6 @@ impl TypeNames {
22462246
self.type_to_str_depth(ty, 30)
22472247
}
22482248

2249-
pub fn types_to_str(&self, tys: &[Type]) -> ~str {
2250-
let strs = tys.map(|t| self.type_to_str(*t));
2251-
fmt!("[%s]", strs.connect(","))
2252-
}
2253-
22542249
pub fn val_to_str(&self, val: ValueRef) -> ~str {
22552250
unsafe {
22562251
let ty = Type::from_ref(llvm::LLVMTypeOf(val));

src/librustc/middle/lint.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ use syntax::{ast, oldvisit, ast_util, visit};
7373
#[deriving(Clone, Eq)]
7474
pub enum lint {
7575
ctypes,
76-
cstack,
7776
unused_imports,
7877
unnecessary_qualification,
7978
while_true,
@@ -147,13 +146,6 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
147146
default: warn
148147
}),
149148

150-
("cstack",
151-
LintSpec {
152-
lint: cstack,
153-
desc: "only invoke foreign functions from fixedstacksegment fns",
154-
default: deny
155-
}),
156-
157149
("unused_imports",
158150
LintSpec {
159151
lint: unused_imports,

src/librustc/middle/stack_check.rs

Lines changed: 0 additions & 110 deletions
This file was deleted.

src/librustc/middle/trans/base.rs

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -203,28 +203,28 @@ pub fn decl_internal_cdecl_fn(llmod: ModuleRef, name: &str, ty: Type) -> ValueRe
203203
return llfn;
204204
}
205205

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,
207207
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,
210210
None => ()
211211
}
212212
let f = decl_fn(llmod, name, cc, ty);
213-
externs.insert(name.to_owned(), f);
213+
externs.insert(name, f);
214214
return f;
215215
}
216216

217217
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,
221221
None => ()
222222
}
223223
unsafe {
224224
let c = do name.with_c_str |buf| {
225225
llvm::LLVMAddGlobal(llmod, ty.to_ref(), buf)
226226
};
227-
externs.insert(name.to_owned(), c);
227+
externs.insert(name, c);
228228
return c;
229229
}
230230
}
@@ -511,6 +511,7 @@ pub fn get_res_dtor(ccx: @mut CrateContext,
511511
None,
512512
ty::lookup_item_type(tcx, parent_id).ty);
513513
let llty = type_of_dtor(ccx, class_ty);
514+
let name = name.to_managed(); // :-(
514515
get_extern_fn(&mut ccx.externs,
515516
ccx.llmod,
516517
name,
@@ -797,13 +798,13 @@ pub fn fail_if_zero(cx: @mut Block, span: span, divrem: ast::binop,
797798
}
798799
}
799800
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())
802803
}
803804
804805
pub fn trans_external_path(ccx: &mut CrateContext, did: ast::def_id, t: ty::t)
805806
-> ValueRef {
806-
let name = csearch::get_symbol(ccx.sess.cstore, did);
807+
let name = csearch::get_symbol(ccx.sess.cstore, did).to_managed(); // Sad
807808
match ty::get(t).sty {
808809
ty::ty_bare_fn(_) | ty::ty_closure(_) => {
809810
let llty = type_of_fn_from_ty(ccx, t);
@@ -1571,7 +1572,7 @@ pub fn mk_return_basic_block(llfn: ValueRef) -> BasicBlockRef {
15711572
// slot where the return value of the function must go.
15721573
pub fn make_return_pointer(fcx: @mut FunctionContext, output_type: ty::t) -> ValueRef {
15731574
unsafe {
1574-
if type_of::return_uses_outptr(fcx.ccx.tcx, output_type) {
1575+
if !ty::type_is_immediate(fcx.ccx.tcx, output_type) {
15751576
llvm::LLVMGetParam(fcx.llfn, 0)
15761577
} else {
15771578
let lloutputtype = type_of::type_of(fcx.ccx, output_type);
@@ -1611,7 +1612,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
16111612
ty::subst_tps(ccx.tcx, substs.tys, substs.self_ty, output_type)
16121613
}
16131614
};
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);
16151616
let fcx = @mut FunctionContext {
16161617
llfn: llfndecl,
16171618
llenv: unsafe {
@@ -1623,7 +1624,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
16231624
llreturn: None,
16241625
llself: None,
16251626
personality: None,
1626-
caller_expects_out_pointer: uses_outptr,
1627+
has_immediate_return_value: is_immediate,
16271628
llargs: @mut HashMap::new(),
16281629
lllocals: @mut HashMap::new(),
16291630
llupvars: @mut HashMap::new(),
@@ -1646,15 +1647,8 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
16461647
fcx.alloca_insert_pt = Some(llvm::LLVMGetFirstInstruction(entry_bcx.llbb));
16471648
}
16481649

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));
16581652
}
16591653
fcx
16601654
}
@@ -1802,7 +1796,7 @@ pub fn finish_fn(fcx: @mut FunctionContext, last_bcx: @mut Block) {
18021796
// Builds the return block for a function.
18031797
pub fn build_return_block(fcx: &FunctionContext, ret_cx: @mut Block) {
18041798
// 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 {
18061800
return RetVoid(ret_cx);
18071801
}
18081802

@@ -1888,7 +1882,9 @@ pub fn trans_closure(ccx: @mut CrateContext,
18881882
// translation calls that don't have a return value (trans_crate,
18891883
// trans_mod, trans_item, et cetera) and those that do
18901884
// (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+
{
18921888
bcx = controlflow::trans_block(bcx, body, expr::Ignore);
18931889
} else {
18941890
let dest = expr::SaveIn(fcx.llretptr.unwrap());
@@ -2133,14 +2129,13 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
21332129
ast::item_fn(ref decl, purity, _abis, ref generics, ref body) => {
21342130
if purity == ast::extern_fn {
21352131
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);
21442139
} else if !generics.is_type_parameterized() {
21452140
let llfndecl = get_item_val(ccx, item.id);
21462141
trans_fn(ccx,
@@ -2201,7 +2196,7 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
22012196
}
22022197
},
22032198
ast::item_foreign_mod(ref foreign_mod) => {
2204-
foreign::trans_foreign_mod(ccx, foreign_mod);
2199+
foreign::trans_foreign_mod(ccx, path, foreign_mod);
22052200
}
22062201
ast::item_struct(struct_def, ref generics) => {
22072202
if !generics.is_type_parameterized() {
@@ -2296,15 +2291,16 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
22962291

22972292
fn create_main(ccx: @mut CrateContext, main_llfn: ValueRef) -> ValueRef {
22982293
let nt = ty::mk_nil();
2299-
let llfty = type_of_rust_fn(ccx, [], nt);
2294+
2295+
let llfty = type_of_fn(ccx, [], nt);
23002296
let llfdecl = decl_fn(ccx.llmod, "_rust_main",
23012297
lib::llvm::CCallConv, llfty);
23022298

23032299
let fcx = new_fn_ctxt(ccx, ~[], llfdecl, nt, None);
23042300

23052301
// the args vector built in create_entry_fn will need
23062302
// be updated if this assertion starts to fail.
2307-
assert!(!fcx.caller_expects_out_pointer);
2303+
assert!(fcx.has_immediate_return_value);
23082304

23092305
let bcx = fcx.entry_bcx.unwrap();
23102306
// Call main.
@@ -2467,10 +2463,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
24672463
let llfn = if purity != ast::extern_fn {
24682464
register_fn(ccx, i.span, sym, i.id, ty)
24692465
} 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)
24742467
};
24752468
set_inline_hint_if_appr(i.attrs, llfn);
24762469
llfn
@@ -2516,7 +2509,9 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
25162509
match ni.node {
25172510
ast::foreign_item_fn(*) => {
25182511
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)
25202515
}
25212516
ast::foreign_item_static(*) => {
25222517
let ident = token::ident_to_str(&ni.ident);

0 commit comments

Comments
 (0)