Skip to content

Commit

Permalink
rustc: Use reachablility through a query
Browse files Browse the repository at this point in the history
Turns out this was already set up as a query, just wasn't using it yet!
  • Loading branch information
alexcrichton committed Sep 17, 2017
1 parent a97ad6a commit baca9a6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
4 changes: 0 additions & 4 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,6 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
}
}

pub fn find_reachable<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Rc<NodeSet> {
tcx.reachable_set(LOCAL_CRATE)
}

fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> Rc<NodeSet> {
debug_assert!(crate_num == LOCAL_CRATE);

Expand Down
1 change: 0 additions & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ mod sty;
#[derive(Clone)]
pub struct CrateAnalysis {
pub access_levels: Rc<AccessLevels>,
pub reachable: Rc<NodeSet>,
pub name: String,
pub glob_map: Option<hir::GlobMap>,
}
Expand Down
12 changes: 2 additions & 10 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use rustc::mir::transform::{MIR_CONST, MIR_VALIDATED, MIR_OPTIMIZED, Passes};
use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
use rustc::traits;
use rustc::util::common::{ErrorReported, time};
use rustc::util::nodemap::NodeSet;
use rustc_allocator as allocator;
use rustc_borrowck as borrowck;
use rustc_incremental::{self, IncrementalHashesMap};
Expand Down Expand Up @@ -243,7 +242,7 @@ pub fn compile_input(sess: &Session,
tcx.print_debug_stats();
}

let trans = phase_4_translate_to_llvm(tcx, analysis, incremental_hashes_map,
let trans = phase_4_translate_to_llvm(tcx, incremental_hashes_map,
&outputs);

if log_enabled!(::log::LogLevel::Info) {
Expand Down Expand Up @@ -885,7 +884,6 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
defs: resolver.definitions,
analysis: ty::CrateAnalysis {
access_levels: Rc::new(AccessLevels::default()),
reachable: Rc::new(NodeSet()),
name: crate_name.to_string(),
glob_map: if resolver.make_glob_map { Some(resolver.glob_map) } else { None },
},
Expand Down Expand Up @@ -1103,11 +1101,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
return Ok(f(tcx, analysis, incremental_hashes_map, sess.compile_status()));
}

analysis.reachable =
time(time_passes,
"reachability checking",
|| reachable::find_reachable(tcx));

time(time_passes, "death checking", || middle::dead::check_crate(tcx));

time(time_passes, "unused lib feature checking", || {
Expand All @@ -1123,7 +1116,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
/// Run the translation phase to LLVM, after which the AST and analysis can
/// be discarded.
pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
analysis: ty::CrateAnalysis,
incremental_hashes_map: IncrementalHashesMap,
output_filenames: &OutputFilenames)
-> write::OngoingCrateTranslation {
Expand All @@ -1136,7 +1128,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let translation =
time(time_passes,
"translation",
move || trans::trans_crate(tcx, analysis, incremental_hashes_map, output_filenames));
move || trans::trans_crate(tcx, incremental_hashes_map, output_filenames));

if tcx.sess.profile_queries() {
profile::dump("profile_queries".to_string())
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,8 @@ fn iter_globals(llmod: llvm::ModuleRef) -> ValueIter {
///
/// This list is later used by linkers to determine the set of symbols needed to
/// be exposed from a dynamic library and it's also encoded into the metadata.
pub fn find_exported_symbols(tcx: TyCtxt, reachable: &NodeSet) -> NodeSet {
reachable.iter().cloned().filter(|&id| {
pub fn find_exported_symbols(tcx: TyCtxt) -> NodeSet {
tcx.reachable_set(LOCAL_CRATE).iter().cloned().filter(|&id| {
// Next, we want to ignore some FFI functions that are not exposed from
// this crate. Reachable FFI functions can be lumped into two
// categories:
Expand Down Expand Up @@ -929,7 +929,6 @@ pub fn find_exported_symbols(tcx: TyCtxt, reachable: &NodeSet) -> NodeSet {
}

pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
analysis: ty::CrateAnalysis,
incremental_hashes_map: IncrementalHashesMap,
output_filenames: &OutputFilenames)
-> OngoingCrateTranslation {
Expand All @@ -940,10 +939,9 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// `TransCrate`, you need to be careful to register "reads" of the
// particular items that will be processed.
let krate = tcx.hir.krate();
let ty::CrateAnalysis { reachable, .. } = analysis;
let check_overflow = tcx.sess.overflow_checks();
let link_meta = link::build_link_meta(&incremental_hashes_map);
let exported_symbol_node_ids = find_exported_symbols(tcx, &reachable);
let exported_symbol_node_ids = find_exported_symbols(tcx);

let shared_ccx = SharedCrateContext::new(tcx,
check_overflow,
Expand Down

0 comments on commit baca9a6

Please sign in to comment.