gh-126298: Don't deduplicate slice constants based on equality#126398
Conversation
da12eed to
af304c8
Compare
brandtbucher
left a comment
There was a problem hiding this comment.
Looks good! Just a typo in one test, and some further suggestions for completeness:
| actual += 1 | ||
| self.assertEqual(actual, expected) | ||
|
|
||
| def check_num_consts(func, typ, expected): |
There was a problem hiding this comment.
I think everywhere this is used it's called with 0 expected. Maybe just replace those calls with check_consts(func, typ, set()) since both functions are so similar?
| def store(): | ||
| x[a:b] = y | ||
| x [a:] = y | ||
| x[a:] = y |
There was a problem hiding this comment.
This whitespace might be intentional... load has the exact same whitespace above. We are testing the compiler, after all.
I'm inclined to just leave it.
| return x[a:b] + x [a:] + x[:b] + x[:] | ||
|
|
||
| check_op_count(load, "BINARY_SLICE", 3) | ||
| check_op_count(load, "BUILD_SLICE", 0) |
There was a problem hiding this comment.
| check_op_count(load, "BUILD_SLICE", 0) | |
| check_op_count(load, "BUILD_SLICE", 0) | |
| check_op_count(load, "BINARY_SUBSCR", 1) |
| x[:] = y | ||
|
|
||
| check_op_count(store, "STORE_SLICE", 3) | ||
| check_op_count(store, "BUILD_SLICE", 0) |
There was a problem hiding this comment.
| check_op_count(store, "BUILD_SLICE", 0) | |
| check_op_count(store, "BUILD_SLICE", 0) | |
| check_op_count(store, "STORE_SUBSCR", 1) |
| return x[a:b:c] | ||
|
|
||
| check_op_count(long_slice, "BUILD_SLICE", 1) | ||
| check_op_count(long_slice, "BINARY_SLICE", 0) |
There was a problem hiding this comment.
| check_op_count(long_slice, "BINARY_SLICE", 0) | |
| check_op_count(long_slice, "BINARY_SLICE", 0) | |
| check_op_count(long_slice, "BINARY_SUBSCR", 1) |
| check_op_count(aug, "BINARY_SLICE", 1) | ||
| check_op_count(aug, "STORE_SLICE", 1) | ||
| check_op_count(aug, "BUILD_SLICE", 0) | ||
| check_num_consts(long_slice, slice, 0) |
There was a problem hiding this comment.
| check_num_consts(long_slice, slice, 0) | |
| check_num_consts(aug, slice, 0) |
|
|
||
| check_op_count(aug, "BINARY_SLICE", 1) | ||
| check_op_count(aug, "STORE_SLICE", 1) | ||
| check_op_count(aug, "BUILD_SLICE", 0) |
There was a problem hiding this comment.
| check_op_count(aug, "BUILD_SLICE", 0) | |
| check_op_count(aug, "BUILD_SLICE", 0) | |
| check_op_count(aug, "BINARY_SUBSCR", 0) | |
| check_op_count(aug, "STORE_SUBSCR", 0) |
| x[1:2] += y | ||
|
|
||
| check_op_count(aug_const, "BINARY_SLICE", 0) | ||
| check_op_count(aug_const, "STORE_SLICE", 0) |
There was a problem hiding this comment.
| check_op_count(aug_const, "STORE_SLICE", 0) | |
| check_op_count(aug_const, "STORE_SLICE", 0) | |
| check_op_count(aug_const, "BINARY_SUBSCR", 1) | |
| check_op_count(aug_const, "STORE_SUBSCR", 1) |
| check_op_count(aug_const, "STORE_SLICE", 0) | ||
| check_consts(aug_const, slice, 1) | ||
| check_op_count(compound_const_slice, "BINARY_SLICE", 0) | ||
| check_op_count(compound_const_slice, "BUILD_SLICE", 0) |
There was a problem hiding this comment.
| check_op_count(compound_const_slice, "BUILD_SLICE", 0) | |
| check_op_count(compound_const_slice, "BUILD_SLICE", 0) | |
| check_op_count(compound_const_slice, "STORE_SLICE", 0) | |
| check_op_count(compound_const_slice, "BINARY_SUBSCR", 1) |
|
|
||
| def check_consts(func, typ, expected): | ||
| slice_consts = 0 | ||
| all_consts = set() |
There was a problem hiding this comment.
I don't think this is working correctly - slices just defer to their contents for hash/equality, so this will be deduplicating the slices in the same way this is trying to fix.
…ython#126398) * pythongh-126298: Don't deduplicated slice constants based on equality * NULL check for PySlice_New * Fix refcounting * Fix refcounting some more * Fix refcounting * Make tests more complete * Fix tests
…ython#126398) * pythongh-126298: Don't deduplicated slice constants based on equality * NULL check for PySlice_New * Fix refcounting * Fix refcounting some more * Fix refcounting * Make tests more complete * Fix tests
Uh oh!
There was an error while loading. Please reload this page.