-
-
Couldn't load subscription status.
- Fork 33.2k
gh-114058: Only allow immortal constants in tier 2 #115817
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 our terms of service and privacy 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?
Changes from all commits
05a604f
38ee21c
c75030d
3ff15c7
c447000
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,10 +164,6 @@ abstractcontext_fini(_Py_UOpsAbstractInterpContext *ctx) | |
| return; | ||
| } | ||
| ctx->curr_frame_depth = 0; | ||
| int tys = ctx->t_arena.ty_curr_number; | ||
| for (int i = 0; i < tys; i++) { | ||
| Py_CLEAR(ctx->t_arena.arena[i].const_val); | ||
| } | ||
| } | ||
|
|
||
| static int | ||
|
|
@@ -218,7 +214,8 @@ ctx_frame_pop( | |
| } | ||
|
|
||
|
|
||
| // Takes a borrowed reference to const_val, turns that into a strong reference. | ||
| // Only accepts immortal constants or borrowed constants that will be kept alive | ||
| // elsewhere. | ||
| static _Py_UOpsSymType* | ||
| sym_new(_Py_UOpsAbstractInterpContext *ctx, | ||
| PyObject *const_val) | ||
|
|
@@ -230,13 +227,9 @@ sym_new(_Py_UOpsAbstractInterpContext *ctx, | |
| return NULL; | ||
| } | ||
| ctx->t_arena.ty_curr_number++; | ||
| self->const_val = NULL; | ||
| self->typ = NULL; | ||
| self->flags = 0; | ||
|
|
||
| if (const_val != NULL) { | ||
| self->const_val = Py_NewRef(const_val); | ||
| } | ||
| self->const_val = const_val; | ||
|
|
||
| return self; | ||
| } | ||
|
|
@@ -331,7 +324,7 @@ sym_new_known_type(_Py_UOpsAbstractInterpContext *ctx, | |
| return res; | ||
| } | ||
|
|
||
| // Takes a borrowed reference to const_val. | ||
| // Decrefs const_val if it is not immortal and discards it. | ||
| static inline _Py_UOpsSymType* | ||
| sym_new_const(_Py_UOpsAbstractInterpContext *ctx, PyObject *const_val) | ||
| { | ||
|
|
@@ -344,9 +337,33 @@ sym_new_const(_Py_UOpsAbstractInterpContext *ctx, PyObject *const_val) | |
| return NULL; | ||
| } | ||
| sym_set_type(temp, Py_TYPE(const_val)); | ||
| sym_set_flag(temp, TRUE_CONST); | ||
| sym_set_flag(temp, KNOWN); | ||
| sym_set_flag(temp, NOT_NULL); | ||
| sym_set_flag(temp, KNOWN | NOT_NULL); | ||
| // If the constant is not immortal, discard it. | ||
| if (_Py_IsImmortal(const_val)) { | ||
| sym_set_flag(temp, TRUE_CONST); | ||
| } | ||
| else { | ||
| Py_DECREF(const_val); | ||
| temp->const_val = NULL; | ||
| } | ||
| return temp; | ||
| } | ||
|
|
||
| // Same as sym_new_const, but borrows const_val, assuming it will be kept alive. | ||
| // Only safe if we know const_val has a strong reference elsewhere. | ||
| static inline _Py_UOpsSymType* | ||
| sym_new_const_borrow(_Py_UOpsAbstractInterpContext *ctx, PyObject *const_val) | ||
|
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 you should scrap this, and leave it to the caller to handle lifetimes. |
||
| { | ||
| assert(const_val != NULL); | ||
| _Py_UOpsSymType *temp = sym_new( | ||
| ctx, | ||
| const_val | ||
| ); | ||
| if (temp == NULL) { | ||
| return NULL; | ||
| } | ||
| sym_set_type(temp, Py_TYPE(const_val)); | ||
| sym_set_flag(temp, KNOWN | NOT_NULL | TRUE_CONST); | ||
| return temp; | ||
| } | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
This seems like an interface that is hard to use. Let the caller worry about mortality.
This also contradicts the comment on
sym_newthat it is OK to pass in mortal objects as long as the caller retains a strong reference.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.
That way is more complex to handle error conditions.
E.g
For newly created objects, out of space means we should decref it, but the code isn't as clean as
but rather becomes
Then we need to repeat that on every call site.
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.
Either
tempis immortal, in which case the caller need do nothing, or it is mortal in which case it needs proper handling.Correctness is paramount here, as bugs are going to be very hard to reproduce. Reproducing bugs in the T1 specializer is hard enough. We need to extra careful here. A bit of verbosity is a small price to pay for being able to reason about the code.
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.
The proposed code here would totally invalidate
_BINARY_OP_ADD_FLOATand other float-producing uops (as well as int-producing uops if the value is not a cached short int -- which is a distinction easily overlooked when testing).