Skip to content

Commit

Permalink
Auto merge of rust-lang#79867 - tmandry:rollup-7mubs3b, r=tmandry
Browse files Browse the repository at this point in the history
Rollup of 12 pull requests

Successful merges:

 - rust-lang#79732 (minor stylistic clippy cleanups)
 - rust-lang#79750 (Fix trimming of lint docs)
 - rust-lang#79777 (Remove `first_merge` from liveness debug logs)
 - rust-lang#79795 (Privatize some of libcore unicode_internals)
 - rust-lang#79803 (Update xsv to prevent random CI failures)
 - rust-lang#79810 (Account for gaps in def path table during decoding)
 - rust-lang#79818 (Fixes to Rust coverage)
 - rust-lang#79824 (Strip prefix instead of replacing it with empty string)
 - rust-lang#79826 (Simplify visit_{foreign,trait}_item)
 - rust-lang#79844 (Move RWUTable to a separate module)
 - rust-lang#79861 (Update LLVM submodule)
 - rust-lang#79862 (Remove tab-lock and replace it with ctrl+up/down arrows to switch between search result tabs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 9, 2020
2 parents f0f6877 + f74f3b2 commit 1cc4107
Show file tree
Hide file tree
Showing 26 changed files with 374 additions and 288 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ fn save_function_record(
/// (functions referenced by other "used" or public items). Any other functions considered unused,
/// or "Unreachable" were still parsed and processed through the MIR stage.
///
/// We can find the unreachable functions by the set different of all MIR `DefId`s (`tcx` query
/// We can find the unreachable functions by the set difference of all MIR `DefId`s (`tcx` query
/// `mir_keys`) minus the codegenned `DefId`s (`tcx` query `collect_and_partition_mono_items`).
///
/// *HOWEVER* the codegenned `DefId`s are partitioned across multiple `CodegenUnit`s (CGUs), and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {

(Some(ret_span), _) => {
let sup_future = self.future_return_type(scope_def_id_sup);
let (return_type, action) = if let Some(_) = sup_future {
let (return_type, action) = if sup_future.is_some() {
("returned future", "held across an await point")
} else {
("return type", "returned")
Expand All @@ -140,7 +140,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
}
(_, Some(ret_span)) => {
let sub_future = self.future_return_type(scope_def_id_sub);
let (return_type, action) = if let Some(_) = sub_future {
let (return_type, action) = if sub_future.is_some() {
("returned future", "held across an await point")
} else {
("return type", "returned")
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_lint/src/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl NonCamelCaseTypes {
let cc = to_camel_case(name);
// We cannot provide meaningful suggestions
// if the characters are in the category of "Lowercase Letter".
if name.to_string() != cc {
if *name != cc {
err.span_suggestion(
ident.span,
"convert the identifier to upper camel case",
Expand Down Expand Up @@ -271,7 +271,7 @@ impl NonSnakeCase {
let mut err = lint.build(&msg);
// We cannot provide meaningful suggestions
// if the characters are in the category of "Uppercase Letter".
if name.to_string() != sc {
if *name != sc {
// We have a valid span in almost all cases, but we don't have one when linting a crate
// name provided via the command line.
if !ident.span.is_dummy() {
Expand Down Expand Up @@ -455,7 +455,7 @@ impl NonUpperCaseGlobals {
lint.build(&format!("{} `{}` should have an upper case name", sort, name));
// We cannot provide meaningful suggestions
// if the characters are in the category of "Lowercase Letter".
if name.to_string() != uc {
if *name != uc {
err.span_suggestion(
ident.span,
"convert the identifier to upper case",
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
return Some(DefId { krate, index: def_index_guess });
}

let is_proc_macro = self.is_proc_macro_crate();

// Slow path: We need to find out the new `DefIndex` of the provided
// `DefPathHash`, if its still exists. This requires decoding every `DefPathHash`
// stored in this crate.
Expand All @@ -1561,9 +1563,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
let mut map = FxHashMap::with_capacity_and_hasher(end_id as usize, Default::default());
for i in 0..end_id {
let def_index = DefIndex::from_u32(i);
let hash =
self.root.tables.def_path_hashes.get(self, def_index).unwrap().decode(self);
map.insert(hash, def_index);
// There may be gaps in the encoded table if we're decoding a proc-macro crate
if let Some(hash) = self.root.tables.def_path_hashes.get(self, def_index) {
map.insert(hash.decode(self), def_index);
} else if !is_proc_macro {
panic!("Missing def_path_hashes entry for {:?}", def_index);
}
}
map
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
type_name, needle_fr
);
if type_name.find(&format!("'{}", counter)).is_some() {
if type_name.contains(&format!("'{}", counter)) {
// Only add a label if we can confirm that a region was labelled.
RegionNameHighlight::CannotMatchHirTy(span, type_name)
} else {
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_mir/src/transform/coverage/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl CoverageGraph {
// Pre-transform MIR `BasicBlock` successors and predecessors into the BasicCoverageBlock
// equivalents. Note that since the BasicCoverageBlock graph has been fully simplified, the
// each predecessor of a BCB leader_bb should be in a unique BCB, and each successor of a
// BCB last_bb should bin in its own unique BCB. Therefore, collecting the BCBs using
// BCB last_bb should be in its own unique BCB. Therefore, collecting the BCBs using
// `bb_to_bcb` should work without requiring a deduplication step.

let successors = IndexVec::from_fn_n(
Expand Down Expand Up @@ -283,7 +283,9 @@ rustc_index::newtype_index! {
}
}

/// A BasicCoverageBlockData (BCB) represents the maximal-length sequence of MIR BasicBlocks without
/// `BasicCoverageBlockData` holds the data indexed by a `BasicCoverageBlock`.
///
/// A `BasicCoverageBlock` (BCB) represents the maximal-length sequence of MIR `BasicBlock`s without
/// conditional branches, and form a new, simplified, coverage-specific Control Flow Graph, without
/// altering the original MIR CFG.
///
Expand Down
22 changes: 18 additions & 4 deletions compiler/rustc_mir/src/transform/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct Instrumentor<'a, 'tcx> {
pass_name: &'a str,
tcx: TyCtxt<'tcx>,
mir_body: &'a mut mir::Body<'tcx>,
source_file: Lrc<SourceFile>,
fn_sig_span: Span,
body_span: Span,
basic_coverage_blocks: CoverageGraph,
Expand All @@ -96,9 +97,13 @@ struct Instrumentor<'a, 'tcx> {

impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
fn new(pass_name: &'a str, tcx: TyCtxt<'tcx>, mir_body: &'a mut mir::Body<'tcx>) -> Self {
let source_map = tcx.sess.source_map();
let (some_fn_sig, hir_body) = fn_sig_and_body(tcx, mir_body.source.def_id());
let body_span = hir_body.value.span;
let fn_sig_span = match some_fn_sig {
let source_file = source_map.lookup_source_file(body_span.lo());
let fn_sig_span = match some_fn_sig.filter(|fn_sig| {
Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.hi()))
}) {
Some(fn_sig) => fn_sig.span.with_hi(body_span.lo()),
None => body_span.shrink_to_lo(),
};
Expand All @@ -108,6 +113,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
pass_name,
tcx,
mir_body,
source_file,
fn_sig_span,
body_span,
basic_coverage_blocks,
Expand Down Expand Up @@ -268,8 +274,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
let tcx = self.tcx;
let source_map = tcx.sess.source_map();
let body_span = self.body_span;
let source_file = source_map.lookup_source_file(body_span.lo());
let file_name = Symbol::intern(&source_file.name.to_string());
let file_name = Symbol::intern(&self.source_file.name.to_string());

let mut bcb_counters = IndexVec::from_elem_n(None, self.basic_coverage_blocks.num_nodes());
for covspan in coverage_spans {
Expand All @@ -285,11 +290,20 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
bug!("Every BasicCoverageBlock should have a Counter or Expression");
};
graphviz_data.add_bcb_coverage_span_with_counter(bcb, &covspan, &counter_kind);

debug!(
"Calling make_code_region(file_name={}, source_file={:?}, span={}, body_span={})",
file_name,
self.source_file,
source_map.span_to_string(span),
source_map.span_to_string(body_span)
);

inject_statement(
self.mir_body,
counter_kind,
self.bcb_last_bb(bcb),
Some(make_code_region(file_name, &source_file, span, body_span)),
Some(make_code_region(file_name, &self.source_file, span, body_span)),
);
}
}
Expand Down
42 changes: 21 additions & 21 deletions compiler/rustc_mir/src/transform/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,27 @@ pub struct CoverageSpans<'a, 'tcx> {
}

impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
/// Generate a minimal set of `CoverageSpan`s, each representing a contiguous code region to be
/// counted.
///
/// The basic steps are:
///
/// 1. Extract an initial set of spans from the `Statement`s and `Terminator`s of each
/// `BasicCoverageBlockData`.
/// 2. Sort the spans by span.lo() (starting position). Spans that start at the same position
/// are sorted with longer spans before shorter spans; and equal spans are sorted
/// (deterministically) based on "dominator" relationship (if any).
/// 3. Traverse the spans in sorted order to identify spans that can be dropped (for instance,
/// if another span or spans are already counting the same code region), or should be merged
/// into a broader combined span (because it represents a contiguous, non-branching, and
/// uninterrupted region of source code).
///
/// Closures are exposed in their enclosing functions as `Assign` `Rvalue`s, and since
/// closures have their own MIR, their `Span` in their enclosing function should be left
/// "uncovered".
///
/// Note the resulting vector of `CoverageSpan`s may not be fully sorted (and does not need
/// to be).
pub(super) fn generate_coverage_spans(
mir_body: &'a mir::Body<'tcx>,
fn_sig_span: Span,
Expand Down Expand Up @@ -247,27 +268,6 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
coverage_spans.to_refined_spans()
}

/// Generate a minimal set of `CoverageSpan`s, each representing a contiguous code region to be
/// counted.
///
/// The basic steps are:
///
/// 1. Extract an initial set of spans from the `Statement`s and `Terminator`s of each
/// `BasicCoverageBlockData`.
/// 2. Sort the spans by span.lo() (starting position). Spans that start at the same position
/// are sorted with longer spans before shorter spans; and equal spans are sorted
/// (deterministically) based on "dominator" relationship (if any).
/// 3. Traverse the spans in sorted order to identify spans that can be dropped (for instance,
/// if another span or spans are already counting the same code region), or should be merged
/// into a broader combined span (because it represents a contiguous, non-branching, and
/// uninterrupted region of source code).
///
/// Closures are exposed in their enclosing functions as `Assign` `Rvalue`s, and since
/// closures have their own MIR, their `Span` in their enclosing function should be left
/// "uncovered".
///
/// Note the resulting vector of `CoverageSpan`s does may not be fully sorted (and does not need
/// to be).
fn mir_to_initial_sorted_coverage_spans(&self) -> Vec<CoverageSpan> {
let mut initial_spans = Vec::<CoverageSpan>::with_capacity(self.mir_body.num_nodes() * 2);
for (bcb, bcb_data) in self.basic_coverage_blocks.iter_enumerated() {
Expand Down
30 changes: 10 additions & 20 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,11 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
}

fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
match trait_item.kind {
hir::TraitItemKind::Const(_, Some(_))
| hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => {
if has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id, &trait_item.attrs)
{
self.worklist.push(trait_item.hir_id);
}
}
_ => {}
use hir::TraitItemKind::{Const, Fn};
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(_, hir::TraitFn::Provided(_)))
&& has_allow_dead_code_or_lang_attr(self.tcx, trait_item.hir_id, &trait_item.attrs)
{
self.worklist.push(trait_item.hir_id);
}
}

Expand All @@ -440,17 +436,11 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
}

fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
match foreign_item.kind {
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Fn(..) => {
if has_allow_dead_code_or_lang_attr(
self.tcx,
foreign_item.hir_id,
&foreign_item.attrs,
) {
self.worklist.push(foreign_item.hir_id);
}
}
_ => {}
use hir::ForeignItemKind::{Fn, Static};
if matches!(foreign_item.kind, Static(..) | Fn(..))
&& has_allow_dead_code_or_lang_attr(self.tcx, foreign_item.hir_id, &foreign_item.attrs)
{
self.worklist.push(foreign_item.hir_id);
}
}
}
Expand Down
Loading

0 comments on commit 1cc4107

Please sign in to comment.