Skip to content

Commit 1eb00ab

Browse files
committed
Auto merge of #76656 - jonas-schievink:fewer-unstable-metadata-queries, r=lcnr
Don't query stability data when `staged_api` is off This data only needs to be encoded when `#![feature(staged_api)]` or `-Zforce-unstable-if-unmarked` is on. Running these queries takes measurable time on large crates with many items, so skip it when the unstable flags have not been enabled.
2 parents f9a322a + a447c21 commit 1eb00ab

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3703,6 +3703,7 @@ dependencies = [
37033703
"rustc_data_structures",
37043704
"rustc_errors",
37053705
"rustc_expand",
3706+
"rustc_feature",
37063707
"rustc_hir",
37073708
"rustc_hir_pretty",
37083709
"rustc_index",

compiler/rustc_metadata/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ rustc_middle = { path = "../rustc_middle" }
1717
rustc_attr = { path = "../rustc_attr" }
1818
rustc_data_structures = { path = "../rustc_data_structures" }
1919
rustc_errors = { path = "../rustc_errors" }
20+
rustc_feature = { path = "../rustc_feature" }
2021
rustc_hir = { path = "../rustc_hir" }
2122
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
2223
rustc_target = { path = "../rustc_target" }

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use tracing::{debug, trace};
4040
pub(super) struct EncodeContext<'a, 'tcx> {
4141
opaque: opaque::Encoder,
4242
tcx: TyCtxt<'tcx>,
43+
feat: &'tcx rustc_feature::Features,
4344

4445
tables: TableBuilders<'tcx>,
4546

@@ -1132,15 +1133,25 @@ impl EncodeContext<'a, 'tcx> {
11321133

11331134
fn encode_stability(&mut self, def_id: DefId) {
11341135
debug!("EncodeContext::encode_stability({:?})", def_id);
1135-
if let Some(stab) = self.tcx.lookup_stability(def_id) {
1136-
record!(self.tables.stability[def_id] <- stab)
1136+
1137+
// The query lookup can take a measurable amount of time in crates with many items. Check if
1138+
// the stability attributes are even enabled before using their queries.
1139+
if self.feat.staged_api || self.tcx.sess.opts.debugging_opts.force_unstable_if_unmarked {
1140+
if let Some(stab) = self.tcx.lookup_stability(def_id) {
1141+
record!(self.tables.stability[def_id] <- stab)
1142+
}
11371143
}
11381144
}
11391145

11401146
fn encode_const_stability(&mut self, def_id: DefId) {
11411147
debug!("EncodeContext::encode_const_stability({:?})", def_id);
1142-
if let Some(stab) = self.tcx.lookup_const_stability(def_id) {
1143-
record!(self.tables.const_stability[def_id] <- stab)
1148+
1149+
// The query lookup can take a measurable amount of time in crates with many items. Check if
1150+
// the stability attributes are even enabled before using their queries.
1151+
if self.feat.staged_api || self.tcx.sess.opts.debugging_opts.force_unstable_if_unmarked {
1152+
if let Some(stab) = self.tcx.lookup_const_stability(def_id) {
1153+
record!(self.tables.const_stability[def_id] <- stab)
1154+
}
11441155
}
11451156
}
11461157

@@ -1979,6 +1990,7 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
19791990
let mut ecx = EncodeContext {
19801991
opaque: encoder,
19811992
tcx,
1993+
feat: tcx.features(),
19821994
tables: Default::default(),
19831995
lazy_state: LazyState::NoNode,
19841996
type_shorthands: Default::default(),

0 commit comments

Comments
 (0)