Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3797379

Browse files
committed
Auto merge of #143247 - cjgillot:metadata-no-red, r=<try>
Avoid depending on forever-red DepNode when encoding metadata. Split from #114669 for perf r? `@petrochenkov`
2 parents 86e05cd + f12e837 commit 3797379

File tree

7 files changed

+37
-37
lines changed

7 files changed

+37
-37
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_metadata/src/rmeta/encoder.rs‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16151615
let table = tcx.associated_types_for_impl_traits_in_associated_fn(def_id);
16161616
record_defaulted_array!(self.tables.associated_types_for_impl_traits_in_associated_fn[def_id] <- table);
16171617
}
1618+
if let DefKind::Mod = tcx.def_kind(def_id) {
1619+
record!(self.tables.doc_link_resolutions[def_id] <- tcx.doc_link_resolutions(def_id));
1620+
record_array!(self.tables.doc_link_traits_in_scope[def_id] <- tcx.doc_link_traits_in_scope(def_id));
1621+
}
16181622
}
16191623

16201624
for (def_id, impls) in &tcx.crate_inherent_impls(()).0.inherent_impls {
@@ -1623,14 +1627,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16231627
def_id.index
16241628
}));
16251629
}
1626-
1627-
for (def_id, res_map) in &tcx.resolutions(()).doc_link_resolutions {
1628-
record!(self.tables.doc_link_resolutions[def_id.to_def_id()] <- res_map);
1629-
}
1630-
1631-
for (def_id, traits) in &tcx.resolutions(()).doc_link_traits_in_scope {
1632-
record_array!(self.tables.doc_link_traits_in_scope[def_id.to_def_id()] <- traits);
1633-
}
16341630
}
16351631

16361632
#[instrument(level = "trace", skip(self))]

‎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
@@ -2059,9 +2059,8 @@ impl<'tcx> TyCtxt<'tcx> {
20592059
}
20602060

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

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

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

20882086
// Freeze definitions once we start iterating on them, to prevent adding new ones
20892087
// 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/late.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,12 +1559,17 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
15591559
}
15601560

15611561
fn with_mod_rib<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T {
1562-
let module = self.r.expect_module(self.r.local_def_id(id).to_def_id());
1562+
let def_id = self.r.local_def_id(id);
1563+
let module = self.r.expect_module(def_id.to_def_id());
15631564
// Move down in the graph.
15641565
let orig_module = replace(&mut self.parent_scope.module, module);
15651566
self.with_rib(ValueNS, RibKind::Module(module), |this| {
15661567
this.with_rib(TypeNS, RibKind::Module(module), |this| {
15671568
let ret = f(this);
1569+
// Make sure there is an entry in these maps, so metadata encoder does not need to
1570+
// understand in which case they are populated.
1571+
this.r.doc_link_resolutions.entry(def_id).or_default();
1572+
this.r.doc_link_traits_in_scope.entry(def_id).or_default();
15681573
this.parent_scope.module = orig_module;
15691574
ret
15701575
})
@@ -5247,6 +5252,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
52475252
BuiltinLintDiag::UnusedLabel,
52485253
);
52495254
}
5255+
// Make sure there is an entry in these maps, so metadata encoder does not need to
5256+
// understand in which case they are populated.
5257+
self.doc_link_resolutions.entry(CRATE_DEF_ID).or_default();
5258+
self.doc_link_traits_in_scope.entry(CRATE_DEF_ID).or_default();
52505259
}
52515260
}
52525261

‎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)

AltStyle によって変換されたページ (->オリジナル) /