Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-144145: Track nullness of properties in the Tier 2 JIT optimizer#144122
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| // Maximum slots per object tracked symbolically | ||
| #define MAX_SYMBOLIC_SLOTS_SIZE 16 | ||
| #define SLOTS_ARENA_SIZE (MAX_SYMBOLIC_SLOTS_SIZE * 100) |
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.
We might need to adjust this arena_size.
markshannon commentedJan 22, 2026
This PR seems unrelated to the issue. It tracks the internal state of objects, not the uniqueness of references. Tracking the internal state of objects is tricky, as we need to keep track of where code might escape and invalidate any knowledge prior to the escape. So far, we have only tracked properties of stateless objects, so it isn't an issue. In future, I would also advise waiting to see if there is general support on the issue before spending time on the implementation. |
cocolato commentedJan 22, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks for reply!
Sorry, I'm linking to this issue because I discussed the implementation logic with@Fidget-Spinner in this issue, and I think this should be a pre-task for unique reference tracking (if I'm wrong, please point it out, thanks!). I'll create a new issue to link to this PR.
Sorry again for overlooking object escape. I think may be Ken Jin's original requirement was just to add tracking for the Slots object(if I'm wrong, please point it out again, thanks!). Perhaps I should remove the optimization in the
Thanks for the reminder. I'll be more careful in the future. |
__slots__ object property tracking for the Tier 2 JIT optimizer__slots__ object property tracking for the Tier 2 JIT optimizerFidget-Spinner commentedJan 22, 2026
Yeah we need to track for escapes. I mentioned it here how to do it#143414 (comment). It got lost in the noise though, so no worries.
I advised@cocolato to embark on this issue. I think there is value in doing it. They waited for me to give my go-ahead before doing it. So I think they didn't do anything wrong. |
cocolato commentedJan 22, 2026
Thanks! I will refactor this to also support#144141. |
cocolato commentedJan 22, 2026
@Fidget-Spinner Hi, one thing i want to know. Should this PR flag which property escape during escape handling UOPs (e.g. |
Fidget-Spinner commentedJan 22, 2026
Sorry I'm busy for these 2 days. I'll try to review on Saturday. If Mark reviews it earlier, we can go with his ideas. |
Fidget-Spinner commentedJan 24, 2026
No. The problem is any uop that escapes must be handled. For example, anything with |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Python/optimizer_analysis.c Outdated
| // Track escapes | ||
| if (_PyUop_Flags[out_ptr->opcode] & HAS_ESCAPES_FLAG) { | ||
| ctx->last_escape_index = uop_buffer_length(&ctx->out_buffer); | ||
| } |
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.
@Fidget-Spinner If we use this method to detect escapes, then eachPOP_TOP following_STORE_ATTR_SLOT will cause tracked slot values invalid due toHAS_ESCAPES_FLAG. Could you please give me some guidance? Thanks!
__slots__ object property tracking for the Tier 2 JIT optimizercocolato commentedJan 28, 2026
Updated. |
cocolato commentedJan 29, 2026
Added new uop |
Fidget-Spinner commentedJan 29, 2026
That doesn't seem right. RETURN_VALUE is escaping, as it's possibly freeing locals in a frame, which can trigger arbitrary code. |
Fidget-Spinner left a comment
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.
Looks pretty good, just two comments
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
cocolato commentedJan 30, 2026
Updated, added |
Fidget-Spinner commentedJan 30, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Cool, this LGTM now I think. This deserves a news entry. Potentially call it: I know it's not just nullness, but in all practicality due to the escapes, it's just nullness for now. |
| typedef struct { | ||
| uint16_t slot_index; | ||
| uint16_t symbol; | ||
| } JitOptDescrMapping; |
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.
Is it safe to use this for both normal objects and objects with__slots__, or do we need a separate symbol?
Basically I'm asking if it's possible for an object to both have STORE_ATTR_INSTANCE_VALUE and STORE_ATTR_SLOT, as this will cause a index collision between the slots and offset. It it safe also withSTORE_ATTR_WITH_HINT, as can that can mix withSTORE_ATTR_INSTANCE_VALUE?
If you think of an answer, please let me know, and we can add it as a comment in the code. otherwise, this is kind of scary.
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.
These two never appear on the same object type because:STORE_ATTR_INSTANCE_VALUE needsPy_TPFLAGS_MANAGED_DICT flag.
Therefore, there is no index collision between slot offsets and inline value offsets.
Lines 665 to 669 in5f57f69
| // No descriptor, or non overriding. | |
| if ((type->tp_flags&Py_TPFLAGS_MANAGED_DICT)==0) { | |
| SPECIALIZATION_FAIL(base_op,SPEC_FAIL_ATTR_NOT_MANAGED_DICT); | |
| return0; | |
| } |
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.
However, conflicts betweenSTORE_ATTR_INSTANCE_VALUE andSTORE_ATTR_WITH_HINT can indeed occur. Perhaps a flag could be added to the index to distinguish between the two types?
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.
Should we trackSTORE_ATTR_WITH_HINT in this PR?
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.
No lets ignore with hint for now.
Fidget-Spinner left a comment
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.
Thanks
1dc12b2 intopython:mainUh oh!
There was an error while loading.Please reload this page.
Fidget-Spinner commentedJan 30, 2026
Thanks! Do you want to handle STORE_ATTR_WITH_HINT Too? |
cocolato commentedJan 30, 2026
Sure, I will work on it :) |
Uh oh!
There was an error while loading.Please reload this page.
This PR implements symbolic tracking for
__slots__object attributes in the Tier 2 JIT optimizer.Currently, when the JIT optimizer encounters
_LOAD_ATTR_SLOT, it creates a new unknown symbol (<!NULL>) even if the same slot was previously written in the same trace. This prevents the optimizer from:Before(set PYTHON_OPT_DEBUG=5):
Now:
__slots__object and its property in the Tier 2 optimizer #144145