TypeState

Struct TypeState 

Source
pub struct TypeState {
    pub trait_impls: TraitImplList,
    pub trace_stack: TraceStack,
    pub diags: DiagList,
    /* private fields */
}
Expand description

State of the type inference algorithm

Fields§

§trait_impls: TraitImplList§trace_stack: TraceStack§diags: DiagList

Implementations§

Source§

impl TypeState

Source

pub fn visit_identifier( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, ) -> Result<()>

Source

pub fn visit_type_level_integer( &mut self, expression: &Loc<Expression>, generic_list: &GenericListToken, ctx: &Context<'_>, ) -> Result<()>

Source

pub fn visit_pipeline_ref( &mut self, expression: &Loc<Expression>, generic_list: &GenericListToken, ctx: &Context<'_>, ) -> Result<()>

Source

pub fn visit_int_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, ) -> Result<()>

Source

pub fn visit_bool_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, ) -> Result<()>

Source

pub fn visit_tri_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, ) -> Result<()>

Source

pub fn visit_tuple_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_tuple_index( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_field_access( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_method_call( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_array_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_array_shorthand_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_create_ports( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, _generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_index( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_range_index( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_block_expr( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_if( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_match( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_binary_operator( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_unary_operator( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source§

impl TypeState

Source

pub fn t_int(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVarID

Source

pub fn t_uint(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVarID

Source

pub fn t_tri(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVarID

Source

pub fn t_bool(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVarID

Source

pub fn t_clock(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVarID

Source

pub fn t_err(&mut self, loc: Loc<()>) -> TypeVarID

Source§

impl TypeState

Source

pub fn type_decl_to_concrete( decl: &TypeDeclaration, type_list: &TypeList, params: Vec<ConcreteType>, invert: bool, ) -> ConcreteType

Source

pub fn type_expr_to_concrete( expr: &TypeExpression, type_list: &TypeList, generic_substitutions: &HashMap<NameID, &ConcreteType>, invert: bool, ) -> ConcreteType

Source

pub fn type_spec_to_concrete( spec: &TypeSpec, type_list: &TypeList, generic_substitutions: &HashMap<NameID, &ConcreteType>, invert: bool, ) -> ConcreteType

Source

pub fn inner_ungenerify_type( &self, var: &TypeVarID, symtab: &SymbolTable, type_list: &TypeList, invert: bool, ) -> Option<ConcreteType>

Source

pub fn ungenerify_type( &self, var: &TypeVarID, symtab: &SymbolTable, type_list: &TypeList, ) -> Option<ConcreteType>

Converts the specified type to a concrete type, returning None if it fails

Source

pub fn concrete_type_of_infallible( &self, id: ExprID, symtab: &SymbolTable, type_list: &TypeList, ) -> ConcreteType

Returns the type of the specified expression ID as a concrete type. If the type is not known, or the type is Generic, panics

Source

pub fn concrete_type_of( &self, id: impl HasConcreteType, symtab: &SymbolTable, types: &TypeList, ) -> Result<ConcreteType, Diagnostic>

Returns the concrete type of anything that might have a concrete type. Errors if the type is not fully known.

Source

pub fn concrete_type_of_name( &self, name: &Loc<NameID>, symtab: &SymbolTable, types: &TypeList, ) -> Result<ConcreteType, Diagnostic>

Like concrete_type_of but reports an error message that mentions names instead of an expression

Source§

impl TypeState

Source

pub fn fresh() -> Self

Create a fresh type state, in most cases, this should be .create_child of an existing type state

Source

pub fn create_child(&self) -> Self

Source

pub fn add_type_var(&mut self, var: TypeVar) -> TypeVarID

Source

pub fn get_equations(&self) -> &TypeEquations

Source

pub fn get_constraints(&self) -> &TypeConstraints

Source

pub fn get_generic_list<'a>( &'a self, generic_list_token: &'a GenericListToken, ) -> Option<&'a HashMap<NameID, TypeVarID>>

Source

pub fn type_var_from_hir<'a>( &'a mut self, loc: Loc<()>, hir_type: &TypeSpec, generic_list_token: &GenericListToken, ) -> Result<TypeVarID>

Source

pub fn type_of(&self, expr: &TypedExpression) -> TypeVarID

Returns the type of the expression with the specified id. Error if no equation for the specified expression exists

Source

pub fn maybe_type_of(&self, expr: &TypedExpression) -> Option<&TypeVarID>

Source

pub fn new_generic_int(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVar

Source

pub fn new_concrete_int(&mut self, size: BigUint, loc: Loc<()>) -> TypeVarID

Source

pub fn new_split_generic_int( &mut self, loc: Loc<()>, symtab: &SymbolTable, ) -> (TypeVarID, TypeVarID)

Return a new generic int. The first returned value is int, and the second value is N

Source

pub fn new_split_generic_uint( &mut self, loc: Loc<()>, symtab: &SymbolTable, ) -> (TypeVarID, TypeVarID)

Source

pub fn new_generic_with_meta( &mut self, loc: Loc<()>, meta: MetaType, ) -> TypeVarID

Source

pub fn new_generic_type(&mut self, loc: Loc<()>) -> TypeVarID

Source

pub fn new_generic_any(&mut self) -> TypeVarID

Source

pub fn new_generic_tlbool(&mut self, loc: Loc<()>) -> TypeVarID

Source

pub fn new_generic_tlstr(&mut self, loc: Loc<()>) -> TypeVarID

Source

pub fn new_generic_tluint(&mut self, loc: Loc<()>) -> TypeVarID

Source

pub fn new_generic_tlint(&mut self, loc: Loc<()>) -> TypeVarID

Source

pub fn new_generic_tlnumber(&mut self, loc: Loc<()>) -> TypeVarID

Source

pub fn new_generic_number( &mut self, loc: Loc<()>, ctx: &Context<'_>, ) -> (TypeVarID, TypeVarID)

Source

pub fn new_generic_with_traits( &mut self, loc: Loc<()>, traits: TraitList, ) -> TypeVarID

Source

pub fn get_pipeline_state<T>( &self, access_loc: &Loc<T>, ) -> Result<&PipelineState>

Returns the current pipeline state. access_loc is not used to specify where to get the state from, it is only used for the Diagnostic::bug that gets emitted if there is no pipeline state

Source

pub fn visit_unit_with_preprocessing( &mut self, entity: &Loc<Unit>, pp: impl Fn(&mut TypeState, &Loc<Unit>, &GenericListToken, &Context<'_>) -> Result<()>, ctx: &Context<'_>, ) -> Result<()>

Visit a unit but before doing any preprocessing run the pp function.

Source

pub fn visit_unit( &mut self, entity: &Loc<Unit>, ctx: &Context<'_>, ) -> Result<()>

Source

pub fn visit_expression_result( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, new_type: TypeVarID, ) -> Result<()>

Source

pub fn visit_expression( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, )

Source

pub fn handle_concat( &mut self, expression_id: Loc<ExprID>, source_lhs_ty: TypeVarID, source_rhs_ty: TypeVarID, source_result_ty: TypeVarID, args: &[Argument<'_, Expression, TypeSpec>], ctx: &Context<'_>, ) -> Result<()>

Source

pub fn handle_trunc( &mut self, expression_id: Loc<ExprID>, source_in_ty: TypeVarID, source_result_ty: TypeVarID, args: &[Argument<'_, Expression, TypeSpec>], ctx: &Context<'_>, ) -> Result<()>

Source

pub fn handle_comb_mod_or_div( &mut self, n_ty: TypeVarID, args: &[Argument<'_, Expression, TypeSpec>], ctx: &Context<'_>, ) -> Result<()>

Source

pub fn handle_clocked_memory( &mut self, num_elements: TypeVarID, addr_size_arg: TypeVarID, args: &[Argument<'_, Expression, TypeSpec>], ctx: &Context<'_>, ) -> Result<()>

Source

pub fn handle_read_memory( &mut self, num_elements: TypeVarID, addr_size_arg: TypeVarID, args: &[Argument<'_, Expression, TypeSpec>], ctx: &Context<'_>, ) -> Result<()>

Source

pub fn create_generic_list( &mut self, source: GenericListSource<'_>, type_params: &[Loc<TypeParam>], scope_type_params: &[Loc<TypeParam>], turbofish: Option<TurbofishCtx<'_>>, where_clauses: &[Loc<WhereClause>], ) -> Result<GenericListToken>

Source

pub fn add_mapped_generic_list( &mut self, source: GenericListSource<'_>, mapping: HashMap<NameID, TypeVarID>, ) -> GenericListToken

Adds a generic list with parameters already mapped to types

Source

pub fn remove_generic_list(&mut self, source: GenericListSource<'_>)

Source

pub fn visit_block( &mut self, block: &Block, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_impl_blocks(&mut self, item_list: &ItemList) -> TraitImplList

Source

pub fn visit_pattern( &mut self, pattern: &Loc<Pattern>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_wal_trace( &mut self, trace: &Loc<WalTrace>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_statement_error( &mut self, stmt: &Loc<Statement>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_statement( &mut self, stmt: &Loc<Statement>, ctx: &Context<'_>, generic_list: &GenericListToken, )

Source

pub fn visit_register( &mut self, reg: &Register, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>

Source

pub fn visit_trait_spec( &mut self, trait_spec: &Loc<TraitSpec>, generic_list: &GenericListToken, ) -> Result<Loc<TraitReq>>

Source

pub fn visit_trait_bounds( &mut self, target: &Loc<NameID>, traits: &[Loc<TraitSpec>], generic_list_tok: &GenericListToken, ) -> Result<()>

Source

pub fn visit_const_generic_with_id( &mut self, gen: &Loc<ConstGenericWithId>, generic_list_token: &GenericListToken, constraint_source: ConstraintSource, ctx: &Context<'_>, ) -> Result<TypeVarID>

Source

pub fn visit_const_generic( &self, constraint: &ConstGeneric, generic_list: &GenericListToken, ) -> Result<ConstraintExpr>

Source§

impl TypeState

Source

pub fn add_equation(&mut self, expression: TypedExpression, var: TypeVarID)

Source

pub fn can_unify( &mut self, e1: &impl HasType, e2: &impl HasType, ctx: &Context<'_>, ) -> bool

Source

pub fn unify( &mut self, e1: &impl HasType, e2: &impl HasType, ctx: &Context<'_>, ) -> Result<TypeVarID, UnificationError>

Source

pub fn unify_expression_generic_error( &mut self, expr: &Loc<Expression>, other: &impl HasType, ctx: &Context<'_>, ) -> Result<TypeVarID>

Source

pub fn check_requirements( &mut self, is_final_check: bool, ctx: &Context<'_>, ) -> Result<()>

Source

pub fn get_replacement(&self, var: &TypeVarID) -> TypeVarID

Source

pub fn do_and_restore<T, E>( &mut self, inner: impl Fn(&mut Self) -> Result<T, E>, ) -> Result<T, E>

Source§

impl TypeState

Source

pub fn print_equations(&self)

Trait Implementations§

Source§

impl Clone for TypeState

Source§

fn clone(&self) -> TypeState

Returns a duplicate 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<'de> Deserialize<'de> for TypeState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TypeState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
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> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. 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<T> WithLocation for T

Source§

fn at(self, file_id: usize, span: &impl HasCodespan) -> Loc<Self>
where Self: Sized,

Source§

fn at_loc<T>(self, loc: &Loc<T>) -> Loc<Self>

Creates a new Loc from another Loc
Source§

fn between( self, file_id: usize, start: &impl HasCodespan, end: &impl HasCodespan, ) -> Loc<Self>

Source§

fn between_locs<T, Y>(self, start: &Loc<T>, end: &Loc<Y>) -> Loc<Self>

Source§

fn nowhere(self) -> Loc<Self>
where Self: Sized,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,