Skip to content

Commit 8aff664

Browse files
committed
Clean llvm wrapper
1 parent 8c61cd4 commit 8aff664

File tree

6 files changed

+684
-540
lines changed

6 files changed

+684
-540
lines changed

compiler/rustc_codegen_llvm/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ mod debuginfo;
7272
mod declare;
7373
mod errors;
7474
mod intrinsic;
75-
// FIXME(Zalathar): Fix all the unreachable-pub warnings that would occur if
76-
// this isn't pub, then make it not pub.
77-
pub mod llvm;
75+
pub(crate) mod llvm;
7876
mod llvm_util;
7977
mod mono_item;
8078
mod type_;

compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ use std::{slice, str};
55

66
use rustc_fs_util::path_to_c_string;
77

8-
pub struct ArchiveRO {
8+
pub(crate) struct ArchiveRO {
99
pub raw: &'static mut super::Archive,
1010
}
1111

1212
unsafe impl Send for ArchiveRO {}
1313

14-
pub struct Iter<'a> {
14+
pub(crate) struct Iter<'a> {
1515
raw: &'a mut super::ArchiveIterator<'a>,
1616
}
1717

18-
pub struct Child<'a> {
18+
pub(crate) struct Child<'a> {
1919
pub raw: &'a mut super::ArchiveChild<'a>,
2020
}
2121

@@ -26,7 +26,7 @@ impl ArchiveRO {
2626
///
2727
/// If this archive is used with a mutable method, then an error will be
2828
/// raised.
29-
pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
29+
pub(crate) fn open(dst: &Path) -> Result<ArchiveRO, String> {
3030
unsafe {
3131
let s = path_to_c_string(dst);
3232
let ar = super::LLVMRustOpenArchive(s.as_ptr()).ok_or_else(|| {
@@ -36,7 +36,7 @@ impl ArchiveRO {
3636
}
3737
}
3838

39-
pub fn iter(&self) -> Iter<'_> {
39+
pub(crate) fn iter(&self) -> Iter<'_> {
4040
unsafe { Iter { raw: super::LLVMRustArchiveIteratorNew(self.raw) } }
4141
}
4242
}
@@ -71,7 +71,7 @@ impl<'a> Drop for Iter<'a> {
7171
}
7272

7373
impl<'a> Child<'a> {
74-
pub fn name(&self) -> Option<&'a str> {
74+
pub(crate) fn name(&self) -> Option<&'a str> {
7575
unsafe {
7676
let mut name_len = 0;
7777
let name_ptr = super::LLVMRustArchiveChildName(self.raw, &mut name_len);

compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
use libc::c_uint;
44
use rustc_span::InnerSpan;
55

6-
pub use self::Diagnostic::*;
7-
pub use self::OptimizationDiagnosticKind::*;
6+
pub(crate) use self::Diagnostic::*;
7+
pub(crate) use self::OptimizationDiagnosticKind::*;
88
use super::{DiagnosticInfo, SMDiagnostic};
99
use crate::value::Value;
1010

1111
#[derive(Copy, Clone, Debug)]
12-
pub enum OptimizationDiagnosticKind {
12+
pub(crate) enum OptimizationDiagnosticKind {
1313
OptimizationRemark,
1414
OptimizationMissed,
1515
OptimizationAnalysis,
@@ -19,9 +19,10 @@ pub enum OptimizationDiagnosticKind {
1919
OptimizationRemarkOther,
2020
}
2121

22-
pub struct OptimizationDiagnostic<'ll> {
22+
pub(crate) struct OptimizationDiagnostic<'ll> {
2323
pub kind: OptimizationDiagnosticKind,
2424
pub pass_name: String,
25+
#[expect(dead_code)]
2526
pub function: &'ll Value,
2627
pub line: c_uint,
2728
pub column: c_uint,
@@ -73,14 +74,14 @@ impl<'ll> OptimizationDiagnostic<'ll> {
7374
}
7475
}
7576

76-
pub struct SrcMgrDiagnostic {
77+
pub(crate) struct SrcMgrDiagnostic {
7778
pub level: super::DiagnosticLevel,
7879
pub message: String,
7980
pub source: Option<(String, Vec<InnerSpan>)>,
8081
}
8182

8283
impl SrcMgrDiagnostic {
83-
pub unsafe fn unpack(diag: &SMDiagnostic) -> SrcMgrDiagnostic {
84+
pub(crate) unsafe fn unpack(diag: &SMDiagnostic) -> SrcMgrDiagnostic {
8485
// Recover the post-substitution assembly code from LLVM for better
8586
// diagnostics.
8687
let mut have_source = false;
@@ -120,7 +121,7 @@ impl SrcMgrDiagnostic {
120121
}
121122

122123
#[derive(Clone)]
123-
pub struct InlineAsmDiagnostic {
124+
pub(crate) struct InlineAsmDiagnostic {
124125
pub level: super::DiagnosticLevel,
125126
pub cookie: u64,
126127
pub message: String,
@@ -158,19 +159,20 @@ impl InlineAsmDiagnostic {
158159
}
159160
}
160161

161-
pub enum Diagnostic<'ll> {
162+
pub(crate) enum Diagnostic<'ll> {
162163
Optimization(OptimizationDiagnostic<'ll>),
163164
InlineAsm(InlineAsmDiagnostic),
164165
PGO(&'ll DiagnosticInfo),
165166
Linker(&'ll DiagnosticInfo),
166167
Unsupported(&'ll DiagnosticInfo),
167168

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

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

176178
unsafe {

compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(non_camel_case_types)]
2+
#![expect(dead_code)]
23

34
use libc::{c_char, c_uint};
45

@@ -8,28 +9,28 @@ use crate::llvm::Bool;
89
#[link(name = "llvm-wrapper", kind = "static")]
910
extern "C" {
1011
// Enzyme
11-
pub fn LLVMRustHasMetadata(I: &Value, KindID: c_uint) -> bool;
12-
pub fn LLVMRustEraseInstUntilInclusive(BB: &BasicBlock, I: &Value);
13-
pub fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>;
14-
pub fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>;
15-
pub fn LLVMRustEraseInstFromParent(V: &Value);
16-
pub fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
17-
pub fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool;
12+
pub(crate) fn LLVMRustHasMetadata(I: &Value, KindID: c_uint) -> bool;
13+
pub(crate) fn LLVMRustEraseInstUntilInclusive(BB: &BasicBlock, I: &Value);
14+
pub(crate) fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>;
15+
pub(crate) fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>;
16+
pub(crate) fn LLVMRustEraseInstFromParent(V: &Value);
17+
pub(crate) fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
18+
pub(crate) fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool;
1819
}
1920

2021
extern "C" {
2122
// Enzyme
22-
pub fn LLVMDumpModule(M: &Module);
23-
pub fn LLVMDumpValue(V: &Value);
24-
pub fn LLVMGetFunctionCallConv(F: &Value) -> c_uint;
25-
pub fn LLVMGetReturnType(T: &Type) -> &Type;
26-
pub fn LLVMGetParams(Fnc: &Value, parms: *mut &Value);
27-
pub fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>;
23+
pub(crate) fn LLVMDumpModule(M: &Module);
24+
pub(crate) fn LLVMDumpValue(V: &Value);
25+
pub(crate) fn LLVMGetFunctionCallConv(F: &Value) -> c_uint;
26+
pub(crate) fn LLVMGetReturnType(T: &Type) -> &Type;
27+
pub(crate) fn LLVMGetParams(Fnc: &Value, parms: *mut &Value);
28+
pub(crate) fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>;
2829
}
2930

3031
#[repr(C)]
3132
#[derive(Copy, Clone, PartialEq)]
32-
pub enum LLVMRustVerifierFailureAction {
33+
pub(crate) enum LLVMRustVerifierFailureAction {
3334
LLVMAbortProcessAction = 0,
3435
LLVMPrintMessageAction = 1,
3536
LLVMReturnStatusAction = 2,

0 commit comments

Comments
 (0)