Skip to content

Commit 8bba5ad

Browse files
committed
Auto merge of #43107 - michaelwoerister:less-span-info-in-debug, r=nikomatsakis
incr.comp.: Don't include span information in the ICH of type definitions This should improve some of the `regex` tests on perf.rlo. Not including spans into the ICH is harmless until we also cache warnings. To really solve the problem, we need to do more refactoring (see #43088). r? @nikomatsakis
2 parents 8ac29bd + bca8570 commit 8bba5ad

File tree

5 files changed

+101
-47
lines changed

5 files changed

+101
-47
lines changed

src/librustc/ich/impls_hir.rs

+24-19
Original file line numberDiff line numberDiff line change
@@ -895,25 +895,28 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::I
895895
fn hash_stable<W: StableHasherResult>(&self,
896896
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
897897
hasher: &mut StableHasher<W>) {
898-
let node_id_hashing_mode = match self.node {
899-
hir::ItemExternCrate(..) |
898+
let (node_id_hashing_mode, hash_spans) = match self.node {
900899
hir::ItemStatic(..) |
901900
hir::ItemConst(..) |
902-
hir::ItemFn(..) |
903-
hir::ItemMod(..) |
901+
hir::ItemFn(..) => {
902+
(NodeIdHashingMode::Ignore, hcx.hash_spans())
903+
}
904+
hir::ItemUse(..) => {
905+
(NodeIdHashingMode::HashTraitsInScope, false)
906+
}
907+
908+
hir::ItemExternCrate(..) |
904909
hir::ItemForeignMod(..) |
905910
hir::ItemGlobalAsm(..) |
911+
hir::ItemMod(..) |
912+
hir::ItemDefaultImpl(..) |
913+
hir::ItemTrait(..) |
914+
hir::ItemImpl(..) |
906915
hir::ItemTy(..) |
907916
hir::ItemEnum(..) |
908917
hir::ItemStruct(..) |
909-
hir::ItemUnion(..) |
910-
hir::ItemTrait(..) |
911-
hir::ItemDefaultImpl(..) |
912-
hir::ItemImpl(..) => {
913-
NodeIdHashingMode::Ignore
914-
}
915-
hir::ItemUse(..) => {
916-
NodeIdHashingMode::HashTraitsInScope
918+
hir::ItemUnion(..) => {
919+
(NodeIdHashingMode::Ignore, false)
917920
}
918921
};
919922

@@ -927,14 +930,16 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::I
927930
} = *self;
928931

929932
hcx.hash_hir_item_like(attrs, |hcx| {
930-
hcx.with_node_id_hashing_mode(node_id_hashing_mode, |hcx| {
931-
id.hash_stable(hcx, hasher);
933+
hcx.while_hashing_spans(hash_spans, |hcx| {
934+
hcx.with_node_id_hashing_mode(node_id_hashing_mode, |hcx| {
935+
id.hash_stable(hcx, hasher);
936+
});
937+
name.hash_stable(hcx, hasher);
938+
attrs.hash_stable(hcx, hasher);
939+
node.hash_stable(hcx, hasher);
940+
vis.hash_stable(hcx, hasher);
941+
span.hash_stable(hcx, hasher);
932942
});
933-
name.hash_stable(hcx, hasher);
934-
attrs.hash_stable(hcx, hasher);
935-
node.hash_stable(hcx, hasher);
936-
vis.hash_stable(hcx, hasher);
937-
span.hash_stable(hcx, hasher);
938943
});
939944
}
940945
}

src/librustc_trans/debuginfo/metadata.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use self::MemberDescriptionFactory::*;
1414
use self::EnumDiscriminantInfo::*;
1515

1616
use super::utils::{debug_context, DIB, span_start, bytes_to_bits, size_and_align_of,
17-
get_namespace_and_span_for_item, create_DIArray, is_node_local_to_unit};
17+
get_namespace_for_item, create_DIArray, is_node_local_to_unit};
1818
use super::namespace::mangled_name_of_item;
1919
use super::type_names::compute_debuginfo_type_name;
2020
use super::{CrateDebugContext};
@@ -421,7 +421,7 @@ fn trait_pointer_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
421421
let containing_scope = match trait_type.sty {
422422
ty::TyDynamic(ref data, ..) => if let Some(principal) = data.principal() {
423423
let def_id = principal.def_id();
424-
get_namespace_and_span_for_item(cx, def_id).0
424+
get_namespace_for_item(cx, def_id)
425425
} else {
426426
NO_SCOPE_METADATA
427427
},
@@ -971,7 +971,7 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
971971
_ => bug!("prepare_struct_metadata on a non-ADT")
972972
};
973973

974-
let (containing_scope, _) = get_namespace_and_span_for_item(cx, struct_def_id);
974+
let containing_scope = get_namespace_for_item(cx, struct_def_id);
975975

976976
let struct_metadata_stub = create_struct_stub(cx,
977977
struct_llvm_type,
@@ -1096,7 +1096,7 @@ fn prepare_union_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
10961096
_ => bug!("prepare_union_metadata on a non-ADT")
10971097
};
10981098

1099-
let (containing_scope, _) = get_namespace_and_span_for_item(cx, union_def_id);
1099+
let containing_scope = get_namespace_for_item(cx, union_def_id);
11001100

11011101
let union_metadata_stub = create_union_stub(cx,
11021102
union_llvm_type,
@@ -1483,7 +1483,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
14831483
-> RecursiveTypeDescription<'tcx> {
14841484
let enum_name = compute_debuginfo_type_name(cx, enum_type, false);
14851485

1486-
let (containing_scope, _) = get_namespace_and_span_for_item(cx, enum_def_id);
1486+
let containing_scope = get_namespace_for_item(cx, enum_def_id);
14871487
// FIXME: This should emit actual file metadata for the enum, but we
14881488
// currently can't get the necessary information when it comes to types
14891489
// imported from other crates. Formerly we violated the ODR when performing
@@ -1781,7 +1781,8 @@ pub fn create_global_var_metadata(cx: &CrateContext,
17811781
let tcx = cx.tcx();
17821782

17831783
let node_def_id = tcx.hir.local_def_id(node_id);
1784-
let (var_scope, span) = get_namespace_and_span_for_item(cx, node_def_id);
1784+
let var_scope = get_namespace_for_item(cx, node_def_id);
1785+
let span = cx.tcx().def_span(node_def_id);
17851786

17861787
let (file_metadata, line_number) = if span != syntax_pos::DUMMY_SP {
17871788
let loc = span_start(cx, span);

src/librustc_trans/debuginfo/namespace.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@
1010

1111
// Namespace Handling.
1212

13-
use super::metadata::{file_metadata, unknown_file_metadata, UNKNOWN_LINE_NUMBER};
14-
use super::utils::{DIB, debug_context, span_start};
13+
use super::metadata::{unknown_file_metadata, UNKNOWN_LINE_NUMBER};
14+
use super::utils::{DIB, debug_context};
1515

1616
use llvm;
1717
use llvm::debuginfo::DIScope;
1818
use rustc::hir::def_id::DefId;
1919
use rustc::hir::map::DefPathData;
2020
use common::CrateContext;
2121

22-
use libc::c_uint;
2322
use std::ffi::CString;
2423
use std::ptr;
25-
use syntax_pos::DUMMY_SP;
2624

2725
pub fn mangled_name_of_item(ccx: &CrateContext, def_id: DefId, extra: &str) -> String {
2826
fn fill_nested(ccx: &CrateContext, def_id: DefId, extra: &str, output: &mut String) {
@@ -69,21 +67,14 @@ pub fn item_namespace(ccx: &CrateContext, def_id: DefId) -> DIScope {
6967
};
7068

7169
let namespace_name = CString::new(namespace_name.as_bytes()).unwrap();
72-
let span = ccx.tcx().def_span(def_id);
73-
let (file, line) = if span != DUMMY_SP {
74-
let loc = span_start(ccx, span);
75-
(file_metadata(ccx, &loc.file.name, def_id.krate), loc.line as c_uint)
76-
} else {
77-
(unknown_file_metadata(ccx), UNKNOWN_LINE_NUMBER)
78-
};
7970

8071
let scope = unsafe {
8172
llvm::LLVMRustDIBuilderCreateNameSpace(
8273
DIB(ccx),
8374
parent_scope,
8475
namespace_name.as_ptr(),
85-
file,
86-
line as c_uint)
76+
unknown_file_metadata(ccx),
77+
UNKNOWN_LINE_NUMBER)
8778
};
8879

8980
debug_context(ccx).namespace_map.borrow_mut().insert(def_id, scope);

src/librustc_trans/debuginfo/utils.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ pub fn DIB(cx: &CrateContext) -> DIBuilderRef {
7373
cx.dbg_cx().as_ref().unwrap().builder
7474
}
7575

76-
pub fn get_namespace_and_span_for_item(cx: &CrateContext, def_id: DefId)
77-
-> (DIScope, Span) {
78-
let containing_scope = item_namespace(cx, cx.tcx().parent(def_id)
79-
.expect("get_namespace_and_span_for_item: missing parent?"));
80-
81-
// Try to get some span information, if we have an inlined item.
82-
let definition_span = cx.tcx().def_span(def_id);
83-
84-
(containing_scope, definition_span)
76+
pub fn get_namespace_for_item(cx: &CrateContext, def_id: DefId) -> DIScope {
77+
item_namespace(cx, cx.tcx().parent(def_id)
78+
.expect("get_namespace_for_item: missing parent?"))
8579
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2014 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 moving a type definition within a source file does not affect
12+
// re-compilation.
13+
14+
// revisions:rpass1 rpass2
15+
// compile-flags: -Z query-dep-graph -g
16+
17+
#![rustc_partition_reused(module="spans_in_type_debuginfo", cfg="rpass2")]
18+
#![rustc_partition_reused(module="spans_in_type_debuginfo-structs", cfg="rpass2")]
19+
#![rustc_partition_reused(module="spans_in_type_debuginfo-enums", cfg="rpass2")]
20+
21+
#![feature(rustc_attrs)]
22+
23+
mod structs {
24+
#[cfg(rpass1)]
25+
pub struct X {
26+
pub x: u32,
27+
}
28+
29+
#[cfg(rpass2)]
30+
pub struct X {
31+
pub x: u32,
32+
}
33+
34+
pub fn foo(x: X) -> u32 {
35+
x.x
36+
}
37+
}
38+
39+
mod enums {
40+
#[cfg(rpass1)]
41+
pub enum X {
42+
A { x: u32 },
43+
B(u32),
44+
}
45+
46+
#[cfg(rpass2)]
47+
pub enum X {
48+
A { x: u32 },
49+
B(u32),
50+
}
51+
52+
pub fn foo(x: X) -> u32 {
53+
match x {
54+
X::A { x } => x,
55+
X::B(x) => x,
56+
}
57+
}
58+
}
59+
60+
pub fn main() {
61+
let _ = structs::foo(structs::X { x: 1 });
62+
let _ = enums::foo(enums::X::A { x: 2 });
63+
}

0 commit comments

Comments
 (0)