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

Fields

§before: Box<Type>
§after: Option<Box<Type>>
§

Subr(SubrType)

§

Callable

Fields

§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

Fields

§name: Str
§params: Vec<TyParam>
§

NamedTuple(Vec<(Field, Type)>)

§

Proj

Fields

§lhs: Box<Type>
§rhs: Str
§

ProjCall

Fields

§attr_name: Str
§args: Vec<TyParam>
§

Structural(Box<Type>)

§

Guard(GuardType)

§

Bounded

Fields

§sub: Box<Type>
§sup: Box<Type>
§

FreeVar(FreeTyVar)

§

Failure

§

Uninited

used to represent TyParam is not initialized (see erg_compiler::context::instantiate_tp)

Implementations§

source§

impl Type

source

pub const OBJ: &'static Self = _

source

pub const NONE: &'static Self = _

source

pub const NOT_IMPLEMENTED: &'static Self = _

source

pub const ELLIPSIS: &'static Self = _

source

pub const INF: &'static Self = _

source

pub const NEG_INF: &'static Self = _

source

pub const NEVER: &'static Self = _

source

pub const FAILURE: &'static Self = _

source

pub fn mutate(self) -> Self

source

pub fn immutate(&self) -> Option<Self>

source

pub fn quantify(self) -> Self

source

pub fn proj<S: Into<Str>>(self, attr: S) -> Self

source

pub fn structuralize(self) -> Self

source

pub fn is_mono_value_class(&self) -> bool

source

pub fn is_value_class(&self) -> bool

value class := mono value object class | (List | Set)(value class)

source

pub fn is_mut_value_class(&self) -> bool

source

pub fn is_procedure(&self) -> bool

Procedure

source

pub fn is_mut_type(&self) -> bool

source

pub fn is_nonelike(&self) -> bool

source

pub fn is_nonetype(&self) -> bool

source

pub fn is_singleton(&self) -> bool

source

pub fn is_union_type(&self) -> bool

source

pub fn is_projection(&self) -> bool

source

pub fn is_intersection_type(&self) -> bool

source

pub fn union_size(&self) -> usize

source

pub fn is_refinement(&self) -> bool

source

pub fn is_singleton_refinement(&self) -> bool

source

pub fn is_record(&self) -> bool

source

pub fn is_module(&self) -> bool

source

pub fn is_erg_module(&self) -> bool

source

pub fn is_py_module(&self) -> bool

source

pub fn is_method(&self) -> bool

source

pub fn is_subr(&self) -> bool

source

pub fn is_quantified_subr(&self) -> bool

source

pub fn is_list(&self) -> bool

source

pub fn is_guard(&self) -> bool

source

pub fn is_list_mut(&self) -> bool

source

pub fn is_iterable(&self) -> bool

source

pub fn is_tuple(&self) -> bool

source

pub fn is_named_tuple(&self) -> bool

source

pub fn is_set(&self) -> bool

source

pub fn is_dict(&self) -> bool

source

pub fn is_dict_mut(&self) -> bool

source

pub fn is_ref(&self) -> bool

source

pub fn ref_inner(&self) -> Option<Type>

source

pub fn is_refmut(&self) -> bool

source

pub fn ref_mut_inner(&self) -> Option<Type>

source

pub fn is_structural(&self) -> bool

source

pub fn is_failure(&self) -> bool

source

pub fn is_class_type(&self) -> bool

source

pub fn is_type(&self) -> bool

NOTE: don’t use this, use Context::subtype_of(t, &Type::Type) instead

source

pub fn is_poly_type_meta(&self) -> bool

source

pub fn as_free(&self) -> Option<&FreeTyVar>

source

pub fn contains_tvar(&self, target: &FreeTyVar) -> bool

source

pub fn contains_type(&self, target: &Type) -> bool

source

pub fn contains_tp(&self, target: &TyParam) -> bool

source

pub fn is_recursive(&self) -> bool

source

pub fn args_ownership(&self) -> ArgsOwnership

source

pub fn ownership(&self) -> Ownership

source

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");
source

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");
source

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");
source

pub fn contains_intersec(&self, typ: &Type) -> bool

assert!((A and B).contains_intersec(B))

source

pub fn union_pair(&self) -> Option<(Type, Type)>

source

pub fn contains_union(&self, typ: &Type) -> bool

assert!((A or B).contains_union(B))

source

pub fn intersection_types(&self) -> Vec<Type>

source

pub fn tvar_name(&self) -> Option<Str>

source

pub fn q_constraint(&self) -> Option<Constraint>

source

pub fn get_super(&self) -> Option<Type>

<: Super

source

pub fn get_sub(&self) -> Option<Type>

:> Sub

source

pub const fn is_free_var(&self) -> bool

source

pub const fn is_callable(&self) -> bool

source

pub fn is_unbound_var(&self) -> bool

source

pub fn is_named_unbound_var(&self) -> bool

source

pub fn is_unnamed_unbound_var(&self) -> bool

source

pub fn is_totally_unbound(&self) -> bool

assert (?T or ?U).totally_unbound()
source

pub fn is_monomorphic(&self) -> bool

See also: is_monomorphized

source

pub fn is_monomorphized(&self) -> bool

Set(Int, 3) is not monomorphic but monomorphized

source

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}
source

pub fn to_singleton(&self) -> Option<RefinementType>

{ .x = {Int} } == {{ .x = Int }}
K({Int}) == {K(Int)} # TODO
source

pub fn deconstruct_refinement(self) -> Result<(Str, Type, Predicate), Type>

source

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
source

pub fn undoable_coerce(&self, list: &UndoableLinkedList)

source

pub fn coerce(&self, list: Option<&UndoableLinkedList>)

source

pub fn qvars(&self) -> Set<(Str, Constraint)>

returns top-level qvars. see also: qvars_inner

source

pub fn qnames(&self) -> Set<Str>

source

pub fn has_uninited_qvars(&self) -> bool

source

pub fn is_qvar(&self) -> bool

source

pub fn has_qvar(&self) -> bool

if the type is polymorphic

assert ('T -> Int).has_qvar()
assert not (|T| T -> T).has_qvar()
source

pub fn is_undoable_linked_var(&self) -> bool

source

pub fn has_undoable_linked_var(&self) -> bool

source

pub fn has_no_qvar(&self) -> bool

source

pub fn has_unbound_var(&self) -> bool

source

pub fn has_no_unbound_var(&self) -> bool

source

pub fn typarams_len(&self) -> Option<usize>

source

pub fn singleton_value(&self) -> Option<&TyParam>

source

pub fn refinement_values(&self) -> Option<Vec<&TyParam>>

source

pub fn container_len(&self) -> Option<usize>

source

pub fn typarams(&self) -> Vec<TyParam>

source

pub fn self_t(&self) -> Option<&Type>

source

pub fn non_default_params(&self) -> Option<&Vec<ParamTy>>

source

pub fn var_params(&self) -> Option<&ParamTy>

source

pub fn default_params(&self) -> Option<&Vec<ParamTy>>

source

pub fn non_var_params(&self) -> Option<impl Iterator<Item = &ParamTy> + Clone>

source

pub fn param_ts(&self) -> Vec<Type>

source

pub fn return_t(&self) -> Option<&Type>

source

pub fn tyvar_mut_return_t(&mut self) -> Option<RefMut<'_, Type>>

source

pub fn mut_return_t(&mut self) -> Option<&mut Type>

source

pub fn derefine(&self) -> Type

source

pub fn eliminate(self, target: &Type) -> Self

source

pub fn replace(self, target: &Type, to: &Type) -> Type

source

pub fn replace_failure(&self) -> Type

(Failure -> Int).replace_failure() == (Obj -> Int)
(Int -> Failure).replace_failure() == (Int -> Never)
List(Failure, 3).replace_failure() == List(Never, 3)
source

pub fn replace_params<'l, 'r>( self, target: impl Iterator<Item = &'l str>, to: impl Iterator<Item = &'r str> ) -> Self

source

pub fn normalize(self) -> Self

TyParam::Value(ValueObj::Type(_)) => TyParam::Type

source

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)
source

pub fn into_bounded(&self) -> Type

source

pub fn ands(&self) -> Set<Type>

Add.ands() == {Add}
(Add and Sub).ands() == {Add, Sub}
source

pub fn ors(&self) -> Set<Type>

Int.ors() == {Int}
(Int or Str).ors() == {Int, Str}
source

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}
source

pub fn dereference(&mut self)

source

pub fn module_path(&self) -> Option<PathBuf>

source

pub fn variables(&self) -> Set<Str>

Trait Implementations§

source§

impl BitAnd for Type

§

type Output = Type

The resulting type after applying the & operator.
source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
source§

impl BitOr for Type

§

type Output = Type

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
source§

impl CanbeFree for Type

source§

fn unbound_name(&self) -> Option<Str>

source§

fn constraint(&self) -> Option<Constraint>

source§

fn destructive_update_constraint( &self, new_constraint: Constraint, in_instantiation: bool )

source§

impl Clone for Type

source§

fn clone(&self) -> Type

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Type

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Type

source§

fn default() -> Type

Returns the “default value” for a type. Read more
source§

impl Display for Type

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&Type> for TypeCode

source§

fn from(arg: &Type) -> Self

Converts to this type from the input type.
source§

impl From<Dict<Field, Type>> for Type

source§

fn from(rec: Dict<Field, Type>) -> Self

Converts to this type from the input type.
source§

impl From<Dict<Type, Type>> for Type

source§

fn from(d: Dict<Type, Type>) -> Self

Converts to this type from the input type.
source§

impl From<Range<&TyParam>> for Type

source§

fn from(r: Range<&TyParam>) -> Self

Converts to this type from the input type.
source§

impl From<Range<TyParam>> for Type

source§

fn from(r: Range<TyParam>) -> Self

Converts to this type from the input type.
source§

impl From<RangeInclusive<&TyParam>> for Type

source§

fn from(r: RangeInclusive<&TyParam>) -> Self

Converts to this type from the input type.
source§

impl From<RangeInclusive<TyParam>> for Type

source§

fn from(r: RangeInclusive<TyParam>) -> Self

Converts to this type from the input type.
source§

impl From<RefinementType> for Type

source§

fn from(refine: RefinementType) -> Self

Converts to this type from the input type.
source§

impl From<SubrType> for Type

source§

fn from(subr: SubrType) -> Self

Converts to this type from the input type.
source§

impl HasLevel for Type

source§

fn level(&self) -> Option<usize>

source§

fn set_level(&self, level: Level)

source§

fn set_lower(&self, level: Level)

source§

fn lift(&self)

source§

fn lower(&self)

source§

fn generalize(&self)

source§

fn is_generalized(&self) -> bool

source§

impl HasType for Type

source§

fn ref_t(&self) -> &Type

source§

fn ref_mut_t(&mut self) -> Option<&mut Type>

source§

fn inner_ts(&self) -> Vec<Type>

source§

fn signature_t(&self) -> Option<&Type>

source§

fn signature_mut_t(&mut self) -> Option<&mut Type>

source§

fn t(&self) -> Type

source§

fn lhs_t(&self) -> &Type

source§

fn rhs_t(&self) -> &Type

source§

impl Hash for Type

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl LimitedDisplay for Type

source§

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:
source§

fn to_string_unabbreviated(&self) -> String

source§

impl Not for Type

§

type Output = Type

The resulting type after applying the ! operator.
source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
source§

impl PartialEq for Type

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralEq for Type

source§

fn structural_eq(&self, other: &Self) -> bool

source§

impl<'a> TryFrom<&'a TyParam> for &'a Type

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(tp: &'a TyParam) -> Result<&'a Type, ()>

Performs the conversion.
source§

impl<'t> TryFrom<&'t Type> for &'t FreeTyVar

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(t: &'t Type) -> Result<&'t FreeTyVar, ()>

Performs the conversion.
source§

impl<'a> TryFrom<&'a Type> for &'a RefinementType

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(t: &'a Type) -> Result<&'a RefinementType, ()>

Performs the conversion.
source§

impl<'t> TryFrom<&'t Type> for &'t SubrType

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(t: &'t Type) -> Result<&'t SubrType, ()>

Performs the conversion.
source§

impl<'a> TryFrom<&'a ValueObj> for &'a Type

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(val: &'a ValueObj) -> Result<Self, ()>

Performs the conversion.
source§

impl TryFrom<Type> for SubrType

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(t: Type) -> Result<Self, ()>

Performs the conversion.
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.