Enum erg_compiler::ty::Type

source ·
pub enum Type {
Show 39 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>), 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>
§

Proj

Fields

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

ProjCall

Fields

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

Structural(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 quantify(self) -> Self

source

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

source

pub fn structuralize(self) -> Self

source

pub fn is_simple_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_union_type(&self) -> bool

source

pub fn is_intersection_type(&self) -> bool

source

pub fn is_refinement(&self) -> bool

source

pub fn is_record(&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_array(&self) -> bool

source

pub fn is_structural(&self) -> bool

source

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

source

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

source

pub fn contains(&self, target: &Type) -> 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");
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_types(&self) -> Option<(Type, Type)>

source

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

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

source

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

source

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

source

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

source

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

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_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

source

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

source

pub fn coerce(&self)

Fix type variables at their lower bound

i: ?T(:> Int)
assert i.Real == 1
i: (Int)
source

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

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

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 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 return_t(&self) -> Option<&Type>

source

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

source

pub fn derefine(&self) -> Type

source

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

source

pub fn normalize(self) -> Self

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

Trait Implementations§

source§

impl BitAnd<Type> 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<Type> 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 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 HasLevel for Type

source§

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

source§

fn set_level(&self, level: Level)

source§

fn lower(&self, level: Level)

source§

fn lift(&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) -> &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(&self, f: &mut Formatter<'_>, limit: usize) -> Result

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<Type> 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<'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<'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<'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 TryFrom<TyParam> for Type

§

type Error = ()

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

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

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 TryFrom<ValueObj> for Type

§

type Error = ()

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

fn try_from(val: ValueObj) -> Result<Type, ()>

Performs the conversion.
source§

impl Eq for Type

Auto Trait Implementations§

§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.