Skip to content

Commit 6483bdd

Browse files
committed
Auto merge of rust-lang#38243 - michaelwoerister:fix-debuginfo-namespace-edge, r=nikomatsakis
incr.comp.: Avoid creating an edge to DepNode::Krate when generating debuginfo namespaces. r? @nikomatsakis Fixes rust-lang#38222
2 parents b4b1e5e + 271fb22 commit 6483bdd

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

src/librustc/hir/map/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,9 @@ impl<'ast> Map<'ast> {
310310
id = p;
311311
}
312312

313-
RootCrate =>
314-
return DepNode::Krate,
313+
RootCrate => {
314+
return DepNode::Hir(DefId::local(CRATE_DEF_INDEX));
315+
}
315316

316317
RootInlinedParent(_) =>
317318
bug!("node {} has inlined ancestor but is not inlined", id0),
@@ -782,7 +783,7 @@ impl<'ast> Map<'ast> {
782783
Some(EntryVisibility(_, &Visibility::Restricted { ref path, .. })) => path.span,
783784
Some(EntryVisibility(_, v)) => bug!("unexpected Visibility {:?}", v),
784785

785-
Some(RootCrate) => self.krate().span,
786+
Some(RootCrate) => self.forest.krate.span,
786787
Some(RootInlinedParent(parent)) => parent.body.span,
787788
Some(NotPresent) | None => {
788789
bug!("hir::map::Map::span: id not in map: {:?}", id)

src/librustc_incremental/calculate_svh/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
112112
hash_spans: hash_spans,
113113
};
114114
record_time(&tcx.sess.perf_stats.incr_comp_hashes_time, || {
115-
visitor.calculate_def_id(DefId::local(CRATE_DEF_INDEX),
116-
|v| visit::walk_crate(v, krate));
115+
visitor.calculate_def_id(DefId::local(CRATE_DEF_INDEX), |v| {
116+
v.hash_crate_root_module(krate);
117+
});
117118
krate.visit_all_item_likes(&mut visitor.as_deep_visitor());
118119

119120
for macro_def in krate.exported_macros.iter() {

src/librustc_incremental/calculate_svh/svh_visitor.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,10 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has
619619
visit::walk_item(self, i)
620620
}
621621

622-
fn visit_mod(&mut self, m: &'tcx Mod, _s: Span, n: NodeId) {
622+
fn visit_mod(&mut self, m: &'tcx Mod, span: Span, n: NodeId) {
623623
debug!("visit_mod: st={:?}", self.st);
624624
SawMod.hash(self.st);
625+
hash_span!(self, span);
625626
visit::walk_mod(self, m, n)
626627
}
627628

@@ -1085,4 +1086,23 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
10851086
token::Token::Shebang(val) => val.as_str().hash(self.st),
10861087
}
10871088
}
1089+
1090+
pub fn hash_crate_root_module(&mut self, krate: &'tcx Crate) {
1091+
let hir::Crate {
1092+
ref module,
1093+
ref attrs,
1094+
span,
1095+
1096+
// These fields are handled separately:
1097+
exported_macros: _,
1098+
items: _,
1099+
impl_items: _,
1100+
exprs: _,
1101+
} = *krate;
1102+
1103+
visit::Visitor::visit_mod(self, module, span, ast::CRATE_NODE_ID);
1104+
// Crate attributes are not copied over to the root `Mod`, so hash them
1105+
// explicitly here.
1106+
hash_attrs!(self, attrs);
1107+
}
10881108
}

src/test/incremental/issue-38222.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
// Test that debuginfo does not introduce a dependency edge to the Krate
12+
// dep-node.
13+
14+
// revisions:rpass1 rpass2
15+
16+
#![feature(rustc_attrs)]
17+
18+
19+
#![rustc_partition_translated(module="issue_38222-mod1", cfg="rpass2")]
20+
21+
// If trans had added a dependency edge to the Krate dep-node, nothing would
22+
// be re-used, so checking that this module was re-used is sufficient.
23+
#![rustc_partition_reused(module="issue_38222", cfg="rpass2")]
24+
25+
//[rpass1] compile-flags: -C debuginfo=1
26+
//[rpass2] compile-flags: -C debuginfo=1
27+
28+
pub fn main() {
29+
mod1::some_fn();
30+
}
31+
32+
mod mod1 {
33+
pub fn some_fn() {
34+
let _ = 1;
35+
}
36+
37+
#[cfg(rpass2)]
38+
fn _some_other_fn() {
39+
}
40+
}

0 commit comments

Comments
 (0)