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: DiagListImplementations§
Source§impl TypeState
impl TypeState
pub fn visit_identifier( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, ) -> Result<()>
pub fn visit_type_level_integer( &mut self, expression: &Loc<Expression>, generic_list: &GenericListToken, ctx: &Context<'_>, ) -> Result<()>
pub fn visit_pipeline_ref( &mut self, expression: &Loc<Expression>, generic_list: &GenericListToken, ctx: &Context<'_>, ) -> Result<()>
pub fn visit_int_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, ) -> Result<()>
pub fn visit_bool_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, ) -> Result<()>
pub fn visit_tri_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, ) -> Result<()>
pub fn visit_tuple_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_tuple_index( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_field_access( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_method_call( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_array_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_array_shorthand_literal( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_create_ports( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, _generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_index( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_range_index( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_block_expr( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_if( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_match( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_binary_operator( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_unary_operator( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
Source§impl TypeState
impl TypeState
pub fn t_int(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVarID
pub fn t_uint(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVarID
pub fn t_tri(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVarID
pub fn t_bool(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVarID
pub fn t_clock(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVarID
pub fn t_err(&mut self, loc: Loc<()>) -> TypeVarID
Source§impl TypeState
impl TypeState
pub fn type_decl_to_concrete( decl: &TypeDeclaration, type_list: &TypeList, params: Vec<ConcreteType>, invert: bool, ) -> ConcreteType
pub fn type_expr_to_concrete( expr: &TypeExpression, type_list: &TypeList, generic_substitutions: &HashMap<NameID, &ConcreteType>, invert: bool, ) -> ConcreteType
pub fn type_spec_to_concrete( spec: &TypeSpec, type_list: &TypeList, generic_substitutions: &HashMap<NameID, &ConcreteType>, invert: bool, ) -> ConcreteType
pub fn inner_ungenerify_type( &self, var: &TypeVarID, symtab: &SymbolTable, type_list: &TypeList, invert: bool, ) -> Option<ConcreteType>
Sourcepub fn ungenerify_type(
&self,
var: &TypeVarID,
symtab: &SymbolTable,
type_list: &TypeList,
) -> Option<ConcreteType>
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
Sourcepub fn concrete_type_of_infallible(
&self,
id: ExprID,
symtab: &SymbolTable,
type_list: &TypeList,
) -> ConcreteType
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
Sourcepub fn concrete_type_of(
&self,
id: impl HasConcreteType,
symtab: &SymbolTable,
types: &TypeList,
) -> Result<ConcreteType, Diagnostic>
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.
Sourcepub fn concrete_type_of_name(
&self,
name: &Loc<NameID>,
symtab: &SymbolTable,
types: &TypeList,
) -> Result<ConcreteType, Diagnostic>
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
impl TypeState
Sourcepub fn fresh() -> Self
pub fn fresh() -> Self
Create a fresh type state, in most cases, this should be .create_child of an existing type state
pub fn create_child(&self) -> Self
pub fn add_type_var(&mut self, var: TypeVar) -> TypeVarID
pub fn get_equations(&self) -> &TypeEquations
pub fn get_constraints(&self) -> &TypeConstraints
pub fn get_generic_list<'a>( &'a self, generic_list_token: &'a GenericListToken, ) -> Option<&'a HashMap<NameID, TypeVarID>>
pub fn type_var_from_hir<'a>( &'a mut self, loc: Loc<()>, hir_type: &TypeSpec, generic_list_token: &GenericListToken, ) -> Result<TypeVarID>
Sourcepub fn type_of(&self, expr: &TypedExpression) -> TypeVarID
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
pub fn maybe_type_of(&self, expr: &TypedExpression) -> Option<&TypeVarID>
pub fn new_generic_int(&mut self, loc: Loc<()>, symtab: &SymbolTable) -> TypeVar
pub fn new_concrete_int(&mut self, size: BigUint, loc: Loc<()>) -> TypeVarID
Sourcepub fn new_split_generic_int(
&mut self,
loc: Loc<()>,
symtab: &SymbolTable,
) -> (TypeVarID, TypeVarID)
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
pub fn new_split_generic_uint( &mut self, loc: Loc<()>, symtab: &SymbolTable, ) -> (TypeVarID, TypeVarID)
pub fn new_generic_with_meta( &mut self, loc: Loc<()>, meta: MetaType, ) -> TypeVarID
pub fn new_generic_type(&mut self, loc: Loc<()>) -> TypeVarID
pub fn new_generic_any(&mut self) -> TypeVarID
pub fn new_generic_tlbool(&mut self, loc: Loc<()>) -> TypeVarID
pub fn new_generic_tlstr(&mut self, loc: Loc<()>) -> TypeVarID
pub fn new_generic_tluint(&mut self, loc: Loc<()>) -> TypeVarID
pub fn new_generic_tlint(&mut self, loc: Loc<()>) -> TypeVarID
pub fn new_generic_tlnumber(&mut self, loc: Loc<()>) -> TypeVarID
pub fn new_generic_number( &mut self, loc: Loc<()>, ctx: &Context<'_>, ) -> (TypeVarID, TypeVarID)
pub fn new_generic_with_traits( &mut self, loc: Loc<()>, traits: TraitList, ) -> TypeVarID
Sourcepub fn get_pipeline_state<T>(
&self,
access_loc: &Loc<T>,
) -> Result<&PipelineState>
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
Sourcepub fn visit_unit_with_preprocessing(
&mut self,
entity: &Loc<Unit>,
pp: impl Fn(&mut TypeState, &Loc<Unit>, &GenericListToken, &Context<'_>) -> Result<()>,
ctx: &Context<'_>,
) -> Result<()>
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.
pub fn visit_unit( &mut self, entity: &Loc<Unit>, ctx: &Context<'_>, ) -> Result<()>
pub fn visit_expression_result( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, new_type: TypeVarID, ) -> Result<()>
pub fn visit_expression( &mut self, expression: &Loc<Expression>, ctx: &Context<'_>, generic_list: &GenericListToken, )
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<()>
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<()>
pub fn handle_comb_mod_or_div( &mut self, n_ty: TypeVarID, args: &[Argument<'_, Expression, TypeSpec>], ctx: &Context<'_>, ) -> Result<()>
pub fn handle_clocked_memory( &mut self, num_elements: TypeVarID, addr_size_arg: TypeVarID, args: &[Argument<'_, Expression, TypeSpec>], ctx: &Context<'_>, ) -> Result<()>
pub fn handle_read_memory( &mut self, num_elements: TypeVarID, addr_size_arg: TypeVarID, args: &[Argument<'_, Expression, TypeSpec>], ctx: &Context<'_>, ) -> Result<()>
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>
Sourcepub fn add_mapped_generic_list(
&mut self,
source: GenericListSource<'_>,
mapping: HashMap<NameID, TypeVarID>,
) -> GenericListToken
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
pub fn remove_generic_list(&mut self, source: GenericListSource<'_>)
pub fn visit_block( &mut self, block: &Block, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_impl_blocks(&mut self, item_list: &ItemList) -> TraitImplList
pub fn visit_pattern( &mut self, pattern: &Loc<Pattern>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_wal_trace( &mut self, trace: &Loc<WalTrace>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_statement_error( &mut self, stmt: &Loc<Statement>, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_statement( &mut self, stmt: &Loc<Statement>, ctx: &Context<'_>, generic_list: &GenericListToken, )
pub fn visit_register( &mut self, reg: &Register, ctx: &Context<'_>, generic_list: &GenericListToken, ) -> Result<()>
pub fn visit_trait_spec( &mut self, trait_spec: &Loc<TraitSpec>, generic_list: &GenericListToken, ) -> Result<Loc<TraitReq>>
pub fn visit_trait_bounds( &mut self, target: &Loc<NameID>, traits: &[Loc<TraitSpec>], generic_list_tok: &GenericListToken, ) -> Result<()>
pub fn visit_const_generic_with_id( &mut self, gen: &Loc<ConstGenericWithId>, generic_list_token: &GenericListToken, constraint_source: ConstraintSource, ctx: &Context<'_>, ) -> Result<TypeVarID>
pub fn visit_const_generic( &self, constraint: &ConstGeneric, generic_list: &GenericListToken, ) -> Result<ConstraintExpr>
Source§impl TypeState
impl TypeState
pub fn add_equation(&mut self, expression: TypedExpression, var: TypeVarID)
pub fn can_unify( &mut self, e1: &impl HasType, e2: &impl HasType, ctx: &Context<'_>, ) -> bool
pub fn unify( &mut self, e1: &impl HasType, e2: &impl HasType, ctx: &Context<'_>, ) -> Result<TypeVarID, UnificationError>
pub fn unify_expression_generic_error( &mut self, expr: &Loc<Expression>, other: &impl HasType, ctx: &Context<'_>, ) -> Result<TypeVarID>
pub fn check_requirements( &mut self, is_final_check: bool, ctx: &Context<'_>, ) -> Result<()>
pub fn get_replacement(&self, var: &TypeVarID) -> TypeVarID
pub fn do_and_restore<T, E>( &mut self, inner: impl Fn(&mut Self) -> Result<T, E>, ) -> Result<T, E>
Source§impl TypeState
impl TypeState
pub fn print_equations(&self)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TypeState
impl<'de> Deserialize<'de> for TypeState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl !Freeze for TypeState
impl !RefUnwindSafe for TypeState
impl Send for TypeState
impl !Sync for TypeState
impl Unpin for TypeState
impl UnwindSafe for TypeState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
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
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
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
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.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
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.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
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.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
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.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
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.