Skip to content

Commit 7a14073

Browse files
committed
move def_id to new rustc_hir crate
1 parent 7eb7b23 commit 7a14073

File tree

8 files changed

+117
-20
lines changed

8 files changed

+117
-20
lines changed

Cargo.lock

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,7 @@ dependencies = [
30913091
"rustc_errors",
30923092
"rustc_feature",
30933093
"rustc_fs_util",
3094+
"rustc_hir",
30943095
"rustc_index",
30953096
"rustc_macros",
30963097
"rustc_session",
@@ -3563,6 +3564,42 @@ dependencies = [
35633564
name = "rustc_fs_util"
35643565
version = "0.0.0"
35653566

3567+
[[package]]
3568+
name = "rustc_hir"
3569+
version = "0.0.0"
3570+
dependencies = [
3571+
"arena",
3572+
"backtrace",
3573+
"bitflags",
3574+
"byteorder",
3575+
"chalk-engine",
3576+
"fmt_macros",
3577+
"graphviz",
3578+
"jobserver",
3579+
"log",
3580+
"measureme",
3581+
"num_cpus",
3582+
"parking_lot",
3583+
"polonius-engine",
3584+
"rustc-rayon",
3585+
"rustc-rayon-core",
3586+
"rustc_apfloat",
3587+
"rustc_data_structures",
3588+
"rustc_error_codes",
3589+
"rustc_errors",
3590+
"rustc_feature",
3591+
"rustc_fs_util",
3592+
"rustc_index",
3593+
"rustc_macros",
3594+
"rustc_session",
3595+
"rustc_span",
3596+
"rustc_target",
3597+
"scoped-tls",
3598+
"serialize",
3599+
"smallvec 1.0.0",
3600+
"syntax",
3601+
]
3602+
35663603
[[package]]
35673604
name = "rustc_incremental"
35683605
version = "0.0.0"
@@ -3603,6 +3640,7 @@ dependencies = [
36033640
"rustc_data_structures",
36043641
"rustc_errors",
36053642
"rustc_expand",
3643+
"rustc_hir",
36063644
"rustc_incremental",
36073645
"rustc_lint",
36083646
"rustc_metadata",

src/librustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rustc-rayon-core = "0.3.0"
2323
polonius-engine = "0.11.0"
2424
rustc_apfloat = { path = "../librustc_apfloat" }
2525
rustc_feature = { path = "../librustc_feature" }
26+
rustc_hir = { path = "../librustc_hir" }
2627
rustc_target = { path = "../librustc_target" }
2728
rustc_macros = { path = "../librustc_macros" }
2829
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc/hir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use syntax::util::parser::ExprPrecedence;
3434

3535
pub mod check_attr;
3636
pub mod def;
37-
pub mod def_id;
37+
pub use rustc_hir::def_id;
3838
pub mod intravisit;
3939
pub mod itemlikevisit;
4040
pub mod map;

src/librustc_hir/Cargo.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "rustc_hir"
4+
version = "0.0.0"
5+
edition = "2018"
6+
7+
[lib]
8+
name = "rustc_hir"
9+
path = "lib.rs"
10+
doctest = false
11+
12+
[dependencies]
13+
arena = { path = "../libarena" }
14+
bitflags = "1.2.1"
15+
fmt_macros = { path = "../libfmt_macros" }
16+
graphviz = { path = "../libgraphviz" }
17+
jobserver = "0.1"
18+
num_cpus = "1.0"
19+
scoped-tls = "1.0"
20+
log = { version = "0.4", features = ["release_max_level_info", "std"] }
21+
rustc-rayon = "0.3.0"
22+
rustc-rayon-core = "0.3.0"
23+
polonius-engine = "0.11.0"
24+
rustc_apfloat = { path = "../librustc_apfloat" }
25+
rustc_feature = { path = "../librustc_feature" }
26+
rustc_target = { path = "../librustc_target" }
27+
rustc_macros = { path = "../librustc_macros" }
28+
rustc_data_structures = { path = "../librustc_data_structures" }
29+
rustc_index = { path = "../librustc_index" }
30+
rustc_span = { path = "../librustc_span" }
31+
errors = { path = "../librustc_errors", package = "rustc_errors" }
32+
rustc_serialize = { path = "../libserialize", package = "serialize" }
33+
syntax = { path = "../libsyntax" }
34+
backtrace = "0.3.40"
35+
parking_lot = "0.9"
36+
byteorder = { version = "1.3" }
37+
chalk-engine = { version = "0.9.0", default-features=false }
38+
rustc_fs_util = { path = "../librustc_fs_util" }
39+
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
40+
measureme = "0.5"
41+
rustc_error_codes = { path = "../librustc_error_codes" }
42+
rustc_session = { path = "../librustc_session" }

src/librustc/hir/def_id.rs renamed to src/librustc_hir/def_id.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::ty;
1+
use rustc_data_structures::AtomicRef;
22
use rustc_index::vec::Idx;
33
use std::fmt;
44
use std::u32;
@@ -40,7 +40,7 @@ impl Idx for CrateNum {
4040
fn index(self) -> usize {
4141
match self {
4242
CrateNum::Index(idx) => Idx::index(idx),
43-
_ => bug!("Tried to get crate index of {:?}", self),
43+
_ => panic!("Tried to get crate index of {:?}", self),
4444
}
4545
}
4646
}
@@ -61,14 +61,14 @@ impl CrateNum {
6161
pub fn as_usize(self) -> usize {
6262
match self {
6363
CrateNum::Index(id) => id.as_usize(),
64-
_ => bug!("tried to get index of non-standard crate {:?}", self),
64+
_ => panic!("tried to get index of non-standard crate {:?}", self),
6565
}
6666
}
6767

6868
pub fn as_u32(self) -> u32 {
6969
match self {
7070
CrateNum::Index(id) => id.as_u32(),
71-
_ => bug!("tried to get index of non-standard crate {:?}", self),
71+
_ => panic!("tried to get index of non-standard crate {:?}", self),
7272
}
7373
}
7474

@@ -113,21 +113,6 @@ pub struct DefId {
113113
pub index: DefIndex,
114114
}
115115

116-
impl fmt::Debug for DefId {
117-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
118-
write!(f, "DefId({}:{}", self.krate, self.index.index())?;
119-
120-
ty::tls::with_opt(|opt_tcx| {
121-
if let Some(tcx) = opt_tcx {
122-
write!(f, " ~ {}", tcx.def_path_debug_str(*self))?;
123-
}
124-
Ok(())
125-
})?;
126-
127-
write!(f, ")")
128-
}
129-
}
130-
131116
impl DefId {
132117
/// Makes a local `DefId` from the given `DefIndex`.
133118
#[inline]
@@ -153,6 +138,19 @@ impl DefId {
153138
impl rustc_serialize::UseSpecializedEncodable for DefId {}
154139
impl rustc_serialize::UseSpecializedDecodable for DefId {}
155140

141+
pub fn default_def_id_debug(def_id: DefId, f: &mut fmt::Formatter<'_>) -> fmt::Result {
142+
f.debug_struct("DefId").field("krate", &def_id.krate).field("index", &def_id.index).finish()
143+
}
144+
145+
pub static DEF_ID_DEBUG: AtomicRef<fn(DefId, &mut fmt::Formatter<'_>) -> fmt::Result> =
146+
AtomicRef::new(&(default_def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
147+
148+
impl fmt::Debug for DefId {
149+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
150+
(*DEF_ID_DEBUG)(*self, f)
151+
}
152+
}
153+
156154
rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId);
157155

158156
/// A LocalDefId is equivalent to a DefId with `krate == LOCAL_CRATE`. Since

src/librustc_hir/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![feature(specialization)]
2+
3+
pub mod def_id;

src/librustc_interface/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
2727
rustc_codegen_ssa = { path = "../librustc_codegen_ssa" }
2828
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
2929
rustc_codegen_llvm = { path = "../librustc_codegen_llvm", optional = true }
30+
rustc_hir = { path = "../librustc_hir" }
3031
rustc_metadata = { path = "../librustc_metadata" }
3132
rustc_mir = { path = "../librustc_mir" }
3233
rustc_passes = { path = "../librustc_passes" }

src/librustc_interface/callbacks.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,23 @@ fn track_diagnostic(diagnostic: &Diagnostic) {
4040
})
4141
}
4242

43+
/// This is a callback from librustc_hir as it cannot access the implicit state
44+
/// in librustc otherwise.
45+
fn def_id_debug(def_id: rustc_hir::def_id::DefId, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46+
write!(f, "DefId({}:{}", def_id.krate, def_id.index.index())?;
47+
tls::with_opt(|opt_tcx| {
48+
if let Some(tcx) = opt_tcx {
49+
write!(f, " ~ {}", tcx.def_path_debug_str(def_id))?;
50+
}
51+
Ok(())
52+
})?;
53+
write!(f, ")")
54+
}
55+
4356
/// Sets up the callbacks in prior crates which we want to refer to the
4457
/// TyCtxt in.
4558
pub fn setup_callbacks() {
4659
rustc_span::SPAN_DEBUG.swap(&(span_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
60+
rustc_hir::def_id::DEF_ID_DEBUG.swap(&(def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
4761
TRACK_DIAGNOSTICS.swap(&(track_diagnostic as fn(&_)));
4862
}

0 commit comments

Comments
 (0)