ides_static_parse (ides v0.4.2)

View Source

Static analysis of supervisor init/1 functions from BEAM abstract code.

Recognized patterns

The parser handles the most common OTP supervisor patterns:

  • Literal SupFlags map#{strategy => one_for_one, intensity => 3, period => 10}
  • Variable-bound SupFlagsSupFlags = #{...} followed by {ok, {SupFlags, Children}}
  • Literal child spec list[#{id => w1, start => {M,F,A}, restart => permanent, type => worker}]
  • Variable-bound child specsChildSpec = #{...}, {ok, {SupFlags, [ChildSpec]}}
  • Variable-bound children listChildren = [...], {ok, {SupFlags, Children}}

Unrecognized patterns (return errors)

These patterns cannot be analyzed statically and produce {error, Reason}:

  • Dynamic SupFlags — strategy/intensity/period derived from function calls or application:get_env at runtime
  • Dynamic children — child specs built from function calls, list comprehensions over runtime data, or ets lookups
  • Conditional childrenif/case expressions in the return value selecting between different child spec lists
  • MFA dispatchapply(M, F, A) patterns or dynamic module names
  • No abstract code — BEAM file compiled without debug_info

Error handling

parse_init/1 returns {ok, SupFlags, [ChildSpec]} on success, or {error, Reason} on failure. Callers should handle the error case.

Summary

Functions

Parse init/1 function from beam_info, extracting SupFlags and ChildSpecs.

Types

child_spec()

-type child_spec() ::
          #{id := atom(),
            start := {module(), atom(), [term()]},
            restart := ides:child_restart_type(),
            type := worker | supervisor}.

sup_flags()

-type sup_flags() ::
          #{strategy := ides:supervisor_strategy(),
            intensity := non_neg_integer(),
            period := non_neg_integer()}.

Functions

parse_init/1

-spec parse_init(ides_static_beam:beam_info()) -> {ok, sup_flags(), [child_spec()]} | {error, term()}.

Parse init/1 function from beam_info, extracting SupFlags and ChildSpecs.