From a1189ac05817d50e135734e446934b2aa61e31bf Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 4 Jan 2019 17:23:39 +0100 Subject: [PATCH 1/2] Replace CrateAnalysis::access_levels with query --- src/librustc/ty/mod.rs | 2 -- src/librustc_driver/driver.rs | 11 +++++------ src/librustc_save_analysis/dump_visitor.rs | 6 +++--- src/librustdoc/core.rs | 5 ++--- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index d40dd830e9fb9..20ae9cb2da1f6 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -14,7 +14,6 @@ use ich::Fingerprint; use ich::StableHashingContext; use infer::canonical::Canonical; use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem}; -use middle::privacy::AccessLevels; use middle::resolve_lifetime::ObjectLifetimeDefault; use mir::Mir; use mir::interpret::{GlobalId, ErrorHandled}; @@ -123,7 +122,6 @@ mod sty; /// *on-demand* infrastructure. #[derive(Clone)] pub struct CrateAnalysis { - pub access_levels: Lrc, pub name: String, pub glob_map: Option, } diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 9b232edc11d4a..851de44c2811e 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -4,7 +4,6 @@ use rustc::hir::lowering::lower_crate; use rustc::hir::map as hir_map; use rustc::lint; use rustc::middle::{self, reachable, resolve_lifetime, stability}; -use rustc::middle::privacy::AccessLevels; use rustc::ty::{self, AllArenas, Resolutions, TyCtxt}; use rustc::traits; use rustc::util::common::{install_panic_hook, time, ErrorReported}; @@ -18,7 +17,7 @@ use rustc_borrowck as borrowck; use rustc_codegen_utils::codegen_backend::CodegenBackend; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::StableHasher; -use rustc_data_structures::sync::{self, Lrc, Lock}; +use rustc_data_structures::sync::{self, Lock}; use rustc_incremental; use rustc_metadata::creader::CrateLoader; use rustc_metadata::cstore::{self, CStore}; @@ -785,7 +784,6 @@ where }, analysis: ty::CrateAnalysis { - access_levels: Lrc::new(AccessLevels::default()), name: crate_name.to_string(), glob_map: if resolver.make_glob_map { Some(resolver.glob_map) @@ -1193,7 +1191,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>( sess: &'tcx Session, cstore: &'tcx CStore, hir_map: hir_map::Map<'tcx>, - mut analysis: ty::CrateAnalysis, + analysis: ty::CrateAnalysis, resolutions: Resolutions, arenas: &'tcx mut AllArenas<'tcx>, name: &str, @@ -1275,8 +1273,9 @@ where rvalue_promotion::check_crate(tcx) }); - analysis.access_levels = - time(sess, "privacy checking", || rustc_privacy::check_crate(tcx)); + time(sess, "privacy checking", || { + rustc_privacy::check_crate(tcx) + }); time(sess, "intrinsic checking", || { middle::intrinsicck::check_crate(tcx) diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 3c83c45f98403..891537309177e 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -14,7 +14,7 @@ //! recording the output. use rustc::hir::def::Def as HirDef; -use rustc::hir::def_id::DefId; +use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::session::config::Input; use rustc::ty::{self, TyCtxt}; use rustc_data_structures::fx::FxHashSet; @@ -56,14 +56,14 @@ macro_rules! access_from { ($save_ctxt:expr, $vis:expr, $id:expr) => { Access { public: $vis.node.is_pub(), - reachable: $save_ctxt.analysis.access_levels.is_reachable($id), + reachable: $save_ctxt.tcx.privacy_access_levels(LOCAL_CRATE).is_reachable($id), } }; ($save_ctxt:expr, $item:expr) => { Access { public: $item.vis.node.is_pub(), - reachable: $save_ctxt.analysis.access_levels.is_reachable($item.id), + reachable: $save_ctxt.tcx.privacy_access_levels(LOCAL_CRATE).is_reachable($item.id), } }; } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 3fa2d085ece94..ccbe48f4ac1fb 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -470,7 +470,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt }).collect(), }; let analysis = ty::CrateAnalysis { - access_levels: Lrc::new(AccessLevels::default()), name: name.to_string(), glob_map: if resolver.make_glob_map { Some(resolver.glob_map.clone()) } else { None }, }; @@ -494,12 +493,12 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt &mut arenas, &name, &output_filenames, - |tcx, analysis, _, result| { + |tcx, _, _, result| { if result.is_err() { sess.fatal("Compilation failed, aborting rustdoc"); } - let ty::CrateAnalysis { access_levels, .. } = analysis; + let access_levels = tcx.privacy_access_levels(LOCAL_CRATE); // Convert from a NodeId set to a DefId set since we don't always have easy access // to the map from defid -> nodeid From 480d0f3a317f8bd4404bfe4df220300372a110c8 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 4 Jan 2019 20:01:01 +0100 Subject: [PATCH 2/2] Remove unused name from CrateAnalysis --- src/librustc/ty/mod.rs | 1 - src/librustc_driver/driver.rs | 1 - src/librustdoc/core.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 20ae9cb2da1f6..efe38eb275f07 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -122,7 +122,6 @@ mod sty; /// *on-demand* infrastructure. #[derive(Clone)] pub struct CrateAnalysis { - pub name: String, pub glob_map: Option, } diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 851de44c2811e..a9b32df801c96 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -784,7 +784,6 @@ where }, analysis: ty::CrateAnalysis { - name: crate_name.to_string(), glob_map: if resolver.make_glob_map { Some(resolver.glob_map) } else { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index ccbe48f4ac1fb..032265c8492dc 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -470,7 +470,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt }).collect(), }; let analysis = ty::CrateAnalysis { - name: name.to_string(), glob_map: if resolver.make_glob_map { Some(resolver.glob_map.clone()) } else { None }, };