Skip to content

Don't query stability data when staged_api is off #76656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3703,6 +3703,7 @@ dependencies = [
"rustc_data_structures",
"rustc_errors",
"rustc_expand",
"rustc_feature",
"rustc_hir",
"rustc_hir_pretty",
"rustc_index",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rustc_middle = { path = "../rustc_middle" }
rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_hir = { path = "../rustc_hir" }
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
rustc_target = { path = "../rustc_target" }
Expand Down
20 changes: 16 additions & 4 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,

Expand Down Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should optimize force_unstable_if_unmarked - we know the result of the query ahead of time if staged API is false, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that flag used anywhere outside building libstd?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No (well, rustc too), but speeding up compiler development if possible seems good.

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

Expand Down Expand Up @@ -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(),
Expand Down