diff --git a/compiler/erg_compiler/context/compare.rs b/compiler/erg_compiler/context/compare.rs index 62db69e0..07c71039 100644 --- a/compiler/erg_compiler/context/compare.rs +++ b/compiler/erg_compiler/context/compare.rs @@ -232,7 +232,7 @@ impl Context { { (Absolutely, true) } - (_, Type::FreeVar(fv)) | (Type::FreeVar(fv), _) => match fv.crack_bound_types() { + (_, Type::FreeVar(fv)) | (Type::FreeVar(fv), _) => match fv.get_bound_types() { Some((Type::Never, Type::Obj)) => (Absolutely, true), _ => (Maybe, false), }, @@ -335,7 +335,7 @@ impl Context { /// assert sup_conforms(?E(<: Eq(?R)), base: T, sup_trait: Eq(U)) /// ``` fn sup_conforms(&self, free: &FreeTyVar, base: &Type, sup_trait: &Type) -> bool { - let (_sub, sup) = free.crack_bound_types().unwrap(); + let (_sub, sup) = free.get_bound_types().unwrap(); free.forced_undoable_link(base); let judge = self.supertype_of(&sup, sup_trait); free.undo(); @@ -345,7 +345,7 @@ impl Context { /// assert!(sup_conforms(?E(<: Eq(?E)), {Nat, Eq(Nat)})) /// assert!(sup_conforms(?E(<: Eq(?R)), {Nat, Eq(T)})) fn _sub_conforms(&self, free: &FreeTyVar, inst_pair: &TraitInstance) -> bool { - let (_sub, sup) = free.crack_bound_types().unwrap(); + let (_sub, sup) = free.get_bound_types().unwrap(); log!(info "{free}"); free.forced_undoable_link(&inst_pair.sub_type); log!(info "{free}"); @@ -403,20 +403,18 @@ impl Context { } // ?T(<: Nat) !:> ?U(:> Int) // ?T(<: Nat) :> ?U(<: Int) (?U can be smaller than ?T) - (FreeVar(lfv), FreeVar(rfv)) => { - match (lfv.crack_bound_types(), rfv.crack_bound_types()) { - (Some((_, l_sup)), Some((r_sub, _))) => self.supertype_of(&l_sup, &r_sub), - _ => { - if lfv.is_linked() { - self.supertype_of(&lfv.crack(), rhs) - } else if rfv.is_linked() { - self.supertype_of(lhs, &rfv.crack()) - } else { - false - } + (FreeVar(lfv), FreeVar(rfv)) => match (lfv.get_bound_types(), rfv.get_bound_types()) { + (Some((_, l_sup)), Some((r_sub, _))) => self.supertype_of(&l_sup, &r_sub), + _ => { + if lfv.is_linked() { + self.supertype_of(&lfv.crack(), rhs) + } else if rfv.is_linked() { + self.supertype_of(lhs, &rfv.crack()) + } else { + false } } - } + }, // true if it can be a supertype, false if it cannot (due to type constraints) // No type constraints are imposed here, as subsequent type decisions are made according to the possibilities (FreeVar(lfv), rhs) => { diff --git a/compiler/erg_compiler/context/hint.rs b/compiler/erg_compiler/context/hint.rs index 4a121cff..38999882 100644 --- a/compiler/erg_compiler/context/hint.rs +++ b/compiler/erg_compiler/context/hint.rs @@ -10,7 +10,7 @@ impl Context { if fv.is_linked() { fv.crack().clone() } else { - let (_sub, sup) = fv.crack_bound_types().unwrap(); + let (_sub, sup) = fv.get_bound_types().unwrap(); sup } } else { diff --git a/compiler/erg_compiler/context/instantiate.rs b/compiler/erg_compiler/context/instantiate.rs index 130d5c87..ee69be4a 100644 --- a/compiler/erg_compiler/context/instantiate.rs +++ b/compiler/erg_compiler/context/instantiate.rs @@ -303,7 +303,7 @@ impl TyVarContext { } fn check_cyclicity_and_link(&self, name: &str, fv_inst: &FreeTyVar, tv: &Type) { - let (sub, sup) = enum_unwrap!(tv, Type::FreeVar).crack_bound_types().unwrap(); + let (sub, sup) = enum_unwrap!(tv, Type::FreeVar).get_bound_types().unwrap(); let new_cyclicity = match (sup.contains_tvar(name), sub.contains_tvar(name)) { (true, true) => Cyclicity::Both, // T <: Super diff --git a/compiler/erg_compiler/context/tyvar.rs b/compiler/erg_compiler/context/tyvar.rs index d8c607d9..d7ef9e8a 100644 --- a/compiler/erg_compiler/context/tyvar.rs +++ b/compiler/erg_compiler/context/tyvar.rs @@ -986,9 +986,9 @@ impl Context { (Type::FreeVar(lfv), Type::FreeVar(rfv)) if lfv.constraint_is_sandwiched() && rfv.constraint_is_sandwiched() => { - let (lsub, lsup) = lfv.crack_bound_types().unwrap(); + let (lsub, lsup) = lfv.get_bound_types().unwrap(); let l_cyc = lfv.cyclicity(); - let (rsub, rsup) = rfv.crack_bound_types().unwrap(); + let (rsub, rsup) = rfv.get_bound_types().unwrap(); let r_cyc = rfv.cyclicity(); let cyclicity = l_cyc.combine(r_cyc); let new_constraint = if let Some(min) = self.min(&lsup, &rsup) { diff --git a/compiler/erg_compiler/eval.rs b/compiler/erg_compiler/eval.rs index fe1494d0..81359a45 100644 --- a/compiler/erg_compiler/eval.rs +++ b/compiler/erg_compiler/eval.rs @@ -609,7 +609,7 @@ impl Context { TyParam::Value(v) => Ok(enum_t(set![v])), TyParam::Erased(t) => Ok((*t).clone()), TyParam::FreeVar(fv) => { - if let Some(t) = fv.type_of() { + if let Some(t) = fv.get_type() { Ok(t) } else { todo!() @@ -637,7 +637,7 @@ impl Context { TyParam::Value(v) => Ok(v.class()), TyParam::Erased(t) => Ok((*t).clone()), TyParam::FreeVar(fv) => { - if let Some(t) = fv.type_of() { + if let Some(t) = fv.get_type() { Ok(t) } else { todo!() diff --git a/compiler/erg_type/free.rs b/compiler/erg_type/free.rs index 1ce5703e..8cd0d05c 100644 --- a/compiler/erg_type/free.rs +++ b/compiler/erg_type/free.rs @@ -512,19 +512,19 @@ impl Free { }) } - pub fn type_of(&self) -> Option { + pub fn get_type(&self) -> Option { self.borrow() .constraint() .and_then(|c| c.get_type().cloned()) } - pub fn crack_sup(&self) -> Option { + pub fn get_sup(&self) -> Option { self.borrow() .constraint() .and_then(|c| c.get_super().cloned()) } - pub fn crack_bound_types(&self) -> Option<(Type, Type)> { + pub fn get_bound_types(&self) -> Option<(Type, Type)> { self.borrow() .constraint() .and_then(|c| c.get_sub_sup().map(|(sub, sup)| (sub.clone(), sup.clone()))) diff --git a/compiler/erg_type/lib.rs b/compiler/erg_type/lib.rs index 0be7ed5c..3578e780 100644 --- a/compiler/erg_type/lib.rs +++ b/compiler/erg_type/lib.rs @@ -1715,7 +1715,7 @@ impl Type { Self::FreeVar(fv) => { fv.unbound_name().map(|n| &n[..] == name).unwrap_or(false) || fv - .crack_bound_types() + .get_bound_types() .map(|(sub, sup)| sub.contains_tvar(name) || sup.contains_tvar(name)) .unwrap_or(false) }