Skip to content

Commit dbf7748

Browse files
committed
Auto merge of rust-lang#131914 - workingjubilee:rollup-o0p7v51, r=workingjubilee
Rollup of 8 pull requests Successful merges: - rust-lang#127462 (std: uefi: Add basic Env variables) - rust-lang#131537 (Fix range misleading field access) - rust-lang#131838 (bootstrap: allow setting `--jobs` in config.toml) - rust-lang#131871 (x86-32 float return for 'Rust' ABI: treat all float types consistently) - rust-lang#131876 (compiler: Use LLVM's Comdat support) - rust-lang#131890 (Update `use` keyword docs to describe precise capturing) - rust-lang#131899 (Mark unexpected variant res suggestion as having placeholders) - rust-lang#131908 (rustdoc: Switch from FxHash to sha256 for static file hashing.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b27f33a + 8d3e989 commit dbf7748

File tree

23 files changed

+321
-115
lines changed

23 files changed

+321
-115
lines changed

Diff for: Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4584,6 +4584,7 @@ dependencies = [
45844584
"rustdoc-json-types",
45854585
"serde",
45864586
"serde_json",
4587+
"sha2",
45874588
"smallvec",
45884589
"tempfile",
45894590
"threadpool",

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
132132
.collect::<Vec<_>>();
133133
let initializer = cx.const_array(cx.type_ptr(), &name_globals);
134134

135-
let array = llvm::add_global(cx.llmod, cx.val_ty(initializer), "__llvm_coverage_names");
135+
let array = llvm::add_global(cx.llmod, cx.val_ty(initializer), c"__llvm_coverage_names");
136136
llvm::set_global_constant(array, true);
137137
llvm::set_linkage(array, llvm::Linkage::InternalLinkage);
138138
llvm::set_initializer(array, initializer);

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::cell::RefCell;
2+
use std::ffi::CString;
23

34
use libc::c_uint;
45
use rustc_codegen_ssa::traits::{
@@ -12,6 +13,7 @@ use rustc_middle::mir::coverage::CoverageKind;
1213
use rustc_middle::ty::Instance;
1314
use rustc_middle::ty::layout::HasTyCtxt;
1415
use rustc_target::abi::{Align, Size};
16+
use rustc_target::spec::HasTargetSpec;
1517
use tracing::{debug, instrument};
1618

1719
use crate::builder::Builder;
@@ -284,10 +286,10 @@ pub(crate) fn save_cov_data_to_mod<'ll, 'tcx>(
284286
cx: &CodegenCx<'ll, 'tcx>,
285287
cov_data_val: &'ll llvm::Value,
286288
) {
287-
let covmap_var_name = llvm::build_string(|s| unsafe {
289+
let covmap_var_name = CString::new(llvm::build_byte_buffer(|s| unsafe {
288290
llvm::LLVMRustCoverageWriteMappingVarNameToString(s);
289-
})
290-
.expect("Rust Coverage Mapping var name failed UTF-8 conversion");
291+
}))
292+
.unwrap();
291293
debug!("covmap var name: {:?}", covmap_var_name);
292294

293295
let covmap_section_name = llvm::build_string(|s| unsafe {
@@ -322,7 +324,8 @@ pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
322324
// of descriptions play distinct roles in LLVM IR; therefore, assign them different names (by
323325
// appending "u" to the end of the function record var name, to prevent `linkonce_odr` merging.
324326
let func_record_var_name =
325-
format!("__covrec_{:X}{}", func_name_hash, if is_used { "u" } else { "" });
327+
CString::new(format!("__covrec_{:X}{}", func_name_hash, if is_used { "u" } else { "" }))
328+
.unwrap();
326329
debug!("function record var name: {:?}", func_record_var_name);
327330
debug!("function record section name: {:?}", covfun_section_name);
328331

@@ -334,7 +337,9 @@ pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
334337
llvm::set_section(llglobal, covfun_section_name);
335338
// LLVM's coverage mapping format specifies 8-byte alignment for items in this section.
336339
llvm::set_alignment(llglobal, Align::EIGHT);
337-
llvm::set_comdat(cx.llmod, llglobal, &func_record_var_name);
340+
if cx.target_spec().supports_comdat() {
341+
llvm::set_comdat(cx.llmod, llglobal, &func_record_var_name);
342+
}
338343
cx.add_used_global(llglobal);
339344
}
340345

Diff for: compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ unsafe extern "C" {
646646
pub type Attribute;
647647
pub type Metadata;
648648
pub type BasicBlock;
649+
pub type Comdat;
649650
}
650651
#[repr(C)]
651652
pub struct Builder<'a>(InvariantOpaque<'a>);
@@ -1490,6 +1491,9 @@ unsafe extern "C" {
14901491
pub fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
14911492

14921493
pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
1494+
1495+
pub fn LLVMGetOrInsertComdat(M: &Module, Name: *const c_char) -> &Comdat;
1496+
pub fn LLVMSetComdat(V: &Value, C: &Comdat);
14931497
}
14941498

14951499
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2320,7 +2324,6 @@ unsafe extern "C" {
23202324

23212325
pub fn LLVMRustPositionBuilderAtStart<'a>(B: &Builder<'a>, BB: &'a BasicBlock);
23222326

2323-
pub fn LLVMRustSetComdat<'a>(M: &'a Module, V: &'a Value, Name: *const c_char, NameLen: size_t);
23242327
pub fn LLVMRustSetModulePICLevel(M: &Module);
23252328
pub fn LLVMRustSetModulePIELevel(M: &Module);
23262329
pub fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel);

Diff for: compiler/rustc_codegen_llvm/src/llvm/mod.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ pub fn SetFunctionCallConv(fn_: &Value, cc: CallConv) {
178178
// function.
179179
// For more details on COMDAT sections see e.g., https://www.airs.com/blog/archives/52
180180
pub fn SetUniqueComdat(llmod: &Module, val: &Value) {
181-
unsafe {
182-
let name = get_value_name(val);
183-
LLVMRustSetComdat(llmod, val, name.as_ptr().cast(), name.len());
184-
}
181+
let name_buf = get_value_name(val).to_vec();
182+
let name =
183+
CString::from_vec_with_nul(name_buf).or_else(|buf| CString::new(buf.into_bytes())).unwrap();
184+
set_comdat(llmod, val, &name);
185185
}
186186

187187
pub fn SetUnnamedAddress(global: &Value, unnamed: UnnamedAddr) {
@@ -217,8 +217,7 @@ pub fn set_section(llglobal: &Value, section_name: &str) {
217217
}
218218
}
219219

220-
pub fn add_global<'a>(llmod: &'a Module, ty: &'a Type, name: &str) -> &'a Value {
221-
let name_cstr = CString::new(name).expect("unexpected CString error");
220+
pub fn add_global<'a>(llmod: &'a Module, ty: &'a Type, name_cstr: &CStr) -> &'a Value {
222221
unsafe { LLVMAddGlobal(llmod, ty, name_cstr.as_ptr()) }
223222
}
224223

@@ -252,9 +251,14 @@ pub fn set_alignment(llglobal: &Value, align: Align) {
252251
}
253252
}
254253

255-
pub fn set_comdat(llmod: &Module, llglobal: &Value, name: &str) {
254+
/// Get the `name`d comdat from `llmod` and assign it to `llglobal`.
255+
///
256+
/// Inserts the comdat into `llmod` if it does not exist.
257+
/// It is an error to call this if the target does not support comdat.
258+
pub fn set_comdat(llmod: &Module, llglobal: &Value, name: &CStr) {
256259
unsafe {
257-
LLVMRustSetComdat(llmod, llglobal, name.as_ptr().cast(), name.len());
260+
let comdat = LLVMGetOrInsertComdat(llmod, name.as_ptr());
261+
LLVMSetComdat(llglobal, comdat);
258262
}
259263
}
260264

Diff for: compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn report_unexpected_variant_res(
419419
}
420420
}
421421

422-
err.multipart_suggestion_verbose(descr, suggestion, Applicability::MaybeIncorrect);
422+
err.multipart_suggestion_verbose(descr, suggestion, Applicability::HasPlaceholders);
423423
err
424424
}
425425
Res::Def(DefKind::Variant, _) if expr.is_none() => {

Diff for: compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -1658,16 +1658,6 @@ extern "C" void LLVMRustPositionBuilderAtStart(LLVMBuilderRef B,
16581658
unwrap(B)->SetInsertPoint(unwrap(BB), Point);
16591659
}
16601660

1661-
extern "C" void LLVMRustSetComdat(LLVMModuleRef M, LLVMValueRef V,
1662-
const char *Name, size_t NameLen) {
1663-
Triple TargetTriple = Triple(unwrap(M)->getTargetTriple());
1664-
GlobalObject *GV = unwrap<GlobalObject>(V);
1665-
if (TargetTriple.supportsCOMDAT()) {
1666-
StringRef NameRef(Name, NameLen);
1667-
GV->setComdat(unwrap(M)->getOrInsertComdat(NameRef));
1668-
}
1669-
}
1670-
16711661
enum class LLVMRustLinkage {
16721662
ExternalLinkage = 0,
16731663
AvailableExternallyLinkage = 1,

Diff for: compiler/rustc_resolve/src/late.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4011,6 +4011,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
40114011
let instead = res.is_some();
40124012
let suggestion = if let Some((start, end)) = this.diag_metadata.in_range
40134013
&& path[0].ident.span.lo() == end.span.lo()
4014+
&& !matches!(start.kind, ExprKind::Lit(_))
40144015
{
40154016
let mut sugg = ".";
40164017
let mut span = start.span.between(end.span);

Diff for: compiler/rustc_target/src/spec/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2514,6 +2514,13 @@ fn add_link_args(link_args: &mut LinkArgs, flavor: LinkerFlavor, args: &[&'stati
25142514
add_link_args_iter(link_args, flavor, args.iter().copied().map(Cow::Borrowed))
25152515
}
25162516

2517+
impl TargetOptions {
2518+
pub fn supports_comdat(&self) -> bool {
2519+
// XCOFF and MachO don't support COMDAT.
2520+
!self.is_like_aix && !self.is_like_osx
2521+
}
2522+
}
2523+
25172524
impl TargetOptions {
25182525
fn link_args(flavor: LinkerFlavor, args: &[&'static str]) -> LinkArgs {
25192526
let mut link_args = LinkArgs::new();

Diff for: compiler/rustc_ty_utils/src/abi.rs

+15-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::iter;
22

3-
use rustc_abi::Float::*;
43
use rustc_abi::Primitive::{Float, Pointer};
54
use rustc_abi::{Abi, AddressSpace, PointerKind, Scalar, Size};
65
use rustc_hir as hir;
@@ -695,37 +694,31 @@ fn fn_abi_adjust_for_abi<'tcx>(
695694
}
696695

697696
// Avoid returning floats in x87 registers on x86 as loading and storing from x87
698-
// registers will quiet signalling NaNs.
697+
// registers will quiet signalling NaNs. Also avoid using SSE registers since they
698+
// are not always available (depending on target features).
699699
if tcx.sess.target.arch == "x86"
700700
&& arg_idx.is_none()
701701
// Intrinsics themselves are not actual "real" functions, so theres no need to
702702
// change their ABIs.
703703
&& abi != SpecAbi::RustIntrinsic
704704
{
705-
match arg.layout.abi {
706-
// Handle similar to the way arguments with an `Abi::Aggregate` abi are handled
707-
// below, by returning arguments up to the size of a pointer (32 bits on x86)
708-
// cast to an appropriately sized integer.
709-
Abi::Scalar(s) if s.primitive() == Float(F32) => {
710-
// Same size as a pointer, return in a register.
711-
arg.cast_to(Reg::i32());
712-
return;
705+
let has_float = match arg.layout.abi {
706+
Abi::Scalar(s) => matches!(s.primitive(), Float(_)),
707+
Abi::ScalarPair(s1, s2) => {
708+
matches!(s1.primitive(), Float(_)) || matches!(s2.primitive(), Float(_))
713709
}
714-
Abi::Scalar(s) if s.primitive() == Float(F64) => {
715-
// Larger than a pointer, return indirectly.
716-
arg.make_indirect();
717-
return;
718-
}
719-
Abi::ScalarPair(s1, s2)
720-
if matches!(s1.primitive(), Float(F32 | F64))
721-
|| matches!(s2.primitive(), Float(F32 | F64)) =>
722-
{
710+
_ => false, // anyway not passed via registers on x86
711+
};
712+
if has_float {
713+
if arg.layout.size <= Pointer(AddressSpace::DATA).size(cx) {
714+
// Same size or smaller than pointer, return in a register.
715+
arg.cast_to(Reg { kind: RegKind::Integer, size: arg.layout.size });
716+
} else {
723717
// Larger than a pointer, return indirectly.
724718
arg.make_indirect();
725-
return;
726719
}
727-
_ => {}
728-
};
720+
return;
721+
}
729722
}
730723

731724
match arg.layout.abi {

Diff for: config.example.toml

+5
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@
414414
# Specify the location of the Android NDK. Used when targeting Android.
415415
#android-ndk = "/path/to/android-ndk-r26d"
416416

417+
# Number of parallel jobs to be used for building and testing. If set to `0` or
418+
# omitted, it will be automatically determined. This is the `-j`/`--jobs` flag
419+
# passed to cargo invocations.
420+
#jobs = 0
421+
417422
# =============================================================================
418423
# General install configuration options
419424
# =============================================================================

Diff for: library/std/src/keyword_docs.rs

+39-7
Original file line numberDiff line numberDiff line change
@@ -2146,10 +2146,13 @@ mod unsafe_keyword {}
21462146

21472147
#[doc(keyword = "use")]
21482148
//
2149-
/// Import or rename items from other crates or modules.
2149+
/// Import or rename items from other crates or modules, or specify precise capturing
2150+
/// with `use<..>`.
21502151
///
2151-
/// Usually a `use` keyword is used to shorten the path required to refer to a module item.
2152-
/// The keyword may appear in modules, blocks and even functions, usually at the top.
2152+
/// ## Importing items
2153+
///
2154+
/// The `use` keyword is employed to shorten the path required to refer to a module item.
2155+
/// The keyword may appear in modules, blocks, and even functions, typically at the top.
21532156
///
21542157
/// The most basic usage of the keyword is `use path::to::item;`,
21552158
/// though a number of convenient shortcuts are supported:
@@ -2190,19 +2193,48 @@ mod unsafe_keyword {}
21902193
/// // Compiles.
21912194
/// let _ = VariantA;
21922195
///
2193-
/// // Does not compile !
2196+
/// // Does not compile!
21942197
/// let n = new();
21952198
/// ```
21962199
///
2197-
/// For more information on `use` and paths in general, see the [Reference].
2200+
/// For more information on `use` and paths in general, see the [Reference][ref-use-decls].
21982201
///
21992202
/// The differences about paths and the `use` keyword between the 2015 and 2018 editions
2200-
/// can also be found in the [Reference].
2203+
/// can also be found in the [Reference][ref-use-decls].
2204+
///
2205+
/// ## Precise capturing
2206+
///
2207+
/// The `use<..>` syntax is used within certain `impl Trait` bounds to control which generic
2208+
/// parameters are captured. This is important for return-position `impl Trait` (RPIT) types,
2209+
/// as it affects borrow checking by controlling which generic parameters can be used in the
2210+
/// hidden type.
2211+
///
2212+
/// For example, the following function demonstrates an error without precise capturing in
2213+
/// Rust 2021 and earlier editions:
2214+
///
2215+
/// ```rust,compile_fail,edition2021
2216+
/// fn f(x: &()) -> impl Sized { x }
2217+
/// ```
2218+
///
2219+
/// By using `use<'_>` for precise capturing, it can be resolved:
2220+
///
2221+
/// ```rust
2222+
/// fn f(x: &()) -> impl Sized + use<'_> { x }
2223+
/// ```
2224+
///
2225+
/// This syntax specifies that the elided lifetime be captured and therefore available for
2226+
/// use in the hidden type.
2227+
///
2228+
/// In Rust 2024, opaque types automatically capture all lifetime parameters in scope.
2229+
/// `use<..>` syntax serves as an important way of opting-out of that default.
2230+
///
2231+
/// For more details about precise capturing, see the [Reference][ref-impl-trait].
22012232
///
22022233
/// [`crate`]: keyword.crate.html
22032234
/// [`self`]: keyword.self.html
22042235
/// [`super`]: keyword.super.html
2205-
/// [Reference]: ../reference/items/use-declarations.html
2236+
/// [ref-use-decls]: ../reference/items/use-declarations.html
2237+
/// [ref-impl-trait]: ../reference/types/impl-trait.html
22062238
mod use_keyword {}
22072239

22082240
#[doc(keyword = "where")]

Diff for: library/std/src/sys/pal/uefi/helpers.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! - More information about protocols can be found [here](https://edk2-docs.gitbook.io/edk-ii-uefi-driver-writer-s-guide/3_foundation/36_protocols_and_handles)
1111
1212
use r_efi::efi::{self, Guid};
13-
use r_efi::protocols::{device_path, device_path_to_text};
13+
use r_efi::protocols::{device_path, device_path_to_text, shell};
1414

1515
use crate::ffi::{OsStr, OsString};
1616
use crate::io::{self, const_io_error};
@@ -424,3 +424,24 @@ pub(crate) fn os_string_to_raw(s: &OsStr) -> Option<Box<[r_efi::efi::Char16]>> {
424424
let temp = s.encode_wide().chain(Some(0)).collect::<Box<[r_efi::efi::Char16]>>();
425425
if temp[..temp.len() - 1].contains(&0) { None } else { Some(temp) }
426426
}
427+
428+
pub(crate) fn open_shell() -> Option<NonNull<shell::Protocol>> {
429+
static LAST_VALID_HANDLE: AtomicPtr<crate::ffi::c_void> =
430+
AtomicPtr::new(crate::ptr::null_mut());
431+
432+
if let Some(handle) = NonNull::new(LAST_VALID_HANDLE.load(Ordering::Acquire)) {
433+
if let Ok(protocol) = open_protocol::<shell::Protocol>(handle, shell::PROTOCOL_GUID) {
434+
return Some(protocol);
435+
}
436+
}
437+
438+
let handles = locate_handles(shell::PROTOCOL_GUID).ok()?;
439+
for handle in handles {
440+
if let Ok(protocol) = open_protocol::<shell::Protocol>(handle, shell::PROTOCOL_GUID) {
441+
LAST_VALID_HANDLE.store(handle.as_ptr(), Ordering::Release);
442+
return Some(protocol);
443+
}
444+
}
445+
446+
None
447+
}

0 commit comments

Comments
 (0)