Module Sarek_ppx_lib.Sarek_mono

Types

type mono_instance = {
  1. mi_name : string;
    (*

    Original function name

    *)
  2. mi_mangled : string;
    (*

    Mangled name for this instance

    *)
  3. mi_types : Sarek_types.typ list;
    (*

    Concrete types for type parameters

    *)
  4. mi_params : Sarek_typed_ast.tparam list;
    (*

    Specialized parameters

    *)
  5. mi_body : Sarek_typed_ast.texpr;
    (*

    Specialized body

    *)
}

A monomorphic instance of a polymorphic function

type mono_env = {
  1. instances : (string * Sarek_types.typ list, string) Stdlib.Hashtbl.t;
  2. specialized : mono_instance list Stdlib.ref;
  3. counter : int Stdlib.ref;
}

Collection of all instances found during monomorphization

Type Utilities

val has_type_vars : Sarek_types.typ -> bool

Check if a type contains any unresolved type variables

val normalize_type : Sarek_types.typ -> Sarek_types.typ

Normalize a type by following all links

val types_equal : Sarek_types.typ -> Sarek_types.typ -> bool

Compare two types for equality (after normalization)

Name Mangling

val mangle_type : Sarek_types.typ -> string

Create a mangled name for a type

val mangle_name : string -> Sarek_types.typ list -> string

Create a mangled name for a function with specific type arguments

Instance Collection

val create_mono_env : unit -> mono_env

Create a fresh monomorphization environment

val get_or_create_instance : mono_env -> string -> Sarek_types.typ list -> string

Get or create a specialized instance name

Type Substitution

type type_subst = (int * Sarek_types.typ) list

Substitution from type variable IDs to concrete types

Apply type substitution to a type

Apply type substitution to a typed expression

Monomorphization Pass

val collect_poly_functions : Sarek_typed_ast.tkernel -> (string * bool * Sarek_typed_ast.tparam list * Sarek_typed_ast.texpr) list

Collect all polymorphic function definitions and their call sites

val collect_call_sites : string list -> Sarek_typed_ast.texpr -> (string * Sarek_types.typ list) list

Collect call sites with their concrete types

val rewrite_calls : mono_env -> string list -> Sarek_typed_ast.texpr -> Sarek_typed_ast.texpr

Rewrite calls to polymorphic functions with mangled names

Main monomorphization entry point