Skip to content

Commit

Permalink
Rollup merge of #54936 - RalfJung:layout-hash, r=oli-obk
Browse files Browse the repository at this point in the history
impl Eq+Hash for TyLayout

As proposed by @eddyb at #53671 (review).

I have an upcoming PR that would also significantly benefit from this.
  • Loading branch information
pietroalbini authored Oct 9, 2018
2 parents a370112 + a0577ee commit ec1b889
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
17 changes: 1 addition & 16 deletions src/librustc_mir/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//! Functions concerning immediate values and operands, and reading from operands.
//! All high-level functions to read from memory work on operands as sources.

use std::hash::{Hash, Hasher};
use std::convert::TryInto;

use rustc::{mir, ty};
Expand Down Expand Up @@ -221,7 +220,7 @@ impl Operand {
}
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct OpTy<'tcx> {
crate op: Operand, // ideally we'd make this private, but const_prop needs this
pub layout: TyLayout<'tcx>,
Expand Down Expand Up @@ -255,20 +254,6 @@ impl<'tcx> From<ValTy<'tcx>> for OpTy<'tcx> {
}
}

// Validation needs to hash OpTy, but we cannot hash Layout -- so we just hash the type
impl<'tcx> Hash for OpTy<'tcx> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.op.hash(state);
self.layout.ty.hash(state);
}
}
impl<'tcx> PartialEq for OpTy<'tcx> {
fn eq(&self, other: &Self) -> bool {
self.op == other.op && self.layout.ty == other.layout.ty
}
}
impl<'tcx> Eq for OpTy<'tcx> {}

// Use the existing layout if given (but sanity check in debug mode),
// or compute the layout.
#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ impl LayoutDetails {
/// to those obtained from `layout_of(ty)`, as we need to produce
/// layouts for which Rust types do not exist, such as enum variants
/// or synthetic fields of enums (i.e. discriminants) and fat pointers.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct TyLayout<'a, Ty> {
pub ty: Ty,
pub details: &'a LayoutDetails
Expand Down

0 comments on commit ec1b889

Please sign in to comment.