Materialize code constants through the VM (#8867)

PyObjBag built code object constants from a Context alone, and its
frozenset arm was unimplemented!(), so ctx.new_code() panicked on code
containing a frozenset constant such as `x in {1, 2, 3}`.

IntoCodeObject now takes a VirtualMachine and uses PyVmBag for bytecode
and frozen code objects. Context::new_code, PyObjBag and
AsBag for &Context are removed; callers use VirtualMachine::new_code.

Assisted-by: Claude:claude-opus-5-5
Assisted-by: Grok:grok-4.7
This commit is contained in:
Jeong, YunWon authored and GitHub committed 2026-10-02 17:24:46 +09:00
1 parent d88c344847
commit c8d63e848e
8 files changed
+49 -100

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ fn run(vm: &vm::VirtualMachine) -> vm::PyResult<()> {
// the file parameter is relative to the current file.
let module = vm::py_compile!(file = "freeze.py");
let res = vm.run_code_obj(vm.ctx.new_code(module), scope);
let res = vm.run_code_obj(vm.new_code(module), scope);
if let Err(exc) = res {
vm.print_exception(&exc);
+1 -1
View File
@@ -16,7 +16,7 @@ macro_rules! add_python_function {
// compile the code to bytecode
let code = vm::py_compile!(source = $src);
// convert the rustpython_compiler_core::CodeObject to a PyRef<PyCode>
let code = $vm.ctx.new_code(code);
let code = $vm.new_code(code);
// run the python code in the scope to store the function
$vm.run_code_obj(code, $scope.clone())