1
Fork 0

move CrateDisambiguator -> rustc_ast

This commit is contained in:
Mazdak Farrokhzad 2020-03-21 04:30:30 +01:00
parent fdf2d2d9dc
commit bb8785ea00
4 changed files with 48 additions and 52 deletions

View file

@ -5,12 +5,13 @@
//! expressions) that are mostly just leftovers. //! expressions) that are mostly just leftovers.
use rustc_ast::ast; use rustc_ast::ast;
use rustc_ast::crate_disambiguator::CrateDisambiguator;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::StableHasher; use rustc_data_structures::stable_hasher::StableHasher;
use rustc_hir as hir; use rustc_hir as hir;
pub use rustc_hir::def_id::DefPathHash;
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_session::CrateDisambiguator;
use rustc_span::hygiene::ExpnId; use rustc_span::hygiene::ExpnId;
use rustc_span::symbol::{sym, Symbol}; use rustc_span::symbol::{sym, Symbol};
use rustc_span::Span; use rustc_span::Span;
@ -18,8 +19,6 @@ use rustc_span::Span;
use std::fmt::Write; use std::fmt::Write;
use std::hash::Hash; use std::hash::Hash;
pub use rustc_hir::def_id::DefPathHash;
/// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa. /// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa.
/// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey` /// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey`
/// stores the `DefIndex` of its parent. /// stores the `DefIndex` of its parent.

View file

@ -0,0 +1,35 @@
// This is here because `rustc_session` wants to refer to it,
// and so does `rustc_hir`, but `rustc_hir` shouldn't refer to `rustc_session`.
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::{base_n, impl_stable_hash_via_hash};
use std::fmt;
/// Hash value constructed out of all the `-C metadata` arguments passed to the
/// compiler. Together with the crate-name forms a unique global identifier for
/// the crate.
#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy, RustcEncodable, RustcDecodable)]
pub struct CrateDisambiguator(Fingerprint);
impl CrateDisambiguator {
pub fn to_fingerprint(self) -> Fingerprint {
self.0
}
}
impl fmt::Display for CrateDisambiguator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
let (a, b) = self.0.as_value();
let as_u128 = a as u128 | ((b as u128) << 64);
f.write_str(&base_n::encode(as_u128, base_n::CASE_INSENSITIVE))
}
}
impl From<Fingerprint> for CrateDisambiguator {
fn from(fingerprint: Fingerprint) -> CrateDisambiguator {
CrateDisambiguator(fingerprint)
}
}
impl_stable_hash_via_hash!(CrateDisambiguator);

View file

@ -40,6 +40,7 @@ pub mod util {
pub mod ast; pub mod ast;
pub mod attr; pub mod attr;
pub use attr::{with_default_globals, with_globals, GLOBALS}; pub use attr::{with_default_globals, with_globals, GLOBALS};
pub mod crate_disambiguator;
pub mod entry; pub mod entry;
pub mod expand; pub mod expand;
pub mod mut_visit; pub mod mut_visit;

View file

@ -1,41 +1,30 @@
use crate::cgu_reuse_tracker::CguReuseTracker;
use crate::code_stats::CodeStats; use crate::code_stats::CodeStats;
pub use crate::code_stats::{DataTypeKind, FieldInfo, SizeKind, VariantInfo}; pub use crate::code_stats::{DataTypeKind, FieldInfo, SizeKind, VariantInfo};
use crate::cgu_reuse_tracker::CguReuseTracker;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use crate::config::{self, OutputType, PrintRequest, Sanitizer, SwitchWithOptPath}; use crate::config::{self, OutputType, PrintRequest, Sanitizer, SwitchWithOptPath};
use crate::filesearch; use crate::filesearch;
use crate::lint; use crate::lint;
use crate::parse::ParseSess;
use crate::search_paths::{PathKind, SearchPath}; use crate::search_paths::{PathKind, SearchPath};
use rustc_data_structures::profiling::duration_to_secs_str;
use rustc_errors::ErrorReported;
use rustc_data_structures::base_n; pub use rustc_ast::crate_disambiguator::CrateDisambiguator;
use rustc_data_structures::impl_stable_hash_via_hash; use rustc_data_structures::flock;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::jobserver::{self, Client};
use rustc_data_structures::profiling::{duration_to_secs_str, SelfProfiler, SelfProfilerRef};
use rustc_data_structures::sync::{ use rustc_data_structures::sync::{
self, AtomicU64, AtomicUsize, Lock, Lrc, Once, OneThread, Ordering, Ordering::SeqCst, self, AtomicU64, AtomicUsize, Lock, Lrc, Once, OneThread, Ordering, Ordering::SeqCst,
}; };
use crate::parse::ParseSess;
use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter; use rustc_errors::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter;
use rustc_errors::emitter::HumanReadableErrorType; use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType};
use rustc_errors::emitter::{Emitter, EmitterWriter};
use rustc_errors::json::JsonEmitter; use rustc_errors::json::JsonEmitter;
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId}; use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticId, ErrorReported};
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::source_map; use rustc_span::source_map::{self, MultiSpan, Span};
use rustc_span::{MultiSpan, Span};
use rustc_data_structures::flock;
use rustc_data_structures::jobserver::{self, Client};
use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef};
use rustc_target::spec::{PanicStrategy, RelroLevel, Target, TargetTriple}; use rustc_target::spec::{PanicStrategy, RelroLevel, Target, TargetTriple};
use std::cell::{self, RefCell}; use std::cell::{self, RefCell};
use std::env; use std::env;
use std::fmt;
use std::io::Write; use std::io::Write;
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::path::PathBuf; use std::path::PathBuf;
@ -1193,34 +1182,6 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
} }
} }
/// Hash value constructed out of all the `-C metadata` arguments passed to the
/// compiler. Together with the crate-name forms a unique global identifier for
/// the crate.
#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy, RustcEncodable, RustcDecodable)]
pub struct CrateDisambiguator(Fingerprint);
impl CrateDisambiguator {
pub fn to_fingerprint(self) -> Fingerprint {
self.0
}
}
impl fmt::Display for CrateDisambiguator {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
let (a, b) = self.0.as_value();
let as_u128 = a as u128 | ((b as u128) << 64);
f.write_str(&base_n::encode(as_u128, base_n::CASE_INSENSITIVE))
}
}
impl From<Fingerprint> for CrateDisambiguator {
fn from(fingerprint: Fingerprint) -> CrateDisambiguator {
CrateDisambiguator(fingerprint)
}
}
impl_stable_hash_via_hash!(CrateDisambiguator);
/// Holds data on the current incremental compilation session, if there is one. /// Holds data on the current incremental compilation session, if there is one.
#[derive(Debug)] #[derive(Debug)]
pub enum IncrCompSession { pub enum IncrCompSession {