summaryrefslogtreecommitdiffstats
path: root/Python/importlib.h
Commit message (Collapse)AuthorAgeFilesLines
* Revert "bpo-43693: Add the MAKE_CELL opcode and interleave fast locals ↵Pablo Galindo2021-06-081-1470/+1470
| | | | | 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-1470/+1470
| | | | | | | (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-1635/+1597
| | | | | | | | | | 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-43693: Revert commits 2c1e2583fdc4db6b43d163239ea42b0e8394171f and ↵Pablo Galindo2021-06-041-1597/+1635
| | | | | | | | | | | | | 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-4/+4
| | | | | | 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-1635/+1597
| | | | | | | | | | | | | | | | | 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-44298: Fix line numbers for early exits in with statements. (GH-26513)Mark Shannon2021-06-031-1770/+1770
|
* bpo-43693: Add _PyCode_New(). (gh-26375)Eric Snow2021-05-271-1483/+1461
| | | | | This is an internal-only API that helps us manage the many values used to create a code object. https://bugs.python.org/issue43693
* bpo-26110: Add ``CALL_METHOD_KW`` opcode to speedup method calls with ↵Ken Jin2021-05-151-5/+5
| | | | | | | | | keywords (GH-26014) * Add CALL_METHOD_KW * Make CALL_METHOD branchless too since it shares the same code * Place parentheses in STACK_SHRINK
* bpo-43933: Force RETURN_VALUE bytecodes to have line numbers (GH-26054)Mark Shannon2021-05-121-1730/+1731
|
* bpo-40222: "Zero cost" exception handling (GH-25729)Mark Shannon2021-05-071-1709/+1798
| | | | | | | | "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-43933: Set frame.f_lineno during call to __exit__ (GH-25719)Mark Shannon2021-04-301-1300/+1301
| | | * Set line number of __exit__ call in a with statement to be that of the with keyword.
* bpo-42739: Don't use sentinels to mark end of line table. (GH-25657)Mark Shannon2021-04-291-1606/+1597
| | | | | * Add length parameter to PyLineTable_InitAddressRange and doen't use sentinel values at end of table. Makes the line number table more robust. * Update PyCodeAddressRange to match PEP 626.
* bpo-41323: compiler: Reuse tuple in constant tuple folding (GH-25419)Inada Naoki2021-04-161-663/+663
|
* bpo-42135: Deprecate implementations of find_module() and find_loader() ↵Brett Cannon2021-04-061-732/+750
| | | | (GH-25169)
* bpo-27129: Use instruction offsets, not byte offsets, in bytecode and ↵Mark Shannon2021-04-011-1089/+1084
| | | | | | | 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
* bpo-42134: Raise ImportWarning when calling find_module() in the import ↵Brett Cannon2021-03-301-441/+448
| | | | system (GH-25044)
* bpo-42136: Deprecate module_repr() as found in importlib (GH-25022)Brett Cannon2021-03-261-772/+786
|
* bpo-42137: have ModuleType.__repr__ prefer __spec__ over module_repr() ↵Brett Cannon2021-03-241-123/+124
| | | | | (GH-24953) This is to work towards the removal of the use of module_repr() in Python 3.12 (documented as deprecated since 3.4).
* bpo-39316: Make sure that attribute accesses and stores, including method ↵Mark Shannon2021-03-141-3/+3
| | | | calls, conform to PEP 626. (GH-24859)
* bpo-42217: compiler: merge same co_code and co_linetable objects (GH-23056)Inada Naoki2021-02-101-1576/+1568
|
* bpo-42908: Mark cleanup code at end of try-except and with artificial (#24202)Mark Shannon2021-01-131-1576/+1577
| | | | | | | | | * Mark bytecodes at end of try-except as artificial. * Make sure that the CFG is consistent throughout optimiization. * Extend line-number propagation logic so that implicit returns after 'try-except' or 'with' have the correct line numbers. * Update importlib
* bpo-42810: Mark jumps at end of if and try statements as artificial. (GH-24091)Mark Shannon2021-01-041-801/+801
| | | | | | | * Mark jumps at end of if and try statements as artificial. * Update importlib * Add comment explaining the purpose of ADDOP_JUMP_NOLINE.
* bpo-42246: Don't eliminate jumps to jumps, if it will break PEP 626. (GH-23896)Mark Shannon2020-12-231-765/+766
|
* bpo-42634: Mark reraise after except blocks as artificial. (GH-23877)Mark Shannon2020-12-211-1726/+1729
| | | | | | | * Mark reraise after except blocks as artificial. * Update importlib * Update dis test.
* bpo-42246: Make sure that `f_lasti`, and thus `f_lineno`, is set correctly ↵Mark Shannon2020-12-171-43/+43
| | | | | | | | | after raising or reraising an exception (GH-23803) * Ensure that f_lasti is set correctly after an exception is raised to conform to PEP 626. * Update importlib * Add NEWS.
* bpo-42645: Make sure that return/break/continue are only traced once when ↵Mark Shannon2020-12-161-1660/+1660
| | | | | | | | | exiting via a finally block. (GH-23780) * Make sure that return/break/continue are only traced once when exiting via a finally block. * Add test for return in try-finally. * Update importlib
* bpo-42615: Delete redundant jump instructions that only bypass empty blocks ↵Om G2020-12-161-101/+101
| | | | | | | | | | | | | | | | | | | | | | | (GH-23733) * Delete jump instructions that bypass empty blocks * Add news entry * Explicitly check for unconditional jump opcodes Using the is_jump function results in the inclusion of instructions like returns for which this optimization is not really valid. So, instead explicitly check that the instruction is an unconditional jump. * Handle conditional jumps, delete jumps gracefully * Ensure b_nofallthrough and b_reachable are valid * Add test for redundant jumps * Regenerate importlib.h and edit Misc/ACKS * Fix bad whitespace
* bpo-42246: Remove DO_NOT_EMIT_BYTECODE macros, so that while loops and if ↵Mark Shannon2020-12-151-1704/+1705
| | | | statements conform to PEP 626. (GH-23743)
* bpo-42635: Mark JUMP_ABSOLUTE at end of 'for' loop as artificial to avoid ↵Mark Shannon2020-12-141-1756/+1756
| | | | spurious line events. (GH-23761)
* Don't generate spurious line number in try-except-finally. (#23760)Mark Shannon2020-12-141-1489/+1489
|
* bpo-26131: Deprecate usage of load_module() (GH-23469)Brett Cannon2020-12-041-1779/+1811
| | | Raise an ImportWarning when the import system falls back on load_module(). As for implementations of load_module(), raise a DeprecationWarning.
* bpo-42246: Don't forget the entry block when ensuring that all exits have a ↵Mark Shannon2020-12-041-1/+1
| | | | | line number (GH-23636) Don't forget the entry block when ensuring that all exits have a line number.
* bpo-42246: Make sure that line number is correct after a return, as required ↵Mark Shannon2020-12-021-1439/+1436
| | | | | by PEP 626 (GH-23495) Make sure that line number is correct after a return, as defined by PEP 626.
* bpo-42403: Use @staticmethod in importlib (GH-23395)Victor Stinner2020-11-201-709/+708
| | | | | | | | | | | | | Use @staticmethod on methods using @classmethod but don't use their cls parameter on the following classes: * BuiltinImporter * FrozenImporter * WindowsRegistryFinder * PathFinder Leave methods using @_requires_builtin or @_requires_frozen unchanged, since this decorator requires the wrapped method to have an extra parameter (cls or self).
* bpo-42403: Simplify importlib external bootstrap (GH-23397)Victor Stinner2020-11-191-1806/+1808
| | | | | | | Simplify the importlib external bootstrap code: importlib._bootstrap_external now uses regular imports to import builtin modules. When it is imported, the builtin __import__() function is already fully working and so can be used to import builtin modules like sys.
* bpo-42349: Compiler clean up. More yak-shaving for PEP 626. (GH-23267)Mark Shannon2020-11-171-1412/+1413
| | | Make sure that CFG from compiler front-end is correct. Be a bit more aggressive in the compiler back-end.
* bpo-42246: Eliminate jumps to exit blocks by copying those blocks. (#23251)Mark Shannon2020-11-121-1410/+1410
| | | * Compiler: eliminate jumps to short exit blocks by copying.
* bpo-42246: Partial implementation of PEP 626. (GH-23113)Mark Shannon2020-11-121-1518/+1533
| | | * Implement new line number table format, as defined in PEP 626.
* bpo-41323: Perform 'peephole' optimizations directly on the CFG. (GH-21517)Mark Shannon2020-07-301-1102/+1098
| | | * Move 'peephole' optimizations into compile.c and perform them directly on the CFG.
* bpo-41076: Pre-feed the parser with the f-string expression location (GH-21054)Lysandros Nikolaou2020-06-271-214/+214
| | | This commit changes the parsing of f-string expressions with the new parser. The parser gets pre-fed with the location of the expression itself (not the f-string, which was what we were doing before). This allows us to completely skip the shifting of the AST nodes after the parsing is completed.
* bpo-40334: PEP 617 implementation: New PEG parser for CPython (GH-19503)Pablo Galindo2020-04-221-44/+45
| | | | Co-authored-by: Guido van Rossum <guido@python.org> Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
* bpo-39987: Simplify setting lineno in the compiler. (GH-19037)Serhiy Storchaka2020-03-171-1621/+1620
|
* bpo-38091: Import deadlock detection causes deadlock (GH-17518)Armin Rigo2020-03-031-1667/+1670
| | | Automerge-Triggered-By: @brettcannon
* bpo-39320: Handle unpacking of **values in compiler (GH-18141)Mark Shannon2020-01-271-1421/+1421
| | | | | | | | | | | | | * Add DICT_UPDATE and DICT_MERGE bytecodes. Use them for ** unpacking. * Remove BUILD_MAP_UNPACK and BUILD_MAP_UNPACK_WITH_CALL, as they are now unused. * Update magic number for ** unpacking opcodes. * Update dis.rst to incorporate new bytecodes. * Add blurb entry.
* bpo-39336: Allow packages to not let their child modules be set on them (#18006)Dino Viehland2020-01-231-337/+346
| | | | | * bpo-39336: Allow setattr to fail on modules which aren't assignable When attaching a child module to a package if the object in sys.modules raises an AttributeError (e.g. because it is immutable) it causes the whole import to fail. This now allows immutable packages to exist and an ImportWarning is reported and the AttributeError exception is ignored.
* bpo-39156: Break up COMPARE_OP into four logically distinct opcodes. (GH-17754)Mark Shannon2020-01-141-1463/+1459
| | | | | | | | Break up COMPARE_OP into four logically distinct opcodes: * COMPARE_OP for rich comparisons * IS_OP for 'is' and 'is not' tests * CONTAINS_OP for 'in' and 'is not' tests * JUMP_IF_NOT_EXC_MATCH for checking exceptions in 'try-except' statements.
* Fix handling of line numbers around finally-blocks. (#17737)Mark Shannon2019-12-301-1622/+1622
|
* Produce cleaner bytecode for 'with' and 'async with' by generating separate ↵Mark Shannon2019-11-211-1076/+1089
| | | | | | code for normal and exceptional paths. (#6641) Remove BEGIN_FINALLY, END_FINALLY, CALL_FINALLY and POP_FINALLY bytecodes. Implement finally blocks by code duplication. Reimplement frame.lineno setter using line numbers rather than bytecode offsets.
* bpo-35923: Update the BuiltinImporter to use loader._ORIGIN instead of a ↵Dong-hee Na2019-09-111-754/+755
| | | | | | hard-coded value (GH-15651)