Skip to content

Commit 77ed20f

Browse files
committed
---
yaml --- r: 262399 b: refs/heads/snap-stage3 c: 32b2ef7 h: refs/heads/master i: 262397: d2eaa0b 262395: eeaa6dd 262391: 0e9b20a 262383: 9644aec 262367: a9da5c6 262335: 6c2e9d3 262271: 719c630 262143: b84c50f
1 parent a592277 commit 77ed20f

File tree

21 files changed

+197
-56
lines changed

21 files changed

+197
-56
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 5a0308abadce38396f27122d5c8639ffb2a21469
3-
refs/heads/snap-stage3: af1a0a346639966373206b70d7cd6376937bb544
3+
refs/heads/snap-stage3: 32b2ef7add2836cba5867d2e5ac9610cef416447
44
refs/heads/try: 29d24a3b02cb805da19450bf9830a8f0a6bd859c
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/snap-stage3/mk/crates.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ DEPS_rustc_passes := syntax rustc core rustc_front
106106
DEPS_rustc_mir := rustc rustc_front syntax
107107
DEPS_rustc_resolve := arena rustc rustc_front log syntax
108108
DEPS_rustc_platform_intrinsics := rustc rustc_llvm
109-
DEPS_rustc_plugin := rustc rustc_metadata syntax
109+
DEPS_rustc_plugin := rustc rustc_metadata syntax rustc_mir
110110
DEPS_rustc_privacy := rustc rustc_front log syntax
111111
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back rustc_mir \
112112
log syntax serialize rustc_llvm rustc_front rustc_platform_intrinsics

branches/snap-stage3/src/librustc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ pub mod mir {
126126
pub mod repr;
127127
pub mod tcx;
128128
pub mod visit;
129+
pub mod transform;
130+
pub mod mir_map;
129131
}
130132

131133
pub mod session;

branches/snap-stage3/src/librustc/middle/cstore.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use middle::lang_items;
2929
use middle::ty::{self, Ty, VariantKind};
3030
use middle::def_id::{DefId, DefIndex};
3131
use mir::repr::Mir;
32+
use mir::mir_map::MirMap;
3233
use session::Session;
3334
use session::search_paths::PathKind;
3435
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
@@ -244,7 +245,7 @@ pub trait CrateStore<'tcx> : Any {
244245
item_symbols: &RefCell<NodeMap<String>>,
245246
link_meta: &LinkMeta,
246247
reachable: &NodeSet,
247-
mir_map: &NodeMap<Mir<'tcx>>,
248+
mir_map: &MirMap<'tcx>,
248249
krate: &hir::Crate) -> Vec<u8>;
249250
fn metadata_encoding_version(&self) -> &[u8];
250251
}
@@ -428,7 +429,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
428429
item_symbols: &RefCell<NodeMap<String>>,
429430
link_meta: &LinkMeta,
430431
reachable: &NodeSet,
431-
mir_map: &NodeMap<Mir<'tcx>>,
432+
mir_map: &MirMap<'tcx>,
432433
krate: &hir::Crate) -> Vec<u8> { vec![] }
433434
fn metadata_encoding_version(&self) -> &[u8] { unimplemented!() }
434435
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use util::nodemap::NodeMap;
12+
use mir::repr::Mir;
13+
use mir::transform::MirPass;
14+
use middle::ty;
15+
16+
pub struct MirMap<'tcx> {
17+
pub map: NodeMap<Mir<'tcx>>,
18+
}
19+
20+
impl<'tcx> MirMap<'tcx> {
21+
pub fn run_passes(&mut self, passes: &mut [Box<MirPass>], tcx: &ty::ctxt<'tcx>) {
22+
for (_, ref mut mir) in &mut self.map {
23+
for pass in &mut *passes {
24+
pass.run_on_mir(mir, tcx)
25+
}
26+
}
27+
}
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use mir::repr::Mir;
12+
use middle::ty::ctxt;
13+
14+
pub trait MirPass {
15+
fn run_on_mir<'tcx>(&mut self, mir: &mut Mir<'tcx>, tcx: &ctxt<'tcx>);
16+
}

branches/snap-stage3/src/librustc/session/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use middle::cstore::CrateStore;
1313
use middle::dependency_format;
1414
use session::search_paths::PathKind;
1515
use util::nodemap::{NodeMap, FnvHashMap};
16+
use mir::transform::MirPass;
1617

1718
use syntax::ast::{NodeId, NodeIdAssigner, Name};
1819
use syntax::codemap::{Span, MultiSpan};
@@ -59,6 +60,7 @@ pub struct Session {
5960
pub lint_store: RefCell<lint::LintStore>,
6061
pub lints: RefCell<NodeMap<Vec<(lint::LintId, Span, String)>>>,
6162
pub plugin_llvm_passes: RefCell<Vec<String>>,
63+
pub plugin_mir_passes: RefCell<Vec<Box<MirPass>>>,
6264
pub plugin_attributes: RefCell<Vec<(String, AttributeType)>>,
6365
pub crate_types: RefCell<Vec<config::CrateType>>,
6466
pub dependency_formats: RefCell<dependency_format::Dependencies>,
@@ -475,6 +477,7 @@ pub fn build_session_(sopts: config::Options,
475477
lint_store: RefCell::new(lint::LintStore::new()),
476478
lints: RefCell::new(NodeMap()),
477479
plugin_llvm_passes: RefCell::new(Vec::new()),
480+
plugin_mir_passes: RefCell::new(Vec::new()),
478481
plugin_attributes: RefCell::new(Vec::new()),
479482
crate_types: RefCell::new(Vec::new()),
480483
dependency_formats: RefCell::new(FnvHashMap()),

branches/snap-stage3/src/librustc_driver/driver.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc::dep_graph::DepGraph;
1212
use rustc::front;
1313
use rustc::front::map as hir_map;
1414
use rustc_mir as mir;
15-
use rustc_mir::mir_map::MirMap;
15+
use rustc::mir::mir_map::MirMap;
1616
use rustc::session::{Session, CompileResult, compile_result_from_err_count};
1717
use rustc::session::config::{self, Input, OutputFilenames, OutputType};
1818
use rustc::session::search_paths::PathKind;
@@ -545,7 +545,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
545545
});
546546

547547
let Registry { syntax_exts, early_lint_passes, late_lint_passes, lint_groups,
548-
llvm_passes, attributes, .. } = registry;
548+
llvm_passes, attributes, mir_passes, .. } = registry;
549549

550550
try!(sess.track_errors(|| {
551551
let mut ls = sess.lint_store.borrow_mut();
@@ -561,6 +561,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
561561
}
562562

563563
*sess.plugin_llvm_passes.borrow_mut() = llvm_passes;
564+
*sess.plugin_mir_passes.borrow_mut() = mir_passes;
564565
*sess.plugin_attributes.borrow_mut() = attributes.clone();
565566
}));
566567

@@ -843,11 +844,15 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
843844
"match checking",
844845
|| middle::check_match::check_crate(tcx));
845846

846-
let mir_map =
847+
let mut mir_map =
847848
time(time_passes,
848849
"MIR dump",
849850
|| mir::mir_map::build_mir_for_crate(tcx));
850851

852+
time(time_passes,
853+
"MIR passes",
854+
|| mir_map.run_passes(&mut sess.plugin_mir_passes.borrow_mut(), tcx));
855+
851856
time(time_passes,
852857
"liveness checking",
853858
|| middle::liveness::check_crate(tcx));

branches/snap-stage3/src/librustc_metadata/csearch.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use middle::def_id::{DefId, DefIndex};
2323

2424
use rustc::front::map as hir_map;
2525
use rustc::mir::repr::Mir;
26+
use rustc::mir::mir_map::MirMap;
2627
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};
2728

2829
use std::cell::RefCell;
@@ -502,7 +503,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
502503
item_symbols: &RefCell<NodeMap<String>>,
503504
link_meta: &LinkMeta,
504505
reachable: &NodeSet,
505-
mir_map: &NodeMap<Mir<'tcx>>,
506+
mir_map: &MirMap<'tcx>,
506507
krate: &hir::Crate) -> Vec<u8>
507508
{
508509
let encode_inlined_item: encoder::EncodeInlinedItem =

branches/snap-stage3/src/librustc_metadata/encoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use middle::ty::{self, Ty};
3030
use rustc::back::svh::Svh;
3131
use rustc::front::map::{LinkedPath, PathElem, PathElems};
3232
use rustc::front::map as ast_map;
33-
use rustc::mir::repr::Mir;
33+
use rustc::mir::mir_map::MirMap;
3434
use rustc::session::config;
3535
use rustc::util::nodemap::{FnvHashMap, NodeMap, NodeSet};
3636

@@ -66,7 +66,7 @@ pub struct EncodeParams<'a, 'tcx: 'a> {
6666
pub cstore: &'a cstore::CStore,
6767
pub encode_inlined_item: EncodeInlinedItem<'a>,
6868
pub reachable: &'a NodeSet,
69-
pub mir_map: &'a NodeMap<Mir<'tcx>>,
69+
pub mir_map: &'a MirMap<'tcx>,
7070
}
7171

7272
pub struct EncodeContext<'a, 'tcx: 'a> {
@@ -79,7 +79,7 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
7979
pub encode_inlined_item: RefCell<EncodeInlinedItem<'a>>,
8080
pub type_abbrevs: tyencode::abbrev_map<'tcx>,
8181
pub reachable: &'a NodeSet,
82-
pub mir_map: &'a NodeMap<Mir<'tcx>>,
82+
pub mir_map: &'a MirMap<'tcx>,
8383
}
8484

8585
impl<'a, 'tcx> EncodeContext<'a,'tcx> {
@@ -824,7 +824,7 @@ fn encode_inlined_item(ecx: &EncodeContext,
824824
}
825825

826826
fn encode_mir(ecx: &EncodeContext, rbml_w: &mut Encoder, node_id: NodeId) {
827-
if let Some(mir) = ecx.mir_map.get(&node_id) {
827+
if let Some(mir) = ecx.mir_map.map.get(&node_id) {
828828
rbml_w.start_tag(tag_mir as usize);
829829
rbml_w.emit_opaque(|opaque_encoder| {
830830
tls::enter_encoding_context(ecx, opaque_encoder, |_, opaque_encoder| {
@@ -1447,7 +1447,7 @@ fn my_visit_expr(expr: &hir::Expr,
14471447

14481448
ecx.tcx.map.with_path(expr.id, |path| encode_path(rbml_w, path));
14491449

1450-
assert!(ecx.mir_map.contains_key(&expr.id));
1450+
assert!(ecx.mir_map.map.contains_key(&expr.id));
14511451
encode_mir(ecx, rbml_w, expr.id);
14521452

14531453
rbml_w.end_tag();

0 commit comments

Comments
 (0)