Skip to main content

QalaType

Enum QalaType 

Source
pub enum QalaType {
Show 14 variants I64, F64, Bool, Str, Byte, Void, Array(Box<QalaType>, Option<usize>), Tuple(Vec<QalaType>), Function { params: Vec<QalaType>, returns: Box<QalaType>, }, Named(Symbol), Result(Box<QalaType>, Box<QalaType>), Option(Box<QalaType>), FileHandle, Unknown,
}
Expand description

every type the type checker can talk about.

derive Debug, Clone, PartialEq only – no Eq, because future variants may carry float-valued metadata, and no serde, because the typed AST and codegen run in-process and never serialize a type. structural equality on primitives and compounds, nominal equality on Named. use QalaType::types_match (not bare ==) for the type-equality predicate the type checker actually consults – it adds the Unknown poison-as-wildcard rule that == does not.

Variants§

§

I64

the 64-bit signed integer primitive.

§

F64

the 64-bit IEEE 754 float primitive.

§

Bool

the boolean primitive.

§

Str

the string primitive.

§

Byte

the byte primitive (one 8-bit unsigned value, distinct from i64).

§

Void

the empty type, used as the return type of a function that has no declared -> T and as the value type of statement-shaped expressions.

§

Array(Box<QalaType>, Option<usize>)

an array. Some(n) is the fixed-length [T; n] form; None is the dynamic [T] form. the element type is boxed because an array of arrays is legal and the box keeps QalaType a fixed size.

§

Tuple(Vec<QalaType>)

a tuple: an ordered list of element types. an empty tuple is the void-shaped tuple that the language does not write directly (a trailing-comma single-element tuple is a QalaType::Tuple of one).

§

Function

a function type. params is the (un-named) parameter types in order; returns is boxed for the same fixed-size reason as Array.

Fields

§params: Vec<QalaType>

the parameter types in declaration order.

§returns: Box<QalaType>

the return type.

§

Named(Symbol)

a user-declared type referenced by name – struct / enum / interface. nominal equality: two Named values are equal iff their Symbols are equal.

§

Result(Box<QalaType>, Box<QalaType>)

the built-in Result<T, E>. the type checker resolves a generic Result<T, E> type expression to this variant directly, without a user-defined generic mechanism.

§

Option(Box<QalaType>)

the built-in Option<T>. the type checker resolves a generic Option<T> type expression to this variant directly.

§

FileHandle

the opaque handle returned by the stdlib open(path) call. a built-in named type rather than a Named(Symbol("FileHandle")) so users do not need to declare it; the stdlib signature table refers to this variant by name. closing a FileHandle (close(h)) is checked structurally the same way as any other call.

§

Unknown

the poison type emitted on a type error so the rest of the program keeps typing. equal to anything under QalaType::types_match – the research’s Pattern 3 – so a chain of expressions after the first error does not cascade into a wall of follow-on errors.

Implementations§

Source§

impl QalaType

Source

pub fn types_match(&self, other: &QalaType) -> bool

the type-equality predicate the type checker uses everywhere.

structural on primitives, Array, Tuple, Function, Result, and Option; nominal on Named (matches by Symbol equality); reflexive on FileHandle. Unknown is symmetrically equal to anything – Unknown.types_match(x) and x.types_match(Unknown) are both true for every x. that rule is what stops one type error from cascading into many; it is Pattern 3 in the phase research.

note this is NOT the same as ==. == is derived structural equality across the whole enum; it does not treat Unknown as a wildcard. always use types_match when asking “do these two types agree, for the purpose of type-checking?”.

Source

pub fn display(&self) -> String

the canonical lowercase form used in expected X, found Y wording.

i64, f64, bool, str, byte, void, [i64; 5] (fixed array), [i64] (dynamic array), (i64, bool) (tuple), fn(i64) -> i64 (function), Shape (named – the symbol’s text verbatim), Result<i64, str>, Option<i64>, FileHandle, and ? for Unknown. the question-mark form for Unknown keeps error messages short when poisoning propagates: “expected i64, found ?” reads better than “expected i64, found unknown”.

recursive: an Array(Box<I64>, Some(5)) renders "[i64; 5]"; a Function { params: vec![I64, Bool], returns: Box::new(Str) } renders "fn(i64, bool) -> str".

Source

pub fn from_prim_type(p: &PrimType) -> Self

bridge from the parser’s PrimType (which records which keyword appeared) to the corresponding QalaType primitive variant.

the type checker’s TypeExpr resolver calls this for the primitive case; the compound cases (Array / DynArray / Tuple / Fn / Generic / Named) recurse into the resolver instead.

Trait Implementations§

Source§

impl Clone for QalaType

Source§

fn clone(&self) -> QalaType

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for QalaType

Source§

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

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

impl Display for QalaType

Source§

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

delegate to QalaType::display so a format!("{ty}") produces the canonical form. lets error messages interpolate types without an explicit .display() call at every site.

Source§

impl PartialEq for QalaType

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for QalaType

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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§

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

Source§

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

Source§

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more