Skip to content

Conversation

@Fidget-Spinner
Copy link
Member

@Fidget-SpinnerFidget-Spinner commented Feb 19, 2024

Copy link
Member

@markshannonmarkshannon left a comment

Choose a reason for hiding this comment

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

All the res = sym_new_... assignments need to wrapped in OUT_OF_SPACE_IF_NULL

@bedevere-app
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

And if you don't make the requested changes, you will be poked with soft cushions!

@gvanrossum
Copy link
Member

Hey @Fidget-Spinner did you make the requested changes? You need to do the dance to make Bedevere happy. :-)

@Fidget-Spinner
Copy link
MemberAuthor

I have made the requested changes; please review again.

@gvanrossum
Copy link
Member

Odd. That test is still failing?!

Copy link
Member

@markshannonmarkshannon left a comment

Choose a reason for hiding this comment

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

Looks good in general.

There are a few optimizations that have been missed, and beware the side effects of C API calls.

Comment on lines 84 to 86
assert(PyLong_CheckExact(get_const(right)));
PyObject*temp=_PyLong_Add((PyLongObject*)get_const(left),
(PyLongObject*)get_const(right));
Copy link
Member

Choose a reason for hiding this comment

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

Maybe there should be s get_long_const() helper which returns (PyLongObject *)get_const(x) and also includes the assert(PyLong_CheckExact()) call, to make code like this more compact. (Same for float.)

Copy link
Member

@gvanrossumgvanrossum left a comment

Choose a reason for hiding this comment

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

One more thing.

Comment on lines 4075 to 4079
pureop (_POP_TOP_LOAD_CONST_INLINE_BORROW, (ptr/4, pop--value)){
TIER_TWO_ONLY;
DECREF_INPUTS();
value=ptr;
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe there could be an even more specialized opcode that doesn't DECREF its input? That would be handy for the case where you introduced this -- the input is known to be None, so we don't really need to bother with the DECREF of the immortal value.

Copy link
Member

Choose a reason for hiding this comment

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

The expectation is that the _POP_TOP part will be removed in a later pass.
LOAD_CONST ; _POP_TOP_LOAD_CONST_INLINE_BORROW -> _LOAD_CONST_INLINE_BORROW

Copy link
Member

@markshannonmarkshannon left a comment

Choose a reason for hiding this comment

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

Two suggestions

Copy link
Member

@gvanrossumgvanrossum left a comment

Choose a reason for hiding this comment

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

LGTM, let's see if @markshannon agrees.

{
sym_set_type(sym, Py_TYPE(const_val));
sym_set_flag(sym, TRUE_CONST | KNOWN | NOT_NULL);
Py_XSETREF(sym->const_val, Py_NewRef(const_val));
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This is temporary, just ignore this for now. I will remove it in #115817.


op(_TO_BOOL_NONE, (value--res)){
if (sym_get_const(value) ==Py_None){
if (sym_is_const(value) && (sym_get_const(value) ==Py_None)){
Copy link
Member

Choose a reason for hiding this comment

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

Why is this necessary? Shouldn't sym_get_const return NULL for anything that isn't a constant?
It does seem rather verbose to have to prefix every sys_get_const with a sys_is_const.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

In the code:

staticinlinePyObject*sym_get_const(_Py_UOpsSymType*sym){assert(sym_is_const(sym)); assert(sym->const_val); returnsym->const_val}

So we assume there is always something there when there's sym_get_const. I think I can just change the contract to return NULL on non constants though.

Copy link
Member

Choose a reason for hiding this comment

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

The new sym_get_const() indeed returns NULL in this case.

@gvanrossum
Copy link
Member

@Fidget-Spinner: It looks like this PR is totally out of date. It adds a new ERROR_IF() macro that should probably be done in a separate cleanup pass. I can do that next (once gh-116062 is merged).

The key part of this PR is to add optimizer specializations for _TO_BOOL etc., but it may be simpler to extract those manually and put them in a fresh PR? Or you could do a massive rebase. :-) But I'd still like the ERROR_IF() cleanup to be separated out.

Copy link
Member

@gvanrossumgvanrossum left a comment

Choose a reason for hiding this comment

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

LGTM, with one nit (to make merging of my PR simpler).

Copy link
Member

@gvanrossumgvanrossum left a comment

Choose a reason for hiding this comment

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

Excellent!

@gvanrossum
Copy link
Member

Since you've addressed Mark's question I don't see a reason to wait for his explicit approval.

@Fidget-SpinnerFidget-Spinner merged commit d01886c into python:mainFeb 29, 2024
@Fidget-SpinnerFidget-Spinner deleted the to_bool_tier2 branch February 29, 2024 22:13
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull request Mar 4, 2024
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@Fidget-Spinner@gvanrossum@markshannon@Eclips4