Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9294f8e
hash foreign items too
nikomatsakis Jul 29, 2016
c56eb4b
remap Hir(InlinedDefId) to MetaData(OriginalDefId)
nikomatsakis Jul 29, 2016
b4929d1
watch out for krate numbers being reassigned
nikomatsakis Jul 29, 2016
2797b2a
remove register_reads
nikomatsakis Jul 30, 2016
2e7df80
make metadata hashes determinstic
nikomatsakis Aug 1, 2016
903142a
dump statistics about re-use w/ -Z time-passes
nikomatsakis Aug 1, 2016
94acff1
replace graph rewriting with detecting inlined ids
nikomatsakis Aug 2, 2016
b13d504
improve log when something no longer exists
nikomatsakis Aug 2, 2016
54595ec
use memoized pattern for SizedConstraint
nikomatsakis Aug 2, 2016
bfbfe63
skip assert-dep-graph unless unit testing
nikomatsakis Aug 3, 2016
a6a97a9
rustfmt save.rs
nikomatsakis Aug 5, 2016
88b2e9a
rename KrateInfo to CrateInfo
nikomatsakis Aug 8, 2016
8fdc72f
track MIR through the dep-graph
nikomatsakis Aug 8, 2016
82b6dc2
fixup tests for new def'n of InlinedItem
nikomatsakis Aug 9, 2016
0e97240
isolate predecessor computation
nikomatsakis Aug 5, 2016
a92b1a7
make DepNode PartialOrd
nikomatsakis Aug 6, 2016
571010b
replace Name with InternedString in DefPathData
nikomatsakis Aug 6, 2016
d4bd054
add a `-Z incremental-info` flag
nikomatsakis Aug 6, 2016
8150494
add a `deterministic_hash` method to `DefPath`
nikomatsakis Aug 6, 2016
9978cbc
generalize BitMatrix to be NxM and not just NxN
nikomatsakis Aug 6, 2016
02a4703
use preds to serialize just what we need
nikomatsakis Aug 6, 2016
ecbcf1b
address comments from mw
nikomatsakis Aug 9, 2016
76eecc7
pacify the mercilous tidy
nikomatsakis Aug 9, 2016
e0b82d5
fix license
nikomatsakis Aug 9, 2016
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: 6 additions & 6 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ pub enum DepNode<D: Clone + Debug> {
Privacy,
IntrinsicCheck(D),
MatchCheck(D),
MirMapConstruction(D),
MirPass(D),
MirTypeck(D),

// Represents the MIR for a fn; also used as the task node for
// things read/modify that MIR.
Mir(D),

BorrowCheck(D),
RvalueCheck(D),
Reachability,
Expand Down Expand Up @@ -214,9 +216,7 @@ impl<D: Clone + Debug> DepNode<D> {
CheckConst(ref d) => op(d).map(CheckConst),
IntrinsicCheck(ref d) => op(d).map(IntrinsicCheck),
MatchCheck(ref d) => op(d).map(MatchCheck),
MirMapConstruction(ref d) => op(d).map(MirMapConstruction),
MirPass(ref d) => op(d).map(MirPass),
MirTypeck(ref d) => op(d).map(MirTypeck),
Mir(ref d) => op(d).map(Mir),
BorrowCheck(ref d) => op(d).map(BorrowCheck),
RvalueCheck(ref d) => op(d).map(RvalueCheck),
TransCrateItem(ref d) => op(d).map(TransCrateItem),
Expand Down
10 changes: 10 additions & 0 deletions src/librustc/dep_graph/dep_tracking_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ impl<M: DepTrackingMapConfig> DepTrackingMap<M> {
self.map.get(k)
}

pub fn get_mut(&mut self, k: &M::Key) -> Option<&mut M::Value> {
self.read(k);
self.write(k);
self.map.get_mut(k)
}

pub fn insert(&mut self, k: M::Key, v: M::Value) -> Option<M::Value> {
self.write(&k);
self.map.insert(k, v)
Expand All @@ -70,6 +76,10 @@ impl<M: DepTrackingMapConfig> DepTrackingMap<M> {
self.read(k);
self.map.contains_key(k)
}

pub fn keys(&self) -> Vec<M::Key> {
self.map.keys().cloned().collect()
}
}

impl<M: DepTrackingMapConfig> MemoizationMap for RefCell<DepTrackingMap<M>> {
Expand Down
26 changes: 24 additions & 2 deletions src/librustc/mir/mir_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,31 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use util::nodemap::NodeMap;
use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig};
use hir::def_id::DefId;
use mir::repr::Mir;
use std::marker::PhantomData;

pub struct MirMap<'tcx> {
pub map: NodeMap<Mir<'tcx>>,
pub map: DepTrackingMap<MirMapConfig<'tcx>>,
}

impl<'tcx> MirMap<'tcx> {
pub fn new(graph: DepGraph) -> Self {
MirMap {
map: DepTrackingMap::new(graph)
}
}
}

pub struct MirMapConfig<'tcx> {
data: PhantomData<&'tcx ()>
}

impl<'tcx> DepTrackingMapConfig for MirMapConfig<'tcx> {
type Key = DefId;
type Value = Mir<'tcx>;
fn to_dep_node(key: &DefId) -> DepNode<DefId> {
DepNode::Mir(*key)
}
}
13 changes: 5 additions & 8 deletions src/librustc/mir/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use dep_graph::DepNode;
use hir;
use hir::map::DefPathData;
use hir::def_id::DefId;
use mir::mir_map::MirMap;
use mir::repr::{Mir, Promoted};
use ty::TyCtxt;
Expand Down Expand Up @@ -73,9 +72,6 @@ impl<'a, 'tcx> MirSource {
/// Various information about pass.
pub trait Pass {
// fn should_run(Session) to check if pass should run?
fn dep_node(&self, def_id: DefId) -> DepNode<DefId> {
DepNode::MirPass(def_id)
}
fn name(&self) -> &str {
let name = unsafe { ::std::intrinsics::type_name::<Self>() };
if let Some(tail) = name.rfind(":") {
Expand Down Expand Up @@ -119,10 +115,11 @@ impl<'tcx, T: MirPass<'tcx>> MirMapPass<'tcx> for T {
map: &mut MirMap<'tcx>,
hooks: &mut [Box<for<'s> MirPassHook<'s>>])
{
for (&id, mir) in &mut map.map {
let def_id = tcx.map.local_def_id(id);
let _task = tcx.dep_graph.in_task(self.dep_node(def_id));

let def_ids = map.map.keys();
for def_id in def_ids {
let _task = tcx.dep_graph.in_task(DepNode::Mir(def_id));
let mir = map.map.get_mut(&def_id).unwrap();
let id = tcx.map.as_local_node_id(def_id).unwrap();
let src = MirSource::from_node(tcx, id);

for hook in &mut *hooks {
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
attributes: &[ast::Attribute]) {
debug!("borrowck_fn(id={})", id);

let def_id = this.tcx.map.local_def_id(id);

if attributes.iter().any(|item| item.check_name("rustc_mir_borrowck")) {
let mir = this.mir_map.unwrap().map.get(&id).unwrap();
let mir = this.mir_map.unwrap().map.get(&def_id).unwrap();
this.with_temp_region_map(id, |this| {
mir::borrowck_mir(this, fk, decl, mir, body, sp, id, attributes)
});
Expand Down
18 changes: 11 additions & 7 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,20 +956,24 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
PpmMir | PpmMirCFG => {
if let Some(mir_map) = mir_map {
if let Some(nodeid) = nodeid {
let mir = mir_map.map.get(&nodeid).unwrap_or_else(|| {
sess.fatal(&format!("no MIR map entry for node {}", nodeid))
});
let def_id = tcx.map.local_def_id(nodeid);
match ppm {
PpmMir => write_mir_pretty(tcx, iter::once((&nodeid, mir)), &mut out),
PpmMir => write_mir_pretty(tcx, iter::once(def_id), &mir_map, &mut out),
PpmMirCFG => {
write_mir_graphviz(tcx, iter::once((&nodeid, mir)), &mut out)
write_mir_graphviz(tcx, iter::once(def_id), &mir_map, &mut out)
}
_ => unreachable!(),
}?;
} else {
match ppm {
PpmMir => write_mir_pretty(tcx, mir_map.map.iter(), &mut out),
PpmMirCFG => write_mir_graphviz(tcx, mir_map.map.iter(), &mut out),
PpmMir => write_mir_pretty(tcx,
mir_map.map.keys().into_iter(),
&mir_map,
&mut out),
PpmMirCFG => write_mir_graphviz(tcx,
mir_map.map.keys().into_iter(),
&mir_map,
&mut out),
_ => unreachable!(),
}?;
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,8 @@ fn encode_repr_attrs(rbml_w: &mut Encoder,
}

fn encode_mir(ecx: &EncodeContext, rbml_w: &mut Encoder, node_id: NodeId) {
if let Some(mir) = ecx.mir_map.map.get(&node_id) {
let def_id = ecx.tcx.map.local_def_id(node_id);
if let Some(mir) = ecx.mir_map.map.get(&def_id) {
rbml_w.start_tag(tag_mir as usize);
rbml_w.emit_opaque(|opaque_encoder| {
tls::enter_encoding_context(ecx, opaque_encoder, |_, opaque_encoder| {
Expand Down Expand Up @@ -1361,7 +1362,7 @@ fn my_visit_expr(expr: &hir::Expr,
ecx.tcx.closure_kind(def_id).encode(rbml_w).unwrap();
rbml_w.end_tag();

assert!(ecx.mir_map.map.contains_key(&expr.id));
assert!(ecx.mir_map.map.contains_key(&def_id));
encode_mir(ecx, rbml_w, expr.id);

rbml_w.end_tag();
Expand Down
14 changes: 11 additions & 3 deletions src/librustc_mir/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
// except according to those terms.

use dot;
use rustc::hir::def_id::DefId;
use rustc::mir::repr::*;
use rustc::mir::mir_map::MirMap;
use rustc::ty::{self, TyCtxt};
use std::fmt::Debug;
use std::io::{self, Write};
Expand All @@ -19,10 +21,16 @@ use rustc_data_structures::indexed_vec::Idx;

/// Write a graphviz DOT graph of a list of MIRs.
pub fn write_mir_graphviz<'a, 'b, 'tcx, W, I>(tcx: TyCtxt<'b, 'tcx, 'tcx>,
iter: I, w: &mut W)
iter: I,
mir_map: &MirMap<'tcx>,
w: &mut W)
-> io::Result<()>
where W: Write, I: Iterator<Item=(&'a NodeId, &'a Mir<'a>)> {
for (&nodeid, mir) in iter {
where W: Write, I: Iterator<Item=DefId>
{
for def_id in iter {
let nodeid = tcx.map.as_local_node_id(def_id).unwrap();
let mir = &mir_map.map[&def_id];

writeln!(w, "digraph Mir_{} {{", nodeid)?;

// Global graph properties
Expand Down
13 changes: 12 additions & 1 deletion src/librustc_mir/hair/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rustc::mir::transform::MirSource;
use rustc::middle::const_val::ConstVal;
use rustc_const_eval as const_eval;
use rustc_data_structures::indexed_vec::Idx;
use rustc::dep_graph::DepNode;
use rustc::hir::def_id::DefId;
use rustc::hir::intravisit::FnKind;
use rustc::hir::map::blocks::FnLikeNode;
Expand Down Expand Up @@ -61,7 +62,17 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
MirSource::Promoted(..) => bug!()
};

let attrs = infcx.tcx.map.attrs(src.item_id());
let src_node_id = src.item_id();

// We are going to be accessing various tables
// generated by TypeckItemBody; we also assume
// that the body passes type check. These tables
// are not individually tracked, so just register
// a read here.
let src_def_id = infcx.tcx.map.local_def_id(src_node_id);
infcx.tcx.dep_graph.read(DepNode::TypeckItemBody(src_def_id));

let attrs = infcx.tcx.map.attrs(src_node_id);

// Some functions always have overflow checks enabled,
// however, they may not get codegen'd, depending on
Expand Down
13 changes: 7 additions & 6 deletions src/librustc_mir/mir_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use build;
use rustc::dep_graph::DepNode;
use rustc::hir::def_id::DefId;
use rustc::mir::repr::Mir;
use rustc::mir::transform::MirSource;
use rustc::mir::visit::MutVisitor;
Expand All @@ -29,7 +30,6 @@ use rustc::infer::InferCtxtBuilder;
use rustc::traits::ProjectionMode;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::subst::Substs;
use rustc::util::nodemap::NodeMap;
use rustc::hir;
use rustc::hir::intravisit::{self, FnKind, Visitor};
use syntax::ast;
Expand All @@ -38,15 +38,13 @@ use syntax_pos::Span;
use std::mem;

pub fn build_mir_for_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> MirMap<'tcx> {
let mut map = MirMap {
map: NodeMap(),
};
let mut map = MirMap::new(tcx.dep_graph.clone());
{
let mut dump = BuildMir {
tcx: tcx,
map: &mut map,
};
tcx.visit_all_items_in_krate(DepNode::MirMapConstruction, &mut dump);
tcx.visit_all_items_in_krate(DepNode::Mir, &mut dump);
}
map
}
Expand Down Expand Up @@ -94,16 +92,19 @@ struct BuildMir<'a, 'tcx: 'a> {
/// F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(Cx<'b, 'gcx, 'tcx>).
struct CxBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
src: MirSource,
def_id: DefId,
infcx: InferCtxtBuilder<'a, 'gcx, 'tcx>,
map: &'a mut MirMap<'gcx>,
}

impl<'a, 'gcx, 'tcx> BuildMir<'a, 'gcx> {
fn cx<'b>(&'b mut self, src: MirSource) -> CxBuilder<'b, 'gcx, 'tcx> {
let param_env = ty::ParameterEnvironment::for_item(self.tcx, src.item_id());
let def_id = self.tcx.map.local_def_id(src.item_id());
CxBuilder {
src: src,
infcx: self.tcx.infer_ctxt(None, Some(param_env), ProjectionMode::AnyFinal),
def_id: def_id,
map: self.map
}
}
Expand Down Expand Up @@ -133,7 +134,7 @@ impl<'a, 'gcx, 'tcx> CxBuilder<'a, 'gcx, 'tcx> {
mir
});

assert!(self.map.map.insert(src.item_id(), mir).is_none())
assert!(self.map.map.insert(self.def_id, mir).is_none())
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/librustc_mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

use build::{Location, ScopeAuxiliaryVec, ScopeId};
use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::mir::repr::*;
use rustc::mir::mir_map::MirMap;
use rustc::mir::transform::MirSource;
use rustc::ty::{self, TyCtxt};
use rustc_data_structures::fnv::FnvHashMap;
use rustc_data_structures::indexed_vec::{Idx};
use std::fmt::Display;
use std::fs;
use std::io::{self, Write};
use syntax::ast::NodeId;
use std::path::{PathBuf, Path};

const INDENT: &'static str = " ";
Expand Down Expand Up @@ -89,19 +90,23 @@ pub fn dump_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
/// Write out a human-readable textual representation for the given MIR.
pub fn write_mir_pretty<'a, 'b, 'tcx, I>(tcx: TyCtxt<'b, 'tcx, 'tcx>,
iter: I,
mir_map: &MirMap<'tcx>,
w: &mut Write)
-> io::Result<()>
where I: Iterator<Item=(&'a NodeId, &'a Mir<'tcx>)>, 'tcx: 'a
where I: Iterator<Item=DefId>, 'tcx: 'a
{
let mut first = true;
for (&id, mir) in iter {
for def_id in iter {
let mir = &mir_map.map[&def_id];

if first {
first = false;
} else {
// Put empty lines between all items
writeln!(w, "")?;
}

let id = tcx.map.as_local_node_id(def_id).unwrap();
let src = MirSource::from_node(tcx, id);
write_mir_fn(tcx, src, mir, w, None)?;

Expand Down
19 changes: 11 additions & 8 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use rustc_data_structures::bitvec::BitVector;
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
use rustc::dep_graph::DepNode;
use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::hir::intravisit::FnKind;
Expand Down Expand Up @@ -881,8 +882,8 @@ fn qualify_const_item_cached<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

let extern_mir;
let param_env_and_mir = if def_id.is_local() {
let node_id = tcx.map.as_local_node_id(def_id).unwrap();
mir_map.and_then(|map| map.map.get(&node_id)).map(|mir| {
mir_map.and_then(|map| map.map.get(&def_id)).map(|mir| {
let node_id = tcx.map.as_local_node_id(def_id).unwrap();
(ty::ParameterEnvironment::for_item(tcx, node_id), mir)
})
} else if let Some(mir) = tcx.sess.cstore.maybe_get_item_mir(tcx, def_id) {
Expand Down Expand Up @@ -917,9 +918,10 @@ impl<'tcx> MirMapPass<'tcx> for QualifyAndPromoteConstants {

// First, visit `const` items, potentially recursing, to get
// accurate MUTABLE_INTERIOR and NEEDS_DROP qualifications.
for &id in map.map.keys() {
let def_id = tcx.map.local_def_id(id);
let _task = tcx.dep_graph.in_task(self.dep_node(def_id));
let keys = map.map.keys();
for &def_id in &keys {
let _task = tcx.dep_graph.in_task(DepNode::Mir(def_id));
let id = tcx.map.as_local_node_id(def_id).unwrap();
let src = MirSource::from_node(tcx, id);
if let MirSource::Const(_) = src {
qualify_const_item_cached(tcx, &mut qualif_map, Some(map), def_id);
Expand All @@ -929,9 +931,9 @@ impl<'tcx> MirMapPass<'tcx> for QualifyAndPromoteConstants {
// Then, handle everything else, without recursing,
// as the MIR map is not shared, since promotion
// in functions (including `const fn`) mutates it.
for (&id, mir) in &mut map.map {
let def_id = tcx.map.local_def_id(id);
let _task = tcx.dep_graph.in_task(self.dep_node(def_id));
for &def_id in &keys {
let _task = tcx.dep_graph.in_task(DepNode::Mir(def_id));
let id = tcx.map.as_local_node_id(def_id).unwrap();
let src = MirSource::from_node(tcx, id);
let mode = match src {
MirSource::Fn(_) => {
Expand All @@ -948,6 +950,7 @@ impl<'tcx> MirMapPass<'tcx> for QualifyAndPromoteConstants {
};
let param_env = ty::ParameterEnvironment::for_item(tcx, id);

let mir = map.map.get_mut(&def_id).unwrap();
for hook in &mut *hooks {
hook.on_mir_pass(tcx, src, mir, self, false);
}
Expand Down
Loading