Skip to content

gh-139393: fix _CALL_LEN JIT tests for tuples - #139394

Merged
picnixz merged 3 commits into
python:mainfrom
picnixz:fix/jit/small-code-points-139393
Sep 28, 2025
Merged

picnixz merged 3 commits into
python:mainfrom
picnixz:fix/jit/small-code-points-139393

Conversation

@picnixz

@picnixz picnixz commented Sep 28, 2025 •

Copy link
Copy Markdown
Member

This fixes a regression introduced in 7ce25ed when _PY_NSMALLPOSINTS was changed from 257 to 1025.

@ashm-dev ashm-dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Everything is ok, I tested the fixes on clang and gcc works without problems!)

Comment thread Modules/_testinternalcapi.c Outdated
Comment on lines +2584 to +2586
if (PyModule_AddIntMacro(module, _PY_NSMALLNEGINTS) < 0) {
return 1;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This isn't used anywhere, is it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Mmh, yes, this one isn't used anymore. I wondered whether I needed one but I don't need to. I'll amend this one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Side comment: this function should return -1 instead of 1 as it's the case for other Py_mod_exec functions (I got surprised by the "return 1"). It doesn't really matter per se, but I think we should generally document what kind of values we expect for Py_mod_* handlers and tp_* ones (it's not clear what tp_clear should return and when).

Currently, errors in Py_mod_exec functions are indicated by a non-zero return value, but it's not documented. I would advise that we document this.

Comment thread Lib/test/test_capi/test_opt.py Outdated
def testfunc(n):
class C:
t = tuple(range(300))
t = tuple(range(2048))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of using a hardcoded magic number, it would be nice if we used _PY_NSMALLPOSINTS * 2 or something like that to make sure this test always works, even if we increase _PY_NSMALLPOSINTS in the future.

@picnixz picnixz Sep 28, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am actually unsure whether we need hardcoding here actually because of the JIT. I'll check if changing it to a compile-time known value is necessary or not.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah that's what I feared. While the test still passes, the uops will be different. I don't remember when we have some inlined computations x * y that are then transformed in a single LOAD_CONST.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Also, I think we should make such change at other places as well. If you want to, let's open a separate issue.

@Fidget-Spinner Fidget-Spinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@picnixz
picnixz merged commit 3779f2b into python:main Sep 28, 2025
47 checks passed
@picnixz
picnixz deleted the fix/jit/small-code-points-139393 branch September 28, 2025 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants