Skip to content

Commit 42614bf

Browse files
committed
Auto merge of rust-lang#142286 - Kobzol:clippy-jemalloc, r=flip1995,blyxyas
Use jemalloc for Clippy The tool macros are annoying, we should IMO just get rid of them, create separate steps for each tool and (re)use some builders in them to share the build code. r? `@ghost`
2 parents 73273f2 + dd0fa3d commit 42614bf

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
5858
[features]
5959
integration = ["dep:tempfile"]
6060
internal = ["dep:clippy_lints_internal", "dep:tempfile"]
61+
jemalloc = []
6162

6263
[package.metadata.rust-analyzer]
6364
# This package uses #[feature(rustc_private)]

src/driver.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ extern crate rustc_interface;
1313
extern crate rustc_session;
1414
extern crate rustc_span;
1515

16+
// See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
17+
// about jemalloc.
18+
#[cfg(feature = "jemalloc")]
19+
extern crate tikv_jemalloc_sys as jemalloc_sys;
20+
1621
use clippy_utils::sym;
1722
use rustc_interface::interface;
1823
use rustc_session::EarlyDiagCtxt;
@@ -181,6 +186,36 @@ const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/ne
181186
#[allow(clippy::too_many_lines)]
182187
#[allow(clippy::ignored_unit_patterns)]
183188
pub fn main() {
189+
// See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
190+
// about jemalloc.
191+
#[cfg(feature = "jemalloc")]
192+
{
193+
use std::os::raw::{c_int, c_void};
194+
195+
#[used]
196+
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
197+
#[used]
198+
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int = jemalloc_sys::posix_memalign;
199+
#[used]
200+
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
201+
#[used]
202+
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
203+
#[used]
204+
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
205+
#[used]
206+
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
207+
208+
#[cfg(target_os = "macos")]
209+
{
210+
unsafe extern "C" {
211+
fn _rjem_je_zone_register();
212+
}
213+
214+
#[used]
215+
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
216+
}
217+
}
218+
184219
let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
185220

186221
rustc_driver::init_rustc_env_logger(&early_dcx);

0 commit comments

Comments
 (0)