Skip to content

Commit ffbe386

Browse files
author
The Miri Cronjob Bot
committed
Merge ref 'd3e1ccdf40ae' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: d3e1ccd Filtered ref: 6b5af2ac5727faaeb5f843668d4b0befce2ab986 Upstream diff: e22dab3...d3e1ccd This merge was created using https://github.com/rust-lang/josh-sync.
2 parents f880f97 + d9ed836 commit ffbe386

File tree

230 files changed

+7273
-1363
lines changed

Some content is hidden

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

230 files changed

+7273
-1363
lines changed

Cargo.lock

Lines changed: 499 additions & 553 deletions
Large diffs are not rendered by default.

bootstrap.example.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,12 @@
708708
# desired in distributions, for example.
709709
#rust.rpath = true
710710

711+
# Additional flags to pass to `rustc`.
712+
# Takes precedence over bootstrap's own flags but not over per target rustflags nor env. vars. like RUSTFLAGS.
713+
# Applies to all stages and targets.
714+
#
715+
#rust.rustflags = []
716+
711717
# Indicates whether symbols should be stripped using `-Cstrip=symbols`.
712718
#rust.strip = false
713719

@@ -1013,6 +1019,12 @@
10131019
# and will override the same option under [rust] section. It only works on Unix platforms
10141020
#rpath = rust.rpath (bool)
10151021

1022+
# Additional flags to pass to `rustc`.
1023+
# Takes precedence over bootstrap's own flags and `rust.rustflags` but not over env. vars. like RUSTFLAGS.
1024+
# Applies to all stages.
1025+
#
1026+
#rustflags = rust.rustflags
1027+
10161028
# Force static or dynamic linkage of the standard library for this target. If
10171029
# this target is a host for rustc, this will also affect the linkage of the
10181030
# compiler itself. This is useful for building rustc on targets that normally

compiler/rustc/Cargo.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ rustc_public = { path = "../rustc_public" }
2020
rustc_public_bridge = { path = "../rustc_public_bridge" }
2121
# tidy-alphabetical-end
2222

23+
# Pin these to avoid pulling in a package with a binary blob
24+
# <https://github.com/rust-lang/rust/pull/136395#issuecomment-2692769062>
25+
[target.'cfg(target_os = "wasi")'.dependencies]
26+
getrandom = "=0.3.3"
27+
wasi = "=0.14.2"
28+
29+
2330
[dependencies.tikv-jemalloc-sys]
24-
version = "0.6.0"
31+
version = "0.6.1"
2532
optional = true
26-
features = ['unprefixed_malloc_on_supported_platforms']
33+
features = ['override_allocator_on_supported_platforms']
2734

2835
[features]
2936
# tidy-alphabetical-start
3037
check_only = ['rustc_driver_impl/check_only']
3138
jemalloc = ['dep:tikv-jemalloc-sys']
3239
llvm = ['rustc_driver_impl/llvm']
3340
llvm_enzyme = ['rustc_driver_impl/llvm_enzyme']
41+
llvm_offload = ['rustc_driver_impl/llvm_offload']
3442
max_level_info = ['rustc_driver_impl/max_level_info']
3543
rustc_randomized_layouts = ['rustc_driver_impl/rustc_randomized_layouts']
3644
# tidy-alphabetical-end

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_attr_parsing/src/attributes/cfg.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ pub fn parse_cfg_entry<S: Stage>(
8282
}
8383
},
8484
a @ (ArgParser::NoArgs | ArgParser::NameValue(_)) => {
85-
let Some(name) = meta.path().word_sym() else {
85+
let Some(name) = meta.path().word_sym().filter(|s| !s.is_path_segment_keyword())
86+
else {
8687
return Err(cx.expected_identifier(meta.path().span()));
8788
};
8889
parse_name_value(name, meta.path().span(), a.name_value(), meta.span(), cx)?
@@ -158,7 +159,7 @@ fn parse_cfg_entry_target<S: Stage>(
158159
};
159160

160161
// Then, parse it as a name-value item
161-
let Some(name) = sub_item.path().word_sym() else {
162+
let Some(name) = sub_item.path().word_sym().filter(|s| !s.is_path_segment_keyword()) else {
162163
return Err(cx.expected_identifier(sub_item.path().span()));
163164
};
164165
let name = Symbol::intern(&format!("target_{name}"));

compiler/rustc_attr_parsing/src/attributes/cfg_old.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ pub fn eval_condition(
220220
}
221221
}
222222
}
223-
MetaItemKind::Word | MetaItemKind::NameValue(..) if cfg.path.segments.len() != 1 => {
223+
MetaItemKind::Word | MetaItemKind::NameValue(..)
224+
if cfg.path.segments.len() != 1
225+
|| cfg.path.segments[0].ident.is_path_segment_keyword() =>
226+
{
224227
dcx.emit_err(session_diagnostics::CfgPredicateIdentifier { span: cfg.path.span });
225228
true
226229
}

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ impl<S: Stage> NoArgsAttributeParser<S> for PassByValueParser {
3838
const CREATE: fn(Span) -> AttributeKind = AttributeKind::PassByValue;
3939
}
4040

41+
pub(crate) struct RustcShouldNotBeCalledOnConstItems;
42+
impl<S: Stage> NoArgsAttributeParser<S> for RustcShouldNotBeCalledOnConstItems {
43+
const PATH: &[Symbol] = &[sym::rustc_should_not_be_called_on_const_items];
44+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
45+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
46+
Allow(Target::Method(MethodKind::Inherent)),
47+
Allow(Target::Method(MethodKind::TraitImpl)),
48+
]);
49+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcShouldNotBeCalledOnConstItems;
50+
}
51+
4152
pub(crate) struct AutomaticallyDerivedParser;
4253
impl<S: Stage> NoArgsAttributeParser<S> for AutomaticallyDerivedParser {
4354
const PATH: &[Symbol] = &[sym::automatically_derived];

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use crate::attributes::link_attrs::{
3939
};
4040
use crate::attributes::lint_helpers::{
4141
AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser,
42+
RustcShouldNotBeCalledOnConstItems,
4243
};
4344
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
4445
use crate::attributes::macro_attrs::{
@@ -244,6 +245,7 @@ attribute_parsers!(
244245
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
245246
Single<WithoutArgs<RustcMainParser>>,
246247
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
248+
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
247249
Single<WithoutArgs<SpecializationTraitParser>>,
248250
Single<WithoutArgs<StdInternalSymbolParser>>,
249251
Single<WithoutArgs<TrackCallerParser>>,

compiler/rustc_codegen_llvm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ tracing = "0.1"
4747
# tidy-alphabetical-start
4848
check_only = ["rustc_llvm/check_only"]
4949
llvm_enzyme = []
50+
llvm_offload = []
5051
# tidy-alphabetical-end
5152

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use libc::{c_char, c_int, c_void, size_t};
99
use rustc_codegen_ssa::back::link::ensure_removed;
1010
use rustc_codegen_ssa::back::versioned_llvm_target;
1111
use rustc_codegen_ssa::back::write::{
12-
BitcodeSection, CodegenContext, EmitObj, ModuleConfig, TargetMachineFactoryConfig,
13-
TargetMachineFactoryFn,
12+
BitcodeSection, CodegenContext, EmitObj, InlineAsmError, ModuleConfig,
13+
TargetMachineFactoryConfig, TargetMachineFactoryFn,
1414
};
1515
use rustc_codegen_ssa::base::wants_wasm_eh;
1616
use rustc_codegen_ssa::traits::*;
@@ -434,7 +434,7 @@ fn report_inline_asm(
434434
level: llvm::DiagnosticLevel,
435435
cookie: u64,
436436
source: Option<(String, Vec<InnerSpan>)>,
437-
) {
437+
) -> InlineAsmError {
438438
// In LTO build we may get srcloc values from other crates which are invalid
439439
// since they use a different source map. To be safe we just suppress these
440440
// in LTO builds.
@@ -454,7 +454,7 @@ fn report_inline_asm(
454454
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
455455
};
456456
let msg = msg.trim_prefix("error: ").to_string();
457-
cgcx.diag_emitter.inline_asm_error(span, msg, level, source);
457+
InlineAsmError { span, msg, level, source }
458458
}
459459

460460
unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void) {
@@ -466,7 +466,13 @@ unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void
466466

467467
match unsafe { llvm::diagnostic::Diagnostic::unpack(info) } {
468468
llvm::diagnostic::InlineAsm(inline) => {
469-
report_inline_asm(cgcx, inline.message, inline.level, inline.cookie, inline.source);
469+
cgcx.diag_emitter.inline_asm_error(report_inline_asm(
470+
cgcx,
471+
inline.message,
472+
inline.level,
473+
inline.cookie,
474+
inline.source,
475+
));
470476
}
471477

472478
llvm::diagnostic::Optimization(opt) => {
@@ -765,6 +771,13 @@ pub(crate) unsafe fn llvm_optimize(
765771
llvm_plugins.len(),
766772
)
767773
};
774+
775+
if cgcx.target_is_like_gpu && config.offload.contains(&config::Offload::Enable) {
776+
unsafe {
777+
llvm::LLVMRustBundleImages(module.module_llvm.llmod(), module.module_llvm.tm.raw());
778+
}
779+
}
780+
768781
result.into_result().unwrap_or_else(|()| llvm_err(dcx, LlvmError::RunLlvmPasses))
769782
}
770783

0 commit comments

Comments
 (0)