Skip to content

Commit ada5df7

Browse files
authored
Merge pull request #4687 from rust-lang/rustup-2025-11-14
Automatic Rustup
2 parents a395522 + e66f1b0 commit ada5df7

File tree

170 files changed

+3681
-1401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+3681
-1401
lines changed

Cargo.lock

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,6 @@ dependencies = [
600600
"serde_json",
601601
"tempfile",
602602
"termize",
603-
"tikv-jemalloc-sys",
604603
"toml 0.9.7",
605604
"ui_test",
606605
"walkdir",
@@ -1289,7 +1288,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
12891288
checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad"
12901289
dependencies = [
12911290
"libc",
1292-
"windows-sys 0.52.0",
1291+
"windows-sys 0.60.2",
12931292
]
12941293

12951294
[[package]]
@@ -2155,7 +2154,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
21552154
checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667"
21562155
dependencies = [
21572156
"cfg-if",
2158-
"windows-targets 0.52.6",
2157+
"windows-targets 0.53.3",
21592158
]
21602159

21612160
[[package]]
@@ -4807,7 +4806,6 @@ dependencies = [
48074806
"stringdex",
48084807
"tempfile",
48094808
"threadpool",
4810-
"tikv-jemalloc-sys",
48114809
"tracing",
48124810
"tracing-subscriber",
48134811
"tracing-tree",
@@ -4907,7 +4905,7 @@ dependencies = [
49074905
"errno",
49084906
"libc",
49094907
"linux-raw-sys",
4910-
"windows-sys 0.52.0",
4908+
"windows-sys 0.61.2",
49114909
]
49124910

49134911
[[package]]
@@ -5275,9 +5273,9 @@ dependencies = [
52755273

52765274
[[package]]
52775275
name = "stringdex"
5278-
version = "0.0.2"
5276+
version = "0.0.3"
52795277
source = "registry+https://github.com/rust-lang/crates.io-index"
5280-
checksum = "18b3bd4f10d15ef859c40291769f0d85209de6b0f1c30713ff9cdf45ac43ea36"
5278+
checksum = "556a6126952cb2f5150057c98a77cc6c771027dea2825bf7fa03d3d638b0a4f8"
52815279
dependencies = [
52825280
"stacker",
52835281
]
@@ -5539,9 +5537,9 @@ version = "0.1.0"
55395537

55405538
[[package]]
55415539
name = "tikv-jemalloc-sys"
5542-
version = "0.6.1+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
5540+
version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
55435541
source = "registry+https://github.com/rust-lang/crates.io-index"
5544-
checksum = "cd8aa5b2ab86a2cefa406d889139c162cbb230092f7d1d7cbc1716405d852a3b"
5542+
checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d"
55455543
dependencies = [
55465544
"cc",
55475545
"libc",

compiler/rustc/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ rustc_public_bridge = { path = "../rustc_public_bridge" }
2121
# tidy-alphabetical-end
2222

2323
[dependencies.tikv-jemalloc-sys]
24-
version = "0.6.1"
24+
version = "0.6.0"
2525
optional = true
26-
features = ['override_allocator_on_supported_platforms']
26+
features = ['unprefixed_malloc_on_supported_platforms']
2727

2828
[features]
2929
# tidy-alphabetical-start

compiler/rustc/src/main.rs

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,26 @@
77
// distribution. The obvious way to do this is with the `#[global_allocator]`
88
// mechanism. However, for complicated reasons (see
99
// https://github.com/rust-lang/rust/pull/81782#issuecomment-784438001 for some
10-
// details) that mechanism doesn't work here. Also, we'd like to use a
11-
// consistent allocator across the rustc <-> llvm boundary, and
12-
// `#[global_allocator]` wouldn't provide that.
10+
// details) that mechanism doesn't work here. Also, we must use a consistent
11+
// allocator across the rustc <-> llvm boundary, and `#[global_allocator]`
12+
// wouldn't provide that.
1313
//
14-
// Instead, we use a lower-level mechanism, namely the
15-
// `"override_allocator_on_supported_platforms"` Cargo feature of jemalloc-sys.
16-
//
17-
// This makes jemalloc-sys override the libc/system allocator's implementation
18-
// of `malloc`, `free`, etc.. This means that Rust's `System` allocator, which
19-
// calls `libc::malloc()` et al., is actually calling into jemalloc.
14+
// Instead, we use a lower-level mechanism. rustc is linked with jemalloc in a
15+
// way such that jemalloc's implementation of `malloc`, `free`, etc., override
16+
// the libc allocator's implementation. This means that Rust's `System`
17+
// allocator, which calls `libc::malloc()` et al., is actually calling into
18+
// jemalloc.
2019
//
2120
// A consequence of not using `GlobalAlloc` (and the `tikv-jemallocator` crate
2221
// provides an impl of that trait, which is called `Jemalloc`) is that we
2322
// cannot use the sized deallocation APIs (`sdallocx`) that jemalloc provides.
2423
// It's unclear how much performance is lost because of this.
2524
//
26-
// NOTE: Even though Cargo passes `--extern` with `tikv_jemalloc_sys`, we still need to `use` the
27-
// crate for the compiler to see the `#[used]`, see https://github.com/rust-lang/rust/issues/64402.
28-
// This is similarly required if we used a crate with `#[global_allocator]`.
25+
// As for the symbol overrides in `main` below: we're pulling in a static copy
26+
// of jemalloc. We need to actually reference its symbols for it to get linked.
27+
// The two crates we link to here, `std` and `rustc_driver`, are both dynamic
28+
// libraries. So we must reference jemalloc symbols one way or another, because
29+
// this file is the only object code in the rustc executable.
2930
//
3031
// NOTE: if you are reading this comment because you want to set a custom `global_allocator` for
3132
// benchmarking, consider using the benchmarks in the `rustc-perf` collector suite instead:
@@ -35,9 +36,43 @@
3536
// to compare their performance, see
3637
// https://github.com/rust-lang/rust/commit/b90cfc887c31c3e7a9e6d462e2464db1fe506175#diff-43914724af6e464c1da2171e4a9b6c7e607d5bc1203fa95c0ab85be4122605ef
3738
// for an example of how to do so.
38-
#[cfg(feature = "jemalloc")]
39-
use tikv_jemalloc_sys as _;
4039

4140
fn main() {
41+
// See the comment at the top of this file for an explanation of this.
42+
#[cfg(feature = "jemalloc")]
43+
{
44+
use std::os::raw::{c_int, c_void};
45+
46+
use tikv_jemalloc_sys as jemalloc_sys;
47+
48+
#[used]
49+
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
50+
#[used]
51+
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
52+
jemalloc_sys::posix_memalign;
53+
#[used]
54+
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
55+
#[used]
56+
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
57+
#[used]
58+
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
59+
#[used]
60+
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
61+
62+
// On OSX, jemalloc doesn't directly override malloc/free, but instead
63+
// registers itself with the allocator's zone APIs in a ctor. However,
64+
// the linker doesn't seem to consider ctors as "used" when statically
65+
// linking, so we need to explicitly depend on the function.
66+
#[cfg(target_os = "macos")]
67+
{
68+
unsafe extern "C" {
69+
fn _rjem_je_zone_register();
70+
}
71+
72+
#[used]
73+
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
74+
}
75+
}
76+
4277
rustc_driver::main()
4378
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
16+
use rustc_span::{ByteSymbol, DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924
arena_vec![self; new_unchecked, get_context],
925925
),
926926
};
927-
self.arena.alloc(self.expr_unsafe(call))
927+
self.arena.alloc(self.expr_unsafe(span, call))
928928
};
929929

930930
// `::std::task::Poll::Ready(result) => break result`
@@ -1832,7 +1832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18321832
arena_vec![self; iter],
18331833
));
18341834
// `unsafe { ... }`
1835-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1835+
let iter = self.arena.alloc(self.expr_unsafe(head_span, iter));
18361836
let kind = self.make_lowered_await(head_span, iter, FutureKind::AsyncIterator);
18371837
self.arena.alloc(hir::Expr { hir_id: self.next_id(), kind, span: head_span })
18381838
}
@@ -1887,7 +1887,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18871887
arena_vec![self; iter],
18881888
));
18891889
// `unsafe { ... }`
1890-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1890+
let iter = self.arena.alloc(self.expr_unsafe(head_span, iter));
18911891
let inner_match_expr = self.arena.alloc(self.expr_match(
18921892
for_span,
18931893
iter,
@@ -2103,30 +2103,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
21032103
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
21042104
}
21052105

2106-
fn expr_uint(&mut self, sp: Span, ty: ast::UintTy, value: u128) -> hir::Expr<'hir> {
2106+
pub(super) fn expr_str(&mut self, sp: Span, value: Symbol) -> hir::Expr<'hir> {
21072107
let lit = hir::Lit {
21082108
span: self.lower_span(sp),
2109-
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
2109+
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
21102110
};
21112111
self.expr(sp, hir::ExprKind::Lit(lit))
21122112
}
21132113

2114-
pub(super) fn expr_usize(&mut self, sp: Span, value: usize) -> hir::Expr<'hir> {
2115-
self.expr_uint(sp, ast::UintTy::Usize, value as u128)
2116-
}
2117-
2118-
pub(super) fn expr_u32(&mut self, sp: Span, value: u32) -> hir::Expr<'hir> {
2119-
self.expr_uint(sp, ast::UintTy::U32, value as u128)
2120-
}
2121-
2122-
pub(super) fn expr_u16(&mut self, sp: Span, value: u16) -> hir::Expr<'hir> {
2123-
self.expr_uint(sp, ast::UintTy::U16, value as u128)
2124-
}
2125-
2126-
pub(super) fn expr_str(&mut self, sp: Span, value: Symbol) -> hir::Expr<'hir> {
2114+
pub(super) fn expr_byte_str(&mut self, sp: Span, value: ByteSymbol) -> hir::Expr<'hir> {
21272115
let lit = hir::Lit {
21282116
span: self.lower_span(sp),
2129-
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
2117+
node: ast::LitKind::ByteStr(value, ast::StrStyle::Cooked),
21302118
};
21312119
self.expr(sp, hir::ExprKind::Lit(lit))
21322120
}
@@ -2262,9 +2250,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22622250
self.expr(span, expr_path)
22632251
}
22642252

2265-
fn expr_unsafe(&mut self, expr: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
2253+
pub(super) fn expr_unsafe(
2254+
&mut self,
2255+
span: Span,
2256+
expr: &'hir hir::Expr<'hir>,
2257+
) -> hir::Expr<'hir> {
22662258
let hir_id = self.next_id();
2267-
let span = expr.span;
22682259
self.expr(
22692260
span,
22702261
hir::ExprKind::Block(
@@ -2302,15 +2293,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
23022293
self.arena.alloc(self.expr_block(b))
23032294
}
23042295

2305-
pub(super) fn expr_array_ref(
2306-
&mut self,
2307-
span: Span,
2308-
elements: &'hir [hir::Expr<'hir>],
2309-
) -> hir::Expr<'hir> {
2310-
let array = self.arena.alloc(self.expr(span, hir::ExprKind::Array(elements)));
2311-
self.expr_ref(span, array)
2312-
}
2313-
23142296
pub(super) fn expr_ref(&mut self, span: Span, expr: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
23152297
self.expr(span, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, expr))
23162298
}

0 commit comments

Comments
 (0)