Typle.Inference.Env
(Typle v0.1.0)
View Source
Type environment for tracking variable types during inference.
Maintains a stack of scopes. Each scope maps variable names to their
inferred types. Entering a case, fn, with, or try block
pushes a new scope; leaving pops it.
Summary
Functions
Returns all recorded types as a map of {line, col} => type.
Looks up a variable type, searching from innermost to outermost scope.
Merges variable bindings from multiple branches (e.g. case clauses).
Variables that appear in all branches get the union of their types.
Variables that appear in only some branches get dynamic().
Creates a new empty environment.
Pops the innermost scope, returning to the parent.
Pushes a new scope (e.g. entering a case/fn/with block).
Pushes a new scope initialized with the given variable bindings.
Puts a variable type in the current (innermost) scope.
Records the inferred type for an expression at the given position.
Returns the type recorded at the given position, or nil.
Types
@type position() :: {non_neg_integer(), non_neg_integer()}
@type t() :: %Typle.Inference.Env{ file: String.t() | nil, module: module() | nil, scopes: [%{required(atom()) => Typle.Type.t()}], types: %{required(position()) => Typle.Type.t()} }
Functions
@spec all_types(t()) :: %{required(position()) => Typle.Type.t()}
Returns all recorded types as a map of {line, col} => type.
@spec get_var(t(), atom()) :: Typle.Type.t()
Looks up a variable type, searching from innermost to outermost scope.
@spec merge_branches(t(), [%{required(atom()) => Typle.Type.t()}]) :: t()
Merges variable bindings from multiple branches (e.g. case clauses).
Variables that appear in all branches get the union of their types.
Variables that appear in only some branches get dynamic().
Creates a new empty environment.
Pops the innermost scope, returning to the parent.
Pushes a new scope (e.g. entering a case/fn/with block).
@spec push_scope(t(), %{required(atom()) => Typle.Type.t()}) :: t()
Pushes a new scope initialized with the given variable bindings.
@spec put_var(t(), atom(), Typle.Type.t()) :: t()
Puts a variable type in the current (innermost) scope.
@spec record_type(t(), non_neg_integer(), non_neg_integer(), Typle.Type.t()) :: t()
Records the inferred type for an expression at the given position.
@spec type_at(t(), non_neg_integer(), non_neg_integer()) :: Typle.Type.t() | nil
Returns the type recorded at the given position, or nil.