Repository navigation
gh-139393: fix _CALL_LEN JIT tests for tuples
#139394
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
|
|
||
| _testinternalcapi = import_helper.import_module("_testinternalcapi") | ||
|
|
||
| from _testinternalcapi import TIER2_THRESHOLD | ||
| from _testinternalcapi import _PY_NSMALLPOSINTS, TIER2_THRESHOLD | ||
|
|
||
| #For test of issue 136154 | ||
| GLOBAL_136154 = 42 | ||
|
|
@@ -2093,6 +2093,10 @@ def testfunc(n): | |
| self.assertNotIn("_GUARD_TOS_INT", uops) | ||
|
|
||
| def test_call_len_known_length_small_int(self): | ||
| # Make sure that len(t) is optimized for a tuple of length 5. | ||
| # See https://github.com/python/cpython/issues/139393. | ||
| self.assertGreater(_PY_NSMALLPOSINTS, 5) | ||
|
|
||
| def testfunc(n): | ||
| x = 0 | ||
| for _ in range(n): | ||
|
|
@@ -2113,13 +2117,17 @@ def testfunc(n): | |
| self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops) | ||
|
|
||
| def test_call_len_known_length(self): | ||
| # Make sure that len(t) is optimized for a tuple of length 2048. | ||
| # See https://github.com/python/cpython/issues/139393. | ||
| self.assertLess(_PY_NSMALLPOSINTS, 2048) | ||
|
|
||
| def testfunc(n): | ||
| class C: | ||
| t = tuple(range(300)) | ||
| t = tuple(range(2048)) | ||
|
Member
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. Instead of using a hardcoded magic number, it would be nice if we used
Member
Author
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 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.
Member
Author
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. 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
Member
Author
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. Also, I think we should make such change at other places as well. If you want to, let's open a separate issue. |
||
|
|
||
| x = 0 | ||
| for _ in range(n): | ||
| if len(C.t) == 300: # comparison + guard removed | ||
| if len(C.t) == 2048: # comparison + guard removed | ||
| x += 1 | ||
| return x | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| #include "pycore_pyerrors.h" // _PyErr_ChainExceptions1() | ||
| #include "pycore_pylifecycle.h" // _PyInterpreterConfig_InitFromDict() | ||
| #include "pycore_pystate.h" // _PyThreadState_GET() | ||
| #include "pycore_runtime_structs.h" // _PY_NSMALLPOSINTS, _PY_NSMALLNEGINTS | ||
| #include "pycore_unicodeobject.h" // _PyUnicode_TransformDecimalAndSpaceToASCII() | ||
|
|
||
| #include "clinic/_testinternalcapi.c.h" | ||
|
|
@@ -2576,6 +2577,14 @@ module_exec(PyObject *module) | |
| return 1; | ||
| } | ||
|
|
||
| if (PyModule_AddIntMacro(module, _PY_NSMALLPOSINTS) < 0) { | ||
| return 1; | ||
| } | ||
|
|
||
| if (PyModule_AddIntMacro(module, _PY_NSMALLNEGINTS) < 0) { | ||
| return 1; | ||
| } | ||
|
Member
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. This isn't used anywhere, is it?
Member
Author
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. 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.
Member
Author
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. Side comment: this function should return -1 instead of 1 as it's the case for other Currently, errors in |
||
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.