Skip to content

Build a MIR Map containing the MIR for each fn body #28866

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 7 commits into from
Oct 7, 2015
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
12 changes: 0 additions & 12 deletions mk/main.mk
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,6 @@ ifdef CFG_DISABLE_STAGE0_LANDING_PADS
RUSTFLAGS_STAGE0 += -Z no-landing-pads
endif

# Enable MIR to "always build" for crates where this works. This is
# just temporary while MIR is being actively built up -- it's just a
# poor man's unit testing infrastructure. Anyway we only want this for
# stage1/stage2.
define ADD_MIR_FLAG
RUSTFLAGS1_$(1) += -Z always-build-mir
RUSTFLAGS2_$(1) += -Z always-build-mir
endef
$(foreach crate,$(TARGET_CRATES),$(eval $(call ADD_MIR_FLAG,$(crate))))
$(foreach crate,$(RUSTC_CRATES),$(eval $(call ADD_MIR_FLAG,$(crate))))
$(foreach crate,$(HOST_CRATES),$(eval $(call ADD_MIR_FLAG,$(crate))))

# platform-specific auto-configuration
include $(CFG_SRC_DIR)mk/platform.mk

Expand Down
6 changes: 0 additions & 6 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ pub struct Options {
pub parse_only: bool,
pub no_trans: bool,
pub treat_err_as_bug: bool,
pub always_build_mir: bool,
pub no_analysis: bool,
pub debugging_opts: DebuggingOptions,
pub prints: Vec<PrintRequest>,
Expand Down Expand Up @@ -211,7 +210,6 @@ pub fn basic_options() -> Options {
parse_only: false,
no_trans: false,
treat_err_as_bug: false,
always_build_mir: false,
no_analysis: false,
debugging_opts: basic_debugging_options(),
prints: Vec::new(),
Expand Down Expand Up @@ -578,8 +576,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"Run all passes except translation; no output"),
treat_err_as_bug: bool = (false, parse_bool,
"Treat all errors that occur as bugs"),
always_build_mir: bool = (false, parse_bool,
"Always build MIR for all fns, even without a #[rustc_mir] annotation"),
no_analysis: bool = (false, parse_bool,
"Parse and expand the source, but run no analysis"),
extra_plugins: Vec<String> = (Vec::new(), parse_list,
Expand Down Expand Up @@ -895,7 +891,6 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let parse_only = debugging_opts.parse_only;
let no_trans = debugging_opts.no_trans;
let treat_err_as_bug = debugging_opts.treat_err_as_bug;
let always_build_mir = debugging_opts.always_build_mir;
let no_analysis = debugging_opts.no_analysis;

if debugging_opts.debug_llvm {
Expand Down Expand Up @@ -1049,7 +1044,6 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
parse_only: parse_only,
no_trans: no_trans,
treat_err_as_bug: treat_err_as_bug,
always_build_mir: always_build_mir,
no_analysis: no_analysis,
debugging_opts: debugging_opts,
prints: prints,
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,9 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: Session,
time(time_passes, "match checking", ||
middle::check_match::check_crate(tcx));

time(time_passes, "MIR dump", ||
mir::dump::dump_crate(tcx));
let _mir_map =
time(time_passes, "MIR dump", ||
mir::mir_map::build_mir_for_crate(tcx));

time(time_passes, "liveness checking", ||
middle::liveness::check_crate(tcx));
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_mir/build/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use build::{BlockAnd, Builder};
use hair::*;
use repr::*;
use build::{BlockAnd, Builder};
use rustc_front::hir;

impl<H:Hair> Builder<H> {
impl<'a,'tcx> Builder<'a,'tcx> {
pub fn ast_block(&mut self,
destination: &Lvalue<H>,
destination: &Lvalue<'tcx>,
mut block: BasicBlock,
ast_block: H::Block)
ast_block: &'tcx hir::Block)
-> BlockAnd<()> {
let this = self;
let Block { extent, span: _, stmts, expr } = this.hir.mirror(ast_block);
Expand Down
28 changes: 14 additions & 14 deletions src/librustc_mir/build/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
//! Routines for manipulating the control-flow graph.

use build::CFG;
use hair::*;
use repr::*;
use syntax::codemap::Span;

impl<H:Hair> CFG<H> {
pub fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<H> {
impl<'tcx> CFG<'tcx> {
pub fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
&self.basic_blocks[blk.index()]
}

pub fn block_data_mut(&mut self, blk: BasicBlock) -> &mut BasicBlockData<H> {
pub fn block_data_mut(&mut self, blk: BasicBlock) -> &mut BasicBlockData<'tcx> {
&mut self.basic_blocks[blk.index()]
}

Expand All @@ -39,21 +39,21 @@ impl<H:Hair> CFG<H> {
BasicBlock::new(node_index)
}

pub fn push(&mut self, block: BasicBlock, statement: Statement<H>) {
pub fn push(&mut self, block: BasicBlock, statement: Statement<'tcx>) {
debug!("push({:?}, {:?})", block, statement);
self.block_data_mut(block).statements.push(statement);
}

pub fn push_assign_constant(&mut self,
block: BasicBlock,
span: H::Span,
temp: &Lvalue<H>,
constant: Constant<H>) {
span: Span,
temp: &Lvalue<'tcx>,
constant: Constant<'tcx>) {
self.push_assign(block, span, temp, Rvalue::Use(Operand::Constant(constant)));
}

pub fn push_drop(&mut self, block: BasicBlock, span: H::Span,
kind: DropKind, lvalue: &Lvalue<H>) {
pub fn push_drop(&mut self, block: BasicBlock, span: Span,
kind: DropKind, lvalue: &Lvalue<'tcx>) {
self.push(block, Statement {
span: span,
kind: StatementKind::Drop(kind, lvalue.clone())
Expand All @@ -62,9 +62,9 @@ impl<H:Hair> CFG<H> {

pub fn push_assign(&mut self,
block: BasicBlock,
span: H::Span,
lvalue: &Lvalue<H>,
rvalue: Rvalue<H>) {
span: Span,
lvalue: &Lvalue<'tcx>,
rvalue: Rvalue<'tcx>) {
self.push(block, Statement {
span: span,
kind: StatementKind::Assign(lvalue.clone(), rvalue)
Expand All @@ -73,7 +73,7 @@ impl<H:Hair> CFG<H> {

pub fn terminate(&mut self,
block: BasicBlock,
terminator: Terminator<H>) {
terminator: Terminator<'tcx>) {
// Check whether this block has already been terminated. For
// this, we rely on the fact that the initial state is to have
// a Diverge terminator and an empty list of targets (which
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/build/expr/as_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ use build::{Builder};
use hair::*;
use repr::*;

impl<H:Hair> Builder<H> {
impl<'a,'tcx> Builder<'a,'tcx> {
/// Compile `expr`, yielding a compile-time constant. Assumes that
/// `expr` is a valid compile-time constant!
pub fn as_constant<M>(&mut self, expr: M) -> Constant<H>
where M: Mirror<H, Output=Expr<H>>
pub fn as_constant<M>(&mut self, expr: M) -> Constant<'tcx>
where M: Mirror<'tcx, Output=Expr<'tcx>>
{
let expr = self.hir.mirror(expr);
self.expr_as_constant(expr)
}

fn expr_as_constant(&mut self, expr: Expr<H>) -> Constant<H> {
fn expr_as_constant(&mut self, expr: Expr<'tcx>) -> Constant<'tcx> {
let this = self;
let Expr { ty, temp_lifetime: _, span, kind } = expr;
match kind {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_mir/build/expr/as_lvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ use build::expr::category::Category;
use hair::*;
use repr::*;

impl<H:Hair> Builder<H> {
impl<'a,'tcx> Builder<'a,'tcx> {
/// Compile `expr`, yielding an lvalue that we can move from etc.
pub fn as_lvalue<M>(&mut self,
block: BasicBlock,
expr: M)
-> BlockAnd<Lvalue<H>>
where M: Mirror<H, Output=Expr<H>>
-> BlockAnd<Lvalue<'tcx>>
where M: Mirror<'tcx, Output=Expr<'tcx>>
{
let expr = self.hir.mirror(expr);
self.expr_as_lvalue(block, expr)
}

fn expr_as_lvalue(&mut self,
mut block: BasicBlock,
expr: Expr<H>)
-> BlockAnd<Lvalue<H>>
expr: Expr<'tcx>)
-> BlockAnd<Lvalue<'tcx>>
{
debug!("expr_as_lvalue(block={:?}, expr={:?})",
block, expr);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_mir/build/expr/as_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ use build::expr::category::Category;
use hair::*;
use repr::*;

impl<H:Hair> Builder<H> {
impl<'a,'tcx> Builder<'a,'tcx> {
/// Compile `expr` into a value that can be used as an operand.
/// If `expr` is an lvalue like `x`, this will introduce a
/// temporary `tmp = x`, so that we capture the value of `x` at
/// this time.
pub fn as_operand<M>(&mut self,
block: BasicBlock,
expr: M)
-> BlockAnd<Operand<H>>
where M: Mirror<H, Output=Expr<H>>
-> BlockAnd<Operand<'tcx>>
where M: Mirror<'tcx, Output=Expr<'tcx>>
{
let expr = self.hir.mirror(expr);
self.expr_as_operand(block, expr)
}

fn expr_as_operand(&mut self,
mut block: BasicBlock,
expr: Expr<H>)
-> BlockAnd<Operand<H>>
expr: Expr<'tcx>)
-> BlockAnd<Operand<'tcx>>
{
debug!("expr_as_operand(block={:?}, expr={:?})",
block, expr);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_mir/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ use build::expr::category::{Category, RvalueFunc};
use hair::*;
use repr::*;

impl<H:Hair> Builder<H> {
impl<'a,'tcx> Builder<'a,'tcx> {
/// Compile `expr`, yielding an rvalue.
pub fn as_rvalue<M>(&mut self,
block: BasicBlock,
expr: M)
-> BlockAnd<Rvalue<H>>
where M: Mirror<H, Output=Expr<H>>
-> BlockAnd<Rvalue<'tcx>>
where M: Mirror<'tcx, Output=Expr<'tcx>>
{
let expr = self.hir.mirror(expr);
self.expr_as_rvalue(block, expr)
}

fn expr_as_rvalue(&mut self,
mut block: BasicBlock,
expr: Expr<H>)
-> BlockAnd<Rvalue<H>>
expr: Expr<'tcx>)
-> BlockAnd<Rvalue<'tcx>>
{
debug!("expr_as_rvalue(block={:?}, expr={:?})",
block, expr);
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_mir/build/expr/as_temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ use build::expr::category::Category;
use hair::*;
use repr::*;

impl<H:Hair> Builder<H> {
impl<'a,'tcx> Builder<'a,'tcx> {
/// Compile `expr` into a fresh temporary. This is used when building
/// up rvalues so as to freeze the value that will be consumed.
pub fn as_temp<M>(&mut self,
block: BasicBlock,
expr: M)
-> BlockAnd<Lvalue<H>>
where M: Mirror<H, Output=Expr<H>>
-> BlockAnd<Lvalue<'tcx>>
where M: Mirror<'tcx, Output=Expr<'tcx>>
{
let expr = self.hir.mirror(expr);
self.expr_as_temp(block, expr)
}

fn expr_as_temp(&mut self,
mut block: BasicBlock,
expr: Expr<H>)
-> BlockAnd<Lvalue<H>>
expr: Expr<'tcx>)
-> BlockAnd<Lvalue<'tcx>>
{
debug!("expr_as_temp(block={:?}, expr={:?})",
block, expr);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub enum RvalueFunc {
/// Determines the category for a given expression. Note that scope
/// and paren expressions have no category.
impl Category {
pub fn of<H:Hair>(ek: &ExprKind<H>) -> Option<Category> {
pub fn of<'tcx>(ek: &ExprKind<'tcx>) -> Option<Category> {
match *ek {
ExprKind::Scope { .. } => None,

Expand Down
14 changes: 8 additions & 6 deletions src/librustc_mir/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ use build::expr::category::{Category, RvalueFunc};
use build::scope::LoopScope;
use hair::*;
use repr::*;
use rustc::middle::region::CodeExtent;
use syntax::codemap::Span;

impl<H:Hair> Builder<H> {
impl<'a,'tcx> Builder<'a,'tcx> {
/// Compile `expr`, storing the result into `destination`, which
/// is assumed to be uninitialized.
pub fn into_expr(&mut self,
destination: &Lvalue<H>,
destination: &Lvalue<'tcx>,
mut block: BasicBlock,
expr: Expr<H>)
expr: Expr<'tcx>)
-> BlockAnd<()>
{
debug!("into_expr(destination={:?}, block={:?}, expr={:?})",
Expand Down Expand Up @@ -266,12 +268,12 @@ impl<H:Hair> Builder<H> {
}

fn break_or_continue<F>(&mut self,
span: H::Span,
label: Option<H::CodeExtent>,
span: Span,
label: Option<CodeExtent>,
block: BasicBlock,
exit_selector: F)
-> BlockAnd<()>
where F: FnOnce(&LoopScope<H>) -> BasicBlock
where F: FnOnce(&LoopScope) -> BasicBlock
{
let loop_scope = self.find_loop_scope(span, label);
let exit_block = exit_selector(&loop_scope);
Expand Down
Loading