Skip to content

Calculate privacy access only via query #57343

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 2 commits into from
Jan 5, 2019
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
3 changes: 0 additions & 3 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -123,8 +122,6 @@ mod sty;
/// *on-demand* infrastructure.
#[derive(Clone)]
pub struct CrateAnalysis {
pub access_levels: Lrc<AccessLevels>,
pub name: String,
pub glob_map: Option<hir::GlobMap>,
}

Expand Down
12 changes: 5 additions & 7 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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};
Expand Down Expand Up @@ -785,8 +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)
} else {
Expand Down Expand Up @@ -1193,7 +1190,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,
Expand Down Expand Up @@ -1275,8 +1272,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)
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
}
};
}
Expand Down
6 changes: 2 additions & 4 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +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 },
};

Expand All @@ -494,12 +492,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
Expand Down