Syntax.Analysis
Analysis walks over the surface syntax tree.
Every function here is a few lines over Control.Layer’s generic queries at expr_layer(), and that is the point: a pass asks for “every variable occurrence” or “every call site” instead of writing its own recursion, and the answer comes back in source order every time. Nothing here decides what a name means; that is the resolver’s job and Syntax.Rename queries it.
Types
ExprCensus
type ExprCensus = ExprCensus {
nodes: Int,
vars: Int,
calls: Int,
binds: Int,
holes: Int
}
A shape census of one expression: the counts a size heuristic, a lint threshold, or a complexity report is built from. nodes is every node, vars every variable occurrence, calls every application, holes every typed hole, and binds every form that introduces a name (a let, a mutable declaration, a lambda, a match, a for loop, a comprehension), counted once per form rather than once per name it binds.
Functions and Values
an_nodes
an_nodes : (Syntax.Ast.Sp(Syntax.Ast.Expr)) -> List(Syntax.Ast.Sp(Syntax.Ast.Expr))
Every node of an expression, root first, in source order.
an_where
an_where : forall e0. ((Syntax.Ast.Sp(Syntax.Ast.Expr)) -> Bool ! {e0}, Syntax.Ast.Sp(Syntax.Ast.Expr)) -> List(Syntax.Ast.Sp(Syntax.Ast.Expr)) ! {e0}
Every node satisfying a predicate, in source order.
an_size
an_size : (Syntax.Ast.Sp(Syntax.Ast.Expr)) -> Int
The number of nodes in an expression.
an_depth
an_depth : (Syntax.Ast.Sp(Syntax.Ast.Expr)) -> Int
The height of an expression: 1 at a leaf.
an_spans
an_spans : (Syntax.Ast.Sp(Syntax.Ast.Expr)) -> List(Syntax.Source.Span)
The span of every node, root first, in source order.
an_var_uses
an_var_uses : (Syntax.Ast.Sp(Syntax.Ast.Expr)) -> List((String, Syntax.Source.Span))
Every variable occurrence: the identifier and the exact span it covers. This is the occurrence table an editor tool wants, and the one place a purely syntactic tool should stop: it says where a name is written, never what it refers to.
an_var_names
an_var_names : (Syntax.Ast.Sp(Syntax.Ast.Expr)) -> List(String)
Every name written as a variable, in first-occurrence order and without repeats.
an_uses_of
an_uses_of : (String, Syntax.Ast.Sp(Syntax.Ast.Expr)) -> Int
How many times a name is written as a variable.
an_calls
an_calls : (Syntax.Ast.Sp(Syntax.Ast.Expr)) -> List(Syntax.Ast.Sp(Syntax.Ast.Expr))
Every call site, in source order.
an_is_call
an_is_call : (Syntax.Ast.Sp(Syntax.Ast.Expr)) -> Bool
Whether a node is an application. The predicate an_calls filters on, made public so a rewrite can scope a rule to call sites without restating it.
an_call_targets
an_call_targets : (Syntax.Ast.Sp(Syntax.Ast.Expr)) -> List(String)
The name of every directly called function, in source order. A call whose head is not a plain variable (a field access, a lambda, a computed callee) contributes nothing rather than a guess.
an_holes
an_holes : (Syntax.Ast.Sp(Syntax.Ast.Expr)) -> List(Syntax.Source.Span)
The span of every typed hole, in source order: what a completion tool asks for first.
an_any
an_any : forall e0. ((Syntax.Ast.Sp(Syntax.Ast.Expr)) -> Bool ! {e0}, Syntax.Ast.Sp(Syntax.Ast.Expr)) -> Bool ! {e0}
Whether any node satisfies the predicate, short-circuiting on the first hit.
an_census
an_census : (Syntax.Ast.Sp(Syntax.Ast.Expr)) -> Syntax.Analysis.ExprCensus
Count every shape in one walk. The combining operation is field-wise addition, which is what lay_summarize was shaped for: one pass, one caller-supplied monoid, no repeated traversals.