summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_peepholer.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-12-15 12:12:14 (GMT)
committerGitHub <noreply@github.com>2017-12-15 12:12:14 (GMT)
commitb580f4f2bf49fd3b11f2a046911993560c02492a (patch)
tree8c0230cbd8e2cdbfaf003d48e14d664fd229de82 /Lib/test/test_peepholer.py
parentb82da9ebb20053637e731fd40589e1e52f9f8f6e (diff)
downloadcpython-b580f4f2bf49fd3b11f2a046911993560c02492a.zip
cpython-b580f4f2bf49fd3b11f2a046911993560c02492a.tar.gz
cpython-b580f4f2bf49fd3b11f2a046911993560c02492a.tar.bz2
[3.6] bpo-30416: Protect the optimizer during constant folding. (#4865)
It no longer spends much time doing complex calculations and no longer consumes much memory for creating large constants that will be dropped later. This fixes also bpo-21074.
Diffstat (limited to 'Lib/test/test_peepholer.py')
-rw-r--r--Lib/test/test_peepholer.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py
index b033640..e028b09 100644
--- a/Lib/test/test_peepholer.py
+++ b/Lib/test/test_peepholer.py
@@ -178,8 +178,15 @@ class TestTranforms(BytecodeTestCase):
self.assertInBytecode(code, 'LOAD_CONST', 'b')
# Verify that large sequences do not result from folding
- code = compile('a="x"*1000', '', 'single')
+ code = compile('a="x"*10000', '', 'single')
+ self.assertInBytecode(code, 'LOAD_CONST', 10000)
+ self.assertNotIn("x"*10000, code.co_consts)
+ code = compile('a=1<<1000', '', 'single')
self.assertInBytecode(code, 'LOAD_CONST', 1000)
+ self.assertNotIn(1<<1000, code.co_consts)
+ code = compile('a=2**1000', '', 'single')
+ self.assertInBytecode(code, 'LOAD_CONST', 1000)
+ self.assertNotIn(2**1000, code.co_consts)
def test_binary_subscr_on_unicode(self):
# valid code get optimized