Skip to content
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

GH-115816: Make tier2 optimizer symbols testable, and add a few tests. #115953

Merged
merged 10 commits into from
Feb 27, 2024

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Feb 26, 2024

This PR:

  • Tries to distinguish between API and internal functions by moving the API functions to a header and prefixing them _Py_uop_
  • Tweaks the API a bit to make it testable
  • Adds a few very basic tests.

Quite a few tests of the new tests are commented out because they don't pass yet.

@AlexWaygood AlexWaygood changed the title GH-115816: Make tier2 optimizer symbols testable, and a few tests. GH-115816: Make tier2 optimizer symbols testable, and add a few tests. Feb 26, 2024
@markshannon markshannon force-pushed the make-symbols-testable branch from 80066b2 to 0a6fecb Compare February 26, 2024 14:04
@markshannon markshannon force-pushed the make-symbols-testable branch from 0a6fecb to 62c544e Compare February 26, 2024 14:16
@markshannon markshannon reopened this Feb 26, 2024
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

I realize that I'm arguing with a bunch of code you inherited from @Fidget-Spinner, but while we're moving it around we might as well improve the API.

I also wonder if I'm just looking at a draft PR and you've already figured out in your head what needs to change to make the tests pass, so maybe my review wasn't so useful. Sorry for that. I'm glad you're doing this!

@@ -33,7 +33,7 @@ dummy_func(void) {
op(_LOAD_FAST_CHECK, (-- value)) {
value = GETLOCAL(oparg);
// We guarantee this will error - just bail and don't optimize it.
if (sym_is_null(value)) {
if (_Py_uop_sym_is_null(value)) {
Copy link
Member

Choose a reason for hiding this comment

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

I find the longer, public names pretty awkward and ugly. I understand they need to be public, but maybe at the top of optimizer_analysis.c we could define shorter aliases with the shorter (unprefixed) names for local use (in optimizer_analysis.c itself and in optimizer_bytecodes.c)? Then the code generator doesn't need to be changed. It would also be simpler to review the important changes in this file.

@@ -355,18 +355,18 @@ dummy_func(void) {
// Can determine statically, so we interleave the new locals
// and make the current stack the new locals.
// This also sets up for true call inlining.
if (sym_is_known(self_or_null)) {
if (_Py_uop_sym_is_null(self_or_null) || _Py_uop_sym_is_not_null(self_or_null)) {
Copy link
Member

Choose a reason for hiding this comment

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

For example, this is one of the few non-trivial changes in this file.

Comment on lines +33 to +35
PyTypeObject *typ;
// constant propagated value (might be NULL)
PyObject *const_val;
Copy link
Member

Choose a reason for hiding this comment

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

I'd rename these to type and const. The comment is not particularly useful, but it feels important to clarify the ownership status (once we've figured it out).

Comment on lines +41 to +43
#define OVERALLOCATE_FACTOR 5

#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * OVERALLOCATE_FACTOR)
Copy link
Member

Choose a reason for hiding this comment

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

I'd just "inline" OVERALLOCATE_FACTOR, it's only used once (here).

Comment on lines +110 to +111
PyAPI_FUNC(PyObject *)
_Py_uop_symbols_test(PyObject *self, PyObject *ignored);
Copy link
Member

Choose a reason for hiding this comment

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

One line:

Suggested change
PyAPI_FUNC(PyObject *)
_Py_uop_symbols_test(PyObject *self, PyObject *ignored);
PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);

}

_Py_UOpsSymType *
_Py_uop_sym_new_notnull(_Py_UOpsAbstractInterpContext *ctx)
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice if we could agree on whether it's spelled "notnull" (here) or "not_null" (as in _Py_uop_sym_is_not_null).

}

bool
_Py_uop_sym_matches_type(_Py_UOpsSymType *sym, PyTypeObject *typ)
Copy link
Member

Choose a reason for hiding this comment

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

An alternative API could be to just get the type, so the caller can do the comparison.

Though I guess in the future we might entertain symbols (other than Bottom/Contradiction) that match multiple types? I'm not sure how an optimizer could make use of that though.

Comment on lines +265 to +267
_Py_uop_ctx_frame_pop(
_Py_UOpsAbstractInterpContext *ctx
)
Copy link
Member

Choose a reason for hiding this comment

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

Fold into one line.

@gvanrossum gvanrossum marked this pull request as draft February 26, 2024 22:05
@gvanrossum
Copy link
Member

(Marked it as draft because it obviously is. :-)

@markshannon
Copy link
Member Author

markshannon commented Feb 27, 2024

I realize that I'm arguing with a bunch of code you inherited from @Fidget-Spinner, but while we're moving it around we might as well improve the API.

I think improving the API in the same PR is a bad idea. It couples two unrelated changes which slows down development and makes it impossible to revert the changes separately.

@markshannon markshannon marked this pull request as ready for review February 27, 2024 09:53
@markshannon markshannon merged commit 10fbcd6 into python:main Feb 27, 2024
58 checks passed
@markshannon markshannon deleted the make-symbols-testable branch February 27, 2024 11:06
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
LukasWoodtli pushed a commit to LukasWoodtli/cpython that referenced this pull request Jan 22, 2025
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.

4 participants