about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-09-14 00:26:43 +0000
committerbors <bors@rust-lang.org>2020-09-14 00:26:43 +0000
commit1eb00abf35b9bb59825edf81d05c2fa2f17cefca (patch)
tree9f2b9778cfea3af242180d0000b2201ceadb4b27 /compiler/rustc_metadata/src
parentf9a322a6fdd1e12fbe30441feaa4402e23efe303 (diff)
parenta447c21afaa00cc047e70fe4205c33c2dc4aa2cb (diff)
downloadrust-1eb00abf35b9bb59825edf81d05c2fa2f17cefca.tar.gz
rust-1eb00abf35b9bb59825edf81d05c2fa2f17cefca.zip
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.
Diffstat (limited to 'compiler/rustc_metadata/src')
-rw-r--r--compiler/rustc_metadata/src/rmeta/encoder.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs
index 1786969a889..1e313b7edfc 100644
--- a/compiler/rustc_metadata/src/rmeta/encoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/encoder.rs
@@ -40,6 +40,7 @@ use tracing::{debug, trace};
 pub(super) struct EncodeContext<'a, 'tcx> {
     opaque: opaque::Encoder,
     tcx: TyCtxt<'tcx>,
+    feat: &'tcx rustc_feature::Features,
 
     tables: TableBuilders<'tcx>,
 
@@ -1132,15 +1133,25 @@ impl EncodeContext<'a, 'tcx> {
 
     fn encode_stability(&mut self, def_id: DefId) {
         debug!("EncodeContext::encode_stability({:?})", def_id);
-        if let Some(stab) = self.tcx.lookup_stability(def_id) {
-            record!(self.tables.stability[def_id] <- stab)
+
+        // The query lookup can take a measurable amount of time in crates with many items. Check if
+        // the stability attributes are even enabled before using their queries.
+        if self.feat.staged_api || self.tcx.sess.opts.debugging_opts.force_unstable_if_unmarked {
+            if let Some(stab) = self.tcx.lookup_stability(def_id) {
+                record!(self.tables.stability[def_id] <- stab)
+            }
         }
     }
 
     fn encode_const_stability(&mut self, def_id: DefId) {
         debug!("EncodeContext::encode_const_stability({:?})", def_id);
-        if let Some(stab) = self.tcx.lookup_const_stability(def_id) {
-            record!(self.tables.const_stability[def_id] <- stab)
+
+        // The query lookup can take a measurable amount of time in crates with many items. Check if
+        // the stability attributes are even enabled before using their queries.
+        if self.feat.staged_api || self.tcx.sess.opts.debugging_opts.force_unstable_if_unmarked {
+            if let Some(stab) = self.tcx.lookup_const_stability(def_id) {
+                record!(self.tables.const_stability[def_id] <- stab)
+            }
         }
     }
 
@@ -1979,6 +1990,7 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
     let mut ecx = EncodeContext {
         opaque: encoder,
         tcx,
+        feat: tcx.features(),
         tables: Default::default(),
         lazy_state: LazyState::NoNode,
         type_shorthands: Default::default(),