pub enum Type {
Show 42 variants
Obj,
Int,
Nat,
Ratio,
Float,
Complex,
Bool,
Str,
NoneType,
Code,
Frame,
Error,
Inf,
NegInf,
Type,
ClassType,
TraitType,
Patch,
NotImplementedType,
Ellipsis,
Never,
Mono(Str),
Ref(Box<Type>),
RefMut {
before: Box<Type>,
after: Option<Box<Type>>,
},
Subr(SubrType),
Callable {
param_ts: Vec<Type>,
return_t: Box<Type>,
},
Record(Dict<Field, Type>),
Refinement(RefinementType),
Quantified(Box<Type>),
And(Vec<Type>, Option<usize>),
Or(Set<Type>),
Not(Box<Type>),
Poly {
name: Str,
params: Vec<TyParam>,
},
NamedTuple(Vec<(Field, Type)>),
Proj {
lhs: Box<Type>,
rhs: Str,
},
ProjCall {
lhs: Box<TyParam>,
attr_name: Str,
args: Vec<TyParam>,
},
Structural(Box<Type>),
Guard(GuardType),
Bounded {
sub: Box<Type>,
sup: Box<Type>,
},
FreeVar(FreeTyVar),
Failure,
Uninited,
}
Variants§
Obj
Int
Nat
Ratio
Float
Complex
Bool
Str
NoneType
Code
Frame
Error
Inf
NegInf
Type
ClassType
TraitType
Patch
NotImplementedType
Ellipsis
Never
Mono(Str)
Ref(Box<Type>)
RefMut
Subr(SubrType)
Callable
Record(Dict<Field, Type>)
Refinement(RefinementType)
Quantified(Box<Type>)
And(Vec<Type>, Option<usize>)
usize: default type index
Or(Set<Type>)
Not(Box<Type>)
Poly
NamedTuple(Vec<(Field, Type)>)
Proj
ProjCall
Structural(Box<Type>)
Guard(GuardType)
Bounded
FreeVar(FreeTyVar)
Failure
for all T, T <: Failure and T :> Failure
Uninited
used to represent TyParam
is not initialized (see erg_compiler::context::instantiate_tp
)
Implementations§
Source§impl Type
impl Type
pub const OBJ: &'static Self = _
pub const NONE: &'static Self = _
pub const NOT_IMPLEMENTED: &'static Self = _
pub const ELLIPSIS: &'static Self = _
pub const INF: &'static Self = _
pub const NEG_INF: &'static Self = _
pub const NEVER: &'static Self = _
pub const FAILURE: &'static Self = _
pub fn mutate(self) -> Self
pub fn immutate(&self) -> Option<Self>
pub fn checked_or(tys: Set<Type>) -> Self
pub fn checked_and(tys: Vec<Type>, idx: Option<usize>) -> Self
pub fn quantify(self) -> Self
pub fn proj<S: Into<Str>>(self, attr: S) -> Self
pub fn structuralize(self) -> Self
pub fn bounded(sub: Type, sup: Type) -> Self
pub fn into_ref(self) -> Self
pub fn into_ref_mut(self, after: Option<Self>) -> Self
pub fn is_mono_value_class(&self) -> bool
Sourcepub fn is_value_class(&self) -> bool
pub fn is_value_class(&self) -> bool
value class := mono value object class | (List | Set)(value class)
pub fn is_mut_value_class(&self) -> bool
Sourcepub fn is_procedure(&self) -> bool
pub fn is_procedure(&self) -> bool
Procedure
pub fn is_mut_type(&self) -> bool
pub fn is_nonelike(&self) -> bool
pub fn is_nonetype(&self) -> bool
pub fn is_singleton(&self) -> bool
pub fn is_union_type(&self) -> bool
pub fn is_proj(&self) -> bool
pub fn has_proj(&self) -> bool
pub fn is_proj_call(&self) -> bool
pub fn has_proj_call(&self) -> bool
pub fn is_intersection_type(&self) -> bool
Sourcepub fn union_size(&self) -> usize
pub fn union_size(&self) -> usize
Int.union_size() == 1
(Int or Str).union_size() == 2
K(Int or Str, Int or Str or NoneType) == 3
pub fn is_refinement(&self) -> bool
pub fn is_singleton_refinement(&self) -> bool
pub fn is_singleton_refinement_type(&self) -> bool
pub fn is_record(&self) -> bool
pub fn is_module(&self) -> bool
pub fn is_erg_module(&self) -> bool
pub fn is_py_module(&self) -> bool
pub fn is_method(&self) -> bool
pub fn is_subr(&self) -> bool
pub fn subr_kind(&self) -> Option<SubrKind>
pub fn is_quantified_subr(&self) -> bool
pub fn is_list(&self) -> bool
pub fn is_unsized_list(&self) -> bool
pub fn is_guard(&self) -> bool
pub fn is_list_mut(&self) -> bool
pub fn is_iterable(&self) -> bool
pub fn is_tuple(&self) -> bool
pub fn is_named_tuple(&self) -> bool
pub fn is_set(&self) -> bool
pub fn is_dict(&self) -> bool
pub fn is_dict_mut(&self) -> bool
pub fn is_range(&self) -> bool
pub fn is_ref(&self) -> bool
pub fn ref_inner(&self) -> Option<Type>
pub fn is_refmut(&self) -> bool
pub fn ref_mut_inner(&self) -> Option<Type>
pub fn is_structural(&self) -> bool
pub fn is_failure(&self) -> bool
pub fn is_class_type(&self) -> bool
Sourcepub fn is_type(&self) -> bool
pub fn is_type(&self) -> bool
NOTE: don’t use this, use Context::subtype_of(t, &Type::Type)
instead
pub fn is_poly_meta_type(&self) -> bool
pub fn as_free(&self) -> Option<&FreeTyVar>
pub fn into_free(self) -> Option<FreeTyVar>
pub fn contains_tvar(&self, target: &FreeTyVar) -> bool
pub fn has_type_satisfies(&self, f: impl Fn(&Type) -> bool + Copy) -> bool
pub fn contains_tvar_in_constraint(&self, target: &FreeTyVar) -> bool
pub fn contains_type(&self, target: &Type) -> bool
pub fn contains_tp(&self, target: &TyParam) -> bool
pub fn contains_value(&self, target: &ValueObj) -> bool
pub fn contains_failure(&self) -> bool
pub fn has_refinement(&self) -> bool
pub fn is_recursive(&self) -> bool
pub fn args_ownership(&self) -> ArgsOwnership
pub fn ownership(&self) -> Ownership
Sourcepub fn qual_name(&self) -> Str
pub fn qual_name(&self) -> Str
full name of the type, if the type is a normal nominal type, then returns the inner name
let i = mono("Int!");
assert_eq!(&i.qual_name()[..], "Int!");
assert_eq!(&i.local_name()[..], "Int!");
let t = mono("http.client.Response");
assert_eq!(&t.qual_name()[..], "http.client.Response");
assert_eq!(&t.local_name()[..], "Response");
let r = Type::from(TyParam::from(1)..TyParam::from(10));
assert_eq!(&r.qual_name()[..], "Int");
Sourcepub fn namespace(&self) -> Str
pub fn namespace(&self) -> Str
let i = mono("Int!");
assert_eq!(&i.namespace()[..], "");
let t = mono("http.client.Response");
assert_eq!(&t.namespace()[..], "http.client");
Sourcepub fn local_name(&self) -> Str
pub fn local_name(&self) -> Str
local name of the type
let i = mono("Int!");
assert_eq!(&i.qual_name()[..], "Int!");
assert_eq!(&i.local_name()[..], "Int!");
let t = mono("http.client.Response");
assert_eq!(&t.qual_name()[..], "http.client.Response");
assert_eq!(&t.local_name()[..], "Response");
Sourcepub fn contains_intersec(&self, typ: &Type) -> bool
pub fn contains_intersec(&self, typ: &Type) -> bool
assert!((A and B).contains_intersec(B))
pub fn union_pair(&self) -> Option<(Type, Type)>
pub fn union_types(&self) -> Option<Set<Type>>
Sourcepub fn contains_union(&self, typ: &Type) -> bool
pub fn contains_union(&self, typ: &Type) -> bool
assert!((A or B).contains_union(B))
pub fn intersection_types(&self) -> Vec<Type>
pub fn default_intersection_type(&self) -> Option<Type>
pub fn with_default_intersec_index(self, idx: usize) -> Self
pub fn tvar_name(&self) -> Option<Str>
pub fn q_constraint(&self) -> Option<Constraint>
pub fn get_meta_type(&self) -> Option<Type>
pub const fn is_free_var(&self) -> bool
pub fn is_callable(&self) -> bool
pub fn is_unbound_var(&self) -> bool
pub fn is_named_unbound_var(&self) -> bool
pub fn is_unnamed_unbound_var(&self) -> bool
Sourcepub fn is_totally_unbound(&self) -> bool
pub fn is_totally_unbound(&self) -> bool
assert (?T or ?U).totally_unbound()
Sourcepub fn is_monomorphic(&self) -> bool
pub fn is_monomorphic(&self) -> bool
See also: is_monomorphized
Sourcepub fn is_monomorphized(&self) -> bool
pub fn is_monomorphized(&self) -> bool
Set(Int, 3)
is not monomorphic but monomorphized
pub fn is_polymorphic(&self) -> bool
Sourcepub fn into_refinement(self) -> RefinementType
pub fn into_refinement(self) -> RefinementType
TODO:
Nat == {x: Int | x >= 0}
Nat or {-1} == {x: Int | x >= 0 or x == -1}
Int == {_: Int | True}
Sourcepub fn to_singleton(&self) -> Option<RefinementType>
pub fn to_singleton(&self) -> Option<RefinementType>
{ .x = {Int} } == {{ .x = Int }}
K({Int}) == {K(Int)} # TODO
pub fn deconstruct_refinement(self) -> Result<(Str, Type, Predicate), Type>
Sourcepub fn destructive_coerce(&self)
pub fn destructive_coerce(&self)
Fix type variables at their lower bound
i: ?T(:> Int)
assert i.Real == 1
i: (Int)
?T(:> ?U(:> Int)).coerce(): ?T == ?U == Int
TODO: ?T(:> Int) or ?U(>: Int) == Int
pub fn undoable_coerce(&self, list: &UndoableLinkedList)
pub fn coerce(&self, list: Option<&UndoableLinkedList>)
Sourcepub fn qvars(&self) -> Set<(Str, Constraint)>
pub fn qvars(&self) -> Set<(Str, Constraint)>
returns top-level qvars.
see also: qvars_inner
pub fn qnames(&self) -> Set<Str>
pub fn has_uninited_qvars(&self) -> bool
pub fn is_qvar(&self) -> bool
Sourcepub fn has_qvar(&self) -> bool
pub fn has_qvar(&self) -> bool
if the type is polymorphic
assert ('T -> Int).has_qvar()
assert not (|T| T -> T).has_qvar()
pub fn is_undoable_linked_var(&self) -> bool
pub fn has_undoable_linked_var(&self) -> bool
pub fn has_no_qvar(&self) -> bool
pub fn has_unbound_var(&self) -> bool
pub fn has_no_unbound_var(&self) -> bool
pub fn is_meta_type(&self) -> bool
pub fn typarams_len(&self) -> Option<usize>
pub fn singleton_value(&self) -> Option<&TyParam>
pub fn refinement_values(&self) -> Option<Vec<&TyParam>>
pub fn container_len(&self) -> Option<usize>
pub fn typarams(&self) -> Vec<TyParam>
pub fn self_t(&self) -> Option<&Type>
pub fn mut_self_t(&mut self) -> Option<&mut Type>
pub fn non_default_params(&self) -> Option<&Vec<ParamTy>>
pub fn var_params(&self) -> Option<&ParamTy>
pub fn default_params(&self) -> Option<&Vec<ParamTy>>
pub fn kw_var_params(&self) -> Option<&ParamTy>
pub fn non_var_params(&self) -> Option<impl Iterator<Item = &ParamTy> + Clone>
pub fn param_ts(&self) -> Vec<Type>
pub fn return_t(&self) -> Option<&Type>
pub fn tyvar_mut_return_t(&mut self) -> Option<RefMut<'_, Type>>
pub fn mut_return_t(&mut self) -> Option<&mut Type>
Sourcepub fn derefine(&self) -> Type
pub fn derefine(&self) -> Type
{1, 2, 3}.derifine() == Nat
List({1, 2, 3}).derifine() == List(Nat)
?T(:> {1, 2, 3}).derifine() == ?T'(:> Nat)
pub fn replace(self, target: &Type, to: &Type) -> Type
Sourcepub fn replace_failure_type(&self) -> Type
pub fn replace_failure_type(&self) -> Type
(Failure -> Int).replace_failure_type() == (Obj -> Int)
(Int -> Failure).replace_failure_type() == (Int -> Never)
List(Failure, 3).replace_failure_type() == List(Never, 3)
Sourcepub fn replace_failure(&self) -> Type
pub fn replace_failure(&self) -> Type
Int.replace_failure() == Int
K(Failure).replace_failure() == K(Never)
{<failure>}.replace_failure() == Never
K(<Failure>).replace_failure() == Never
pub fn try_map_tp<E>( self, f: &mut impl FnMut(TyParam) -> Result<TyParam, E>, tvs: &SharedFrees, ) -> Result<Type, E>
pub fn eliminate_and_or(&mut self)
pub fn replace_params<'l, 'r>( self, target: impl Iterator<Item = &'l str>, to: impl Iterator<Item = &'r str>, ) -> Self
Sourcepub fn lower_bounded(&self) -> Type
pub fn lower_bounded(&self) -> Type
assert Int.lower_bounded() == Int
assert ?T(:> Str).lower_bounded() == Str
assert (?T(:> Str) or ?U(:> Int)).lower_bounded() == (Str or Int)
Sourcepub fn upper_bounded(&self) -> Type
pub fn upper_bounded(&self) -> Type
assert Int.upper_bounded() == Int
assert ?T(<: Str).upper_bounded() == Str
assert (?T(<: Str) or ?U(<: Int)).upper_bounded() == (Str or Int)
pub fn into_bounded(&self) -> Type
Sourcepub fn contained_ts(&self) -> Set<Type>
pub fn contained_ts(&self) -> Set<Type>
Int.contained_ts() == {Int}
List(List(Int)).contained_ts() == {List(Int), Int}
(Int or Str).contained_ts() == {Int, Str}
pub fn dereference(&mut self)
pub fn module_path(&self) -> Option<PathBuf>
pub fn variables(&self) -> Set<Str>
Trait Implementations§
Source§impl CanbeFree for Type
impl CanbeFree for Type
fn unbound_name(&self) -> Option<Str>
fn unbound_id(&self) -> Option<usize>
fn constraint(&self) -> Option<Constraint>
fn destructive_update_constraint( &self, new_constraint: Constraint, in_instantiation: bool, )
Source§impl From<RangeInclusive<&TyParam>> for Type
impl From<RangeInclusive<&TyParam>> for Type
Source§fn from(r: RangeInclusive<&TyParam>) -> Self
fn from(r: RangeInclusive<&TyParam>) -> Self
Converts to this type from the input type.
Source§impl From<RangeInclusive<TyParam>> for Type
impl From<RangeInclusive<TyParam>> for Type
Source§fn from(r: RangeInclusive<TyParam>) -> Self
fn from(r: RangeInclusive<TyParam>) -> Self
Converts to this type from the input type.
Source§impl From<RefinementType> for Type
impl From<RefinementType> for Type
Source§fn from(refine: RefinementType) -> Self
fn from(refine: RefinementType) -> Self
Converts to this type from the input type.
Source§impl HasType for Type
impl HasType for Type
fn ref_t(&self) -> &Type
fn ref_mut_t(&mut self) -> Option<&mut Type>
fn inner_ts(&self) -> Vec<Type>
fn signature_t(&self) -> Option<&Type>
fn signature_mut_t(&mut self) -> Option<&mut Type>
fn t(&self) -> Type
fn lhs_t(&self) -> &Type
fn rhs_t(&self) -> &Type
Source§impl LimitedDisplay for Type
impl LimitedDisplay for Type
Source§fn limited_fmt<W: Write>(&self, f: &mut W, limit: isize) -> Result
fn limited_fmt<W: Write>(&self, f: &mut W, limit: isize) -> Result
If
limit
was set to a negative value, it will be displayed without abbreviation.
FIXME:fn to_string_unabbreviated(&self) -> String
const DEFAULT_LIMIT: isize = 10isize
Source§impl StructuralEq for Type
impl StructuralEq for Type
fn structural_eq(&self, other: &Self) -> bool
Source§impl<'a> TryFrom<&'a Type> for &'a RefinementType
impl<'a> TryFrom<&'a Type> for &'a RefinementType
impl Eq for Type
Auto Trait Implementations§
impl Freeze for Type
impl RefUnwindSafe for Type
impl Send for Type
impl Sync for Type
impl Unpin for Type
impl UnwindSafe for Type
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more