Skip to content

Commit 556d20a

Browse files
committed
Auto merge of #143247 - cjgillot:metadata-no-red, r=petrochenkov
Avoid depending on forever-red DepNode when encoding metadata. Split from #114669 for perf r? `@petrochenkov`
2 parents 1b61d43 + 992fa62 commit 556d20a

File tree

5 files changed

+23
-28
lines changed

5 files changed

+23
-28
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
871871
providers.analysis = analysis;
872872
providers.hir_crate = rustc_ast_lowering::lower_to_hir;
873873
providers.resolver_for_lowering_raw = resolver_for_lowering_raw;
874-
providers.stripped_cfg_items =
875-
|tcx, _| tcx.arena.alloc_from_iter(tcx.resolutions(()).stripped_cfg_items.steal());
874+
providers.stripped_cfg_items = |tcx, _| &tcx.resolutions(()).stripped_cfg_items[..];
876875
providers.resolutions = |tcx, ()| tcx.resolver_for_lowering_raw(()).1;
877876
providers.early_lint_checks = early_lint_checks;
878877
providers.env_var_os = env_var_os;

compiler/rustc_middle/src/query/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ rustc_queries! {
195195
}
196196

197197
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
198-
no_hash
199198
desc { "getting the resolver outputs" }
200199
}
201200

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,9 +2058,8 @@ impl<'tcx> TyCtxt<'tcx> {
20582058
}
20592059

20602060
pub fn iter_local_def_id(self) -> impl Iterator<Item = LocalDefId> {
2061-
// Create a dependency to the red node to be sure we re-execute this when the amount of
2062-
// definitions change.
2063-
self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE);
2061+
// Depend on the `analysis` query to ensure compilation if finished.
2062+
self.ensure_ok().analysis(());
20642063

20652064
let definitions = &self.untracked.definitions;
20662065
gen {
@@ -2080,9 +2079,8 @@ impl<'tcx> TyCtxt<'tcx> {
20802079
}
20812080

20822081
pub fn def_path_table(self) -> &'tcx rustc_hir::definitions::DefPathTable {
2083-
// Create a dependency to the crate to be sure we re-execute this when the amount of
2084-
// definitions change.
2085-
self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE);
2082+
// Depend on the `analysis` query to ensure compilation if finished.
2083+
self.ensure_ok().analysis(());
20862084

20872085
// Freeze definitions once we start iterating on them, to prevent adding new ones
20882086
// while iterating. If some query needs to add definitions, it should be `ensure`d above.

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
3333
use rustc_data_structures::intern::Interned;
3434
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3535
use rustc_data_structures::steal::Steal;
36-
use rustc_data_structures::unord::UnordMap;
36+
use rustc_data_structures::unord::{UnordMap, UnordSet};
3737
use rustc_errors::{Diag, ErrorGuaranteed};
3838
use rustc_hir::LangItem;
3939
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
@@ -176,11 +176,11 @@ pub struct ResolverOutputs {
176176
pub ast_lowering: ResolverAstLowering,
177177
}
178178

179-
#[derive(Debug)]
179+
#[derive(Debug, HashStable)]
180180
pub struct ResolverGlobalCtxt {
181181
pub visibilities_for_hashing: Vec<(LocalDefId, Visibility)>,
182182
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
183-
pub expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
183+
pub expn_that_defined: UnordMap<LocalDefId, ExpnId>,
184184
pub effective_visibilities: EffectiveVisibilities,
185185
pub extern_crate_map: UnordMap<LocalDefId, CrateNum>,
186186
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
@@ -196,8 +196,8 @@ pub struct ResolverGlobalCtxt {
196196
pub confused_type_with_std_module: FxIndexMap<Span, Span>,
197197
pub doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
198198
pub doc_link_traits_in_scope: FxIndexMap<LocalDefId, Vec<DefId>>,
199-
pub all_macro_rules: FxHashSet<Symbol>,
200-
pub stripped_cfg_items: Steal<Vec<StrippedCfgItem>>,
199+
pub all_macro_rules: UnordSet<Symbol>,
200+
pub stripped_cfg_items: Vec<StrippedCfgItem>,
201201
}
202202

203203
/// Resolutions that should only be used for lowering.
@@ -243,7 +243,7 @@ pub struct DelegationFnSig {
243243
pub target_feature: bool,
244244
}
245245

246-
#[derive(Clone, Copy, Debug)]
246+
#[derive(Clone, Copy, Debug, HashStable)]
247247
pub struct MainDefinition {
248248
pub res: Res<ast::NodeId>,
249249
pub is_import: bool,

compiler/rustc_resolve/src/lib.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
4646
use rustc_data_structures::intern::Interned;
4747
use rustc_data_structures::steal::Steal;
4848
use rustc_data_structures::sync::FreezeReadGuard;
49-
use rustc_data_structures::unord::UnordMap;
49+
use rustc_data_structures::unord::{UnordMap, UnordSet};
5050
use rustc_errors::{Applicability, Diag, ErrCode, ErrorGuaranteed};
5151
use rustc_expand::base::{DeriveResolution, SyntaxExtension, SyntaxExtensionKind};
5252
use rustc_feature::BUILTIN_ATTRIBUTES;
@@ -1031,7 +1031,7 @@ pub struct Resolver<'ra, 'tcx> {
10311031
tcx: TyCtxt<'tcx>,
10321032

10331033
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
1034-
expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
1034+
expn_that_defined: UnordMap<LocalDefId, ExpnId>,
10351035

10361036
graph_root: Module<'ra>,
10371037

@@ -1208,7 +1208,7 @@ pub struct Resolver<'ra, 'tcx> {
12081208
effective_visibilities: EffectiveVisibilities,
12091209
doc_link_resolutions: FxIndexMap<LocalDefId, DocLinkResMap>,
12101210
doc_link_traits_in_scope: FxIndexMap<LocalDefId, Vec<DefId>>,
1211-
all_macro_rules: FxHashSet<Symbol>,
1211+
all_macro_rules: UnordSet<Symbol>,
12121212

12131213
/// Invocation ids of all glob delegations.
12141214
glob_delegation_invoc_ids: FxHashSet<LocalExpnId>,
@@ -1653,16 +1653,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16531653
let confused_type_with_std_module = self.confused_type_with_std_module;
16541654
let effective_visibilities = self.effective_visibilities;
16551655

1656-
let stripped_cfg_items = Steal::new(
1657-
self.stripped_cfg_items
1658-
.into_iter()
1659-
.filter_map(|item| {
1660-
let parent_module =
1661-
self.node_id_to_def_id.get(&item.parent_module)?.key().to_def_id();
1662-
Some(StrippedCfgItem { parent_module, ident: item.ident, cfg: item.cfg })
1663-
})
1664-
.collect(),
1665-
);
1656+
let stripped_cfg_items = self
1657+
.stripped_cfg_items
1658+
.into_iter()
1659+
.filter_map(|item| {
1660+
let parent_module =
1661+
self.node_id_to_def_id.get(&item.parent_module)?.key().to_def_id();
1662+
Some(StrippedCfgItem { parent_module, ident: item.ident, cfg: item.cfg })
1663+
})
1664+
.collect();
16661665

16671666
let global_ctxt = ResolverGlobalCtxt {
16681667
expn_that_defined,

0 commit comments

Comments
 (0)