Give each callable type its own `PyTrait::py_call`

Merged
RE
3mo ago
+428-161

VM::call_heap_callable had grown into a hundred-line match over HeapData, one arm per callable type. py_call is added to PyTrait.

Closure, FunctionDefaults and ExtFunction gain the PyTrait impls they never had.

Note:py_call holds its HeapRead across the dispatch.

🤖 Generated with Claude Code


Summary by cubic

Moves callable dispatch out of a single match over heap callables into PyTrait::py_call, implemented by each callable type in its own module. No behavior change is intended; Closure, FunctionDefaults, and ExtFunction gain the PyTrait impls they previously lacked.

Refactors

  • The trait default raises the same TypeError for non-callables the rejected match arm raised, while dropping the call's arguments.
  • A callable that dispatches onward holds its HeapRead across the nested call, which callers' own references make safe.
  • Regression tests cover leaking arguments on the non-callable TypeError path and the partial chain RecursionError bail-out path.