pub struct TypeChecker {
pub env: TypeEnv,
pub subst: Substitution,
pub diags: DiagnosticBag,
pub impl_table: Option<ImplTable>,
/* private fields */
}Expand description
Fields§
§env: TypeEnvScoped variable / function type environment.
subst: SubstitutionAccumulated type-variable substitution from unification.
diags: DiagnosticBagDiagnostics emitted during type checking.
impl_table: Option<ImplTable>Trait impl table for checking where-clause bounds at call sites.
When None, trait-bound checking is skipped.
Implementations§
Source§impl TypeChecker
impl TypeChecker
Sourcepub fn type_of(&self, id: NodeId) -> Option<&Type>
pub fn type_of(&self, id: NodeId) -> Option<&Type>
Look up the resolved type for node_id from the side-table.
Sourcepub fn record_field_types(&self) -> &HashMap<String, Vec<(String, Type)>>
pub fn record_field_types(&self) -> &HashMap<String, Vec<(String, Type)>>
Record field types: record_name → [(field_name, field_type)].
Sourcepub fn record_generic_params(&self) -> &HashMap<String, Vec<String>>
pub fn record_generic_params(&self) -> &HashMap<String, Vec<String>>
Generic type parameter names for records: record_name → Vec<param_name>.
Sourcepub fn effect_op_types(&self) -> &HashMap<String, Vec<(String, Type)>>
pub fn effect_op_types(&self) -> &HashMap<String, Vec<(String, Type)>>
Effect operation types: effect_name → [(op_name, fn_type)].
Sourcepub fn effect_components(&self) -> &HashMap<String, Vec<String>>
pub fn effect_components(&self) -> &HashMap<String, Vec<String>>
Component effects for composite effects: effect_name → Vec<component_name>.
Sourcepub fn method_types(&self) -> &HashMap<String, HashMap<String, Type>>
pub fn method_types(&self) -> &HashMap<String, HashMap<String, Type>>
Inherent impl method signatures: type_name → (method_name → fn_type).
Sourcepub fn trait_method_types(&self) -> &HashMap<String, HashMap<String, Type>>
pub fn trait_method_types(&self) -> &HashMap<String, HashMap<String, Type>>
Trait method signatures: trait_name → (method_name → fn_type).
Sourcepub fn type_aliases(&self) -> &HashMap<String, Type>
pub fn type_aliases(&self) -> &HashMap<String, Type>
Type alias mappings: alias_name → underlying type.
Sourcepub fn fn_where_bounds(&self, name: &str) -> Vec<(TypeVarId, Vec<String>)>
pub fn fn_where_bounds(&self, name: &str) -> Vec<(TypeVarId, Vec<String>)>
Where-clause trait bounds on a generic function’s type parameters,
keyed by the TypeVarId the parameter was assigned during signature
collection.
Returns (var_id, [trait_name, …]) pairs — one entry per generic
parameter that carries at least one bound. The var_id is the same id
that appears as ?<id> in the function’s exported Type string, so
the export ABI can encode the bound against the right type variable
(Q-xmod-bounds). Returns an empty vec for an unknown or non-generic
function, or one with no where-clause bounds.
Sourcepub fn insert_record_field_types(
&mut self,
name: String,
fields: Vec<(String, Type)>,
)
pub fn insert_record_field_types( &mut self, name: String, fields: Vec<(String, Type)>, )
Insert record field types for an imported record.
Sourcepub fn insert_record_generic_params(
&mut self,
name: String,
params: Vec<String>,
)
pub fn insert_record_generic_params( &mut self, name: String, params: Vec<String>, )
Insert generic parameter names for an imported record/enum.
Sourcepub fn insert_trait_method_types(
&mut self,
name: String,
methods: HashMap<String, Type>,
)
pub fn insert_trait_method_types( &mut self, name: String, methods: HashMap<String, Type>, )
Insert trait method signatures for an imported trait.
Sourcepub fn insert_effect_op_types(&mut self, name: String, ops: Vec<(String, Type)>)
pub fn insert_effect_op_types(&mut self, name: String, ops: Vec<(String, Type)>)
Insert effect operation types for an imported effect.
Sourcepub fn insert_effect_components(
&mut self,
name: String,
components: Vec<String>,
)
pub fn insert_effect_components( &mut self, name: String, components: Vec<String>, )
Insert component effects for an imported composite effect.
Sourcepub fn register_imported_trait_impl(
&mut self,
trait_name: String,
trait_args: Vec<Type>,
target: Type,
)
pub fn register_imported_trait_impl( &mut self, trait_name: String, trait_args: Vec<Type>, target: Type, )
Record a trait impl declared in an imported module (Q-xmod-impl).
trait_args is empty for a plain trait impl (impl Comparable for B)
and non-empty for a parameterized one (impl From[A] for B). The
recorded impls are folded into the freshly-built impl_table in
TypeChecker::check_module, so cross-module .into() resolution and
cross-module where-clause bound satisfaction see them.
Sourcepub fn insert_type_alias(&mut self, name: String, underlying: Type)
pub fn insert_type_alias(&mut self, name: String, underlying: Type)
Insert a type alias for an imported type alias.
Sourcepub fn insert_method_types(
&mut self,
type_name: String,
methods: HashMap<String, Type>,
)
pub fn insert_method_types( &mut self, type_name: String, methods: HashMap<String, Type>, )
Insert method types for an imported type’s inherent impl.
Sourcepub fn seed_imported_generic_fn(&mut self, name: &str, fn_ty: &FnType) -> Type
pub fn seed_imported_generic_fn(&mut self, name: &str, fn_ty: &FnType) -> Type
Seed an imported generic function signature so that each call site
gets fresh TypeVarIds (just like local generic functions).
When a generic function is exported, its type string contains the
original TypeVarIds (e.g. "Fn(?3) -> ?3"). Without an FnSig
entry the call-site instantiation logic in the Call handler is
bypassed, causing the first call to bind those vars permanently.
This method re-allocates fresh TypeVarIds, remaps the function
type, stores the remapped type in env, and inserts a matching
FnSig into fn_sigs.
Sourcepub fn seed_imported_generic_fn_with_bounds(
&mut self,
name: &str,
fn_ty: &FnType,
bounds: &[(TypeVarId, Vec<String>)],
) -> Type
pub fn seed_imported_generic_fn_with_bounds( &mut self, name: &str, fn_ty: &FnType, bounds: &[(TypeVarId, Vec<String>)], ) -> Type
Like Self::seed_imported_generic_fn but also reconstructs the
imported function’s where-clause trait bounds so they are enforced at
call sites in the importing module (Q-xmod-bounds).
bounds is (original_type_var_id, [trait_name, …]), where the var id
is the one encoded in the export ABI (the ?<id> that appears in the
exported type string). Each id is matched to the synthetic generic
parameter (T<position>) created for it here, and a TypeConstraint
is built so the call-site trait-bound check can enforce it.
Sourcepub fn check_module(&mut self, module: &mut AIRNode)
pub fn check_module(&mut self, module: &mut AIRNode)
Type-check an AIR module, annotating every node with its resolved type.
Performs two sub-passes:
- Collect — gather all top-level function signatures.
- Check — infer/check each top-level item.
Sourcepub fn infer_expr(&mut self, expr: &AIRNode) -> Type
pub fn infer_expr(&mut self, expr: &AIRNode) -> Type
Synthesis (public): query the side-table for the type of an expression node, or re-infer it on a temporary clone if not yet visited.
Callers that have already called check_module should use type_of
to avoid re-inference overhead.
Sourcepub fn check_expr(&mut self, expr: &AIRNode, expected: &Type)
pub fn check_expr(&mut self, expr: &AIRNode, expected: &Type)
Checking (public): verify that expr has the given expected type.
Emits a diagnostic if the types do not unify. Like infer_expr, this
operates on a clone when the node has not yet been visited.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TypeChecker
impl !RefUnwindSafe for TypeChecker
impl !Sync for TypeChecker
impl Send for TypeChecker
impl Unpin for TypeChecker
impl UnsafeUnpin for TypeChecker
impl UnwindSafe for TypeChecker
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> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);