Skip to content

Commit 0b329f8

Browse files
committed
Auto merge of #148851 - Zalathar:rollup-4y7ywyd, r=Zalathar
Rollup of 16 pull requests Successful merges: - #146627 (Simplify `jemalloc` setup) - #147753 (Suggest add bounding value for RangeTo) - #147832 (rustdoc: Don't pass `RenderOptions` to `DocContext`) - #147974 (Improve diagnostics for buffer reuse with borrowed references) - #148080 ([rustdoc] Fix invalid jump to def macro link generation) - #148465 (Adjust spans into the `for` loops context before creating the new desugaring spans.) - #148500 (Update git index before running diff-index) - #148531 (rustc_target: introduce Abi, Env, Os) - #148536 (cmse: add test for `async` and `const` functions) - #148770 (implement `feature(c_variadic_naked_functions)`) - #148780 (fix filecheck typos in tests) - #148819 (Remove specialized warning for removed target) - #148830 (miri subtree update) - #148833 (Update rustbook dependencies) - #148834 (fix(rustdoc): Color doctest errors) - #148841 (Remove more `#[must_use]` from portable-simd) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 11339a0 + 2443cfb commit 0b329f8

File tree

351 files changed

+3441
-2090
lines changed

Some content is hidden

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

351 files changed

+3441
-2090
lines changed

Cargo.lock

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ dependencies = [
600600
"serde_json",
601601
"tempfile",
602602
"termize",
603+
"tikv-jemalloc-sys",
603604
"toml 0.9.7",
604605
"ui_test",
605606
"walkdir",
@@ -4806,6 +4807,7 @@ dependencies = [
48064807
"stringdex",
48074808
"tempfile",
48084809
"threadpool",
4810+
"tikv-jemalloc-sys",
48094811
"tracing",
48104812
"tracing-subscriber",
48114813
"tracing-tree",
@@ -5537,9 +5539,9 @@ version = "0.1.0"
55375539

55385540
[[package]]
55395541
name = "tikv-jemalloc-sys"
5540-
version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
5542+
version = "0.6.1+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
55415543
source = "registry+https://github.com/rust-lang/crates.io-index"
5542-
checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d"
5544+
checksum = "cd8aa5b2ab86a2cefa406d889139c162cbb230092f7d1d7cbc1716405d852a3b"
55435545
dependencies = [
55445546
"cc",
55455547
"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.0"
24+
version = "0.6.1"
2525
optional = true
26-
features = ['unprefixed_malloc_on_supported_platforms']
26+
features = ['override_allocator_on_supported_platforms']
2727

2828
[features]
2929
# tidy-alphabetical-start

compiler/rustc/src/main.rs

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,25 @@
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 must use a consistent
11-
// allocator across the rustc <-> llvm boundary, and `#[global_allocator]`
12-
// wouldn't provide that.
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.
1313
//
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.
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.
1920
//
2021
// A consequence of not using `GlobalAlloc` (and the `tikv-jemallocator` crate
2122
// provides an impl of that trait, which is called `Jemalloc`) is that we
2223
// cannot use the sized deallocation APIs (`sdallocx`) that jemalloc provides.
2324
// It's unclear how much performance is lost because of this.
2425
//
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.
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]`.
3029
//
3130
// NOTE: if you are reading this comment because you want to set a custom `global_allocator` for
3231
// benchmarking, consider using the benchmarks in the `rustc-perf` collector suite instead:
@@ -36,43 +35,9 @@
3635
// to compare their performance, see
3736
// https://github.com/rust-lang/rust/commit/b90cfc887c31c3e7a9e6d462e2464db1fe506175#diff-43914724af6e464c1da2171e4a9b6c7e607d5bc1203fa95c0ab85be4122605ef
3837
// for an example of how to do so.
38+
#[cfg(feature = "jemalloc")]
39+
use tikv_jemalloc_sys as _;
3940

4041
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-
7742
rustc_driver::main()
7843
}

compiler/rustc_ast/src/visit.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,9 @@ macro_rules! common_visitor_and_walkers {
645645
fn visit_fn(
646646
&mut self,
647647
fk: FnKind<$($lt)? $(${ignore($mut)} '_)?>,
648+
_: &AttrVec,
648649
_: Span,
649-
_: NodeId
650+
_: NodeId,
650651
) -> Self::Result {
651652
walk_fn(self, fk)
652653
}
@@ -740,6 +741,7 @@ macro_rules! common_visitor_and_walkers {
740741
type Ctxt;
741742
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
742743
&$($lt)? $($mut)? self,
744+
attrs: &AttrVec,
743745
span: Span,
744746
id: NodeId,
745747
visibility: &$($lt)? $($mut)? Visibility,
@@ -773,7 +775,7 @@ macro_rules! common_visitor_and_walkers {
773775
) -> V::Result {
774776
let Item { attrs, id, kind, vis, span, tokens: _ } = item;
775777
visit_visitable!($($mut)? visitor, id, attrs, vis);
776-
try_visit!(kind.walk(*span, *id, vis, ctxt, visitor));
778+
try_visit!(kind.walk(attrs, *span, *id, vis, ctxt, visitor));
777779
visit_visitable!($($mut)? visitor, span);
778780
V::Result::output()
779781
}
@@ -799,6 +801,7 @@ macro_rules! common_visitor_and_walkers {
799801
type Ctxt = ();
800802
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
801803
&$($lt)? $($mut)? self,
804+
attrs: &AttrVec,
802805
span: Span,
803806
id: NodeId,
804807
visibility: &$($lt)? $($mut)? Visibility,
@@ -808,7 +811,7 @@ macro_rules! common_visitor_and_walkers {
808811
match self {
809812
ItemKind::Fn(func) => {
810813
let kind = FnKind::Fn(FnCtxt::Free, visibility, &$($mut)? *func);
811-
try_visit!(vis.visit_fn(kind, span, id));
814+
try_visit!(vis.visit_fn(kind, attrs, span, id));
812815
}
813816
ItemKind::ExternCrate(orig_name, ident) =>
814817
visit_visitable!($($mut)? vis, orig_name, ident),
@@ -856,6 +859,7 @@ macro_rules! common_visitor_and_walkers {
856859
type Ctxt = AssocCtxt;
857860
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
858861
&$($lt)? $($mut)? self,
862+
attrs: &AttrVec,
859863
span: Span,
860864
id: NodeId,
861865
visibility: &$($lt)? $($mut)? Visibility,
@@ -867,7 +871,7 @@ macro_rules! common_visitor_and_walkers {
867871
visit_visitable!($($mut)? vis, item),
868872
AssocItemKind::Fn(func) => {
869873
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), visibility, &$($mut)? *func);
870-
try_visit!(vis.visit_fn(kind, span, id))
874+
try_visit!(vis.visit_fn(kind, attrs, span, id))
871875
}
872876
AssocItemKind::Type(alias) =>
873877
visit_visitable!($($mut)? vis, alias),
@@ -886,6 +890,7 @@ macro_rules! common_visitor_and_walkers {
886890
type Ctxt = ();
887891
fn walk<$($lt,)? V: $Visitor$(<$lt>)?>(
888892
&$($lt)? $($mut)? self,
893+
attrs: &AttrVec,
889894
span: Span,
890895
id: NodeId,
891896
visibility: &$($lt)? $($mut)? Visibility,
@@ -897,7 +902,7 @@ macro_rules! common_visitor_and_walkers {
897902
visit_visitable!($($mut)? vis, item),
898903
ForeignItemKind::Fn(func) => {
899904
let kind = FnKind::Fn(FnCtxt::Foreign, visibility, &$($mut)?*func);
900-
try_visit!(vis.visit_fn(kind, span, id))
905+
try_visit!(vis.visit_fn(kind, attrs, span, id))
901906
}
902907
ForeignItemKind::TyAlias(alias) =>
903908
visit_visitable!($($mut)? vis, alias),
@@ -999,7 +1004,7 @@ macro_rules! common_visitor_and_walkers {
9991004
}) => {
10001005
visit_visitable!($($mut)? vis, constness, movability, capture_clause);
10011006
let kind = FnKind::Closure(binder, coroutine_kind, fn_decl, body);
1002-
try_visit!(vis.visit_fn(kind, *span, *id));
1007+
try_visit!(vis.visit_fn(kind, attrs, *span, *id));
10031008
visit_visitable!($($mut)? vis, fn_decl_span, fn_arg_span);
10041009
}
10051010
ExprKind::Block(block, opt_label) =>

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,8 +1771,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
17711771
let pat = self.lower_pat(pat);
17721772
let for_span =
17731773
self.mark_span_with_reason(DesugaringKind::ForLoop, self.lower_span(e.span), None);
1774-
let head_span = self.mark_span_with_reason(DesugaringKind::ForLoop, head.span, None);
1775-
let pat_span = self.mark_span_with_reason(DesugaringKind::ForLoop, pat.span, None);
1774+
let for_ctxt = for_span.ctxt();
1775+
1776+
// Try to point both the head and pat spans to their position in the for loop
1777+
// rather than inside a macro.
1778+
let head_span =
1779+
head.span.find_ancestor_in_same_ctxt(e.span).unwrap_or(head.span).with_ctxt(for_ctxt);
1780+
let pat_span =
1781+
pat.span.find_ancestor_in_same_ctxt(e.span).unwrap_or(pat.span).with_ctxt(for_ctxt);
17761782

17771783
let loop_hir_id = self.lower_node_id(e.id);
17781784
let label = self.lower_label(opt_label, e.id, loop_hir_id);

compiler/rustc_ast_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ ast_passes_c_variadic_bad_extern = `...` is not supported for `extern "{$abi}"`
6868
.label = `extern "{$abi}"` because of this
6969
.help = only `extern "C"` and `extern "C-unwind"` functions may have a C variable argument list
7070
71+
ast_passes_c_variadic_bad_naked_extern = `...` is not supported for `extern "{$abi}"` naked functions
72+
.label = `extern "{$abi}"` because of this
73+
.help = C-variadic function must have a compatible calling convention
74+
7175
ast_passes_c_variadic_must_be_unsafe =
7276
functions with a C variable argument list must be unsafe
7377
.suggestion = add the `unsafe` keyword to this definition

0 commit comments

Comments
 (0)