Enum erg_compiler::ty::Type
source · pub enum Type {
Show 41 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>,
},
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
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 quantify(self) -> Self
pub fn proj<S: Into<Str>>(self, attr: S) -> Self
pub fn structuralize(self) -> Self
pub fn is_simple_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_intersection_type(&self) -> bool
pub fn is_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_structural(&self) -> bool
pub fn as_free(&self) -> Option<&FreeTyVar>
pub fn contains_tvar(&self, target: &FreeTyVar) -> bool
pub fn contains(&self, target: &Type) -> 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 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) -> Vec<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 tvar_name(&self) -> Option<Str>
pub fn q_constraint(&self) -> Option<Constraint>
pub fn get_super(&self) -> Option<Type>
pub fn get_sub(&self) -> Option<Type>
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_totally_unbound(&self) -> bool
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}
pub fn deconstruct_refinement(self) -> Result<(Str, Type, Predicate), Type>
sourcepub fn coerce(&self)
pub fn coerce(&self)
Fix type variables at their lower bound
i: ?T(:> Int)
assert i.Real == 1
i: (Int)
pub fn qvars(&self) -> Set<(Str, Constraint)>
pub fn qnames(&self) -> Set<Str>
pub fn has_uninited_qvars(&self) -> bool
pub fn is_qvar(&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 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 return_t(&self) -> Option<&Type>
pub fn mut_return_t(&mut self) -> Option<&mut Type>
pub fn derefine(&self) -> Type
pub fn replace(self, target: &Type, to: &Type) -> Type
Trait Implementations§
source§impl CanbeFree for Type
impl CanbeFree for Type
fn unbound_name(&self) -> Option<Str>
fn constraint(&self) -> Option<Constraint>
fn 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
source§fn ref_mut_t(&mut self) -> &mut Type
fn ref_mut_t(&mut self) -> &mut Type
x.ref_mut_t()
may panic, in which case x
is Call
and x.ref_t() == Type::Failure
.