Commit Graph

245 Commits

Author SHA1 Message Date
Kay Hayen
ec8e28efef Optimization: Also decide writing traces for parameter variables faster 2025-11-26 11:19:43 +00:00
Kay Hayen
6dc316c189 Optimization: Much faster Python passes
* Escape and unknown traces now have their own
  number spaces. This allows to do some tests
  for a trace without using the actual object.

* Narrow the scope of variables to the outline scope
  that uses them, so that they don't need to be dealt
  with in merging later code where they don't ever
  change anymore and are not used at all.

* When checking for unused variables, do not ask the
  trace collection to filter its traces, instead work
  of the ones attached in the variable already. This
  avoids a lot of searching work. Also use a method
  to decide if a trace constitutes usage rather than
  a long elif chain.

* For "PASS 1" of "telethon.tl.types" which has been one
  of the known trouble makers with many classes and type
  annotations all changes combined improve the compilation
  time by 800%.
2025-11-26 11:19:43 +00:00
Kay Hayen
186dace03e AIX: Another instance of using "$" in identifiers fixed 2025-10-10 17:04:14 +02:00
Kay Hayen
7b6cdb1cb1 Fix, values passed into helper calls were not escaped properly
* Unlike normal function calls, these didn't annotate that
  their called function could change the values.
2025-04-28 11:04:39 +02:00
Kay Hayen
718ab60539 Bump copyright year 2025-04-28 11:04:36 +02:00
Kay Hayen
c4ccebf7df Python3.3: Make more 3.4 checks be Python3 checks
* Still more code that can be removed because the Python3.3 special cases no longer exist.
2024-12-18 11:10:21 +01:00
Kay Hayen
3e864e0eee Cleanup, change 3.4 checks to 3.0 checks as Python3.3 is no longer supported
* This cleans up version checks. We now treat >=3.4 either as >=3 or can just drop checks.
2024-12-18 11:08:31 +01:00
Kay Hayen
5f5062942b Optimization: Avoid changing code names for complex call helpers
* The numbering of function causes issues when code
  is used from cache, because then unused helpers
  never come to exist.

* This avoids a re-compilation for some modules the
  second time around a compilation happens and not
  all complex helpers are added at all.
2024-12-18 10:54:59 +01:00
Kay Hayen
7837563b67 Standalone: Added support for "tensorflow.function" JIT
* This adds support to preserve the source code of
  decorated functions and provide it at runtime to
  tensorflow so it can do its tracing.

* The code generation now has  a way of providing
  module level init codes.

* This mechanism should be possible to generalize
  to other JIT making modules as well.

* Without this, some codes using tensorflow.function
  could totally miss out on the specialization it does,
  that compilation with Nuitka does not currently
  replace.
2024-12-18 10:52:03 +01:00
Kay Hayen
695d23ca76 Quality: Updated to latest version of black
* Many improvements, esp. for the ternary expressions
  that are frequently used, they are now formatted
  much better.
2024-12-18 10:51:12 +01:00
Kay Hayen
f34f8d0c63 Bump copyright year
* Also split copyright notices between the top and bottom,
  such that readability of just opened files is not harmed
  by license text.
2024-12-18 10:48:16 +01:00
Kay Hayen
70ce1e0dd9 Optimization: Statically optimize "sys.exit" into exception raise
* That allows for solving our "setup" trick transparent for the new pylint.

* Should make a bunch of dead code obvious to Nuitka, it can now tell this aborts
  execution of a branch.
2024-12-18 10:46:08 +01:00
Kay Hayen
72a2c05a63 Quality: Updated requirements
* New black removes a few leading new lines in blocks, so many
  files changed in that way.

* The "pygments" has a vulnerability, but updating that and the
  restructured text checking stuff did not actually matter at
  all.

* Bumped needed version for development to 3.8, since black does
  not do 3.7 anymore, and it's old enough.
2024-01-22 21:40:07 +01:00
Kay Hayen
707ba87cfe Optimization: Refactor towards unification of statement and expression
* Make existing statement operations used that feature, so they are
  immediately closer to what expressions do.

* Remove checks for expression or statement, we won't use that
  anymore.
2023-07-23 19:10:35 +02:00
Kay Hayen
909d41f02d Bump copyright year 2023-06-02 15:07:22 +02:00
Kay Hayen
d9ada19072 Quality: Updated to latest PyLint
* The 3.11 with newer pip cannot build dependencies of older
  astroid due to some breaking of pip, so we are kind of pushed
  to update this.

* A few nice findings, but unfortunately arguments-differ no
  longer is usable.
2023-06-02 15:07:21 +02:00
Kay Hayen
78a6a21b1c Optimization: Add dict shape for Python2 class bodies
* We need this for optimization of dictionary "in" operation, such that
  the use in the Python2 reformulation of it does not cause problems, as
  Python3 classes do not have this (immediately).

* This also opens the door for more variations, e.g. where annotations
  are used inside the body or not.
2023-04-14 13:27:07 +02:00
Kay Hayen
ad5615b934 Minor cleanups 2023-04-14 13:27:07 +02:00
Kay Hayen
4968773f3d Optimization: Massive generated children mixin work.
* All expression nodes now use a dedicated generated children mixin
  class, aimed at optimal use.

* Some select expression nodes now use dedicated base classes with
  automatic computations done in there.

* When cloning nodes or getting visitable nodes, more more compact
  code is used that should perform better.

* Named chilren now have types, and "tuple" is handled explicitely
  without checking values for their type, so updates, iteration etc.
  is all directl.

* Remove useless checker for "kw_defaults" from function creation nodes,
  they are only ever "None" when the node is created. No need to check
  afterwards anymore.

* Only when a function node is created, is there a chance for "kw_defaults"
  to be empty dict, so use a factory function instead.

* With useless checkers removed, generated children mixins now do apply
  the checkers statically rather than checking on every update if there
  is one, and the checkers dictionary per expression can be dropped as
  result, making things perform much better for child replacement.

* Attach type shapes to methods specs for use in attribute node
  generation, such that the proper mixin class for the result
  type shape can be chosen automatically, but we do have some types,
  that depend on Python version looking at it, and won't be suitable yet.

* Factories for nodes are now detected automatically in node generation,
  making them easier to use.

* Added support for "importlib.metadata.entry_points" and its
  backport variant "importlib_metadata" too.

* Added operations for all "bytes" methods as well, such that the
  existing few ones are automatically generated as well.

* Added "auto_compute" for annotations of nodes that never change and do
  annotate and potentially raise an exception or not. This will allow to
  do stub method implementations, and rather have the base class contain
  this directly.

* The "iter" node for 2 arguments was not annotating its exception exit,
  which was discovered when looking for a boiler plate node to migrate
  to "auto_compute" which then of course resolves the bug.

* Make sure we pass tuple values when creating nodes that have children
  with that type. We created node lists only to always convert them to
  tuple value when the node is created. This is now avoided in many
  cases.

* Sequences had dead attribute "sequence_kind", removed that attribute.

* Made a new sequence mixin for reuse in "importlib.metadata.EntryPoints"
  values which are more or less a sequence derived class.

* Made dictionary mixin for reuse in "importlib.metadata.SelectableGroups"
  as these are more or less a dict derived class.

* Replaced "willRaiseException" with "willRaiseAnyException" which will be
  more accurate and faster, and matches what the result of the function
  is more closely anyway. We do not ask the other question at all yet.

* Remove useless raise checks in sequence making nodes, they were
  repeating the effort done in the base class for no good reason,
  potentially wasting a lot of time.

* Made meta data using test cover the new entry_points method without
  arguments at least.
2023-01-09 16:44:30 +01:00
Kay Hayen
66ef2a38c0 Python3.11: Need to addition qualname to code objects
* As a result, it needs to be known much sooner, therefore we delegate
  the responsibility to the provider object who has to make the
  difference anyway
2022-11-19 16:02:23 +01:00
Kay Hayen
758a82a450 Optimization: Added dedicated nodes for "pkg_resources.require" and "pkg_resources.get_distribution"
* These optimize into a new compile time constant, that is persisted,
  but not for module mode, where changes are expected.

* The "pkg-resources" attempted to do the similar thing with source code
  based matches, that are no longer necessary.
2022-06-17 12:07:08 +02:00
Kay Hayen
94baddf053 Fix, this was not handling functions with list star arguments correctly yet. 2022-06-17 12:07:08 +02:00
Kay Hayen
4cfdd9f9c0 Bump copyright year 2022-05-23 10:28:11 +02:00
Kay Hayen
9665934e5b Optimization: The complex call helpers could trigger unnecessary passes
* The pure functions were fully optimized immediately, but then also
  a second time potentially, and with loops that sometimes was not
  finished immediately.

* Also optimized how --verbose and progress bar interact, that was
  not fully correct before.
2022-02-02 18:20:45 +01:00
Kay Hayen
41bb8b7e50 Fix, optimization inside pure function bodies was not annotating tag properly 2021-12-20 12:55:29 +01:00
Kay Hayen
e2442d4ea2 Cleanup specs with pseudo star list arguments
* Some functions take a single positional argument, and that's optional,
  but no more, and there is no default value for those.

* This offers a saner method for implementing them before adding more of
  the same kind for dictionary method "update".
2021-12-07 09:39:59 +01:00
Kay Hayen
fb56a2efa6 Optimization: Faster processing of statement only nodes
* The expressions are already supposed to annotate their exception exits,
  expression only statements were duplicating those which can cause severe
  decrease in performance due to many more branches to merge in trace
  collection and memory churn due to them.

* All "computeExpressionDrop" usages return a changed or unchanged self,
  we do not need to compare.

* Added a mixin for nodes that statically say they have no side effects
  by themselves, and make this provide a non-checking
  "computeExpressionDrop" overload.

* Added missing exception raise annotations for where nodes replace
  themselves with exceptions, as these were previously hidden bugs.

* Also added static declaration of no raising exception for things without
  side effect, as that is considered.

* Remove annotations that just expressed the defaults for all expressions
  or were duplicated, e.g. because compile time constants base class has
  it already.

* Use staticmethod even more often, in some cases the overload is only
  there to add a comment with a TODO, but these calls should not be
  slower.

* Added TODOs for unclear cases where side effects and exception
  raising disagree.
2021-12-07 09:38:43 +01:00
Kay Hayen
44ad986fd8 Optimization: Solve TODO for locals dict copy node
* This has become visible through recent new optimization of locals.
2021-09-12 13:52:47 +02:00
Kay Hayen
a76e012e8d Optimization: Make sure to only optimize internal helpers once
* Also optimize them repeatedly, so they are immediately complete.
2021-02-24 19:56:39 +01:00
Kay Hayen
c0c4e30229 Optimization: Avoid global passes for module specific stuff
* The variable completeness of the module is now traced in the module locals
  scope and taken from there, allowing to use it sooner.

* The functions completeness is likewise traces in its local scope.

* Unused temporary variables and unnecessary closure variables are now
  removed more immediately

* Auto releases of parameter variables are introduced sooner

* This should make it use less iterations to optimize a module and
  ideally only one global pass for these optimizations.
2021-01-29 13:09:18 +01:00
Kay Hayen
9210979a07 Optimization: Make sure to use slots for all nodes
* In some cases, mixins were not specifying slots, causing it to not
  not being used.

* Now we enforce the present of slots in all node bases.

* Some minor refactorings, because now it's not possible anymore to have
  optional attributes.

* This should gain a bit more speed and save memory as well.
2021-01-29 13:09:18 +01:00
Kay Hayen
b900b03b7b Fix, container operations were not properly removing empty/non-empty assignment traces
* Also optimize "len" through variables as well, this was noted as not being
  optimized and therefore being corect where boolean tests were not.

* Plenty of cases where value escaping was added or refined, the "len"
  optimization found many of them.
2021-01-22 09:58:00 +01:00
Kay Hayen
e43b72e087 Bump copyright year to 2021. 2021-01-22 09:58:00 +01:00
Kay Hayen
97ffc2c607 Cleanup, stop using getters and setters entirely
* This has been done in some places only, now do it everywhere.

* This is supposed to make things cleaner and faster.

* Use class level attributes for cases where e.g. the step of a range
  is only present for some variants.

* Dedicated return node for case of returning in tried handler.
2021-01-10 13:12:06 +01:00
Kay Hayen
e93e24cd1d Optimization: Use "__slots__" for all node kinds
* The trick is that mixins need to specify that they do have empty slots, then
  the using classes need to list them.

* Our meta class does the hard work where possible.
2020-12-17 10:24:44 +01:00
Kay Hayen
dd5a9f2dd5 Cleanup, avoid decimal and string comparisons for version checks
* This is in preparation for 3.10 which will fail to work that work.

* Extended numeric values to be hexadecimal.

* Using tuples over strings in testing.
2020-12-17 09:06:53 +01:00
Kay Hayen
2639d88f3b Compatibility: Fix, the code object co_freevars works now
* This is needed for matplotlib3 at least.

* Avoid passing NULL instead of empty tuple for varnames and freevars,
  allowing to optimize some of these calls to compensate the extra code.
2020-11-22 11:53:30 +01:00
Kay Hayen
edc557bccc Python3.9: Added support for new error display of callables
* This also moves function attributes nodes to dedicated module.
2020-11-05 11:50:54 +01:00
Kay Hayen
b82dc34980 Optimization: Enhanced container creation and truth checks
* Container creation helper functions were solifified into one and are now used
  consistently, allowing more direct optimizations.

* Never creates empty tuple, lists, or set creations which ought to
  allow optimization to assume non-empty.

* More efficient handling of set literals.

* Checking for compile time constant should be faster now.
2020-11-05 11:50:53 +01:00
Kay Hayen
7a5ce93302 Optimization: Even more constants refinements
* Take advantage of checking for None or empty
  dict or tuple nodes directly, as these have a
  dedicated node type, much faster.

* Do away with special API "getConstant" and use
  the general "getCompileTimeConstant" one.

* Generalized "extractSideEffects" to all compile time
  constants, for better optimization of unused stuff.

* Cleaned up mapping specific functions, moving to
  the constant node type they apply to instead of
  asserting their correct usage.

* Faster iteration length results, removed special
  checks for string and unicode constants, can be
  done with node type checks.
2020-11-05 11:50:53 +01:00
Kay Hayen
0a2795182a Optimization: Even more uses of staticmethod 2020-11-05 11:50:53 +01:00
Kay Hayen
54e165ddf0 Optimization: Use shared C code for all forms of constant return
* So far this only worked for empty functions, i.e. those
  that only "return None", but there are plenty of
  others that fit the bill, by making it an attribute
  of the function object.

* This doesn't yet do mutable constants, but we can
  add that later.
2020-11-05 11:50:52 +01:00
Kay Hayen
9360323962 Optimization: Annotate that "staticmethod" and "classmethod" cannot raise
* This avoids useless exception checking in generated code which we did
  so far.

* For classes with many such methods this reduces code generated
  by a lot.
2020-11-05 11:50:52 +01:00
Kay Hayen
8dd8ed93c6 Quality: Updated to latest versions of black and isort 2020-11-02 18:43:05 +01:00
Kay Hayen
9521d9a93f Fix, locals scope needs to be attached to usage and loop optimization
could hang

* The locals could refer to the wrong scope if it is not attached at
  creation time, which it now is.

* To get to the optimization, variable references for builtin names
  have the scope attached just in case they later use it, this has
  a dedicated node to save the attribute for the general case.

* Also for Optimization, prepare inlining of helper function bodies,
  with local scopes, this should now be easy to accomplish later.

* For loops, we were not considering the initial trace state reliably,
  esp. not if it was an uninit trace, which has been fixed.

* Compare traces instead of type shapes to decide if we stablized in
  a loop analysis, that is more telling and faster to do.

* More correct annotation of trace escaping, doing away with loop usage
  and potential usage.

* Make sure construct the type shapes with alternatives in place, so
  we don't have do unmerge them later in code that uses the set of
  shapes for a trace or variable.
2020-11-02 18:41:53 +01:00
Kay Hayen
aff78d7e53 Minor cleanup
* Added documentation instead of comment, that is also more correct
2020-08-22 20:02:43 +02:00
Kay Hayen
0532f82a85 Minor cleanups 2020-06-06 10:44:15 +02:00
Kay Hayen
9ab7390f07 Fix, functions with star dict could crashed when optimizing to direct call 2020-06-04 13:35:58 +02:00
Kay Hayen
128e93f935 Quality: Upgraded to newer black.
* Unpacking to single arguments is something we use, this makes it more
  clear with braces.

* Unpack to multiple arguments is now displayed much cleaner.

* Multiline imports are used more often at least.
2020-05-01 11:33:24 +02:00
Kay Hayen
4ac0f5d55f Optimization: Prepare enhanced optimization for "del" statements
* This will need releases to also have their own traces to be done
  reliably.

* This reduces generated C code in some cases, as no extra assignment
  needs to be done anymore.
2020-05-01 11:33:18 +02:00