Repository navigation
new TestUopsOptimization test case failing an assert #117180
Copy link
Copy link
Closed
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
While writing test cases for #116168, I ran into a case that failed on main too. Here's the test as a diff. It's under test_opt.TestUopsOptimization:
diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py
index b0859a382d..269753e4c1 100644
--- a/Lib/test/test_capi/test_opt.py
+++ b/Lib/test/test_capi/test_opt.py
@@ -955,6 +955,31 @@ def testfunc(n):
_, ex = self._run_with_optimizer(testfunc, 16)
self.assertIsNone(ex)
+ def test_many_nested(self):
+ # overflow the trace_stack
+ def dummy_a(x):
+ return x
+ def dummy_b(x):
+ return dummy_a(x)
+ def dummy_c(x):
+ return dummy_b(x)
+ def dummy_d(x):
+ return dummy_c(x)
+ def dummy_e(x):
+ return dummy_d(x)
+ def dummy_f(x):
+ return dummy_e(x)
+ def dummy_g(x):
+ return dummy_f(x)
+ def dummy_h(x):
+ return dummy_g(x)
+ def testfunc(n):
+ a = 0
+ for _ in range(n):
+ a += dummy_h(n)
+ return a
+
+ self._run_with_optimizer(testfunc, 32)
if __name__ == "__main__":
unittest.main()I'm running this locally (source build of main 9967b568edd2e35b0415c14c7242f3ca2c0dc03d on an M1 mac).
Command:
./python.exe -m test test.test_capi.test_opt
Output:
Using random seed: 1780919823
Raised RLIMIT_NOFILE: 256 -> 1024
0:00:00 load avg: 2.88 Run 1 test sequentially
0:00:00 load avg: 2.88 [1/1] test.test_capi.test_opt
Assertion failed: ((this_instr + 2)->opcode == _PUSH_FRAME), function optimize_uops, file optimizer_cases.c.h, line 1600.
Fatal Python error: Aborted
Current thread 0x000000020140a100 (most recent call first):
File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/test/test_capi/test_opt.py", line 979 in testfunc
File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/test/test_capi/test_opt.py", line 588 in _run_with_optimizer
File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/test/test_capi/test_opt.py", line 982 in test_many_nested
File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/unittest/case.py", line 589 in _callTestMethod
....[truncated for brevity]....
File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/runpy.py", line 88 in _run_code
File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/runpy.py", line 198 in _run_module_as_main
Extension modules: _testcapi, _testinternalcapi (total: 2)
zsh: abort ./python.exe -m test test.test_capi.test_opt
This assertion is in the optimizer case for _INIT_CALL_PY_EXACT_ARGS. I haven't investigated any further beyond that.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
gvanrossum commentedon Mar 23, 2024
Thanks for finding this. It's this assert:
in
_INIT_CALL_PY_EXACT_ARGSin optimizer_bytecodes.c. I added that a few days ago. I'll come up with a fix.Fidget-Spinner commentedon Mar 23, 2024
@gvanrossum I dug into this further and it's actually two bugs:
gvanrossum commentedon Mar 23, 2024
Oh, thanks! If you have time for a fix I can review it.
gvanrossum commentedon Mar 23, 2024
Maybe it's better to back out the entire sequence of uops generated by the
CALL_*instruction containing the push?Fidget-Spinner commentedon Mar 23, 2024
Yeah that seems better. Right now it's deopting after _INIT_CALL_PY_EXACT_ARGS which creates a new frame, this means the stack is inconsistent with CALL_PY_EXACT_ARGS and the whole thing crashes.
gvanrossum commentedon Mar 23, 2024
In the end I think it's better to emit the
_PUSH_TRACE(it was being emitted until I refactored that code a few days ago).gh-117180: Complete call sequence when trace stack overflow (GH-117184)
lazorchakp commentedon Mar 24, 2024
Thanks for getting to this so quickly! This fix should also simplify an edge case for #116168 too, which is helpful for me.
pythongh-117180: Complete call sequence when trace stack overflow (py…
Squashed commit of the following:
Squashed commit of the following:
pythongh-117180: Complete call sequence when trace stack overflow (py…