Skip to content

Just derive Hashstable in librustc #66457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 20, 2019
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
@@ -3720,6 +3720,7 @@ dependencies = [
"rustc_errors",
"rustc_index",
"rustc_lexer",
"rustc_macros",
"rustc_target",
"serialize",
"smallvec 1.0.0",
6 changes: 1 addition & 5 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
@@ -578,7 +578,7 @@ impl<'tcx> DepNodeParams<'tcx> for HirId {
/// the need to be mapped or unmapped. (This ensures we can serialize
/// them even in the absence of a tcx.)
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
RustcEncodable, RustcDecodable)]
RustcEncodable, RustcDecodable, HashStable)]
pub struct WorkProductId {
hash: Fingerprint
}
@@ -599,7 +599,3 @@ impl WorkProductId {
}
}
}

impl_stable_hash_for!(struct crate::dep_graph::WorkProductId {
hash
});
4 changes: 1 addition & 3 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
@@ -313,11 +313,9 @@ pub enum DefPathData {
}

#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
RustcEncodable, RustcDecodable)]
RustcEncodable, RustcDecodable, HashStable)]
pub struct DefPathHash(pub Fingerprint);

impl_stable_hash_for!(tuple_struct DefPathHash { fingerprint });

impl Borrow<Fingerprint> for DefPathHash {
#[inline]
fn borrow(&self) -> &Fingerprint {
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
@@ -1215,7 +1215,7 @@ impl UnOp {
}

/// A statement.
#[derive(RustcEncodable, RustcDecodable)]
#[derive(RustcEncodable, RustcDecodable, HashStable)]
pub struct Stmt {
pub hir_id: HirId,
pub kind: StmtKind,
7 changes: 0 additions & 7 deletions src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
@@ -140,13 +140,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty {

impl_stable_hash_for_spanned!(hir::BinOpKind);

impl_stable_hash_for!(struct hir::Stmt {
hir_id,
kind,
span,
});


impl_stable_hash_for_spanned!(ast::Name);

impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr {
6 changes: 1 addition & 5 deletions src/librustc/infer/outlives/free_region_map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ty::{self, Lift, TyCtxt, Region};
use rustc_data_structures::transitive_relation::TransitiveRelation;

#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default, HashStable)]
pub struct FreeRegionMap<'tcx> {
// Stores the relation `a < b`, where `a` and `b` are regions.
//
@@ -89,10 +89,6 @@ fn is_free_or_static(r: Region<'_>) -> bool {
}
}

impl_stable_hash_for!(struct FreeRegionMap<'tcx> {
relation
});

impl<'a, 'tcx> Lift<'tcx> for FreeRegionMap<'a> {
type Lifted = FreeRegionMap<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<FreeRegionMap<'tcx>> {
17 changes: 2 additions & 15 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
@@ -543,18 +543,11 @@ impl LintId {
}

/// Setting for how to handle a lint.
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, HashStable)]
pub enum Level {
Allow, Warn, Deny, Forbid,
}

impl_stable_hash_for!(enum self::Level {
Allow,
Warn,
Deny,
Forbid
});

impl Level {
/// Converts a level to a lower-case string.
pub fn as_str(self) -> &'static str {
@@ -590,7 +583,7 @@ impl Level {
}

/// How a lint level was set.
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq, HashStable)]
pub enum LintSource {
/// Lint is at the default level as declared
/// in rustc or a plugin.
@@ -603,12 +596,6 @@ pub enum LintSource {
CommandLine(Symbol),
}

impl_stable_hash_for!(enum self::LintSource {
Default,
Node(name, span, reason),
CommandLine(text)
});

pub type LevelSource = (Level, LintSource);

pub mod builtin;
7 changes: 1 addition & 6 deletions src/librustc/middle/exported_symbols.rs
Original file line number Diff line number Diff line change
@@ -11,17 +11,12 @@ use crate::ty::subst::SubstsRef;
/// kind of crate, including cdylibs which export very few things.
/// `Rust` will only be exported if the crate produced is a Rust
/// dylib.
#[derive(Eq, PartialEq, Debug, Copy, Clone, RustcEncodable, RustcDecodable)]
#[derive(Eq, PartialEq, Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
pub enum SymbolExportLevel {
C,
Rust,
}

impl_stable_hash_for!(enum self::SymbolExportLevel {
C,
Rust
});

impl SymbolExportLevel {
pub fn is_below_threshold(self, threshold: SymbolExportLevel) -> bool {
threshold == SymbolExportLevel::Rust // export everything from Rust dylibs
8 changes: 1 addition & 7 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
@@ -207,20 +207,14 @@ struct NamedRegionMap {
}

/// See [`NamedRegionMap`].
#[derive(Default)]
#[derive(Default, HashStable)]
pub struct ResolveLifetimes {
defs: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Region>>,
late_bound: FxHashMap<LocalDefId, FxHashSet<ItemLocalId>>,
object_lifetime_defaults:
FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>>,
}

impl_stable_hash_for!(struct crate::middle::resolve_lifetime::ResolveLifetimes {
defs,
late_bound,
object_lifetime_defaults
});

struct LifetimeContext<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
map: &'a mut NamedRegionMap,
15 changes: 2 additions & 13 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ enum AnnotationKind {
}

/// An entry in the `depr_map`.
#[derive(Clone)]
#[derive(Clone, HashStable)]
pub struct DeprecationEntry {
/// The metadata of the attribute associated with this entry.
pub attr: Deprecation,
@@ -61,11 +61,6 @@ pub struct DeprecationEntry {
origin: Option<HirId>,
}

impl_stable_hash_for!(struct self::DeprecationEntry {
attr,
origin
});

impl DeprecationEntry {
fn local(attr: Deprecation, id: HirId) -> DeprecationEntry {
DeprecationEntry {
@@ -90,6 +85,7 @@ impl DeprecationEntry {
}

/// A stability index, giving the stability level for items and methods.
#[derive(HashStable)]
pub struct Index<'tcx> {
/// This is mostly a cache, except the stabilities of local items
/// are filled by the annotator.
@@ -103,13 +99,6 @@ pub struct Index<'tcx> {
active_features: FxHashSet<Symbol>,
}

impl_stable_hash_for!(struct self::Index<'tcx> {
stab_map,
depr_map,
staged_api,
active_features
});

// A private tree-walker for producing an Index.
struct Annotator<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
6 changes: 2 additions & 4 deletions src/librustc/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ use super::{
Pointer, InterpResult, AllocId, ScalarMaybeUndef, write_target_uint, read_target_uint, Scalar,
};

use crate::mir;
use crate::ty::layout::{Size, Align};

use rustc_data_structures::sorted_map::SortedMap;
@@ -787,14 +786,13 @@ type Block = u64;

/// A bitmask where each bit refers to the byte with the same index. If the bit is `true`, the byte
/// is defined. If it is `false` the byte is undefined.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash,
RustcEncodable, RustcDecodable, HashStable)]
pub struct UndefMask {
blocks: Vec<Block>,
len: Size,
}

impl_stable_hash_for!(struct mir::interpret::UndefMask{blocks, len});

impl UndefMask {
pub const BLOCK_SIZE: u64 = 64;

7 changes: 1 addition & 6 deletions src/librustc/mir/interpret/value.rs
Original file line number Diff line number Diff line change
@@ -458,7 +458,7 @@ impl<Tag> From<Pointer<Tag>> for Scalar<Tag> {
}
}

#[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable)]
#[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable, HashStable)]
pub enum ScalarMaybeUndef<Tag = (), Id = AllocId> {
Scalar(Scalar<Tag, Id>),
Undef,
@@ -583,11 +583,6 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
}
}

impl_stable_hash_for!(enum crate::mir::interpret::ScalarMaybeUndef {
Scalar(v),
Undef
});

/// Gets the bytes of a constant slice value.
pub fn get_slice_bytes<'tcx>(cx: &impl HasDataLayout, val: ConstValue<'tcx>) -> &'tcx [u8] {
if let ConstValue::Slice { data, start, end } = val {
62 changes: 8 additions & 54 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -70,7 +70,8 @@ impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
/// The various "big phases" that MIR goes through.
///
/// Warning: ordering of variants is significant.
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable,
Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum MirPhase {
Build = 0,
Const = 1,
@@ -86,7 +87,7 @@ impl MirPhase {
}

/// The lowered representation of a single function.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, TypeFoldable)]
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable, TypeFoldable)]
pub struct Body<'tcx> {
/// A list of basic blocks. References to basic block use a newtyped index type `BasicBlock`
/// that indexes into this vector.
@@ -412,24 +413,6 @@ pub enum Safety {
ExplicitUnsafe(hir::HirId),
}

impl_stable_hash_for!(struct Body<'tcx> {
phase,
basic_blocks,
source_scopes,
source_scope_local_data,
yield_ty,
generator_drop,
generator_layout,
local_decls,
user_type_annotations,
arg_count,
__upvar_debuginfo_codegen_only_do_not_use,
spread_arg,
control_flow_destroyed,
span,
cache
});

impl<'tcx> Index<BasicBlock> for Body<'tcx> {
type Output = BasicBlockData<'tcx>;

@@ -609,7 +592,7 @@ pub enum LocalKind {
ReturnPointer,
}

#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub struct VarBindingForm<'tcx> {
/// Is variable bound via `x`, `mut x`, `ref x`, or `ref mut x`?
pub binding_mode: ty::BindingMode,
@@ -642,7 +625,7 @@ pub enum BindingForm<'tcx> {
}

/// Represents what type of implicit self a function has, if any.
#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable)]
#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub enum ImplicitSelfKind {
/// Represents a `fn x(self);`.
Imm,
@@ -659,28 +642,6 @@ pub enum ImplicitSelfKind {

CloneTypeFoldableAndLiftImpls! { BindingForm<'tcx>, }

impl_stable_hash_for!(struct self::VarBindingForm<'tcx> {
binding_mode,
opt_ty_info,
opt_match_place,
pat_span
});

impl_stable_hash_for!(enum self::ImplicitSelfKind {
Imm,
Mut,
ImmRef,
MutRef,
None
});

impl_stable_hash_for!(enum self::MirPhase {
Build,
Const,
Validated,
Optimized,
});

mod binding_form_impl {
use crate::ich::StableHashingContext;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -707,7 +668,7 @@ mod binding_form_impl {
/// involved in borrow_check errors, e.g., explanations of where the
/// temporaries come from, when their destructors are run, and/or how
/// one might revise the code to satisfy the borrow checker's rules.
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub struct BlockTailInfo {
/// If `true`, then the value resulting from evaluating this tail
/// expression is ignored by the block's expression context.
@@ -717,8 +678,6 @@ pub struct BlockTailInfo {
pub tail_result_is_ignored: bool,
}

impl_stable_hash_for!(struct BlockTailInfo { tail_result_is_ignored });

/// A MIR local.
///
/// This can be a binding declared by the user, a temporary inserted by the compiler, a function
@@ -1746,7 +1705,8 @@ pub enum PlaceBase<'tcx> {
}

/// We store the normalized type to avoid requiring normalization when reading MIR
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash,
RustcEncodable, RustcDecodable, HashStable)]
pub struct Static<'tcx> {
pub ty: Ty<'tcx>,
pub kind: StaticKind<'tcx>,
@@ -1768,12 +1728,6 @@ pub enum StaticKind<'tcx> {
Static,
}

impl_stable_hash_for!(struct Static<'tcx> {
ty,
kind,
def_id
});

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(RustcEncodable, RustcDecodable, HashStable)]
pub enum ProjectionElem<V, T> {
Loading