Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ pub use layout::{FIRST_VARIANT, FieldIdx, LayoutCalculator, LayoutCalculatorErro
#[cfg(feature = "nightly")]
pub use layout::{Layout, TyAbiInterface, TyAndLayout};

/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
/// instead of implementing everything in `rustc_middle`.
#[cfg(feature = "nightly")]
pub trait HashStableContext {}

#[derive(Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(
feature = "nightly",
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ use rustc_data_structures::tagged_ptr::Tag;
use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable};
pub use rustc_span::AttrId;
use rustc_span::{
ByteSymbol, DUMMY_SP, ErrorGuaranteed, Ident, Span, Spanned, Symbol, kw, respan, sym,
ByteSymbol, DUMMY_SP, ErrorGuaranteed, HashStableContext, Ident, Span, Spanned, Symbol, kw,
respan, sym,
};
use thin_vec::{ThinVec, thin_vec};

Expand Down Expand Up @@ -120,7 +121,7 @@ impl PartialEq<&[Symbol]> for Path {
}
}

impl<Hcx: rustc_span::HashStableContext> HashStable<Hcx> for Path {
impl<Hcx: HashStableContext> HashStable<Hcx> for Path {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
self.segments.len().hash_stable(hcx, hasher);
for segment in &self.segments {
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,3 @@ pub mod visit;

pub use self::ast::*;
pub use self::ast_traits::{AstNodeWrapper, HasAttrs, HasNodeId, HasTokens};

/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
/// instead of implementing everything in `rustc_middle`.
pub trait HashStableContext: rustc_span::HashStableContext {}
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync;
use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable};
use rustc_serialize::{Decodable, Encodable};
use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
use rustc_span::{DUMMY_SP, HashStableContext, Span, SpanDecoder, SpanEncoder, Symbol, sym};
use thin_vec::ThinVec;

use crate::ast::AttrStyle;
Expand Down Expand Up @@ -826,7 +826,7 @@ impl FromIterator<TokenTree> for TokenStream {

impl<Hcx> HashStable<Hcx> for TokenStream
where
Hcx: crate::HashStableContext,
Hcx: HashStableContext,
{
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
for sub_tt in self.iter() {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use rustc_data_structures::stable_hasher::ToStableHashKey;
use rustc_data_structures::unord::UnordMap;
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
use rustc_span::Symbol;
use rustc_span::def_id::{DefId, LocalDefId};
use rustc_span::hygiene::MacroKind;
use rustc_span::{HashStableContext, Symbol};

use crate::definitions::DefPathData;
use crate::hir;
Expand Down Expand Up @@ -712,7 +712,7 @@ impl IntoDiagArg for Namespace {
}
}

impl<Hcx: crate::HashStableContext> ToStableHashKey<Hcx> for Namespace {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for Namespace {
type KeyType = Namespace;

#[inline]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub use hir::*;
pub use lang_items::{LangItem, LanguageItems};
pub use rustc_ast::attr::version::*;
pub use stability::*;
pub use stable_hash_impls::HashStableContext;
pub use target::{MethodKind, Target};

arena_types!(rustc_arena::declare_arena);
42 changes: 19 additions & 23 deletions compiler/rustc_hir/src/stable_hash_impls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use rustc_span::HashStableContext;
use rustc_span::def_id::DefPathHash;

use crate::HashIgnoredAttrId;
Expand All @@ -8,53 +9,48 @@ use crate::hir::{
use crate::hir_id::ItemLocalId;
use crate::lints::DelayedLints;

/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
/// instead of implementing everything in `rustc_middle`.
pub trait HashStableContext: rustc_ast::HashStableContext + rustc_abi::HashStableContext {}

impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for BodyId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for BodyId {
type KeyType = (DefPathHash, ItemLocalId);

#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> (DefPathHash, ItemLocalId) {
fn to_stable_hash_key(&self, hcx: &Hcx) -> (DefPathHash, ItemLocalId) {
let BodyId { hir_id } = *self;
hir_id.to_stable_hash_key(hcx)
}
}

impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ItemId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ItemId {
type KeyType = DefPathHash;

#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}

impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for TraitItemId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for TraitItemId {
type KeyType = DefPathHash;

#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}

impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ImplItemId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ImplItemId {
type KeyType = DefPathHash;

#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}

impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for ForeignItemId {
type KeyType = DefPathHash;

#[inline]
fn to_stable_hash_key(&self, hcx: &HirCtx) -> DefPathHash {
fn to_stable_hash_key(&self, hcx: &Hcx) -> DefPathHash {
self.owner_id.def_id.to_stable_hash_key(hcx)
}
}
Expand All @@ -66,8 +62,8 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId
// want to pick up on a reference changing its target, so we hash the NodeIds
// in "DefPath Mode".

impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'tcx> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for OwnerNodes<'tcx> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
// We ignore the `nodes` and `bodies` fields since these refer to information included in
// `hash` which is hashed in the collector and used for the crate hash.
// `local_id_to_def_id` is also ignored because is dependent on the body, then just hashing
Expand All @@ -78,24 +74,24 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'
}
}

impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for DelayedLints {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
impl<Hcx: HashStableContext> HashStable<Hcx> for DelayedLints {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let DelayedLints { opt_hash, .. } = *self;
opt_hash.unwrap().hash_stable(hcx, hasher);
}
}

impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for AttributeMap<'tcx> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
impl<'tcx, Hcx: HashStableContext> HashStable<Hcx> for AttributeMap<'tcx> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
// We ignore the `map` since it refers to information included in `opt_hash` which is
// hashed in the collector and used for the crate hash.
let AttributeMap { opt_hash, define_opaque: _, map: _ } = *self;
opt_hash.unwrap().hash_stable(hcx, hasher);
}
}

impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HashIgnoredAttrId {
fn hash_stable(&self, _hcx: &mut HirCtx, _hasher: &mut StableHasher) {
impl<Hcx: HashStableContext> HashStable<Hcx> for HashIgnoredAttrId {
fn hash_stable(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher) {
/* we don't hash HashIgnoredAttrId, we ignore them */
}
}
4 changes: 2 additions & 2 deletions compiler/rustc_hir_id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt::{self, Debug};

use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
pub use rustc_span::HashStableContext;
use rustc_span::HashStableContext;
use rustc_span::def_id::{CRATE_DEF_ID, DefId, DefIndex, DefPathHash, LocalDefId};

#[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)]
Expand Down Expand Up @@ -176,7 +176,7 @@ pub const CRATE_HIR_ID: HirId =

pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID };

impl<Hcx: rustc_span::HashStableContext> ToStableHashKey<Hcx> for HirId {
impl<Hcx: HashStableContext> ToStableHashKey<Hcx> for HirId {
type KeyType = (DefPathHash, ItemLocalId);

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use rustc_data_structures::stable_hasher::{
HashStable, StableCompare, StableHasher, ToStableHashKey,
};
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
use rustc_hir_id::{HashStableContext, HirId, ItemLocalId};
use rustc_hir_id::{HirId, ItemLocalId};
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
use rustc_span::def_id::DefPathHash;
pub use rustc_span::edition::Edition;
use rustc_span::{Ident, Span, Symbol, sym};
use rustc_span::{HashStableContext, Ident, Span, Symbol, sym};
use serde::{Deserialize, Serialize};

pub use self::Level::*;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/hash_stable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn hash_stable_derive_with_mode(
match mode {
HashStableMode::Normal => {}
HashStableMode::Generic => {
s.add_where_predicate(parse_quote! { __CTX: crate::HashStableContext });
s.add_where_predicate(parse_quote! { __CTX: ::rustc_span::HashStableContext });
}
HashStableMode::NoContext => {}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc_hir::lints::DelayedLint;
use rustc_hir::*;
use rustc_index::IndexVec;
use rustc_macros::{Decodable, Encodable, HashStable};
use rustc_span::{ErrorGuaranteed, ExpnId, Span};
use rustc_span::{ErrorGuaranteed, ExpnId, HashStableContext, Span};

use crate::query::Providers;
use crate::ty::{ResolverAstLowering, TyCtxt};
Expand Down Expand Up @@ -77,8 +77,8 @@ impl<'hir> Crate<'hir> {
}
}

impl<HirCtx: HashStableContext> HashStable<HirCtx> for Crate<'_> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
impl<Hcx: HashStableContext> HashStable<Hcx> for Crate<'_> {
fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
let Crate { opt_hir_hash, .. } = self;
opt_hir_hash.unwrap().hash_stable(hcx, hasher)
}
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_middle/src/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_hir::definitions::DefPathHash;
use rustc_session::Session;
use rustc_session::cstore::Untracked;
use rustc_span::source_map::SourceMap;
use rustc_span::{CachingSourceMapView, DUMMY_SP, Pos, Span};
use rustc_span::{CachingSourceMapView, DUMMY_SP, HashStableContext, Pos, Span};

// Very often, we are hashing something that does not need the `CachingSourceMapView`, so we
// initialize it lazily.
Expand Down Expand Up @@ -73,7 +73,7 @@ impl<'a> StableHashingContext<'a> {
}
}

impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
impl<'a> HashStableContext for StableHashingContext<'a> {
/// Hashes a span in a stable way. We can't directly hash the span's `BytePos` fields (that
/// would be similar to hashing pointers, since those are just offsets into the `SourceMap`).
/// Instead, we hash the (file name, line, column) triple, which stays the same even if the
Expand Down Expand Up @@ -189,8 +189,3 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
);
}
}

impl<'a> rustc_abi::HashStableContext for StableHashingContext<'a> {}
impl<'a> rustc_ast::HashStableContext for StableHashingContext<'a> {}
impl<'a> rustc_hir::HashStableContext for StableHashingContext<'a> {}
impl<'a> rustc_session::HashStableContext for StableHashingContext<'a> {}
5 changes: 3 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use rustc_macros::{BlobDecodable, Decodable, Encodable, HashStable_Generic};
use rustc_span::edition::{DEFAULT_EDITION, EDITION_NAME_LIST, Edition, LATEST_STABLE_EDITION};
use rustc_span::source_map::FilePathMapping;
use rustc_span::{
FileName, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm, Symbol, sym,
FileName, HashStableContext, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm,
Symbol, sym,
};
use rustc_target::spec::{
FramePointer, LinkSelfContainedComponents, LinkerFeatures, PanicStrategy, SplitDebuginfo,
Expand All @@ -38,7 +39,7 @@ use crate::errors::FileWriteFail;
pub use crate::options::*;
use crate::search_paths::SearchPath;
use crate::utils::CanonicalizedPath;
use crate::{EarlyDiagCtxt, HashStableContext, Session, filesearch, lint};
use crate::{EarlyDiagCtxt, Session, filesearch, lint};

mod cfg;
mod externs;
Expand Down
21 changes: 6 additions & 15 deletions compiler/rustc_session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,21 @@
#![recursion_limit = "256"]
// tidy-alphabetical-end

pub mod errors;

pub mod utils;
pub use getopts;
pub use lint::{declare_lint, declare_lint_pass, declare_tool_lint, impl_lint_pass};
pub use rustc_lint_defs as lint;
pub mod parse;
pub use session::*;

pub mod code_stats;
pub mod errors;
pub mod parse;
pub mod utils;
#[macro_use]
pub mod config;
pub mod cstore;
pub mod filesearch;
mod macros;
mod options;
pub mod output;
pub mod search_paths;

mod session;
pub use session::*;

pub mod output;

pub use getopts;

/// Requirements for a `StableHashingContext` to be used in this crate.
/// This is a hack to allow using the `HashStable_Generic` derive macro
/// instead of implementing everything in `rustc_middle`.
pub trait HashStableContext: rustc_ast::HashStableContext + rustc_hir::HashStableContext {}
8 changes: 4 additions & 4 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2796,10 +2796,10 @@ impl InnerSpan {
}
}

/// Requirements for a `StableHashingContext` to be used in this crate.
///
/// This is a hack to allow using the [`HashStable_Generic`] derive macro
/// instead of implementing everything in rustc_middle.
/// This trait lets `HashStable` and `derive(HashStable_Generic)` be used in
/// this crate (and other crates upstream of `rustc_middle`), while leaving
/// certain operations to be defined in `rustc_middle` where more things are
/// visible.
pub trait HashStableContext {
/// The main event: stable hashing of a span.
fn span_hash_stable(&mut self, span: Span, hasher: &mut StableHasher);
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_target/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ pub mod target_features;
#[cfg(test)]
mod tests;

use rustc_abi::HashStableContext;

/// The name of rustc's own place to organize libraries.
///
/// Used to be `rustc`, now the default is `rustlib`.
Expand Down
Loading