bpo-43846: Use less stack for large literals and calls (GH-25403)
* Modify compiler to reduce stack consumption for large expressions.
* Add more tests for stack usage.
* Add NEWS item.
* Raise SystemError for truly excessive stack use.
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index c0de3be..fd1ef61 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -961,6 +961,32 @@ def test_if_else(self):
def test_binop(self):
self.check_stack_size("x + " * self.N + "x")
+ def test_list(self):
+ self.check_stack_size("[" + "x, " * self.N + "x]")
+
+ def test_tuple(self):
+ self.check_stack_size("(" + "x, " * self.N + "x)")
+
+ def test_set(self):
+ self.check_stack_size("{" + "x, " * self.N + "x}")
+
+ def test_dict(self):
+ self.check_stack_size("{" + "x:x, " * self.N + "x:x}")
+
+ def test_func_args(self):
+ self.check_stack_size("f(" + "x, " * self.N + ")")
+
+ def test_func_kwargs(self):
+ kwargs = (f'a{i}=x' for i in range(self.N))
+ self.check_stack_size("f(" + ", ".join(kwargs) + ")")
+
+ def test_func_args(self):
+ self.check_stack_size("o.m(" + "x, " * self.N + ")")
+
+ def test_meth_kwargs(self):
+ kwargs = (f'a{i}=x' for i in range(self.N))
+ self.check_stack_size("o.m(" + ", ".join(kwargs) + ")")
+
def test_func_and(self):
code = "def f(x):\n"
code += " x and x\n" * self.N