mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
gh-130704: Strength reduce LOAD_FAST{_LOAD_FAST}
(#130708)
Optimize `LOAD_FAST` opcodes into faster versions that load borrowed references onto the operand stack when we can prove that the lifetime of the local outlives the lifetime of the temporary that is loaded onto the stack.
This commit is contained in:
parent
e9556e1004
commit
053c285f6b
35 changed files with 1282 additions and 345 deletions
|
@ -597,6 +597,22 @@ class TestFrameLocals(unittest.TestCase):
|
|||
with self.assertRaises(TypeError):
|
||||
FrameLocalsProxy(frame=sys._getframe()) # no keyword arguments
|
||||
|
||||
def test_overwrite_locals(self):
|
||||
# Verify we do not crash if we overwrite a local passed as an argument
|
||||
# from an ancestor in the call stack.
|
||||
def f():
|
||||
xs = [1, 2, 3]
|
||||
ys = [4, 5, 6]
|
||||
return g(xs)
|
||||
|
||||
def g(xs):
|
||||
f = sys._getframe()
|
||||
f.f_back.f_locals["xs"] = None
|
||||
f.f_back.f_locals["ys"] = None
|
||||
return xs[1]
|
||||
|
||||
self.assertEqual(f(), 2)
|
||||
|
||||
|
||||
class FrameLocalsProxyMappingTests(mapping_tests.TestHashMappingProtocol):
|
||||
"""Test that FrameLocalsProxy behaves like a Mapping (with exceptions)"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue