Expand description
Type expression utilities for Mangle’s structural type system.
Type expressions are represented as IR instructions (Inst::ApplyFn for
compound types, Inst::Name for base types). This module provides:
- Predicates (
is_struct_type,is_union_type, etc.) - Accessors (
struct_type_field,list_type_arg, etc.) - Wellformedness validation (
wellformed_type) - Type conformance (
set_conforms,type_conforms) - HasType runtime validation (
has_type) - TaggedUnion expansion
Constants§
- FN_
EMPTY_ TYPE - FN_FUN
- FN_LIST
- FN_MAP
- FN_OPT
- FN_
OPTION - FN_PAIR
- FN_REL
- FN_
SINGLETON - FN_
STRUCT - FN_
TAGGED_ UNION - FN_
TUPLE - FN_
UNION
Functions§
- apply_
subst - Applies a substitution (type variable -> type) to a type expression. Returns a new InstId with all type variables replaced.
- collect_
vars - Collects all type variables from a type expression into a set.
- empty_
type - Creates or finds the empty type sentinel
fn:EmptyType(). - expand_
tagged_ union_ for_ bounds - Like
expand_tagged_union_typebut uses/nameinstead offn:Singletonfor the tag field type. This is less precise but compatible with the bounds checker’s type inference (which infers/namefor name constants in facts). - expand_
tagged_ union_ type - Expands
fn:TaggedUnion(tag_field, tag1, struct1, tag2, struct2, ...)intofn:Union(fn:Struct(tag_field, fn:Singleton(tag1), ...fields1), ...). - find_
or_ create_ name - Finds or creates a
Nameinstruction in the IR. - get_
type_ context - Gets the type context (all type variables mapped to
/any) from the type variables appearing in a type expression. - has_
type - Checks if a concrete IR constant value matches a type expression.
- intersect_
type - Computes the intersection (greatest lower bound) of two type expressions.
- is_any
- True if this is
/any. - is_
base_ type - True if this is a base type name constant (e.g.
/number,/string,/any). - is_
empty_ type - True if this is the empty type sentinel
fn:EmptyType(). - is_
fun_ type - is_
list_ type - is_
map_ type - is_
name_ const - True if this is a
Inst::Name(any name constant, including base types and user-defined name hierarchy members like/animal/dog). - is_
opt_ field - is_
option_ type - is_
pair_ type - is_
rel_ type - is_
singleton_ type - is_
struct_ type - is_
tagged_ union_ type - is_
tuple_ type - is_
type_ var - True if this is a type variable (
Inst::Var). - is_
union_ type - list_
type_ arg - Returns the element type of a
fn:Listtype expression. - lower_
bound - Computes the lower bound (most general common subtype) of a set of type expressions.
- map_
type_ args - Returns
(key_type, value_type)of afn:Maptype expression. - new_
list_ type - Creates a
fn:List(elem_type)type expression. - new_
map_ type - Creates a
fn:Map(key_type, val_type)type expression. - new_
rel_ type - Builds a
fn:Rel(t1, t2, ...)type from a slice of argument types. - new_
struct_ type - Creates a
fn:Struct(field1, type1, ...)type expression. - new_
tuple_ type - Creates a
fn:Tuple(t1, t2, ...)type expression. - new_
union_ or_ single - Builds
fn:Union(alts...)or returns the single type if only one. - rel_
type_ alternatives - Extracts alternatives from a possibly-union-wrapped relation type.
- rel_
type_ args - Extracts the argument types from a
fn:Rel(t1, t2, ...). - rel_
type_ from_ alternatives - Creates a single relation type or union from a list of alternatives.
- rel_
types_ from_ decl - Builds
fn:Reltypes from declaration bounds. Each BoundDecl becomes onefn:Rel. - remove_
from_ union_ type - Removes types conforming to
to_removefrom a union type. Returns the remaining union, or EmptyType if nothing remains. - set_
conforms - Checks if
leftset-conforms toright. - struct_
type_ field - Returns the type of a struct field by name (simple struct only).
- struct_
type_ field_ deep - Returns the type of a struct field by name. Handles Struct, Union, and TaggedUnion by projecting the field from each alternative and returning their upper bound.
- struct_
type_ fields - Iterates struct type args, yielding
(field_name_id, field_type_id, is_optional). - tagged_
union_ tag_ field - Returns the tag field
InstId(a Name) of afn:TaggedUnion. - tagged_
union_ variants - Returns
(tags, variant_struct_types)for afn:TaggedUnion. Tags are at odd indices starting from 1, variant structs at even indices from 2. - type_
conforms - Checks structural type conformance (non-union, non-tagged-union).
- union_
type_ args - Returns the alternative type expressions of a
fn:Union. - upper_
bound - Computes the upper bound (least common supertype) of a set of type expressions.
- wellformed_
type - Validates that a type expression is well-formed.
Type Aliases§
- Type
Context - Type variable context: maps variable NameId to its bound (an InstId type expr).