Skip to content

Comments

fix interpreter source traceback#602

Merged
Roger-luo merged 6 commits intomainfrom
neelay/stacktrace-fix
Feb 25, 2026
Merged

fix interpreter source traceback#602
Roger-luo merged 6 commits intomainfrom
neelay/stacktrace-fix

Conversation

@neelay893
Copy link
Contributor

When KIRIN_PYTHON_STACKTRACE is set to 0, the source traceback should identify the statement in the original kernel that's causing the error. This is currently blank due to a bug in the base interpreter error handling; this PR fixes the issue.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
11748 10476 89% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/kirin/interp/abc.py 87% 🟢
src/kirin/lowering/python/binding.py 87% 🟢
TOTAL 87% 🟢

updated for commit: b11d3fb by action🐍

@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-02-25 05:19 UTC

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@neelay893
Copy link
Contributor Author

I also updated the black version to 26.1 as this was causing issues with github actions (I think actions is configured to use the latest stable version of black)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to fix missing/blank “source traceback” output when KIRIN_PYTHON_STACKTRACE=0 by preserving interpreter frames on exceptions so the exception handler can identify the originating kernel statement.

Changes:

  • Modify InterpreterABC.new_frame() to avoid popping frames on exceptions, preserving the full frame chain for traceback formatting.
  • Update a few formatting/style items (assignment tests, generator script formatting, Binding error string formatting).
  • Update dev tooling/dependencies (Black, lockfile changes; plus new optional deps/extra entries in the lockfile).

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/kirin/interp/abc.py Preserve interpreter frame chain on exceptions to enable correct source traceback output.
src/kirin/lowering/python/binding.py Reformat NotImplementedError raising code (string layout changed).
test/lowering/test_assign.py Adjust tuple-unpacking assignment syntax to match formatter expectations.
src/kirin/dialects/math/_gen.py Refactor string writes into more compact calls (no functional intent indicated).
pyproject.toml Bump Black version requirement.
.pre-commit-config.yaml Bump Black pre-commit hook revision.
uv.lock Lockfile updates: toolchain version bump, Black/pathspec/pytokens updates, and new optional dependency entries (e.g., vmath extra with numpy/scipy).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +267 to +271
except BaseException:
# NOTE: Don't pop frames on exception so that eval_context
# can capture the full frame chain for the stack trace.
# The state is re-initialized on the next eval_context call.
raise
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

new_frame now catches BaseException and deliberately leaves frames on the interpreter state. This means KeyboardInterrupt/SystemExit will also leave the interpreter stack dirty, and it also doesn't line up with eval_context, which only annotates Exception instances with KIRIN_INTERP_STATE. Consider catching Exception here (or alternatively updating eval_context to handle BaseException and resetting self.state after attaching it to the raised exception) so non-error control-flow exceptions don't leak frames.

Copilot uses AI. Check for mistakes.
Comment on lines +268 to 273
# NOTE: Don't pop frames on exception so that eval_context
# can capture the full frame chain for the stack trace.
# The state is re-initialized on the next eval_context call.
raise
else:
self.state.pop_frame()
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

Because frames are no longer popped on exception, there’s currently no test coverage ensuring the source traceback includes the expected statement when KIRIN_PYTHON_STACKTRACE=0. Adding a regression test that triggers an interpreter error and asserts the printed stack trace contains the originating stmt/source would prevent this from silently regressing.

Copilot uses AI. Check for mistakes.
neelay893 and others added 2 commits February 24, 2026 15:54
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Collaborator

@kaihsin kaihsin left a comment

Choose a reason for hiding this comment

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

LGTM

@Roger-luo Roger-luo merged commit cbace08 into main Feb 25, 2026
13 checks passed
@Roger-luo Roger-luo deleted the neelay/stacktrace-fix branch February 25, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants