Skip to content

gh-131798: JIT: Split CALL_TYPE_1 into several uops #132419

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

tomasr8
Copy link
Member

@tomasr8 tomasr8 commented Apr 11, 2025

This mostly works now, though the there are now two unused stackref variables in executor_cases.c.h (null and callable) and I'm not sure how to convince the cases generator to remove them. I tried:

  • using DEAD(x) in the guard uops - does not work because the stack variable also appears in the output of the uop. I also can't easily pop them off the stack since neither null or callable is TOS.
  • removing DEAD(x) from _CALL_TYPE_1: not possible, apparently this is needed before I can set res.

I'm out of ideas so if anyone knows how to fix it, I'd love to know :)

sym_set_null(null);
}

op(_GUARD_CALLABLE_TYPE_1, (callable, unused, unused2 -- callable, unused, unused2)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not entirely sure why I cannot do this here:

Suggested change
op(_GUARD_CALLABLE_TYPE_1, (callable, unused, unused2 -- callable, unused, unused2)) {
op(_GUARD_CALLABLE_TYPE_1, (callable, unused, unused -- callable, unused, unused)) {

I get SyntaxError: Duplicate name unused, though bytecodes.c allows it 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Weird. Maybe unused isn't a meaningful value here like it is in bytecodes.c (maybe @markshannon knows)?

Copy link
Member

Choose a reason for hiding this comment

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

We can leave it like this. I'll create an issue for Mark to update the cases generator and mention this line.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok!

Copy link
Member Author

Choose a reason for hiding this comment

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

Appears to be fixed now thanks to #132615, I updated the PR

sym_set_null(null);
}

op(_GUARD_CALLABLE_TYPE_1, (callable, unused, unused2 -- callable, unused, unused2)) {
Copy link
Member

Choose a reason for hiding this comment

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

Weird. Maybe unused isn't a meaningful value here like it is in bytecodes.c (maybe @markshannon knows)?

@bedevere-app
Copy link

bedevere-app bot commented Apr 11, 2025

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

tomasr8 and others added 2 commits April 12, 2025 22:54
Co-authored-by: Brandt Bucher <[email protected]>
Co-authored-by: Brandt Bucher <[email protected]>
Comment on lines +850 to +852
if (sym_has_type(arg)) {
res = sym_new_const(ctx, (PyObject *)sym_get_type(arg));
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Is there an easy way to test this part? i.e. that the res becomes const? AFAIK there are no other uops/guards that check for instances of type so we can't test it indirectly by checking for removed uops..

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, none check for instances of type specifically... mostly because we haven't separated these out or added optimizer cases for them yet! ;)

I think we could still use the fact that it's a const to our advantage, though. Haven't tried this, but you might be able to write a test that does t = type(foo); if t is not None: .... I'm pretty sure the JIT will remove the _GUARD_IS_NOT_NONE_POP instruction when the value is a known constant like this.

@tomasr8
Copy link
Member Author

tomasr8 commented Apr 14, 2025

Just to update the status:

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Apr 14, 2025

Thanks for making the requested changes!

@brandtbucher: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from brandtbucher April 14, 2025 08:44
Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

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

Up to you if you want to add the additional test. I'll leave this open for a bit longer just in case.

@tomasr8
Copy link
Member Author

tomasr8 commented Apr 14, 2025

I added the test you suggested since it was quite easy to do :)

Also, should we care about the compiler warnings I mentioned in the PR description? There are now two unused variable warnings:

In file included from Python/ceval.c:1121:
Python/executor_cases.c.h: In function_PyEval_EvalFrameDefault’:
Python/executor_cases.c.h:5142:25: warning: variablecallableset but not used [-Wunused-but-set-variable]
 5142 |             _PyStackRef callable;
      |                         ^~~~~~~~
Python/executor_cases.c.h:5141:25: warning: variablenullset but not used [-Wunused-but-set-variable]
 5141 |             _PyStackRef null;
      |                         ^~~~

@brandtbucher
Copy link
Member

Yeah, we should fix those. Can you rename them to unused, and remove the two DEAD calls, and add an INPUTS_DEAD() call at the very end, after the arg is closed?

@tomasr8
Copy link
Member Author

tomasr8 commented Apr 14, 2025

Yeah, we should fix those. Can you rename them to unused, and remove the two DEAD calls, and add an INPUTS_DEAD() call at the very end, after the arg is closed?

it's getting a bit late here so maybe I missed something, but I'm getting SyntaxError: Input 'null' is still live when output 'res' is defined. FTR, this is what I did:

diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 22bb4097611..129e606bde2 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -3969,15 +3969,14 @@ dummy_func(
             DEOPT_IF(callable_o != (PyObject *)&PyType_Type);
         }
 
-        op(_CALL_TYPE_1, (callable, null, arg -- res)) {
+        op(_CALL_TYPE_1, (unused, unused, arg -- res)) {
             PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
 
             assert(oparg == 1);
-            DEAD(null);
-            DEAD(callable);
             STAT_INC(CALL, hit);
             res = PyStackRef_FromPyObjectNew(Py_TYPE(arg_o));
             PyStackRef_CLOSE(arg);
+            INPUTS_DEAD();
         }
 
         macro(CALL_TYPE_1) =

@tomasr8
Copy link
Member Author

tomasr8 commented Apr 15, 2025

How about we add

(void)null;
(void)callable;

I've seen it used in some other instructions. Not sure whether it's the best fix but it does get rid of the warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants