-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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-91389: Fix dis
position information for CACHE
s
#93663
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
41cfadc
Update tests for intended behavior
brandtbucher 0653bc5
Fix interactions between Positions and CACHEs
brandtbucher 44c742a
blurb add
brandtbucher 986ce3a
make patchcheck
brandtbucher 994d711
Catch up with main
brandtbucher 8266ba9
Feedback from code review
brandtbucher d500bf2
Naming is hard
brandtbucher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1197,8 +1197,10 @@ def test_show_caches(self): | |||||
caches = list(self.get_cached_values(quickened, adaptive)) | ||||||
for cache in caches: | ||||||
self.assertRegex(cache, pattern) | ||||||
self.assertEqual(caches.count(""), 8) | ||||||
self.assertEqual(len(caches), 22) | ||||||
total_caches = 22 | ||||||
empty_caches = 8 if adaptive and quickened else total_caches | ||||||
self.assertEqual(caches.count(""), empty_caches) | ||||||
self.assertEqual(len(caches), total_caches) | ||||||
|
||||||
|
||||||
class DisWithFileTests(DisTests): | ||||||
|
@@ -1751,6 +1753,36 @@ def test_co_positions_missing_info(self): | |||||
self.assertIsNone(positions.col_offset) | ||||||
self.assertIsNone(positions.end_col_offset) | ||||||
|
||||||
@requires_debug_ranges() | ||||||
def test_co_positions_with_lots_of_caches(self): | ||||||
def roots(a, b, c): | ||||||
d = b**2 - 4 * a * c | ||||||
yield (-b - cmath.sqrt(d)) / (2 * a) | ||||||
if d: | ||||||
yield (-b + cmath.sqrt(d)) / (2 * a) | ||||||
code = roots.__code__ | ||||||
ops = code.co_code[::2] | ||||||
cache = opcode.opmap["CACHE"] | ||||||
caches = sum(op == cache for op in ops) | ||||||
non_caches = len(ops) - caches | ||||||
# Make sure we have "lots of caches". If not, roots should be updated: | ||||||
assert 1 / 3 <= caches / non_caches, "this test needs more caches!" | ||||||
for show_caches in (False, True): | ||||||
for adaptive in (False, True): | ||||||
with self.subTest(f"{adaptive=}, {show_caches=}"): | ||||||
co_positions = [ | ||||||
positions | ||||||
for op, positions in zip(ops, code.co_positions(), strict=True) | ||||||
if show_caches or op != cache | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
] | ||||||
dis_positions = [ | ||||||
instruction.positions | ||||||
for instruction in dis.get_instructions( | ||||||
code, adaptive=adaptive, show_caches=show_caches | ||||||
) | ||||||
] | ||||||
self.assertEqual(co_positions, dis_positions) | ||||||
|
||||||
# get_instructions has its own tests above, so can rely on it to validate | ||||||
# the object oriented API | ||||||
class BytecodeTests(InstructionTestCase, DisTestBase): | ||||||
|
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Library/2022-06-09-17-15-26.gh-issue-91389.OE4vS5.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix an issue where :mod:`dis` utilities could report missing or incorrect | ||
position information in the presence of ``CACHE`` entries. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.