From e92bc6753690c1e45b98f55da27adfab1b0a939e Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Mon, 10 Jul 2023 14:07:39 +0900 Subject: [PATCH 1/3] gh-104635: Add a test case for variables that have a dependency. --- Lib/test/test_compile.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 784c0550cc09b1..1e064895ae4d1c 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -1186,6 +1186,12 @@ def f(x, y, z): return a self.assertEqual(f("x", "y", "z"), "y") + def test_variable_dependent(self): + def f(): + a = 42; b = a + 54; a = 54 + return a, b + self.assertEqual(f(), (54, 96)) + @requires_debug_ranges() class TestSourcePositions(unittest.TestCase): From b228473242570b7f6f4934b231e73f42c3af1d80 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Mon, 10 Jul 2023 23:35:47 +0900 Subject: [PATCH 2/3] Add comment --- Lib/test/test_compile.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 1e064895ae4d1c..141f835f0a3b4e 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -1187,6 +1187,9 @@ def f(x, y, z): self.assertEqual(f("x", "y", "z"), "y") def test_variable_dependent(self): + # gh-104635: Since the value of b is dependent on the value of a + # the first STORE_FAST for a should not be skipped. (e.g POP_TOP). + # This test case is added for prevent future regression from aggresive optimization. def f(): a = 42; b = a + 54; a = 54 return a, b From c0f039337cb9fa5fd45bf7a11531c78236b89789 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Tue, 11 Jul 2023 07:27:50 +0900 Subject: [PATCH 3/3] Update Lib/test/test_compile.py Co-authored-by: Carl Meyer --- Lib/test/test_compile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 141f835f0a3b4e..85ce0a4b39d854 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -1189,7 +1189,7 @@ def f(x, y, z): def test_variable_dependent(self): # gh-104635: Since the value of b is dependent on the value of a # the first STORE_FAST for a should not be skipped. (e.g POP_TOP). - # This test case is added for prevent future regression from aggresive optimization. + # This test case is added to prevent potential regression from aggressive optimization. def f(): a = 42; b = a + 54; a = 54 return a, b