This commit is contained in:
Shunsuke Shibayama 2022-09-05 11:11:57 +09:00
parent 25094efd17
commit fb0d2f5737
7 changed files with 23 additions and 25 deletions

View file

@ -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) => {

View file

@ -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 {

View file

@ -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

View file

@ -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) {

View file

@ -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!()