From 9723a3bc379c208bd0d872cbf9d8b23888d404ee Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Tue, 23 Feb 2016 21:06:32 +0200 Subject: [PATCH] Move simd_ffi gating from trans to typeck. --- src/librustc_trans/trans/foreign.rs | 31 ----------------------------- src/librustc_typeck/collect.rs | 25 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/librustc_trans/trans/foreign.rs b/src/librustc_trans/trans/foreign.rs index 8e728ca808ccb..37de40efd3ddd 100644 --- a/src/librustc_trans/trans/foreign.rs +++ b/src/librustc_trans/trans/foreign.rs @@ -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"); @@ -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 diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 0f88640b62951..258c7af1316eb 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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::>(); let output = match decl.output { hir::Return(ref ty) => @@ -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,