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

+2-2
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

+2-2
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

+59-2
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

+1-1
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

+1-2
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

+2-3
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

+1-1
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

+1
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

+1-1
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

+1-1
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

compiler/rustc_middle/src/ty/adt.rs

-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc_span::symbol::sym;
1717
use rustc_target::abi::VariantIdx;
1818

1919
use std::cell::RefCell;
20-
use std::cmp::Ordering;
2120
use std::hash::{Hash, Hasher};
2221
use std::ops::Range;
2322
use std::str;
@@ -100,20 +99,6 @@ pub struct AdtDef {
10099
pub repr: ReprOptions,
101100
}
102101

103-
impl PartialOrd for AdtDef {
104-
fn partial_cmp(&self, other: &AdtDef) -> Option<Ordering> {
105-
Some(self.cmp(&other))
106-
}
107-
}
108-
109-
/// There should be only one AdtDef for each `did`, therefore
110-
/// it is fine to implement `Ord` only based on `did`.
111-
impl Ord for AdtDef {
112-
fn cmp(&self, other: &AdtDef) -> Ordering {
113-
self.did.cmp(&other.did)
114-
}
115-
}
116-
117102
/// There should be only one AdtDef for each `did`, therefore
118103
/// it is fine to implement `PartialEq` only based on `did`.
119104
impl PartialEq for AdtDef {

compiler/rustc_middle/src/ty/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use kind::*;
1818
pub use valtree::*;
1919

2020
/// Typed constant value.
21-
#[derive(Copy, Clone, Debug, Hash, TyEncodable, TyDecodable, Eq, PartialEq, Ord, PartialOrd)]
21+
#[derive(Copy, Clone, Debug, Hash, TyEncodable, TyDecodable, Eq, PartialEq)]
2222
#[derive(HashStable)]
2323
pub struct Const<'tcx> {
2424
pub ty: Ty<'tcx>,

compiler/rustc_middle/src/ty/consts/kind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_target::abi::Size;
1212

1313
use super::ScalarInt;
1414
/// An unevaluated, potentially generic, constant.
15-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
15+
#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable, Lift)]
1616
#[derive(Hash, HashStable)]
1717
pub struct Unevaluated<'tcx, P = Option<Promoted>> {
1818
pub def: ty::WithOptConstParam<DefId>,
@@ -43,7 +43,7 @@ impl<'tcx, P: Default> Unevaluated<'tcx, P> {
4343
}
4444

4545
/// Represents a constant in Rust.
46-
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable)]
46+
#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable)]
4747
#[derive(Hash, HashStable)]
4848
pub enum ConstKind<'tcx> {
4949
/// A const generic parameter.

compiler/rustc_middle/src/ty/fold.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ use crate::ty::{self, flags::FlagComputation, Binder, Ty, TyCtxt, TypeFlags};
3535
use rustc_hir as hir;
3636
use rustc_hir::def_id::DefId;
3737

38-
use rustc_data_structures::fx::FxHashSet;
38+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3939
use rustc_data_structures::sso::SsoHashSet;
40-
use std::collections::BTreeMap;
4140
use std::fmt;
4241
use std::ops::ControlFlow;
4342

@@ -695,12 +694,12 @@ impl<'tcx> TyCtxt<'tcx> {
695694
self,
696695
value: Binder<'tcx, T>,
697696
mut fld_r: F,
698-
) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>)
697+
) -> (T, FxHashMap<ty::BoundRegion, ty::Region<'tcx>>)
699698
where
700699
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
701700
T: TypeFoldable<'tcx>,
702701
{
703-
let mut region_map = BTreeMap::new();
702+
let mut region_map = FxHashMap::default();
704703
let mut real_fld_r =
705704
|br: ty::BoundRegion| *region_map.entry(br).or_insert_with(|| fld_r(br));
706705
let value = value.skip_binder();
@@ -747,14 +746,14 @@ impl<'tcx> TyCtxt<'tcx> {
747746
mut fld_r: F,
748747
fld_t: G,
749748
fld_c: H,
750-
) -> (T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>)
749+
) -> (T, FxHashMap<ty::BoundRegion, ty::Region<'tcx>>)
751750
where
752751
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
753752
G: FnMut(ty::BoundTy) -> Ty<'tcx>,
754753
H: FnMut(ty::BoundVar, Ty<'tcx>) -> &'tcx ty::Const<'tcx>,
755754
T: TypeFoldable<'tcx>,
756755
{
757-
let mut region_map = BTreeMap::new();
756+
let mut region_map = FxHashMap::default();
758757
let real_fld_r = |br: ty::BoundRegion| *region_map.entry(br).or_insert_with(|| fld_r(br));
759758
let value = self.replace_escaping_bound_vars(value.skip_binder(), real_fld_r, fld_t, fld_c);
760759
(value, region_map)

compiler/rustc_middle/src/ty/mod.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ use rustc_span::symbol::{kw, Ident, Symbol};
4242
use rustc_span::{sym, Span};
4343
use rustc_target::abi::Align;
4444

45-
use std::cmp::Ordering;
46-
use std::collections::BTreeMap;
4745
use std::hash::{Hash, Hasher};
4846
use std::ops::ControlFlow;
4947
use std::{fmt, ptr, str};
@@ -134,7 +132,7 @@ pub struct ResolverOutputs {
134132
/// via `extern crate` item and not `--extern` option or compiler built-in.
135133
pub extern_prelude: FxHashMap<Symbol, bool>,
136134
pub main_def: Option<MainDefinition>,
137-
pub trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
135+
pub trait_impls: FxHashMap<DefId, Vec<LocalDefId>>,
138136
/// A list of proc macro LocalDefIds, written out in the order in which
139137
/// they are declared in the static array generated by proc_macro_harness.
140138
pub proc_macros: Vec<LocalDefId>,
@@ -421,18 +419,6 @@ impl<'tcx> TyS<'tcx> {
421419
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
422420
static_assert_size!(TyS<'_>, 40);
423421

424-
impl<'tcx> Ord for TyS<'tcx> {
425-
fn cmp(&self, other: &TyS<'tcx>) -> Ordering {
426-
self.kind().cmp(other.kind())
427-
}
428-
}
429-
430-
impl<'tcx> PartialOrd for TyS<'tcx> {
431-
fn partial_cmp(&self, other: &TyS<'tcx>) -> Option<Ordering> {
432-
Some(self.kind().cmp(other.kind()))
433-
}
434-
}
435-
436422
impl<'tcx> PartialEq for TyS<'tcx> {
437423
#[inline]
438424
fn eq(&self, other: &TyS<'tcx>) -> bool {
@@ -1101,7 +1087,7 @@ pub type PlaceholderRegion = Placeholder<BoundRegionKind>;
11011087
pub type PlaceholderType = Placeholder<BoundVar>;
11021088

11031089
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
1104-
#[derive(TyEncodable, TyDecodable, PartialOrd, Ord)]
1090+
#[derive(TyEncodable, TyDecodable)]
11051091
pub struct BoundConst<'tcx> {
11061092
pub var: BoundVar,
11071093
pub ty: Ty<'tcx>,
@@ -1161,7 +1147,7 @@ pub type PlaceholderConst<'tcx> = Placeholder<BoundConst<'tcx>>;
11611147
/// Meaning that we need to use `type_of(const_param_did)` if `const_param_did` is `Some`
11621148
/// to get the type of `did`.
11631149
#[derive(Copy, Clone, Debug, TypeFoldable, Lift, TyEncodable, TyDecodable)]
1164-
#[derive(PartialEq, Eq, PartialOrd, Ord)]
1150+
#[derive(PartialEq, Eq)]
11651151
#[derive(Hash, HashStable)]
11661152
pub struct WithOptConstParam<T> {
11671153
pub did: T,

0 commit comments

Comments
 (0)