Skip to content

Commit 308dffd

Browse files
committed
Auto merge of #89179 - the8472:rollup-moxrtaj, r=the8472
Rollup of 8 pull requests Successful merges: - #89036 (Fix missing `no_global_oom_handling` cfg-gating) - #89041 (Work around invalid DWARF bugs for fat LTO) - #89046 ("Fix" an overflow in byte position math) - #89127 (Re-enable the `src/test/debuginfo/mutex.rs` test on Windows) - #89133 (Fix ICE with `--cap-lints=allow` and `-Zfuel=...=0`) - #89162 (rustc_index: Add some map-like APIs to `IndexVec`) - #89164 (Document `--show-type-layout` in the rustdoc book) - #89170 (Disable the leak sanitizer on Macos aarch64 for now) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cfff31b + 26c7838 commit 308dffd

File tree

22 files changed

+130
-56
lines changed

22 files changed

+130
-56
lines changed

compiler/rustc_ast_lowering/src/item.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
474474
res
475475
} else {
476476
// Associate an HirId to both ids even if there is no resolution.
477-
self.node_id_to_hir_id.ensure_contains_elem(new_node_id, || None);
478-
debug_assert!(self.node_id_to_hir_id[new_node_id].is_none());
479-
self.node_id_to_hir_id[new_node_id] = Some(hir::HirId::make_owner(new_id));
477+
let _old = self
478+
.node_id_to_hir_id
479+
.insert(new_node_id, hir::HirId::make_owner(new_id));
480+
debug_assert!(_old.is_none());
480481
continue;
481482
};
482483
let ident = *ident;

compiler/rustc_ast_lowering/src/lib.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
469469
let def_id = self.resolver.local_def_id(owner);
470470

471471
// Always allocate the first `HirId` for the owner itself.
472-
self.node_id_to_hir_id.ensure_contains_elem(owner, || None);
473-
if let Some(_lowered) = self.node_id_to_hir_id[owner] {
474-
panic!("with_hir_id_owner must not be called multiple times on owner {:?}", def_id);
475-
}
476-
self.node_id_to_hir_id[owner] = Some(hir::HirId::make_owner(def_id));
472+
let _old = self.node_id_to_hir_id.insert(owner, hir::HirId::make_owner(def_id));
473+
debug_assert_eq!(_old, None);
477474

478475
let current_owner = std::mem::replace(&mut self.current_hir_id_owner, def_id);
479476
let current_local_counter =
@@ -484,8 +481,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
484481
self.current_hir_id_owner = current_owner;
485482
self.item_local_id_counter = current_local_counter;
486483

487-
self.owners.ensure_contains_elem(def_id, || None);
488-
self.owners[def_id] = Some(item);
484+
let _old = self.owners.insert(def_id, item);
485+
debug_assert!(_old.is_none());
489486

490487
def_id
491488
}
@@ -499,18 +496,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
499496
fn lower_node_id(&mut self, ast_node_id: NodeId) -> hir::HirId {
500497
assert_ne!(ast_node_id, DUMMY_NODE_ID);
501498

502-
self.node_id_to_hir_id.ensure_contains_elem(ast_node_id, || None);
503-
if let Some(existing_hir_id) = self.node_id_to_hir_id[ast_node_id] {
504-
existing_hir_id
505-
} else {
499+
*self.node_id_to_hir_id.get_or_insert_with(ast_node_id, || {
506500
// Generate a new `HirId`.
507501
let owner = self.current_hir_id_owner;
508502
let local_id = self.item_local_id_counter;
509503
self.item_local_id_counter.increment_by(1);
510-
let hir_id = hir::HirId { owner, local_id };
511-
self.node_id_to_hir_id[ast_node_id] = Some(hir_id);
512-
hir_id
513-
}
504+
hir::HirId { owner, local_id }
505+
})
514506
}
515507

516508
fn next_id(&mut self) -> hir::HirId {

compiler/rustc_codegen_llvm/src/back/lto.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,20 @@ fn fat_lto(
325325
drop(linker);
326326
save_temp_bitcode(&cgcx, &module, "lto.input");
327327

328+
// Fat LTO also suffers from the invalid DWARF issue similar to Thin LTO.
329+
// Here we rewrite all `DICompileUnit` pointers if there is only one `DICompileUnit`.
330+
// This only works around the problem when codegen-units = 1.
331+
// Refer to the comments in the `optimize_thin_module` function for more details.
332+
let mut cu1 = ptr::null_mut();
333+
let mut cu2 = ptr::null_mut();
334+
unsafe { llvm::LLVMRustLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2) };
335+
if !cu2.is_null() {
336+
let _timer =
337+
cgcx.prof.generic_activity_with_arg("LLVM_fat_lto_patch_debuginfo", &*module.name);
338+
unsafe { llvm::LLVMRustLTOPatchDICompileUnit(llmod, cu1) };
339+
save_temp_bitcode(cgcx, &module, "fat-lto-after-patch");
340+
}
341+
328342
// Internalize everything below threshold to help strip out more modules and such.
329343
unsafe {
330344
let ptr = symbols_below_threshold.as_ptr();
@@ -748,7 +762,7 @@ pub unsafe fn optimize_thin_module(
748762
// an error.
749763
let mut cu1 = ptr::null_mut();
750764
let mut cu2 = ptr::null_mut();
751-
llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
765+
llvm::LLVMRustLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
752766
if !cu2.is_null() {
753767
let msg = "multiple source DICompileUnits found";
754768
return Err(write::llvm_err(&diag_handler, msg));
@@ -847,7 +861,7 @@ pub unsafe fn optimize_thin_module(
847861
let _timer = cgcx
848862
.prof
849863
.generic_activity_with_arg("LLVM_thin_lto_patch_debuginfo", thin_module.name());
850-
llvm::LLVMRustThinLTOPatchDICompileUnit(llmod, cu1);
864+
llvm::LLVMRustLTOPatchDICompileUnit(llmod, cu1);
851865
save_temp_bitcode(cgcx, &module, "thin-lto-after-patch");
852866
}
853867

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -2377,12 +2377,8 @@ extern "C" {
23772377
len: usize,
23782378
out_len: &mut usize,
23792379
) -> *const u8;
2380-
pub fn LLVMRustThinLTOGetDICompileUnit(
2381-
M: &Module,
2382-
CU1: &mut *mut c_void,
2383-
CU2: &mut *mut c_void,
2384-
);
2385-
pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
2380+
pub fn LLVMRustLTOGetDICompileUnit(M: &Module, CU1: &mut *mut c_void, CU2: &mut *mut c_void);
2381+
pub fn LLVMRustLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
23862382

23872383
pub fn LLVMRustLinkerNew(M: &'a Module) -> &'a mut Linker<'a>;
23882384
pub fn LLVMRustLinkerAdd(

compiler/rustc_errors/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
#[macro_use]
1414
extern crate rustc_macros;
1515

16+
#[macro_use]
17+
extern crate tracing;
18+
1619
pub use emitter::ColorConfig;
1720

18-
use tracing::debug;
1921
use Level::*;
2022

2123
use emitter::{is_case_difference, Emitter, EmitterWriter};

compiler/rustc_index/src/bit_set.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1072,13 +1072,9 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
10721072
}
10731073

10741074
fn ensure_row(&mut self, row: R) -> &mut HybridBitSet<C> {
1075-
// Instantiate any missing rows up to and including row `row` with an
1076-
// empty HybridBitSet.
1077-
self.rows.ensure_contains_elem(row, || None);
1078-
1075+
// Instantiate any missing rows up to and including row `row` with an empty HybridBitSet.
10791076
// Then replace row `row` with a full HybridBitSet if necessary.
1080-
let num_columns = self.num_columns;
1081-
self.rows[row].get_or_insert_with(|| HybridBitSet::new_empty(num_columns))
1077+
self.rows.get_or_insert_with(row, || HybridBitSet::new_empty(self.num_columns))
10821078
}
10831079

10841080
/// Sets the cell at `(row, column)` to true. Put another way, insert

compiler/rustc_index/src/vec.rs

+15
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,21 @@ impl<I: Idx, T> IndexVec<I, T> {
720720
}
721721
}
722722

723+
/// `IndexVec` is often used as a map, so it provides some map-like APIs.
724+
impl<I: Idx, T> IndexVec<I, Option<T>> {
725+
#[inline]
726+
pub fn insert(&mut self, index: I, value: T) -> Option<T> {
727+
self.ensure_contains_elem(index, || None);
728+
self[index].replace(value)
729+
}
730+
731+
#[inline]
732+
pub fn get_or_insert_with(&mut self, index: I, value: impl FnOnce() -> T) -> &mut T {
733+
self.ensure_contains_elem(index, || None);
734+
self[index].get_or_insert_with(value)
735+
}
736+
}
737+
723738
impl<I: Idx, T: Clone> IndexVec<I, T> {
724739
#[inline]
725740
pub fn resize(&mut self, new_len: usize, value: T) {

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ LLVMRustGetBitcodeSliceFromObjectData(const char *data,
17471747
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
17481748
// the comment in `back/lto.rs` for why this exists.
17491749
extern "C" void
1750-
LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod,
1750+
LLVMRustLTOGetDICompileUnit(LLVMModuleRef Mod,
17511751
DICompileUnit **A,
17521752
DICompileUnit **B) {
17531753
Module *M = unwrap(Mod);
@@ -1765,7 +1765,7 @@ LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod,
17651765
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
17661766
// the comment in `back/lto.rs` for why this exists.
17671767
extern "C" void
1768-
LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
1768+
LLVMRustLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
17691769
Module *M = unwrap(Mod);
17701770

17711771
// If the original source module didn't have a `DICompileUnit` then try to

compiler/rustc_parse/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#![feature(box_patterns)]
77
#![recursion_limit = "256"]
88

9+
#[macro_use]
10+
extern crate tracing;
11+
912
use rustc_ast as ast;
1013
use rustc_ast::token::{self, Nonterminal, Token, TokenKind};
1114
use rustc_ast::tokenstream::{self, AttributesData, CanSynthesizeMissingTokens, LazyTokenStream};

compiler/rustc_parse/src/parser/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ impl<'a> Parser<'a> {
10841084

10851085
/// If we encounter a parser state that looks like the user has written a `struct` literal with
10861086
/// parentheses instead of braces, recover the parser state and provide suggestions.
1087+
#[instrument(skip(self, seq, snapshot), level = "trace")]
10871088
fn maybe_recover_struct_lit_bad_delims(
10881089
&mut self,
10891090
lo: Span,

compiler/rustc_session/src/session.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,12 @@ impl Session {
902902
let mut fuel = self.optimization_fuel.lock();
903903
ret = fuel.remaining != 0;
904904
if fuel.remaining == 0 && !fuel.out_of_fuel {
905-
self.warn(&format!("optimization-fuel-exhausted: {}", msg()));
905+
if self.diagnostic().can_emit_warnings() {
906+
// We only call `msg` in case we can actually emit warnings.
907+
// Otherwise, this could cause a `delay_good_path_bug` to
908+
// trigger (issue #79546).
909+
self.warn(&format!("optimization-fuel-exhausted: {}", msg()));
910+
}
906911
fuel.out_of_fuel = true;
907912
} else if fuel.remaining > 0 {
908913
fuel.remaining -= 1;

compiler/rustc_span/src/lib.rs

+26-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#[macro_use]
2626
extern crate rustc_macros;
2727

28+
#[macro_use]
29+
extern crate tracing;
30+
2831
use rustc_data_structures::AtomicRef;
2932
use rustc_macros::HashStable_Generic;
3033
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
@@ -782,13 +785,30 @@ impl Span {
782785
/// ^^^^^^^^^^^^^^^^^
783786
/// ```
784787
pub fn until(self, end: Span) -> Span {
785-
let span = self.data();
786-
let end = end.data();
788+
// Most of this function's body is copied from `to`.
789+
// We can't just do `self.to(end.shrink_to_lo())`,
790+
// because to also does some magic where it uses min/max so
791+
// it can handle overlapping spans. Some advanced mis-use of
792+
// `until` with different ctxts makes this visible.
793+
let span_data = self.data();
794+
let end_data = end.data();
795+
// FIXME(jseyfried): `self.ctxt` should always equal `end.ctxt` here (cf. issue #23480).
796+
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
797+
// have an incomplete span than a completely nonsensical one.
798+
if span_data.ctxt != end_data.ctxt {
799+
if span_data.ctxt == SyntaxContext::root() {
800+
return end;
801+
} else if end_data.ctxt == SyntaxContext::root() {
802+
return self;
803+
}
804+
// Both spans fall within a macro.
805+
// FIXME(estebank): check if it is the *same* macro.
806+
}
787807
Span::new(
788-
span.lo,
789-
end.lo,
790-
if end.ctxt == SyntaxContext::root() { end.ctxt } else { span.ctxt },
791-
if span.parent == end.parent { span.parent } else { None },
808+
span_data.lo,
809+
end_data.lo,
810+
if end_data.ctxt == SyntaxContext::root() { end_data.ctxt } else { span_data.ctxt },
811+
if span_data.parent == end_data.parent { span_data.parent } else { None },
792812
)
793813
}
794814

compiler/rustc_span/src/source_map.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,12 @@ impl SourceMap {
474474
f.lookup_line(sp.lo()) != f.lookup_line(sp.hi())
475475
}
476476

477+
#[instrument(skip(self), level = "trace")]
477478
pub fn is_valid_span(&self, sp: Span) -> Result<(Loc, Loc), SpanLinesError> {
478479
let lo = self.lookup_char_pos(sp.lo());
479-
debug!("span_to_lines: lo={:?}", lo);
480+
trace!(?lo);
480481
let hi = self.lookup_char_pos(sp.hi());
481-
debug!("span_to_lines: hi={:?}", hi);
482+
trace!(?hi);
482483
if lo.file.start_pos != hi.file.start_pos {
483484
return Err(SpanLinesError::DistinctSources(DistinctSources {
484485
begin: (lo.file.name.clone(), lo.file.start_pos),

compiler/rustc_target/src/spec/aarch64_apple_darwin.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ pub fn target() -> Target {
44
let mut base = super::apple_base::opts("macos");
55
base.cpu = "apple-a12".to_string();
66
base.max_atomic_width = Some(128);
7-
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::THREAD;
7+
8+
// FIXME: The leak sanitizer currently fails the tests, see #88132.
9+
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;
810

911
base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-arch".to_string(), "arm64".to_string()]);
1012
base.link_env_remove.extend(super::apple_base::macos_link_env_remove());

library/alloc/src/boxed.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
10861086
}
10871087
}
10881088

1089+
#[cfg(not(no_global_oom_handling))]
10891090
#[stable(feature = "rust1", since = "1.0.0")]
10901091
impl<T: Default> Default for Box<T> {
10911092
/// Creates a `Box<T>`, with the `Default` value for T.
@@ -1394,6 +1395,7 @@ impl<A: Allocator> From<Box<str, A>> for Box<[u8], A> {
13941395
}
13951396
}
13961397

1398+
#[cfg(not(no_global_oom_handling))]
13971399
#[stable(feature = "box_from_array", since = "1.45.0")]
13981400
impl<T, const N: usize> From<[T; N]> for Box<[T]> {
13991401
/// Converts a `[T; N]` into a `Box<[T]>`

library/alloc/src/vec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2841,6 +2841,7 @@ impl<T: Clone> From<&mut [T]> for Vec<T> {
28412841
}
28422842
}
28432843

2844+
#[cfg(not(no_global_oom_handling))]
28442845
#[stable(feature = "vec_from_array", since = "1.44.0")]
28452846
impl<T, const N: usize> From<[T; N]> for Vec<T> {
28462847
#[cfg(not(test))]

src/doc/rustdoc/src/unstable-features.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,22 @@ some consideration for their stability, and names that end in a number). Giving
209209
`rustdoc` will disable this sorting and instead make it print the items in the order they appear in
210210
the source.
211211

212+
### `--show-type-layout`: add a section to each type's docs describing its memory layout
213+
214+
Using this flag looks like this:
215+
216+
```bash
217+
$ rustdoc src/lib.rs -Z unstable-options --show-type-layout
218+
```
219+
220+
When this flag is passed, rustdoc will add a "Layout" section at the bottom of
221+
each type's docs page that includes a summary of the type's memory layout as
222+
computed by rustc. For example, rustdoc will show the size in bytes that a value
223+
of that type will take in memory.
224+
225+
Note that most layout information is **completely unstable** and may even differ
226+
between compilations.
227+
212228
### `--resource-suffix`: modifying the name of CSS/JavaScript in crate docs
213229

214230
Using this flag looks like this:
@@ -333,7 +349,7 @@ Some methodology notes about what rustdoc counts in this metric:
333349
Public items that are not documented can be seen with the built-in `missing_docs` lint. Private
334350
items that are not documented can be seen with Clippy's `missing_docs_in_private_items` lint.
335351

336-
## `-w`/`--output-format`: output format
352+
### `-w`/`--output-format`: output format
337353

338354
When using
339355
[`--show-coverage`](https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#--show-coverage-get-statistics-about-code-documentation-coverage),

src/librustdoc/html/render/print_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
16631663
writeln!(
16641664
w,
16651665
"<div class=\"warning\"><p><strong>Note:</strong> Most layout information is \
1666-
completely unstable and may be different between compiler versions and platforms. \
1666+
<strong>completely unstable</strong> and may even differ between compilations. \
16671667
The only exception is types with certain <code>repr(...)</code> attributes. \
16681668
Please see the Rust Reference’s \
16691669
<a href=\"https://doc.rust-lang.org/reference/type-layout.html\">“Type Layout”</a> \

src/test/debuginfo/mutex.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// cdb-only
44
// min-cdb-version: 10.0.21287.1005
55
// compile-flags:-g
6-
// FIXME: Failed on update to 10.0.22000.1
7-
// ignore-windows
86

97
// === CDB TESTS ==================================================================================
108
//
@@ -14,17 +12,17 @@
1412
// cdb-check:m,d [Type: std::sync::mutex::Mutex<i32>]
1513
// cdb-check: [...] inner [Type: std::sys_common::mutex::MovableMutex]
1614
// cdb-check: [...] poison [Type: std::sync::poison::Flag]
17-
// cdb-check: [...] data [Type: core::cell::UnsafeCell<i32>]
15+
// cdb-check: [...] data : 0 [Type: core::cell::UnsafeCell<i32>]
1816

1917
//
2018
// cdb-command:dx m.data,d
21-
// cdb-check:m.data,d [Type: core::cell::UnsafeCell<i32>]
22-
// cdb-check: [...] value : 0 [Type: int]
19+
// cdb-check:m.data,d : 0 [Type: core::cell::UnsafeCell<i32>]
20+
// cdb-check: [<Raw View>] [Type: core::cell::UnsafeCell<i32>]
2321

2422
//
2523
// cdb-command:dx lock,d
26-
// cdb-check:lock,d : Ok [Type: enum$<core::result::Result<std::sync::mutex::MutexGuard<i32>, enum$<std::sync::poison::TryLockError<std::sync::mutex::MutexGuard<i32> >, 0, 1, Poisoned> > >]
27-
// cdb-check: [...] variant$ : Ok (0) [Type: core::result::Result]
24+
// cdb-check:lock,d : Ok [Type: enum$<core::result::Result<std::sync::mutex::MutexGuard<i32>,enum$<std::sync::poison::TryLockError<std::sync::mutex::MutexGuard<i32> >, 0, 1, Poisoned> > >]
25+
// cdb-check: [variant] : Ok
2826
// cdb-check: [...] __0 [Type: std::sync::mutex::MutexGuard<i32>]
2927

3028
use std::sync::Mutex;
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Regression test for the ICE described in #79546.
2+
3+
// compile-flags: --cap-lints=allow -Zfuel=issue79546=0
4+
// check-pass
5+
#![crate_name="issue79546"]
6+
7+
struct S;
8+
fn main() {}

0 commit comments

Comments
 (0)