Skip to content

Commit 387d6c5

Browse files
committed
Lift restriction on calling extern C functions, and propagate
the ABI as part of the type of an extern fn. cc #3678
1 parent 7b2020f commit 387d6c5

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,19 +1311,6 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
13111311
// Extract the function signature from `in_fty`.
13121312
let fn_sty = structure_of(fcx, f.span, fn_ty);
13131313

1314-
// FIXME(#3678) For now, do not permit calls to C abi functions.
1315-
match fn_sty {
1316-
ty::ty_bare_fn(ty::BareFnTy {abis, _}) => {
1317-
if !abis.is_rust() {
1318-
fcx.tcx().sess.span_err(
1319-
call_expr.span,
1320-
fmt!("Calls to C ABI functions are not (yet) \
1321-
supported; be patient, dear user"));
1322-
}
1323-
}
1324-
_ => {}
1325-
}
1326-
13271314
let fn_sig = match fn_sty {
13281315
ty::ty_bare_fn(ty::BareFnTy {sig: sig, _}) |
13291316
ty::ty_closure(ty::ClosureTy {sig: sig, _}) => sig,
@@ -3607,7 +3594,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
36073594
};
36083595
let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
36093596
purity: ast::unsafe_fn,
3610-
abis: AbiSet::Rust(),
3597+
abis: AbiSet::Intrinsic(),
36113598
sig: FnSig {bound_lifetime_names: opt_vec::Empty,
36123599
inputs: inputs,
36133600
output: output}

src/librustc/middle/typeck/collect.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ impl AstConv for CrateCtxt {
134134
Some(&ast_map::node_item(item, _)) => {
135135
ty_of_item(self, item)
136136
}
137-
Some(&ast_map::node_foreign_item(foreign_item, _, _, _)) => {
138-
ty_of_foreign_item(self, foreign_item)
137+
Some(&ast_map::node_foreign_item(foreign_item, abis, _, _)) => {
138+
ty_of_foreign_item(self, foreign_item, abis)
139139
}
140140
ref x => {
141141
self.tcx.sess.bug(fmt!("unexpected sort of item \
@@ -932,7 +932,20 @@ pub fn convert_foreign(ccx: &CrateCtxt, i: @ast::foreign_item) {
932932
// As above, this call populates the type table with the converted
933933
// type of the foreign item. We simply write it into the node type
934934
// table.
935-
let tpt = ty_of_foreign_item(ccx, i);
935+
936+
// For reasons I cannot fully articulate, I do so hate the AST
937+
// map, and I regard each time that I use it as a personal and
938+
// moral failing, but at the moment it seems like the only
939+
// convenient way to extract the ABI. - ndm
940+
let abis = match ccx.tcx.items.find(&i.id) {
941+
Some(&ast_map::node_foreign_item(_, abis, _, _)) => abis,
942+
ref x => {
943+
ccx.tcx.sess.bug(fmt!("unexpected sort of item \
944+
in get_item_ty(): %?", (*x)));
945+
}
946+
};
947+
948+
let tpt = ty_of_foreign_item(ccx, i, abis);
936949
write_ty_to_tcx(ccx.tcx, i.id, tpt.ty);
937950
ccx.tcx.tcache.insert(local_def(i.id), tpt);
938951
}
@@ -1103,14 +1116,17 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: @ast::item)
11031116
}
11041117
}
11051118
1106-
pub fn ty_of_foreign_item(ccx: &CrateCtxt, it: @ast::foreign_item)
1107-
-> ty::ty_param_bounds_and_ty {
1119+
pub fn ty_of_foreign_item(ccx: &CrateCtxt,
1120+
it: @ast::foreign_item,
1121+
abis: AbiSet) -> ty::ty_param_bounds_and_ty
1122+
{
11081123
match it.node {
11091124
ast::foreign_item_fn(ref fn_decl, _, ref generics) => {
11101125
ty_of_foreign_fn_decl(ccx,
11111126
fn_decl,
11121127
local_def(it.id),
1113-
generics)
1128+
generics,
1129+
abis)
11141130
}
11151131
ast::foreign_item_const(t) => {
11161132
ty::ty_param_bounds_and_ty {
@@ -1197,7 +1213,8 @@ pub fn ty_generics(ccx: &CrateCtxt,
11971213
pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
11981214
decl: &ast::fn_decl,
11991215
def_id: ast::def_id,
1200-
ast_generics: &ast::Generics)
1216+
ast_generics: &ast::Generics,
1217+
abis: AbiSet)
12011218
-> ty::ty_param_bounds_and_ty {
12021219
let ty_generics = ty_generics(ccx, None, ast_generics, 0);
12031220
let region_param_names = RegionParamNames::from_generics(ast_generics);
@@ -1208,7 +1225,7 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
12081225
let t_fn = ty::mk_bare_fn(
12091226
ccx.tcx,
12101227
ty::BareFnTy {
1211-
abis: AbiSet::Rust(),
1228+
abis: abis,
12121229
purity: ast::unsafe_fn,
12131230
sig: ty::FnSig {bound_lifetime_names: opt_vec::Empty,
12141231
inputs: input_tys,

0 commit comments

Comments
 (0)