Rollup merge of #143456 - joshtriplett:mbe-unused-rules-bitset, r=lqd
mbe: Change `unused_macro_rules` to a `DenseBitSet` Now that it only contains indexes, and no other information, a bitset provides a more compact and simpler representation. This builds on <https://github.com/rust-lang/rust/pull/143416>. Only the last commit is new.
This commit is contained in:
commit
a1b51aa400
5 changed files with 9 additions and 6 deletions
|
|
@ -4474,6 +4474,7 @@ dependencies = [
|
|||
"rustc_feature",
|
||||
"rustc_fluent_macro",
|
||||
"rustc_hir",
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
"rustc_metadata",
|
||||
"rustc_middle",
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ rustc_expand = { path = "../rustc_expand" }
|
|||
rustc_feature = { path = "../rustc_feature" }
|
||||
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
|
||||
rustc_hir = { path = "../rustc_hir" }
|
||||
rustc_index = { path = "../rustc_index" }
|
||||
rustc_macros = { path = "../rustc_macros" }
|
||||
rustc_metadata = { path = "../rustc_metadata" }
|
||||
rustc_middle = { path = "../rustc_middle" }
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ use rustc_expand::base::ResolverExpand;
|
|||
use rustc_expand::expand::AstFragment;
|
||||
use rustc_hir::def::{self, *};
|
||||
use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
|
||||
use rustc_index::bit_set::DenseBitSet;
|
||||
use rustc_metadata::creader::LoadedMacro;
|
||||
use rustc_middle::metadata::ModChild;
|
||||
use rustc_middle::ty::Feed;
|
||||
|
|
@ -1202,9 +1203,8 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
|||
fn insert_unused_macro(&mut self, ident: Ident, def_id: LocalDefId, node_id: NodeId) {
|
||||
if !ident.as_str().starts_with('_') {
|
||||
self.r.unused_macros.insert(def_id, (node_id, ident));
|
||||
for rule_i in 0..self.r.macro_map[&def_id.to_def_id()].nrules {
|
||||
self.r.unused_macro_rules.entry(node_id).or_default().insert(rule_i);
|
||||
}
|
||||
let nrules = self.r.macro_map[&def_id.to_def_id()].nrules;
|
||||
self.r.unused_macro_rules.insert(node_id, DenseBitSet::new_filled(nrules));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ use rustc_hir::def::{
|
|||
use rustc_hir::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
|
||||
use rustc_hir::definitions::DisambiguatorState;
|
||||
use rustc_hir::{PrimTy, TraitCandidate};
|
||||
use rustc_index::bit_set::DenseBitSet;
|
||||
use rustc_metadata::creader::{CStore, CrateLoader};
|
||||
use rustc_middle::metadata::ModChild;
|
||||
use rustc_middle::middle::privacy::EffectiveVisibilities;
|
||||
|
|
@ -1135,7 +1136,7 @@ pub struct Resolver<'ra, 'tcx> {
|
|||
ast_transform_scopes: FxHashMap<LocalExpnId, Module<'ra>>,
|
||||
unused_macros: FxIndexMap<LocalDefId, (NodeId, Ident)>,
|
||||
/// A map from the macro to all its potentially unused arms.
|
||||
unused_macro_rules: FxIndexMap<NodeId, UnordSet<usize>>,
|
||||
unused_macro_rules: FxIndexMap<NodeId, DenseBitSet<usize>>,
|
||||
proc_macro_stubs: FxHashSet<LocalDefId>,
|
||||
/// Traces collected during macro resolution and validated when it's complete.
|
||||
single_segment_macro_resolutions:
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
|
|||
|
||||
fn record_macro_rule_usage(&mut self, id: NodeId, rule_i: usize) {
|
||||
if let Some(rules) = self.unused_macro_rules.get_mut(&id) {
|
||||
rules.remove(&rule_i);
|
||||
rules.remove(rule_i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -359,7 +359,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
|
|||
let SyntaxExtensionKind::LegacyBang(ref ext) = m.ext.kind else {
|
||||
continue;
|
||||
};
|
||||
for &arm_i in unused_arms.to_sorted_stable_ord() {
|
||||
for arm_i in unused_arms.iter() {
|
||||
if let Some((ident, rule_span)) = ext.get_unused_rule(arm_i) {
|
||||
self.lint_buffer.buffer_lint(
|
||||
UNUSED_MACRO_RULES,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue