Skip to content

Commit

Permalink
Move simd_ffi gating from trans to typeck.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Mar 17, 2016
1 parent b47fcb8 commit 9723a3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
31 changes: 0 additions & 31 deletions src/librustc_trans/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,30 +463,6 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
return bcx;
}

// feature gate SIMD types in FFI, since I (huonw) am not sure the
// ABIs are handled at all correctly.
fn gate_simd_ffi(tcx: &TyCtxt, decl: &hir::FnDecl, ty: &ty::BareFnTy) {
if !tcx.sess.features.borrow().simd_ffi {
let check = |ast_ty: &hir::Ty, ty: ty::Ty| {
if ty.is_simd() {
tcx.sess.struct_span_err(ast_ty.span,
&format!("use of SIMD type `{}` in FFI is highly experimental and \
may result in invalid code",
pprust::ty_to_string(ast_ty)))
.fileline_help(ast_ty.span,
"add #![feature(simd_ffi)] to the crate attributes to enable")
.emit();
}
};
let sig = &ty.sig.0;
for (input, ty) in decl.inputs.iter().zip(&sig.inputs) {
check(&input.ty, *ty)
}
if let hir::Return(ref ty) = decl.output {
check(&ty, sig.output.unwrap())
}
}
}

pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &hir::ForeignMod) {
let _icx = push_ctxt("foreign::trans_foreign_mod");
Expand All @@ -498,13 +474,6 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &hir::ForeignMod) {
Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic => {}
abi => {
let ty = ccx.tcx().node_id_to_type(foreign_item.id);
match ty.sty {
ty::TyFnDef(_, _, bft) |
ty::TyFnPtr(bft) => gate_simd_ffi(ccx.tcx(), &decl, bft),
_ => ccx.tcx().sess.span_bug(foreign_item.span,
"foreign fn's sty isn't a bare_fn_ty?")
}

register_foreign_item_fn(ccx, abi, ty, &lname, &foreign_item.attrs);
// Unlike for other items, we shouldn't call
// `base::update_linkage` here. Foreign items have
Expand Down
25 changes: 24 additions & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
let input_tys = decl.inputs
.iter()
.map(|a| ty_of_arg(&ccx.icx(ast_generics), &rb, a, None))
.collect();
.collect::<Vec<_>>();

let output = match decl.output {
hir::Return(ref ty) =>
Expand All @@ -2166,6 +2166,29 @@ fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
ty::FnDiverging
};

// feature gate SIMD types in FFI, since I (huonw) am not sure the
// ABIs are handled at all correctly.
if abi != abi::Abi::RustIntrinsic && abi != abi::Abi::PlatformIntrinsic
&& !ccx.tcx.sess.features.borrow().simd_ffi {
let check = |ast_ty: &hir::Ty, ty: ty::Ty| {
if ty.is_simd() {
ccx.tcx.sess.struct_span_err(ast_ty.span,
&format!("use of SIMD type `{}` in FFI is highly experimental and \
may result in invalid code",
pprust::ty_to_string(ast_ty)))
.fileline_help(ast_ty.span,
"add #![feature(simd_ffi)] to the crate attributes to enable")
.emit();
}
};
for (input, ty) in decl.inputs.iter().zip(&input_tys) {
check(&input.ty, ty)
}
if let hir::Return(ref ty) = decl.output {
check(&ty, output.unwrap())
}
}

let substs = ccx.tcx.mk_substs(mk_item_substs(ccx, &ty_generics));
let t_fn = ccx.tcx.mk_fn_def(id, substs, ty::BareFnTy {
abi: abi,
Expand Down

0 comments on commit 9723a3b

Please sign in to comment.