Skip to content

[Feature] Add interactive IR lower-trace comparison viewer - #2148

Open
lyfne123 wants to merge 20 commits into
mainfrom
issue-2134-ir-lower-trace
Open

[Feature] Add interactive IR lower-trace comparison viewer#2148
lyfne123 wants to merge 20 commits into
mainfrom
issue-2134-ir-lower-trace

Conversation

@lyfne123

@lyfne123 lyfne123 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add the pypto-ir-trace CLI for deterministic, self-contained HTML reports from pass dumps
  • discover and validate snapshots, compute aligned textual diffs, and render an interactive IDE-style viewer
  • handle atomic output and concise CLI errors, with aligned English and Chinese user documentation
  • keep Superpowers design, plan, and execution artifacts local through precise Git ignore rules

Testing

  • cmake --build build --parallel 8
  • focused IR trace tests after rebase: 47 passed
  • pre-commit run --all-files
  • isolated editable package and installed console-script checks passed
  • real SimpleAdd compile generated 44 pass snapshots; the CLI produced a deterministic 1.31 MB report with 6 changed and 38 no-op passes
  • full unit run: 7702 passed, 17 skipped; 44 failures and 9 errors are confined to existing runtime tests affected by the stale local simpler installation

Fixes #2134

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 06dddd8d-f3a7-400d-8f03-781eb0795016

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds pypto-ir-trace, which discovers pass snapshots, computes deterministic textual diffs, and produces a self-contained interactive HTML report. The CLI supports validation, filtering, navigation, warnings, copying, folding, themes, atomic output, and documented exit codes.

Changes

IR Lower Trace workflow

Layer / File(s) Summary
Design and usage contracts
docs/en/superpowers/..., docs/zh-cn/superpowers/..., docs/en/dev/..., docs/zh-cn/dev/...
Defines the CLI contract, snapshot validation, diff semantics, HTML viewer behavior, security and determinism rules, implementation plan, tests, and bilingual usage guidance.
Snapshot models and discovery
python/pypto/tools/ir_trace/model.py, python/pypto/tools/ir_trace/discovery.py, python/pypto/tools/ir_trace/__init__.py, tests/ut/tools/test_ir_trace.py
Adds immutable trace models and validates, orders, reads, and annotates pass snapshots and warning logs.
Diff, folding, and highlighting
python/pypto/tools/ir_trace/diff.py, tests/ut/tools/test_ir_trace.py
Computes aligned textual diffs and statistics, folds unchanged regions, and safely highlights Python source with fallback handling.
Deterministic HTML viewer
python/pypto/tools/ir_trace/html.py, tests/ut/tools/test_ir_trace.py
Embeds stable trace data, styles, and browser interactions for pass selection, filtering, diff display, warnings, copying, folding, keyboard navigation, and themes.
CLI wiring and end-to-end validation
python/pypto/tools/ir_trace/cli.py, pyproject.toml, tests/ut/tools/test_ir_trace.py
Registers pypto-ir-trace, implements argument handling and atomic writes, connects the processing pipeline, and tests success, failures, cleanup, determinism, and viewer behavior.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI as pypto-ir-trace CLI
  participant Discovery as discover_snapshots
  participant Diff as build_trace
  participant HTML as render_html
  participant Report as ir_trace.html
  CLI->>Discovery: load passes_dump
  Discovery-->>CLI: ordered Snapshots
  CLI->>Diff: build pass traces with context
  Diff-->>CLI: PassTrace sequence
  CLI->>HTML: render traces
  HTML-->>CLI: deterministic HTML
  CLI->>Report: atomically replace output
Loading

Poem

Poem

A rabbit hops through passes bright,
Diffing rows from left to right.
Snapshots fold, warnings gleam,
HTML blooms into a dream.
One safe file, neatly spun—
Lowering traced for everyone!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.03% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements the requested snapshot discovery, diff statistics, interactive self-contained HTML viewer, warning logs, and focused tests for #2134.
Out of Scope Changes check ✅ Passed All listed changes stay within the IR trace viewer, CLI, docs, tests, and packaging needed for #2134.
Title check ✅ Passed The title clearly matches the main change: an interactive IR lower-trace comparison viewer.
Description check ✅ Passed The description accurately summarizes the CLI, viewer, docs, testing, and related artifacts in this PR.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread python/pypto/tools/ir_trace/cli.py Fixed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/en/superpowers/specs/2026-07-24-ir-lower-trace-design.md`:
- Around line 230-247: Update the missing snapshot index diagnostic described in
the Error Handling section to include the neighboring snapshot filenames
surrounding the gap, matching the documented “between X and Y” format. Keep the
existing index and directory context, and align the specification with the
behavior implemented by discovery.py.

In `@python/pypto/tools/ir_trace/diff.py`:
- Around line 34-83: Update highlight_python to catch SyntaxError alongside the
existing tokenize.TokenError, IndentationError, and ValueError exceptions when
generating or validating tokens. Preserve the current fallback of returning
escaped_lines so invalid IR dumps render safely as plain text across supported
Python versions.

In `@python/pypto/tools/ir_trace/discovery.py`:
- Around line 85-90: Update the missing-index error handling in the snapshot
validation loop to include the immediately preceding and following snapshot
filenames, matching the documented “between … and …” diagnostic format. Derive
both bordering names from the indexed snapshot data and retain the zero-padded
missing index in the IRTraceError message.

In `@python/pypto/tools/ir_trace/html.py`:
- Around line 529-541: Update the keydown guard in the document
keyboard-navigation listener to exclude only text-entry targets, not BUTTON
elements, so focused .pass-item buttons still allow j/k and arrow navigation
after clicks. Preserve the existing visible-pass selection and navigation
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e5f20d69-ade0-4923-8189-dc0f90e53efd

📥 Commits

Reviewing files that changed from the base of the PR and between bcaea33 and bbd46f6.

📒 Files selected for processing (14)
  • docs/en/dev/07-ir-lower-trace.md
  • docs/en/superpowers/plans/2026-07-27-ir-lower-trace.md
  • docs/en/superpowers/specs/2026-07-24-ir-lower-trace-design.md
  • docs/zh-cn/dev/07-ir-lower-trace.md
  • docs/zh-cn/superpowers/plans/2026-07-27-ir-lower-trace.md
  • docs/zh-cn/superpowers/specs/2026-07-24-ir-lower-trace-design.md
  • pyproject.toml
  • python/pypto/tools/ir_trace/__init__.py
  • python/pypto/tools/ir_trace/cli.py
  • python/pypto/tools/ir_trace/diff.py
  • python/pypto/tools/ir_trace/discovery.py
  • python/pypto/tools/ir_trace/html.py
  • python/pypto/tools/ir_trace/model.py
  • tests/ut/tools/test_ir_trace.py

Comment thread docs/en/superpowers/specs/2026-07-24-ir-lower-trace-design.md Outdated
Comment thread python/pypto/tools/ir_trace/diff.py Outdated
Comment thread python/pypto/tools/ir_trace/discovery.py Outdated
Comment thread python/pypto/tools/ir_trace/html.py
lyfne123 added a commit that referenced this pull request Jul 28, 2026
- fall back safely when tokenization raises SyntaxError
- report missing snapshots with neighboring filenames
- preserve keyboard navigation from focused pass buttons
- document best-effort cleanup error handling
lyfne123 added a commit that referenced this pull request Jul 28, 2026
- fall back safely when tokenization raises SyntaxError
- report missing snapshots with neighboring filenames
- preserve keyboard navigation from focused pass buttons
- document best-effort cleanup error handling
@lyfne123
lyfne123 force-pushed the issue-2134-ir-lower-trace branch from 45b299b to ca96f0c Compare July 28, 2026 10:29
@lyfne123
lyfne123 force-pushed the issue-2134-ir-lower-trace branch from ca96f0c to f305391 Compare July 29, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Feature] Add an interactive IR lower-trace comparison viewer

1 participant