Skip to content

Commit d9885c4

Browse files
authored
Rollup merge of #57343 - Xanewok:querify-access-levels, r=nikomatsakis
Calculate privacy access only via query Initially converted to query in a9f6bab and then changed to respect dependencies 8281e88. I did this as an effort to prune `CrateAnalysis` from librustc_save_analysis, with the only thing remaining being the glob map (`name` is unused, existing `crate_name` is exposed in the compiler passes, instead). Since calculating the glob map is opt-in, it'd be great if we could calculate that on-demand. However, it seems that it'd require converting resolution to queries, which I'm not sure how to do yet. In an effort to get rid of `CrateAnalysis` altogether, could we try unconditionally calculating the glob_map in the resolver, thus completely removing `CrateAnalysis` struct, and doing a perf run? r? @nikomatsakis cc @petrochenkov do you have any idea how/if at all could we querify the resolver? I've stumbled upon a comment that's ~3? years old at the moment, so I'm guessing things might have changed and it actually may be feasible now. https://github.com/rust-lang/rust/blob/fe0c10019d7ee96909cc42cc265ef999a6b5dd70/src/librustc_driver/driver.rs#L589-L593
2 parents 06c07f9 + 480d0f3 commit d9885c4

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

src/librustc/ty/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use ich::Fingerprint;
1414
use ich::StableHashingContext;
1515
use infer::canonical::Canonical;
1616
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
17-
use middle::privacy::AccessLevels;
1817
use middle::resolve_lifetime::ObjectLifetimeDefault;
1918
use mir::Mir;
2019
use mir::interpret::{GlobalId, ErrorHandled};
@@ -123,8 +122,6 @@ mod sty;
123122
/// *on-demand* infrastructure.
124123
#[derive(Clone)]
125124
pub struct CrateAnalysis {
126-
pub access_levels: Lrc<AccessLevels>,
127-
pub name: String,
128125
pub glob_map: Option<hir::GlobMap>,
129126
}
130127

src/librustc_driver/driver.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc::hir::lowering::lower_crate;
44
use rustc::hir::map as hir_map;
55
use rustc::lint;
66
use rustc::middle::{self, reachable, resolve_lifetime, stability};
7-
use rustc::middle::privacy::AccessLevels;
87
use rustc::ty::{self, AllArenas, Resolutions, TyCtxt};
98
use rustc::traits;
109
use rustc::util::common::{install_panic_hook, time, ErrorReported};
@@ -18,7 +17,7 @@ use rustc_borrowck as borrowck;
1817
use rustc_codegen_utils::codegen_backend::CodegenBackend;
1918
use rustc_data_structures::fingerprint::Fingerprint;
2019
use rustc_data_structures::stable_hasher::StableHasher;
21-
use rustc_data_structures::sync::{self, Lrc, Lock};
20+
use rustc_data_structures::sync::{self, Lock};
2221
use rustc_incremental;
2322
use rustc_metadata::creader::CrateLoader;
2423
use rustc_metadata::cstore::{self, CStore};
@@ -785,8 +784,6 @@ where
785784
},
786785

787786
analysis: ty::CrateAnalysis {
788-
access_levels: Lrc::new(AccessLevels::default()),
789-
name: crate_name.to_string(),
790787
glob_map: if resolver.make_glob_map {
791788
Some(resolver.glob_map)
792789
} else {
@@ -1193,7 +1190,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
11931190
sess: &'tcx Session,
11941191
cstore: &'tcx CStore,
11951192
hir_map: hir_map::Map<'tcx>,
1196-
mut analysis: ty::CrateAnalysis,
1193+
analysis: ty::CrateAnalysis,
11971194
resolutions: Resolutions,
11981195
arenas: &'tcx mut AllArenas<'tcx>,
11991196
name: &str,
@@ -1275,8 +1272,9 @@ where
12751272
rvalue_promotion::check_crate(tcx)
12761273
});
12771274

1278-
analysis.access_levels =
1279-
time(sess, "privacy checking", || rustc_privacy::check_crate(tcx));
1275+
time(sess, "privacy checking", || {
1276+
rustc_privacy::check_crate(tcx)
1277+
});
12801278

12811279
time(sess, "intrinsic checking", || {
12821280
middle::intrinsicck::check_crate(tcx)

src/librustc_save_analysis/dump_visitor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//! recording the output.
1515
1616
use rustc::hir::def::Def as HirDef;
17-
use rustc::hir::def_id::DefId;
17+
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
1818
use rustc::session::config::Input;
1919
use rustc::ty::{self, TyCtxt};
2020
use rustc_data_structures::fx::FxHashSet;
@@ -56,14 +56,14 @@ macro_rules! access_from {
5656
($save_ctxt:expr, $vis:expr, $id:expr) => {
5757
Access {
5858
public: $vis.node.is_pub(),
59-
reachable: $save_ctxt.analysis.access_levels.is_reachable($id),
59+
reachable: $save_ctxt.tcx.privacy_access_levels(LOCAL_CRATE).is_reachable($id),
6060
}
6161
};
6262

6363
($save_ctxt:expr, $item:expr) => {
6464
Access {
6565
public: $item.vis.node.is_pub(),
66-
reachable: $save_ctxt.analysis.access_levels.is_reachable($item.id),
66+
reachable: $save_ctxt.tcx.privacy_access_levels(LOCAL_CRATE).is_reachable($item.id),
6767
}
6868
};
6969
}

src/librustdoc/core.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
476476
}).collect(),
477477
};
478478
let analysis = ty::CrateAnalysis {
479-
access_levels: Lrc::new(AccessLevels::default()),
480-
name: name.to_string(),
481479
glob_map: if resolver.make_glob_map { Some(resolver.glob_map.clone()) } else { None },
482480
};
483481

@@ -500,12 +498,12 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
500498
&mut arenas,
501499
&name,
502500
&output_filenames,
503-
|tcx, analysis, _, result| {
501+
|tcx, _, _, result| {
504502
if result.is_err() {
505503
sess.fatal("Compilation failed, aborting rustdoc");
506504
}
507505

508-
let ty::CrateAnalysis { access_levels, .. } = analysis;
506+
let access_levels = tcx.privacy_access_levels(LOCAL_CRATE);
509507

510508
// Convert from a NodeId set to a DefId set since we don't always have easy access
511509
// to the map from defid -> nodeid

0 commit comments

Comments
 (0)