diff --git a/src/abi/comments.rs b/src/abi/comments.rs index 71df9dba61b..0ac3bec74c7 100644 --- a/src/abi/comments.rs +++ b/src/abi/comments.rs @@ -5,7 +5,7 @@ use rustc::mir; use crate::abi::pass_mode::*; use crate::prelude::*; -pub fn add_args_header_comment(fx: &mut FunctionCx) { +pub(super) fn add_args_header_comment(fx: &mut FunctionCx) { fx.add_global_comment(format!( "kind loc.idx param pass mode ty" )); @@ -49,14 +49,14 @@ pub(super) fn add_arg_comment<'tcx>( )); } -pub fn add_locals_header_comment(fx: &mut FunctionCx) { +pub(super) fn add_locals_header_comment(fx: &mut FunctionCx) { fx.add_global_comment(String::new()); fx.add_global_comment(format!( "kind local ty size align (abi,pref)" )); } -pub fn add_local_place_comments<'tcx>( +pub(super) fn add_local_place_comments<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, place: CPlace<'tcx>, local: Local, diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 5d6a0772ce8..2e7a73a484d 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -10,10 +10,10 @@ use cranelift_codegen::ir::AbiParam; use self::pass_mode::*; use crate::prelude::*; -pub use self::returning::{can_return_to_ssa_var, codegen_return}; +pub(crate) use self::returning::{can_return_to_ssa_var, codegen_return}; // Copied from https://github.com/rust-lang/rust/blob/c2f4c57296f0d929618baed0b0d6eb594abf01eb/src/librustc/ty/layout.rs#L2349 -pub fn fn_sig_for_fn_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::PolyFnSig<'tcx> { +pub(crate) fn fn_sig_for_fn_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::PolyFnSig<'tcx> { let ty = instance.monomorphic_ty(tcx); match ty.kind { ty::FnDef(..) | @@ -163,7 +163,7 @@ fn clif_sig_from_fn_sig<'tcx>( } } -pub fn get_function_name_and_sig<'tcx>( +pub(crate) fn get_function_name_and_sig<'tcx>( tcx: TyCtxt<'tcx>, triple: &target_lexicon::Triple, inst: Instance<'tcx>, @@ -180,7 +180,7 @@ pub fn get_function_name_and_sig<'tcx>( } /// Instance must be monomorphized -pub fn import_function<'tcx>( +pub(crate) fn import_function<'tcx>( tcx: TyCtxt<'tcx>, module: &mut Module, inst: Instance<'tcx>, @@ -193,7 +193,7 @@ pub fn import_function<'tcx>( impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> { /// Instance must be monomorphized - pub fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef { + pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef { let func_id = import_function(self.tcx, self.module, inst); let func_ref = self .module @@ -234,7 +234,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> { results } - pub fn easy_call( + pub(crate) fn easy_call( &mut self, name: &str, args: &[CValue<'tcx>], @@ -288,7 +288,7 @@ fn local_place<'tcx>( fx.local_map[&local] } -pub fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_block: Block, should_codegen_locals: bool) { +pub(crate) fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_block: Block, should_codegen_locals: bool) { let ssa_analyzed = crate::analyze::analyze(fx); #[cfg(debug_assertions)] @@ -423,7 +423,7 @@ pub fn codegen_fn_prelude(fx: &mut FunctionCx<'_, '_, impl Backend>, start_block .jump(*fx.block_map.get(START_BLOCK).unwrap(), &[]); } -pub fn codegen_terminator_call<'tcx>( +pub(crate) fn codegen_terminator_call<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, span: Span, func: &Operand<'tcx>, @@ -444,7 +444,7 @@ pub fn codegen_terminator_call<'tcx>( ty::Instance::resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap(); if fx.tcx.symbol_name(instance).name.as_str().starts_with("llvm.") { - crate::intrinsics::llvm::codegen_llvm_intrinsic_call( + crate::intrinsics::codegen_llvm_intrinsic_call( fx, &fx.tcx.symbol_name(instance).name.as_str(), substs, @@ -640,7 +640,7 @@ fn codegen_call_inner<'tcx>( } } -pub fn codegen_drop<'tcx>( +pub(crate) fn codegen_drop<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, span: Span, drop_place: CPlace<'tcx>, diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index dc6908fc72d..bed4574717e 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -3,7 +3,7 @@ use crate::prelude::*; pub(super) use EmptySinglePair::*; #[derive(Copy, Clone, Debug)] -pub enum PassMode { +pub(super) enum PassMode { NoPass, ByVal(Type), ByValPair(Type, Type), @@ -76,7 +76,7 @@ impl PassMode { } } -pub fn get_pass_mode<'tcx>(tcx: TyCtxt<'tcx>, layout: TyLayout<'tcx>) -> PassMode { +pub(super) fn get_pass_mode<'tcx>(tcx: TyCtxt<'tcx>, layout: TyLayout<'tcx>) -> PassMode { if layout.is_zst() { // WARNING zst arguments must never be passed, as that will break CastKind::ClosureFnPointer PassMode::NoPass diff --git a/src/abi/returning.rs b/src/abi/returning.rs index 0262728bb67..59836f881b6 100644 --- a/src/abi/returning.rs +++ b/src/abi/returning.rs @@ -5,7 +5,7 @@ fn return_layout<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> TyLay fx.layout_of(fx.monomorphize(&fx.mir.local_decls[RETURN_PLACE].ty)) } -pub fn can_return_to_ssa_var<'tcx>(tcx: TyCtxt<'tcx>, dest_layout: TyLayout<'tcx>) -> bool { +pub(crate) fn can_return_to_ssa_var<'tcx>(tcx: TyCtxt<'tcx>, dest_layout: TyLayout<'tcx>) -> bool { match get_pass_mode(tcx, dest_layout) { PassMode::NoPass | PassMode::ByVal(_) => true, // FIXME Make it possible to return ByValPair and ByRef to an ssa var. @@ -101,7 +101,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>( (call_inst, meta) } -pub fn codegen_return(fx: &mut FunctionCx) { +pub(crate) fn codegen_return(fx: &mut FunctionCx) { match get_pass_mode(fx.tcx, return_layout(fx)) { PassMode::NoPass | PassMode::ByRef { sized: true } => { fx.bcx.ins().return_(&[]); diff --git a/src/allocator.rs b/src/allocator.rs index eeead3050d8..b8240f4a822 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -13,7 +13,7 @@ use crate::prelude::*; use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS}; /// Returns whether an allocator shim was created -pub fn codegen(tcx: TyCtxt<'_>, module: &mut Module) -> bool { +pub(crate) fn codegen(tcx: TyCtxt<'_>, module: &mut Module) -> bool { let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| { use rustc::middle::dependency_format::Linkage; list.iter().any(|&linkage| linkage == Linkage::Dynamic) diff --git a/src/analyze.rs b/src/analyze.rs index 965e363d2ba..b82e16217ef 100644 --- a/src/analyze.rs +++ b/src/analyze.rs @@ -4,12 +4,12 @@ use rustc::mir::StatementKind::*; use rustc_index::vec::IndexVec; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -pub enum SsaKind { +pub(crate) enum SsaKind { NotSsa, Ssa, } -pub fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec { +pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec { let mut flag_map = fx.mir.local_decls.iter().map(|local_decl| { if fx.clif_type(fx.monomorphize(&local_decl.ty)).is_some() { SsaKind::Ssa diff --git a/src/archive.rs b/src/archive.rs index 49bbc1da606..6ebb713b267 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -23,7 +23,7 @@ enum ArchiveEntry { File(PathBuf), } -pub struct ArArchiveBuilder<'a> { +pub(crate) struct ArArchiveBuilder<'a> { config: ArchiveConfig<'a>, src_archives: Vec<(PathBuf, ar::Archive)>, // Don't use `HashMap` here, as the order is important. `rust.metadata.bin` must always be at diff --git a/src/atomic_shim.rs b/src/atomic_shim.rs index 83c1b164fc1..d277b33e1b6 100644 --- a/src/atomic_shim.rs +++ b/src/atomic_shim.rs @@ -8,7 +8,7 @@ use crate::prelude::*; #[no_mangle] pub static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t = libc::PTHREAD_MUTEX_INITIALIZER; -pub fn init_global_lock(module: &mut Module, bcx: &mut FunctionBuilder<'_>) { +pub(crate) fn init_global_lock(module: &mut Module, bcx: &mut FunctionBuilder<'_>) { if std::env::var("CG_CLIF_JIT").is_ok () { // When using JIT, dylibs won't find the __cg_clif_global_atomic_mutex data object defined here, // so instead define it in the cg_clif dylib. @@ -46,7 +46,7 @@ pub fn init_global_lock(module: &mut Module, bcx: &mut FunctionBui bcx.ins().call(pthread_mutex_init, &[atomic_mutex, nullptr]); } -pub fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) { +pub(crate) fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) { let atomic_mutex = fx.module.declare_data( "__cg_clif_global_atomic_mutex", Linkage::Import, @@ -71,7 +71,7 @@ pub fn lock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) { fx.bcx.ins().call(pthread_mutex_lock, &[atomic_mutex]); } -pub fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) { +pub(crate) fn unlock_global_lock(fx: &mut FunctionCx<'_, '_, impl Backend>) { let atomic_mutex = fx.module.declare_data( "__cg_clif_global_atomic_mutex", Linkage::Import, diff --git a/src/backend.rs b/src/backend.rs index 5c57e16125c..723f1bca55a 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -14,7 +14,7 @@ use gimli::SectionId; use crate::debuginfo::{DebugReloc, DebugRelocName}; -pub trait WriteMetadata { +pub(crate) trait WriteMetadata { fn add_rustc_section(&mut self, symbol_name: String, data: Vec, is_like_osx: bool); } @@ -38,7 +38,7 @@ impl WriteMetadata for object::write::Object { } } -pub trait WriteDebugInfo { +pub(crate) trait WriteDebugInfo { type SectionId; fn add_debug_section(&mut self, name: SectionId, data: Vec) -> Self::SectionId; @@ -99,7 +99,7 @@ impl WriteDebugInfo for ObjectProduct { } } -pub trait Emit { +pub(crate) trait Emit { fn emit(self) -> Vec; } @@ -109,7 +109,7 @@ impl Emit for ObjectProduct { } } -pub fn with_object(sess: &Session, name: &str, f: impl FnOnce(&mut Object)) -> Vec { +pub(crate) fn with_object(sess: &Session, name: &str, f: impl FnOnce(&mut Object)) -> Vec { let triple = crate::build_isa(sess, true).triple().clone(); let mut metadata_object = object::write::Object::new(triple.binary_format, triple.architecture); @@ -118,9 +118,9 @@ pub fn with_object(sess: &Session, name: &str, f: impl FnOnce(&mut Object)) -> V metadata_object.write().unwrap() } -pub type Backend = impl cranelift_module::Backend; +pub(crate) type Backend = impl cranelift_module::Backend; -pub fn make_module(sess: &Session, name: String) -> Module { +pub(crate) fn make_module(sess: &Session, name: String) -> Module { let module: Module = Module::new( ObjectBuilder::new( crate::build_isa(sess, true), diff --git a/src/base.rs b/src/base.rs index 4a865fdb731..a9012581638 100644 --- a/src/base.rs +++ b/src/base.rs @@ -3,7 +3,7 @@ use rustc_index::vec::IndexVec; use crate::prelude::*; -pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( +pub(crate) fn trans_fn<'clif, 'tcx, B: Backend + 'static>( cx: &mut crate::CodegenCx<'clif, 'tcx, B>, instance: Instance<'tcx>, linkage: Linkage, @@ -202,7 +202,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( context.clear(); } -pub fn verify_func(tcx: TyCtxt, writer: &crate::pretty_clif::CommentWriter, func: &Function) { +pub(crate) fn verify_func(tcx: TyCtxt, writer: &crate::pretty_clif::CommentWriter, func: &Function) { tcx.sess.time("verify clif ir", || { let flags = settings::Flags::new(settings::builder()); match ::cranelift_codegen::verify_function(&func, &flags) { @@ -724,7 +724,7 @@ fn codegen_array_len<'tcx>( } } -pub fn trans_place<'tcx>( +pub(crate) fn trans_place<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, place: &Place<'tcx>, ) -> CPlace<'tcx> { @@ -792,7 +792,7 @@ pub fn trans_place<'tcx>( cplace } -pub fn trans_operand<'tcx>( +pub(crate) fn trans_operand<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, operand: &Operand<'tcx>, ) -> CValue<'tcx> { diff --git a/src/cast.rs b/src/cast.rs index d945ad7d054..08dc68b08d7 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub fn clif_intcast( +pub(crate) fn clif_intcast( fx: &mut FunctionCx<'_, '_, impl Backend>, val: Value, to: Type, @@ -48,7 +48,7 @@ pub fn clif_intcast( } } -pub fn clif_int_or_float_cast( +pub(crate) fn clif_int_or_float_cast( fx: &mut FunctionCx<'_, '_, impl Backend>, from: Value, from_signed: bool, diff --git a/src/codegen_i128.rs b/src/codegen_i128.rs index f1bdb49b74a..e2bb5b17ba2 100644 --- a/src/codegen_i128.rs +++ b/src/codegen_i128.rs @@ -2,7 +2,7 @@ use crate::prelude::*; -pub fn maybe_codegen<'tcx>( +pub(crate) fn maybe_codegen<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, bin_op: BinOp, checked: bool, diff --git a/src/common.rs b/src/common.rs index f0cc8dd4db7..09133d94db2 100644 --- a/src/common.rs +++ b/src/common.rs @@ -6,11 +6,11 @@ use cranelift_codegen::ir::{InstructionData, Opcode, ValueDef}; use crate::prelude::*; -pub fn mir_var(loc: Local) -> Variable { +pub(crate) fn mir_var(loc: Local) -> Variable { Variable::with_u32(loc.index() as u32) } -pub fn pointer_ty(tcx: TyCtxt) -> types::Type { +pub(crate) fn pointer_ty(tcx: TyCtxt) -> types::Type { match tcx.data_layout.pointer_size.bits() { 16 => types::I16, 32 => types::I32, @@ -19,7 +19,7 @@ pub fn pointer_ty(tcx: TyCtxt) -> types::Type { } } -pub fn scalar_to_clif_type(tcx: TyCtxt, scalar: Scalar) -> Type { +pub(crate) fn scalar_to_clif_type(tcx: TyCtxt, scalar: Scalar) -> Type { match scalar.value { Primitive::Int(int, _sign) => match int { Integer::I8 => types::I8, @@ -72,7 +72,7 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { +pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { let ptr_ty = tcx.mk_ptr(TypeAndMut { ty, mutbl: rustc_hir::Mutability::Not }); match &tcx.layout_of(ParamEnv::reveal_all().and(ptr_ty)).unwrap().abi { Abi::Scalar(_) => false, @@ -81,7 +81,7 @@ pub fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { } } -pub fn codegen_icmp( +pub(crate) fn codegen_icmp( fx: &mut FunctionCx<'_, '_, impl Backend>, intcc: IntCC, lhs: Value, @@ -126,7 +126,7 @@ pub fn codegen_icmp( } } -pub fn codegen_icmp_imm( +pub(crate) fn codegen_icmp_imm( fx: &mut FunctionCx<'_, '_, impl Backend>, intcc: IntCC, lhs: Value, @@ -207,7 +207,7 @@ fn resolve_128bit_value_imm(func: &Function, val: Value) -> Option { Some(msb << 64 | lsb) } -pub fn resolve_value_imm(func: &Function, val: Value) -> Option { +pub(crate) fn resolve_value_imm(func: &Function, val: Value) -> Option { if func.dfg.value_type(val) == types::I128 { resolve_128bit_value_imm(func, val) } else { @@ -215,7 +215,7 @@ pub fn resolve_value_imm(func: &Function, val: Value) -> Option { } } -pub fn type_min_max_value(ty: Type, signed: bool) -> (i64, i64) { +pub(crate) fn type_min_max_value(ty: Type, signed: bool) -> (i64, i64) { assert!(ty.is_int()); let min = match (ty, signed) { (types::I8, false) | (types::I16, false) | (types::I32, false) | (types::I64, false) => { @@ -245,7 +245,7 @@ pub fn type_min_max_value(ty: Type, signed: bool) -> (i64, i64) { (min, max) } -pub fn type_sign(ty: Ty<'_>) -> bool { +pub(crate) fn type_sign(ty: Ty<'_>) -> bool { match ty.kind { ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..) | ty::Char | ty::Uint(..) | ty::Bool => false, ty::Int(..) => true, @@ -254,30 +254,30 @@ pub fn type_sign(ty: Ty<'_>) -> bool { } } -pub struct FunctionCx<'clif, 'tcx, B: Backend + 'static> { +pub(crate) struct FunctionCx<'clif, 'tcx, B: Backend + 'static> { // FIXME use a reference to `CodegenCx` instead of `tcx`, `module` and `constants` and `caches` - pub tcx: TyCtxt<'tcx>, - pub module: &'clif mut Module, - pub pointer_type: Type, // Cached from module + pub(crate) tcx: TyCtxt<'tcx>, + pub(crate) module: &'clif mut Module, + pub(crate) pointer_type: Type, // Cached from module - pub instance: Instance<'tcx>, - pub mir: &'tcx Body<'tcx>, + pub(crate) instance: Instance<'tcx>, + pub(crate) mir: &'tcx Body<'tcx>, - pub bcx: FunctionBuilder<'clif>, - pub block_map: IndexVec, - pub local_map: HashMap>, + pub(crate) bcx: FunctionBuilder<'clif>, + pub(crate) block_map: IndexVec, + pub(crate) local_map: HashMap>, /// When `#[track_caller]` is used, the implicit caller location is stored in this variable. - pub caller_location: Option>, + pub(crate) caller_location: Option>, /// See [crate::optimize::code_layout] for more information. - pub cold_blocks: EntitySet, + pub(crate) cold_blocks: EntitySet, - pub clif_comments: crate::pretty_clif::CommentWriter, - pub constants_cx: &'clif mut crate::constant::ConstantCx, - pub vtables: &'clif mut HashMap<(Ty<'tcx>, Option>), DataId>, + pub(crate) clif_comments: crate::pretty_clif::CommentWriter, + pub(crate) constants_cx: &'clif mut crate::constant::ConstantCx, + pub(crate) vtables: &'clif mut HashMap<(Ty<'tcx>, Option>), DataId>, - pub source_info_set: indexmap::IndexSet, + pub(crate) source_info_set: indexmap::IndexSet, } impl<'tcx, B: Backend> LayoutOf for FunctionCx<'_, 'tcx, B> { @@ -333,7 +333,7 @@ impl<'tcx, B: Backend> BackendTypes for FunctionCx<'_, 'tcx, B> { } impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> { - pub fn monomorphize(&self, value: &T) -> T + pub(crate) fn monomorphize(&self, value: &T) -> T where T: TypeFoldable<'tcx>, { @@ -344,26 +344,26 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> { ) } - pub fn clif_type(&self, ty: Ty<'tcx>) -> Option { + pub(crate) fn clif_type(&self, ty: Ty<'tcx>) -> Option { clif_type_from_ty(self.tcx, ty) } - pub fn get_block(&self, bb: BasicBlock) -> Block { + pub(crate) fn get_block(&self, bb: BasicBlock) -> Block { *self.block_map.get(bb).unwrap() } - pub fn get_local_place(&mut self, local: Local) -> CPlace<'tcx> { + pub(crate) fn get_local_place(&mut self, local: Local) -> CPlace<'tcx> { *self.local_map.get(&local).unwrap_or_else(|| { panic!("Local {:?} doesn't exist", local); }) } - pub fn set_debug_loc(&mut self, source_info: mir::SourceInfo) { + pub(crate) fn set_debug_loc(&mut self, source_info: mir::SourceInfo) { let (index, _) = self.source_info_set.insert_full(source_info); self.bcx.set_srcloc(SourceLoc::new(index as u32)); } - pub fn get_caller_location(&mut self, span: Span) -> CValue<'tcx> { + pub(crate) fn get_caller_location(&mut self, span: Span) -> CValue<'tcx> { if let Some(loc) = self.caller_location { // `#[track_caller]` is used; return caller location instead of current location. return loc; @@ -382,7 +382,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> { ) } - pub fn triple(&self) -> &target_lexicon::Triple { + pub(crate) fn triple(&self) -> &target_lexicon::Triple { self.module.isa().triple() } } diff --git a/src/constant.rs b/src/constant.rs index e6953b97a5d..98a69c11cdd 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -19,7 +19,7 @@ use cranelift_module::*; use crate::prelude::*; #[derive(Default)] -pub struct ConstantCx { +pub(crate) struct ConstantCx { todo: Vec, done: FxHashSet, } @@ -31,7 +31,7 @@ enum TodoItem { } impl ConstantCx { - pub fn finalize(mut self, tcx: TyCtxt<'_>, module: &mut Module) { + pub(crate) fn finalize(mut self, tcx: TyCtxt<'_>, module: &mut Module) { //println!("todo {:?}", self.todo); define_all_allocs(tcx, module, &mut self); //println!("done {:?}", self.done); @@ -39,7 +39,7 @@ impl ConstantCx { } } -pub fn codegen_static(constants_cx: &mut ConstantCx, def_id: DefId) { +pub(crate) fn codegen_static(constants_cx: &mut ConstantCx, def_id: DefId) { constants_cx.todo.push(TodoItem::Static(def_id)); } @@ -56,7 +56,7 @@ fn codegen_static_ref<'tcx>( cplace_for_dataid(fx, layout, local_data_id) } -pub fn trans_constant<'tcx>( +pub(crate) fn trans_constant<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, constant: &Constant<'tcx>, ) -> CValue<'tcx> { @@ -77,7 +77,7 @@ pub fn trans_constant<'tcx>( trans_const_value(fx, const_) } -pub fn trans_const_value<'tcx>( +pub(crate) fn trans_const_value<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, const_: &'tcx Const<'tcx>, ) -> CValue<'tcx> { @@ -489,7 +489,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for TransPlaceInterpreter { } } -pub fn mir_operand_get_const_val<'tcx>( +pub(crate) fn mir_operand_get_const_val<'tcx>( fx: &FunctionCx<'_, 'tcx, impl Backend>, operand: &Operand<'tcx>, ) -> Option<&'tcx Const<'tcx>> { diff --git a/src/debuginfo/emit.rs b/src/debuginfo/emit.rs index 2b6dc9f669f..16527353fbc 100644 --- a/src/debuginfo/emit.rs +++ b/src/debuginfo/emit.rs @@ -8,7 +8,7 @@ use crate::backend::WriteDebugInfo; use super::DebugContext; impl DebugContext<'_> { - pub fn emit(&mut self, product: &mut P) { + pub(crate) fn emit(&mut self, product: &mut P) { let unit_range_list_id = self.dwarf.unit.ranges.add(self.unit_range_list.clone()); let root = self.dwarf.unit.root(); let root = self.dwarf.unit.get_mut(root); @@ -41,15 +41,15 @@ impl DebugContext<'_> { } #[derive(Clone)] -pub struct DebugReloc { - pub offset: u32, - pub size: u8, - pub name: DebugRelocName, - pub addend: i64, +pub(crate) struct DebugReloc { + pub(crate) offset: u32, + pub(crate) size: u8, + pub(crate) name: DebugRelocName, + pub(crate) addend: i64, } #[derive(Clone)] -pub enum DebugRelocName { +pub(crate) enum DebugRelocName { Section(SectionId), Symbol(usize), } diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index fda861c5519..0870f89e3d8 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -3,7 +3,7 @@ use std::path::{Component, Path}; use crate::prelude::*; -use rustc_span::{FileName, SourceFileAndLine}; +use rustc_span::{FileName, SourceFileAndLine, Pos}; use cranelift_codegen::binemit::CodeOffset; @@ -162,7 +162,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { let current_file_changed = if let Some(last_file) = &last_file { // If the allocations are not equal, then the files may still be equal, but that // is not a problem, as this is just an optimization. - !Lrc::ptr_eq(last_file, &file) + !rustc_data_structures::sync::Lrc::ptr_eq(last_file, &file) } else { true }; diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 363abb8cd77..95fde120a9c 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -13,7 +13,7 @@ use gimli::write::{ }; use gimli::{Encoding, Format, LineEncoding, Register, RunTimeEndian, X86_64}; -pub use emit::{DebugReloc, DebugRelocName}; +pub(crate) use emit::{DebugReloc, DebugRelocName}; fn target_endian(tcx: TyCtxt) -> RunTimeEndian { use rustc::ty::layout::Endian; @@ -24,7 +24,7 @@ fn target_endian(tcx: TyCtxt) -> RunTimeEndian { } } -pub struct DebugContext<'tcx> { +pub(crate) struct DebugContext<'tcx> { tcx: TyCtxt<'tcx>, endian: RunTimeEndian, @@ -37,7 +37,7 @@ pub struct DebugContext<'tcx> { } impl<'tcx> DebugContext<'tcx> { - pub fn new(tcx: TyCtxt<'tcx>, address_size: u8) -> Self { + pub(crate) fn new(tcx: TyCtxt<'tcx>, address_size: u8) -> Self { let encoding = Encoding { format: Format::Dwarf32, // TODO: this should be configurable @@ -187,7 +187,7 @@ impl<'tcx> DebugContext<'tcx> { } } -pub struct FunctionDebugContext<'a, 'tcx> { +pub(crate) struct FunctionDebugContext<'a, 'tcx> { debug_context: &'a mut DebugContext<'tcx>, entry_id: UnitEntryId, symbol: usize, @@ -196,7 +196,7 @@ pub struct FunctionDebugContext<'a, 'tcx> { } impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { - pub fn new( + pub(crate) fn new( debug_context: &'a mut DebugContext<'tcx>, instance: Instance<'tcx>, func_id: FuncId, @@ -250,7 +250,7 @@ impl<'a, 'tcx> FunctionDebugContext<'a, 'tcx> { var_id } - pub fn define( + pub(crate) fn define( &mut self, context: &Context, isa: &dyn TargetIsa, diff --git a/src/discriminant.rs b/src/discriminant.rs index 82d2d9fd8b3..a6d6d814fc9 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -2,7 +2,7 @@ use crate::prelude::*; -pub fn codegen_set_discriminant<'tcx>( +pub(crate) fn codegen_set_discriminant<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, place: CPlace<'tcx>, variant_index: VariantIdx, @@ -52,7 +52,7 @@ pub fn codegen_set_discriminant<'tcx>( } } -pub fn codegen_get_discriminant<'tcx>( +pub(crate) fn codegen_get_discriminant<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, value: CValue<'tcx>, dest_layout: TyLayout<'tcx>, diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 00bc0042841..d4582e6f1ff 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -89,7 +89,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> { let formats = tcx.dependency_formats(LOCAL_CRATE); let data = &formats .iter() - .find(|(crate_type, _data)| *crate_type == CrateType::Executable) + .find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable) .unwrap() .1; for &(cnum, _) in &crate_info.used_crates_dynamic { diff --git a/src/driver/mod.rs b/src/driver/mod.rs index d68cb5bb7ee..7f46150252e 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -1,7 +1,7 @@ use std::any::Any; use rustc::middle::cstore::EncodedMetadata; -use rustc::mir::mono::{Linkage as RLinkage, Visibility}; +use rustc::mir::mono::{Linkage as RLinkage, MonoItem, Visibility}; use crate::prelude::*; @@ -9,7 +9,7 @@ mod aot; #[cfg(not(target_arch = "wasm32"))] mod jit; -pub fn codegen_crate( +pub(crate) fn codegen_crate( tcx: TyCtxt<'_>, metadata: EncodedMetadata, need_metadata_module: bool, @@ -17,7 +17,7 @@ pub fn codegen_crate( tcx.sess.abort_if_errors(); if std::env::var("CG_CLIF_JIT").is_ok() - && tcx.sess.crate_types.get().contains(&CrateType::Executable) + && tcx.sess.crate_types.get().contains(&rustc_session::config::CrateType::Executable) { #[cfg(not(target_arch = "wasm32"))] let _: ! = jit::run_jit(tcx); diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index b30f3b8f8db..e1a0066fc48 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -3,7 +3,7 @@ use crate::prelude::*; use rustc::ty::subst::SubstsRef; -pub fn codegen_llvm_intrinsic_call<'tcx>( +pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, intrinsic: &str, substs: SubstsRef<'tcx>, diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 2df8948054f..c6db8504a80 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -1,6 +1,8 @@ -pub mod llvm; +mod llvm; mod simd; +pub(crate) use llvm::codegen_llvm_intrinsic_call; + use crate::prelude::*; macro intrinsic_pat { @@ -332,7 +334,7 @@ macro simd_flt_binop($fx:expr, $op:ident($x:ident, $y:ident) -> $ret:ident) { ); } -pub fn codegen_intrinsic_call<'tcx>( +pub(crate) fn codegen_intrinsic_call<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, instance: Instance<'tcx>, args: &[mir::Operand<'tcx>], diff --git a/src/lib.rs b/src/lib.rs index 061f78c8a92..303ef3f7f94 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,62 +62,52 @@ mod value_and_place; mod vtable; mod prelude { - pub use std::any::Any; - pub use std::collections::{HashMap, HashSet}; - pub use std::convert::{TryFrom, TryInto}; + pub(crate) use std::collections::HashMap; + pub(crate) use std::convert::{TryFrom, TryInto}; - pub use rustc_ast::ast::{FloatTy, IntTy, UintTy}; - pub use rustc_span::{Pos, Span}; + pub(crate) use rustc_ast::ast::{FloatTy, IntTy, UintTy}; + pub(crate) use rustc_span::Span; - pub use rustc::bug; - pub use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; - pub use rustc::mir::{self, interpret::AllocId, mono::MonoItem, *}; - pub use rustc_session::{ - config::{CrateType, Lto}, - Session, - }; - pub use rustc::ty::layout::{self, Abi, LayoutOf, Scalar, Size, TyLayout, VariantIdx}; - pub use rustc::ty::{ - self, FnSig, Instance, InstanceDef, ParamEnv, PolyFnSig, Ty, TyCtxt, TypeAndMut, - TypeFoldable, + pub(crate) use rustc::bug; + pub(crate) use rustc_hir::def_id::{DefId, LOCAL_CRATE}; + pub(crate) use rustc::mir::{self, *}; + pub(crate) use rustc_session::Session; + pub(crate) use rustc::ty::layout::{self, Abi, LayoutOf, Scalar, Size, TyLayout, VariantIdx}; + pub(crate) use rustc::ty::{ + self, FnSig, Instance, InstanceDef, ParamEnv, Ty, TyCtxt, TypeAndMut, TypeFoldable, }; - pub use rustc_data_structures::{ - fx::{FxHashMap, FxHashSet}, - sync::Lrc, + pub(crate) use rustc_data_structures::fx::FxHashMap; + + pub(crate) use rustc_index::vec::Idx; + + pub(crate) use rustc_codegen_ssa::traits::*; + pub(crate) use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleKind}; + + pub(crate) use cranelift_codegen::Context; + pub(crate) use cranelift_codegen::entity::EntitySet; + pub(crate) use cranelift_codegen::ir::{AbiParam, Block, ExternalName, FuncRef, Inst, InstBuilder, MemFlags, Signature, SourceLoc, StackSlot, StackSlotData, StackSlotKind, TrapCode, Type, Value}; + pub(crate) use cranelift_codegen::ir::condcodes::{FloatCC, IntCC}; + pub(crate) use cranelift_codegen::ir::function::Function; + pub(crate) use cranelift_codegen::ir::types; + pub(crate) use cranelift_codegen::isa::{self, CallConv}; + pub(crate) use cranelift_codegen::settings::{self, Configurable}; + pub(crate) use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; + pub(crate) use cranelift_module::{ + self, Backend, DataContext, DataId, FuncId, Linkage, Module, }; - pub use rustc_index::vec::Idx; + pub(crate) use crate::abi::*; + pub(crate) use crate::base::{trans_operand, trans_place}; + pub(crate) use crate::cast::*; + pub(crate) use crate::common::*; + pub(crate) use crate::debuginfo::{DebugContext, FunctionDebugContext}; + pub(crate) use crate::pointer::Pointer; + pub(crate) use crate::trap::*; + pub(crate) use crate::value_and_place::{CPlace, CPlaceInner, CValue}; + pub(crate) use crate::CodegenCx; - pub use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue}; - pub use rustc_codegen_ssa::traits::*; - pub use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleKind}; - - pub use cranelift_codegen::Context; - pub use cranelift_codegen::entity::EntitySet; - pub use cranelift_codegen::ir::{AbiParam, Block, ExternalName, FuncRef, Inst, InstBuilder, MemFlags, Signature, SourceLoc, StackSlot, StackSlotData, StackSlotKind, TrapCode, Type, Value}; - pub use cranelift_codegen::ir::condcodes::{FloatCC, IntCC}; - pub use cranelift_codegen::ir::function::Function; - pub use cranelift_codegen::ir::immediates::{Ieee32, Ieee64}; - pub use cranelift_codegen::ir::types; - pub use cranelift_codegen::isa::{self, CallConv}; - pub use cranelift_codegen::settings::{self, Configurable}; - pub use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; - pub use cranelift_module::{ - self, Backend, DataContext, DataId, FuncId, FuncOrDataId, Linkage, Module, - }; - - pub use crate::abi::*; - pub use crate::base::{trans_operand, trans_place}; - pub use crate::cast::*; - pub use crate::common::*; - pub use crate::debuginfo::{DebugContext, FunctionDebugContext}; - pub use crate::pointer::Pointer; - pub use crate::trap::*; - pub use crate::value_and_place::{CPlace, CPlaceInner, CValue}; - pub use crate::CodegenCx; - - pub struct PrintOnPanic String>(pub F); + pub(crate) struct PrintOnPanic String>(pub F); impl String> Drop for PrintOnPanic { fn drop(&mut self) { if ::std::thread::panicking() { @@ -126,12 +116,12 @@ mod prelude { } } - pub macro unimpl_fatal($tcx:expr, $span:expr, $($tt:tt)*) { + pub(crate) macro unimpl_fatal($tcx:expr, $span:expr, $($tt:tt)*) { $tcx.sess.span_fatal($span, &format!($($tt)*)); } } -pub struct CodegenCx<'clif, 'tcx, B: Backend + 'static> { +pub(crate) struct CodegenCx<'clif, 'tcx, B: Backend + 'static> { tcx: TyCtxt<'tcx>, module: &'clif mut Module, constants_cx: ConstantCx, diff --git a/src/linkage.rs b/src/linkage.rs index bf5c2956222..6b4c4353964 100644 --- a/src/linkage.rs +++ b/src/linkage.rs @@ -2,7 +2,7 @@ use rustc::mir::mono::{Linkage as RLinkage, MonoItem, Visibility}; use crate::prelude::*; -pub fn get_clif_linkage(mono_item: MonoItem, linkage: RLinkage, visibility: Visibility) -> Linkage { +pub(crate) fn get_clif_linkage(mono_item: MonoItem, linkage: RLinkage, visibility: Visibility) -> Linkage { match (linkage, visibility) { (RLinkage::External, Visibility::Default) => Linkage::Export, (RLinkage::Internal, Visibility::Default) => Linkage::Local, @@ -11,7 +11,7 @@ pub fn get_clif_linkage(mono_item: MonoItem, linkage: RLinkage, visibility: Visi } } -pub fn get_static_ref_linkage(tcx: TyCtxt, def_id: DefId) -> Linkage { +pub(crate) fn get_static_ref_linkage(tcx: TyCtxt, def_id: DefId) -> Linkage { let fn_attrs = tcx.codegen_fn_attrs(def_id); if let Some(linkage) = fn_attrs.linkage { diff --git a/src/main_shim.rs b/src/main_shim.rs index 145dd704bad..81f9e0ebad9 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -2,7 +2,7 @@ use crate::prelude::*; /// Create the `main` function which will initialize the rust runtime and call /// users main function. -pub fn maybe_create_entry_wrapper(tcx: TyCtxt<'_>, module: &mut Module) { +pub(crate) fn maybe_create_entry_wrapper(tcx: TyCtxt<'_>, module: &mut Module) { use rustc::middle::lang_items::StartFnLangItem; use rustc_session::config::EntryFnType; diff --git a/src/metadata.rs b/src/metadata.rs index 3c3a7c50149..748d4075a70 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -12,7 +12,7 @@ use rustc_target::spec::Target; use crate::backend::WriteMetadata; -pub struct CraneliftMetadataLoader; +pub(crate) struct CraneliftMetadataLoader; impl MetadataLoader for CraneliftMetadataLoader { fn get_rlib_metadata( @@ -59,7 +59,7 @@ impl MetadataLoader for CraneliftMetadataLoader { } // Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112 -pub fn write_metadata(tcx: TyCtxt<'_>, product: &mut P) -> EncodedMetadata { +pub(crate) fn write_metadata(tcx: TyCtxt<'_>, product: &mut P) -> EncodedMetadata { use flate2::write::DeflateEncoder; use flate2::Compression; use std::io::Write; diff --git a/src/num.rs b/src/num.rs index 103c15eca41..b0d04f12279 100644 --- a/src/num.rs +++ b/src/num.rs @@ -1,6 +1,6 @@ use crate::prelude::*; -pub fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> Option { +pub(crate) fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> Option { use BinOp::*; use IntCC::*; Some(match bin_op { @@ -51,7 +51,7 @@ fn codegen_compare_bin_op<'tcx>( CValue::by_val(val, fx.layout_of(fx.tcx.types.bool)) } -pub fn codegen_binop<'tcx>( +pub(crate) fn codegen_binop<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, bin_op: BinOp, in_lhs: CValue<'tcx>, @@ -100,7 +100,7 @@ pub fn codegen_binop<'tcx>( } } -pub fn trans_bool_binop<'tcx>( +pub(crate) fn trans_bool_binop<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, bin_op: BinOp, in_lhs: CValue<'tcx>, @@ -121,7 +121,7 @@ pub fn trans_bool_binop<'tcx>( CValue::by_val(res, fx.layout_of(fx.tcx.types.bool)) } -pub fn trans_int_binop<'tcx>( +pub(crate) fn trans_int_binop<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, bin_op: BinOp, in_lhs: CValue<'tcx>, @@ -192,7 +192,7 @@ pub fn trans_int_binop<'tcx>( CValue::by_val(val, in_lhs.layout()) } -pub fn trans_checked_int_binop<'tcx>( +pub(crate) fn trans_checked_int_binop<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, bin_op: BinOp, in_lhs: CValue<'tcx>, @@ -297,7 +297,7 @@ pub fn trans_checked_int_binop<'tcx>( out_place.to_cvalue(fx) } -pub fn trans_float_binop<'tcx>( +pub(crate) fn trans_float_binop<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, bin_op: BinOp, in_lhs: CValue<'tcx>, @@ -342,7 +342,7 @@ pub fn trans_float_binop<'tcx>( CValue::by_val(res, in_lhs.layout()) } -pub fn trans_ptr_binop<'tcx>( +pub(crate) fn trans_ptr_binop<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, bin_op: BinOp, in_lhs: CValue<'tcx>, diff --git a/src/optimize/mod.rs b/src/optimize/mod.rs index 29ad5321d57..d59df98e750 100644 --- a/src/optimize/mod.rs +++ b/src/optimize/mod.rs @@ -3,7 +3,7 @@ use crate::prelude::*; mod code_layout; mod stack2reg; -pub fn optimize_function<'tcx>( +pub(crate) fn optimize_function<'tcx>( tcx: TyCtxt<'tcx>, #[cfg_attr(not(debug_assertions), allow(unused_variables))] instance: Instance<'tcx>, diff --git a/src/pointer.rs b/src/pointer.rs index b9183aeedc9..854a7cd4401 100644 --- a/src/pointer.rs +++ b/src/pointer.rs @@ -3,33 +3,33 @@ use crate::prelude::*; use cranelift_codegen::ir::immediates::Offset32; #[derive(Copy, Clone, Debug)] -pub struct Pointer { +pub(crate) struct Pointer { base: PointerBase, offset: Offset32, } #[derive(Copy, Clone, Debug)] -pub enum PointerBase { +pub(crate) enum PointerBase { Addr(Value), Stack(StackSlot), } impl Pointer { - pub fn new(addr: Value) -> Self { + pub(crate) fn new(addr: Value) -> Self { Pointer { base: PointerBase::Addr(addr), offset: Offset32::new(0), } } - pub fn stack_slot(stack_slot: StackSlot) -> Self { + pub(crate) fn stack_slot(stack_slot: StackSlot) -> Self { Pointer { base: PointerBase::Stack(stack_slot), offset: Offset32::new(0), } } - pub fn const_addr<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>, addr: i64) -> Self { + pub(crate) fn const_addr<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>, addr: i64) -> Self { let addr = fx.bcx.ins().iconst(fx.pointer_type, addr); Pointer { base: PointerBase::Addr(addr), @@ -38,11 +38,11 @@ impl Pointer { } #[cfg(debug_assertions)] - pub fn base_and_offset(self) -> (PointerBase, Offset32) { + pub(crate) fn base_and_offset(self) -> (PointerBase, Offset32) { (self.base, self.offset) } - pub fn get_addr<'a, 'tcx>(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> Value { + pub(crate) fn get_addr<'a, 'tcx>(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> Value { match self.base { PointerBase::Addr(base_addr) => { let offset: i64 = self.offset.into(); @@ -56,7 +56,7 @@ impl Pointer { } } - pub fn offset<'a, 'tcx>( + pub(crate) fn offset<'a, 'tcx>( self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>, extra_offset: Offset32, @@ -64,7 +64,7 @@ impl Pointer { self.offset_i64(fx, extra_offset.into()) } - pub fn offset_i64<'a, 'tcx>( + pub(crate) fn offset_i64<'a, 'tcx>( self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>, extra_offset: i64, @@ -92,7 +92,7 @@ impl Pointer { } } - pub fn offset_value<'a, 'tcx>( + pub(crate) fn offset_value<'a, 'tcx>( self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>, extra_offset: Value, @@ -112,7 +112,7 @@ impl Pointer { } } - pub fn load<'a, 'tcx>( + pub(crate) fn load<'a, 'tcx>( self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>, ty: Type, @@ -130,7 +130,7 @@ impl Pointer { } } - pub fn store<'a, 'tcx>( + pub(crate) fn store<'a, 'tcx>( self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>, value: Value, diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 725df448161..911b215bf13 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -64,13 +64,13 @@ use crate::prelude::*; /// ``` #[derive(Debug)] -pub struct CommentWriter { +pub(crate) struct CommentWriter { global_comments: Vec, entity_comments: HashMap, } impl CommentWriter { - pub fn new<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self { + pub(crate) fn new<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Self { let global_comments = if cfg!(debug_assertions) { vec![ format!("symbol {}", tcx.symbol_name(instance).name.as_str()), @@ -97,11 +97,11 @@ impl CommentWriter { #[cfg(debug_assertions)] impl CommentWriter { - pub fn add_global_comment>(&mut self, comment: S) { + pub(crate) fn add_global_comment>(&mut self, comment: S) { self.global_comments.push(comment.into()); } - pub fn add_comment + AsRef, E: Into>( + pub(crate) fn add_comment + AsRef, E: Into>( &mut self, entity: E, comment: S, @@ -186,11 +186,11 @@ impl FuncWriter for &'_ CommentWriter { #[cfg(debug_assertions)] impl<'a, 'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> { - pub fn add_global_comment>(&mut self, comment: S) { + pub(crate) fn add_global_comment>(&mut self, comment: S) { self.clif_comments.add_global_comment(comment); } - pub fn add_comment + AsRef, E: Into>( + pub(crate) fn add_comment + AsRef, E: Into>( &mut self, entity: E, comment: S, @@ -200,7 +200,7 @@ impl<'a, 'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> { } #[cfg(debug_assertions)] -pub fn write_clif_file<'tcx>( +pub(crate) fn write_clif_file<'tcx>( tcx: TyCtxt<'tcx>, postfix: &str, instance: Instance<'tcx>, diff --git a/src/target_features_whitelist.rs b/src/target_features_whitelist.rs index cbc88fc6b51..de433cca514 100644 --- a/src/target_features_whitelist.rs +++ b/src/target_features_whitelist.rs @@ -115,7 +115,7 @@ const WASM_WHITELIST: &[(&str, Option)] = &[ /// /// IMPORTANT: If you're adding another whitelist to the above lists, make sure to add it to this /// iterator! -pub fn all_known_features() -> impl Iterator)> { +pub(crate) fn all_known_features() -> impl Iterator)> { ARM_WHITELIST .iter() .cloned() @@ -127,7 +127,7 @@ pub fn all_known_features() -> impl Iterator &'static [(&'static str, Option)] { +pub(crate) fn target_feature_whitelist(sess: &Session) -> &'static [(&'static str, Option)] { match &*sess.target.target.arch { "arm" => ARM_WHITELIST, "aarch64" => AARCH64_WHITELIST, diff --git a/src/trap.rs b/src/trap.rs index c13260424ff..d63e86db29d 100644 --- a/src/trap.rs +++ b/src/trap.rs @@ -55,7 +55,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, ms /// Use this when `rustc_codegen_llvm` would insert a call to the panic handler. /// /// Trap code: user0 -pub fn trap_panic( +pub(crate) fn trap_panic( fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: impl AsRef, ) { @@ -67,7 +67,7 @@ pub fn trap_panic( /// so you can **not** add instructions to it afterwards. /// /// Trap code: user65535 -pub fn trap_unreachable( +pub(crate) fn trap_unreachable( fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: impl AsRef, ) { @@ -78,7 +78,7 @@ pub fn trap_unreachable( /// Like `trap_unreachable` but returns a fake value of the specified type. /// /// Trap code: user65535 -pub fn trap_unreachable_ret_value<'tcx>( +pub(crate) fn trap_unreachable_ret_value<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl cranelift_module::Backend>, dest_layout: TyLayout<'tcx>, msg: impl AsRef, @@ -92,7 +92,7 @@ pub fn trap_unreachable_ret_value<'tcx>( /// to it afterwards. /// /// Trap code: user65535 -pub fn trap_unimplemented( +pub(crate) fn trap_unimplemented( fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: impl AsRef, ) { @@ -104,7 +104,7 @@ pub fn trap_unimplemented( /// Like `trap_unimplemented` but returns a fake value of the specified type. /// /// Trap code: user65535 -pub fn trap_unimplemented_ret_value<'tcx>( +pub(crate) fn trap_unimplemented_ret_value<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl cranelift_module::Backend>, dest_layout: TyLayout<'tcx>, msg: impl AsRef, diff --git a/src/unsize.rs b/src/unsize.rs index 9d2e73714fc..d6a85deda78 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -8,7 +8,7 @@ use crate::prelude::*; /// The `old_info` argument is a bit funny. It is intended for use /// in an upcast, where the new vtable for an object will be derived /// from the old one. -pub fn unsized_info<'tcx>( +pub(crate) fn unsized_info<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, source: Ty<'tcx>, target: Ty<'tcx>, @@ -84,7 +84,7 @@ fn unsize_thin_ptr<'tcx>( /// Coerce `src`, which is a reference to a value of type `src_ty`, /// to a value of type `dst_ty` and store the result in `dst` -pub fn coerce_unsized_into<'tcx>( +pub(crate) fn coerce_unsized_into<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, src: CValue<'tcx>, dst: CPlace<'tcx>, @@ -137,7 +137,7 @@ pub fn coerce_unsized_into<'tcx>( // Adapted from https://github.com/rust-lang/rust/blob/2a663555ddf36f6b041445894a8c175cd1bc718c/src/librustc_codegen_ssa/glue.rs -pub fn size_and_align_of_dst<'tcx>( +pub(crate) fn size_and_align_of_dst<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, layout: TyLayout<'tcx>, info: Value, diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 64d585e8a99..41fe85795c2 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -62,7 +62,7 @@ fn scalar_pair_calculate_b_offset(tcx: TyCtxt<'_>, a_scalar: &Scalar, b_scalar: /// A read-only value #[derive(Debug, Copy, Clone)] -pub struct CValue<'tcx>(CValueInner, TyLayout<'tcx>); +pub(crate) struct CValue<'tcx>(CValueInner, TyLayout<'tcx>); #[derive(Debug, Copy, Clone)] enum CValueInner { @@ -72,28 +72,28 @@ enum CValueInner { } impl<'tcx> CValue<'tcx> { - pub fn by_ref(ptr: Pointer, layout: TyLayout<'tcx>) -> CValue<'tcx> { + pub(crate) fn by_ref(ptr: Pointer, layout: TyLayout<'tcx>) -> CValue<'tcx> { CValue(CValueInner::ByRef(ptr, None), layout) } - pub fn by_ref_unsized(ptr: Pointer, meta: Value, layout: TyLayout<'tcx>) -> CValue<'tcx> { + pub(crate) fn by_ref_unsized(ptr: Pointer, meta: Value, layout: TyLayout<'tcx>) -> CValue<'tcx> { CValue(CValueInner::ByRef(ptr, Some(meta)), layout) } - pub fn by_val(value: Value, layout: TyLayout<'tcx>) -> CValue<'tcx> { + pub(crate) fn by_val(value: Value, layout: TyLayout<'tcx>) -> CValue<'tcx> { CValue(CValueInner::ByVal(value), layout) } - pub fn by_val_pair(value: Value, extra: Value, layout: TyLayout<'tcx>) -> CValue<'tcx> { + pub(crate) fn by_val_pair(value: Value, extra: Value, layout: TyLayout<'tcx>) -> CValue<'tcx> { CValue(CValueInner::ByValPair(value, extra), layout) } - pub fn layout(&self) -> TyLayout<'tcx> { + pub(crate) fn layout(&self) -> TyLayout<'tcx> { self.1 } // FIXME remove - pub fn force_stack<'a>(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> (Pointer, Option) { + pub(crate) fn force_stack<'a>(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> (Pointer, Option) { let layout = self.1; match self.0 { CValueInner::ByRef(ptr, meta) => (ptr, meta), @@ -105,7 +105,7 @@ impl<'tcx> CValue<'tcx> { } } - pub fn try_to_ptr(self) -> Option<(Pointer, Option)> { + pub(crate) fn try_to_ptr(self) -> Option<(Pointer, Option)> { match self.0 { CValueInner::ByRef(ptr, meta) => Some((ptr, meta)), CValueInner::ByVal(_) | CValueInner::ByValPair(_, _) => None, @@ -113,7 +113,7 @@ impl<'tcx> CValue<'tcx> { } /// Load a value with layout.abi of scalar - pub fn load_scalar<'a>(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> Value { + pub(crate) fn load_scalar<'a>(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> Value { let layout = self.1; match self.0 { CValueInner::ByRef(ptr, None) => { @@ -134,7 +134,7 @@ impl<'tcx> CValue<'tcx> { } /// Load a value pair with layout.abi of scalar pair - pub fn load_scalar_pair<'a>( + pub(crate) fn load_scalar_pair<'a>( self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, ) -> (Value, Value) { @@ -158,7 +158,7 @@ impl<'tcx> CValue<'tcx> { } } - pub fn value_field<'a>( + pub(crate) fn value_field<'a>( self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, field: mir::Field, @@ -187,16 +187,18 @@ impl<'tcx> CValue<'tcx> { } } - pub fn unsize_value<'a>(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, dest: CPlace<'tcx>) { + pub(crate) fn unsize_value<'a>(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, dest: CPlace<'tcx>) { crate::unsize::coerce_unsized_into(fx, self, dest); } /// If `ty` is signed, `const_val` must already be sign extended. - pub fn const_val( + pub(crate) fn const_val( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, layout: TyLayout<'tcx>, const_val: u128, ) -> CValue<'tcx> { + use cranelift_codegen::ir::immediates::{Ieee32, Ieee64}; + let clif_ty = fx.clif_type(layout.ty).unwrap(); match layout.ty.kind { @@ -241,42 +243,42 @@ impl<'tcx> CValue<'tcx> { CValue::by_val(val, layout) } - pub fn unchecked_cast_to(self, layout: TyLayout<'tcx>) -> Self { + pub(crate) fn unchecked_cast_to(self, layout: TyLayout<'tcx>) -> Self { CValue(self.0, layout) } } /// A place where you can write a value to or read a value from #[derive(Debug, Copy, Clone)] -pub struct CPlace<'tcx> { +pub(crate) struct CPlace<'tcx> { inner: CPlaceInner, layout: TyLayout<'tcx>, } #[derive(Debug, Copy, Clone)] -pub enum CPlaceInner { +pub(crate) enum CPlaceInner { Var(Local), Addr(Pointer, Option), NoPlace, } impl<'tcx> CPlace<'tcx> { - pub fn layout(&self) -> TyLayout<'tcx> { + pub(crate) fn layout(&self) -> TyLayout<'tcx> { self.layout } - pub fn inner(&self) -> &CPlaceInner { + pub(crate) fn inner(&self) -> &CPlaceInner { &self.inner } - pub fn no_place(layout: TyLayout<'tcx>) -> CPlace<'tcx> { + pub(crate) fn no_place(layout: TyLayout<'tcx>) -> CPlace<'tcx> { CPlace { inner: CPlaceInner::NoPlace, layout, } } - pub fn new_stack_slot( + pub(crate) fn new_stack_slot( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, layout: TyLayout<'tcx>, ) -> CPlace<'tcx> { @@ -299,7 +301,7 @@ impl<'tcx> CPlace<'tcx> { } } - pub fn new_var( + pub(crate) fn new_var( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, local: Local, layout: TyLayout<'tcx>, @@ -312,21 +314,21 @@ impl<'tcx> CPlace<'tcx> { } } - pub fn for_ptr(ptr: Pointer, layout: TyLayout<'tcx>) -> CPlace<'tcx> { + pub(crate) fn for_ptr(ptr: Pointer, layout: TyLayout<'tcx>) -> CPlace<'tcx> { CPlace { inner: CPlaceInner::Addr(ptr, None), layout, } } - pub fn for_ptr_with_extra(ptr: Pointer, extra: Value, layout: TyLayout<'tcx>) -> CPlace<'tcx> { + pub(crate) fn for_ptr_with_extra(ptr: Pointer, extra: Value, layout: TyLayout<'tcx>) -> CPlace<'tcx> { CPlace { inner: CPlaceInner::Addr(ptr, Some(extra)), layout, } } - pub fn to_cvalue(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> CValue<'tcx> { + pub(crate) fn to_cvalue(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> CValue<'tcx> { let layout = self.layout(); match self.inner { CPlaceInner::Var(var) => { @@ -348,14 +350,14 @@ impl<'tcx> CPlace<'tcx> { } } - pub fn to_ptr(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> Pointer { + pub(crate) fn to_ptr(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> Pointer { match self.to_ptr_maybe_unsized(fx) { (ptr, None) => ptr, (_, Some(_)) => bug!("Expected sized cplace, found {:?}", self), } } - pub fn to_ptr_maybe_unsized( + pub(crate) fn to_ptr_maybe_unsized( self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, ) -> (Pointer, Option) { @@ -371,7 +373,7 @@ impl<'tcx> CPlace<'tcx> { } } - pub fn write_cvalue(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, from: CValue<'tcx>) { + pub(crate) fn write_cvalue(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, from: CValue<'tcx>) { #[cfg(debug_assertions)] { use cranelift_codegen::cursor::{Cursor, CursorPosition}; @@ -516,7 +518,7 @@ impl<'tcx> CPlace<'tcx> { } } - pub fn place_field( + pub(crate) fn place_field( self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, field: mir::Field, @@ -532,7 +534,7 @@ impl<'tcx> CPlace<'tcx> { } } - pub fn place_index( + pub(crate) fn place_index( self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, index: Value, @@ -551,7 +553,7 @@ impl<'tcx> CPlace<'tcx> { CPlace::for_ptr(ptr.offset_value(fx, offset), elem_layout) } - pub fn place_deref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> CPlace<'tcx> { + pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> CPlace<'tcx> { let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap().ty); if has_ptr_meta(fx.tcx, inner_layout.ty) { let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx); @@ -561,7 +563,7 @@ impl<'tcx> CPlace<'tcx> { } } - pub fn write_place_ref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, dest: CPlace<'tcx>) { + pub(crate) fn write_place_ref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, dest: CPlace<'tcx>) { if has_ptr_meta(fx.tcx, self.layout().ty) { let (ptr, extra) = self.to_ptr_maybe_unsized(fx); let ptr = CValue::by_val_pair( @@ -576,7 +578,7 @@ impl<'tcx> CPlace<'tcx> { } } - pub fn unchecked_cast_to(self, layout: TyLayout<'tcx>) -> Self { + pub(crate) fn unchecked_cast_to(self, layout: TyLayout<'tcx>) -> Self { assert!(!self.layout().is_unsized()); match self.inner { CPlaceInner::NoPlace => { @@ -590,7 +592,7 @@ impl<'tcx> CPlace<'tcx> { } } - pub fn downcast_variant( + pub(crate) fn downcast_variant( self, fx: &FunctionCx<'_, 'tcx, impl Backend>, variant: VariantIdx, diff --git a/src/vtable.rs b/src/vtable.rs index 28688fee049..127e4ce79a6 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -12,7 +12,7 @@ fn vtable_memflags() -> MemFlags { flags } -pub fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value { +pub(crate) fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value { let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize; fx.bcx.ins().load( pointer_ty(fx.tcx), @@ -22,7 +22,7 @@ pub fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) ) } -pub fn size_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value { +pub(crate) fn size_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value { let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize; fx.bcx.ins().load( pointer_ty(fx.tcx), @@ -32,7 +32,7 @@ pub fn size_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> ) } -pub fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value { +pub(crate) fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value { let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize; fx.bcx.ins().load( pointer_ty(fx.tcx), @@ -42,7 +42,7 @@ pub fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value ) } -pub fn get_ptr_and_method_ref<'tcx>( +pub(crate) fn get_ptr_and_method_ref<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, arg: CValue<'tcx>, idx: usize, @@ -67,7 +67,7 @@ pub fn get_ptr_and_method_ref<'tcx>( (ptr, func_ref) } -pub fn get_vtable<'tcx>( +pub(crate) fn get_vtable<'tcx>( fx: &mut FunctionCx<'_, 'tcx, impl Backend>, layout: TyLayout<'tcx>, trait_ref: Option>,