Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address code review
  • Loading branch information
corona10 committed Jun 22, 2025
commit ea112a555b885f6ab84bd73232adb210b9c65419
17 changes: 9 additions & 8 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2367,19 +2367,20 @@ def testfunc(n):
def test_store_fast_pop_top_specialize_unicode(self):
def random_str(n):
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(n))
def testfunc(n):
y = random_str(32)
def testfunc(args):
a, b, n = args
c = ''
for _ in range(n):
x = y + y # _POP_TOP
x = None # _POP_TOP_NOP

testfunc(TIER2_THRESHOLD)
c += a + b
return c

ex = get_first_executor(testfunc)
r0, r1 = random_str(32), random_str(32)
res, ex = self._run_with_optimizer(testfunc, (r0, r1, TIER2_THRESHOLD))
self.assertAlmostEqual(res, TIER2_THRESHOLD * (r0 + r1))
self.assertIsNotNone(ex)
uops = get_opnames(ex)

self.assertIn("_POP_TOP_NOP", uops)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also add

self.assertIn("_BINARY_OP_ADD_UNICODE", uops)

to make sure this is the op that's actually generated?

Should we also test for _POP_TOP_UNICODE?

Copy link
Member Author

Choose a reason for hiding this comment

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

In this code, It will be replaced to _POP_TOP_NOP because _POP_TOP_UNICODE will be optimized to _POP_TOP_NOP .

Copy link
Member

Choose a reason for hiding this comment

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

Yup, do you think it makes sense to test _POP_TOP_UNICODE separately? That is, the case when it is not optimized to _POP_TOP_NOP? (not sure how difficult it'll be to come up with a test case though)

Copy link
Member

Choose a reason for hiding this comment

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

I have a test for that in my original PR already.

self.assertNotIn("_POP_TOP_UNICODE", uops)

def test_attr_promotion_failure(self):
# We're not testing for any specific uops here, just
Expand Down
Loading