Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #89179

Merged
merged 20 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
be5a5b7
Fix missing `no_global_oom_handling` cfg-gating
nbdd0121 Sep 17, 2021
d5de680
Work around invalid DWARF bugs for fat LTO
sticnarf Sep 17, 2021
4281380
Add some more tracing
oli-obk Sep 20, 2021
c9fe093
Avoid the overflow with rustc+debugassertions in issue-44406
oli-obk Sep 20, 2021
bd5bc49
Re-enable the `src/test/debuginfo/mutex.rs` test on Windows
wesleywiser Sep 20, 2021
8c5bdb9
Fix ICE with `--cap-lints=allow` and `-Zfuel=...=0`
FabianWolff Sep 20, 2021
fbe5e5c
rustc_index: Add some map-like APIs to `IndexVec`
petrochenkov Sep 21, 2021
71a4add
Document `--show-type-layout` in the rustdoc book
camelid Sep 22, 2021
57399e2
Fix inconsistent heading level in the rustdoc book
camelid Sep 22, 2021
490a8cf
rustdoc: Note that type layout may differ between compilations
camelid Sep 22, 2021
fcb837b
rustdoc: Emphasize "completely unstable"
camelid Sep 22, 2021
59e37c8
Disable the leak sanitizer on Macos aarch64 for now.
hkratz Sep 22, 2021
0063551
Rollup merge of #89036 - nbdd0121:alloc, r=yaahc
the8472 Sep 22, 2021
1deef1f
Rollup merge of #89041 - sticnarf:sticnarf/fat-lto-dwarf, r=nagisa
the8472 Sep 22, 2021
5948a7b
Rollup merge of #89046 - oli-obk:fix_oflo, r=estebank
the8472 Sep 22, 2021
0cbddff
Rollup merge of #89127 - wesleywiser:reenable_mutex_debuginfo_test, r…
the8472 Sep 22, 2021
3bdc894
Rollup merge of #89133 - FabianWolff:issue-79546, r=michaelwoerister
the8472 Sep 22, 2021
91af000
Rollup merge of #89162 - petrochenkov:ivmap, r=davidtwco
the8472 Sep 22, 2021
3cb28de
Rollup merge of #89164 - camelid:show-type-layout-docs, r=jyn514
the8472 Sep 22, 2021
26c7838
Rollup merge of #89170 - rusticstuff:aarch64_macos_disable_leak_sanit…
the8472 Sep 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
res
} else {
// Associate an HirId to both ids even if there is no resolution.
self.node_id_to_hir_id.ensure_contains_elem(new_node_id, || None);
debug_assert!(self.node_id_to_hir_id[new_node_id].is_none());
self.node_id_to_hir_id[new_node_id] = Some(hir::HirId::make_owner(new_id));
let _old = self
.node_id_to_hir_id
.insert(new_node_id, hir::HirId::make_owner(new_id));
debug_assert!(_old.is_none());
continue;
};
let ident = *ident;
Expand Down
22 changes: 7 additions & 15 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let def_id = self.resolver.local_def_id(owner);

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

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

self.owners.ensure_contains_elem(def_id, || None);
self.owners[def_id] = Some(item);
let _old = self.owners.insert(def_id, item);
debug_assert!(_old.is_none());

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

self.node_id_to_hir_id.ensure_contains_elem(ast_node_id, || None);
if let Some(existing_hir_id) = self.node_id_to_hir_id[ast_node_id] {
existing_hir_id
} else {
*self.node_id_to_hir_id.get_or_insert_with(ast_node_id, || {
// Generate a new `HirId`.
let owner = self.current_hir_id_owner;
let local_id = self.item_local_id_counter;
self.item_local_id_counter.increment_by(1);
let hir_id = hir::HirId { owner, local_id };
self.node_id_to_hir_id[ast_node_id] = Some(hir_id);
hir_id
}
hir::HirId { owner, local_id }
})
}

fn next_id(&mut self) -> hir::HirId {
Expand Down
18 changes: 16 additions & 2 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,20 @@ fn fat_lto(
drop(linker);
save_temp_bitcode(&cgcx, &module, "lto.input");

// Fat LTO also suffers from the invalid DWARF issue similar to Thin LTO.
// Here we rewrite all `DICompileUnit` pointers if there is only one `DICompileUnit`.
// This only works around the problem when codegen-units = 1.
// Refer to the comments in the `optimize_thin_module` function for more details.
let mut cu1 = ptr::null_mut();
let mut cu2 = ptr::null_mut();
unsafe { llvm::LLVMRustLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2) };
if !cu2.is_null() {
let _timer =
cgcx.prof.generic_activity_with_arg("LLVM_fat_lto_patch_debuginfo", &*module.name);
unsafe { llvm::LLVMRustLTOPatchDICompileUnit(llmod, cu1) };
save_temp_bitcode(cgcx, &module, "fat-lto-after-patch");
}

// Internalize everything below threshold to help strip out more modules and such.
unsafe {
let ptr = symbols_below_threshold.as_ptr();
Expand Down Expand Up @@ -748,7 +762,7 @@ pub unsafe fn optimize_thin_module(
// an error.
let mut cu1 = ptr::null_mut();
let mut cu2 = ptr::null_mut();
llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
llvm::LLVMRustLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
if !cu2.is_null() {
let msg = "multiple source DICompileUnits found";
return Err(write::llvm_err(&diag_handler, msg));
Expand Down Expand Up @@ -847,7 +861,7 @@ pub unsafe fn optimize_thin_module(
let _timer = cgcx
.prof
.generic_activity_with_arg("LLVM_thin_lto_patch_debuginfo", thin_module.name());
llvm::LLVMRustThinLTOPatchDICompileUnit(llmod, cu1);
llvm::LLVMRustLTOPatchDICompileUnit(llmod, cu1);
save_temp_bitcode(cgcx, &module, "thin-lto-after-patch");
}

Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2377,12 +2377,8 @@ extern "C" {
len: usize,
out_len: &mut usize,
) -> *const u8;
pub fn LLVMRustThinLTOGetDICompileUnit(
M: &Module,
CU1: &mut *mut c_void,
CU2: &mut *mut c_void,
);
pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
pub fn LLVMRustLTOGetDICompileUnit(M: &Module, CU1: &mut *mut c_void, CU2: &mut *mut c_void);
pub fn LLVMRustLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);

pub fn LLVMRustLinkerNew(M: &'a Module) -> &'a mut Linker<'a>;
pub fn LLVMRustLinkerAdd(
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#[macro_use]
extern crate rustc_macros;

#[macro_use]
extern crate tracing;

pub use emitter::ColorConfig;

use tracing::debug;
use Level::*;

use emitter::{is_case_difference, Emitter, EmitterWriter};
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,13 +1072,9 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
}

fn ensure_row(&mut self, row: R) -> &mut HybridBitSet<C> {
// Instantiate any missing rows up to and including row `row` with an
// empty HybridBitSet.
self.rows.ensure_contains_elem(row, || None);

// Instantiate any missing rows up to and including row `row` with an empty HybridBitSet.
// Then replace row `row` with a full HybridBitSet if necessary.
let num_columns = self.num_columns;
self.rows[row].get_or_insert_with(|| HybridBitSet::new_empty(num_columns))
self.rows.get_or_insert_with(row, || HybridBitSet::new_empty(self.num_columns))
}

/// Sets the cell at `(row, column)` to true. Put another way, insert
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_index/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,21 @@ impl<I: Idx, T> IndexVec<I, T> {
}
}

/// `IndexVec` is often used as a map, so it provides some map-like APIs.
impl<I: Idx, T> IndexVec<I, Option<T>> {
#[inline]
pub fn insert(&mut self, index: I, value: T) -> Option<T> {
self.ensure_contains_elem(index, || None);
self[index].replace(value)
}

#[inline]
pub fn get_or_insert_with(&mut self, index: I, value: impl FnOnce() -> T) -> &mut T {
self.ensure_contains_elem(index, || None);
self[index].get_or_insert_with(value)
}
}

impl<I: Idx, T: Clone> IndexVec<I, T> {
#[inline]
pub fn resize(&mut self, new_len: usize, value: T) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,7 @@ LLVMRustGetBitcodeSliceFromObjectData(const char *data,
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
// the comment in `back/lto.rs` for why this exists.
extern "C" void
LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod,
LLVMRustLTOGetDICompileUnit(LLVMModuleRef Mod,
DICompileUnit **A,
DICompileUnit **B) {
Module *M = unwrap(Mod);
Expand All @@ -1765,7 +1765,7 @@ LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod,
// Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See
// the comment in `back/lto.rs` for why this exists.
extern "C" void
LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
LLVMRustLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) {
Module *M = unwrap(Mod);

// If the original source module didn't have a `DICompileUnit` then try to
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#![feature(box_patterns)]
#![recursion_limit = "256"]

#[macro_use]
extern crate tracing;

use rustc_ast as ast;
use rustc_ast::token::{self, Nonterminal, Token, TokenKind};
use rustc_ast::tokenstream::{self, AttributesData, CanSynthesizeMissingTokens, LazyTokenStream};
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ impl<'a> Parser<'a> {

/// If we encounter a parser state that looks like the user has written a `struct` literal with
/// parentheses instead of braces, recover the parser state and provide suggestions.
#[instrument(skip(self, seq, snapshot), level = "trace")]
fn maybe_recover_struct_lit_bad_delims(
&mut self,
lo: Span,
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,12 @@ impl Session {
let mut fuel = self.optimization_fuel.lock();
ret = fuel.remaining != 0;
if fuel.remaining == 0 && !fuel.out_of_fuel {
self.warn(&format!("optimization-fuel-exhausted: {}", msg()));
if self.diagnostic().can_emit_warnings() {
// We only call `msg` in case we can actually emit warnings.
// Otherwise, this could cause a `delay_good_path_bug` to
// trigger (issue #79546).
self.warn(&format!("optimization-fuel-exhausted: {}", msg()));
}
fuel.out_of_fuel = true;
} else if fuel.remaining > 0 {
fuel.remaining -= 1;
Expand Down
32 changes: 26 additions & 6 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#[macro_use]
extern crate rustc_macros;

#[macro_use]
extern crate tracing;

use rustc_data_structures::AtomicRef;
use rustc_macros::HashStable_Generic;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
Expand Down Expand Up @@ -782,13 +785,30 @@ impl Span {
/// ^^^^^^^^^^^^^^^^^
/// ```
pub fn until(self, end: Span) -> Span {
let span = self.data();
let end = end.data();
// Most of this function's body is copied from `to`.
// We can't just do `self.to(end.shrink_to_lo())`,
// because to also does some magic where it uses min/max so
// it can handle overlapping spans. Some advanced mis-use of
// `until` with different ctxts makes this visible.
let span_data = self.data();
let end_data = end.data();
// FIXME(jseyfried): `self.ctxt` should always equal `end.ctxt` here (cf. issue #23480).
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
// have an incomplete span than a completely nonsensical one.
if span_data.ctxt != end_data.ctxt {
if span_data.ctxt == SyntaxContext::root() {
return end;
} else if end_data.ctxt == SyntaxContext::root() {
return self;
}
// Both spans fall within a macro.
// FIXME(estebank): check if it is the *same* macro.
}
Span::new(
span.lo,
end.lo,
if end.ctxt == SyntaxContext::root() { end.ctxt } else { span.ctxt },
if span.parent == end.parent { span.parent } else { None },
span_data.lo,
end_data.lo,
if end_data.ctxt == SyntaxContext::root() { end_data.ctxt } else { span_data.ctxt },
if span_data.parent == end_data.parent { span_data.parent } else { None },
)
}

Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,12 @@ impl SourceMap {
f.lookup_line(sp.lo()) != f.lookup_line(sp.hi())
}

#[instrument(skip(self), level = "trace")]
pub fn is_valid_span(&self, sp: Span) -> Result<(Loc, Loc), SpanLinesError> {
let lo = self.lookup_char_pos(sp.lo());
debug!("span_to_lines: lo={:?}", lo);
trace!(?lo);
let hi = self.lookup_char_pos(sp.hi());
debug!("span_to_lines: hi={:?}", hi);
trace!(?hi);
if lo.file.start_pos != hi.file.start_pos {
return Err(SpanLinesError::DistinctSources(DistinctSources {
begin: (lo.file.name.clone(), lo.file.start_pos),
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_target/src/spec/aarch64_apple_darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ pub fn target() -> Target {
let mut base = super::apple_base::opts("macos");
base.cpu = "apple-a12".to_string();
base.max_atomic_width = Some(128);
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::THREAD;

// FIXME: The leak sanitizer currently fails the tests, see #88132.
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::THREAD;

base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-arch".to_string(), "arm64".to_string()]);
base.link_env_remove.extend(super::apple_base::macos_link_env_remove());
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
}
}

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

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "box_from_array", since = "1.45.0")]
impl<T, const N: usize> From<[T; N]> for Box<[T]> {
/// Converts a `[T; N]` into a `Box<[T]>`
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2841,6 +2841,7 @@ impl<T: Clone> From<&mut [T]> for Vec<T> {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "vec_from_array", since = "1.44.0")]
impl<T, const N: usize> From<[T; N]> for Vec<T> {
#[cfg(not(test))]
Expand Down
18 changes: 17 additions & 1 deletion src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ some consideration for their stability, and names that end in a number). Giving
`rustdoc` will disable this sorting and instead make it print the items in the order they appear in
the source.

### `--show-type-layout`: add a section to each type's docs describing its memory layout

Using this flag looks like this:

```bash
$ rustdoc src/lib.rs -Z unstable-options --show-type-layout
```

When this flag is passed, rustdoc will add a "Layout" section at the bottom of
each type's docs page that includes a summary of the type's memory layout as
computed by rustc. For example, rustdoc will show the size in bytes that a value
of that type will take in memory.

Note that most layout information is **completely unstable** and may even differ
between compilations.

### `--resource-suffix`: modifying the name of CSS/JavaScript in crate docs

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

## `-w`/`--output-format`: output format
### `-w`/`--output-format`: output format

When using
[`--show-coverage`](https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#--show-coverage-get-statistics-about-code-documentation-coverage),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
writeln!(
w,
"<div class=\"warning\"><p><strong>Note:</strong> Most layout information is \
completely unstable and may be different between compiler versions and platforms. \
<strong>completely unstable</strong> and may even differ between compilations. \
The only exception is types with certain <code>repr(...)</code> attributes. \
Please see the Rust Reference’s \
<a href=\"https://doc.rust-lang.org/reference/type-layout.html\">“Type Layout”</a> \
Expand Down
12 changes: 5 additions & 7 deletions src/test/debuginfo/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// cdb-only
// min-cdb-version: 10.0.21287.1005
// compile-flags:-g
// FIXME: Failed on update to 10.0.22000.1
// ignore-windows

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

//
// cdb-command:dx m.data,d
// cdb-check:m.data,d [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [...] value : 0 [Type: int]
// cdb-check:m.data,d : 0 [Type: core::cell::UnsafeCell<i32>]
// cdb-check: [<Raw View>] [Type: core::cell::UnsafeCell<i32>]

//
// cdb-command:dx lock,d
// 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> > >]
// cdb-check: [...] variant$ : Ok (0) [Type: core::result::Result]
// 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> > >]
// cdb-check: [variant] : Ok
// cdb-check: [...] __0 [Type: std::sync::mutex::MutexGuard<i32>]

use std::sync::Mutex;
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/lint/issue-79546-fuel-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Regression test for the ICE described in #79546.

// compile-flags: --cap-lints=allow -Zfuel=issue79546=0
// check-pass
#![crate_name="issue79546"]

struct S;
fn main() {}
Loading