Use LocalDefIdSet/Map instead of FxHashSet/Map for live_symbols_and_ignored_derived_traits query.
This commit is contained in:
parent
f0eadbafd4
commit
b0202d9c2c
@ -899,8 +899,8 @@
|
|||||||
/// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
|
/// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
|
||||||
/// their respective impl (i.e., part of the derive macro)
|
/// their respective impl (i.e., part of the derive macro)
|
||||||
query live_symbols_and_ignored_derived_traits(_: ()) -> &'tcx (
|
query live_symbols_and_ignored_derived_traits(_: ()) -> &'tcx (
|
||||||
FxHashSet<LocalDefId>,
|
LocalDefIdSet,
|
||||||
FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
|
LocalDefIdMap<Vec<(DefId, DefId)>>
|
||||||
) {
|
) {
|
||||||
arena_cache
|
arena_cache
|
||||||
desc { "finding live symbols in crate" }
|
desc { "finding live symbols in crate" }
|
||||||
|
@ -50,7 +50,9 @@
|
|||||||
use rustc_errors::ErrorGuaranteed;
|
use rustc_errors::ErrorGuaranteed;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, DocLinkResMap};
|
use rustc_hir::def::{DefKind, DocLinkResMap};
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LocalDefIdSet};
|
use rustc_hir::def_id::{
|
||||||
|
CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LocalDefIdMap, LocalDefIdSet,
|
||||||
|
};
|
||||||
use rustc_hir::hir_id::OwnerId;
|
use rustc_hir::hir_id::OwnerId;
|
||||||
use rustc_hir::lang_items::{LangItem, LanguageItems};
|
use rustc_hir::lang_items::{LangItem, LanguageItems};
|
||||||
use rustc_hir::{Crate, ItemLocalId, TraitCandidate};
|
use rustc_hir::{Crate, ItemLocalId, TraitCandidate};
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
// closely. The idea is that all reachable symbols are live, codes called
|
// closely. The idea is that all reachable symbols are live, codes called
|
||||||
// from live codes are live, and everything else is dead.
|
// from live codes are live, and everything else is dead.
|
||||||
|
|
||||||
|
use hir::def_id::{LocalDefIdMap, LocalDefIdSet};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
|
||||||
use rustc_errors::MultiSpan;
|
use rustc_errors::MultiSpan;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||||
@ -45,17 +45,17 @@ struct MarkSymbolVisitor<'tcx> {
|
|||||||
worklist: Vec<LocalDefId>,
|
worklist: Vec<LocalDefId>,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
maybe_typeck_results: Option<&'tcx ty::TypeckResults<'tcx>>,
|
maybe_typeck_results: Option<&'tcx ty::TypeckResults<'tcx>>,
|
||||||
live_symbols: FxHashSet<LocalDefId>,
|
live_symbols: LocalDefIdSet,
|
||||||
repr_has_repr_c: bool,
|
repr_has_repr_c: bool,
|
||||||
repr_has_repr_simd: bool,
|
repr_has_repr_simd: bool,
|
||||||
in_pat: bool,
|
in_pat: bool,
|
||||||
ignore_variant_stack: Vec<DefId>,
|
ignore_variant_stack: Vec<DefId>,
|
||||||
// maps from tuple struct constructors to tuple struct items
|
// maps from tuple struct constructors to tuple struct items
|
||||||
struct_constructors: FxHashMap<LocalDefId, LocalDefId>,
|
struct_constructors: LocalDefIdMap<LocalDefId>,
|
||||||
// maps from ADTs to ignored derived traits (e.g. Debug and Clone)
|
// maps from ADTs to ignored derived traits (e.g. Debug and Clone)
|
||||||
// and the span of their respective impl (i.e., part of the derive
|
// and the span of their respective impl (i.e., part of the derive
|
||||||
// macro)
|
// macro)
|
||||||
ignored_derived_traits: FxHashMap<LocalDefId, Vec<(DefId, DefId)>>,
|
ignored_derived_traits: LocalDefIdMap<Vec<(DefId, DefId)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> MarkSymbolVisitor<'tcx> {
|
impl<'tcx> MarkSymbolVisitor<'tcx> {
|
||||||
@ -237,7 +237,7 @@ fn handle_tuple_field_pattern_match(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mark_live_symbols(&mut self) {
|
fn mark_live_symbols(&mut self) {
|
||||||
let mut scanned = FxHashSet::default();
|
let mut scanned = LocalDefIdSet::default();
|
||||||
while let Some(id) = self.worklist.pop() {
|
while let Some(id) = self.worklist.pop() {
|
||||||
if !scanned.insert(id) {
|
if !scanned.insert(id) {
|
||||||
continue;
|
continue;
|
||||||
@ -371,7 +371,7 @@ fn visit_variant_data(&mut self, def: &'tcx hir::VariantData<'tcx>) {
|
|||||||
}
|
}
|
||||||
if tcx.visibility(def_id).is_public() { Some(def_id) } else { None }
|
if tcx.visibility(def_id).is_public() { Some(def_id) } else { None }
|
||||||
});
|
});
|
||||||
self.live_symbols.extend(live_fields);
|
Extend::extend(&mut self.live_symbols, live_fields);
|
||||||
|
|
||||||
intravisit::walk_struct_def(self, def);
|
intravisit::walk_struct_def(self, def);
|
||||||
}
|
}
|
||||||
@ -506,7 +506,7 @@ fn has_used_like_attr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
|||||||
fn check_item<'tcx>(
|
fn check_item<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
worklist: &mut Vec<LocalDefId>,
|
worklist: &mut Vec<LocalDefId>,
|
||||||
struct_constructors: &mut FxHashMap<LocalDefId, LocalDefId>,
|
struct_constructors: &mut LocalDefIdMap<LocalDefId>,
|
||||||
id: hir::ItemId,
|
id: hir::ItemId,
|
||||||
) {
|
) {
|
||||||
let allow_dead_code = has_allow_dead_code_or_lang_attr(tcx, id.owner_id.def_id);
|
let allow_dead_code = has_allow_dead_code_or_lang_attr(tcx, id.owner_id.def_id);
|
||||||
@ -583,9 +583,7 @@ fn check_foreign_item(tcx: TyCtxt<'_>, worklist: &mut Vec<LocalDefId>, id: hir::
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_and_seed_worklist(
|
fn create_and_seed_worklist(tcx: TyCtxt<'_>) -> (Vec<LocalDefId>, LocalDefIdMap<LocalDefId>) {
|
||||||
tcx: TyCtxt<'_>,
|
|
||||||
) -> (Vec<LocalDefId>, FxHashMap<LocalDefId, LocalDefId>) {
|
|
||||||
let effective_visibilities = &tcx.effective_visibilities(());
|
let effective_visibilities = &tcx.effective_visibilities(());
|
||||||
// see `MarkSymbolVisitor::struct_constructors`
|
// see `MarkSymbolVisitor::struct_constructors`
|
||||||
let mut struct_constructors = Default::default();
|
let mut struct_constructors = Default::default();
|
||||||
@ -617,7 +615,7 @@ fn create_and_seed_worklist(
|
|||||||
fn live_symbols_and_ignored_derived_traits(
|
fn live_symbols_and_ignored_derived_traits(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
(): (),
|
(): (),
|
||||||
) -> (FxHashSet<LocalDefId>, FxHashMap<LocalDefId, Vec<(DefId, DefId)>>) {
|
) -> (LocalDefIdSet, LocalDefIdMap<Vec<(DefId, DefId)>>) {
|
||||||
let (worklist, struct_constructors) = create_and_seed_worklist(tcx);
|
let (worklist, struct_constructors) = create_and_seed_worklist(tcx);
|
||||||
let mut symbol_visitor = MarkSymbolVisitor {
|
let mut symbol_visitor = MarkSymbolVisitor {
|
||||||
worklist,
|
worklist,
|
||||||
@ -629,7 +627,7 @@ fn live_symbols_and_ignored_derived_traits(
|
|||||||
in_pat: false,
|
in_pat: false,
|
||||||
ignore_variant_stack: vec![],
|
ignore_variant_stack: vec![],
|
||||||
struct_constructors,
|
struct_constructors,
|
||||||
ignored_derived_traits: FxHashMap::default(),
|
ignored_derived_traits: Default::default(),
|
||||||
};
|
};
|
||||||
symbol_visitor.mark_live_symbols();
|
symbol_visitor.mark_live_symbols();
|
||||||
(symbol_visitor.live_symbols, symbol_visitor.ignored_derived_traits)
|
(symbol_visitor.live_symbols, symbol_visitor.ignored_derived_traits)
|
||||||
@ -643,8 +641,8 @@ struct DeadVariant {
|
|||||||
|
|
||||||
struct DeadVisitor<'tcx> {
|
struct DeadVisitor<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
live_symbols: &'tcx FxHashSet<LocalDefId>,
|
live_symbols: &'tcx LocalDefIdSet,
|
||||||
ignored_derived_traits: &'tcx FxHashMap<LocalDefId, Vec<(DefId, DefId)>>,
|
ignored_derived_traits: &'tcx LocalDefIdMap<Vec<(DefId, DefId)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ShouldWarnAboutField {
|
enum ShouldWarnAboutField {
|
||||||
|
Loading…
Reference in New Issue
Block a user