1
Fork 0

Rollup merge of #137247 - dpaoliello:cleanllvm, r=Zalathar

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

Final part of #135502

Reduces the visibility of types, modules and using declarations in the `rustc_codegen_llvm` to private or `pub(crate)` where possible, and marks unused fields and enum entries with `#[expect(dead_code)]`.

r? Zalathar
This commit is contained in:
Matthias Krüger 2025-03-25 18:09:03 +01:00 committed by GitHub
commit b66e9320c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 144 additions and 136 deletions

View file

@ -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(); let mut ptr = NonNull::new(ptr).unwrap();
ThinBuffer(unsafe { ptr.as_mut() }) ThinBuffer(unsafe { ptr.as_mut() })
} }

View file

@ -29,7 +29,7 @@ use back::owned_target_machine::OwnedTargetMachine;
use back::write::{create_informational_target_machine, create_target_machine}; use back::write::{create_informational_target_machine, create_target_machine};
use context::SimpleCx; use context::SimpleCx;
use errors::{AutoDiffWithoutLTO, ParseTargetMachineConfig}; 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::allocator::AllocatorKind;
use rustc_ast::expand::autodiff_attrs::AutoDiffItem; use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule}; use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
@ -71,9 +71,7 @@ mod debuginfo;
mod declare; mod declare;
mod errors; mod errors;
mod intrinsic; mod intrinsic;
// FIXME(Zalathar): Fix all the unreachable-pub warnings that would occur if mod llvm;
// this isn't pub, then make it not pub.
pub mod llvm;
mod llvm_util; mod llvm_util;
mod mono_item; mod mono_item;
mod type_; mod type_;

View file

@ -5,17 +5,17 @@ use std::{slice, str};
use rustc_fs_util::path_to_c_string; use rustc_fs_util::path_to_c_string;
pub struct ArchiveRO { pub(crate) struct ArchiveRO {
pub raw: &'static mut super::Archive, pub raw: &'static mut super::Archive,
} }
unsafe impl Send for ArchiveRO {} unsafe impl Send for ArchiveRO {}
pub struct Iter<'a> { pub(crate) struct Iter<'a> {
raw: &'a mut super::ArchiveIterator<'a>, raw: &'a mut super::ArchiveIterator<'a>,
} }
pub struct Child<'a> { pub(crate) struct Child<'a> {
pub raw: &'a mut super::ArchiveChild<'a>, pub raw: &'a mut super::ArchiveChild<'a>,
} }

View file

@ -3,13 +3,13 @@
use libc::c_uint; use libc::c_uint;
use rustc_span::InnerSpan; use rustc_span::InnerSpan;
pub use self::Diagnostic::*; pub(crate) use self::Diagnostic::*;
pub use self::OptimizationDiagnosticKind::*; use self::OptimizationDiagnosticKind::*;
use super::{DiagnosticInfo, SMDiagnostic}; use super::{DiagnosticInfo, SMDiagnostic};
use crate::value::Value; use crate::value::Value;
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum OptimizationDiagnosticKind { pub(crate) enum OptimizationDiagnosticKind {
OptimizationRemark, OptimizationRemark,
OptimizationMissed, OptimizationMissed,
OptimizationAnalysis, OptimizationAnalysis,
@ -19,9 +19,10 @@ pub enum OptimizationDiagnosticKind {
OptimizationRemarkOther, OptimizationRemarkOther,
} }
pub struct OptimizationDiagnostic<'ll> { pub(crate) struct OptimizationDiagnostic<'ll> {
pub kind: OptimizationDiagnosticKind, pub kind: OptimizationDiagnosticKind,
pub pass_name: String, pub pass_name: String,
#[expect(dead_code)]
pub function: &'ll Value, pub function: &'ll Value,
pub line: c_uint, pub line: c_uint,
pub column: c_uint, pub column: c_uint,
@ -73,14 +74,14 @@ impl<'ll> OptimizationDiagnostic<'ll> {
} }
} }
pub struct SrcMgrDiagnostic { pub(crate) struct SrcMgrDiagnostic {
pub level: super::DiagnosticLevel, pub level: super::DiagnosticLevel,
pub message: String, pub message: String,
pub source: Option<(String, Vec<InnerSpan>)>, pub source: Option<(String, Vec<InnerSpan>)>,
} }
impl SrcMgrDiagnostic { 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 // Recover the post-substitution assembly code from LLVM for better
// diagnostics. // diagnostics.
let mut have_source = false; let mut have_source = false;
@ -120,7 +121,7 @@ impl SrcMgrDiagnostic {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct InlineAsmDiagnostic { pub(crate) struct InlineAsmDiagnostic {
pub level: super::DiagnosticLevel, pub level: super::DiagnosticLevel,
pub cookie: u64, pub cookie: u64,
pub message: String, pub message: String,
@ -158,7 +159,7 @@ impl InlineAsmDiagnostic {
} }
} }
pub enum Diagnostic<'ll> { pub(crate) enum Diagnostic<'ll> {
Optimization(OptimizationDiagnostic<'ll>), Optimization(OptimizationDiagnostic<'ll>),
InlineAsm(InlineAsmDiagnostic), InlineAsm(InlineAsmDiagnostic),
PGO(&'ll DiagnosticInfo), PGO(&'ll DiagnosticInfo),
@ -166,11 +167,12 @@ pub enum Diagnostic<'ll> {
Unsupported(&'ll DiagnosticInfo), Unsupported(&'ll DiagnosticInfo),
/// LLVM has other types that we do not wrap here. /// LLVM has other types that we do not wrap here.
#[expect(dead_code)]
UnknownDiagnostic(&'ll DiagnosticInfo), UnknownDiagnostic(&'ll DiagnosticInfo),
} }
impl<'ll> Diagnostic<'ll> { 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; use super::DiagnosticKind as Dk;
unsafe { unsafe {

View file

@ -31,20 +31,20 @@ unsafe extern "C" {
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
pub enum LLVMRustVerifierFailureAction { pub(crate) enum LLVMRustVerifierFailureAction {
LLVMAbortProcessAction = 0, LLVMAbortProcessAction = 0,
LLVMPrintMessageAction = 1, LLVMPrintMessageAction = 1,
LLVMReturnStatusAction = 2, LLVMReturnStatusAction = 2,
} }
#[cfg(llvm_enzyme)] #[cfg(llvm_enzyme)]
pub use self::Enzyme_AD::*; pub(crate) use self::Enzyme_AD::*;
#[cfg(llvm_enzyme)] #[cfg(llvm_enzyme)]
pub mod Enzyme_AD { pub(crate) mod Enzyme_AD {
use libc::c_void; use libc::c_void;
unsafe extern "C" { 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" { unsafe extern "C" {
static mut EnzymePrintPerf: c_void; static mut EnzymePrintPerf: c_void;
@ -56,42 +56,42 @@ pub mod Enzyme_AD {
static mut EnzymeInline: c_void; static mut EnzymeInline: c_void;
static mut RustTypeRules: c_void; static mut RustTypeRules: c_void;
} }
pub fn set_print_perf(print: bool) { pub(crate) fn set_print_perf(print: bool) {
unsafe { unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintPerf), print as u8); 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 { unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintActivity), print as u8); 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 { unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintType), print as u8); EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintType), print as u8);
} }
} }
pub fn set_print(print: bool) { pub(crate) fn set_print(print: bool) {
unsafe { unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrint), print as u8); 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 { unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeStrictAliasing), strict as u8); 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 { unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(looseTypeAnalysis), loose as u8); EnzymeSetCLBool(std::ptr::addr_of_mut!(looseTypeAnalysis), loose as u8);
} }
} }
pub fn set_inline(val: bool) { pub(crate) fn set_inline(val: bool) {
unsafe { unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeInline), val as u8); 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 { unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(RustTypeRules), val as u8); EnzymeSetCLBool(std::ptr::addr_of_mut!(RustTypeRules), val as u8);
} }
@ -99,34 +99,34 @@ pub mod Enzyme_AD {
} }
#[cfg(not(llvm_enzyme))] #[cfg(not(llvm_enzyme))]
pub use self::Fallback_AD::*; pub(crate) use self::Fallback_AD::*;
#[cfg(not(llvm_enzyme))] #[cfg(not(llvm_enzyme))]
pub mod Fallback_AD { pub(crate) mod Fallback_AD {
#![allow(unused_variables)] #![allow(unused_variables)]
pub fn set_inline(val: bool) { pub(crate) fn set_inline(val: bool) {
unimplemented!() unimplemented!()
} }
pub fn set_print_perf(print: bool) { pub(crate) fn set_print_perf(print: bool) {
unimplemented!() unimplemented!()
} }
pub fn set_print_activity(print: bool) { pub(crate) fn set_print_activity(print: bool) {
unimplemented!() unimplemented!()
} }
pub fn set_print_type(print: bool) { pub(crate) fn set_print_type(print: bool) {
unimplemented!() unimplemented!()
} }
pub fn set_print(print: bool) { pub(crate) fn set_print(print: bool) {
unimplemented!() unimplemented!()
} }
pub fn set_strict_aliasing(strict: bool) { pub(crate) fn set_strict_aliasing(strict: bool) {
unimplemented!() unimplemented!()
} }
pub fn set_loose_types(loose: bool) { pub(crate) fn set_loose_types(loose: bool) {
unimplemented!() unimplemented!()
} }
pub fn set_rust_rules(val: bool) { pub(crate) fn set_rust_rules(val: bool) {
unimplemented!() unimplemented!()
} }
} }

View file

@ -32,10 +32,10 @@ use crate::llvm;
/// In the LLVM-C API, boolean values are passed as `typedef int LLVMBool`, /// In the LLVM-C API, boolean values are passed as `typedef int LLVMBool`,
/// which has a different ABI from Rust or C++ `bool`. /// which has a different ABI from Rust or C++ `bool`.
pub type Bool = c_int; pub(crate) type Bool = c_int;
pub const True: Bool = 1 as Bool; pub(crate) const True: Bool = 1 as Bool;
pub const False: Bool = 0 as Bool; pub(crate) const False: Bool = 0 as Bool;
/// Wrapper for a raw enum value returned from LLVM's C APIs. /// Wrapper for a raw enum value returned from LLVM's C APIs.
/// ///
@ -44,7 +44,7 @@ pub const False: Bool = 0 as Bool;
/// value and returns it. Instead, return this raw wrapper, then convert to the /// value and returns it. Instead, return this raw wrapper, then convert to the
/// Rust-side enum explicitly. /// Rust-side enum explicitly.
#[repr(transparent)] #[repr(transparent)]
pub struct RawEnum<T> { pub(crate) struct RawEnum<T> {
value: u32, value: u32,
/// We don't own or consume a `T`, but we can produce one. /// We don't own or consume a `T`, but we can produce one.
_rust_side_type: PhantomData<fn() -> T>, _rust_side_type: PhantomData<fn() -> T>,
@ -64,7 +64,7 @@ impl<T: TryFrom<u32>> RawEnum<T> {
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
#[repr(C)] #[repr(C)]
#[allow(dead_code)] // Variants constructed by C++. #[allow(dead_code)] // Variants constructed by C++.
pub enum LLVMRustResult { pub(crate) enum LLVMRustResult {
Success, Success,
Failure, Failure,
} }
@ -83,7 +83,7 @@ pub enum LLVMRustResult {
/// C++ API. /// C++ API.
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
#[repr(C)] #[repr(C)]
pub enum ModuleFlagMergeBehavior { pub(crate) enum ModuleFlagMergeBehavior {
Error = 1, Error = 1,
Warning = 2, Warning = 2,
Require = 3, Require = 3,
@ -101,7 +101,7 @@ pub enum ModuleFlagMergeBehavior {
/// See <https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/CallingConv.h> /// See <https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/CallingConv.h>
#[derive(Copy, Clone, PartialEq, Debug, TryFromU32)] #[derive(Copy, Clone, PartialEq, Debug, TryFromU32)]
#[repr(C)] #[repr(C)]
pub enum CallConv { pub(crate) enum CallConv {
CCallConv = 0, CCallConv = 0,
FastCallConv = 8, FastCallConv = 8,
ColdCallConv = 9, ColdCallConv = 9,
@ -126,7 +126,7 @@ pub enum CallConv {
/// Must match the layout of `LLVMLinkage`. /// Must match the layout of `LLVMLinkage`.
#[derive(Copy, Clone, PartialEq, TryFromU32)] #[derive(Copy, Clone, PartialEq, TryFromU32)]
#[repr(C)] #[repr(C)]
pub enum Linkage { pub(crate) enum Linkage {
ExternalLinkage = 0, ExternalLinkage = 0,
AvailableExternallyLinkage = 1, AvailableExternallyLinkage = 1,
LinkOnceAnyLinkage = 2, LinkOnceAnyLinkage = 2,
@ -153,7 +153,7 @@ pub enum Linkage {
/// Must match the layout of `LLVMVisibility`. /// Must match the layout of `LLVMVisibility`.
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, PartialEq, TryFromU32)] #[derive(Copy, Clone, PartialEq, TryFromU32)]
pub enum Visibility { pub(crate) enum Visibility {
Default = 0, Default = 0,
Hidden = 1, Hidden = 1,
Protected = 2, Protected = 2,
@ -171,8 +171,9 @@ impl Visibility {
/// LLVMUnnamedAddr /// LLVMUnnamedAddr
#[repr(C)] #[repr(C)]
pub enum UnnamedAddr { pub(crate) enum UnnamedAddr {
No, No,
#[expect(dead_code)]
Local, Local,
Global, Global,
} }
@ -180,7 +181,7 @@ pub enum UnnamedAddr {
/// LLVMDLLStorageClass /// LLVMDLLStorageClass
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum DLLStorageClass { pub(crate) enum DLLStorageClass {
#[allow(dead_code)] #[allow(dead_code)]
Default = 0, Default = 0,
DllImport = 1, // Function to be imported from DLL. DllImport = 1, // Function to be imported from DLL.
@ -193,7 +194,8 @@ pub enum DLLStorageClass {
/// though it is not ABI compatible (since it's a C++ enum) /// though it is not ABI compatible (since it's a C++ enum)
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum AttributeKind { #[expect(dead_code, reason = "Some variants are unused, but are kept to match the C++")]
pub(crate) enum AttributeKind {
AlwaysInline = 0, AlwaysInline = 0,
ByVal = 1, ByVal = 1,
Cold = 2, Cold = 2,
@ -241,7 +243,7 @@ pub enum AttributeKind {
/// LLVMIntPredicate /// LLVMIntPredicate
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum IntPredicate { pub(crate) enum IntPredicate {
IntEQ = 32, IntEQ = 32,
IntNE = 33, IntNE = 33,
IntUGT = 34, IntUGT = 34,
@ -275,7 +277,7 @@ impl IntPredicate {
/// LLVMRealPredicate /// LLVMRealPredicate
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum RealPredicate { pub(crate) enum RealPredicate {
RealPredicateFalse = 0, RealPredicateFalse = 0,
RealOEQ = 1, RealOEQ = 1,
RealOGT = 2, RealOGT = 2,
@ -321,7 +323,8 @@ impl RealPredicate {
/// LLVMTypeKind /// LLVMTypeKind
#[derive(Copy, Clone, PartialEq, Debug)] #[derive(Copy, Clone, PartialEq, Debug)]
#[repr(C)] #[repr(C)]
pub enum TypeKind { #[expect(dead_code, reason = "Some variants are unused, but are kept to match LLVM-C")]
pub(crate) enum TypeKind {
Void = 0, Void = 0,
Half = 1, Half = 1,
Float = 2, Float = 2,
@ -373,7 +376,7 @@ impl TypeKind {
/// LLVMAtomicRmwBinOp /// LLVMAtomicRmwBinOp
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum AtomicRmwBinOp { pub(crate) enum AtomicRmwBinOp {
AtomicXchg = 0, AtomicXchg = 0,
AtomicAdd = 1, AtomicAdd = 1,
AtomicSub = 2, AtomicSub = 2,
@ -409,7 +412,7 @@ impl AtomicRmwBinOp {
/// LLVMAtomicOrdering /// LLVMAtomicOrdering
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum AtomicOrdering { pub(crate) enum AtomicOrdering {
#[allow(dead_code)] #[allow(dead_code)]
NotAtomic = 0, NotAtomic = 0,
Unordered = 1, Unordered = 1,
@ -438,7 +441,7 @@ impl AtomicOrdering {
/// LLVMRustFileType /// LLVMRustFileType
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum FileType { pub(crate) enum FileType {
AssemblyFile, AssemblyFile,
ObjectFile, ObjectFile,
} }
@ -446,7 +449,8 @@ pub enum FileType {
/// LLVMMetadataType /// LLVMMetadataType
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum MetadataType { #[expect(dead_code, reason = "Some variants are unused, but are kept to match LLVM-C")]
pub(crate) enum MetadataType {
MD_dbg = 0, MD_dbg = 0,
MD_tbaa = 1, MD_tbaa = 1,
MD_prof = 2, MD_prof = 2,
@ -470,7 +474,7 @@ pub enum MetadataType {
/// LLVMRustAsmDialect /// LLVMRustAsmDialect
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
#[repr(C)] #[repr(C)]
pub enum AsmDialect { pub(crate) enum AsmDialect {
Att, Att,
Intel, Intel,
} }
@ -478,7 +482,7 @@ pub enum AsmDialect {
/// LLVMRustCodeGenOptLevel /// LLVMRustCodeGenOptLevel
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
#[repr(C)] #[repr(C)]
pub enum CodeGenOptLevel { pub(crate) enum CodeGenOptLevel {
None, None,
Less, Less,
Default, Default,
@ -487,7 +491,7 @@ pub enum CodeGenOptLevel {
/// LLVMRustPassBuilderOptLevel /// LLVMRustPassBuilderOptLevel
#[repr(C)] #[repr(C)]
pub enum PassBuilderOptLevel { pub(crate) enum PassBuilderOptLevel {
O0, O0,
O1, O1,
O2, O2,
@ -499,7 +503,7 @@ pub enum PassBuilderOptLevel {
/// LLVMRustOptStage /// LLVMRustOptStage
#[derive(PartialEq)] #[derive(PartialEq)]
#[repr(C)] #[repr(C)]
pub enum OptStage { pub(crate) enum OptStage {
PreLinkNoLTO, PreLinkNoLTO,
PreLinkThinLTO, PreLinkThinLTO,
PreLinkFatLTO, PreLinkFatLTO,
@ -509,7 +513,7 @@ pub enum OptStage {
/// LLVMRustSanitizerOptions /// LLVMRustSanitizerOptions
#[repr(C)] #[repr(C)]
pub struct SanitizerOptions { pub(crate) struct SanitizerOptions {
pub sanitize_address: bool, pub sanitize_address: bool,
pub sanitize_address_recover: bool, pub sanitize_address_recover: bool,
pub sanitize_cfi: bool, pub sanitize_cfi: bool,
@ -530,7 +534,7 @@ pub struct SanitizerOptions {
/// LLVMRustRelocModel /// LLVMRustRelocModel
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
#[repr(C)] #[repr(C)]
pub enum RelocModel { pub(crate) enum RelocModel {
Static, Static,
PIC, PIC,
DynamicNoPic, DynamicNoPic,
@ -542,7 +546,7 @@ pub enum RelocModel {
/// LLVMRustFloatABI /// LLVMRustFloatABI
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
#[repr(C)] #[repr(C)]
pub enum FloatAbi { pub(crate) enum FloatAbi {
Default, Default,
Soft, Soft,
Hard, Hard,
@ -551,7 +555,7 @@ pub enum FloatAbi {
/// LLVMRustCodeModel /// LLVMRustCodeModel
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum CodeModel { pub(crate) enum CodeModel {
Tiny, Tiny,
Small, Small,
Kernel, Kernel,
@ -564,7 +568,7 @@ pub enum CodeModel {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
#[allow(dead_code)] // Variants constructed by C++. #[allow(dead_code)] // Variants constructed by C++.
pub enum DiagnosticKind { pub(crate) enum DiagnosticKind {
Other, Other,
InlineAsm, InlineAsm,
StackSize, StackSize,
@ -587,7 +591,7 @@ pub enum DiagnosticKind {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
#[allow(dead_code)] // Variants constructed by C++. #[allow(dead_code)] // Variants constructed by C++.
pub enum DiagnosticLevel { pub(crate) enum DiagnosticLevel {
Error, Error,
Warning, Warning,
Note, Note,
@ -597,7 +601,7 @@ pub enum DiagnosticLevel {
/// LLVMRustArchiveKind /// LLVMRustArchiveKind
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum ArchiveKind { pub(crate) enum ArchiveKind {
K_GNU, K_GNU,
K_BSD, K_BSD,
K_DARWIN, K_DARWIN,
@ -607,15 +611,15 @@ pub enum ArchiveKind {
unsafe extern "C" { unsafe extern "C" {
// LLVMRustThinLTOData // LLVMRustThinLTOData
pub type ThinLTOData; pub(crate) type ThinLTOData;
// LLVMRustThinLTOBuffer // LLVMRustThinLTOBuffer
pub type ThinLTOBuffer; pub(crate) type ThinLTOBuffer;
} }
/// LLVMRustThinLTOModule /// LLVMRustThinLTOModule
#[repr(C)] #[repr(C)]
pub struct ThinLTOModule { pub(crate) struct ThinLTOModule {
pub identifier: *const c_char, pub identifier: *const c_char,
pub data: *const u8, pub data: *const u8,
pub len: usize, pub len: usize,
@ -624,7 +628,8 @@ pub struct ThinLTOModule {
/// LLVMThreadLocalMode /// LLVMThreadLocalMode
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum ThreadLocalMode { pub(crate) enum ThreadLocalMode {
#[expect(dead_code)]
NotThreadLocal, NotThreadLocal,
GeneralDynamic, GeneralDynamic,
LocalDynamic, LocalDynamic,
@ -635,7 +640,7 @@ pub enum ThreadLocalMode {
/// LLVMRustChecksumKind /// LLVMRustChecksumKind
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum ChecksumKind { pub(crate) enum ChecksumKind {
None, None,
MD5, MD5,
SHA1, SHA1,
@ -645,7 +650,7 @@ pub enum ChecksumKind {
/// LLVMRustMemoryEffects /// LLVMRustMemoryEffects
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum MemoryEffects { pub(crate) enum MemoryEffects {
None, None,
ReadOnly, ReadOnly,
InaccessibleMemOnly, InaccessibleMemOnly,
@ -654,7 +659,8 @@ pub enum MemoryEffects {
/// LLVMOpcode /// LLVMOpcode
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Copy, Clone, PartialEq, Eq)]
#[repr(C)] #[repr(C)]
pub enum Opcode { #[expect(dead_code, reason = "Some variants are unused, but are kept to match LLVM-C")]
pub(crate) enum Opcode {
Ret = 1, Ret = 1,
Br = 2, Br = 2,
Switch = 3, Switch = 3,
@ -735,48 +741,48 @@ struct InvariantOpaque<'a> {
// Opaque pointer types // Opaque pointer types
unsafe extern "C" { unsafe extern "C" {
pub type Module; pub(crate) type Module;
pub type Context; pub(crate) type Context;
pub type Type; pub(crate) type Type;
pub type Value; pub(crate) type Value;
pub type ConstantInt; pub(crate) type ConstantInt;
pub type Attribute; pub(crate) type Attribute;
pub type Metadata; pub(crate) type Metadata;
pub type BasicBlock; pub(crate) type BasicBlock;
pub type Comdat; pub(crate) type Comdat;
} }
#[repr(C)] #[repr(C)]
pub struct Builder<'a>(InvariantOpaque<'a>); pub(crate) struct Builder<'a>(InvariantOpaque<'a>);
#[repr(C)] #[repr(C)]
pub struct PassManager<'a>(InvariantOpaque<'a>); pub(crate) struct PassManager<'a>(InvariantOpaque<'a>);
unsafe extern "C" { unsafe extern "C" {
pub type TargetMachine; pub type TargetMachine;
pub type Archive; pub(crate) type Archive;
} }
#[repr(C)] #[repr(C)]
pub struct ArchiveIterator<'a>(InvariantOpaque<'a>); pub(crate) struct ArchiveIterator<'a>(InvariantOpaque<'a>);
#[repr(C)] #[repr(C)]
pub struct ArchiveChild<'a>(InvariantOpaque<'a>); pub(crate) struct ArchiveChild<'a>(InvariantOpaque<'a>);
unsafe extern "C" { unsafe extern "C" {
pub type Twine; pub(crate) type Twine;
pub type DiagnosticInfo; pub(crate) type DiagnosticInfo;
pub type SMDiagnostic; pub(crate) type SMDiagnostic;
} }
#[repr(C)] #[repr(C)]
pub struct RustArchiveMember<'a>(InvariantOpaque<'a>); pub(crate) struct RustArchiveMember<'a>(InvariantOpaque<'a>);
/// Opaque pointee of `LLVMOperandBundleRef`. /// Opaque pointee of `LLVMOperandBundleRef`.
#[repr(C)] #[repr(C)]
pub(crate) struct OperandBundle<'a>(InvariantOpaque<'a>); pub(crate) struct OperandBundle<'a>(InvariantOpaque<'a>);
#[repr(C)] #[repr(C)]
pub struct Linker<'a>(InvariantOpaque<'a>); pub(crate) struct Linker<'a>(InvariantOpaque<'a>);
unsafe extern "C" { unsafe extern "C" {
pub type DiagnosticHandler; pub(crate) type DiagnosticHandler;
} }
pub type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void); pub(crate) type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
pub mod debuginfo { pub(crate) mod debuginfo {
use std::ptr; use std::ptr;
use bitflags::bitflags; use bitflags::bitflags;
@ -793,7 +799,7 @@ pub mod debuginfo {
/// builder reference typically has a shorter lifetime than the LLVM /// builder reference typically has a shorter lifetime than the LLVM
/// session (`'ll`) that it participates in. /// session (`'ll`) that it participates in.
#[repr(C)] #[repr(C)]
pub struct DIBuilder<'ll>(InvariantOpaque<'ll>); pub(crate) struct DIBuilder<'ll>(InvariantOpaque<'ll>);
/// Owning pointer to a `DIBuilder<'ll>` that will dispose of the builder /// Owning pointer to a `DIBuilder<'ll>` that will dispose of the builder
/// when dropped. Use `.as_ref()` to get the underlying `&DIBuilder` /// when dropped. Use `.as_ref()` to get the underlying `&DIBuilder`
@ -822,22 +828,22 @@ pub mod debuginfo {
} }
} }
pub type DIDescriptor = Metadata; pub(crate) type DIDescriptor = Metadata;
pub type DILocation = Metadata; pub(crate) type DILocation = Metadata;
pub type DIScope = DIDescriptor; pub(crate) type DIScope = DIDescriptor;
pub type DIFile = DIScope; pub(crate) type DIFile = DIScope;
pub type DILexicalBlock = DIScope; pub(crate) type DILexicalBlock = DIScope;
pub type DISubprogram = DIScope; pub(crate) type DISubprogram = DIScope;
pub type DIType = DIDescriptor; pub(crate) type DIType = DIDescriptor;
pub type DIBasicType = DIType; pub(crate) type DIBasicType = DIType;
pub type DIDerivedType = DIType; pub(crate) type DIDerivedType = DIType;
pub type DICompositeType = DIDerivedType; pub(crate) type DICompositeType = DIDerivedType;
pub type DIVariable = DIDescriptor; pub(crate) type DIVariable = DIDescriptor;
pub type DIGlobalVariableExpression = DIDescriptor; pub(crate) type DIGlobalVariableExpression = DIDescriptor;
pub type DIArray = DIDescriptor; pub(crate) type DIArray = DIDescriptor;
pub type DISubrange = DIDescriptor; pub(crate) type DISubrange = DIDescriptor;
pub type DIEnumerator = DIDescriptor; pub(crate) type DIEnumerator = DIDescriptor;
pub type DITemplateTypeParameter = DIDescriptor; pub(crate) type DITemplateTypeParameter = DIDescriptor;
bitflags! { bitflags! {
/// Must match the layout of `LLVMDIFlags` in the LLVM-C API. /// Must match the layout of `LLVMDIFlags` in the LLVM-C API.
@ -846,7 +852,7 @@ pub mod debuginfo {
/// assertions in `RustWrapper.cpp` used by `fromRust(LLVMDIFlags)`. /// assertions in `RustWrapper.cpp` used by `fromRust(LLVMDIFlags)`.
#[repr(transparent)] #[repr(transparent)]
#[derive(Clone, Copy, Default)] #[derive(Clone, Copy, Default)]
pub struct DIFlags: u32 { pub(crate) struct DIFlags: u32 {
const FlagZero = 0; const FlagZero = 0;
const FlagPrivate = 1; const FlagPrivate = 1;
const FlagProtected = 2; const FlagProtected = 2;
@ -886,7 +892,7 @@ pub mod debuginfo {
bitflags! { bitflags! {
#[repr(transparent)] #[repr(transparent)]
#[derive(Clone, Copy, Default)] #[derive(Clone, Copy, Default)]
pub struct DISPFlags: u32 { pub(crate) struct DISPFlags: u32 {
const SPFlagZero = 0; const SPFlagZero = 0;
const SPFlagVirtual = 1; const SPFlagVirtual = 1;
const SPFlagPureVirtual = 2; const SPFlagPureVirtual = 2;
@ -900,7 +906,7 @@ pub mod debuginfo {
/// LLVMRustDebugEmissionKind /// LLVMRustDebugEmissionKind
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub enum DebugEmissionKind { pub(crate) enum DebugEmissionKind {
NoDebug, NoDebug,
FullDebug, FullDebug,
LineTablesOnly, LineTablesOnly,
@ -932,8 +938,9 @@ pub mod debuginfo {
/// LLVMRustDebugNameTableKind /// LLVMRustDebugNameTableKind
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
#[repr(C)] #[repr(C)]
pub enum DebugNameTableKind { pub(crate) enum DebugNameTableKind {
Default, Default,
#[expect(dead_code)]
Gnu, Gnu,
None, None,
} }
@ -943,7 +950,7 @@ pub mod debuginfo {
bitflags! { bitflags! {
#[repr(transparent)] #[repr(transparent)]
#[derive(Default)] #[derive(Default)]
pub struct AllocKindFlags : u64 { pub(crate) struct AllocKindFlags : u64 {
const Unknown = 0; const Unknown = 0;
const Alloc = 1; const Alloc = 1;
const Realloc = 1 << 1; const Realloc = 1 << 1;
@ -966,19 +973,20 @@ bitflags! {
} }
unsafe extern "C" { unsafe extern "C" {
pub type ModuleBuffer; pub(crate) type ModuleBuffer;
} }
pub type SelfProfileBeforePassCallback = pub(crate) type SelfProfileBeforePassCallback =
unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char); unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char);
pub type SelfProfileAfterPassCallback = unsafe extern "C" fn(*mut c_void); pub(crate) type SelfProfileAfterPassCallback = unsafe extern "C" fn(*mut c_void);
pub type GetSymbolsCallback = unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void; pub(crate) type GetSymbolsCallback =
pub type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void; unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void;
pub(crate) type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(transparent)] #[repr(transparent)]
pub struct MetadataKindId(c_uint); pub(crate) struct MetadataKindId(c_uint);
impl From<MetadataType> for MetadataKindId { impl From<MetadataType> for MetadataKindId {
fn from(value: MetadataType) -> Self { fn from(value: MetadataType) -> Self {

View file

@ -9,18 +9,18 @@ use libc::c_uint;
use rustc_abi::{Align, Size, WrappingRange}; use rustc_abi::{Align, Size, WrappingRange};
use rustc_llvm::RustString; use rustc_llvm::RustString;
pub use self::CallConv::*; pub(crate) use self::CallConv::*;
pub use self::CodeGenOptSize::*; pub(crate) use self::CodeGenOptSize::*;
pub use self::MetadataType::*; pub(crate) use self::MetadataType::*;
pub use self::ffi::*; pub(crate) use self::ffi::*;
use crate::common::AsCCharPtr; use crate::common::AsCCharPtr;
pub mod archive_ro; pub(crate) mod archive_ro;
pub mod diagnostic; pub(crate) mod diagnostic;
pub mod enzyme_ffi; pub(crate) mod enzyme_ffi;
mod ffi; mod ffi;
pub use self::enzyme_ffi::*; pub(crate) use self::enzyme_ffi::*;
impl LLVMRustResult { impl LLVMRustResult {
pub(crate) fn into_result(self) -> Result<(), ()> { pub(crate) fn into_result(self) -> Result<(), ()> {
@ -127,7 +127,7 @@ pub(crate) fn CreateRangeAttr(llcx: &Context, size: Size, range: WrappingRange)
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum AttributePlace { pub(crate) enum AttributePlace {
ReturnValue, ReturnValue,
Argument(u32), Argument(u32),
Function, Function,
@ -145,7 +145,7 @@ impl AttributePlace {
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
#[repr(C)] #[repr(C)]
pub enum CodeGenOptSize { pub(crate) enum CodeGenOptSize {
CodeGenOptSizeNone = 0, CodeGenOptSizeNone = 0,
CodeGenOptSizeDefault = 1, CodeGenOptSizeDefault = 1,
CodeGenOptSizeAggressive = 2, CodeGenOptSizeAggressive = 2,