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: Cleanups for object property tracking in JIT optimizer#144366
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -526,9 +526,9 @@ optimize_uops( | ||||
| if (ctx->out_buffer.next==out_ptr) { | ||||
| *(ctx->out_buffer.next++)=*this_instr; | ||||
| } | ||||
| boolis_init_shim=CURRENT_FRAME_IS_INIT_SHIM(); | ||||
Contributor 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
Perhaps we can remove the MemberAuthor 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. I think it's fine to just use the variable for now. | ||||
| // Track escapes | ||||
| if (_PyUop_Flags[out_ptr->opcode]&HAS_ESCAPES_FLAG) | ||||
| { | ||||
| ctx->last_escape_index=uop_buffer_length(&ctx->out_buffer)-1; | ||||
| } | ||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -25,24 +25,24 @@ state represents no information, and the BOTTOM state represents contradictory | ||||||||
| information. Though symbols logically progress through all intermediate nodes, | ||||||||
| we often skip in-between states for convenience: | ||||||||
| UNKNOWN-------------------+------------+ | ||||||||
| | | | | | ||||||||
| NULL | | | | ||||||||
| | | | |<- Anything below this level is an object. | ||||||||
| | NON_NULL-+ | | | ||||||||
| | | | | |<- Anything below this level has a known type version. | ||||||||
| | TYPE_VERSION | | | | ||||||||
| | | | | |<- Anything below this level has a known type. | ||||||||
| | KNOWN_CLASS | | | | ||||||||
| | | | | | | PREDICATE DESCR | ||||||||
| | | | INT* | | | | | ||||||||
| | | | | | | | |<- Anything below this level has a known truthiness. | ||||||||
| | | | | | TRUTHINESS | | | ||||||||
| | | | | | | | | | ||||||||
| | TUPLE | | | | | | | ||||||||
| | | | | | | | |<- Anything below this level is a known constant. | ||||||||
| | KNOWN_VALUE--+----------+------------+ | ||||||||
| | |<- Anything below this level is unreachable. | ||||||||
| BOTTOM | ||||||||
| For example, after guarding that the type of an UNKNOWN local is int, we can | ||||||||
| @@ -980,7 +980,7 @@ _Py_uop_sym_new_descr_object(JitOptContext *ctx, unsigned int type_version) | ||||||||
| res->descr.num_descrs = 0; | ||||||||
| res->descr.descrs = NULL; | ||||||||
| res->descr.type_version = type_version; | ||||||||
| res->descr.last_escape_index = uop_buffer_length(&ctx->out_buffer); | ||||||||
| return PyJitRef_Wrap(res); | ||||||||
| } | ||||||||
| @@ -995,7 +995,7 @@ _Py_uop_sym_get_attr(JitOptContext *ctx, JitOptRef ref, uint16_t slot_index) | ||||||||
| // 1. Symbol has mappings allocated | ||||||||
| // 2. No escape has occurred since last modification (state is fresh) | ||||||||
| if (sym->descr.descrs != NULL && | ||||||||
| sym->descr.last_escape_index >= ctx->last_escape_index) | ||||||||
| { | ||||||||
| for (int i = 0; i < sym->descr.num_descrs; i++) { | ||||||||
| if (sym->descr.descrs[i].slot_index == slot_index) { | ||||||||
| @@ -1026,57 +1026,56 @@ JitOptRef | ||||||||
| _Py_uop_sym_set_attr(JitOptContext *ctx, JitOptRef ref, uint16_t slot_index, JitOptRef value) | ||||||||
| { | ||||||||
| JitOptSymbol *sym = PyJitRef_Unwrap(ref); | ||||||||
| switch (sym->tag) { | ||||||||
| case JIT_SYM_DESCR_TAG: { | ||||||||
| // Check escape | ||||||||
| if (sym->descr.last_escape_index < ctx->last_escape_index) { | ||||||||
| sym->descr.num_descrs = 0; | ||||||||
| sym->descr.last_escape_index = uop_buffer_length(&ctx->out_buffer); | ||||||||
| return _Py_uop_sym_new_unknown(ctx); | ||||||||
Contributor 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
Can we update the MemberAuthor 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. Done. | ||||||||
| } | ||||||||
| // Get old value before updating | ||||||||
| JitOptRef old_value = _Py_uop_sym_new_unknown(ctx); | ||||||||
| if (sym->descr.descrs != NULL) { | ||||||||
| for (int i = 0; i < sym->descr.num_descrs; i++) { | ||||||||
| if (sym->descr.descrs[i].slot_index == slot_index) { | ||||||||
| old_value = PyJitRef_Wrap(allocation_base(ctx) + sym->descr.descrs[i].symbol); | ||||||||
| break; | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| // Check if have arena space allocated | ||||||||
| if (sym->descr.descrs == NULL) { | ||||||||
| sym->descr.descrs = descr_arena_alloc(ctx); | ||||||||
| if (sym->descr.descrs == NULL) { | ||||||||
| ctx->done = true; | ||||||||
| ctx->out_of_space = true; | ||||||||
| return _Py_uop_sym_new_null(ctx); | ||||||||
| } | ||||||||
| } | ||||||||
| // Check if the slot already exists | ||||||||
| for (int i = 0; i < sym->descr.num_descrs; i++) { | ||||||||
| if (sym->descr.descrs[i].slot_index == slot_index) { | ||||||||
| sym->descr.descrs[i].symbol = (uint16_t)(PyJitRef_Unwrap(value) - allocation_base(ctx)); | ||||||||
| assert(!_Py_uop_sym_is_null(old_value)); | ||||||||
| return old_value; | ||||||||
| } | ||||||||
| } | ||||||||
| // Add new mapping if there's space | ||||||||
| if (sym->descr.num_descrs < MAX_SYMBOLIC_DESCR_SIZE) { | ||||||||
| int idx = sym->descr.num_descrs++; | ||||||||
| sym->descr.descrs[idx].slot_index = slot_index; | ||||||||
| sym->descr.descrs[idx].symbol = (uint16_t)(PyJitRef_Unwrap(value) - allocation_base(ctx)); | ||||||||
| } | ||||||||
| // No value there. Objects are initialized to NULL, so it's safe. | ||||||||
| return _Py_uop_sym_new_null(ctx); | ||||||||
| } | ||||||||
| default: | ||||||||
| return _Py_uop_sym_new_unknown(ctx); | ||||||||
| } | ||||||||
| } | ||||||||
| // 0 on success, -1 on error. | ||||||||
| @@ -1698,6 +1697,12 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored)) | ||||||||
| retrieved = _Py_uop_sym_get_attr(ctx, descr_obj, 0); | ||||||||
| TEST_PREDICATE(_Py_uop_sym_get_const(ctx, retrieved) == val_43, | ||||||||
| "descr getattr(0) changed unexpectedly"); | ||||||||
| // Test setattr with escape | ||||||||
| ctx->last_escape_index = INT_MAX; | ||||||||
| retrieved = _Py_uop_sym_set_attr(ctx, descr_obj, 1, slot_val3); | ||||||||
| TEST_PREDICATE(PyJitRef_Unwrap(retrieved)->tag == JIT_SYM_UNKNOWN_TAG, | ||||||||
| "descr setattr should be unknown after escaping"); | ||||||||
| ctx->last_escape_index = 0; | ||||||||
| // Test escape invalidation | ||||||||
| JitOptRef descr_obj3 = _Py_uop_sym_new_descr_object(ctx, 100); | ||||||||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.