Skip to content

cg_llvm: Reduce the visibility of types, modules and using declarations in rustc_codegen_llvm. #137247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ impl ThinBuffer {
}
}

pub unsafe fn from_raw_ptr(ptr: *mut llvm::ThinLTOBuffer) -> ThinBuffer {
pub(crate) unsafe fn from_raw_ptr(ptr: *mut llvm::ThinLTOBuffer) -> ThinBuffer {
let mut ptr = NonNull::new(ptr).unwrap();
ThinBuffer(unsafe { ptr.as_mut() })
}
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use back::owned_target_machine::OwnedTargetMachine;
use back::write::{create_informational_target_machine, create_target_machine};
use context::SimpleCx;
use errors::{AutoDiffWithoutLTO, ParseTargetMachineConfig};
pub(crate) use llvm_util::target_features_cfg;
use llvm_util::target_features_cfg;
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
Expand Down Expand Up @@ -71,9 +71,7 @@ mod debuginfo;
mod declare;
mod errors;
mod intrinsic;
// FIXME(Zalathar): Fix all the unreachable-pub warnings that would occur if
// this isn't pub, then make it not pub.
pub mod llvm;
mod llvm;
mod llvm_util;
mod mono_item;
mod type_;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ use std::{slice, str};

use rustc_fs_util::path_to_c_string;

pub struct ArchiveRO {
pub(crate) struct ArchiveRO {
pub raw: &'static mut super::Archive,
}

unsafe impl Send for ArchiveRO {}

pub struct Iter<'a> {
pub(crate) struct Iter<'a> {
raw: &'a mut super::ArchiveIterator<'a>,
}

pub struct Child<'a> {
pub(crate) struct Child<'a> {
pub raw: &'a mut super::ArchiveChild<'a>,
}

Expand Down
20 changes: 11 additions & 9 deletions compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
use libc::c_uint;
use rustc_span::InnerSpan;

pub use self::Diagnostic::*;
pub use self::OptimizationDiagnosticKind::*;
pub(crate) use self::Diagnostic::*;
use self::OptimizationDiagnosticKind::*;
use super::{DiagnosticInfo, SMDiagnostic};
use crate::value::Value;

#[derive(Copy, Clone, Debug)]
pub enum OptimizationDiagnosticKind {
pub(crate) enum OptimizationDiagnosticKind {
OptimizationRemark,
OptimizationMissed,
OptimizationAnalysis,
Expand All @@ -19,9 +19,10 @@ pub enum OptimizationDiagnosticKind {
OptimizationRemarkOther,
}

pub struct OptimizationDiagnostic<'ll> {
pub(crate) struct OptimizationDiagnostic<'ll> {
pub kind: OptimizationDiagnosticKind,
pub pass_name: String,
#[expect(dead_code)]
pub function: &'ll Value,
pub line: c_uint,
pub column: c_uint,
Expand Down Expand Up @@ -73,14 +74,14 @@ impl<'ll> OptimizationDiagnostic<'ll> {
}
}

pub struct SrcMgrDiagnostic {
pub(crate) struct SrcMgrDiagnostic {
pub level: super::DiagnosticLevel,
pub message: String,
pub source: Option<(String, Vec<InnerSpan>)>,
}

impl SrcMgrDiagnostic {
pub unsafe fn unpack(diag: &SMDiagnostic) -> SrcMgrDiagnostic {
pub(crate) unsafe fn unpack(diag: &SMDiagnostic) -> SrcMgrDiagnostic {
// Recover the post-substitution assembly code from LLVM for better
// diagnostics.
let mut have_source = false;
Expand Down Expand Up @@ -120,7 +121,7 @@ impl SrcMgrDiagnostic {
}

#[derive(Clone)]
pub struct InlineAsmDiagnostic {
pub(crate) struct InlineAsmDiagnostic {
pub level: super::DiagnosticLevel,
pub cookie: u64,
pub message: String,
Expand Down Expand Up @@ -158,19 +159,20 @@ impl InlineAsmDiagnostic {
}
}

pub enum Diagnostic<'ll> {
pub(crate) enum Diagnostic<'ll> {
Optimization(OptimizationDiagnostic<'ll>),
InlineAsm(InlineAsmDiagnostic),
PGO(&'ll DiagnosticInfo),
Linker(&'ll DiagnosticInfo),
Unsupported(&'ll DiagnosticInfo),

/// LLVM has other types that we do not wrap here.
#[expect(dead_code)]
UnknownDiagnostic(&'ll DiagnosticInfo),
}

impl<'ll> Diagnostic<'ll> {
pub unsafe fn unpack(di: &'ll DiagnosticInfo) -> Self {
pub(crate) unsafe fn unpack(di: &'ll DiagnosticInfo) -> Self {
use super::DiagnosticKind as Dk;

unsafe {
Expand Down
44 changes: 22 additions & 22 deletions compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ unsafe extern "C" {

#[repr(C)]
#[derive(Copy, Clone, PartialEq)]
pub enum LLVMRustVerifierFailureAction {
pub(crate) enum LLVMRustVerifierFailureAction {
LLVMAbortProcessAction = 0,
LLVMPrintMessageAction = 1,
LLVMReturnStatusAction = 2,
}

#[cfg(llvm_enzyme)]
pub use self::Enzyme_AD::*;
pub(crate) use self::Enzyme_AD::*;

#[cfg(llvm_enzyme)]
pub mod Enzyme_AD {
pub(crate) mod Enzyme_AD {
use libc::c_void;
unsafe extern "C" {
pub fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8);
pub(crate) fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8);
}
unsafe extern "C" {
static mut EnzymePrintPerf: c_void;
Expand All @@ -56,77 +56,77 @@ pub mod Enzyme_AD {
static mut EnzymeInline: c_void;
static mut RustTypeRules: c_void;
}
pub fn set_print_perf(print: bool) {
pub(crate) fn set_print_perf(print: bool) {
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintPerf), print as u8);
}
}
pub fn set_print_activity(print: bool) {
pub(crate) fn set_print_activity(print: bool) {
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintActivity), print as u8);
}
}
pub fn set_print_type(print: bool) {
pub(crate) fn set_print_type(print: bool) {
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintType), print as u8);
}
}
pub fn set_print(print: bool) {
pub(crate) fn set_print(print: bool) {
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrint), print as u8);
}
}
pub fn set_strict_aliasing(strict: bool) {
pub(crate) fn set_strict_aliasing(strict: bool) {
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeStrictAliasing), strict as u8);
}
}
pub fn set_loose_types(loose: bool) {
pub(crate) fn set_loose_types(loose: bool) {
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(looseTypeAnalysis), loose as u8);
}
}
pub fn set_inline(val: bool) {
pub(crate) fn set_inline(val: bool) {
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeInline), val as u8);
}
}
pub fn set_rust_rules(val: bool) {
pub(crate) fn set_rust_rules(val: bool) {
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(RustTypeRules), val as u8);
}
}
}

#[cfg(not(llvm_enzyme))]
pub use self::Fallback_AD::*;
pub(crate) use self::Fallback_AD::*;

#[cfg(not(llvm_enzyme))]
pub mod Fallback_AD {
pub(crate) mod Fallback_AD {
#![allow(unused_variables)]

pub fn set_inline(val: bool) {
pub(crate) fn set_inline(val: bool) {
unimplemented!()
}
pub fn set_print_perf(print: bool) {
pub(crate) fn set_print_perf(print: bool) {
unimplemented!()
}
pub fn set_print_activity(print: bool) {
pub(crate) fn set_print_activity(print: bool) {
unimplemented!()
}
pub fn set_print_type(print: bool) {
pub(crate) fn set_print_type(print: bool) {
unimplemented!()
}
pub fn set_print(print: bool) {
pub(crate) fn set_print(print: bool) {
unimplemented!()
}
pub fn set_strict_aliasing(strict: bool) {
pub(crate) fn set_strict_aliasing(strict: bool) {
unimplemented!()
}
pub fn set_loose_types(loose: bool) {
pub(crate) fn set_loose_types(loose: bool) {
unimplemented!()
}
pub fn set_rust_rules(val: bool) {
pub(crate) fn set_rust_rules(val: bool) {
unimplemented!()
}
}
Loading
Loading