Enum erg_compiler::ty::Type
source · 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(Box<Type>, Box<Type>),
Or(Box<Type>, Box<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(Box<Type>, Box<Type>)
Or(Box<Type>, Box<Type>)
Not(Box<Type>)
Poly
NamedTuple(Vec<(Field, Type)>)
Proj
ProjCall
Structural(Box<Type>)
Guard(GuardType)
Bounded
FreeVar(FreeTyVar)
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 quantify(self) -> Self
pub fn proj<S: Into<Str>>(self, attr: S) -> Self
pub fn structuralize(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 | (Array | 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_union_type(&self) -> bool
pub fn is_projection(&self) -> bool
pub fn is_intersection_type(&self) -> bool
pub fn union_size(&self) -> usize
pub fn is_refinement(&self) -> bool
pub fn is_singleton_refinement(&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 is_quantified_subr(&self) -> bool
pub fn is_array(&self) -> bool
pub fn is_array_mut(&self) -> bool
pub fn is_iterable(&self) -> bool
pub fn is_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_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_type_meta(&self) -> bool
pub fn as_free(&self) -> Option<&FreeTyVar>
pub fn contains_tvar(&self, target: &FreeTyVar) -> bool
pub fn contains_type(&self, target: &Type) -> bool
pub fn contains_tp(&self, target: &TyParam) -> 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)>
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 tvar_name(&self) -> Option<Str>
pub fn q_constraint(&self) -> Option<Constraint>
pub const fn is_free_var(&self) -> bool
pub const 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
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
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 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 non_default_params(&self) -> Option<&Vec<ParamTy>>
pub fn var_params(&self) -> Option<&ParamTy>
pub fn default_params(&self) -> Option<&Vec<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>
pub fn derefine(&self) -> Type
pub fn eliminate(self, target: &Type) -> Self
pub fn replace(self, target: &Type, to: &Type) -> Type
sourcepub fn replace_failure(&self) -> Type
pub fn replace_failure(&self) -> Type
(Failure -> Int).replace_failure() == (Obj -> Int)
(Int -> Failure).replace_failure() == (Int -> Never)
Array(Failure, 3).replace_failure() == Array(Never, 3)
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)
pub fn into_bounded(&self) -> Type
sourcepub fn contained_ts(&self) -> Set<Type>
pub fn contained_ts(&self) -> Set<Type>
Int.contained_ts() == {Int}
Array(Array(Int)).contained_ts() == {Array(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 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§impl PartialEq for Type
impl PartialEq for Type
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