Skip to content
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

run rustfmt on librustc_incremental folder #37346

Closed
wants to merge 1 commit into from
Closed
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
128 changes: 63 additions & 65 deletions src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ pub fn assert_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {

// Find annotations supplied by user (if any).
let (if_this_changed, then_this_would_need) = {
let mut visitor = IfThisChanged { tcx: tcx,
if_this_changed: vec![],
then_this_would_need: vec![] };
let mut visitor = IfThisChanged {
tcx: tcx,
if_this_changed: vec![],
then_this_would_need: vec![],
};
visitor.process_attrs(ast::CRATE_NODE_ID, &tcx.map.krate().attrs);
tcx.map.krate().visit_all_items(&mut visitor);
(visitor.if_this_changed, visitor.then_this_would_need)
Expand All @@ -89,7 +91,8 @@ pub fn assert_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
assert!(tcx.sess.opts.debugging_opts.query_dep_graph,
"cannot use the `#[{}]` or `#[{}]` annotations \
without supplying `-Z query-dep-graph`",
ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED);
ATTR_IF_THIS_CHANGED,
ATTR_THEN_THIS_WOULD_NEED);
}

// Check paths.
Expand All @@ -99,7 +102,7 @@ pub fn assert_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
type Sources = Vec<(Span, DefId, DepNode<DefId>)>;
type Targets = Vec<(Span, InternedString, ast::NodeId, DepNode<DefId>)>;

struct IfThisChanged<'a, 'tcx:'a> {
struct IfThisChanged<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
if_this_changed: Sources,
then_this_would_need: Targets,
Expand Down Expand Up @@ -153,15 +156,11 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> {
}
}
None => {
self.tcx.sess.span_fatal(
attr.span,
&format!("missing DepNode variant"));
self.tcx.sess.span_fatal(attr.span, &format!("missing DepNode variant"));
}
};
self.then_this_would_need.push((attr.span,
dep_node_interned.clone().unwrap(),
node_id,
dep_node));
self.then_this_would_need
.push((attr.span, dep_node_interned.clone().unwrap(), node_id, dep_node));
}
}
}
Expand All @@ -175,14 +174,12 @@ impl<'a, 'tcx> Visitor<'tcx> for IfThisChanged<'a, 'tcx> {

fn check_paths<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if_this_changed: &Sources,
then_this_would_need: &Targets)
{
then_this_would_need: &Targets) {
// Return early here so as not to construct the query, which is not cheap.
if if_this_changed.is_empty() {
for &(target_span, _, _, _) in then_this_would_need {
tcx.sess.span_err(
target_span,
&format!("no #[rustc_if_this_changed] annotation detected"));
tcx.sess.span_err(target_span,
&format!("no #[rustc_if_this_changed] annotation detected"));

}
return;
Expand All @@ -192,15 +189,12 @@ fn check_paths<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let dependents = query.transitive_successors(source_dep_node);
for &(target_span, ref target_pass, _, ref target_dep_node) in then_this_would_need {
if !dependents.contains(&target_dep_node) {
tcx.sess.span_err(
target_span,
&format!("no path from `{}` to `{}`",
tcx.item_path_str(source_def_id),
target_pass));
tcx.sess.span_err(target_span,
&format!("no path from `{}` to `{}`",
tcx.item_path_str(source_def_id),
target_pass));
} else {
tcx.sess.span_err(
target_span,
&format!("OK"));
tcx.sess.span_err(target_span, &format!("OK"));
}
}
}
Expand All @@ -213,30 +207,31 @@ fn dump_graph(tcx: TyCtxt) {
let nodes = match env::var("RUST_DEP_GRAPH_FILTER") {
Ok(string) => {
// Expect one of: "-> target", "source -> target", or "source ->".
let edge_filter = EdgeFilter::new(&string).unwrap_or_else(|e| {
bug!("invalid filter: {}", e)
});
let edge_filter = EdgeFilter::new(&string)
.unwrap_or_else(|e| bug!("invalid filter: {}", e));
let sources = node_set(&query, &edge_filter.source);
let targets = node_set(&query, &edge_filter.target);
filter_nodes(&query, &sources, &targets)
}
Err(_) => {
query.nodes()
.into_iter()
.collect()
.into_iter()
.collect()
}
};
let edges = filter_edges(&query, &nodes);

{ // dump a .txt file with just the edges:
{
// dump a .txt file with just the edges:
let txt_path = format!("{}.txt", path);
let mut file = File::create(&txt_path).unwrap();
for &(ref source, ref target) in &edges {
write!(file, "{:?} -> {:?}\n", source, target).unwrap();
}
}

{ // dump a .dot file in graphviz format:
{
// dump a .dot file in graphviz format:
let dot_path = format!("{}.dot", path);
let mut v = Vec::new();
dot::render(&GraphvizDepGraph(nodes, edges), &mut v).unwrap();
Expand Down Expand Up @@ -272,10 +267,14 @@ impl<'a, 'tcx, 'q> dot::Labeller<'a> for GraphvizDepGraph<'q> {
dot::Id::new("DependencyGraph").unwrap()
}
fn node_id(&self, n: &&'q DepNode<DefId>) -> dot::Id {
let s: String =
format!("{:?}", n).chars()
.map(|c| if c == '_' || c.is_alphanumeric() { c } else { '_' })
.collect();
let s: String = format!("{:?}", n)
.chars()
.map(|c| if c == '_' || c.is_alphanumeric() {
c
} else {
'_'
})
.collect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nrc @ubsan This looks harder to read.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is probably the trickiest corner of formatting at the moment - I prefer visual indent for method chains, but it makes closures either ugly or subject to extreme rightward drift.

debug!("n={:?} s={:?}", n, s);
dot::Id::new(s).unwrap()
}
Expand All @@ -287,9 +286,9 @@ impl<'a, 'tcx, 'q> dot::Labeller<'a> for GraphvizDepGraph<'q> {
// Given an optional filter like `"x,y,z"`, returns either `None` (no
// filter) or the set of nodes whose labels contain all of those
// substrings.
fn node_set<'q>(query: &'q DepGraphQuery<DefId>, filter: &DepNodeFilter)
-> Option<FnvHashSet<&'q DepNode<DefId>>>
{
fn node_set<'q>(query: &'q DepGraphQuery<DefId>,
filter: &DepNodeFilter)
-> Option<FnvHashSet<&'q DepNode<DefId>>> {
debug!("node_set(filter={:?})", filter);

if filter.accepts_all() {
Expand All @@ -302,8 +301,7 @@ fn node_set<'q>(query: &'q DepGraphQuery<DefId>, filter: &DepNodeFilter)
fn filter_nodes<'q>(query: &'q DepGraphQuery<DefId>,
sources: &Option<FnvHashSet<&'q DepNode<DefId>>>,
targets: &Option<FnvHashSet<&'q DepNode<DefId>>>)
-> FnvHashSet<&'q DepNode<DefId>>
{
-> FnvHashSet<&'q DepNode<DefId>> {
if let &Some(ref sources) = sources {
if let &Some(ref targets) = targets {
walk_between(query, sources, targets)
Expand All @@ -320,11 +318,12 @@ fn filter_nodes<'q>(query: &'q DepGraphQuery<DefId>,
fn walk_nodes<'q>(query: &'q DepGraphQuery<DefId>,
starts: &FnvHashSet<&'q DepNode<DefId>>,
direction: Direction)
-> FnvHashSet<&'q DepNode<DefId>>
{
-> FnvHashSet<&'q DepNode<DefId>> {
let mut set = FnvHashSet();
for &start in starts {
debug!("walk_nodes: start={:?} outgoing?={:?}", start, direction == OUTGOING);
debug!("walk_nodes: start={:?} outgoing?={:?}",
start,
direction == OUTGOING);
if set.insert(start) {
let mut stack = vec![query.indices[start]];
while let Some(index) = stack.pop() {
Expand All @@ -344,15 +343,19 @@ fn walk_nodes<'q>(query: &'q DepGraphQuery<DefId>,
fn walk_between<'q>(query: &'q DepGraphQuery<DefId>,
sources: &FnvHashSet<&'q DepNode<DefId>>,
targets: &FnvHashSet<&'q DepNode<DefId>>)
-> FnvHashSet<&'q DepNode<DefId>>
{
-> FnvHashSet<&'q DepNode<DefId>> {
// This is a bit tricky. We want to include a node only if it is:
// (a) reachable from a source and (b) will reach a target. And we
// have to be careful about cycles etc. Luckily efficiency is not
// a big concern!

#[derive(Copy, Clone, PartialEq)]
enum State { Undecided, Deciding, Included, Excluded }
enum State {
Undecided,
Deciding,
Included,
Excluded,
}

let mut node_states = vec![State::Undecided; query.graph.len_nodes()];

Expand All @@ -365,18 +368,14 @@ fn walk_between<'q>(query: &'q DepGraphQuery<DefId>,
}

return query.nodes()
.into_iter()
.filter(|&n| {
let index = query.indices[n];
node_states[index.0] == State::Included
})
.collect();

fn recurse(query: &DepGraphQuery<DefId>,
node_states: &mut [State],
node: NodeIndex)
-> bool
{
.into_iter()
.filter(|&n| {
let index = query.indices[n];
node_states[index.0] == State::Included
})
.collect();

fn recurse(query: &DepGraphQuery<DefId>, node_states: &mut [State], node: NodeIndex) -> bool {
match node_states[node.0] {
// known to reach a target
State::Included => return true,
Expand All @@ -387,7 +386,7 @@ fn walk_between<'q>(query: &'q DepGraphQuery<DefId>,
// backedge, not yet known, say false
State::Deciding => return false,

State::Undecided => { }
State::Undecided => {}
}

node_states[node.0] = State::Deciding;
Expand All @@ -411,10 +410,9 @@ fn walk_between<'q>(query: &'q DepGraphQuery<DefId>,

fn filter_edges<'q>(query: &'q DepGraphQuery<DefId>,
nodes: &FnvHashSet<&'q DepNode<DefId>>)
-> Vec<(&'q DepNode<DefId>, &'q DepNode<DefId>)>
{
-> Vec<(&'q DepNode<DefId>, &'q DepNode<DefId>)> {
query.edges()
.into_iter()
.filter(|&(source, target)| nodes.contains(source) && nodes.contains(target))
.collect()
.into_iter()
.filter(|&(source, target)| nodes.contains(source) && nodes.contains(target))
.collect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'tcx> CachingCodemapView<'tcx> {

// No cache hit ...
let mut oldest = 0;
for index in 1 .. self.line_cache.len() {
for index in 1..self.line_cache.len() {
if self.line_cache[index].time_stamp < self.line_cache[oldest].time_stamp {
oldest = index;
}
Expand Down
13 changes: 7 additions & 6 deletions src/librustc_incremental/calculate_svh/def_path_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ impl<'a, 'tcx> DefPathHashes<'a, 'tcx> {
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
DefPathHashes {
tcx: tcx,
data: DefIdMap()
data: DefIdMap(),
}
}

pub fn hash(&mut self, def_id: DefId) -> u64 {
let tcx = self.tcx;
*self.data.entry(def_id)
.or_insert_with(|| {
let def_path = tcx.def_path(def_id);
def_path.deterministic_hash(tcx)
})
*self.data
.entry(def_id)
.or_insert_with(|| {
let def_path = tcx.def_path(def_id);
def_path.deterministic_hash(tcx)
})
}
}
2 changes: 1 addition & 1 deletion src/librustc_incremental/calculate_svh/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl IchHasher {
let hash_size = mem::size_of::<Fingerprint>();
IchHasher {
state: ArchIndependentHasher::new(Blake2bHasher::new(hash_size, &[])),
bytes_hashed: 0
bytes_hashed: 0,
}
}

Expand Down
35 changes: 18 additions & 17 deletions src/librustc_incremental/calculate_svh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)

tcx.sess.perf_stats.incr_comp_hashes_count.set(visitor.hashes.len() as u64);

record_time(&tcx.sess.perf_stats.svh_time, || visitor.compute_crate_hash());
record_time(&tcx.sess.perf_stats.svh_time,
|| visitor.compute_crate_hash());
visitor.hashes
}

Expand Down Expand Up @@ -146,10 +147,11 @@ impl<'a, 'tcx> HashItemsVisitor<'a, 'tcx> {
let bytes_hashed = state.bytes_hashed();
let item_hash = state.finish();
self.hashes.insert(DepNode::Hir(def_id), item_hash);
debug!("calculate_item_hash: def_id={:?} hash={:?}", def_id, item_hash);
debug!("calculate_item_hash: def_id={:?} hash={:?}",
def_id,
item_hash);

let bytes_hashed = self.tcx.sess.perf_stats.incr_comp_bytes_hashed.get() +
bytes_hashed;
let bytes_hashed = self.tcx.sess.perf_stats.incr_comp_bytes_hashed.get() + bytes_hashed;
self.tcx.sess.perf_stats.incr_comp_bytes_hashed.set(bytes_hashed);
}

Expand All @@ -167,18 +169,18 @@ impl<'a, 'tcx> HashItemsVisitor<'a, 'tcx> {
// crate hash.
{
let def_path_hashes = &mut self.def_path_hashes;
let mut item_hashes: Vec<_> =
self.hashes.iter()
.map(|(item_dep_node, &item_hash)| {
// convert from a DepNode<DefId> tp a
// DepNode<u64> where the u64 is the
// hash of the def-id's def-path:
let item_dep_node =
item_dep_node.map_def(|&did| Some(def_path_hashes.hash(did)))
.unwrap();
(item_dep_node, item_hash)
})
.collect();
let mut item_hashes: Vec<_> = self.hashes
.iter()
.map(|(item_dep_node, &item_hash)| {
// convert from a DepNode<DefId> tp a
// DepNode<u64> where the u64 is the
// hash of the def-id's def-path:
let item_dep_node =
item_dep_node.map_def(|&did| Some(def_path_hashes.hash(did)))
.unwrap();
(item_dep_node, item_hash)
})
.collect();
item_hashes.sort(); // avoid artificial dependencies on item ordering
item_hashes.hash(&mut crate_state);
}
Expand Down Expand Up @@ -210,4 +212,3 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for HashItemsVisitor<'a, 'tcx> {
visit::walk_foreign_item(self, item);
}
}

Loading