summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
Commit message (Collapse)AuthorAgeFilesLines
...
* bpo-44337: Improve LOAD_ATTR specialization (GH-26759)Mark Shannon2021-06-211-0/+2
| | | | | | | | * Specialize obj.__class__ with LOAD_ATTR_SLOT * Specialize instance attribute lookup with attribute on class, provided attribute on class is not an overriding descriptor. * Add stat for how many times the unquickened instruction has executed.
* bpo-44032: Move pointer to code object from frame-object to frame specials ↵Mark Shannon2021-06-181-11/+12
| | | | array. (GH-26771)
* bpo-43693: Eliminate unused "fast locals". (gh-26587)Eric Snow2021-06-151-20/+4
| | | | | Currently, if an arg value escapes (into the closure for an inner function) we end up allocating two indices in the fast locals even though only one gets used. Additionally, using the lower index would be better in some cases, such as with no-arg `super()`. To address this, we update the compiler to fix the offsets so each variable only gets one "fast local". As a consequence, now some cell offsets are interspersed with the locals (only when an arg escapes to an inner function). https://bugs.python.org/issue43693
* Remove accidentally duplicated STAT_INC (GH-26718)Mark Shannon2021-06-141-1/+0
|
* bpo-44338: Port LOAD_GLOBAL to PEP 659 adaptive interpreter (GH-26638)Mark Shannon2021-06-141-231/+83
| | | | | | | | | | * Add specializations of LOAD_GLOBAL. * Add more stats. * Remove old opcache; it is no longer used. * Add NEWS
* bpo-44348: Move trace-info to thread-state (GH-26623)Mark Shannon2021-06-101-83/+63
| | | | | * Move trace-info to thread state. * Correct output for pdb when turning on tracing in middle of line
* bpo-44337: Port LOAD_ATTR to PEP 659 adaptive interpreter (GH-26595)Mark Shannon2021-06-101-184/+164
| | | | | | | | | | | | | | * Specialize LOAD_ATTR with LOAD_ATTR_SLOT and LOAD_ATTR_SPLIT_KEYS * Move dict-common.h to internal/pycore_dict.h * Add LOAD_ATTR_WITH_HINT specialized opcode. * Quicken in function if loopy * Specialize LOAD_ATTR for module attributes. * Add specialization stats
* bpo-43693: Un-revert commit f3fa63e. (#26609)Eric Snow2021-06-081-21/+28
| | | | | | | | | This was reverted in GH-26596 (commit 6d518bb) due to some bad memory accesses. * Add the MAKE_CELL opcode. (gh-26396) The memory accesses have been fixed. https://bugs.python.org/issue43693
* Revert "bpo-43693: Add the MAKE_CELL opcode and interleave fast locals ↵Pablo Galindo2021-06-081-28/+21
| | | | | offsets. (gh-26396)" (GH-26597) This reverts commit 631f9938b1604d4f893417ec339b9e0fa9196fb1.
* bpo-43693: Add the MAKE_CELL opcode and interleave fast locals offsets. ↵Eric Snow2021-06-071-21/+28
| | | | | | | (gh-26396) This moves logic out of the frame initialization code and into the compiler and eval loop. Doing so simplifies the runtime code and allows us to optimize it better. https://bugs.python.org/issue43693
* bpo-43693: Un-revert commits 2c1e258 and b2bf2bc. (gh-26577)Eric Snow2021-06-071-46/+32
| | | | | | | | | | These were reverted in gh-26530 (commit 17c4edc) due to refleaks. * 2c1e258 - Compute deref offsets in compiler (gh-25152) * b2bf2bc - Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388) This change fixes the refleaks. https://bugs.python.org/issue43693
* bpo-44187: Quickening infrastructure (GH-26264)Mark Shannon2021-06-071-6/+22
| | | | | | | | | | | | | | * Add co_firstinstr field to code object. * Implement barebones quickening. * Use non-quickened bytecode when tracing. * Add NEWS item * Add new file to Windows build. * Don't specialize instructions with EXTENDED_ARG.
* bpo-43693: Revert commits 2c1e2583fdc4db6b43d163239ea42b0e8394171f and ↵Pablo Galindo2021-06-041-32/+46
| | | | | | | | | | | | | b2bf2bc1ece673d387341e06c8d3c2bc6e259747 (GH-26530) * Revert "bpo-43693: Compute deref offsets in compiler (gh-25152)" This reverts commit b2bf2bc1ece673d387341e06c8d3c2bc6e259747. * Revert "bpo-43693: Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388)" This reverts commit 2c1e2583fdc4db6b43d163239ea42b0e8394171f. These two commits are breaking the refleak buildbots.
* bpo-43693: Compute deref offsets in compiler (gh-25152)Mark Shannon2021-06-041-25/+13
| | | | | | Merges locals and cells into a single array. Saves a pointer in the interpreter and means that we don't need the LOAD_CLOSURE opcode any more https://bugs.python.org/issue43693
* bpo-43693: Add new internal code objects fields: co_fastlocalnames and ↵Eric Snow2021-06-031-27/+25
| | | | | | | | | | | | | | | | | co_fastlocalkinds. (gh-26388) A number of places in the code base (notably ceval.c and frameobject.c) rely on mapping variable names to indices in the frame "locals plus" array (AKA fast locals), and thus opargs. Currently the compiler indirectly encodes that information on the code object as the tuples co_varnames, co_cellvars, and co_freevars. At runtime the dependent code must calculate the proper mapping from those, which isn't ideal and impacts performance-sensitive sections. This is something we can easily address in the compiler instead. This change addresses the situation by replacing internal use of co_varnames, etc. with a single combined tuple of names in locals-plus order, along with a minimal array mapping each to its kind (local vs. cell vs. free). These two new PyCodeObject fields, co_fastlocalnames and co_fastllocalkinds, are not exposed to Python code for now, but co_varnames, etc. are still available with the same values as before (though computed lazily). Aside from the (mild) performance impact, there are a number of other benefits: * there's now a clear, direct relationship between locals-plus and variables * code that relies on the locals-plus-to-name mapping is simpler * marshaled code objects are smaller and serialize/de-serialize faster Also note that we can take this approach further by expanding the possible values in co_fastlocalkinds to include specific argument types (e.g. positional-only, kwargs). Doing so would allow further speed-ups in _PyEval_MakeFrameVector(), which is where args get unpacked into the locals-plus array. It would also allow us to shrink marshaled code objects even further. https://bugs.python.org/issue43693
* bpo-17792: more accurate error message for unbound variable access ↵Irit Katriel2021-06-021-3/+3
| | | | exceptions (GH-24976)
* bpo-43693: Clean up the PyCodeObject fields. (GH-26364)Eric Snow2021-05-261-9/+8
| | | | | | | | | | * Move up the comment about fields using in hashing/comparision. * Group the fields more clearly. * Add co_ncellvars and co_nfreevars. * Raise ValueError if nlocals != len(varnames), rather than aborting.
* bpo-44032: Move data stack to thread from FrameObject. (GH-26076)Mark Shannon2021-05-211-81/+114
| | | | | | | | | | | | | | | | * Remove 'zombie' frames. We won't need them once we are allocating fixed-size frames. * Add co_nlocalplus field to code object to avoid recomputing size of locals + frees + cells. * Move locals, cells and freevars out of frame object into separate memory buffer. * Use per-threadstate allocated memory chunks for local variables. * Move globals and builtins from frame object to per-thread stack. * Move (slow) locals frame object to per-thread stack. * Move internal frame functions to internal header.
* Remove unused function in ceval.c (GH-26246)Pablo Galindo2021-05-191-9/+0
|
* bpo-26110: Add ``CALL_METHOD_KW`` opcode to speedup method calls with ↵Ken Jin2021-05-151-26/+42
| | | | | | | | | keywords (GH-26014) * Add CALL_METHOD_KW * Make CALL_METHOD branchless too since it shares the same code * Place parentheses in STACK_SHRINK
* Remove PyTryblock struct (GH-26059)Mark Shannon2021-05-121-26/+17
|
* Prevent access outside buffer (GH-26012)Dennis Sweeney2021-05-101-3/+5
|
* bpo-40222: "Zero cost" exception handling (GH-25729)Mark Shannon2021-05-071-140/+231
| | | | | | | | "Zero cost" exception handling. * Uses a lookup table to determine how to handle exceptions. * Removes SETUP_FINALLY and POP_TOP block instructions, eliminating (most of) the runtime overhead of try statements. * Reduces the size of the frame object by about 60%.
* bpo-43754: Eliminate bindings for partial pattern matches (GH-25229)Brandt Bucher2021-05-021-0/+8
|
* bpo-43977: Use tp_flags for collection matching (GH-25723)Mark Shannon2021-04-301-64/+8
| | | | | | | | | | | | | * Add Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING, add to all relevant standard builtin classes. * Set relevant flags on collections.abc.Sequence and Mapping. * Use flags in MATCH_SEQUENCE and MATCH_MAPPING opcodes. * Inherit Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING. * Add NEWS * Remove interpreter-state map_abc and seq_abc fields.
* bpo-38530: Offer suggestions on NameError (GH-25397)Pablo Galindo2021-04-141-0/+14
| | | | | | | | | | | When printing NameError raised by the interpreter, PyErr_Display will offer suggestions of simmilar variable names in the function that the exception was raised from: >>> schwarzschild_black_hole = None >>> schwarschild_black_hole Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'schwarschild_black_hole' is not defined. Did you mean: schwarzschild_black_hole?
* bpo-43760: Speed up check for tracing in interpreter dispatch (#25276)Mark Shannon2021-04-131-23/+32
| | | | | | | | | * Remove redundant tracing_possible field from interpreter state. * Move 'use_tracing' from tstate onto C stack, for fastest possible checking in dispatch logic. * Add comments stressing the importance stack discipline when dealing with CFrames. * Add NEWS
* bpo-43753: Add Py_Is() and Py_IsNone() functions (GH-25227)Victor Stinner2021-04-101-17/+16
| | | | | | | Add the Py_Is(x, y) function to test if the 'x' object is the 'y' object, the same as "x is y" in Python. Add also the Py_IsNone(), Py_IsTrue(), Py_IsFalse() functions to test if an object is, respectively, the None singleton, the True singleton or the False singleton.
* bpo-43760: Streamline dispatch sequence for machines without computed gotos. ↵Mark Shannon2021-04-081-61/+52
| | | | | | | | (GH-25244) * Do fetch and decode at end of opcode then jump directly to switch. Should allow compilers that don't support computed-gotos, specifically MSVC, to generate better code.
* bpo-43683: Handle generator entry in bytecode (GH-25138)Mark Shannon2021-04-061-0/+24
| | | | | | * Handle check for sending None to starting generator and coroutine into bytecode. * Document new bytecode and make it fail gracefully if mis-compiled.
* bpo-42128: __match_args__ can't be a list anymore (GH-25203)Brandt Bucher2021-04-061-8/+1
|
* bpo-27129: Use instruction offsets, not byte offsets, in bytecode and ↵Mark Shannon2021-04-011-17/+12
| | | | | | | internally. (GH-25069) * Use instruction offset, rather than bytecode offset. Streamlines interpreter dispatch a bit, and removes most EXTENDED_ARGs for jumps. * Change some uses of PyCode_Addr2Line to PyFrame_GetLineNumber
* Move big block of macros out of function to improve readability. (GH-25020)Mark Shannon2021-03-251-38/+40
|
* Only check evalbreaker after calls and on backwards egdes. Makes sure that ↵Mark Shannon2021-03-241-46/+37
| | | | __exit__ or __aexit__ is called in with statments in case of interrupt. (GH-18334)
* bpo-43541: Fix PyEval_EvalCodeEx() regression (GH-24918)Victor Stinner2021-03-181-4/+2
| | | | | | | | | | | * Remove an assertion which required CO_NEWLOCALS and CO_OPTIMIZED code flags. It is ok to call this function on a code with these flags set. * Fix reference counting on builtins: remove Py_DECREF(). Fix regression introduced in the commit 46496f9d12582bf11f4911ad0f23315d6f277907. Add also a comment to document that _PyEval_BuiltinsFromGlobals() returns a borrowed reference.
* Make tracing info (bounds, and previous instruction offset) a bit more ↵Mark Shannon2021-03-051-52/+72
| | | | robust. (GH-24726)
* bpo-43271: Re-enable ceval.c optimizations for Windows debug builds (GH-24739)db3l2021-03-041-0/+1
| | | | | | Partially reverts commit b74396c3167cc780f01309148db02709bc37b432 The optimizations are necessary to prevent the interpreter from crashing in a number of tests involving recursion.
* bpo-37146: Deactivate opcode cache only when using huntrleaks in the test ↵Pablo Galindo2021-02-281-10/+12
| | | | suite (GH-24643)
* bpo-42128: Structural Pattern Matching (PEP 634) (GH-22917)Brandt Bucher2021-02-261-0/+382
| | | | | Co-authored-by: Guido van Rossum <guido@python.org> Co-authored-by: Talin <viridia@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* bpo-42093: Cleanup _PyDict_GetItemHint() (GH-24582)Victor Stinner2021-02-211-5/+16
| | | | | | * No longer save/restore the current exception. It is no longer used with an exception raised. * No longer clear the current exception on error: it's now up to the caller.
* bpo-42990: Functions inherit current builtins (GH-24564)Victor Stinner2021-02-201-12/+16
| | | | | | | | | | | | | | | | | | | | The types.FunctionType constructor now inherits the current builtins if the globals dictionary has no "__builtins__" key, rather than using {"None": None} as builtins: same behavior as eval() and exec() functions. Defining a function with "def function(...): ..." in Python is not affected, globals cannot be overriden with this syntax: it also inherits the current builtins. PyFrame_New(), PyEval_EvalCode(), PyEval_EvalCodeEx(), PyFunction_New() and PyFunction_NewWithQualName() now inherits the current builtins namespace if the globals dictionary has no "__builtins__" key. * Add _PyEval_GetBuiltins() function. * _PyEval_BuiltinsFromGlobals() now uses _PyEval_GetBuiltins() if builtins cannot be found in globals. * Add tstate parameter to _PyEval_BuiltinsFromGlobals().
* bpo-43268: Pass interp rather than tstate to internal functions (GH-24580)Victor Stinner2021-02-191-16/+15
| | | | | | | | | | | | | | | Pass the current interpreter (interp) rather than the current Python thread state (tstate) to internal functions which only use the interpreter. Modified functions: * _PyXXX_Fini() and _PyXXX_ClearFreeList() functions * _PyEval_SignalAsyncExc(), make_pending_calls() * _PySys_GetObject(), sys_set_object(), sys_set_object_id(), sys_set_object_str() * should_audit(), set_flags_from_config(), make_flags() * _PyAtExit_Call() * init_stdio_encoding() * etc.
* bpo-43270: Remove private _PyErr_OCCURRED() macro (GH-24579)Victor Stinner2021-02-191-1/+1
| | | | | | | | Remove the private _PyErr_OCCURRED() macro: use the public PyErr_Occurred() function instead. CPython internals must use the internal _PyErr_Occurred(tstate) function instead: it is the most efficient way to check if an exception was raised.
* bpo-43268: _Py_IsMainInterpreter() now expects interp (GH-24577)Victor Stinner2021-02-191-2/+2
| | | | The _Py_IsMainInterpreter() function now expects interp rather than tstate.
* bpo-42990: Refactor _PyFrame_New_NoTrack() (GH-24566)Victor Stinner2021-02-181-3/+3
| | | | | | | | | | | | * Refactor _PyFrame_New_NoTrack() and PyFunction_NewWithQualName() code. * PyFrame_New() checks for _PyEval_BuiltinsFromGlobals() failure. * Fix a ref leak in _PyEval_BuiltinsFromGlobals() error path. * Complete PyFunction_GetModule() documentation: it returns a borrowed reference and it can return NULL. * Move _PyEval_BuiltinsFromGlobals() definition to the internal C API. * PyFunction_NewWithQualName() uses _Py_IDENTIFIER() API for the "__name__" string to make it compatible with subinterpreters.
* bpo-43152: Update assert statement to remove unused warning (GH-24473)Dong-hee Na2021-02-141-2/+1
|
* bpo-42990: Further refactoring of PyEval_ functions. (GH-24368)Mark Shannon2021-02-011-123/+200
| | | | | | | | | | * Further refactoring of PyEval_EvalCode and friends. Break into make-frame, and eval-frame parts. * Simplify function vector call using new _PyEval_Vector. * Remove unused internal functions: _PyEval_EvalCodeWithName and _PyEval_EvalCode. * Don't use legacy function PyEval_EvalCodeEx.
* bpo-42927: Inline cache for attributes defined with '__slots__' (#24216)Guido van Rossum2021-01-301-64/+116
|
* bpo-42990: Introduce 'frame constructor' struct to simplify API for ↵Mark Shannon2021-01-291-62/+68
| | | | | | | PyEval_CodeEval and friends (GH-24298) * Introduce 'frame constructor' to simplify API for frame creation * Embed struct using a macro to conform to PEP 7
* Update frame.f_lineno before any call to the (C) tracing function. (GH-24150)Mark Shannon2021-01-071-33/+54
| | | * Minimizes breakage of C extensions and ensures PyFrame_GetLineNumber is efficient.