Skip to content

Commit bd2621e

Browse files
committed
Auto merge of rust-lang#130854 - matthiaskrgr:rollup-prsu23n, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#129687 (Implement RFC3137 trim-paths sysroot changes - take 2) - rust-lang#129759 (Stabilize `const_refs_to_static`) - rust-lang#130329 (Reorder stack spills so that constants come later.) - rust-lang#130845 (Utf8Chunks: add link to Utf8Chunk) - rust-lang#130846 (Revert Break into the debugger on panic (129019)) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9e394f5 + 58be7fa commit bd2621e

File tree

58 files changed

+374
-682
lines changed

Some content is hidden

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

58 files changed

+374
-682
lines changed

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+40-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::hash_map::Entry;
2+
use std::marker::PhantomData;
23
use std::ops::Range;
34

45
use rustc_data_structures::fx::FxHashMap;
@@ -14,7 +15,7 @@ use rustc_target::abi::{Abi, FieldIdx, FieldsShape, Size, VariantIdx};
1415

1516
use super::operand::{OperandRef, OperandValue};
1617
use super::place::{PlaceRef, PlaceValue};
17-
use super::{FunctionCx, LocalRef};
18+
use super::{FunctionCx, LocalRef, PerLocalVarDebugInfoIndexVec};
1819
use crate::traits::*;
1920

2021
pub struct FunctionDebugContext<'tcx, S, L> {
@@ -48,6 +49,17 @@ pub struct PerLocalVarDebugInfo<'tcx, D> {
4849
pub projection: &'tcx ty::List<mir::PlaceElem<'tcx>>,
4950
}
5051

52+
/// Information needed to emit a constant.
53+
pub struct ConstDebugInfo<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
54+
pub name: String,
55+
pub source_info: mir::SourceInfo,
56+
pub operand: OperandRef<'tcx, Bx::Value>,
57+
pub dbg_var: Bx::DIVariable,
58+
pub dbg_loc: Bx::DILocation,
59+
pub fragment: Option<Range<Size>>,
60+
pub _phantom: PhantomData<&'a ()>,
61+
}
62+
5163
#[derive(Clone, Copy, Debug)]
5264
pub struct DebugScope<S, L> {
5365
pub dbg_scope: S,
@@ -427,19 +439,36 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
427439
}
428440
}
429441

430-
pub(crate) fn debug_introduce_locals(&self, bx: &mut Bx) {
442+
pub(crate) fn debug_introduce_locals(
443+
&self,
444+
bx: &mut Bx,
445+
consts: Vec<ConstDebugInfo<'a, 'tcx, Bx>>,
446+
) {
431447
if bx.sess().opts.debuginfo == DebugInfo::Full || !bx.sess().fewer_names() {
432448
for local in self.locals.indices() {
433449
self.debug_introduce_local(bx, local);
434450
}
451+
452+
for ConstDebugInfo { name, source_info, operand, dbg_var, dbg_loc, fragment, .. } in
453+
consts.into_iter()
454+
{
455+
self.set_debug_loc(bx, source_info);
456+
let base = FunctionCx::spill_operand_to_stack(operand, Some(name), bx);
457+
bx.clear_dbg_loc();
458+
459+
bx.dbg_var_addr(dbg_var, dbg_loc, base.val.llval, Size::ZERO, &[], fragment);
460+
}
435461
}
436462
}
437463

438464
/// Partition all `VarDebugInfo` in `self.mir`, by their base `Local`.
439465
pub(crate) fn compute_per_local_var_debug_info(
440466
&self,
441467
bx: &mut Bx,
442-
) -> Option<IndexVec<mir::Local, Vec<PerLocalVarDebugInfo<'tcx, Bx::DIVariable>>>> {
468+
) -> Option<(
469+
PerLocalVarDebugInfoIndexVec<'tcx, Bx::DIVariable>,
470+
Vec<ConstDebugInfo<'a, 'tcx, Bx>>,
471+
)> {
443472
let full_debug_info = self.cx.sess().opts.debuginfo == DebugInfo::Full;
444473

445474
let target_is_msvc = self.cx.sess().target.is_like_msvc;
@@ -449,6 +478,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
449478
}
450479

451480
let mut per_local = IndexVec::from_elem(vec![], &self.mir.local_decls);
481+
let mut constants = vec![];
452482
let mut params_seen: FxHashMap<_, Bx::DIVariable> = Default::default();
453483
for var in &self.mir.var_debug_info {
454484
let dbg_scope_and_span = if full_debug_info {
@@ -545,23 +575,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
545575
let Some(dbg_loc) = self.dbg_loc(var.source_info) else { continue };
546576

547577
let operand = self.eval_mir_constant_to_operand(bx, &c);
548-
self.set_debug_loc(bx, var.source_info);
549-
let base =
550-
Self::spill_operand_to_stack(operand, Some(var.name.to_string()), bx);
551-
bx.clear_dbg_loc();
552-
553-
bx.dbg_var_addr(
578+
constants.push(ConstDebugInfo {
579+
name: var.name.to_string(),
580+
source_info: var.source_info,
581+
operand,
554582
dbg_var,
555583
dbg_loc,
556-
base.val.llval,
557-
Size::ZERO,
558-
&[],
559584
fragment,
560-
);
585+
_phantom: PhantomData,
586+
});
561587
}
562588
}
563589
}
564590
}
565-
Some(per_local)
591+
Some((per_local, constants))
566592
}
567593
}

compiler/rustc_codegen_ssa/src/mir/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ enum CachedLlbb<T> {
4141
Skip,
4242
}
4343

44+
type PerLocalVarDebugInfoIndexVec<'tcx, V> =
45+
IndexVec<mir::Local, Vec<PerLocalVarDebugInfo<'tcx, V>>>;
46+
4447
/// Master context for codegenning from MIR.
4548
pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
4649
instance: Instance<'tcx>,
@@ -107,8 +110,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
107110

108111
/// All `VarDebugInfo` from the MIR body, partitioned by `Local`.
109112
/// This is `None` if no variable debuginfo/names are needed.
110-
per_local_var_debug_info:
111-
Option<IndexVec<mir::Local, Vec<PerLocalVarDebugInfo<'tcx, Bx::DIVariable>>>>,
113+
per_local_var_debug_info: Option<PerLocalVarDebugInfoIndexVec<'tcx, Bx::DIVariable>>,
112114

113115
/// Caller location propagated if this function has `#[track_caller]`.
114116
caller_location: Option<OperandRef<'tcx, Bx::Value>>,
@@ -216,7 +218,9 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
216218
// monomorphization, and if there is an error during collection then codegen never starts -- so
217219
// we don't have to do it again.
218220

219-
fx.per_local_var_debug_info = fx.compute_per_local_var_debug_info(&mut start_bx);
221+
let (per_local_var_debug_info, consts_debug_info) =
222+
fx.compute_per_local_var_debug_info(&mut start_bx).unzip();
223+
fx.per_local_var_debug_info = per_local_var_debug_info;
220224

221225
let traversal_order = traversal::mono_reachable_reverse_postorder(mir, cx.tcx(), instance);
222226
let memory_locals = analyze::non_ssa_locals(&fx, &traversal_order);
@@ -268,7 +272,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
268272
fx.initialize_locals(local_values);
269273

270274
// Apply debuginfo to the newly allocated locals.
271-
fx.debug_introduce_locals(&mut start_bx);
275+
fx.debug_introduce_locals(&mut start_bx, consts_debug_info.unwrap_or_default());
272276

273277
// If the backend supports coverage, and coverage is enabled for this function,
274278
// do any necessary start-of-function codegen (e.g. locals for MC/DC bitmaps).

compiler/rustc_const_eval/src/check_consts/check.rs

-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
317317
{
318318
self.error_emitted = Some(guar);
319319
}
320-
self.check_op_spanned(ops::StaticAccess, span)
321320
}
322321

323322
/// Returns whether this place can possibly escape the evaluation of the current const/static

compiler/rustc_const_eval/src/check_consts/ops.rs

-28
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_middle::ty::{
1616
suggest_constraining_type_param,
1717
};
1818
use rustc_middle::util::{CallDesugaringKind, CallKind, call_kind};
19-
use rustc_session::parse::feature_err;
2019
use rustc_span::symbol::sym;
2120
use rustc_span::{BytePos, Pos, Span, Symbol};
2221
use rustc_trait_selection::traits::SelectionContext;
@@ -477,33 +476,6 @@ impl<'tcx> NonConstOp<'tcx> for RawPtrToIntCast {
477476
}
478477
}
479478

480-
/// An access to a (non-thread-local) `static`.
481-
#[derive(Debug)]
482-
pub(crate) struct StaticAccess;
483-
impl<'tcx> NonConstOp<'tcx> for StaticAccess {
484-
fn status_in_item(&self, ccx: &ConstCx<'_, 'tcx>) -> Status {
485-
if let hir::ConstContext::Static(_) = ccx.const_kind() {
486-
Status::Allowed
487-
} else {
488-
Status::Unstable(sym::const_refs_to_static)
489-
}
490-
}
491-
492-
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
493-
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
494-
let mut err = feature_err(
495-
&ccx.tcx.sess,
496-
sym::const_refs_to_static,
497-
span,
498-
format!("referencing statics in {}s is unstable", ccx.const_kind(),),
499-
);
500-
err
501-
.note("`static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable.")
502-
.help("to fix this, the value can be extracted to a `const` and then used.");
503-
err
504-
}
505-
}
506-
507479
/// An access to a thread-local `static`.
508480
#[derive(Debug)]
509481
pub(crate) struct ThreadLocalAccess;

compiler/rustc_error_codes/src/error_codes/E0013.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ variable cannot refer to a static variable.
55

66
Erroneous code example:
77

8-
```compile_fail,E0658
8+
```
99
static X: i32 = 42;
1010
const Y: i32 = X;
1111
```

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ declare_features! (
151151
(accepted, const_raw_ptr_deref, "1.58.0", Some(51911)),
152152
/// Allows references to types with interior mutability within constants
153153
(accepted, const_refs_to_cell, "CURRENT_RUSTC_VERSION", Some(80384)),
154+
/// Allows creating pointers and references to `static` items in constants.
155+
(accepted, const_refs_to_static, "CURRENT_RUSTC_VERSION", Some(119618)),
154156
/// Allows implementing `Copy` for closures where possible (RFC 2132).
155157
(accepted, copy_closures, "1.26.0", Some(44490)),
156158
/// Allows `crate` in paths.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,6 @@ declare_features! (
407407
(unstable, const_for, "1.56.0", Some(87575)),
408408
/// Be more precise when looking for live drops in a const context.
409409
(unstable, const_precise_live_drops, "1.46.0", Some(73255)),
410-
/// Allows creating pointers and references to `static` items in constants.
411-
(unstable, const_refs_to_static, "1.78.0", Some(119618)),
412410
/// Allows `impl const Trait for T` syntax.
413411
(unstable, const_trait_impl, "1.42.0", Some(67792)),
414412
/// Allows the `?` operator in const contexts.

compiler/rustc_metadata/src/rmeta/decoder.rs

+56-49
Original file line numberDiff line numberDiff line change
@@ -1622,56 +1622,63 @@ impl<'a> CrateMetadataRef<'a> {
16221622
);
16231623

16241624
for virtual_dir in virtual_rust_source_base_dir.iter().flatten() {
1625-
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
1626-
if let rustc_span::FileName::Real(old_name) = name {
1627-
if let rustc_span::RealFileName::Remapped { local_path: _, virtual_name } =
1628-
old_name
1629-
{
1630-
if let Ok(rest) = virtual_name.strip_prefix(virtual_dir) {
1631-
let virtual_name = virtual_name.clone();
1632-
1633-
// The std library crates are in
1634-
// `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
1635-
// may be in `$sysroot/lib/rustlib/src/rust/` directly. So we
1636-
// detect crates from the std libs and handle them specially.
1637-
const STD_LIBS: &[&str] = &[
1638-
"core",
1639-
"alloc",
1640-
"std",
1641-
"test",
1642-
"term",
1643-
"unwind",
1644-
"proc_macro",
1645-
"panic_abort",
1646-
"panic_unwind",
1647-
"profiler_builtins",
1648-
"rtstartup",
1649-
"rustc-std-workspace-core",
1650-
"rustc-std-workspace-alloc",
1651-
"rustc-std-workspace-std",
1652-
"backtrace",
1653-
];
1654-
let is_std_lib = STD_LIBS.iter().any(|l| rest.starts_with(l));
1655-
1656-
let new_path = if is_std_lib {
1657-
real_dir.join("library").join(rest)
1658-
} else {
1659-
real_dir.join(rest)
1660-
};
1661-
1662-
debug!(
1663-
"try_to_translate_virtual_to_real: `{}` -> `{}`",
1664-
virtual_name.display(),
1665-
new_path.display(),
1666-
);
1667-
let new_name = rustc_span::RealFileName::Remapped {
1668-
local_path: Some(new_path),
1669-
virtual_name,
1670-
};
1671-
*old_name = new_name;
1672-
}
1625+
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir
1626+
&& let rustc_span::FileName::Real(old_name) = name
1627+
&& let rustc_span::RealFileName::Remapped { local_path: _, virtual_name } =
1628+
old_name
1629+
&& let Ok(rest) = virtual_name.strip_prefix(virtual_dir)
1630+
{
1631+
// The std library crates are in
1632+
// `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
1633+
// may be in `$sysroot/lib/rustlib/src/rust/` directly. So we
1634+
// detect crates from the std libs and handle them specially.
1635+
const STD_LIBS: &[&str] = &[
1636+
"core",
1637+
"alloc",
1638+
"std",
1639+
"test",
1640+
"term",
1641+
"unwind",
1642+
"proc_macro",
1643+
"panic_abort",
1644+
"panic_unwind",
1645+
"profiler_builtins",
1646+
"rtstartup",
1647+
"rustc-std-workspace-core",
1648+
"rustc-std-workspace-alloc",
1649+
"rustc-std-workspace-std",
1650+
"backtrace",
1651+
];
1652+
let is_std_lib = STD_LIBS.iter().any(|l| rest.starts_with(l));
1653+
1654+
let new_path = if is_std_lib {
1655+
real_dir.join("library").join(rest)
1656+
} else {
1657+
real_dir.join(rest)
1658+
};
1659+
1660+
debug!(
1661+
"try_to_translate_virtual_to_real: `{}` -> `{}`",
1662+
virtual_name.display(),
1663+
new_path.display(),
1664+
);
1665+
1666+
// Check if the translated real path is affected by any user-requested
1667+
// remaps via --remap-path-prefix. Apply them if so.
1668+
// Note that this is a special case for imported rust-src paths specified by
1669+
// https://rust-lang.github.io/rfcs/3127-trim-paths.html#handling-sysroot-paths.
1670+
// Other imported paths are not currently remapped (see #66251).
1671+
let (user_remapped, applied) =
1672+
sess.source_map().path_mapping().map_prefix(&new_path);
1673+
let new_name = if applied {
1674+
rustc_span::RealFileName::Remapped {
1675+
local_path: Some(new_path.clone()),
1676+
virtual_name: user_remapped.to_path_buf(),
16731677
}
1674-
}
1678+
} else {
1679+
rustc_span::RealFileName::LocalPath(new_path)
1680+
};
1681+
*old_name = new_name;
16751682
}
16761683
}
16771684
};

library/core/src/str/lossy.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ impl [u8] {
88
/// Creates an iterator over the contiguous valid UTF-8 ranges of this
99
/// slice, and the non-UTF-8 fragments in between.
1010
///
11+
/// See the [`Utf8Chunk`] type for documenation of the items yielded by this iterator.
12+
///
1113
/// # Examples
1214
///
1315
/// This function formats arbitrary but mostly-UTF-8 bytes into Rust source
@@ -148,6 +150,8 @@ impl fmt::Debug for Debug<'_> {
148150
/// If you want a simple conversion from UTF-8 byte slices to string slices,
149151
/// [`from_utf8`] is easier to use.
150152
///
153+
/// See the [`Utf8Chunk`] type for documenation of the items yielded by this iterator.
154+
///
151155
/// [byteslice]: slice
152156
/// [`from_utf8`]: super::from_utf8
153157
///

library/std/src/panicking.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use crate::mem::{self, ManuallyDrop};
2323
use crate::panic::{BacktraceStyle, PanicHookInfo};
2424
use crate::sync::atomic::{AtomicBool, Ordering};
2525
use crate::sync::{PoisonError, RwLock};
26+
use crate::sys::backtrace;
2627
use crate::sys::stdio::panic_output;
27-
use crate::sys::{backtrace, dbg};
2828
use crate::{fmt, intrinsics, process, thread};
2929

3030
// Binary interface to the panic runtime that the standard library depends on.
@@ -859,29 +859,13 @@ pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
859859
#[cfg_attr(not(test), rustc_std_internal_symbol)]
860860
#[cfg(not(feature = "panic_immediate_abort"))]
861861
fn rust_panic(msg: &mut dyn PanicPayload) -> ! {
862-
// Break into the debugger if it is attached.
863-
// The return value is not currently used.
864-
//
865-
// This function isn't used anywhere else, and
866-
// using inside `#[panic_handler]` doesn't seem
867-
// to count, so a warning is issued.
868-
let _ = dbg::breakpoint_if_debugging();
869-
870862
let code = unsafe { __rust_start_panic(msg) };
871863
rtabort!("failed to initiate panic, error {code}")
872864
}
873865

874866
#[cfg_attr(not(test), rustc_std_internal_symbol)]
875867
#[cfg(feature = "panic_immediate_abort")]
876868
fn rust_panic(_: &mut dyn PanicPayload) -> ! {
877-
// Break into the debugger if it is attached.
878-
// The return value is not currently used.
879-
//
880-
// This function isn't used anywhere else, and
881-
// using inside `#[panic_handler]` doesn't seem
882-
// to count, so a warning is issued.
883-
let _ = dbg::breakpoint_if_debugging();
884-
885869
unsafe {
886870
crate::intrinsics::abort();
887871
}

0 commit comments

Comments
 (0)