P5b: analysis package — AnalysisContext, session split, analysis/loops, typed lower-bound IR

Open
#512 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #546 by @LKlinke — closed without merging

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start with the design note required by the issue, then read docs/source/architecture.md sections “Current state and target” and “Order of the milestone,” and check which items are already on main. The work spans prodigy/analysis/, including session.py, while_handler.py, lowerbounds/ir.py, and prodigy/util/logger.py; begin by mapping the target module tree and PR order. Done means the specified package changes and #508 fix are complete, targeted tests, make fuzz, and examples remain unchanged, and the listed pylint checks pass.

Written by the indexing model from the issue text.

Description

area: analysis area: maintenance priority: medium

Work package P5b of #221 (index): the analysis package after the layer cuts of P5a (#497). Several PRs.

Scope

  • T11: instruction handlers get an explicit AnalysisContext instead of the 6-argument positional signature and current_context(); dispatch by a table.
  • T12, second part: split analysis/session.py (decision providers, records, session) below 800 lines; also nested_inference.py, result.py, trace.py, while_handler.py below 800 lines (review A1, A5 layout only — JSON types are P9).
  • T13: analysis/loops/ holds the loop proof rules (while_handler strategies, evtinvariants/, lowerbounds/), one module per strategy group, the registry in one place; strategies declare their goals; the invariant check no longer reaches into the compare mode (review A3).
  • T14, first part: the lower-bound calculus works on a typed AST with a fragment check instead of the tuple IR (lowerbounds/ir.py); affine guard forms through distribution/linear_guards.py (review §2.6). Steps 2–3 belong to #417.
  • Review A4 (plan_parameters, certificate_checks, egcalc.assign: split by case), A9 (silent except: pass → debug log), A11 (templates as expressions, not strings), §2.4 for evtinvariants (shared three-valued all).
  • #508: the unrolling "terminated already" test never fires for programs with variables — fix it with the loops/ move (behaviour change only there; soundness argument in the PR).
  • B5: check the lower-bound zip() sites by hand (already strict=True?) and confirm no constraint can be dropped.
  • Logging leftover of #284 (exists on main): every logger is created with level DEBUG (prodigy/util/logger.py, 29 log_setup(…, logging.DEBUG) calls), so each debug call builds a LogRecord even without a log file; and 7 calls format eagerly with str(…) (e.g. analyzer.py:83 prints the whole program on every compute_semantics). Change: level WARNING unless PRODIGY_LOG_FILE is set (then DEBUG), lazy arguments at the 7 sites, a test that no debug record is created without the variable. With PR 2 (it rewrites analyzer.py).
  • Left by #525 (exist on main): too-many-locals in 11 functions of session, trace, nested_inference (session constructor, Tracer.snapshot/finish/_record_iterate, infer, call_in_joint, run_loop, …); AnalysisSession.__init__ with 18 keyword arguments (a parameter object changes the front-end API: decide with PR 8); Tracer.pseudo_step/loop_iterate/_record_iterate with 6–7 positional arguments.
  • From #537 (exists on main), for PR 8: compute_semantics raises "No analysis is running" unless prodigy.analysis.session was imported, because the session module registers the detached context at import. With the removal of activate/use_context, make the detached context independent of that import.
  • From #522/#539 (exist on main), for PR 8: equivalence/equivalence_check.py:20 still defines its own copy of the 5-argument Analyzer alias (the second-order check moves in PR 8; use Frame or the one alias in context.py); AnalysisContext.loop_iterate, AnalysisSession.loop_iterate and Tracer.loop_iterate take terminated: Any, inside: Any and 6 positional arguments — type them (no reflexive Any) and decide keyword-only together with LoopTask.iterate.
  • From #522 (deviation), for PR 8: Frame.config is a field next to the context's configuration, because the CLI's evt_* commands run a detached session with their own configuration. When activate goes and the CLI passes its session explicitly, give that session the command's configuration and derive Frame.config from the context, so there is one source of the configuration.

pylint checks this package makes clean

too-many-arguments/-positional-arguments in analysis (handlers, loops), too-many-branches/-statements in lowerbounds and evtinvariants, too-many-lines of while_handler, session, nested_inference, result, trace, duplicate-code (three-valued all), too-many-locals in analysis.

Approach

A design note first (one page, posted here): the AnalysisContext fields and lifetime, the target module tree of analysis/ and analysis/loops/, the typed IR of T14, and the PR order. Coding starts after the note is checked. No shared files with P4 (distribution), P6 (language), P7 (web, cli).

Done when

  • T11–T13 and the first part of T14 are reached as described in architecture.md; #508 is closed.
  • No module of analysis has more than 800 lines; no handler takes the session globally.
  • Targeted tests, make fuzz and the examples are unchanged; the checks above are clean for prodigy/analysis.

Rules for this package

  • Work package of the v0.7.0 milestone; target and order in docs/source/architecture.md ("Current state and target", "Order of the milestone"). Review items refer to the written review in #221 (first comment); §13 is the pool of PRs.
  • Behaviour-preserving: no change of results, messages only where an item says so. Soundness unchanged; the examples give the same results on all engines.
  • Items may already be done by P1–P3/P5a: check each against main and say in the PR which were already done.
  • The package's pylint checks are clean at the end, measured with pylint --disable=all --enable=<check> prodigy/<package>; any local exception is justified in a comment.
  • New findings for this package go into this issue's body, not into #221.
Dominant language
Python
Stars
6
Forks
2
Avg merge
1h 52m
Merged PRs (30d)
187

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LKlinke/Prodigy

All issues in LKlinke/Prodigy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.