pub struct TypeInferenceEngine {
pub env: TypeEnvironment,
pub type_var_gen: TypeVarGen,
pub callsite_type_args: HashMap<(String, usize, usize), Vec<(String, TypeAnnotation)>>,
/* private fields */
}Fields§
§env: TypeEnvironmentType environment tracking variable types
type_var_gen: TypeVarGenPer-engine generator for fresh type variables (B4). Replaces the
former process-global NEXT_TYPEVAR_ID counter so test runs and
independent inference sessions can’t alias each other’s IDs.
callsite_type_args: HashMap<(String, usize, usize), Vec<(String, TypeAnnotation)>>Resolved type parameter substitutions at generic call sites. Key: (function_name, span_start, span_end) Value: [(original_param_name, concrete_TypeAnnotation)]
Populated during infer_function_call when all type params of a
polymorphic callee resolve to concrete types. Consumed by the
bytecode compiler to drive monomorphization.
Implementations§
Source§impl TypeInferenceEngine
impl TypeInferenceEngine
Sourcepub fn check_expr(&mut self, expr: &Expr, mode: CheckMode) -> TypeResult<Type>
pub fn check_expr(&mut self, expr: &Expr, mode: CheckMode) -> TypeResult<Type>
Check an expression with a given mode
This is the main entry point for bidirectional type checking.
Sourcepub fn check_against(
&mut self,
expr: &Expr,
expected: &Type,
) -> TypeResult<Type>
pub fn check_against( &mut self, expr: &Expr, expected: &Type, ) -> TypeResult<Type>
Check an expression against an expected type
The expected type guides inference and provides better error messages.
Source§impl TypeInferenceEngine
impl TypeInferenceEngine
Sourcepub fn infer_expr(&mut self, expr: &Expr) -> TypeResult<Type>
pub fn infer_expr(&mut self, expr: &Expr) -> TypeResult<Type>
Infer type of an expression
Source§impl TypeInferenceEngine
impl TypeInferenceEngine
pub fn new() -> Self
Sourcepub fn register_known_bindings(&mut self, names: &[String])
pub fn register_known_bindings(&mut self, names: &[String])
Register host-known root-scope bindings before program inference.
These names come from host configuration (project/frontmatter/extensions) and prevent false-positive “undefined variable” diagnostics in the shared analyzer.
Sourcepub fn fresh_var(&mut self) -> TypeVar
pub fn fresh_var(&mut self) -> TypeVar
Allocate a fresh type variable from this engine’s local counter.
IDs are scoped to a single inference run, so independent
TypeInferenceEngine instances (e.g. one per test) cannot alias.
Sourcepub fn fresh_type_var(&mut self) -> Type
pub fn fresh_type_var(&mut self) -> Type
Allocate a fresh type variable wrapped in Type::Variable.
pub fn find_origin_for_unsolved_constraints( &self, constraints: &[(Type, Type)], ) -> Option<Span>
Sourcepub fn resolve_named_to_enum(&self, ty: &SemanticType) -> SemanticType
pub fn resolve_named_to_enum(&self, ty: &SemanticType) -> SemanticType
Resolve a Named type to a full Enum type if the name refers to an enum
This is used for exhaustiveness checking - we need the full enum variant information to verify all cases are covered.
Sourcepub fn run_hoisting_prepass(&mut self, program: &Program)
pub fn run_hoisting_prepass(&mut self, program: &Program)
Infer types for a complete program Run the optimistic hoisting pre-pass
This collects all property assignments (e.g., a.b = 2) and registers
them as hoisted fields so they’re available during the main type checking pass.
Call this BEFORE infer_program or infer_expr for optimistic hoisting to work.
Sourcepub fn infer_program(
&mut self,
program: &Program,
) -> TypeResult<HashMap<String, Type>>
pub fn infer_program( &mut self, program: &Program, ) -> TypeResult<HashMap<String, Type>>
Infer types for a complete program
This runs the hoisting pre-pass automatically before main type inference.
Sourcepub fn infer_program_best_effort(
&mut self,
program: &Program,
) -> (HashMap<String, Type>, Vec<TypeError>)
pub fn infer_program_best_effort( &mut self, program: &Program, ) -> (HashMap<String, Type>, Vec<TypeError>)
Infer types for a complete program and keep successful inferences even when some items fail type checking.
This uses the same inference engine and constraint solver as infer_program
and is intended for tooling surfaces that should avoid guessing.