Struct move_model::ty::Substitution
source · pub struct Substitution { /* private fields */ }
Expand description
A type substitution.
Implementations§
source§impl Substitution
impl Substitution
sourcepub fn specialize(&self, t: &Type) -> Type
pub fn specialize(&self, t: &Type) -> Type
Specializes the type, substituting all variables bound in this substitution.
sourcepub fn get_substitution(&self, var: u16, shallow: bool) -> Option<Type>
pub fn get_substitution(&self, var: u16, shallow: bool) -> Option<Type>
Return either a shallow or deep substitution of the type variable.
If deep substitution is requested, follow down the substitution chain until either
Some(ty)
when the final type is not a type variable orNone
when the final type variable does not have a substitution
sourcepub fn unify(
&mut self,
variance: Variance,
t1: &Type,
t2: &Type
) -> Result<Type, TypeUnificationError>
pub fn unify( &mut self, variance: Variance, t1: &Type, t2: &Type ) -> Result<Type, TypeUnificationError>
Unify two types, returning the unified type.
This currently implements the following notion of type compatibility:
-
- References are dropped (i.e. &T and T are compatible)
-
- All integer types are compatible if co-variance is allowed.
-
- With the joint effect of 1) and 2), if (P, Q) is compatible under co-variance, (&P, Q), (P, &Q), and (&P, &Q) are all compatible under co-variance.
-
- If in two tuples (P1, P2, …, Pn) and (Q1, Q2, …, Qn), all (Pi, Qi) pairs are compatible under co-variance, then the two tuples are compatible under co-variance.
The substitution will be refined by variable assignments as needed to perform unification. If unification fails, the substitution will be in some intermediate state; to implement transactional unification, the substitution must be cloned before calling this.
Trait Implementations§
source§impl Clone for Substitution
impl Clone for Substitution
source§fn clone(&self) -> Substitution
fn clone(&self) -> Substitution
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more