forked from M-Labs/nac3
1
0
Fork 0

added documentation

This commit is contained in:
pca006132 2021-07-16 14:34:52 +08:00
parent 8b078dfa1b
commit f4121b570d
2 changed files with 8 additions and 0 deletions

View File

@ -177,6 +177,7 @@ mod test {
]
; "record obj merge"
)]
/// Test cases for valid unifications.
fn test_unify(
variable_count: u32,
unify_pairs: &[(&'static str, &'static str)],
@ -249,6 +250,7 @@ mod test {
(("v1", "v2"), "Recursive type is prohibited.")
; "recursive type for lists"
)]
/// Test cases for invalid unifications.
fn test_invalid_unification(
variable_count: u32,
unify_pairs: &[(&'static str, &'static str)],

View File

@ -225,6 +225,7 @@ impl Unifier {
table.probe_value(a).0
}
/// Unify two types, i.e. a = b.
pub fn unify(&self, mut a: Type, mut b: Type) -> Result<(), String> {
let (mut ty_a_cell, mut ty_b_cell) = {
let mut table = self.unification_table.borrow_mut();
@ -467,6 +468,10 @@ impl Unifier {
Ok(())
}
/// Substitute type variables within a type into other types.
/// If this returns Some(T), T would be the substituted type.
/// If this returns None, the result type would be the original type
/// (no substitution has to be done).
pub fn subst(&self, a: Type, mapping: &VarMap) -> Option<Type> {
let ty_cell = self.unification_table.borrow_mut().probe_value(a);
let ty = ty_cell.borrow();
@ -577,6 +582,7 @@ impl Unifier {
map2
}
/// Check whether two types are equal.
pub fn eq(&self, a: Type, b: Type) -> bool {
if a == b {
return true;