pub struct HashConsed<T>(HashByAddr<Arc<T>>);Expand description
Hash-consed data structure: a reference-counted wrapper that guarantees that two equal value will be stored at the same address. This makes it possible to use the pointer address as a hash value.
Tuple Fields§
§0: HashByAddr<Arc<T>>Implementations§
Source§impl<T> HashConsed<T>where
T: HashConsable,
impl<T> HashConsed<T>where
T: HashConsable,
Sourcepub fn new(inner: T) -> Self
pub fn new(inner: T) -> Self
Deduplicate the values by hashing them. This deduplication is crucial for the hashing
function to be correct. This is the only function allowed to create Self values.
Sourcepub fn from_arc(inner: Arc<T>) -> Self
pub fn from_arc(inner: Arc<T>) -> Self
Rarely used: in case we already have an Arc, may avoid an allocation.
Sourcepub fn as_mut(&mut self) -> impl DerefMut<Target = T>
pub fn as_mut(&mut self) -> impl DerefMut<Target = T>
Get a reference to the pointed-to value that can be mutated. Avoids cloning/allocation if this is the sole pointer to that value.
The returned value must not be leaked as this would break the hash-consing invariant.
Sourcepub fn with_inner_mut<R>(&mut self, f: impl FnOnce(&mut T) -> R) -> R
pub fn with_inner_mut<R>(&mut self, f: impl FnOnce(&mut T) -> R) -> R
Clones if needed to get mutable access to the inner value.
Trait Implementations§
Source§impl<T: AstVisitable + HashConsable> AstVisitable for HashConsed<T>
impl<T: AstVisitable + HashConsable> AstVisitable for HashConsed<T>
Source§fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn drive_two<V: ZipAst>(&self, other: &Self, v: &mut V) -> ControlFlow<V::Break>
fn drive_two<V: ZipAst>(&self, other: &Self, v: &mut V) -> ControlFlow<V::Break>
visit_$any
method if it exists, otherwise visit_inner.Source§fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))where
Self: Sized,
fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))where
Self: Sized,
self, in pre-order traversal.Source§fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))where
Self: Sized,
fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))where
Self: Sized,
self, in pre-order traversal.Source§impl<T> Clone for HashConsed<T>
impl<T> Clone for HashConsed<T>
Source§impl<T: Debug> Debug for HashConsed<T>
impl<T: Debug> Debug for HashConsed<T>
Source§impl<T> Deref for HashConsed<T>
impl<T> Deref for HashConsed<T>
Source§impl<'de, T> Deserialize<'de> for HashConsed<T>where
T: Deserialize<'de> + HashConsable,
impl<'de, T> Deserialize<'de> for HashConsed<T>where
T: Deserialize<'de> + HashConsable,
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'de, T, State> DeserializeState<'de, State> for HashConsed<T>where
T: DeserializeState<'de, State> + HashConsable,
State: DedupSerializerState,
impl<'de, T, State> DeserializeState<'de, State> for HashConsed<T>where
T: DeserializeState<'de, State> + HashConsable,
State: DedupSerializerState,
fn deserialize_state<D>(
state: &State,
deserializer: D,
) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'s, T, V: Visit<'s, T>> Drive<'s, V> for HashConsed<T>
impl<'s, T, V: Visit<'s, T>> Drive<'s, V> for HashConsed<T>
Source§fn drive_inner(&'s self, v: &mut V) -> ControlFlow<V::Break>
fn drive_inner(&'s self, v: &mut V) -> ControlFlow<V::Break>
v.visit() on the immediate contents of self.Source§impl<'s, T, V> DriveMut<'s, V> for HashConsed<T>where
T: HashConsable,
V: for<'a> VisitMut<'a, T>,
Note: this explores the inner value mutably by cloning and re-hashing afterwards.
impl<'s, T, V> DriveMut<'s, V> for HashConsed<T>where
T: HashConsable,
V: for<'a> VisitMut<'a, T>,
Note: this explores the inner value mutably by cloning and re-hashing afterwards.
Source§fn drive_inner_mut(&'s mut self, v: &mut V) -> ControlFlow<V::Break>
fn drive_inner_mut(&'s mut self, v: &mut V) -> ControlFlow<V::Break>
v.visit() on the immediate contents of self.Source§impl<'s, T, V: VisitTwo<'s, T>> DriveTwo<'s, V> for HashConsed<T>
impl<'s, T, V: VisitTwo<'s, T>> DriveTwo<'s, V> for HashConsed<T>
Source§fn drive_two_inner(
&'s self,
other: &'s Self,
v: &mut V,
) -> ControlFlow<V::Break>
fn drive_two_inner( &'s self, other: &'s Self, v: &mut V, ) -> ControlFlow<V::Break>
v.visit() on the immediate contents of self and other, if they correspond. If
the values don’t match up, this returns Break(Default::default()).impl<T: Eq> Eq for HashConsed<T>
Source§impl<T: Hash> Hash for HashConsed<T>
impl<T: Hash> Hash for HashConsed<T>
Source§impl<T: Ord> Ord for HashConsed<T>
impl<T: Ord> Ord for HashConsed<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialEq> PartialEq for HashConsed<T>
impl<T: PartialEq> PartialEq for HashConsed<T>
Source§impl<T: PartialOrd> PartialOrd for HashConsed<T>
impl<T: PartialOrd> PartialOrd for HashConsed<T>
Source§impl<T> Serialize for HashConsed<T>where
T: Serialize + HashConsable,
impl<T> Serialize for HashConsed<T>where
T: Serialize + HashConsable,
Source§impl<T, State> SerializeState<State> for HashConsed<T>where
T: SerializeState<State> + HashConsable,
State: DedupSerializerState,
Options for the state are () to serialize values normally and DedupSerializer
to deduplicate identical values in the serialized output.
impl<T, State> SerializeState<State> for HashConsed<T>where
T: SerializeState<State> + HashConsable,
State: DedupSerializerState,
Options for the state are () to serialize values normally and DedupSerializer
to deduplicate identical values in the serialized output.
fn serialize_state<S>(
&self,
state: &State,
serializer: S,
) -> Result<S::Ok, S::Error>where
S: Serializer,
impl<T: PartialEq> StructuralPartialEq for HashConsed<T>
Auto Trait Implementations§
impl<T> Freeze for HashConsed<T>
impl<T> RefUnwindSafe for HashConsed<T>
impl<T> Send for HashConsed<T>
impl<T> Sync for HashConsed<T>
impl<T> Unpin for HashConsed<T>
impl<T> UnsafeUnpin for HashConsed<T>
impl<T> UnwindSafe for HashConsed<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> Dedup for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> Formattable for T
impl<T> HashConsable for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> Mappable for T
Source§impl<T> TyVisitable for Twhere
T: AstVisitable,
impl<T> TyVisitable for Twhere
T: AstVisitable,
Source§fn type_info(&self) -> TypeInfo
fn type_info(&self) -> TypeInfo
TypeInfo.Source§fn visit_vars(&mut self, v: &mut impl VarsVisitor)
fn visit_vars(&mut self, v: &mut impl VarsVisitor)
self, as seen from the outside of self. This means
that any variable bound inside self will be skipped, and all the seen De Bruijn indices
will count from the outside of self.Source§fn substitute(self, generics: &GenericArgs) -> Self
fn substitute(self, generics: &GenericArgs) -> Self
self by replacing them with the provided values.
Note: if self is an item that comes from a TraitDecl, you must use
substitute_with_self or substitute_inner_binder, otherwise you’ll get panics.Source§fn substitute_inner_binder(self, generics: &GenericArgs) -> Self
fn substitute_inner_binder(self, generics: &GenericArgs) -> Self
self by replacing them with the provided values.
This is appropriate when substituting an inner binder.Source§fn substitute_explicits(self, generics: &GenericArgs) -> Self
fn substitute_explicits(self, generics: &GenericArgs) -> Self
Source§fn substitute_with_self(
self,
generics: &GenericArgs,
self_ref: &TraitRefKind,
) -> Self
fn substitute_with_self( self, generics: &GenericArgs, self_ref: &TraitRefKind, ) -> Self
TraitRefKind::SelfId trait ref.Source§fn substitute_with_tref(self, tref: &TraitRef) -> Self
fn substitute_with_tref(self, tref: &TraitRef) -> Self
TraitRefKind::SelfId trait ref.Source§fn try_substitute_with_tref(
self,
tref: &TraitRef,
) -> Result<Self, GenericsMismatch>
fn try_substitute_with_tref( self, tref: &TraitRef, ) -> Result<Self, GenericsMismatch>
TraitRefKind::SelfId trait ref.fn try_substitute( self, generics: &GenericArgs, ) -> Result<Self, GenericsMismatch>
fn try_substitute_with_self( self, generics: &GenericArgs, self_ref: &TraitRefKind, ) -> Result<Self, GenericsMismatch>
Source§fn move_under_binder(self) -> Self
fn move_under_binder(self) -> Self
Source§fn move_under_binders(self, depth: DeBruijnId) -> Self
fn move_under_binders(self, depth: DeBruijnId) -> Self
depth binders.Source§fn move_from_under_binder(self) -> Option<Self>
fn move_from_under_binder(self) -> Option<Self>
Source§fn move_from_under_binders(self, depth: DeBruijnId) -> Option<Self>
fn move_from_under_binders(self, depth: DeBruijnId) -> Option<Self>
depth binders. Returns None if it contains a variable bound in
one of these depth binders.Source§fn visit_db_id<B>(
&mut self,
f: impl FnMut(&mut DeBruijnId) -> ControlFlow<B>,
) -> ControlFlow<B>
fn visit_db_id<B>( &mut self, f: impl FnMut(&mut DeBruijnId) -> ControlFlow<B>, ) -> ControlFlow<B>
self, as seen from the outside of self. This means
that any variable bound inside self will be skipped, and all the seen indices will count
from the outside of self.Source§fn collect_regions(&self) -> impl Iterator<Item = Region>
fn collect_regions(&self) -> impl Iterator<Item = Region>
self.