Skip to content

Commit c7da7c3

Browse files
author
The Miri Cronjob Bot
committed
Merge ref 'ceb7df7e6f17' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: ceb7df7 Filtered ref: cc5fca3f935d6a43e0de7e2ff4c16039b88f5d1c Upstream diff: 401ae55...ceb7df7 This merge was created using https://github.com/rust-lang/josh-sync.
2 parents f6b751e + ceb7df7 commit c7da7c3

File tree

98 files changed

+1385
-404
lines changed

Some content is hidden

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

98 files changed

+1385
-404
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ dependencies = [
8080

8181
[[package]]
8282
name = "annotate-snippets"
83-
version = "0.12.7"
83+
version = "0.12.8"
8484
source = "registry+https://github.com/rust-lang/crates.io-index"
85-
checksum = "47224528f74de27d1d06aad6a5dda4f865b6ebe2e56c538943d746a7270cb67e"
85+
checksum = "025c7edcdffa4ccc5c0905f472a0ae3759378cfbef88ef518a3575e19ae3aebd"
8686
dependencies = [
8787
"anstyle",
8888
"unicode-width 0.2.2",
@@ -2334,9 +2334,9 @@ dependencies = [
23342334

23352335
[[package]]
23362336
name = "memchr"
2337-
version = "2.7.5"
2337+
version = "2.7.6"
23382338
source = "registry+https://github.com/rust-lang/crates.io-index"
2339-
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
2339+
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
23402340

23412341
[[package]]
23422342
name = "memmap2"
@@ -3766,7 +3766,7 @@ dependencies = [
37663766
name = "rustc_errors"
37673767
version = "0.0.0"
37683768
dependencies = [
3769-
"annotate-snippets 0.12.7",
3769+
"annotate-snippets 0.12.8",
37703770
"anstream",
37713771
"anstyle",
37723772
"derive_setters",

RELEASES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Version 1.91.1 (2025-11-10)
2+
===========================
3+
4+
<a id="1.91.1"></a>
5+
6+
- [Enable file locking support in illumos](https://github.com/rust-lang/rust/pull/148322). This fixes Cargo not locking the build directory on illumos.
7+
- [Fix `wasm_import_module` attribute cross-crate](https://github.com/rust-lang/rust/pull/148363). This fixes linker errors on WASM targets.
8+
19
Version 1.91.0 (2025-10-30)
210
==========================
311

compiler/rustc_ast/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
9-
memchr = "2.7.4"
9+
memchr = "2.7.6"
1010
rustc-literal-escaper = "0.0.5"
1111
rustc_ast_ir = { path = "../rustc_ast_ir" }
1212
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_builtin_macros/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ builtin_macros_duplicate_macro_attribute = duplicated attribute
156156
157157
builtin_macros_env_not_defined = environment variable `{$var}` not defined at compile time
158158
.cargo = Cargo sets build script variables at run time. Use `std::env::var({$var_expr})` instead
159+
.cargo_typo = there is a similar Cargo environment variable: `{$suggested_var}`
159160
.custom = use `std::env::var({$var_expr})` to read the variable at run time
160161
161162
builtin_macros_env_not_unicode = environment variable `{$var}` is not a valid Unicode string

compiler/rustc_builtin_macros/src/env.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_ast::token::{self, LitKind};
1010
use rustc_ast::tokenstream::TokenStream;
1111
use rustc_ast::{ExprKind, GenericArg, Mutability};
1212
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
13+
use rustc_span::edit_distance::edit_distance;
1314
use rustc_span::{Ident, Span, Symbol, kw, sym};
1415
use thin_vec::thin_vec;
1516

@@ -144,6 +145,12 @@ pub(crate) fn expand_env<'cx>(
144145
if let Some(msg_from_user) = custom_msg {
145146
cx.dcx()
146147
.emit_err(errors::EnvNotDefinedWithUserMessage { span, msg_from_user })
148+
} else if let Some(suggested_var) = find_similar_cargo_var(var.as_str()) {
149+
cx.dcx().emit_err(errors::EnvNotDefined::CargoEnvVarTypo {
150+
span,
151+
var: *symbol,
152+
suggested_var: Symbol::intern(suggested_var),
153+
})
147154
} else if is_cargo_env_var(var.as_str()) {
148155
cx.dcx().emit_err(errors::EnvNotDefined::CargoEnvVar {
149156
span,
@@ -176,3 +183,49 @@ fn is_cargo_env_var(var: &str) -> bool {
176183
|| var.starts_with("DEP_")
177184
|| matches!(var, "OUT_DIR" | "OPT_LEVEL" | "PROFILE" | "HOST" | "TARGET")
178185
}
186+
187+
const KNOWN_CARGO_VARS: &[&str] = &[
188+
// List of known Cargo environment variables that are set for crates (not build scripts, OUT_DIR etc).
189+
// See: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates
190+
"CARGO_PKG_VERSION",
191+
"CARGO_PKG_VERSION_MAJOR",
192+
"CARGO_PKG_VERSION_MINOR",
193+
"CARGO_PKG_VERSION_PATCH",
194+
"CARGO_PKG_VERSION_PRE",
195+
"CARGO_PKG_AUTHORS",
196+
"CARGO_PKG_NAME",
197+
"CARGO_PKG_DESCRIPTION",
198+
"CARGO_PKG_HOMEPAGE",
199+
"CARGO_PKG_REPOSITORY",
200+
"CARGO_PKG_LICENSE",
201+
"CARGO_PKG_LICENSE_FILE",
202+
"CARGO_PKG_RUST_VERSION",
203+
"CARGO_PKG_README",
204+
"CARGO_MANIFEST_DIR",
205+
"CARGO_MANIFEST_PATH",
206+
"CARGO_CRATE_NAME",
207+
"CARGO_BIN_NAME",
208+
"CARGO_PRIMARY_PACKAGE",
209+
];
210+
211+
fn find_similar_cargo_var(var: &str) -> Option<&'static str> {
212+
if !var.starts_with("CARGO_") {
213+
return None;
214+
}
215+
216+
let lookup_len = var.chars().count();
217+
let max_dist = std::cmp::max(lookup_len, 3) / 3;
218+
let mut best_match = None;
219+
let mut best_distance = usize::MAX;
220+
221+
for &known_var in KNOWN_CARGO_VARS {
222+
if let Some(distance) = edit_distance(var, known_var, max_dist) {
223+
if distance < best_distance {
224+
best_distance = distance;
225+
best_match = Some(known_var);
226+
}
227+
}
228+
}
229+
230+
best_match
231+
}

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,14 @@ pub(crate) enum EnvNotDefined<'a> {
535535
var_expr: &'a rustc_ast::Expr,
536536
},
537537
#[diag(builtin_macros_env_not_defined)]
538+
#[help(builtin_macros_cargo_typo)]
539+
CargoEnvVarTypo {
540+
#[primary_span]
541+
span: Span,
542+
var: Symbol,
543+
suggested_var: Symbol,
544+
},
545+
#[diag(builtin_macros_env_not_defined)]
538546
#[help(builtin_macros_custom)]
539547
CustomEnvVar {
540548
#[primary_span]

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ pub(crate) fn run_pass_manager(
616616
write::llvm_optimize(cgcx, dcx, module, None, config, opt_level, opt_stage, stage);
617617
}
618618

619-
if enable_gpu && !thin {
619+
// Here we only handle the GPU host (=cpu) code.
620+
if enable_gpu && !thin && !cgcx.target_is_like_gpu {
620621
let cx =
621622
SimpleCx::new(module.module_llvm.llmod(), &module.module_llvm.llcx, cgcx.pointer_size);
622623
crate::builder::gpu_offload::handle_gpu_code(cgcx, &cx);

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::errors::{
4343
use crate::llvm::diagnostic::OptimizationDiagnosticKind::*;
4444
use crate::llvm::{self, DiagnosticInfo};
4545
use crate::type_::llvm_type_ptr;
46-
use crate::{LlvmCodegenBackend, ModuleLlvm, base, common, llvm_util};
46+
use crate::{LlvmCodegenBackend, ModuleLlvm, SimpleCx, base, common, llvm_util};
4747

4848
pub(crate) fn llvm_err<'a>(dcx: DiagCtxtHandle<'_>, err: LlvmError<'a>) -> ! {
4949
match llvm::last_error() {
@@ -645,6 +645,74 @@ pub(crate) unsafe fn llvm_optimize(
645645
None
646646
};
647647

648+
fn handle_offload<'ll>(cx: &'ll SimpleCx<'_>, old_fn: &llvm::Value) {
649+
let old_fn_ty = cx.get_type_of_global(old_fn);
650+
let old_param_types = cx.func_params_types(old_fn_ty);
651+
let old_param_count = old_param_types.len();
652+
if old_param_count == 0 {
653+
return;
654+
}
655+
656+
let first_param = llvm::get_param(old_fn, 0);
657+
let c_name = llvm::get_value_name(first_param);
658+
let first_arg_name = str::from_utf8(&c_name).unwrap();
659+
// We might call llvm_optimize (and thus this code) multiple times on the same IR,
660+
// but we shouldn't add this helper ptr multiple times.
661+
// FIXME(offload): This could break if the user calls his first argument `dyn_ptr`.
662+
if first_arg_name == "dyn_ptr" {
663+
return;
664+
}
665+
666+
// Create the new parameter list, with ptr as the first argument
667+
let mut new_param_types = Vec::with_capacity(old_param_count as usize + 1);
668+
new_param_types.push(cx.type_ptr());
669+
new_param_types.extend(old_param_types);
670+
671+
// Create the new function type
672+
let ret_ty = unsafe { llvm::LLVMGetReturnType(old_fn_ty) };
673+
let new_fn_ty = cx.type_func(&new_param_types, ret_ty);
674+
675+
// Create the new function, with a temporary .offload name to avoid a name collision.
676+
let old_fn_name = String::from_utf8(llvm::get_value_name(old_fn)).unwrap();
677+
let new_fn_name = format!("{}.offload", &old_fn_name);
678+
let new_fn = cx.add_func(&new_fn_name, new_fn_ty);
679+
let a0 = llvm::get_param(new_fn, 0);
680+
llvm::set_value_name(a0, CString::new("dyn_ptr").unwrap().as_bytes());
681+
682+
// Here we map the old arguments to the new arguments, with an offset of 1 to make sure
683+
// that we don't use the newly added `%dyn_ptr`.
684+
unsafe {
685+
llvm::LLVMRustOffloadMapper(cx.llmod(), old_fn, new_fn);
686+
}
687+
688+
llvm::set_linkage(new_fn, llvm::get_linkage(old_fn));
689+
llvm::set_visibility(new_fn, llvm::get_visibility(old_fn));
690+
691+
// Replace all uses of old_fn with new_fn (RAUW)
692+
unsafe {
693+
llvm::LLVMReplaceAllUsesWith(old_fn, new_fn);
694+
}
695+
let name = llvm::get_value_name(old_fn);
696+
unsafe {
697+
llvm::LLVMDeleteFunction(old_fn);
698+
}
699+
// Now we can re-use the old name, without name collision.
700+
llvm::set_value_name(new_fn, &name);
701+
}
702+
703+
if cgcx.target_is_like_gpu && config.offload.contains(&config::Offload::Enable) {
704+
let cx =
705+
SimpleCx::new(module.module_llvm.llmod(), module.module_llvm.llcx, cgcx.pointer_size);
706+
// For now we only support up to 10 kernels named kernel_0 ... kernel_9, a follow-up PR is
707+
// introducing a proper offload intrinsic to solve this limitation.
708+
for num in 0..9 {
709+
let name = format!("kernel_{num}");
710+
if let Some(kernel) = cx.get_function(&name) {
711+
handle_offload(&cx, kernel);
712+
}
713+
}
714+
}
715+
648716
let mut llvm_profiler = cgcx
649717
.prof
650718
.llvm_recording_enabled()

compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub(crate) fn handle_gpu_code<'ll>(
1919
let mut memtransfer_types = vec![];
2020
let mut region_ids = vec![];
2121
let offload_entry_ty = TgtOffloadEntry::new_decl(&cx);
22+
// This is a temporary hack, we only search for kernel_0 to kernel_9 functions.
23+
// There is a draft PR in progress which will introduce a proper offload intrinsic to remove
24+
// this limitation.
2225
for num in 0..9 {
2326
let kernel = cx.get_function(&format!("kernel_{num}"));
2427
if let Some(kernel) = kernel {

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,11 @@ unsafe extern "C" {
11271127

11281128
// Operations on functions
11291129
pub(crate) fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
1130+
pub(crate) fn LLVMAddFunction<'a>(
1131+
Mod: &'a Module,
1132+
Name: *const c_char,
1133+
FunctionTy: &'a Type,
1134+
) -> &'a Value;
11301135
pub(crate) fn LLVMDeleteFunction(Fn: &Value);
11311136

11321137
// Operations about llvm intrinsics
@@ -2017,6 +2022,7 @@ unsafe extern "C" {
20172022
) -> &Attribute;
20182023

20192024
// Operations on functions
2025+
pub(crate) fn LLVMRustOffloadMapper<'a>(M: &'a Module, Fn: &'a Value, Fn: &'a Value);
20202026
pub(crate) fn LLVMRustGetOrInsertFunction<'a>(
20212027
M: &'a Module,
20222028
Name: *const c_char,

0 commit comments

Comments
 (0)