mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-03 10:23:20 +00:00
refactor: inst (instance) -> imp (impl)
This commit is contained in:
parent
b40666d618
commit
a5ce33f2c4
8 changed files with 38 additions and 18 deletions
|
@ -260,9 +260,9 @@ impl Context {
|
|||
|
||||
fn _find_compatible_glue_patch(&self, sup: &Type, sub: &Type) -> Option<&Context> {
|
||||
for patch in self.all_patches().into_iter() {
|
||||
if let ContextKind::GluePatch(tr_inst) = &patch.kind {
|
||||
if self.subtype_of(sub, &tr_inst.sub_type)
|
||||
&& self.subtype_of(&tr_inst.sup_trait, sup)
|
||||
if let ContextKind::GluePatch(tr_impl) = &patch.kind {
|
||||
if self.subtype_of(sub, &tr_impl.sub_type)
|
||||
&& self.subtype_of(&tr_impl.sup_trait, sup)
|
||||
{
|
||||
return Some(patch);
|
||||
}
|
||||
|
|
|
@ -868,9 +868,8 @@ impl Context {
|
|||
|
||||
fn mono_class_trait_impl_exist(&self, class: &Type, trait_: &Type) -> bool {
|
||||
let mut super_exists = false;
|
||||
for inst in self.get_trait_impls(trait_).into_iter() {
|
||||
if self.supertype_of(&inst.sub_type, class)
|
||||
&& self.supertype_of(&inst.sup_trait, trait_)
|
||||
for imp in self.get_trait_impls(trait_).into_iter() {
|
||||
if self.supertype_of(&imp.sub_type, class) && self.supertype_of(&imp.sup_trait, trait_)
|
||||
{
|
||||
super_exists = true;
|
||||
break;
|
||||
|
@ -881,9 +880,8 @@ impl Context {
|
|||
|
||||
fn poly_class_trait_impl_exists(&self, class: &Type, trait_: &Type) -> bool {
|
||||
let mut super_exists = false;
|
||||
for inst in self.get_trait_impls(trait_).into_iter() {
|
||||
if self.supertype_of(&inst.sub_type, class)
|
||||
&& self.supertype_of(&inst.sup_trait, trait_)
|
||||
for imp in self.get_trait_impls(trait_).into_iter() {
|
||||
if self.supertype_of(&imp.sub_type, class) && self.supertype_of(&imp.sup_trait, trait_)
|
||||
{
|
||||
super_exists = true;
|
||||
break;
|
||||
|
|
|
@ -841,12 +841,12 @@ impl Context {
|
|||
.insert(method_name.clone(), vec![name.clone()]);
|
||||
}
|
||||
}
|
||||
if let ContextKind::GluePatch(tr_inst) = &ctx.kind {
|
||||
if let Some(impls) = self.trait_impls().get_mut(&tr_inst.sup_trait.qual_name()) {
|
||||
impls.insert(tr_inst.clone());
|
||||
if let ContextKind::GluePatch(tr_impl) = &ctx.kind {
|
||||
if let Some(impls) = self.trait_impls().get_mut(&tr_impl.sup_trait.qual_name()) {
|
||||
impls.insert(tr_impl.clone());
|
||||
} else {
|
||||
self.trait_impls()
|
||||
.register(tr_inst.sup_trait.qual_name(), set![tr_inst.clone()]);
|
||||
.register(tr_impl.sup_trait.qual_name(), set![tr_impl.clone()]);
|
||||
}
|
||||
}
|
||||
self.patches.insert(name, ctx);
|
||||
|
|
|
@ -2606,9 +2606,9 @@ impl Context {
|
|||
|
||||
fn get_trait_proj_candidates(&self, trait_: &Type, rhs: &Str) -> Set<Type> {
|
||||
let impls = self.get_trait_impls(trait_);
|
||||
let candidates = impls.into_iter().filter_map(move |inst| {
|
||||
if self.supertype_of(&inst.sup_trait, trait_) {
|
||||
self.eval_t_params(proj(inst.sub_type, rhs), self.level, &())
|
||||
let candidates = impls.into_iter().filter_map(move |imp| {
|
||||
if self.supertype_of(&imp.sup_trait, trait_) {
|
||||
self.eval_t_params(proj(imp.sub_type, rhs), self.level, &())
|
||||
.ok()
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
use erg_common::traits::StructuralEq;
|
||||
use erg_common::Str;
|
||||
|
||||
use crate::ty::constructors::{func1, mono, mono_q, poly, refinement};
|
||||
use crate::ty::constructors::{func1, mono, mono_q, poly, refinement, ty_tp};
|
||||
use crate::ty::free::Constraint;
|
||||
use crate::ty::typaram::TyParam;
|
||||
use crate::ty::{Predicate, Type};
|
||||
|
@ -85,4 +85,14 @@ impl Context {
|
|||
assert_eq!(quantified, quantified_again);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn test_patch(&self) -> Result<(), ()> {
|
||||
use crate::ty::constructors::or;
|
||||
assert!(self.subtype_of(&Int, &mono("Eq")));
|
||||
assert!(self.subtype_of(&or(Int, NoneType), &mono("Eq")));
|
||||
assert!(!self.subtype_of(&or(Int, Float), &mono("Eq")));
|
||||
assert!(self.subtype_of(&Int, &poly("Sub", vec![ty_tp(Int)])));
|
||||
assert!(self.subtype_of(&Nat, &poly("Sub", vec![ty_tp(Nat)])));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue