Typle.Inference.Expander (Typle v0.2.0)

View Source

Macro expansion layer for the inference engine.

Wraps ExPanda to produce fully-expanded ASTs before type inference. Expansion is applied at the function-definition level (the full def/defp form, not just the body), so that ExPanda's Walker registers function parameters as variables before expanding the body. The outer defmodule structure is preserved as-is because the compiler's internal expander requires full compiler state for module forms.

Each expansion is guarded by a timeout (default 5000ms) to prevent hangs when :elixir_expand enters an infinite loop on certain AST patterns.

Summary

Functions

Parses a source file and expands macros in all function definitions.

Expands macros in a full def/defp AST node (or expression).

Functions

expand_file(file_path, opts \\ [])

@spec expand_file(
  String.t(),
  keyword()
) :: {:ok, Macro.t()} | {:error, term()}

Parses a source file and expands macros in all function definitions.

The module structure (defmodule, alias, etc.) is preserved as-is. Each def/defp form is expanded via ExPanda (including parameter registration) with a per-definition timeout guard.

Returns {:ok, expanded_ast} on success, or {:error, reason} if parsing fails.

expand_node(ast)

@spec expand_node(Macro.t()) :: Macro.t()

Expands macros in a full def/defp AST node (or expression).

Uses ExPanda.expand/1 with a timeout guard. On failure or timeout, returns the original AST unchanged.