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

38 files changed

Lines changed: 528 additions & 135 deletions

File tree

‎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
ifletSome(msg_from_user) = custom_msg {
145146
cx.dcx()
146147
.emit_err(errors::EnvNotDefinedWithUserMessage{ span, msg_from_user })
148+
}elseifletSome(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
}elseifis_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+
constKNOWN_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+
fnfind_similar_cargo_var(var:&str) -> Option<&'staticstr>{
212+
if !var.starts_with("CARGO_"){
213+
returnNone;
214+
}
215+
216+
let lookup_len = var.chars().count();
217+
let max_dist = std::cmp::max(lookup_len,3) / 3;
218+
letmut best_match = None;
219+
letmut best_distance = usize::MAX;
220+
221+
for&known_var inKNOWN_CARGO_VARS{
222+
ifletSome(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
usecrate::llvm::diagnostic::OptimizationDiagnosticKind::*;
4444
usecrate::llvm::{self,DiagnosticInfo};
4545
usecrate::type_::llvm_type_ptr;
46-
usecrate::{LlvmCodegenBackend,ModuleLlvm, base, common, llvm_util};
46+
usecrate::{LlvmCodegenBackend,ModuleLlvm,SimpleCx,base, common, llvm_util};
4747

4848
pub(crate)fnllvm_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+
fnhandle_offload<'ll>(cx:&'llSimpleCx<'_>,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+
letmut new_param_types = Vec::with_capacity(old_param_count asusize + 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 in0..9{
709+
let name = format!("kernel_{num}");
710+
ifletSome(kernel) = cx.get_function(&name){
711+
handle_offload(&cx, kernel);
712+
}
713+
}
714+
}
715+
648716
letmut 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
letmut memtransfer_types = vec![];
2020
letmut 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 in0..9{
2326
let kernel = cx.get_function(&format!("kernel_{num}"));
2427
ifletSome(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)fnLLVMSetFunctionCallConv(Fn:&Value,CC:c_uint);
1130+
pub(crate)fnLLVMAddFunction<'a>(
1131+
Mod:&'aModule,
1132+
Name:*constc_char,
1133+
FunctionTy:&'aType,
1134+
) -> &'aValue;
11301135
pub(crate)fnLLVMDeleteFunction(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)fnLLVMRustOffloadMapper<'a>(M:&'aModule,Fn:&'aValue,Fn:&'aValue);
20202026
pub(crate)fnLLVMRustGetOrInsertFunction<'a>(
20212027
M:&'aModule,
20222028
Name:*constc_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 asc_uint)}
6969
}
7070

71+
pub(crate)fnadd_func(&self,name:&str,ty:&'llType) -> &'llValue{
72+
let name = SmallCStr::new(name);
73+
unsafe{ llvm::LLVMAddFunction(self.llmod(), name.as_ptr(), ty)}
74+
}
75+
7176
pub(crate)fnfunc_params_types(&self,ty:&'llType) -> Vec<&'llType>{
7277
unsafe{
7378
let n_args = llvm::LLVMCountParamTypes(ty)asusize;

‎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
pubtarget_arch:String,
343343
pubtarget_is_like_darwin:bool,
344344
pubtarget_is_like_aix:bool,
345+
pubtarget_is_like_gpu:bool,
345346
pubsplit_debuginfo: rustc_target::spec::SplitDebuginfo,
346347
pubsplit_dwarf_kind: rustc_session::config::SplitDwarfKind,
347348
pubpointer_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)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Auto merge of #148624 - jhpratt:rollup-is5je9r, r=jhpratt · rust-lang/rust@0bbef55 · GitHub
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

38 files changed

Lines changed: 528 additions & 135 deletions

File tree

‎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
ifletSome(msg_from_user) = custom_msg {
145146
cx.dcx()
146147
.emit_err(errors::EnvNotDefinedWithUserMessage{ span, msg_from_user })
148+
}elseifletSome(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
}elseifis_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+
constKNOWN_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+
fnfind_similar_cargo_var(var:&str) -> Option<&'staticstr>{
212+
if !var.starts_with("CARGO_"){
213+
returnNone;
214+
}
215+
216+
let lookup_len = var.chars().count();
217+
let max_dist = std::cmp::max(lookup_len,3) / 3;
218+
letmut best_match = None;
219+
letmut best_distance = usize::MAX;
220+
221+
for&known_var inKNOWN_CARGO_VARS{
222+
ifletSome(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
usecrate::llvm::diagnostic::OptimizationDiagnosticKind::*;
4444
usecrate::llvm::{self,DiagnosticInfo};
4545
usecrate::type_::llvm_type_ptr;
46-
usecrate::{LlvmCodegenBackend,ModuleLlvm, base, common, llvm_util};
46+
usecrate::{LlvmCodegenBackend,ModuleLlvm,SimpleCx,base, common, llvm_util};
4747

4848
pub(crate)fnllvm_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+
fnhandle_offload<'ll>(cx:&'llSimpleCx<'_>,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+
letmut new_param_types = Vec::with_capacity(old_param_count asusize + 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 in0..9{
709+
let name = format!("kernel_{num}");
710+
ifletSome(kernel) = cx.get_function(&name){
711+
handle_offload(&cx, kernel);
712+
}
713+
}
714+
}
715+
648716
letmut 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
letmut memtransfer_types = vec![];
2020
letmut 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 in0..9{
2326
let kernel = cx.get_function(&format!("kernel_{num}"));
2427
ifletSome(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)fnLLVMSetFunctionCallConv(Fn:&Value,CC:c_uint);
1130+
pub(crate)fnLLVMAddFunction<'a>(
1131+
Mod:&'aModule,
1132+
Name:*constc_char,
1133+
FunctionTy:&'aType,
1134+
) -> &'aValue;
11301135
pub(crate)fnLLVMDeleteFunction(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)fnLLVMRustOffloadMapper<'a>(M:&'aModule,Fn:&'aValue,Fn:&'aValue);
20202026
pub(crate)fnLLVMRustGetOrInsertFunction<'a>(
20212027
M:&'aModule,
20222028
Name:*constc_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 asc_uint)}
6969
}
7070

71+
pub(crate)fnadd_func(&self,name:&str,ty:&'llType) -> &'llValue{
72+
let name = SmallCStr::new(name);
73+
unsafe{ llvm::LLVMAddFunction(self.llmod(), name.as_ptr(), ty)}
74+
}
75+
7176
pub(crate)fnfunc_params_types(&self,ty:&'llType) -> Vec<&'llType>{
7277
unsafe{
7378
let n_args = llvm::LLVMCountParamTypes(ty)asusize;

‎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
pubtarget_arch:String,
343343
pubtarget_is_like_darwin:bool,
344344
pubtarget_is_like_aix:bool,
345+
pubtarget_is_like_gpu:bool,
345346
pubsplit_debuginfo: rustc_target::spec::SplitDebuginfo,
346347
pubsplit_dwarf_kind: rustc_session::config::SplitDwarfKind,
347348
pubpointer_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)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Auto merge of #148624 - jhpratt:rollup-is5je9r, r=jhpratt · rust-lang/rust@0bbef55 · GitHub
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

38 files changed

Lines changed: 528 additions & 135 deletions

File tree

‎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
ifletSome(msg_from_user) = custom_msg {
145146
cx.dcx()
146147
.emit_err(errors::EnvNotDefinedWithUserMessage{ span, msg_from_user })
148+
}elseifletSome(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
}elseifis_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+
constKNOWN_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+
fnfind_similar_cargo_var(var:&str) -> Option<&'staticstr>{
212+
if !var.starts_with("CARGO_"){
213+
returnNone;
214+
}
215+
216+
let lookup_len = var.chars().count();
217+
let max_dist = std::cmp::max(lookup_len,3) / 3;
218+
letmut best_match = None;
219+
letmut best_distance = usize::MAX;
220+
221+
for&known_var inKNOWN_CARGO_VARS{
222+
ifletSome(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
usecrate::llvm::diagnostic::OptimizationDiagnosticKind::*;
4444
usecrate::llvm::{self,DiagnosticInfo};
4545
usecrate::type_::llvm_type_ptr;
46-
usecrate::{LlvmCodegenBackend,ModuleLlvm, base, common, llvm_util};
46+
usecrate::{LlvmCodegenBackend,ModuleLlvm,SimpleCx,base, common, llvm_util};
4747

4848
pub(crate)fnllvm_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+
fnhandle_offload<'ll>(cx:&'llSimpleCx<'_>,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+
letmut new_param_types = Vec::with_capacity(old_param_count asusize + 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 in0..9{
709+
let name = format!("kernel_{num}");
710+
ifletSome(kernel) = cx.get_function(&name){
711+
handle_offload(&cx, kernel);
712+
}
713+
}
714+
}
715+
648716
letmut 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
letmut memtransfer_types = vec![];
2020
letmut 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 in0..9{
2326
let kernel = cx.get_function(&format!("kernel_{num}"));
2427
ifletSome(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)fnLLVMSetFunctionCallConv(Fn:&Value,CC:c_uint);
1130+
pub(crate)fnLLVMAddFunction<'a>(
1131+
Mod:&'aModule,
1132+
Name:*constc_char,
1133+
FunctionTy:&'aType,
1134+
) -> &'aValue;
11301135
pub(crate)fnLLVMDeleteFunction(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)fnLLVMRustOffloadMapper<'a>(M:&'aModule,Fn:&'aValue,Fn:&'aValue);
20202026
pub(crate)fnLLVMRustGetOrInsertFunction<'a>(
20212027
M:&'aModule,
20222028
Name:*constc_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 asc_uint)}
6969
}
7070

71+
pub(crate)fnadd_func(&self,name:&str,ty:&'llType) -> &'llValue{
72+
let name = SmallCStr::new(name);
73+
unsafe{ llvm::LLVMAddFunction(self.llmod(), name.as_ptr(), ty)}
74+
}
75+
7176
pub(crate)fnfunc_params_types(&self,ty:&'llType) -> Vec<&'llType>{
7277
unsafe{
7378
let n_args = llvm::LLVMCountParamTypes(ty)asusize;

‎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
pubtarget_arch:String,
343343
pubtarget_is_like_darwin:bool,
344344
pubtarget_is_like_aix:bool,
345+
pubtarget_is_like_gpu:bool,
345346
pubsplit_debuginfo: rustc_target::spec::SplitDebuginfo,
346347
pubsplit_dwarf_kind: rustc_session::config::SplitDwarfKind,
347348
pubpointer_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)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Auto merge of #148624 - jhpratt:rollup-is5je9r, r=jhpratt · rust-lang/rust@0bbef55 · GitHub
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

38 files changed

Lines changed: 528 additions & 135 deletions

File tree

‎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
ifletSome(msg_from_user) = custom_msg {
145146
cx.dcx()
146147
.emit_err(errors::EnvNotDefinedWithUserMessage{ span, msg_from_user })
148+
}elseifletSome(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
}elseifis_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+
constKNOWN_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+
fnfind_similar_cargo_var(var:&str) -> Option<&'staticstr>{
212+
if !var.starts_with("CARGO_"){
213+
returnNone;
214+
}
215+
216+
let lookup_len = var.chars().count();
217+
let max_dist = std::cmp::max(lookup_len,3) / 3;
218+
letmut best_match = None;
219+
letmut best_distance = usize::MAX;
220+
221+
for&known_var inKNOWN_CARGO_VARS{
222+
ifletSome(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
usecrate::llvm::diagnostic::OptimizationDiagnosticKind::*;
4444
usecrate::llvm::{self,DiagnosticInfo};
4545
usecrate::type_::llvm_type_ptr;
46-
usecrate::{LlvmCodegenBackend,ModuleLlvm, base, common, llvm_util};
46+
usecrate::{LlvmCodegenBackend,ModuleLlvm,SimpleCx,base, common, llvm_util};
4747

4848
pub(crate)fnllvm_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+
fnhandle_offload<'ll>(cx:&'llSimpleCx<'_>,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+
letmut new_param_types = Vec::with_capacity(old_param_count asusize + 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 in0..9{
709+
let name = format!("kernel_{num}");
710+
ifletSome(kernel) = cx.get_function(&name){
711+
handle_offload(&cx, kernel);
712+
}
713+
}
714+
}
715+
648716
letmut 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
letmut memtransfer_types = vec![];
2020
letmut 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 in0..9{
2326
let kernel = cx.get_function(&format!("kernel_{num}"));
2427
ifletSome(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)fnLLVMSetFunctionCallConv(Fn:&Value,CC:c_uint);
1130+
pub(crate)fnLLVMAddFunction<'a>(
1131+
Mod:&'aModule,
1132+
Name:*constc_char,
1133+
FunctionTy:&'aType,
1134+
) -> &'aValue;
11301135
pub(crate)fnLLVMDeleteFunction(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)fnLLVMRustOffloadMapper<'a>(M:&'aModule,Fn:&'aValue,Fn:&'aValue);
20202026
pub(crate)fnLLVMRustGetOrInsertFunction<'a>(
20212027
M:&'aModule,
20222028
Name:*constc_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 asc_uint)}
6969
}
7070

71+
pub(crate)fnadd_func(&self,name:&str,ty:&'llType) -> &'llValue{
72+
let name = SmallCStr::new(name);
73+
unsafe{ llvm::LLVMAddFunction(self.llmod(), name.as_ptr(), ty)}
74+
}
75+
7176
pub(crate)fnfunc_params_types(&self,ty:&'llType) -> Vec<&'llType>{
7277
unsafe{
7378
let n_args = llvm::LLVMCountParamTypes(ty)asusize;

‎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
pubtarget_arch:String,
343343
pubtarget_is_like_darwin:bool,
344344
pubtarget_is_like_aix:bool,
345+
pubtarget_is_like_gpu:bool,
345346
pubsplit_debuginfo: rustc_target::spec::SplitDebuginfo,
346347
pubsplit_dwarf_kind: rustc_session::config::SplitDwarfKind,
347348
pubpointer_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)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Auto merge of #148624 - jhpratt:rollup-is5je9r, r=jhpratt · rust-lang/rust@0bbef55 · GitHub
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

38 files changed

Lines changed: 528 additions & 135 deletions

File tree

‎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
ifletSome(msg_from_user) = custom_msg {
145146
cx.dcx()
146147
.emit_err(errors::EnvNotDefinedWithUserMessage{ span, msg_from_user })
148+
}elseifletSome(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
}elseifis_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+
constKNOWN_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+
fnfind_similar_cargo_var(var:&str) -> Option<&'staticstr>{
212+
if !var.starts_with("CARGO_"){
213+
returnNone;
214+
}
215+
216+
let lookup_len = var.chars().count();
217+
let max_dist = std::cmp::max(lookup_len,3) / 3;
218+
letmut best_match = None;
219+
letmut best_distance = usize::MAX;
220+
221+
for&known_var inKNOWN_CARGO_VARS{
222+
ifletSome(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
usecrate::llvm::diagnostic::OptimizationDiagnosticKind::*;
4444
usecrate::llvm::{self,DiagnosticInfo};
4545
usecrate::type_::llvm_type_ptr;
46-
usecrate::{LlvmCodegenBackend,ModuleLlvm, base, common, llvm_util};
46+
usecrate::{LlvmCodegenBackend,ModuleLlvm,SimpleCx,base, common, llvm_util};
4747

4848
pub(crate)fnllvm_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+
fnhandle_offload<'ll>(cx:&'llSimpleCx<'_>,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+
letmut new_param_types = Vec::with_capacity(old_param_count asusize + 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 in0..9{
709+
let name = format!("kernel_{num}");
710+
ifletSome(kernel) = cx.get_function(&name){
711+
handle_offload(&cx, kernel);
712+
}
713+
}
714+
}
715+
648716
letmut 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
letmut memtransfer_types = vec![];
2020
letmut 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 in0..9{
2326
let kernel = cx.get_function(&format!("kernel_{num}"));
2427
ifletSome(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)fnLLVMSetFunctionCallConv(Fn:&Value,CC:c_uint);
1130+
pub(crate)fnLLVMAddFunction<'a>(
1131+
Mod:&'aModule,
1132+
Name:*constc_char,
1133+
FunctionTy:&'aType,
1134+
) -> &'aValue;
11301135
pub(crate)fnLLVMDeleteFunction(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)fnLLVMRustOffloadMapper<'a>(M:&'aModule,Fn:&'aValue,Fn:&'aValue);
20202026
pub(crate)fnLLVMRustGetOrInsertFunction<'a>(
20212027
M:&'aModule,
20222028
Name:*constc_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 asc_uint)}
6969
}
7070

71+
pub(crate)fnadd_func(&self,name:&str,ty:&'llType) -> &'llValue{
72+
let name = SmallCStr::new(name);
73+
unsafe{ llvm::LLVMAddFunction(self.llmod(), name.as_ptr(), ty)}
74+
}
75+
7176
pub(crate)fnfunc_params_types(&self,ty:&'llType) -> Vec<&'llType>{
7277
unsafe{
7378
let n_args = llvm::LLVMCountParamTypes(ty)asusize;

‎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
pubtarget_arch:String,
343343
pubtarget_is_like_darwin:bool,
344344
pubtarget_is_like_aix:bool,
345+
pubtarget_is_like_gpu:bool,
345346
pubsplit_debuginfo: rustc_target::spec::SplitDebuginfo,
346347
pubsplit_dwarf_kind: rustc_session::config::SplitDwarfKind,
347348
pubpointer_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)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Auto merge of #148624 - jhpratt:rollup-is5je9r, r=jhpratt · rust-lang/rust@0bbef55 · GitHub
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

38 files changed

Lines changed: 528 additions & 135 deletions

File tree

‎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
ifletSome(msg_from_user) = custom_msg {
145146
cx.dcx()
146147
.emit_err(errors::EnvNotDefinedWithUserMessage{ span, msg_from_user })
148+
}elseifletSome(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
}elseifis_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+
constKNOWN_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+
fnfind_similar_cargo_var(var:&str) -> Option<&'staticstr>{
212+
if !var.starts_with("CARGO_"){
213+
returnNone;
214+
}
215+
216+
let lookup_len = var.chars().count();
217+
let max_dist = std::cmp::max(lookup_len,3) / 3;
218+
letmut best_match = None;
219+
letmut best_distance = usize::MAX;
220+
221+
for&known_var inKNOWN_CARGO_VARS{
222+
ifletSome(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
usecrate::llvm::diagnostic::OptimizationDiagnosticKind::*;
4444
usecrate::llvm::{self,DiagnosticInfo};
4545
usecrate::type_::llvm_type_ptr;
46-
usecrate::{LlvmCodegenBackend,ModuleLlvm, base, common, llvm_util};
46+
usecrate::{LlvmCodegenBackend,ModuleLlvm,SimpleCx,base, common, llvm_util};
4747

4848
pub(crate)fnllvm_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+
fnhandle_offload<'ll>(cx:&'llSimpleCx<'_>,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+
letmut new_param_types = Vec::with_capacity(old_param_count asusize + 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 in0..9{
709+
let name = format!("kernel_{num}");
710+
ifletSome(kernel) = cx.get_function(&name){
711+
handle_offload(&cx, kernel);
712+
}
713+
}
714+
}
715+
648716
letmut 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
letmut memtransfer_types = vec![];
2020
letmut 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 in0..9{
2326
let kernel = cx.get_function(&format!("kernel_{num}"));
2427
ifletSome(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)fnLLVMSetFunctionCallConv(Fn:&Value,CC:c_uint);
1130+
pub(crate)fnLLVMAddFunction<'a>(
1131+
Mod:&'aModule,
1132+
Name:*constc_char,
1133+
FunctionTy:&'aType,
1134+
) -> &'aValue;
11301135
pub(crate)fnLLVMDeleteFunction(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)fnLLVMRustOffloadMapper<'a>(M:&'aModule,Fn:&'aValue,Fn:&'aValue);
20202026
pub(crate)fnLLVMRustGetOrInsertFunction<'a>(
20212027
M:&'aModule,
20222028
Name:*constc_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 asc_uint)}
6969
}
7070

71+
pub(crate)fnadd_func(&self,name:&str,ty:&'llType) -> &'llValue{
72+
let name = SmallCStr::new(name);
73+
unsafe{ llvm::LLVMAddFunction(self.llmod(), name.as_ptr(), ty)}
74+
}
75+
7176
pub(crate)fnfunc_params_types(&self,ty:&'llType) -> Vec<&'llType>{
7277
unsafe{
7378
let n_args = llvm::LLVMCountParamTypes(ty)asusize;

‎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
pubtarget_arch:String,
343343
pubtarget_is_like_darwin:bool,
344344
pubtarget_is_like_aix:bool,
345+
pubtarget_is_like_gpu:bool,
345346
pubsplit_debuginfo: rustc_target::spec::SplitDebuginfo,
346347
pubsplit_dwarf_kind: rustc_session::config::SplitDwarfKind,
347348
pubpointer_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)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Auto merge of #148624 - jhpratt:rollup-is5je9r, r=jhpratt · rust-lang/rust@0bbef55 · GitHub
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

38 files changed

Lines changed: 528 additions & 135 deletions

File tree

‎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
ifletSome(msg_from_user) = custom_msg {
145146
cx.dcx()
146147
.emit_err(errors::EnvNotDefinedWithUserMessage{ span, msg_from_user })
148+
}elseifletSome(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
}elseifis_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+
constKNOWN_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+
fnfind_similar_cargo_var(var:&str) -> Option<&'staticstr>{
212+
if !var.starts_with("CARGO_"){
213+
returnNone;
214+
}
215+
216+
let lookup_len = var.chars().count();
217+
let max_dist = std::cmp::max(lookup_len,3) / 3;
218+
letmut best_match = None;
219+
letmut best_distance = usize::MAX;
220+
221+
for&known_var inKNOWN_CARGO_VARS{
222+
ifletSome(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
usecrate::llvm::diagnostic::OptimizationDiagnosticKind::*;
4444
usecrate::llvm::{self,DiagnosticInfo};
4545
usecrate::type_::llvm_type_ptr;
46-
usecrate::{LlvmCodegenBackend,ModuleLlvm, base, common, llvm_util};
46+
usecrate::{LlvmCodegenBackend,ModuleLlvm,SimpleCx,base, common, llvm_util};
4747

4848
pub(crate)fnllvm_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+
fnhandle_offload<'ll>(cx:&'llSimpleCx<'_>,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+
letmut new_param_types = Vec::with_capacity(old_param_count asusize + 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 in0..9{
709+
let name = format!("kernel_{num}");
710+
ifletSome(kernel) = cx.get_function(&name){
711+
handle_offload(&cx, kernel);
712+
}
713+
}
714+
}
715+
648716
letmut 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
letmut memtransfer_types = vec![];
2020
letmut 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 in0..9{
2326
let kernel = cx.get_function(&format!("kernel_{num}"));
2427
ifletSome(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)fnLLVMSetFunctionCallConv(Fn:&Value,CC:c_uint);
1130+
pub(crate)fnLLVMAddFunction<'a>(
1131+
Mod:&'aModule,
1132+
Name:*constc_char,
1133+
FunctionTy:&'aType,
1134+
) -> &'aValue;
11301135
pub(crate)fnLLVMDeleteFunction(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)fnLLVMRustOffloadMapper<'a>(M:&'aModule,Fn:&'aValue,Fn:&'aValue);
20202026
pub(crate)fnLLVMRustGetOrInsertFunction<'a>(
20212027
M:&'aModule,
20222028
Name:*constc_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 asc_uint)}
6969
}
7070

71+
pub(crate)fnadd_func(&self,name:&str,ty:&'llType) -> &'llValue{
72+
let name = SmallCStr::new(name);
73+
unsafe{ llvm::LLVMAddFunction(self.llmod(), name.as_ptr(), ty)}
74+
}
75+
7176
pub(crate)fnfunc_params_types(&self,ty:&'llType) -> Vec<&'llType>{
7277
unsafe{
7378
let n_args = llvm::LLVMCountParamTypes(ty)asusize;

‎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
pubtarget_arch:String,
343343
pubtarget_is_like_darwin:bool,
344344
pubtarget_is_like_aix:bool,
345+
pubtarget_is_like_gpu:bool,
345346
pubsplit_debuginfo: rustc_target::spec::SplitDebuginfo,
346347
pubsplit_dwarf_kind: rustc_session::config::SplitDwarfKind,
347348
pubpointer_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)