Juggernaut.Mutator.Context (Juggernaut v0.4.0)

Copy Markdown View Source

What an operator knows about the site it is offered (design notes §8.1).

The walk (Juggernaut.Mutator.Walk) builds one context per site:

  • position - :runtime, :pattern or :guard;
  • pattern - which kind of pattern a :pattern site is in: :def (a function head), :clause (a case, fn, receive, with or for clause) or :match (the left of =), else nil;
  • module, function ({name, arity}), clause (index among the module's clauses of that name and arity), kind (:def, :defp, :defmacro, :defmacrop);
  • aliases (%{[:Short] => Full.Module}), imports (modules imported or used by the module), locals ({name, arity} the module defines), genserver? (the module uses or declares GenServer);
  • pipe_stage? - the node is the call on the right of |> (call families are offered the |> node instead, so they see every argument);
  • tail? - the node is a return path of its function or fn clause;
  • condition? - the node is the condition of an if, unless or cond clause;
  • pattern_root? - the node is a whole pattern (one argument of a head, the left of a match, one pattern of a clause); repeated - variable names bound more than once in the enclosing pattern;
  • in_rhs? - the node is the right operand of in in a guard;
  • timeout? - the node is a timeout or duration argument of a known call;
  • unit? - every return path of the function is literally :ok or nil, and it is not marked @impl; fun_clauses - body-bearing clauses of the function;
  • rescue? - the node is a rescue clause or its pattern;
  • capture? - the node is the body of an & capture (&(&1 + 1));
  • negated? - the node is the operand of a unary minus (-3);
  • key? - the node is a keyword key (open?: in %{open?: x} or f(x, timeout: 5)); struct? - the node is a field of a struct literal, whose keys are never sites.
  • match_pattern? - the node is inside the pattern of a match?/2 (walked as a runtime site and lifted, Juggernaut.Schemata.Site), where a swapped <> would not compile.

Summary

Functions

The context for a node's children: the flags that describe one node only are reset.

Types

t()

@type t() :: %Juggernaut.Mutator.Context{
  aliases: %{required([atom()]) => module()},
  capture?: boolean(),
  clause: non_neg_integer() | nil,
  condition?: boolean(),
  fun_clauses: pos_integer(),
  function: {atom(), arity()} | nil,
  genserver?: boolean(),
  imports: [module()],
  in_rhs?: boolean(),
  key?: boolean(),
  kind: :def | :defp | :defmacro | :defmacrop,
  locals: MapSet.t({atom(), arity()}),
  match_pattern?: boolean(),
  module: module() | nil,
  negated?: boolean(),
  pattern: :def | :clause | :match | nil,
  pattern_root?: boolean(),
  pipe_stage?: boolean(),
  position: :runtime | :pattern | :guard,
  repeated: MapSet.t(atom()),
  rescue?: boolean(),
  struct?: boolean(),
  tail?: boolean(),
  timeout?: boolean(),
  unit?: boolean()
}

Functions

child(ctx)

@spec child(t()) :: t()

The context for a node's children: the flags that describe one node only are reset.