Skip to content

Commit 308dffd

Browse files
committed
Auto merge of rust-lang#89179 - the8472:rollup-moxrtaj, r=the8472
Rollup of 8 pull requests Successful merges: - rust-lang#89036 (Fix missing `no_global_oom_handling` cfg-gating) - rust-lang#89041 (Work around invalid DWARF bugs for fat LTO) - rust-lang#89046 ("Fix" an overflow in byte position math) - rust-lang#89127 (Re-enable the `src/test/debuginfo/mutex.rs` test on Windows) - rust-lang#89133 (Fix ICE with `--cap-lints=allow` and `-Zfuel=...=0`) - rust-lang#89162 (rustc_index: Add some map-like APIs to `IndexVec`) - rust-lang#89164 (Document `--show-type-layout` in the rustdoc book) - rust-lang#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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 7 additions & 15 deletions
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

Lines changed: 16 additions & 2 deletions
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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 2 additions & 6 deletions
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

Lines changed: 15 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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,

0 commit comments

Comments
 (0)