pub struct UnificationTable { /* private fields */ }Expand description
Union-Find table implementing Robinson unification with occurs check.
Type variables are allocated by fresh and resolved by find.
zonk fully resolves a type after inference, converting remaining
unbound variables to InferType::Unknown (which maps to LogosType::Unknown).
Implementations§
Source§impl UnificationTable
impl UnificationTable
pub fn new() -> Self
Sourcepub fn fresh(&mut self) -> InferType
pub fn fresh(&mut self) -> InferType
Allocate a fresh unbound type variable, returning the wrapped InferType.
Sourcepub fn fresh_var(&mut self) -> TyVar
pub fn fresh_var(&mut self) -> TyVar
Allocate a fresh unbound type variable, returning the raw TyVar.
Sourcepub fn instantiate(&mut self, scheme: &TypeScheme) -> InferType
pub fn instantiate(&mut self, scheme: &TypeScheme) -> InferType
Instantiate a TypeScheme by replacing each quantified variable with a fresh one.
Each call site of a generic function gets independent fresh variables so that
two calls to identity(42) and identity(true) do not interfere.
Sourcepub fn find(&self, tv: TyVar) -> InferType
pub fn find(&self, tv: TyVar) -> InferType
Follow the binding chain for a type variable (iterative, no path compression).
Sourcepub fn resolve(&self, ty: &InferType) -> InferType
pub fn resolve(&self, ty: &InferType) -> InferType
Resolve type variables, keeping unbound variables as Var(tv).
Unlike zonk, this does not convert unbound variables to Unknown.
Use this during inference to preserve generic type params as Var(tv)
so they can be unified at call sites.
Sourcepub fn zonk(&self, ty: &InferType) -> InferType
pub fn zonk(&self, ty: &InferType) -> InferType
Fully resolve all type variables in a type.
Unbound variables become InferType::Unknown, which maps to
LogosType::Unknown when converted by to_logos_type.
Sourcepub fn to_logos_type(&self, ty: &InferType) -> LogosType
pub fn to_logos_type(&self, ty: &InferType) -> LogosType
Zonk then convert to LogosType. Unsolved variables become Unknown.
Auto Trait Implementations§
impl Freeze for UnificationTable
impl RefUnwindSafe for UnificationTable
impl Send for UnificationTable
impl Sync for UnificationTable
impl Unpin for UnificationTable
impl UnsafeUnpin for UnificationTable
impl UnwindSafe for UnificationTable
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.