summaryrefslogtreecommitdiff
path: root/Cython/Compiler/ParseTreeTransforms.py
Commit message (Collapse)AuthorAgeFilesLines
* Warn about useless directives that do not change the previous setting.Stefan Behnel2023-04-241-0/+3
| | | | Also, make sure that we correctly allow resetting directives, even if the new value is the same as the value from outside (since we might already have set it differently in the same directives block).
* Disallow @cfunc being applied to a @ufunc.Stefan Behnel2023-04-241-1/+6
| | | | Closes https://github.com/cython/cython/issues/5399
* Treat @ufunc directive like @cfunc/@ccall directives by excluding it from ↵Stefan Behnel2023-04-241-1/+1
| | | | the normal directives dict unless it's being used.
* Disallow @cfunc together with @ccall on the same function.Stefan Behnel2023-04-241-0/+2
|
* Improve error message for 'cimport cython.floating' (GH-5295)da-woods2023-03-271-1/+11
| | | | Tries to provide some helpful hints for https://github.com/cython/cython/issues/5288 where people may be trying to cimport directives/types as if they were a module.
* Allow InterpretCompilerDirectives.visit_AnnotationNode() to process nodes ↵Chia-Hsiang Cheng2023-03-261-1/+1
| | | | | that have no children (GH-5336) Closes https://github.com/cython/cython/issues/5235
* Fix some issues when optimising the builtin memoryview (GH-5271)da-woods2023-03-011-0/+1
| | | | | | | Error in capitalization. Closes https://github.com/cython/cython/issues/5270 Context managers were being optimized into a non-working state when involving a CloneNode. Closes https://github.com/cython/cython/issues/5268
* Support auto-generation of Numpy ufuncs (GH-4803)da-woods2023-02-251-0/+4
| | | | | Provides a decorator to automatically transform a cdef function into a Numpy ufunc (with the loop embedded in the function so hopefully pretty efficient). Closes https://github.com/cython/cython/issues/4758
* Remove "from x cimport class C" (#4904)da-woods2022-10-111-9/+5
| | | | | | | | | | | | | | | | | | | | | | | (and "struct S"/"union U") This appears to be an old Pyrex feature introduced in https://github.com/cython/cython/commit/9bac9c2e014ed63c2ac435e9b431fae124fba668 to provide a way of "forward cimporting" a class. I originally tried to make a test for it, but couldn't actually come up with a useful way of using it in the intended way, where the name would be unavailable initially but avaialble later. It looks to be completely untested, and responsible for some missing coverage in Nodes.py (https://github.com/cython/cython/issues/4163). The large section containing ``` if kind == 'struct' or kind == 'union': # 8479 ↛ 8480 ``` I propose to fix the missing coverage by killing off the feature. The only people I could find using this syntax were H5Py, who look to have removed their sole use of it 3 years ago https://github.com/h5py/h5py/commit/8d2498c7f5e3fec884ff56e9aca905c325d82484 Therefore it seems a good candidate to go in Cython 3
* PEP614 decorators (#4991)da-woods2022-10-011-1/+2
| | | Relaxes the grammar restrictions on decorators
* Allow empty args to dataclass and field directives (#4957)da-woods2022-09-241-1/+1
| | | Part of the bug fixes in https://github.com/cython/cython/issues/4956
* Fix memoryview iteration in generator expressions (GH-4968)da-woods2022-08-091-1/+3
| | | | | As a result of f946fe22fff32077dc58beeb64ec1ebc85d37632 And fix at least one pre-existing reference counting leak for memoryview references in things like `any(i > 0 for i in memview)`
* Generator expression and comprehension scope (#4254)da-woods2022-08-081-1/+141
| | | | | | | | Fixes #1159. This should be a simpler way of dealing with the long-standing generator and comprehension scoping issues. Unlike the previous PR it is fairly non-intrusive (i.e. doesn't wrap everything in `ResultRefNodes`) and therefore the changes should be more reasonable. Instead it: * Gives `IteratorNode` a scope (pointed at the outer scope rather than the scope of the generator/comprehension) * Tags each `ExprNode` inside the generator iterator sequence with a number, and uses those tags later to work out what needs to be converted to an argument for the generator. If an `ExprNode` is optimized out then that's fine - one of its children will have been tagged.
* Fix handling of annotations in functions in dataclasses (#4954)da-woods2022-08-081-2/+1
| | | | | | | | Fixes #4953. Before this change the annotations were being treated as "dataclass-related" annotations, and thus being made "public".
* Validate imported "cython.*" module names and reject unknown module names.Stefan Behnel2022-08-041-2/+42
| | | | Closes https://github.com/cython/cython/issues/4947
* Minor code simplification.Stefan Behnel2022-08-031-2/+1
|
* Merge branch '0.29.x'Stefan Behnel2022-07-201-16/+24
|\
| * Minor code cleanups after 3a373e2ccdddc79202d9ed13edc85d4b95616b26.Stefan Behnel2022-07-201-3/+5
| |
| * Make pickle checksum calculation succeed even if one of the hash algorithms ↵Stefan Behnel2022-07-201-18/+21
| | | | | | | | | | | | | | | | is blocked at runtime. Also, pass "usedforsecurity=False" in Py3.9+ to unblock MD5 also on some security constrained systems (FIPS). Closes https://github.com/cython/cython/issues/4909
| * Revert "Avoid acquiring the GIL at the end of nogil functions (GH-3556) ↵Stefan Behnel2022-05-171-0/+14
| | | | | | | | | | | | (GH-4749)" This reverts commit 74073417c4f7e616af0a139a55f790f1ec7fe728.
| * Avoid acquiring the GIL at the end of nogil functions (GH-3556) (GH-4749)Oleksandr Pavlyk2022-05-031-14/+0
| | | | | | | | | | | | | | | | | | | | | | | | Closes https://github.com/cython/cython/issues/4637 See See https://github.com/cython/cython/issues/3556 * Acquire the GIL in nogil functions only when strictly needed on function exit, e.g. for cleaning up temp variables from with-gil blocks or adding tracebacks. See https://github.com/cython/cython/issues/3554 * Make the GIL-avoidance in 7d99b0f0 actually work in nogil functions and not just nogil sections. See https://github.com/cython/cython/issues/3558
| * Revert "Avoid acquiring the GIL at the end of nogil functions (GH-3556) ↵scoder2022-04-161-0/+14
| | | | | | | | | | | | | | | | | | | | (GH-4703)" (GH-4742) PR 4703 was an incomplete backport of the changes needed for #3554 and generates incorrect C code. See https://github.com/cython/cython/issues/3554 Reverts https://github.com/cython/cython/pull/4703 This reverts commit d395a56f8e68ee563f866d0dec5a31a37f77df9e.
| * Avoid acquiring the GIL at the end of nogil functions (GH-3556) (GH-4703)Oleksandr Pavlyk2022-03-311-14/+0
| | | | | | | | | | | | Acquire the GIL in nogil functions only when strictly needed on function exit, e.g. for cleaning up temp variables from with-gil blocks or adding tracebacks. Closes GH-3554 Closes GH-4637
* | Avoid conflict between propery names and function variables (GH-4845)da-woods2022-07-161-0/+6
| | | | | | | | | | Fixes https://github.com/cython/cython/issues/4836 Bug introduced by https://github.com/cython/cython/commit/8c7b0f3fb745aa7bd0afedfbeb862eecc5fdff0c
* | Merge branch '0.29.x'Stefan Behnel2022-03-141-1/+1
|\ \ | |/
| * Make error message more readable by using hex integer values for all ↵Stefan Behnel2022-03-141-1/+1
| | | | | | | | presented checksums, not just the compile time ones.
| * For the auto-pickle checksum, allow SHA-1 and SHA-256 which are used by ↵Stefan Behnel2022-03-141-5/+21
| | | | | | | | | | | | Cython 3.x pickles now. Otherwise stick to MD5 since that was used before. Closes https://github.com/cython/cython/issues/4680
| * Small changes to get `--cython-compile-all` working again (GH-3650)da-woods2021-11-161-1/+1
| | | | | | | | Fixes https://github.com/cython/cython/issues/3647
| * Run ParallelRangeTransform also recursively on function arguments (GH-3608)da-woods2020-05-151-0/+1
| | | | | | | | Closes https://github.com/cython/cython/issues/3594
* | For the auto-pickle checksum, allow MD5 again since it was used by Cython ↵Stefan Behnel2022-03-141-5/+19
| | | | | | | | | | | | 0.x pickles. Otherwise switch to SHA-256 since that should be safe enough to stay available in Python's hashlib module for another while. Closes https://github.com/cython/cython/issues/4680
* | Stop cfunc/ccall/class applying to inner funcs/classes (GH-4575)da-woods2022-02-101-16/+49
| | | | | | | | | | | | | | Fixes https://github.com/cython/cython/issues/4092 Nested cdef classes are not tested because they don't officially work at this stage (see https://github.com/cython/cython/issues/4572). It should be tested if/when they're fully supported.
* | Implement cdef dataclasses (GH-3400)da-woods2022-01-291-4/+20
| | | | | | | | | | | | | | | | | | | | | | | | New decorator/function "@cython.dataclasses.dataclass" and "cython.dataclasses.field()" to mark dataclasses and their fields. Tries to match the interface provided by a regular dataclass as much as possible. This means taking the types from the dataclasses module if available (so they match exactly) or a fallback Python version that just implements the core parts (executed with "PyRun_String()" in the C source). Use of placeholders in generated "__init__" code means the code in the C file isn't hugely readable. Probably not a huge issue, but don't really see a way round that. As part of this I've also also implemented a Cython version of "typing.ClassVar". Although really designed for use with dataclasses it behaves sensibly when used in types in a normal cdef class. This is worth documenting more thoroughly. Closes https://github.com/cython/cython/issues/2903
* | Implement PEP 572: Named/Assignment Expressions (GH-3691)da-woods2022-01-271-2/+131
| | | | | | Closes https://github.com/cython/cython/issues/2636
* | Avoid unnecessary directives tracking in the WithTransform since it does not ↵Stefan Behnel2022-01-031-1/+3
| | | | | | | | need it.
* | Clean up individual child traversals in transforms using the new ↵Stefan Behnel2021-12-281-14/+13
| | | | | | | | visitchild() method.
* | Fix cython.pointer() type usage in class annotations (GH-4515)da-woods2021-12-231-0/+2
| | | | | | | | | | Annotations attached to namenodes weren't correctly processed with "InterpretCompilerDirectivesTransform" Closes https://github.com/cython/cython/issues/4514
* | Allow releasing the GIL in nogil functions (GH-4318)da-woods2021-12-181-2/+12
| | | | | | | | | | | | | | Also adds a check whether we have the GIL before doing so. This is important because Py_UNBLOCK_THREADS is documented as unsafe if we don't hold the GIL. Closes https://github.com/cython/cython/issues/4137
* | Handle function "outer_attrs" more consistently (GH-4375)da-woods2021-10-011-2/+0
| | | | | | | | | | | | A few children of function nodes need to be consistently evaluated outside the function scope. This PR attempts to do so and thus fixes https://github.com/cython/cython/issues/4367.
* | Restore error when using arbitrary decorators on cdef functions (GH-4323)da-woods2021-08-071-1/+9
| | | | | | | | | | These were lost when cdef properties (for extern types) were introduced. Closes #4322 (based on my interpretation of the problem as an error-reporting issue)
* | Fix compilation of "ParseTreeTransforms" in Py2. It previously tried to ↵Stefan Behnel2021-07-261-0/+2
| | | | | | | | compare the 'directivetype' to 'str', which misses Py2 str when compiling with language level 3.
* | Resolve some issues with "cpp_locals" (GH-4265)da-woods2021-07-191-1/+3
| | | | | | | | | | | | | | * Fix class attributes access where cpp_locals=False. * Add "no-cpp-locals" tag to mark a test as not suitable for running with "cpp_locals=True". * Add a list of "extra_directives" to runtests as additional test mode. Resolves some issues in https://github.com/cython/cython/issues/4266
* | Fix: overwrite target node after analysis.Stefan Behnel2021-07-131-2/+2
| |
* | Add directive "cpp_locals" to handle C++ variables using std::optional (GH-4225)da-woods2021-06-291-0/+24
| | | | | | | | | | This avoids the need for default constructors of stack allocated variables and temps by allowing late initialisation. Closes https://github.com/cython/cython/issues/4160
* | Set "is_cython_module" on annotations correctly (GH-4248)da-woods2021-06-281-0/+7
| | | | | | | | | | | | Fixes https://github.com/cython/cython/issues/4243 (and probably a bunch more annotation bugs) AnnotationNode doesn't have any child_attrs/subexprs because it mostly doesn't want to be analyzed (it's just transformed to an evaluable string). However this means that InterpretCompilerDirectives wasn't visiting its children to set is_cython_module and so the typing was failing. I've special-cased InterpretCompilerDirectives to visit AnnotationNode fully.
* | Simplify code and add a comment.Stefan Behnel2021-06-091-4/+3
| |
* | Fixed optimizations in defined cppclassda-woods2021-06-051-0/+7
| | | | | | | | The problem was they were being skipped with SkipDeclarations
* | Support cimports in pure Python code. (GH-4190)scoder2021-05-231-22/+61
| | | | | | | | | | Uses a special package prefix "cython.cimports", followed by the actual .pxd module/package names. Also allows "import cython.cimports.libc.math as libc_math" etc., rather than only "from ... import ...". All we need to guard against is that the import does not overwrite the name "cython".
* | Fix a crash when compiling a module without statements, only a single ↵Stefan Behnel2021-05-221-0/+7
| | | | | | | | declaration.
* | Execute AlignFunctionDefinitions before MarkClosureTransform. (GH-4127)Matus Valo2021-05-111-7/+35
| | | | | | | | This commit fixes a crash of Cython when generator expressions are used in cdef functions in pure python mode. Closes https://github.com/cython/cython/issues/3477
* | Modernise code: use set literals/comprehensions where possible, frozenset ↵Stefan Behnel2021-04-131-5/+7
| | | | | | | | where appropriate.