Skip to content

Commit

Permalink
Limit publicness to crate where possible and remove unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Mar 27, 2020
1 parent b113e88 commit f288959
Show file tree
Hide file tree
Showing 35 changed files with 225 additions and 231 deletions.
6 changes: 3 additions & 3 deletions src/abi/comments.rs
Expand Up @@ -5,7 +5,7 @@ use rustc::mir;
use crate::abi::pass_mode::*;
use crate::prelude::*;

pub fn add_args_header_comment(fx: &mut FunctionCx<impl Backend>) {
pub(super) fn add_args_header_comment(fx: &mut FunctionCx<impl Backend>) {
fx.add_global_comment(format!(
"kind loc.idx param pass mode ty"
));
Expand Down Expand Up @@ -49,14 +49,14 @@ pub(super) fn add_arg_comment<'tcx>(
));
}

pub fn add_locals_header_comment(fx: &mut FunctionCx<impl Backend>) {
pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<impl Backend>) {
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,
Expand Down
20 changes: 10 additions & 10 deletions src/abi/mod.rs
Expand Up @@ -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(..) |
Expand Down Expand Up @@ -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>,
Expand All @@ -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<impl Backend>,
inst: Instance<'tcx>,
Expand All @@ -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
Expand Down Expand Up @@ -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>],
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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>,
Expand All @@ -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,
Expand Down Expand Up @@ -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>,
Expand Down
4 changes: 2 additions & 2 deletions src/abi/pass_mode.rs
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/abi/returning.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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<impl Backend>) {
pub(crate) fn codegen_return(fx: &mut FunctionCx<impl Backend>) {
match get_pass_mode(fx.tcx, return_layout(fx)) {
PassMode::NoPass | PassMode::ByRef { sized: true } => {
fx.bcx.ins().return_(&[]);
Expand Down
2 changes: 1 addition & 1 deletion src/allocator.rs
Expand Up @@ -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<impl Backend + 'static>) -> bool {
pub(crate) fn codegen(tcx: TyCtxt<'_>, module: &mut Module<impl Backend + 'static>) -> 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)
Expand Down
4 changes: 2 additions & 2 deletions src/analyze.rs
Expand Up @@ -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<Local, SsaKind> {
pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local, SsaKind> {
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
Expand Down
2 changes: 1 addition & 1 deletion src/archive.rs
Expand Up @@ -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<File>)>,
// Don't use `HashMap` here, as the order is important. `rust.metadata.bin` must always be at
Expand Down
6 changes: 3 additions & 3 deletions src/atomic_shim.rs
Expand Up @@ -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<impl Backend>, bcx: &mut FunctionBuilder<'_>) {
pub(crate) fn init_global_lock(module: &mut Module<impl Backend>, 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.
Expand Down Expand Up @@ -46,7 +46,7 @@ pub fn init_global_lock(module: &mut Module<impl Backend>, 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,
Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions src/backend.rs
Expand Up @@ -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<u8>, is_like_osx: bool);
}

Expand All @@ -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<u8>) -> Self::SectionId;
Expand Down Expand Up @@ -99,7 +99,7 @@ impl WriteDebugInfo for ObjectProduct {
}
}

pub trait Emit {
pub(crate) trait Emit {
fn emit(self) -> Vec<u8>;
}

Expand All @@ -109,7 +109,7 @@ impl Emit for ObjectProduct {
}
}

pub fn with_object(sess: &Session, name: &str, f: impl FnOnce(&mut Object)) -> Vec<u8> {
pub(crate) fn with_object(sess: &Session, name: &str, f: impl FnOnce(&mut Object)) -> Vec<u8> {
let triple = crate::build_isa(sess, true).triple().clone();
let mut metadata_object =
object::write::Object::new(triple.binary_format, triple.architecture);
Expand All @@ -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<Product: Emit + WriteDebugInfo>;
pub(crate) type Backend = impl cranelift_module::Backend<Product: Emit + WriteDebugInfo>;

pub fn make_module(sess: &Session, name: String) -> Module<Backend> {
pub(crate) fn make_module(sess: &Session, name: String) -> Module<Backend> {
let module: Module<ObjectBackend> = Module::new(
ObjectBuilder::new(
crate::build_isa(sess, true),
Expand Down
8 changes: 4 additions & 4 deletions src/base.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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> {
Expand Down
4 changes: 2 additions & 2 deletions 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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/codegen_i128.rs
Expand Up @@ -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,
Expand Down

0 comments on commit f288959

Please sign in to comment.