Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-104635: Add a test case for variables that have a dependency. #106583

Merged
merged 3 commits into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,15 @@ def f(x, y, z):
return a
self.assertEqual(f("x", "y", "z"), "y")

def test_variable_dependent(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain the purpose of the test in a comment? From the code, it's nonibvious to me how it can be miscompiled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain the purpose of the test in a comment? From the code, it's nonibvious to me how it can be miscompiled.

No, it doesn't miscompile at this optimization moment.
But I was quite surprised with the CI never failed with the wrong compile for the #106571 (comment).
So it could be good to be added. I thought that miscompile case should be caught at the CI level.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't say that the code is miscompiled. I propose adding a comment to explain that the test checks that this specific code is not miscompiled, but please explain why it could be miscompiled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

# 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 to prevent potential regression from aggressive optimization.
def f():
a = 42; b = a + 54; a = 54
return a, b
self.assertEqual(f(), (54, 96))


@requires_debug_ranges()
class TestSourcePositions(unittest.TestCase):
Expand Down