summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_code.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-135437: Account For Duplicate Names in _PyCode_SetUnboundVarCounts() ↵Eric Snow2025-06-131-0/+5
| | | | (gh-135438)
* gh-132775: Expand the Capability of Interpreter.call() (gh-133484)Eric Snow2025-05-301-2/+46
| | | It now supports most callables, full args, and return values.
* gh-132775: Add _PyCode_GetScriptXIData() (gh-133480)Eric Snow2025-05-081-0/+27
| | | | | | | This converts functions, code, str, bytes, bytearray, and memoryview objects to PyCodeObject, and ensure that the object looks like a script. That means no args, no return, and no closure. _PyCode_GetPureScriptXIData() takes it a step further and ensures there are no globals. We also add _PyObject_SupportedAsScript() to the internal C-API.
* gh-132775: Unrevert "Add _PyCode_VerifyStateless()" (gh-133528)Eric Snow2025-05-081-20/+34
| | | | | | | | This reverts commit 3c73cf5 (gh-133497), which itself reverted the original commit d270bb5 (gh-133221). We reverted the original change due to failing android tests. The checks in _PyCode_CheckNoInternalState() were too strict, so we've relaxed them.
* gh-132775: Revert "gh-132775: Add _PyCode_VerifyStateless() (gh-133221)" ↵Petr Viktorin2025-05-061-34/+20
| | | | (#133497)
* gh-132775: Add _PyCode_GetXIData() (gh-133475)Eric Snow2025-05-051-0/+26
|
* gh-132775: Add _PyCode_VerifyStateless() (gh-133221)Eric Snow2025-05-051-20/+75
| | | | | | | | "Stateless" code is a function or code object which does not rely on external state or internal state. It may rely on arguments and builtins, but not globals or a closure. I've left a comment in pycore_code.h that provides more detail. We also add _PyFunction_VerifyStateless(). The new functions will be used in several later changes that facilitate "sharing" functions and code objects between interpreters.
* gh-132775: Unrevert "Add _PyCode_GetVarCounts()" (gh-133265)Eric Snow2025-05-051-0/+230
| | | | | | This reverts commit 811edcf (gh-133232), which itself reverted the original commit 811edcf (gh-133128). We reverted the original change due to failing s390 builds (a big-endian architecture). It ended up that I had not accommodated op caches.
* Revert "gh-132775: Add _PyCode_GetVarCounts() (gh-133128)" (gh-133232)Eric Snow2025-05-011-230/+0
| | | | | The change broke the s390 builds, so I'm reverting it while I investigate. This reverts commit 94b4fcd806e7b692955173d309ea3b70a193ad96.
* gh-132775: Add _PyCode_GetVarCounts() (gh-133128)Eric Snow2025-04-301-0/+230
| | | | | | | This helper is useful in a variety of ways, including in demonstrating how the different counts relate to one another. It will be used in a later change to help identify if a function is "stateless", meaning it doesn't have any free vars or globals. Note that a majority of this change is tests.
* gh-87859: Track Code Object Local Kinds For Arguments (gh-132980)Eric Snow2025-04-291-0/+123
| | | | | Doing this was always the intention. I was finally motivated to find the time to do it. See #87859 (comment).
* gh-132775: Add _PyCode_ReturnsOnlyNone() (gh-132981)Eric Snow2025-04-291-0/+59
| | | | | The function indicates whether or not the function has a return statement. This is used by a later change related treating some functions like scripts.
* GH-128534: Fix behavior of branch monitoring for `async for` (GH-130847)Mark Shannon2025-03-071-0/+9
| | | * Both branches in a pair now have a common source and are included in co_branches
* gh-130574: renumber RESUME opcode from 149 to 128 (GH-130685)Tomasz Pytel2025-03-061-5/+5
|
* gh-130851: Don't crash when deduping unusual code constants (#130853)Sam Gross2025-03-051-0/+17
| | | | | | | | | | The bytecode compiler only generates a few different types of constants, like str, int, tuple, slices, etc. Users can construct code objects with various unusual constants, including ones that are not hashable or not even constant. The free threaded build previously crashed with a fatal error when confronted with these constants. Instead, treat distinct objects of otherwise unhandled types as not equal for the purposes of deduplication.
* gh-100239: specialize long tail of binary operations (#128722)Irit Katriel2025-01-161-5/+5
|
* GH-128375: Better instrument for `FOR_ITER` (GH-128445)Mark Shannon2025-01-061-0/+40
|
* gh-126072: Set docstring attribute for module and class (#126231)Xuanteng Huang2024-11-081-0/+41
|
* gh-126072: do not add `None` to `co_consts` if there is no docstring (GH-126101)Xuanteng Huang2024-10-301-2/+57
|
* GH-125837: Split `LOAD_CONST` into three. (GH-125972)Mark Shannon2024-10-291-2/+3
| | | | | | | | * Add LOAD_CONST_IMMORTAL opcode * Add LOAD_SMALL_INT opcode * Remove RETURN_CONST opcode
* gh-125900: Clean-up logic around immortalization in free-threading (#125901)Sam Gross2024-10-241-7/+1
| | | | | | | | | * Remove `@suppress_immortalization` decorator * Make suppression flag per-thread instead of per-interpreter * Suppress immortalization in `eval()` to avoid refleaks in three tests (test_datetime.test_roundtrip, test_logging.test_config8_ok, and test_random.test_after_fork). * frozenset() is constant, but not a singleton. When run multiple times, the test could fail due to constant interning.
* gh-119180: Add LOAD_COMMON_CONSTANT opcode (#119321)Jelle Zijlstra2024-05-221-1/+1
| | | | | | | | | | The PEP 649 implementation will require a way to load NotImplementedError from the bytecode. @markshannon suggested implementing this by converting LOAD_ASSERTION_ERROR into a more general mechanism for loading constants. This PR adds this new opcode. I will work on the rest of the implementation of the PEP separately. Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
* gh-118527: Intern code consts in free-threaded build (#118667)Sam Gross2024-05-071-1/+22
| | | | | | We already intern and immortalize most string constants. In the free-threaded build, other constants can be a source of reference count contention because they are shared by all threads running the same code objects.
* gh-117783: Immortalize objects that use deferred reference counting (#118112)Sam Gross2024-04-291-1/+5
| | | | | | | | | Deferred reference counting is not fully implemented yet. As a temporary measure, we immortalize objects that would use deferred reference counting to avoid multi-threaded scaling bottlenecks. This is only performed in the free-threaded build once the first non-main thread is started. Additionally, some tests, including refleak tests, suppress this behavior.
* gh-117683: Fix test_free_different_thread failures with GIL disabled (#117685)Sam Gross2024-04-161-2/+6
|
* gh-117376: Partial implementation of deferred reference counting (#117696)Sam Gross2024-04-121-0/+2
| | | | | This marks objects as using deferred refrence counting using the `ob_gc_bits` field in the free-threaded build and collects those objects during GC.
* gh-116303: Skip test module dependent tests if test modules are unavailable ↵Erlend E. Aasland2024-04-031-4/+3
| | | | (#117341)
* gh-110481: Implement inter-thread queue for biased reference counting (#114824)Sam Gross2024-02-091-0/+1
| | | | | | | | | Biased reference counting maintains two refcount fields in each object: `ob_ref_local` and `ob_ref_shared`. The true refcount is the sum of these two fields. In some cases, when refcounting operations are split across threads, the ob_ref_shared field can be negative (although the total refcount must be at least zero). In this case, the thread that decremented the refcount requests that the owning thread give up ownership and merge the refcount fields.
* gh-112962: in dis module, put cache information in the Instruction instead ↵Irit Katriel2023-12-131-4/+4
| | | | of creating fake Instructions to represent it (#113016)
* gh-109052: Use the base opcode when comparing code objects (gh-109107)Tian Gao2023-09-091-0/+19
|
* gh-108751: Add copy.replace() function (GH-108752)Serhiy Storchaka2023-09-061-0/+7
| | | | | | | | | It creates a modified copy of an object by calling the object's __replace__() method. It is a generalization of dataclasses.replace(), named tuple's _replace() method and replace() methods in various classes, and supports all these stdlib classes.
* gh-106581: Project through calls (#108067)Guido van Rossum2023-08-171-1/+1
| | | | This finishes the work begun in gh-107760. When, while projecting a superblock, we encounter a call to a short, simple function, the superblock will now enter the function using `_PUSH_FRAME`, continue through it, and leave it using `_POP_FRAME`, and then continue through the original code. Multiple frame pushes and pops are even possible. It is also possible to stop appending to the superblock in the middle of a called function, when running out of space or encountering an unsupported bytecode.
* GH-103805: Lib test f541 linting issue fix (#103812)Rodolfo M. Pereira2023-04-241-1/+1
| | | | | | | | | | | | | | | | This PR makes some minor linting adjustments to the Lib/test module caught by [ruff](https://github.com/charliermarsh/ruff). The adjustments are all related to the `F541 f-string without any placeholders` issue. Issue: https://github.com/python/cpython/issues/103805 <!-- gh-issue-number: gh-103805 --> * Issue: gh-103805 <!-- /gh-issue-number --> --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* GH-103082: Implementation of PEP 669: Low Impact Monitoring for CPython ↵Mark Shannon2023-04-121-5/+5
| | | | | | | | | | (GH-103083) * The majority of the monitoring code is in instrumentation.c * The new instrumentation bytecodes are in bytecodes.c * legacy_tracing.c adapts the new API to the old sys.setrace and sys.setprofile APIs
* gh-101865: Deprecate `co_lnotab` from code objects as per PEP 626 (#101866)Nikita Sobolev2023-04-031-0/+7
| | | Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
* gh-101101: Unstable C API tier (PEP 689) (GH-101102)Petr Viktorin2023-02-281-3/+3
|
* gh-101632: Add the new RETURN_CONST opcode (#101633)penguin_wwy2023-02-071-0/+1
|
* GH-100117: Make `co_lines` more efficient (GH-100447)Brandt Bucher2023-01-101-1/+2
|
* gh-94155: Reduce hash collisions for code objects (#100183)Dennis Sweeney2022-12-231-0/+26
| | | | | | | * Uses a better hashing algorithm to get better dispersion and remove commutativity. * Incorporates `co_firstlineno`, `Py_SIZE(co)`, and bytecode instructions. * This is now the entire set of criteria used in `code_richcompare`, except for `_PyCode_ConstantKey` (which would incorporate the types of `co_consts` rather than just their values).
* gh-100077: make test_code.test_invalid_bytecode more robust and maintainable ↵Irit Katriel2022-12-071-8/+12
| | | | (#100078)
* GH-97779: Ensure that *all* frame objects are backed by "complete" frames ↵Brandt Bucher2022-10-051-0/+33
| | | | (GH-97845)
* gh-96711: Enhance SystemError message upon Invalid opcode (#96712)serge-sans-paille2022-09-201-0/+11
| | | | | | Raise verbose SystemError instead of printing debug information upon Invalid opcode. Fix #96711
* GH-95150: Use position and exception tables for code hashing and equality ↵Brandt Bucher2022-08-011-0/+21
| | | | (GH-95509)
* Revert "gh-94816: Improve coverage of decode_linetable (GH-94853)" (GH-94982)Michael Droettboom2022-07-181-23/+0
| | | This reverts commit 20b9d2a658059c8c1624400f60bb6ba19a31ee9b.
* gh-94816: Improve coverage of decode_linetable (GH-94853)Michael Droettboom2022-07-141-0/+23
| | | | | | | This makes calls to co_lnotab to exercise this code, as well as generating synthetically large code to exercise the corner cases where line numbers need multiple bytes. Automerge-Triggered-By: GH:brandtbucher
* gh-94485: Set line number of module's RESUME instruction to 0, as specified ↵Irit Katriel2022-07-051-1/+0
| | | | | by PEP 626 (GH-94552) Co-authored-by: Mark Shannon <mark@hotpy.org>
* gh-84461: Fix ctypes and test_ctypes on Emscripten (#94142)Christian Heimes2022-06-241-0/+2
| | | | | - c_longlong and c_longdouble need experimental WASM bigint. - Skip tests that need threading - Define ``CTYPES_MAX_ARGCOUNT`` for Emscripten. libffi-emscripten 2022-06-23 supports up to 1000 args.
* GH-93662: Make sure that column offsets are correct in multi-line method ↵Mark Shannon2022-06-141-1/+30
| | | | calls. (GH-93673)
* GH-88116: Document that PyCodeNew is dangerous, and make PyCode_NewEmpty ↵Mark Shannon2022-04-211-0/+3
| | | | less dangerous. (GH-91790)
* GH-88116: Use a compact format to represent end line and column offsets. ↵Mark Shannon2022-04-211-39/+130
| | | | | | | | | | | | (GH-91666) * Stores all location info in linetable to conform to PEP 626. * Remove column table from code objects. * Remove end-line table from code objects. * Document new location table format