Skip to content

Separate analysis snapshots from diagnostics and rendering #1078

@elazarg

Description

@elazarg

Problem

AnalysisResult stores important facts, but diagnostic behavior is coupled to result storage and rendering paths:
invariant printing, observation checking, first failure selection, unreachable analysis, and failure slicing.

Reusable tooling needs to query one analysis result in several ways without rerunning analysis or rebuilding display
state.

Direction

Introduce a queryable analysis snapshot that owns the analysis result plus the context needed to explain it.

AnalysisSnapshot {
  result
  variable_registry
  prepared_program_id or prepared program reference
  analysis_options
  dependency metadata
}

Then move diagnostic and rendering behavior into separate components:

DiagnosticsEngine
  find_first_error
  compute_failure_slices
  find_unreachable
  check_observation
  explain_assertion_failure

Renderer
  print_invariants
  print_failure_slices
  print_cfg
  render_json

PR-sized closures

  • Add AnalysisSnapshot as a wrapper over current AnalysisResult plus VariableRegistry.
  • Move one diagnostic query at a time to standalone functions operating on the snapshot.
  • Keep existing public/CLI behavior as wrappers while internals migrate.
  • Separate rendering options from analysis options where they are currently conflated.
  • Add structured output for diagnostics only after the snapshot/query boundary is clear.

Related existing issues

Related PRs

  • #1061 extracts compute_slice_from_label from
    compute_failure_slices, making slicing available for arbitrary labels. If it lands, this issue should treat that as
    existing infrastructure rather than re-requesting it.
  • #1062 adds AnalysisEngine sessions with live access to
    AnalysisResult; this may be the first concrete home for snapshot-like query operations.
  • #1047 exposes invariants, errors, CFG, disassembly, source mapping,
    slicing, and constraint checks through MCP. The diagnostic snapshot issue should define the protocol-independent
    library boundary underneath that PR, not duplicate the MCP tool layer.

Notes

This is a prerequisite for good server behavior, but it is useful before any server exists. It improves tests because
diagnostic queries can be exercised directly over a stable analysis snapshot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions