From: Niko Matsakis Date: Wed, 21 Oct 2015 21:20:00 +0000 (-0400) Subject: Pass the mir map to trans X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=3c07b4611815d4d593fba22aaaa975ed97818919;p=rust.git Pass the mir map to trans --- diff --git a/mk/crates.mk b/mk/crates.mk index 6673b9b28e7..2a627a6da2b 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -103,7 +103,7 @@ DEPS_rustc_mir := rustc rustc_front syntax DEPS_rustc_resolve := rustc rustc_front log syntax DEPS_rustc_platform_intrinsics := rustc rustc_llvm DEPS_rustc_privacy := rustc rustc_front log syntax -DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \ +DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back rustc_mir \ log syntax serialize rustc_llvm rustc_front rustc_platform_intrinsics DEPS_rustc_typeck := rustc syntax rustc_front rustc_platform_intrinsics diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 69c4dcb0a19..06708a5127f 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -11,6 +11,7 @@ use rustc::front; use rustc::front::map as hir_map; use rustc_mir as mir; +use rustc_mir::mir_map::MirMap; use rustc::session::Session; use rustc::session::config::{self, Input, OutputFilenames, OutputType}; use rustc::session::search_paths::PathKind; @@ -22,6 +23,7 @@ use rustc::middle; use rustc::plugin::registry::Registry; use rustc::plugin; +use rustc::util::nodemap::NodeMap; use rustc::util::common::time; use rustc_borrowck as borrowck; use rustc_resolve as resolve; @@ -146,7 +148,7 @@ macro_rules! controller_entry_point{($point: ident, $tsess: expr, $make_state: e &arenas, &id, control.make_glob_map, - |tcx, analysis| { + |tcx, mir_map, analysis| { { let state = CompileState::state_after_analysis(input, @@ -170,7 +172,7 @@ macro_rules! controller_entry_point{($point: ident, $tsess: expr, $make_state: e println!("Pre-trans"); tcx.print_debug_stats(); } - let trans = phase_4_translate_to_llvm(tcx, analysis); + let trans = phase_4_translate_to_llvm(tcx, &mir_map, analysis); if log_enabled!(::log::INFO) { println!("Post-trans"); @@ -670,6 +672,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, f: F) -> R where F: for<'a> FnOnce(&'a ty::ctxt<'tcx>, + MirMap<'tcx>, ty::CrateAnalysis) -> R { let time_passes = sess.time_passes(); @@ -751,18 +754,18 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, time(time_passes, "match checking", || middle::check_match::check_crate(tcx)); - match tcx.sess.opts.unstable_features { + let mir_map = match tcx.sess.opts.unstable_features { UnstableFeatures::Disallow => { // use this as a shorthand for beta/stable, and skip // MIR construction there until known regressions are // addressed + NodeMap() } UnstableFeatures::Allow | UnstableFeatures::Cheat => { - let _mir_map = - time(time_passes, "MIR dump", || - mir::mir_map::build_mir_for_crate(tcx)); + time(time_passes, "MIR dump", || + mir::mir_map::build_mir_for_crate(tcx)) } - } + }; time(time_passes, "liveness checking", || middle::liveness::check_crate(tcx)); @@ -804,7 +807,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, // The above three passes generate errors w/o aborting tcx.sess.abort_if_errors(); - f(tcx, ty::CrateAnalysis { + f(tcx, mir_map, ty::CrateAnalysis { export_map: export_map, exported_items: exported_items, public_items: public_items, @@ -817,8 +820,10 @@ 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(tcx: &ty::ctxt, analysis: ty::CrateAnalysis) - -> trans::CrateTranslation { +pub fn phase_4_translate_to_llvm<'tcx>(tcx: &ty::ctxt<'tcx>, + mir_map: &MirMap<'tcx>, + analysis: ty::CrateAnalysis) + -> trans::CrateTranslation { let time_passes = tcx.sess.time_passes(); time(time_passes, "resolving dependency formats", || @@ -826,7 +831,7 @@ pub fn phase_4_translate_to_llvm(tcx: &ty::ctxt, analysis: ty::CrateAnalysis) // Option dance to work around the lack of stack once closures. time(time_passes, "translation", move || - trans::trans_crate(tcx, analysis)) + trans::trans_crate(tcx, mir_map, analysis)) } /// Run LLVM itself, producing a bitcode file, assembly file or object file diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index a30c437197c..f53822d2400 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -182,7 +182,7 @@ fn call_with_pp_support_hir<'tcx, A, B, F>(&self, arenas, id, resolve::MakeGlobMap::No, - |tcx, _| { + |tcx, _, _| { let annotation = TypedAnnotation { tcx: tcx }; f(&annotation, payload, &ast_map.forest.krate) }) @@ -782,7 +782,7 @@ pub fn pretty_print_input(sess: Session, &arenas, &id, resolve::MakeGlobMap::No, - |tcx, _| { + |tcx, _, _| { print_flowgraph(variants, tcx, code, mode, out) }) } diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index e02ce49132a..bc5b6f6b9d7 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -37,6 +37,7 @@ #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] +#![feature(slice_patterns)] #![feature(staged_api)] #![feature(unicode)] #![feature(vec_push_all)] @@ -52,6 +53,7 @@ extern crate rustc_back; extern crate rustc_front; extern crate rustc_llvm as llvm; +extern crate rustc_mir; extern crate rustc_platform_intrinsics as intrinsics; extern crate serialize; diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 46a4cb0c92e..f28b7e8f52d 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -44,6 +44,7 @@ use middle::subst::Substs; use middle::ty::{self, Ty, HasTypeFlags}; use rustc::front::map as hir_map; +use rustc_mir::mir_map::MirMap; use session::config::{self, NoDebugInfo, FullDebugInfo}; use session::Session; use trans::_match; @@ -2737,7 +2738,10 @@ pub fn filter_reachable_ids(ccx: &SharedCrateContext) -> NodeSet { }).collect() } -pub fn trans_crate(tcx: &ty::ctxt, analysis: ty::CrateAnalysis) -> CrateTranslation { +pub fn trans_crate<'tcx>(tcx: &ty::ctxt<'tcx>, + mir_map: &MirMap<'tcx>, + analysis: ty::CrateAnalysis) + -> CrateTranslation { let ty::CrateAnalysis { export_map, reachable, name, .. } = analysis; let krate = tcx.map.krate(); @@ -2779,6 +2783,7 @@ pub fn trans_crate(tcx: &ty::ctxt, analysis: ty::CrateAnalysis) -> CrateTranslat let shared_ccx = SharedCrateContext::new(&link_meta.crate_name, codegen_units, tcx, + &mir_map, export_map, Sha256::new(), link_meta.clone(), diff --git a/src/librustc_trans/trans/context.rs b/src/librustc_trans/trans/context.rs index 01d0c51a08d..1f1d43feeb3 100644 --- a/src/librustc_trans/trans/context.rs +++ b/src/librustc_trans/trans/context.rs @@ -14,6 +14,7 @@ use middle::def::ExportMap; use middle::def_id::DefId; use middle::traits; +use rustc_mir::mir_map::MirMap; use trans::adt; use trans::base; use trans::builder::Builder; @@ -70,6 +71,7 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> { stats: Stats, check_overflow: bool, check_drop_flag_for_sanity: bool, + mir_map: &'a MirMap<'tcx>, available_drop_glues: RefCell, String>>, use_dll_storage_attrs: bool, @@ -251,6 +253,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> { pub fn new(crate_name: &str, local_count: usize, tcx: &'b ty::ctxt<'tcx>, + mir_map: &'b MirMap<'tcx>, export_map: ExportMap, symbol_hasher: Sha256, link_meta: LinkMeta, @@ -317,6 +320,7 @@ pub fn new(crate_name: &str, link_meta: link_meta, symbol_hasher: RefCell::new(symbol_hasher), tcx: tcx, + mir_map: mir_map, stats: Stats { n_glues_created: Cell::new(0), n_null_glues: Cell::new(0), @@ -803,6 +807,10 @@ pub fn check_drop_flag_for_sanity(&self) -> bool { pub fn use_dll_storage_attrs(&self) -> bool { self.shared.use_dll_storage_attrs() } + + pub fn mir_map(&self) -> &'b MirMap<'tcx> { + self.shared.mir_map + } } pub struct TypeOfDepthLock<'a, 'tcx: 'a>(&'a LocalCrateContext<'tcx>); diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 4955951d36e..d07d44a2a94 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -145,7 +145,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec, externs: Externs, &arenas, &name, resolve::MakeGlobMap::No, - |tcx, analysis| { + |tcx, _, analysis| { let ty::CrateAnalysis { exported_items, public_items, .. } = analysis; // Convert from a NodeId set to a DefId set since we don't always have easy access diff --git a/src/test/run-make/execution-engine/test.rs b/src/test/run-make/execution-engine/test.rs index f4031a3aaae..f2dd155595a 100644 --- a/src/test/run-make/execution-engine/test.rs +++ b/src/test/run-make/execution-engine/test.rs @@ -229,9 +229,9 @@ fn compile_program(input: &str, sysroot: PathBuf) let ast_map = driver::make_map(&sess, &mut hir_forest); driver::phase_3_run_analysis_passes( - &sess, ast_map, &arenas, &id, MakeGlobMap::No, |tcx, analysis| { + &sess, ast_map, &arenas, &id, MakeGlobMap::No, |tcx, mir_map, analysis| { - let trans = driver::phase_4_translate_to_llvm(tcx, analysis); + let trans = driver::phase_4_translate_to_llvm(tcx, &mir_map, analysis); let crates = tcx.sess.cstore.get_used_crates(RequireDynamic);