Skip to content

Commit

Permalink
mlir: Impl PartialEq, Eq, Hash for MlirValue
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianschuiki committed Jul 12, 2022
1 parent a456553 commit fb20be7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions src/circt-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

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

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

pub unsafe fn mlirStringRefCreateFromStr(s: impl AsRef<str>) -> MlirStringRef {
Expand All @@ -30,6 +32,24 @@ pub unsafe fn mlirIdentifierToStr<'a, R>(i: MlirIdentifier, f: impl Fn(&'a str)
mlirStringRefToStr(mlirIdentifierStr(i), f)
}

impl Eq for MlirValue {}

impl PartialEq for MlirValue {
fn eq(&self, other: &Self) -> bool {
match (self.ptr.is_null(), other.ptr.is_null()) {
(true, true) => true,
(false, false) => unsafe { mlirValueEqual(*self, *other) },
_ => false,
}
}
}

impl Hash for MlirValue {
fn hash<H: Hasher>(&self, state: &mut H) {
self.ptr.hash(state);
}
}

impl Eq for MlirType {}

impl PartialEq for MlirType {
Expand All @@ -42,6 +62,12 @@ impl PartialEq for MlirType {
}
}

impl Hash for MlirType {
fn hash<H: Hasher>(&self, state: &mut H) {
self.ptr.hash(state);
}
}

impl Eq for MlirBlock {}

impl PartialEq for MlirBlock {
Expand All @@ -53,3 +79,9 @@ impl PartialEq for MlirBlock {
}
}
}

impl Hash for MlirBlock {
fn hash<H: Hasher>(&self, state: &mut H) {
self.ptr.hash(state);
}
}
2 changes: 1 addition & 1 deletion src/circt/src/mlir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::crate_prelude::*;
use std::fmt::{Debug, Display};

/// An MLIR type.
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct Type(MlirType);

impl Type {
Expand Down
2 changes: 1 addition & 1 deletion src/circt/src/mlir/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::crate_prelude::*;
use std::fmt::{Debug, Display};

/// An MLIR value.
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct Value(MlirValue);

impl Value {
Expand Down

0 comments on commit fb20be7

Please sign in to comment.