@@ -179,20 +179,50 @@ impl std::str::FromStr for NumberType {
179179 }
180180}
181181
182+ /// Discriminates the semantic category of a [`TypeInfo`] value.
183+ ///
184+ /// Variants mirror the type system of the Inference language.
185+ /// See the module-level documentation for the full hierarchy.
182186#[ derive( Debug , Eq , PartialEq , Clone , Hash ) ]
183187pub enum TypeInfoKind {
188+ /// The unit type `unit` — the implicit return type of void functions.
184189 Unit ,
190+ /// The boolean type `bool`.
185191 Bool ,
192+ /// The string type `string` (UTF-8, partial support).
186193 String ,
194+ /// A numeric integer type (signed or unsigned, 8–64 bit).
187195 Number ( NumberType ) ,
196+ /// A user-defined type referenced by name that has not yet been resolved
197+ /// to a struct or enum entry in the symbol table.
198+ ///
199+ /// After type registration this should have been replaced by
200+ /// [`Struct`](TypeInfoKind::Struct) or [`Enum`](TypeInfoKind::Enum).
188201 Custom ( String ) ,
202+ /// A fixed-size array: element type and element count.
189203 Array ( Box < TypeInfo > , u32 ) ,
204+ /// An unresolved generic type parameter (e.g. `T` in `fn foo<T>(x: T) -> T`).
205+ ///
206+ /// Replaced by a concrete type after type-parameter substitution.
190207 Generic ( String ) ,
208+ /// A two-segment qualified type name (`module::Type`) from the source.
191209 QualifiedName ( String ) ,
210+ /// A single-segment qualified type reference carrying an alias prefix.
192211 Qualified ( String ) ,
212+ /// A function type. The inner string takes one of three forms depending on
213+ /// how the function was referenced:
214+ ///
215+ /// - `"FunctionName"` — a free function referenced by name (from `function_definition.name()`)
216+ /// - `"ReceiverType::MethodName"` — a method or type-member access expression
217+ /// - `"Function<N, ReturnType>"` — a function-type literal from a `Type::Function` node
218+ ///
219+ /// Used to annotate function-name expressions in the `TypedContext`.
193220 Function ( String ) ,
221+ /// A resolved struct type, carrying the struct's canonical name.
194222 Struct ( String ) ,
223+ /// A resolved enum type, carrying the enum's canonical name.
195224 Enum ( String ) ,
225+ /// A spec (specification) type, carrying the spec's canonical name.
196226 Spec ( String ) ,
197227}
198228
@@ -267,11 +297,19 @@ impl TypeInfoKind {
267297 }
268298}
269299
300+ /// The semantic type of a value expression after type checking.
301+ ///
302+ /// Produced by [`TypeInfo::new`] from AST [`Type`] nodes and stored in
303+ /// [`TypedContext`](crate::typed_context::TypedContext) keyed by AST node ID.
270304#[ derive( Debug , Eq , PartialEq , Clone , Hash ) ]
271305pub struct TypeInfo {
306+ /// The concrete type category (e.g. `Number(I32)`, `Struct("Point")`).
272307 pub kind : TypeInfoKind ,
308+ /// Names of any unresolved generic type parameters carried by this type
309+ /// (e.g. `["T"]` for a value whose type is a generic parameter `T`).
310+ ///
311+ /// After all type parameters have been substituted this will be empty.
273312 pub type_params : Vec < String > ,
274- // (Field type information could be added here if needed for struct field checking.)
275313}
276314
277315impl Default for TypeInfo {
@@ -299,6 +337,10 @@ impl Display for TypeInfo {
299337}
300338
301339impl TypeInfo {
340+ /// Construct a `bool` `TypeInfo` value.
341+ ///
342+ /// Shorthand for the common case of representing a boolean result,
343+ /// for example when checking conditions or logical operator results.
302344 #[ must_use]
303345 pub fn boolean ( ) -> Self {
304346 Self {
@@ -315,6 +357,10 @@ impl TypeInfo {
315357 }
316358 }
317359
360+ /// Convert an AST [`Type`] to its semantic `TypeInfo` representation.
361+ ///
362+ /// Equivalent to `TypeInfo::new_with_type_params(ty, &[])` — use this
363+ /// when there are no in-scope generic type parameters to consider.
318364 #[ must_use]
319365 pub fn new ( ty : & Type ) -> Self {
320366 Self :: new_with_type_params ( ty, & [ ] )
0 commit comments