Skip to content

Commit 9723a3b

Browse files
committed
Move simd_ffi gating from trans to typeck.
1 parent b47fcb8 commit 9723a3b

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

src/librustc_trans/trans/foreign.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -463,30 +463,6 @@ pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
463463
return bcx;
464464
}
465465

466-
// feature gate SIMD types in FFI, since I (huonw) am not sure the
467-
// ABIs are handled at all correctly.
468-
fn gate_simd_ffi(tcx: &TyCtxt, decl: &hir::FnDecl, ty: &ty::BareFnTy) {
469-
if !tcx.sess.features.borrow().simd_ffi {
470-
let check = |ast_ty: &hir::Ty, ty: ty::Ty| {
471-
if ty.is_simd() {
472-
tcx.sess.struct_span_err(ast_ty.span,
473-
&format!("use of SIMD type `{}` in FFI is highly experimental and \
474-
may result in invalid code",
475-
pprust::ty_to_string(ast_ty)))
476-
.fileline_help(ast_ty.span,
477-
"add #![feature(simd_ffi)] to the crate attributes to enable")
478-
.emit();
479-
}
480-
};
481-
let sig = &ty.sig.0;
482-
for (input, ty) in decl.inputs.iter().zip(&sig.inputs) {
483-
check(&input.ty, *ty)
484-
}
485-
if let hir::Return(ref ty) = decl.output {
486-
check(&ty, sig.output.unwrap())
487-
}
488-
}
489-
}
490466

491467
pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &hir::ForeignMod) {
492468
let _icx = push_ctxt("foreign::trans_foreign_mod");
@@ -498,13 +474,6 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &hir::ForeignMod) {
498474
Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic => {}
499475
abi => {
500476
let ty = ccx.tcx().node_id_to_type(foreign_item.id);
501-
match ty.sty {
502-
ty::TyFnDef(_, _, bft) |
503-
ty::TyFnPtr(bft) => gate_simd_ffi(ccx.tcx(), &decl, bft),
504-
_ => ccx.tcx().sess.span_bug(foreign_item.span,
505-
"foreign fn's sty isn't a bare_fn_ty?")
506-
}
507-
508477
register_foreign_item_fn(ccx, abi, ty, &lname, &foreign_item.attrs);
509478
// Unlike for other items, we shouldn't call
510479
// `base::update_linkage` here. Foreign items have

src/librustc_typeck/collect.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,7 @@ fn compute_type_scheme_of_foreign_fn_decl<'a, 'tcx>(
21552155
let input_tys = decl.inputs
21562156
.iter()
21572157
.map(|a| ty_of_arg(&ccx.icx(ast_generics), &rb, a, None))
2158-
.collect();
2158+
.collect::<Vec<_>>();
21592159

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

2169+
// feature gate SIMD types in FFI, since I (huonw) am not sure the
2170+
// ABIs are handled at all correctly.
2171+
if abi != abi::Abi::RustIntrinsic && abi != abi::Abi::PlatformIntrinsic
2172+
&& !ccx.tcx.sess.features.borrow().simd_ffi {
2173+
let check = |ast_ty: &hir::Ty, ty: ty::Ty| {
2174+
if ty.is_simd() {
2175+
ccx.tcx.sess.struct_span_err(ast_ty.span,
2176+
&format!("use of SIMD type `{}` in FFI is highly experimental and \
2177+
may result in invalid code",
2178+
pprust::ty_to_string(ast_ty)))
2179+
.fileline_help(ast_ty.span,
2180+
"add #![feature(simd_ffi)] to the crate attributes to enable")
2181+
.emit();
2182+
}
2183+
};
2184+
for (input, ty) in decl.inputs.iter().zip(&input_tys) {
2185+
check(&input.ty, ty)
2186+
}
2187+
if let hir::Return(ref ty) = decl.output {
2188+
check(&ty, output.unwrap())
2189+
}
2190+
}
2191+
21692192
let substs = ccx.tcx.mk_substs(mk_item_substs(ccx, &ty_generics));
21702193
let t_fn = ccx.tcx.mk_fn_def(id, substs, ty::BareFnTy {
21712194
abi: abi,

0 commit comments

Comments
 (0)