From f4121b570dcce12adc1ef8af609c97ef9b504ac2 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 16 Jul 2021 14:34:52 +0800 Subject: [PATCH] added documentation --- nac3core/src/typecheck/test_typedef.rs | 2 ++ nac3core/src/typecheck/typedef.rs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/nac3core/src/typecheck/test_typedef.rs b/nac3core/src/typecheck/test_typedef.rs index a8f5e68fb..b61bdb991 100644 --- a/nac3core/src/typecheck/test_typedef.rs +++ b/nac3core/src/typecheck/test_typedef.rs @@ -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)], diff --git a/nac3core/src/typecheck/typedef.rs b/nac3core/src/typecheck/typedef.rs index d105e9470..b7fd33a66 100644 --- a/nac3core/src/typecheck/typedef.rs +++ b/nac3core/src/typecheck/typedef.rs @@ -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 { 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;