Metastatic.Analysis.Purity.Result
(Metastatic v0.10.4)
View Source
Result structure for purity analysis.
Contains information about whether a function/code block is pure or impure, what side effects were detected, confidence level, and locations of impure operations.
Fields
:pure?- Boolean indicating if the code is pure (no side effects detected):effects- List of detected effect atoms (:io,:mutation,:random,:time,:network,:database,:exception):confidence- Confidence level (:high,:medium,:low):impure_locations- List of{:line, line_number, effect_type}tuples:summary- Human-readable summary string:unknown_calls- List of function calls that couldn't be classified
Examples
# Pure function
iex> %Metastatic.Analysis.Purity.Result{
...> pure?: true,
...> effects: [],
...> confidence: :high,
...> impure_locations: [],
...> summary: "Function is pure"
...> }
# Impure function with I/O
iex> %Metastatic.Analysis.Purity.Result{
...> pure?: false,
...> effects: [:io],
...> confidence: :high,
...> impure_locations: [{:line, 42, :io}],
...> summary: "Function is impure due to I/O operations"
...> }
# Unknown purity (unclassified function calls)
iex> %Metastatic.Analysis.Purity.Result{
...> pure?: false,
...> effects: [],
...> confidence: :low,
...> impure_locations: [],
...> summary: "Function purity unknown - contains unclassified calls",
...> unknown_calls: ["custom_function"]
...> }
Summary
Functions
Creates a new impure result with the given effects and locations.
Merges multiple results, keeping impurity if any result is impure.
Creates a new pure result.
Creates a result with unknown purity (low confidence).
Types
@type confidence() :: :high | :medium | :low
@type effect() ::
:io
| :mutation
| :random
| :time
| :network
| :database
| :exception
| :unknown
@type location() :: {:line, non_neg_integer(), effect()}
Functions
Creates a new impure result with the given effects and locations.
Examples
iex> Metastatic.Analysis.Purity.Result.impure([:io], [{:line, 10, :io}])
%Metastatic.Analysis.Purity.Result{
pure?: false,
effects: [:io],
confidence: :high,
impure_locations: [{:line, 10, :io}],
summary: "Function is impure due to I/O operations",
unknown_calls: []
}
Merges multiple results, keeping impurity if any result is impure.
Examples
iex> r1 = Metastatic.Analysis.Purity.Result.pure()
iex> r2 = Metastatic.Analysis.Purity.Result.impure([:io], [{:line, 10, :io}])
iex> result = Metastatic.Analysis.Purity.Result.merge([r1, r2])
iex> result.pure?
false
iex> result.effects
[:io]
@spec pure() :: t()
Creates a new pure result.
Examples
iex> Metastatic.Analysis.Purity.Result.pure()
%Metastatic.Analysis.Purity.Result{
pure?: true,
effects: [],
confidence: :high,
impure_locations: [],
summary: "Function is pure",
unknown_calls: []
}
Creates a result with unknown purity (low confidence).
Examples
iex> Metastatic.Analysis.Purity.Result.unknown(["custom_func"])
%Metastatic.Analysis.Purity.Result{
pure?: false,
effects: [],
confidence: :low,
impure_locations: [],
summary: "Function purity unknown - contains unclassified calls: custom_func",
unknown_calls: ["custom_func"]
}