Skip to content

Commit 3c07b46

Browse files
committed
Pass the mir map to trans
1 parent 15c1da4 commit 3c07b46

File tree

8 files changed

+38
-18
lines changed

8 files changed

+38
-18
lines changed

mk/crates.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ DEPS_rustc_mir := rustc rustc_front syntax
103103
DEPS_rustc_resolve := rustc rustc_front log syntax
104104
DEPS_rustc_platform_intrinsics := rustc rustc_llvm
105105
DEPS_rustc_privacy := rustc rustc_front log syntax
106-
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
106+
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back rustc_mir \
107107
log syntax serialize rustc_llvm rustc_front rustc_platform_intrinsics
108108
DEPS_rustc_typeck := rustc syntax rustc_front rustc_platform_intrinsics
109109

src/librustc_driver/driver.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use rustc::front;
1212
use rustc::front::map as hir_map;
1313
use rustc_mir as mir;
14+
use rustc_mir::mir_map::MirMap;
1415
use rustc::session::Session;
1516
use rustc::session::config::{self, Input, OutputFilenames, OutputType};
1617
use rustc::session::search_paths::PathKind;
@@ -22,6 +23,7 @@ use rustc::middle::dependency_format;
2223
use rustc::middle;
2324
use rustc::plugin::registry::Registry;
2425
use rustc::plugin;
26+
use rustc::util::nodemap::NodeMap;
2527
use rustc::util::common::time;
2628
use rustc_borrowck as borrowck;
2729
use rustc_resolve as resolve;
@@ -146,7 +148,7 @@ pub fn compile_input(sess: Session,
146148
&arenas,
147149
&id,
148150
control.make_glob_map,
149-
|tcx, analysis| {
151+
|tcx, mir_map, analysis| {
150152

151153
{
152154
let state = CompileState::state_after_analysis(input,
@@ -170,7 +172,7 @@ pub fn compile_input(sess: Session,
170172
println!("Pre-trans");
171173
tcx.print_debug_stats();
172174
}
173-
let trans = phase_4_translate_to_llvm(tcx, analysis);
175+
let trans = phase_4_translate_to_llvm(tcx, &mir_map, analysis);
174176

175177
if log_enabled!(::log::INFO) {
176178
println!("Post-trans");
@@ -670,6 +672,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
670672
f: F)
671673
-> R
672674
where F: for<'a> FnOnce(&'a ty::ctxt<'tcx>,
675+
MirMap<'tcx>,
673676
ty::CrateAnalysis) -> R
674677
{
675678
let time_passes = sess.time_passes();
@@ -751,18 +754,18 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
751754
time(time_passes, "match checking", ||
752755
middle::check_match::check_crate(tcx));
753756

754-
match tcx.sess.opts.unstable_features {
757+
let mir_map = match tcx.sess.opts.unstable_features {
755758
UnstableFeatures::Disallow => {
756759
// use this as a shorthand for beta/stable, and skip
757760
// MIR construction there until known regressions are
758761
// addressed
762+
NodeMap()
759763
}
760764
UnstableFeatures::Allow | UnstableFeatures::Cheat => {
761-
let _mir_map =
762-
time(time_passes, "MIR dump", ||
763-
mir::mir_map::build_mir_for_crate(tcx));
765+
time(time_passes, "MIR dump", ||
766+
mir::mir_map::build_mir_for_crate(tcx))
764767
}
765-
}
768+
};
766769

767770
time(time_passes, "liveness checking", ||
768771
middle::liveness::check_crate(tcx));
@@ -804,7 +807,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
804807
// The above three passes generate errors w/o aborting
805808
tcx.sess.abort_if_errors();
806809

807-
f(tcx, ty::CrateAnalysis {
810+
f(tcx, mir_map, ty::CrateAnalysis {
808811
export_map: export_map,
809812
exported_items: exported_items,
810813
public_items: public_items,
@@ -817,16 +820,18 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
817820

818821
/// Run the translation phase to LLVM, after which the AST and analysis can
819822
/// be discarded.
820-
pub fn phase_4_translate_to_llvm(tcx: &ty::ctxt, analysis: ty::CrateAnalysis)
821-
-> trans::CrateTranslation {
823+
pub fn phase_4_translate_to_llvm<'tcx>(tcx: &ty::ctxt<'tcx>,
824+
mir_map: &MirMap<'tcx>,
825+
analysis: ty::CrateAnalysis)
826+
-> trans::CrateTranslation {
822827
let time_passes = tcx.sess.time_passes();
823828

824829
time(time_passes, "resolving dependency formats", ||
825830
dependency_format::calculate(&tcx.sess));
826831

827832
// Option dance to work around the lack of stack once closures.
828833
time(time_passes, "translation", move ||
829-
trans::trans_crate(tcx, analysis))
834+
trans::trans_crate(tcx, mir_map, analysis))
830835
}
831836

832837
/// Run LLVM itself, producing a bitcode file, assembly file or object file

src/librustc_driver/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl PpSourceMode {
182182
arenas,
183183
id,
184184
resolve::MakeGlobMap::No,
185-
|tcx, _| {
185+
|tcx, _, _| {
186186
let annotation = TypedAnnotation { tcx: tcx };
187187
f(&annotation, payload, &ast_map.forest.krate)
188188
})
@@ -782,7 +782,7 @@ pub fn pretty_print_input(sess: Session,
782782
&arenas,
783783
&id,
784784
resolve::MakeGlobMap::No,
785-
|tcx, _| {
785+
|tcx, _, _| {
786786
print_flowgraph(variants, tcx, code, mode, out)
787787
})
788788
}

src/librustc_trans/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#![feature(quote)]
3838
#![feature(rustc_diagnostic_macros)]
3939
#![feature(rustc_private)]
40+
#![feature(slice_patterns)]
4041
#![feature(staged_api)]
4142
#![feature(unicode)]
4243
#![feature(vec_push_all)]
@@ -52,6 +53,7 @@ extern crate rustc;
5253
extern crate rustc_back;
5354
extern crate rustc_front;
5455
extern crate rustc_llvm as llvm;
56+
extern crate rustc_mir;
5557
extern crate rustc_platform_intrinsics as intrinsics;
5658
extern crate serialize;
5759

src/librustc_trans/trans/base.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use middle::pat_util::simple_name;
4444
use middle::subst::Substs;
4545
use middle::ty::{self, Ty, HasTypeFlags};
4646
use rustc::front::map as hir_map;
47+
use rustc_mir::mir_map::MirMap;
4748
use session::config::{self, NoDebugInfo, FullDebugInfo};
4849
use session::Session;
4950
use trans::_match;
@@ -2737,7 +2738,10 @@ pub fn filter_reachable_ids(ccx: &SharedCrateContext) -> NodeSet {
27372738
}).collect()
27382739
}
27392740

2740-
pub fn trans_crate(tcx: &ty::ctxt, analysis: ty::CrateAnalysis) -> CrateTranslation {
2741+
pub fn trans_crate<'tcx>(tcx: &ty::ctxt<'tcx>,
2742+
mir_map: &MirMap<'tcx>,
2743+
analysis: ty::CrateAnalysis)
2744+
-> CrateTranslation {
27412745
let ty::CrateAnalysis { export_map, reachable, name, .. } = analysis;
27422746
let krate = tcx.map.krate();
27432747

@@ -2779,6 +2783,7 @@ pub fn trans_crate(tcx: &ty::ctxt, analysis: ty::CrateAnalysis) -> CrateTranslat
27792783
let shared_ccx = SharedCrateContext::new(&link_meta.crate_name,
27802784
codegen_units,
27812785
tcx,
2786+
&mir_map,
27822787
export_map,
27832788
Sha256::new(),
27842789
link_meta.clone(),

src/librustc_trans/trans/context.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use metadata::common::LinkMeta;
1414
use middle::def::ExportMap;
1515
use middle::def_id::DefId;
1616
use middle::traits;
17+
use rustc_mir::mir_map::MirMap;
1718
use trans::adt;
1819
use trans::base;
1920
use trans::builder::Builder;
@@ -70,6 +71,7 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> {
7071
stats: Stats,
7172
check_overflow: bool,
7273
check_drop_flag_for_sanity: bool,
74+
mir_map: &'a MirMap<'tcx>,
7375

7476
available_drop_glues: RefCell<FnvHashMap<DropGlueKind<'tcx>, String>>,
7577
use_dll_storage_attrs: bool,
@@ -251,6 +253,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
251253
pub fn new(crate_name: &str,
252254
local_count: usize,
253255
tcx: &'b ty::ctxt<'tcx>,
256+
mir_map: &'b MirMap<'tcx>,
254257
export_map: ExportMap,
255258
symbol_hasher: Sha256,
256259
link_meta: LinkMeta,
@@ -317,6 +320,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
317320
link_meta: link_meta,
318321
symbol_hasher: RefCell::new(symbol_hasher),
319322
tcx: tcx,
323+
mir_map: mir_map,
320324
stats: Stats {
321325
n_glues_created: Cell::new(0),
322326
n_null_glues: Cell::new(0),
@@ -803,6 +807,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
803807
pub fn use_dll_storage_attrs(&self) -> bool {
804808
self.shared.use_dll_storage_attrs()
805809
}
810+
811+
pub fn mir_map(&self) -> &'b MirMap<'tcx> {
812+
self.shared.mir_map
813+
}
806814
}
807815

808816
pub struct TypeOfDepthLock<'a, 'tcx: 'a>(&'a LocalCrateContext<'tcx>);

src/librustdoc/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
145145
&arenas,
146146
&name,
147147
resolve::MakeGlobMap::No,
148-
|tcx, analysis| {
148+
|tcx, _, analysis| {
149149
let ty::CrateAnalysis { exported_items, public_items, .. } = analysis;
150150

151151
// Convert from a NodeId set to a DefId set since we don't always have easy access

src/test/run-make/execution-engine/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ fn compile_program(input: &str, sysroot: PathBuf)
229229
let ast_map = driver::make_map(&sess, &mut hir_forest);
230230

231231
driver::phase_3_run_analysis_passes(
232-
&sess, ast_map, &arenas, &id, MakeGlobMap::No, |tcx, analysis| {
232+
&sess, ast_map, &arenas, &id, MakeGlobMap::No, |tcx, mir_map, analysis| {
233233

234-
let trans = driver::phase_4_translate_to_llvm(tcx, analysis);
234+
let trans = driver::phase_4_translate_to_llvm(tcx, &mir_map, analysis);
235235

236236
let crates = tcx.sess.cstore.get_used_crates(RequireDynamic);
237237

0 commit comments

Comments
 (0)