Uh oh!
There was an error while loading. Please reload this page.
gh-148374: Fix a bug in _Py_uop_sym_get_type - #148375
Conversation
Sacul0457
commented
Apr 11, 2026
Also, would this need a news entry? |
| _Py_uop_sym_set_recorded_gen_func(ctx, rg1, func); | ||
| TEST_PREDICATE(_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func not treated as generator"); | ||
| TEST_PREDICATE(!_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func treated as generator"); | ||
| TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg1) == NULL, "recorded gen func treated as generator"); |
There was a problem hiding this comment.
This should be PyGen_Type, please edit the probable type function
There was a problem hiding this comment.
Oh sorry, I just realised what you meant in #148372, one sec
Fidget-Spinner
commented
Apr 11, 2026
I think this doesnt need one because the bug wont manifest on its own, as its always tied for FOR_ITER_GEN_FRAME which prior to your PR, was properly guarded |
Uh oh!
There was an error while loading. Please reload this page.
Sacul0457
commented
Apr 11, 2026
I just realised there's more tests I need to update |
| _Py_uop_sym_set_recorded_gen_func(ctx, rg1, func); | ||
| TEST_PREDICATE(_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func not treated as generator"); | ||
| TEST_PREDICATE(!_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func treated as generator"); | ||
| TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg1) == &PyGen_Type, "recorded gen func not treated as generator"); |
There was a problem hiding this comment.
Seems like the test is failing. Not sure why. can you do some debugging please and check what type returns? You can do something like printf("TYPE: %s\n", rg1->tp_name); (assuming rg1 is not NULL).
There was a problem hiding this comment.
I thought it was due to this test?
I have to go for a bit now, I'll upload the debug prints when i'm back
There was a problem hiding this comment.
Okay, I think I understand what's going on.
Also, it seems like all the tests use rg1. Is that intended?
JitOptRef doesn't seem to have a tp_name member I'm guessing you meant something else?
In the meantime, I did this instead:
JitOptRefrg1=_Py_uop_sym_new_unknown(ctx);
_Py_uop_sym_set_recorded_gen_func(ctx, rg1, func);
TEST_PREDICATE(!_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func treated as generator");
TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg1) ==&PyGen_Type, "rg1: recorded gen func not treated as generator");
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg1) ==NULL, "recorded gen func is treated as known value");
/* Test that setting type narrows correctly */JitOptRefrg2=_Py_uop_sym_new_unknown(ctx);
_Py_uop_sym_set_recorded_gen_func(ctx, rg2, func);
_Py_uop_sym_set_type(ctx, rg2, &PyGen_Type);
TEST_PREDICATE(!_Py_uop_sym_matches_type(rg2, &PyGen_Type), "rg2: recorded gen func not treated as generator");
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg2) ==NULL, "known type is treated as known value");
JitOptRefrg3=_Py_uop_sym_new_unknown(ctx);
_Py_uop_sym_set_recorded_gen_func(ctx, rg3, func);
_Py_uop_sym_set_type_version(ctx, rg3, PyGen_Type.tp_version_tag);
TEST_PREDICATE(!_Py_uop_sym_matches_type(rg3, &PyGen_Type), "rg3: recorded gen func not treated as generator");
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg3) ==NULL, "recorded value with type is treated as known");Output:
RunningDebug|x64interpreter...
F.....
======================================================================FAIL: test_optimizer_symbols (test.test_optimizer.TestOptimizerSymbols.test_optimizer_symbols)
----------------------------------------------------------------------Traceback (mostrecentcalllast):
File"C:\Sacul Dev Stuff\Cpython - Contributing\cpython\Lib\test\test_optimizer.py", line86, intest_optimizer_symbols_testinternalcapi.uop_symbols_test()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^AssertionError: rg2: recordedgenfuncnottreatedasgeneratorRunningDebug|x64interpreter...
F.....
======================================================================FAIL: test_optimizer_symbols (test.test_optimizer.TestOptimizerSymbols.test_optimizer_symbols)
----------------------------------------------------------------------Traceback (mostrecentcalllast):
File"C:\Sacul Dev Stuff\Cpython - Contributing\cpython\Lib\test\test_optimizer.py", line86, intest_optimizer_symbols_testinternalcapi.uop_symbols_test()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^AssertionError: rg3: recordedgenfuncnottreatedasgeneratorThere was a problem hiding this comment.
Oh yeah you're right. Please amend the other tests.
| _Py_uop_sym_set_recorded_gen_func(ctx, rg2, func); | ||
| _Py_uop_sym_set_type(ctx, rg2, &PyGen_Type); | ||
| TEST_PREDICATE(_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func not treated as generator"); | ||
| TEST_PREDICATE(!_Py_uop_sym_matches_type(rg2, &PyGen_Type), "recorded gen func treated as generator"); |
There was a problem hiding this comment.
Please add for this test and below the converse as well
TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg2) == &PyGen_Type, "recorded gen func not treated as generator");
Uh oh!
There was an error while loading. Please reload this page.
@Fidget-Spinner gentle ping!
_Py_uop_sym_get_typereturnsPyGen_Typeinstead ofNULL#148374