Skip to content

Commit f0fce21

Browse files
committed
rest of huge changes from before
1 parent a8fc79b commit f0fce21

File tree

34 files changed

+167
-148
lines changed

34 files changed

+167
-148
lines changed

compiler/rustc_borrowck/src/region_infer/dump_mir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
7171
}
7272
}
7373

74-
let mut constraints: Vec<_> = self.constraints.outlives().iter().collect();
75-
constraints.sort();
74+
let constraints: Vec<_> = self.constraints.outlives().iter().collect();
75+
// constraints.sort();
7676
for constraint in &constraints {
7777
let OutlivesConstraint { sup, sub, locations, category, variance_info: _ } = constraint;
7878
let (name, arg) = match locations {

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
611611
#[instrument(skip(self, _body), level = "debug")]
612612
fn propagate_constraints(&mut self, _body: &Body<'tcx>) {
613613
debug!("constraints={:#?}", {
614-
let mut constraints: Vec<_> = self.constraints.outlives().iter().collect();
615-
constraints.sort();
614+
let constraints: Vec<_> = self.constraints.outlives().iter().collect();
615+
// constraints.sort();
616616
constraints
617617
.into_iter()
618618
.map(|c| (c, self.constraint_sccs.scc(c.sup), self.constraint_sccs.scc(c.sub)))

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,64 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
319319
continue;
320320
}
321321

322-
debug!("generating unused fn: {:?}", non_codegenned_def_id);
323-
cx.define_unused_fn(non_codegenned_def_id);
322+
if unused_def_ids_by_file.is_empty() {
323+
// There are no unused functions with file names to add (in any CGU)
324+
return;
325+
}
326+
327+
// Each `CodegenUnit` (CGU) has its own function_coverage_map, and generates a specific binary
328+
// with its own coverage map.
329+
//
330+
// Each covered function `Instance` can be included in only one coverage map, produced from a
331+
// specific function_coverage_map, from a specific CGU.
332+
//
333+
// Since unused functions did not generate code, they are not associated with any CGU yet.
334+
//
335+
// To avoid injecting the unused functions in multiple coverage maps (for multiple CGUs)
336+
// determine which function_coverage_map has the responsibility for publishing unreachable
337+
// coverage, based on file name: For each unused function, find the CGU that generates the
338+
// first function (based on sorted `DefId`) from the same file.
339+
//
340+
// Add a new `FunctionCoverage` to the `function_coverage_map`, with unreachable code regions
341+
// for each region in it's MIR.
342+
343+
let mut first_covered_def_id_by_file: FxHashMap<Symbol, DefId> = FxHashMap::default();
344+
for &def_id in codegenned_def_ids.iter() {
345+
if let Some(covered_file_name) = tcx.covered_file_name(def_id) {
346+
// Only add files known to have unused functions
347+
if unused_def_ids_by_file.contains_key(covered_file_name) {
348+
first_covered_def_id_by_file.entry(*covered_file_name).or_insert(def_id);
349+
}
350+
}
351+
}
352+
353+
// Get the set of def_ids with coverage regions, known by *this* CoverageContext.
354+
let cgu_covered_def_ids: DefIdSet = match cx.coverage_context() {
355+
Some(ctx) => ctx
356+
.function_coverage_map
357+
.borrow()
358+
.keys()
359+
.map(|&instance| instance.def.def_id())
360+
.collect(),
361+
None => return,
362+
};
363+
364+
let cgu_covered_files: FxHashSet<Symbol> =
365+
first_covered_def_id_by_file
366+
.iter()
367+
.filter_map(|(&file_name, def_id)| {
368+
if cgu_covered_def_ids.contains(def_id) { Some(file_name) } else { None }
369+
})
370+
.collect();
371+
372+
// For each file for which this CGU is responsible for adding unused function coverage,
373+
// get the `def_id`s for each unused function (if any), define a synthetic function with a
374+
// single LLVM coverage counter, and add the function's coverage `CodeRegion`s. to the
375+
// function_coverage_map.
376+
for covered_file_name in cgu_covered_files {
377+
for def_id in unused_def_ids_by_file.remove(&covered_file_name).into_iter().flatten() {
378+
cx.define_unused_fn(def_id);
379+
}
380+
}
324381
}
325382
}

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
446446
}
447447
}
448448
let all_len = self.place_cache.len();
449-
self.place_cache.sort_unstable();
449+
self.place_cache.sort_by_key(|b| b.local);
450450
self.place_cache.dedup();
451451
let has_duplicates = all_len != self.place_cache.len();
452452
if has_duplicates {

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use rustc_span::symbol::Symbol;
3535
use rustc_span::Span;
3636

3737
use std::cell::{Cell, Ref, RefCell};
38-
use std::collections::BTreeMap;
3938
use std::fmt;
4039

4140
use self::combine::CombineFields;
@@ -1500,7 +1499,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15001499
span: Span,
15011500
lbrct: LateBoundRegionConversionTime,
15021501
value: ty::Binder<'tcx, T>,
1503-
) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>)
1502+
) -> (T, FxHashMap<ty::BoundRegion, ty::Region<'tcx>>)
15041503
where
15051504
T: TypeFoldable<'tcx>,
15061505
{

compiler/rustc_infer/src/infer/region_constraints/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_middle::ty::{ReLateBound, ReVar};
2020
use rustc_middle::ty::{Region, RegionVid};
2121
use rustc_span::Span;
2222

23-
use std::collections::BTreeMap;
2423
use std::ops::Range;
2524
use std::{cmp, fmt, mem};
2625

@@ -90,7 +89,7 @@ pub type VarInfos = IndexVec<RegionVid, RegionVariableInfo>;
9089
pub struct RegionConstraintData<'tcx> {
9190
/// Constraints of the form `A <= B`, where either `A` or `B` can
9291
/// be a region variable (or neither, as it happens).
93-
pub constraints: BTreeMap<Constraint<'tcx>, SubregionOrigin<'tcx>>,
92+
pub constraints: FxHashMap<Constraint<'tcx>, SubregionOrigin<'tcx>>,
9493

9594
/// Constraints of the form `R0 member of [R1, ..., Rn]`, meaning that
9695
/// `R0` must be equal to one of the regions `R1..Rn`. These occur
@@ -127,7 +126,7 @@ pub struct RegionConstraintData<'tcx> {
127126
}
128127

129128
/// Represents a constraint that influences the inference process.
130-
#[derive(Clone, Copy, PartialEq, Eq, Debug, PartialOrd, Ord)]
129+
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
131130
pub enum Constraint<'tcx> {
132131
/// A region variable is a subregion of another.
133132
VarSubVar(RegionVid, RegionVid),

compiler/rustc_middle/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ rustc_index = { path = "../rustc_index" }
2929
rustc_serialize = { path = "../rustc_serialize" }
3030
rustc_ast = { path = "../rustc_ast" }
3131
rustc_span = { path = "../rustc_span" }
32-
chalk-ir = "0.75.0"
32+
chalk-ir = "0.76.0"
3333
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
3434
rustc_session = { path = "../rustc_session" }
3535
rustc_type_ir = { path = "../rustc_type_ir" }

compiler/rustc_middle/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#![feature(get_mut_unchecked)]
3737
#![feature(if_let_guard)]
3838
#![feature(map_first_last)]
39+
#![feature(negative_impls)]
3940
#![feature(never_type)]
4041
#![feature(extern_types)]
4142
#![feature(new_uninit)]

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,7 @@ rustc_index::newtype_index! {
18411841
}
18421842
}
18431843

1844-
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1844+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
18451845
pub struct PlaceRef<'tcx> {
18461846
pub local: Local,
18471847
pub projection: &'tcx [PlaceElem<'tcx>],

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ rustc_queries! {
10891089
}
10901090

10911091
/// Return all `impl` blocks in the current crate.
1092-
query all_local_trait_impls(_: ()) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
1092+
query all_local_trait_impls(_: ()) -> &'tcx FxHashMap<DefId, Vec<LocalDefId>> {
10931093
desc { "local trait impls" }
10941094
}
10951095

0 commit comments

Comments
 (0)