pub struct MethodContext {
pub id: DefId,
pub typ: ClassDefType,
pub ctx: Context,
}
Fields§
§id: DefId
§typ: ClassDefType
§ctx: Context
Implementations§
Source§impl MethodContext
impl MethodContext
pub const fn new(id: DefId, typ: ClassDefType, ctx: Context) -> Self
Methods from Deref<Target = Context>§
Sourcepub fn subtype_of(&self, lhs: &Type, rhs: &Type) -> bool
pub fn subtype_of(&self, lhs: &Type, rhs: &Type) -> bool
lhs <: rhs ?
e.g.
Named :> Module
=> Module.super_types == [Named]
Seq(T) :> Range(T)
=> Range(T).super_types == [Eq, Mutate, Seq(T), Output(T)]
Sourcepub fn fields(&self, t: &Type) -> Dict<Field, Type>
pub fn fields(&self, t: &Type) -> Dict<Field, Type>
Int.fields() == { imag: Int, real: Int, abs: (self: Int) -> Nat, ... }
?T(<: Int).fields() == Int.fields()
Structural({ .x = Int }).fields() == { x: Int }
Sourcepub fn diff(&self, lhs: &Type, rhs: &Type) -> Type
pub fn diff(&self, lhs: &Type, rhs: &Type) -> Type
Returns difference of two types (A - B
== A and not B
).
(A or B).diff(B) == A
pub fn eval_value_proj_call( &self, lhs: TyParam, attr_name: Str, args: Vec<TyParam>, t_loc: &impl Locational, ) -> EvalResult<Result<ValueObj, TyParam>>
pub const TOP_LEVEL: usize = 1usize
pub fn readable_type(&self, t: Type) -> Type
pub fn get_method_kv(&self, name: &str) -> Option<(&VarName, &VarInfo)>
Sourcepub fn get_singular_ctxs_by_hir_expr(
&self,
obj: &Expr,
namespace: &Context,
) -> SingleTyCheckResult<Vec<&Context>>
pub fn get_singular_ctxs_by_hir_expr( &self, obj: &Expr, namespace: &Context, ) -> SingleTyCheckResult<Vec<&Context>>
get_singular_ctxs_by_hir_expr(1) == Err
get_singular_ctxs_by_hir_expr(Int) == [<type Int>, <type Type>, ...]
get_singular_ctxs_by_hir_expr(math) == [<module math>]
Sourcepub fn sort_types<'a>(
&self,
types: impl Iterator<Item = &'a Type>,
) -> Vec<&'a Type>
pub fn sort_types<'a>( &self, types: impl Iterator<Item = &'a Type>, ) -> Vec<&'a Type>
Perform types linearization. TODO: Current implementation may be very inefficient.
C3 linearization requires prior knowledge of inter-type dependencies, and cannot be used for Erg structural subtype linearization
Algorithm:
[Int, Str, Nat, Never, Obj, Str!, Module]
=> [], [Int, Str, Nat, Never, Obj, Str!, Module]
=> [[Int]], [Str, Nat, Never, Obj, Str!, Module]
# 1. If related, put them in the same array; if not, put them in different arrays.
=> [[Int], [Str]], [Nat, Never, Obj, Str!, Module]
=> ...
=> [[Int, Nat, Never, Obj]], [Str, Str!], [Module]]
# 2. Then, perform sorting on the arrays
=> [[Never, Nat, Int, Obj], [Str!, Str], [Module]]
# 3. Concatenate the arrays
=> [Never, Nat, Int, Obj, Str!, Str, Module]
# 4. From the left, "slide" types as far as it can.
=> [Never, Nat, Int, Str!, Str, Module, Obj]
Sourcepub fn min_type<'a>(
&self,
types: impl Iterator<Item = &'a Type>,
) -> Option<&'a Type>
pub fn min_type<'a>( &self, types: impl Iterator<Item = &'a Type>, ) -> Option<&'a Type>
Returns the smallest type among the iterators of a given type.
If there is no subtype relationship, returns None
.
min_type([Int, Int]) == Int
min_type([Int, Nat]) == Nat
min_type([Int, Str]) == None
min_type([Int, Str, Nat]) == None
Sourcepub fn max_type<'a>(
&self,
types: impl Iterator<Item = &'a Type>,
) -> Option<&'a Type>
pub fn max_type<'a>( &self, types: impl Iterator<Item = &'a Type>, ) -> Option<&'a Type>
Returns the largest type among the iterators of a given type.
If there is no subtype relationship, returns None
.
max_type([Int, Int]) == Int
max_type([Int, Nat]) == Int
max_type([Int, Str]) == None
max_type([Int, Str, Nat]) == None
pub fn min_by_type<T>(&self, types: Vec<(T, Type)>) -> Option<(T, Type)>
pub fn max_by_type<T>(&self, types: Vec<(T, Type)>) -> Option<(T, Type)>
Sourcepub fn get_nominal_super_type_ctxs<'a>(
&'a self,
t: &Type,
) -> Option<Vec<&'a TypeContext>>
pub fn get_nominal_super_type_ctxs<'a>( &'a self, t: &Type, ) -> Option<Vec<&'a TypeContext>>
get_nominal_super_type_ctxs(Nat) == [<Nat>, <Int>, <Float>, ..., <Obj>, <Eq>, ...]
# FIXME: ↓ should be [<Type>, <Obj>, <Eq>, ...]
get_nominal_super_type_ctxs({Nat}) == [<Nat>, <Int>, <Float>, ..., <Obj>, <Eq>, ...]
get_nominal_super_type_ctxs(?T(:> Nat, <: Eq)) == == [<Eq>, ...]
pub fn get_mod_with_t(&self, mod_t: &Type) -> Option<&Context>
pub fn get_type_info_by_str(&self, name: &str) -> Option<(&VarName, &VarInfo)>
pub fn partial_get_methods_by_name( &self, partial_attr: &Identifier, ) -> Vec<(&Str, &Vec<MethodPair>)>
pub fn is_class(&self, typ: &Type) -> bool
pub fn is_trait(&self, typ: &Type) -> bool
Sourcepub fn meta_type(&self, typ: &Type) -> Type
pub fn meta_type(&self, typ: &Type) -> Type
Int.meta_type() == ClassType (<: Type)
Show.meta_type() == TraitType (<: Type)
[Int; 3].meta_type() == [ClassType; 3] (<: Type)
(Int, Str).meta_type() == (ClassType, ClassType) (<: Type)
{Str: Int}.meta_type() == {ClassType: ClassType} (<: Type)
Indexable(T).meta_type() == TraitType (<: Type)
NamedTuple({ .x = Int; .y = Str }).meta_type() == NamedTuple({ .x = ClassType; .y = ClassType })
pub fn del(&mut self, ident: &Identifier) -> CompileResult<()>
pub fn assert_var_type(&self, varname: &str, ty: &Type) -> Result<(), ()>
pub fn assert_attr_type( &self, receiver_t: &Type, attr: &str, ty: &Type, ) -> Result<(), ()>
pub fn test_refinement_subtyping(&self) -> Result<(), ()>
pub fn test_quant_subtyping(&self) -> Result<(), ()>
pub fn test_resolve_trait_inner1(&self) -> Result<(), ()>
pub fn test_instantiation_and_generalization(&self) -> Result<(), ()>
pub fn test_patch(&self) -> Result<(), ()>
pub fn test_intersection(&self) -> Result<(), ()>
pub fn dir(&self) -> Dict<&VarName, &VarInfo>
pub fn get_receiver_ctx(&self, receiver_name: &str) -> Option<&Context>
pub fn get_receiver_ctxs(&self, receiver_name: &str) -> Vec<&Context>
pub fn get_var_info(&self, name: &str) -> Option<(&VarName, &VarInfo)>
pub fn has(&self, name: &str) -> bool
Sourcepub fn get_type_info(&self, typ: &Type) -> Option<(&VarName, &VarInfo)>
pub fn get_type_info(&self, typ: &Type) -> Option<(&VarName, &VarInfo)>
NOTE: Actually, this can be used for searching variables, attributes, etc.
pub fn unregister(&mut self, name: &str) -> Option<VarInfo>
pub fn caused_by(&self) -> String
pub fn is_empty(&self) -> bool
Sourcepub fn initialize(&mut self)
pub fn initialize(&mut self)
This method is intended to be called only in the top-level module.
.cfg
is not initialized and is used around.
pub fn local_dir(&self) -> Dict<&VarName, &VarInfo>
pub fn index(&self) -> &SharedModuleIndex
pub fn graph(&self) -> &SharedModuleGraph
pub fn trait_impls(&self) -> &SharedTraitImpls
pub fn promises(&self) -> &SharedPromises
pub fn current_control_flow(&self) -> Option<ControlKind>
pub fn control_kind(&self) -> Option<ControlKind>
Sourcepub fn current_true_function_ctx(&self) -> Option<&Context>
pub fn current_true_function_ctx(&self) -> Option<&Context>
Context of the function that actually creates the scope. Control flow function blocks do not create actual scopes.
Trait Implementations§
Source§impl Clone for MethodContext
impl Clone for MethodContext
Source§fn clone(&self) -> MethodContext
fn clone(&self) -> MethodContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more