Skip to content

Commit 0bbef55

Browse files
committed
Auto merge of #148624 - jhpratt:rollup-is5je9r, r=jhpratt
Rollup of 12 pull requests Successful merges: - #145768 (Offload device) - #145992 (Stabilize `vec_deque_pop_if`) - #147416 (Early return if span is from expansion so we dont get empty span and ice later on) - #147808 (btree: cleanup difference, intersection, is_subset) - #148520 (style: Use binary literals instead of hex literals in doctests for `highest_one` and `lowest_one`) - #148559 (Add typo suggestion for a misspelt Cargo environment variable) - #148567 (Fix incorrect precedence caused by range expression) - #148570 (Fix mismatched brackets in generated .dir-locals.el) - #148575 (fix dev guide link in rustc_query_system/dep_graph/README.md) - #148578 (core docs: add notes about availability of `Atomic*::from_mut_slice`) - #148603 (Backport 1.91.1 relnotes to main) - #148609 (Sync str::rsplit_once example with str::split_once) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c90bcb9 + c932d7c commit 0bbef55

File tree

38 files changed

+528
-135
lines changed

38 files changed

+528
-135
lines changed

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_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,

compiler/rustc_codegen_llvm/src/type_.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
6868
unsafe { llvm::LLVMVectorType(ty, len as c_uint) }
6969
}
7070

71+
pub(crate) fn add_func(&self, name: &str, ty: &'ll Type) -> &'ll Value {
72+
let name = SmallCStr::new(name);
73+
unsafe { llvm::LLVMAddFunction(self.llmod(), name.as_ptr(), ty) }
74+
}
75+
7176
pub(crate) fn func_params_types(&self, ty: &'ll Type) -> Vec<&'ll Type> {
7277
unsafe {
7378
let n_args = llvm::LLVMCountParamTypes(ty) as usize;

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
342342
pub target_arch: String,
343343
pub target_is_like_darwin: bool,
344344
pub target_is_like_aix: bool,
345+
pub target_is_like_gpu: bool,
345346
pub split_debuginfo: rustc_target::spec::SplitDebuginfo,
346347
pub split_dwarf_kind: rustc_session::config::SplitDwarfKind,
347348
pub pointer_size: Size,
@@ -1309,6 +1310,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
13091310
target_arch: tcx.sess.target.arch.to_string(),
13101311
target_is_like_darwin: tcx.sess.target.is_like_darwin,
13111312
target_is_like_aix: tcx.sess.target.is_like_aix,
1313+
target_is_like_gpu: tcx.sess.target.is_like_gpu,
13121314
split_debuginfo: tcx.sess.split_debuginfo(),
13131315
split_dwarf_kind: tcx.sess.opts.unstable_opts.split_dwarf_kind,
13141316
parallel: backend.supports_parallel() && !sess.opts.unstable_opts.no_parallel_backend,

0 commit comments

Comments
 (0)