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 9 pull requests #119648

Merged
merged 32 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
786e0bb
bootstrap: Move -Clto= setting from Rustc::run to rustc_cargo
xry111 Dec 29, 2023
1ab60f2
rustdoc-search: fix inaccurate type descriptions
notriddle Dec 31, 2023
86b9550
rustdoc-search: tighter encoding for `f` index
notriddle Dec 31, 2023
a68ac32
Clean up serialization code nits
notriddle Jan 4, 2024
506b9f9
coverage: Avoid early returns from `mir_to_initial_sorted_coverage_sp…
Zalathar Dec 22, 2023
df0df52
coverage: Overhaul how "visible macros" are determined
Zalathar Dec 28, 2023
cd3a976
coverage: Hoist the removal of unwanted macro expansion spans
Zalathar Dec 21, 2023
d4d2f14
coverage: Hoist the splitting of visible macro invocations
Zalathar Dec 22, 2023
cd50843
coverage: Split out `SpanFromMir` from `CoverageSpan`
Zalathar Dec 22, 2023
514e026
coverage: Make the remaining fields of `CoverageSpan` non-public
Zalathar Dec 28, 2023
ddfcf86
Allow emitting diagnostics from the `#[diagnostic]` namespace without a
weiznich Dec 21, 2023
2c3aeea
Replace some usage of `#[rustc_on_unimplemented]` with
weiznich Dec 22, 2023
91e1af3
Add a test that emitting diagnostics does not require the crate to use
weiznich Dec 23, 2023
97c8238
remove duplicate test
RalfJung Jan 5, 2024
54967d7
Ignore a rustdoc test
fmease Jan 5, 2024
004bfc5
Add notes about the serialization format
notriddle Jan 5, 2024
2746748
fix OOM when `ty::Instance` is used in query description
Jan 5, 2024
339fa31
fix cycle error for "use constructor" suggestion
Jan 5, 2024
7366bda
Handle ForeignItem as TAIT scope.
cjgillot Dec 29, 2023
6dfdeab
Do not run check on foreign items.
cjgillot Dec 31, 2023
eeaea57
Rebase fallout.
cjgillot Jan 5, 2024
0489fd0
library: Fix warnings in rtstartup
petrochenkov Jan 5, 2024
0d70e58
library: Fix a symlink test failing on Windows
petrochenkov Jan 5, 2024
bacddd3
Rollup merge of #119208 - Zalathar:hoist, r=WaffleLapkin,Swatinem
compiler-errors Jan 6, 2024
d90c702
Rollup merge of #119216 - weiznich:use_diagnostic_namespace_in_stdlib…
compiler-errors Jan 6, 2024
98ba299
Rollup merge of #119414 - xry111:xry111/lto-test, r=Mark-Simulacrum
compiler-errors Jan 6, 2024
9585ebc
Rollup merge of #119420 - cjgillot:issue-119295, r=compiler-errors
compiler-errors Jan 6, 2024
b3f3074
Rollup merge of #119468 - notriddle:notriddle/compression, r=Guillaum…
compiler-errors Jan 6, 2024
a95a363
Rollup merge of #119628 - RalfJung:duplicate-test, r=compiler-errors
compiler-errors Jan 6, 2024
61c776a
Rollup merge of #119638 - lukas-code:suggest-constructor-cycle-error,…
compiler-errors Jan 6, 2024
a98993c
Rollup merge of #119640 - petrochenkov:rtstartup, r=Mark-Simulacrum
compiler-errors Jan 6, 2024
71610e2
Rollup merge of #119642 - petrochenkov:winstdtest, r=ChrisDenton
compiler-errors Jan 6, 2024
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: 7 additions & 0 deletions compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local
Node::Item(it) => locator.visit_item(it),
Node::ImplItem(it) => locator.visit_impl_item(it),
Node::TraitItem(it) => locator.visit_trait_item(it),
Node::ForeignItem(it) => locator.visit_foreign_item(it),
other => bug!("{:?} is not a valid scope for an opaque type item", other),
}
}
Expand Down Expand Up @@ -240,6 +241,12 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
self.check(it.owner_id.def_id);
intravisit::walk_trait_item(self, it);
}
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
trace!(?it.owner_id);
assert_ne!(it.owner_id.def_id, self.def_id);
// No need to call `check`, as we do not run borrowck on foreign items.
intravisit::walk_foreign_item(self, it);
}
}

pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,16 @@ impl<'tcx> InstanceDef<'tcx> {
fn fmt_instance(
f: &mut fmt::Formatter<'_>,
instance: &Instance<'_>,
type_length: rustc_session::Limit,
type_length: Option<rustc_session::Limit>,
) -> fmt::Result {
ty::tls::with(|tcx| {
let args = tcx.lift(instance.args).expect("could not lift for printing");

let mut cx = FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length);
let mut cx = if let Some(type_length) = type_length {
FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length)
} else {
FmtPrinter::new(tcx, Namespace::ValueNS)
};
cx.print_def_path(instance.def_id(), args)?;
let s = cx.into_buffer();
f.write_str(&s)
Expand All @@ -324,13 +328,13 @@ pub struct ShortInstance<'a, 'tcx>(pub &'a Instance<'tcx>, pub usize);

impl<'a, 'tcx> fmt::Display for ShortInstance<'a, 'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_instance(f, self.0, rustc_session::Limit(self.1))
fmt_instance(f, self.0, Some(rustc_session::Limit(self.1)))
}
}

impl<'tcx> fmt::Display for Instance<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
ty::tls::with(|tcx| fmt_instance(f, self, tcx.type_length_limit()))
fmt_instance(f, self, None)
}
}

Expand Down
140 changes: 11 additions & 129 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::cell::OnceCell;

use rustc_data_structures::graph::WithNumNodes;
use rustc_index::IndexVec;
use rustc_middle::mir;
use rustc_span::{BytePos, ExpnKind, MacroKind, Span, Symbol, DUMMY_SP};
use rustc_span::{BytePos, Span, DUMMY_SP};

use super::graph::{BasicCoverageBlock, CoverageGraph, START_BCB};
use super::graph::{BasicCoverageBlock, CoverageGraph};
use crate::coverage::ExtractedHirInfo;

mod from_mir;
Expand Down Expand Up @@ -70,35 +68,17 @@ impl CoverageSpans {
/// `dominates()` the `BasicBlock`s in this `CoverageSpan`.
#[derive(Debug, Clone)]
struct CoverageSpan {
pub span: Span,
pub expn_span: Span,
pub current_macro_or_none: OnceCell<Option<Symbol>>,
pub bcb: BasicCoverageBlock,
span: Span,
bcb: BasicCoverageBlock,
/// List of all the original spans from MIR that have been merged into this
/// span. Mainly used to precisely skip over gaps when truncating a span.
pub merged_spans: Vec<Span>,
pub is_closure: bool,
merged_spans: Vec<Span>,
is_closure: bool,
}

impl CoverageSpan {
pub fn for_fn_sig(fn_sig_span: Span) -> Self {
Self::new(fn_sig_span, fn_sig_span, START_BCB, false)
}

pub(super) fn new(
span: Span,
expn_span: Span,
bcb: BasicCoverageBlock,
is_closure: bool,
) -> Self {
Self {
span,
expn_span,
current_macro_or_none: Default::default(),
bcb,
merged_spans: vec![span],
is_closure,
}
fn new(span: Span, bcb: BasicCoverageBlock, is_closure: bool) -> Self {
Self { span, bcb, merged_spans: vec![span], is_closure }
}

pub fn merge_from(&mut self, other: &Self) {
Expand All @@ -123,37 +103,6 @@ impl CoverageSpan {
pub fn is_in_same_bcb(&self, other: &Self) -> bool {
self.bcb == other.bcb
}

/// If the span is part of a macro, returns the macro name symbol.
pub fn current_macro(&self) -> Option<Symbol> {
self.current_macro_or_none
.get_or_init(|| {
if let ExpnKind::Macro(MacroKind::Bang, current_macro) =
self.expn_span.ctxt().outer_expn_data().kind
{
return Some(current_macro);
}
None
})
.map(|symbol| symbol)
}

/// If the span is part of a macro, and the macro is visible (expands directly to the given
/// body_span), returns the macro name symbol.
pub fn visible_macro(&self, body_span: Span) -> Option<Symbol> {
let current_macro = self.current_macro()?;
let parent_callsite = self.expn_span.parent_callsite()?;

// In addition to matching the context of the body span, the parent callsite
// must also be the source callsite, i.e. the parent must have no parent.
let is_visible_macro =
parent_callsite.parent_callsite().is_none() && parent_callsite.eq_ctxt(body_span);
is_visible_macro.then_some(current_macro)
}

pub fn is_macro_expansion(&self) -> bool {
self.current_macro().is_some()
}
}

/// Converts the initial set of `CoverageSpan`s (one per MIR `Statement` or `Terminator`) into a
Expand All @@ -164,10 +113,6 @@ impl CoverageSpan {
/// execution
/// * Carve out (leave uncovered) any span that will be counted by another MIR (notably, closures)
struct CoverageSpansGenerator<'a> {
/// A `Span` covering the function body of the MIR (typically from left curly brace to right
/// curly brace).
body_span: Span,

/// The BasicCoverageBlock Control Flow Graph (BCB CFG).
basic_coverage_blocks: &'a CoverageGraph,

Expand Down Expand Up @@ -244,7 +189,6 @@ impl<'a> CoverageSpansGenerator<'a> {
);

let coverage_spans = Self {
body_span: hir_info.body_span,
basic_coverage_blocks,
sorted_spans_iter: sorted_spans.into_iter(),
some_curr: None,
Expand All @@ -266,7 +210,6 @@ impl<'a> CoverageSpansGenerator<'a> {
// span-processing steps don't make sense yet.
if self.some_prev.is_none() {
debug!(" initial span");
self.maybe_push_macro_name_span();
continue;
}

Expand All @@ -278,15 +221,13 @@ impl<'a> CoverageSpansGenerator<'a> {
debug!(" same bcb (and neither is a closure), merge with prev={prev:?}");
let prev = self.take_prev();
self.curr_mut().merge_from(&prev);
self.maybe_push_macro_name_span();
// Note that curr.span may now differ from curr_original_span
} else if prev.span.hi() <= curr.span.lo() {
debug!(
" different bcbs and disjoint spans, so keep curr for next iter, and add prev={prev:?}",
);
let prev = self.take_prev();
self.refined_spans.push(prev);
self.maybe_push_macro_name_span();
} else if prev.is_closure {
// drop any equal or overlapping span (`curr`) and keep `prev` to test again in the
// next iter
Expand All @@ -297,35 +238,11 @@ impl<'a> CoverageSpansGenerator<'a> {
} else if curr.is_closure {
self.carve_out_span_for_closure();
} else if self.prev_original_span == curr.span {
// Note that this compares the new (`curr`) span to `prev_original_span`.
// In this branch, the actual span byte range of `prev_original_span` is not
// important. What is important is knowing whether the new `curr` span was
// **originally** the same as the original span of `prev()`. The original spans
// reflect their original sort order, and for equal spans, conveys a partial
// ordering based on CFG dominator priority.
if prev.is_macro_expansion() && curr.is_macro_expansion() {
// Macros that expand to include branching (such as
// `assert_eq!()`, `assert_ne!()`, `info!()`, `debug!()`, or
// `trace!()`) typically generate callee spans with identical
// ranges (typically the full span of the macro) for all
// `BasicBlocks`. This makes it impossible to distinguish
// the condition (`if val1 != val2`) from the optional
// branched statements (such as the call to `panic!()` on
// assert failure). In this case it is better (or less
// worse) to drop the optional branch bcbs and keep the
// non-conditional statements, to count when reached.
debug!(
" curr and prev are part of a macro expansion, and curr has the same span \
as prev, but is in a different bcb. Drop curr and keep prev for next iter. \
prev={prev:?}",
);
self.take_curr(); // Discards curr.
} else {
self.update_pending_dups();
}
// `prev` and `curr` have the same span, or would have had the
// same span before `prev` was modified by other spans.
self.update_pending_dups();
} else {
self.cutoff_prev_at_overlapping_curr();
self.maybe_push_macro_name_span();
}
}

Expand Down Expand Up @@ -360,41 +277,6 @@ impl<'a> CoverageSpansGenerator<'a> {
self.refined_spans
}

/// If `curr` is part of a new macro expansion, carve out and push a separate
/// span that ends just after the macro name and its subsequent `!`.
fn maybe_push_macro_name_span(&mut self) {
let curr = self.curr();

let Some(visible_macro) = curr.visible_macro(self.body_span) else { return };
if let Some(prev) = &self.some_prev
&& prev.expn_span.eq_ctxt(curr.expn_span)
{
return;
}

// The split point is relative to `curr_original_span`,
// because `curr.span` may have been merged with preceding spans.
let split_point_after_macro_bang = self.curr_original_span.lo()
+ BytePos(visible_macro.as_str().len() as u32)
+ BytePos(1); // add 1 for the `!`
debug_assert!(split_point_after_macro_bang <= curr.span.hi());
if split_point_after_macro_bang > curr.span.hi() {
// Something is wrong with the macro name span;
// return now to avoid emitting malformed mappings (e.g. #117788).
return;
}

let mut macro_name_cov = curr.clone();
macro_name_cov.span = macro_name_cov.span.with_hi(split_point_after_macro_bang);
self.curr_mut().span = curr.span.with_lo(split_point_after_macro_bang);

debug!(
" and curr starts a new macro expansion, so add a new span just for \
the macro `{visible_macro}!`, new span={macro_name_cov:?}",
);
self.refined_spans.push(macro_name_cov);
}

#[track_caller]
fn curr(&self) -> &CoverageSpan {
self.some_curr.as_ref().unwrap_or_else(|| bug!("some_curr is None (curr)"))
Expand Down
Loading
Loading