move def_id to new rustc_hir crate
This commit is contained in:
parent
7eb7b23b2a
commit
7a14073875
38
Cargo.lock
38
Cargo.lock
@ -3091,6 +3091,7 @@ dependencies = [
|
||||
"rustc_errors",
|
||||
"rustc_feature",
|
||||
"rustc_fs_util",
|
||||
"rustc_hir",
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
"rustc_session",
|
||||
@ -3563,6 +3564,42 @@ dependencies = [
|
||||
name = "rustc_fs_util"
|
||||
version = "0.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_hir"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"arena",
|
||||
"backtrace",
|
||||
"bitflags",
|
||||
"byteorder",
|
||||
"chalk-engine",
|
||||
"fmt_macros",
|
||||
"graphviz",
|
||||
"jobserver",
|
||||
"log",
|
||||
"measureme",
|
||||
"num_cpus",
|
||||
"parking_lot",
|
||||
"polonius-engine",
|
||||
"rustc-rayon",
|
||||
"rustc-rayon-core",
|
||||
"rustc_apfloat",
|
||||
"rustc_data_structures",
|
||||
"rustc_error_codes",
|
||||
"rustc_errors",
|
||||
"rustc_feature",
|
||||
"rustc_fs_util",
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
"scoped-tls",
|
||||
"serialize",
|
||||
"smallvec 1.0.0",
|
||||
"syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_incremental"
|
||||
version = "0.0.0"
|
||||
@ -3603,6 +3640,7 @@ dependencies = [
|
||||
"rustc_data_structures",
|
||||
"rustc_errors",
|
||||
"rustc_expand",
|
||||
"rustc_hir",
|
||||
"rustc_incremental",
|
||||
"rustc_lint",
|
||||
"rustc_metadata",
|
||||
|
@ -23,6 +23,7 @@ rustc-rayon-core = "0.3.0"
|
||||
polonius-engine = "0.11.0"
|
||||
rustc_apfloat = { path = "../librustc_apfloat" }
|
||||
rustc_feature = { path = "../librustc_feature" }
|
||||
rustc_hir = { path = "../librustc_hir" }
|
||||
rustc_target = { path = "../librustc_target" }
|
||||
rustc_macros = { path = "../librustc_macros" }
|
||||
rustc_data_structures = { path = "../librustc_data_structures" }
|
||||
|
@ -34,7 +34,7 @@ use syntax::util::parser::ExprPrecedence;
|
||||
|
||||
pub mod check_attr;
|
||||
pub mod def;
|
||||
pub mod def_id;
|
||||
pub use rustc_hir::def_id;
|
||||
pub mod intravisit;
|
||||
pub mod itemlikevisit;
|
||||
pub mod map;
|
||||
|
42
src/librustc_hir/Cargo.toml
Normal file
42
src/librustc_hir/Cargo.toml
Normal file
@ -0,0 +1,42 @@
|
||||
[package]
|
||||
authors = ["The Rust Project Developers"]
|
||||
name = "rustc_hir"
|
||||
version = "0.0.0"
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "rustc_hir"
|
||||
path = "lib.rs"
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
arena = { path = "../libarena" }
|
||||
bitflags = "1.2.1"
|
||||
fmt_macros = { path = "../libfmt_macros" }
|
||||
graphviz = { path = "../libgraphviz" }
|
||||
jobserver = "0.1"
|
||||
num_cpus = "1.0"
|
||||
scoped-tls = "1.0"
|
||||
log = { version = "0.4", features = ["release_max_level_info", "std"] }
|
||||
rustc-rayon = "0.3.0"
|
||||
rustc-rayon-core = "0.3.0"
|
||||
polonius-engine = "0.11.0"
|
||||
rustc_apfloat = { path = "../librustc_apfloat" }
|
||||
rustc_feature = { path = "../librustc_feature" }
|
||||
rustc_target = { path = "../librustc_target" }
|
||||
rustc_macros = { path = "../librustc_macros" }
|
||||
rustc_data_structures = { path = "../librustc_data_structures" }
|
||||
rustc_index = { path = "../librustc_index" }
|
||||
rustc_span = { path = "../librustc_span" }
|
||||
errors = { path = "../librustc_errors", package = "rustc_errors" }
|
||||
rustc_serialize = { path = "../libserialize", package = "serialize" }
|
||||
syntax = { path = "../libsyntax" }
|
||||
backtrace = "0.3.40"
|
||||
parking_lot = "0.9"
|
||||
byteorder = { version = "1.3" }
|
||||
chalk-engine = { version = "0.9.0", default-features=false }
|
||||
rustc_fs_util = { path = "../librustc_fs_util" }
|
||||
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
|
||||
measureme = "0.5"
|
||||
rustc_error_codes = { path = "../librustc_error_codes" }
|
||||
rustc_session = { path = "../librustc_session" }
|
@ -1,4 +1,4 @@
|
||||
use crate::ty;
|
||||
use rustc_data_structures::AtomicRef;
|
||||
use rustc_index::vec::Idx;
|
||||
use std::fmt;
|
||||
use std::u32;
|
||||
@ -40,7 +40,7 @@ impl Idx for CrateNum {
|
||||
fn index(self) -> usize {
|
||||
match self {
|
||||
CrateNum::Index(idx) => Idx::index(idx),
|
||||
_ => bug!("Tried to get crate index of {:?}", self),
|
||||
_ => panic!("Tried to get crate index of {:?}", self),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,14 +61,14 @@ impl CrateNum {
|
||||
pub fn as_usize(self) -> usize {
|
||||
match self {
|
||||
CrateNum::Index(id) => id.as_usize(),
|
||||
_ => bug!("tried to get index of non-standard crate {:?}", self),
|
||||
_ => panic!("tried to get index of non-standard crate {:?}", self),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_u32(self) -> u32 {
|
||||
match self {
|
||||
CrateNum::Index(id) => id.as_u32(),
|
||||
_ => bug!("tried to get index of non-standard crate {:?}", self),
|
||||
_ => panic!("tried to get index of non-standard crate {:?}", self),
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,21 +113,6 @@ pub struct DefId {
|
||||
pub index: DefIndex,
|
||||
}
|
||||
|
||||
impl fmt::Debug for DefId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "DefId({}:{}", self.krate, self.index.index())?;
|
||||
|
||||
ty::tls::with_opt(|opt_tcx| {
|
||||
if let Some(tcx) = opt_tcx {
|
||||
write!(f, " ~ {}", tcx.def_path_debug_str(*self))?;
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
write!(f, ")")
|
||||
}
|
||||
}
|
||||
|
||||
impl DefId {
|
||||
/// Makes a local `DefId` from the given `DefIndex`.
|
||||
#[inline]
|
||||
@ -153,6 +138,19 @@ impl DefId {
|
||||
impl rustc_serialize::UseSpecializedEncodable for DefId {}
|
||||
impl rustc_serialize::UseSpecializedDecodable for DefId {}
|
||||
|
||||
pub fn default_def_id_debug(def_id: DefId, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("DefId").field("krate", &def_id.krate).field("index", &def_id.index).finish()
|
||||
}
|
||||
|
||||
pub static DEF_ID_DEBUG: AtomicRef<fn(DefId, &mut fmt::Formatter<'_>) -> fmt::Result> =
|
||||
AtomicRef::new(&(default_def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
|
||||
|
||||
impl fmt::Debug for DefId {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
(*DEF_ID_DEBUG)(*self, f)
|
||||
}
|
||||
}
|
||||
|
||||
rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId);
|
||||
|
||||
/// A LocalDefId is equivalent to a DefId with `krate == LOCAL_CRATE`. Since
|
3
src/librustc_hir/lib.rs
Normal file
3
src/librustc_hir/lib.rs
Normal file
@ -0,0 +1,3 @@
|
||||
#![feature(specialization)]
|
||||
|
||||
pub mod def_id;
|
@ -27,6 +27,7 @@ rustc_data_structures = { path = "../librustc_data_structures" }
|
||||
rustc_codegen_ssa = { path = "../librustc_codegen_ssa" }
|
||||
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
|
||||
rustc_codegen_llvm = { path = "../librustc_codegen_llvm", optional = true }
|
||||
rustc_hir = { path = "../librustc_hir" }
|
||||
rustc_metadata = { path = "../librustc_metadata" }
|
||||
rustc_mir = { path = "../librustc_mir" }
|
||||
rustc_passes = { path = "../librustc_passes" }
|
||||
|
@ -40,9 +40,23 @@ fn track_diagnostic(diagnostic: &Diagnostic) {
|
||||
})
|
||||
}
|
||||
|
||||
/// This is a callback from librustc_hir as it cannot access the implicit state
|
||||
/// in librustc otherwise.
|
||||
fn def_id_debug(def_id: rustc_hir::def_id::DefId, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "DefId({}:{}", def_id.krate, def_id.index.index())?;
|
||||
tls::with_opt(|opt_tcx| {
|
||||
if let Some(tcx) = opt_tcx {
|
||||
write!(f, " ~ {}", tcx.def_path_debug_str(def_id))?;
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
write!(f, ")")
|
||||
}
|
||||
|
||||
/// Sets up the callbacks in prior crates which we want to refer to the
|
||||
/// TyCtxt in.
|
||||
pub fn setup_callbacks() {
|
||||
rustc_span::SPAN_DEBUG.swap(&(span_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
|
||||
rustc_hir::def_id::DEF_ID_DEBUG.swap(&(def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
|
||||
TRACK_DIAGNOSTICS.swap(&(track_diagnostic as fn(&_)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user