Skip to content

Prevent symbol table exhaustion during codegen#6670

Merged
youknowone merged 5 commits intomainfrom
copilot/fix-panic-in-compile-rs
Jan 8, 2026
Merged

Prevent symbol table exhaustion during codegen#6670
youknowone merged 5 commits intomainfrom
copilot/fix-panic-in-compile-rs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 7, 2026

The compiler panicked on push_symbol_table when compiling xonsh/pytest hooks, crashing the run.

  • Error handling: push_symbol_table now returns a codegen error if no subtable is available, rather than panicking.
  • Propagation: All callers (function/class/type-param/type-alias/comprehension setup) were adjusted to bubble the failure instead of assuming infallibility.
  • Robustness: Symbol tables now keep a cursor instead of removing subtables, so repeated compilation paths (e.g., try/finally double passes) reuse the same entries and avoid exhaustion.

Example (simplified):

// Before: panic!("push_symbol_table: no sub_tables…")
let table = self.push_symbol_table()?; // now returns a CompileResult
self.enter_scope(name, table.typ, key, lineno)?;
Original prompt

This section details on the original issue you should resolve

<issue_title>thread 'main' panicked at crates/codegen/src/compile.rs:648:13:</issue_title>
<issue_description>```xsh
rustpython -V

Python 3.13.0alpha (heads/master:8bfe927de

```xsh
cd xonsh/
RUST_BACKTRACE=full rust-pytest
thread 'main' (16880887) panicked at crates/codegen/src/compile.rs:648:13:
push_symbol_table: no sub_tables available in pytest_runtest_protocol (type: Function)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
RUST_BACKTRACE=full rust-pytest
thread 'main' (16878492) panicked at crates/codegen/src/compile.rs:648:13:
push_symbol_table: no sub_tables available in pytest_runtest_protocol (type: Function)
stack backtrace:
   0:        0x102dc7ba0 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h2808c764b780ef77
   1:        0x10230cfb4 - core::fmt::write::h164e2e78980a3344
   2:        0x102da5654 - std::io::Write::write_fmt::hc5b2a4d160c11c86
   3:        0x102dabf88 - std::sys::backtrace::BacktraceLock::print::h765d16e49e83c7b3
   4:        0x102dae4b0 - std::panicking::default_hook::{{closure}}::hf5d7ef6cefa10586
   5:        0x102dae110 - std::panicking::default_hook::h8781bd6c5c54e4cc
   6:        0x102dae9a0 - std::panicking::panic_with_hook::h93c775fc227522dd
   7:        0x102dae68c - std::panicking::panic_handler::{{closure}}::h8561e58c9391724a
   8:        0x102dac094 - std::sys::backtrace::__rust_end_short_backtrace::h55629ed76aaa9d26
   9:        0x102d9d948 - __rustc[d9b87f19e823c0ef]::rust_begin_unwind
  10:        0x102f63924 - core::panicking::panic_fmt::hfe9cfd57c06d80d9
  11:        0x1025b79c4 - rustpython_codegen::compile::Compiler::push_symbol_table::hfeafda8d0290b5ca
  12:        0x1025ae1d0 - rustpython_codegen::compile::Compiler::push_output::ha6ee3ae42a4636e3
  13:        0x1025bddf4 - rustpython_codegen::compile::Compiler::compile_comprehension::hb484e6cf43f9f5cf
  14:        0x1025ba7ec - rustpython_codegen::compile::Compiler::compile_expression::he6bbf8bb018e050e
  15:        0x1025b9854 - rustpython_codegen::compile::Compiler::compile_expression::he6bbf8bb018e050e
  16:        0x1025b476c - rustpython_codegen::compile::Compiler::compile_statement::hc5fc9a32b46a1d02
  17:        0x1025c064c - rustpython_codegen::compile::Compiler::compile_try_statement::hc999aeecc9056ff6
  18:        0x1025b5430 - rustpython_codegen::compile::Compiler::compile_statement::hc5fc9a32b46a1d02
  19:        0x1025be78c - rustpython_codegen::compile::Compiler::compile_function_body::h9dee484648b86dae
  20:        0x1025b6500 - rustpython_codegen::compile::Compiler::compile_statement::hc5fc9a32b46a1d02
  21:        0x1025b8dd0 - rustpython_codegen::compile::Compiler::compile_class_body::h3590690ed451b898
  22:        0x1025b68f0 - rustpython_codegen::compile::Compiler::compile_statement::hc5fc9a32b46a1d02
  23:        0x1025aad50 - rustpython_codegen::compile::compile_program::ha3ec8bdff9e2b9e1
  24:        0x1025aaa18 - rustpython_codegen::compile::compile_top::haa9565b0967bdaa9
  25:        0x10262019c - rustpython_compiler::compile::hecf8b963be2e901f
  26:        0x102b492e0 - rustpython_vm::vm::compile::<impl rustpython_vm::vm::VirtualMachine>::compile_with_opts::h6b00ff523f94fe36
  27:        0x102c43ec8 - rustpython_vm::function::builtin::<impl rustpython_vm::function::builtin::sealed::PyNativeFnInternal<(rustpython_vm::function::builtin::OwnedParam<T1>,),R,rustpython_vm::vm::VirtualMachine> for F>::call_::h593b1ec8c5dcbe5b
  28:        0x102bd684c - rustpython_vm::types::slot::Callable::slot_call::h5005acbfd54ce314
  29:        0x102c11458 - rustpython_vm::protocol::callable::PyCallable::invoke::hc7b3c913f7e70e38
  30:        0x10284a180 - rustpython_vm::protocol::callable::<impl rustpython_vm::object::core::PyObject>::call_with_args::hc88ea6065efebfed
  31:        0x10297e928 - rustpython_vm::frame::ExecutingFrame::execute_call::h8fca0c22a2e74162
  32:        0x102983240 - rustpython_vm::frame::ExecutingFrame::run::h4716dfe6b63c4134
  33:        0x10281b614 - rustpython_vm::frame::<impl rustpython_vm::object::core::Py<rustpython_vm::frame::Frame>>::run::hebd968f3912dd00a
  34:        0x102b344f0 - rustpython_vm::vm::VirtualMachine::with_frame::ha2d5eded57c7e9ac
  35:        0x10283e61c - rustpython_vm::builtins::function::<impl rustpython_vm::object::core::Py<rustpython_vm::builtins::function::PyFunction>>::invoke_with_locals::hd27346d63756e6f4
  36:        0x1029943ac - rustpython_vm::types::slot::Callable::slot_call::hac99f1a27112728a
  37:        0x102c11458 - rustpython_vm::protocol::callable::PyCallable::invoke::hc7b3c913f7e70e38
  38:        0x10284a180 - rustpython_vm::protocol::callable::<impl rustpython_vm::object::core::PyObject>::call_with_args::hc88ea6065efebfed
  39:        0x1029804d8 - rustpython_vm::frame::ExecutingFrame::execute_method_call::h50295f4f91eb6167
  40:        0x1029844...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes RustPython/RustPython#6641

<!-- START COPILOT CODING AGENT TIPS -->
---Let Copilot coding agent [set things up for you](https://github.com/RustPython/RustPython/issues/new?title=+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 7, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

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


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

Copilot AI and others added 2 commits January 7, 2026 00:57
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic in compile.rs at push_symbol_table Stop panicking when symbol tables are exhausted during codegen Jan 7, 2026
Copilot AI requested a review from youknowone January 7, 2026 01:04
@youknowone
Copy link
Copy Markdown
Member

@copilot That's a meaningful enhancement, but doesn't fix the fundamental problem. Could you investigate more what caused that error and fix the fundamental problem?

Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 7, 2026

@copilot That's a meaningful enhancement, but doesn't fix the fundamental problem. Could you investigate more what caused that error and fix the fundamental problem?

Root cause was that we consumed and removed sub-tables, so double-compilation paths (e.g., try/finally) could exhaust the cursor and leave no tables for later scopes. I switched to tracking a per-table cursor and resetting it when recompiling paths, so we reuse the same symbol tables instead of removing them (commit 5121b75).

Copilot AI changed the title Stop panicking when symbol tables are exhausted during codegen Prevent symbol table exhaustion during codegen Jan 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 7, 2026

Code has been automatically formatted

The code in this PR has been formatted using cargo fmt --all.
Please pull the latest changes before pushing again:

git pull origin copilot/fix-panic-in-compile-rs

@youknowone youknowone marked this pull request as ready for review January 8, 2026 09:15
@youknowone youknowone merged commit a3425b4 into main Jan 8, 2026
43 of 46 checks passed
@youknowone youknowone deleted the copilot/fix-panic-in-compile-rs branch January 8, 2026 21:32
terryluan12 pushed a commit to terryluan12/RustPython that referenced this pull request Jan 15, 2026
* Handle missing symbol table without panic

* Update symbol table error message

* Track symbol table cursors to avoid exhaustion

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

2 participants