summary refs log tree commit diff stats
path: root/compiler/closureiters.nim
Commit message (Collapse)AuthorAgeFilesLines
* Optimize closure iterator locals (#23787)Yuriy Glukhov2024-07-031-63/+120
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This pr redefines the relation between lambda lifting and closureiter transformation. Key takeaways: - Lambdalifting now has less distinction between closureiters and regular closures. Namely instead of lifting _all_ closureiter variables, it lifts only those variables it would also lift for simple closure, i.e. those not owned by the closure. - It is now closureiter transformation's responsibility to lift all the locals that need lifting and are not lifted by lambdalifting. So now we lift only those locals that appear in more than one state. The rest remains on stack, yay! - Closureiter transformation always relies on the closure env param created by lambdalifting. Special care taken to make lambdalifting create it even in cases when it's "too early" to lift. - Environments created by lambdalifting will contain `:state` only for closureiters, whereas previously any closure env contained it. IMO this is a more reasonable approach as it simplifies not only lambdalifting, but transf too (e.g. freshVarsForClosureIters is now gone for good). I tried to organize the changes logically by commits, so it might be easier to review this on per commit basis. Some ugliness: - Adding lifting to closureiters transformation I had to repeat this matching of `return result = value` node. I tried to understand why it is needed, but that was just another rabbit hole, so I left it for another time. @Araq your input is welcome. - In the last commit I've reused currently undocumented `liftLocals` pragma for symbols so that closureiter transformation will forcefully lift those even if they don't require lifting otherwise. This is needed for [yasync](https://github.com/yglukhov/yasync) or else it will be very sad. Overall I'm quite happy with the results, I'm seeing some noticeable code size reductions in my projects. Heavy closureiter/async users, please give it a go.
* fixes #4695; closure iterators support for JS backend (#23493)ringabout2024-04-181-43/+45
| | | | | | | | | | | | | | | | | | | | | | | fixes #4695 ref https://github.com/nim-lang/Nim/pull/15818 Since `nkState` is only for the main loop state labels and `nkGotoState` is used only for dispatching the `:state` (since https://github.com/nim-lang/Nim/pull/7770), it's feasible to rewrite the loop body into a single case-based dispatcher, which enables support for JS, VM backend. `nkState` Node is replaced by a label and Node pair and `nkGotoState` is only used for intermediary processing. Backends only need to implement `nkBreakState` and `closureIterSetupExc` to support closure iterators. pending https://github.com/nim-lang/Nim/pull/23484 <del> I also observed some performance boost for C backend in the release mode (not in the danger mode though, I suppose the old implementation is optimized into computed goto in the danger mode) </del> allPathsAsgnResult???
* fixes yet another strictdefs bug (#23069)ringabout2023-12-151-5/+2
|
* Types: Refactorings; step 1 (#23055)Andreas Rumpf2023-12-121-3/+3
|
* IC: progress and refactorings (#22961)Andreas Rumpf2023-11-201-2/+2
|
* prepare for the enforcement of `std` prefix (#22873)ringabout2023-10-291-1/+3
| | | follow up https://github.com/nim-lang/Nim/pull/22851
* use strictdefs for compiler (#22365)ringabout2023-08-061-4/+9
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* fixes #22297; return in the finally in the closure iterators (#22300)ringabout2023-07-221-1/+3
| | | ref #22297; return in the finally in the closure iterators
* minor code improvement (#22293)Andreas Rumpf2023-07-191-6/+7
|
* refactoring in preparation for better, simpler name mangling that wor… ↵Andreas Rumpf2023-04-241-4/+4
| | | | | | | | | | | (#21667) * refactoring in preparation for better, simpler name mangling that works with IC flawlessly * use new disamb field * see if this makes tests green * make tests green again
* fix closure iter state table init type [backport] (#20717)Jacek Sieka2022-10-311-1/+1
| | | | | | | fix closure iter state table init type It is a well-known fact that using closed intervals for ranges is logically, objectively and eternally wrong, as evidenced by this off-by-one.
* Fix double defer with break in closureiterators [backport] (#20630)Tanguy2022-10-241-0/+2
| | | | | | | Fix double defer with break in closureiterators Signed-off-by: Tanguy <tanguy@status.im> Signed-off-by: Tanguy <tanguy@status.im>
* fixes #20572 (#20585)Andreas Rumpf2022-10-171-2/+2
| | | | | * fixes #20572 * added a test case
* Fixed compilation of void closureiters with try stmt (#20138) [backport]Yuriy Glukhov2022-08-031-4/+7
|
* Fix nested finally handling in closureiters [backport] (#19933)Tanguy2022-07-111-6/+25
| | | | | | | | | | | | | | | * Fix nested finally handling in closureiters * Fix CI * review comment * third time the charm * Update compiler/closureiters.nim Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com> Co-authored-by: Dominik Picheta <dominikpicheta@googlemail.com>
* move assertions out of system (#19599)flywind2022-03-231-0/+3
|
* fixes #19575 (#19596) [backport]Andreas Rumpf2022-03-091-2/+4
| | | | | * fixes #19575 * better bugfix
* real bugfix for #17170 (#18171)Andreas Rumpf2021-06-041-4/+6
| | | | | * real bugfix for #17170 * better fix
* Fixes #17849 (#18055) [backport:1.2]Yuriy Glukhov2021-05-301-0/+6
| | | | | | * Fixes #17849 * Update compiler/closureiters.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #11225; generic sandwich problems; [backport:1.2] (#17255)Andreas Rumpf2021-03-091-1/+1
| | | | | * fixes #11225; generic sandwich problems; [backport:1.2] * progress * delegating these symbols must be done via 'bind'
* fixes #17170 (#17171)Andreas Rumpf2021-02-241-1/+2
|
* big steps torwards an efficient, simple IC implementation (#16543)Andreas Rumpf2021-01-021-6/+6
| | | | | | | | | | | | | | | | | | | * reworked ID handling * the packed AST now has its own ID mechanism * basic serialization code works * extract rodfiles to its own module * rodfiles: store and compare configs * rodfiles: store dependencies * store config at the end * precise dependency tracking * dependency tracking for rodfiles * completed loading of PSym, PType, etc * removed dead code * bugfix: do not realloc seqs when taking addr into an element * make IC opt-in for now * makes tcompilerapi green again * final cleanups Co-authored-by: Andy Davidoff <github@andy.disruptek.com>
* explicit ID generation for easier IC (#15559)Andreas Rumpf2020-10-251-15/+20
| | | | | | | | | | | | | | | | | * refactoring: idents don't need inheritance * refactoring: adding an IdGenerator (part 1) * refactoring: adding an IdGenerator (part 2) * refactoring: adding an IdGenerator (part 3) * refactoring: adding an IdGenerator (part 4) * refactoring: adding an IdGenerator (part 5) * refactoring: adding an IdGenerator (part 5) * IdGenerator must be a ref type; hello world works again * make bootstrapping work again * progress: add back the 'exactReplica' ideas * added back the missing exactReplica hacks * make tcompilerapi work again * make important packages green * attempt to fix the build for 32 bit machines (probably need a better solution here)
* closureiters: fixes #15243 (#15454) [backport:1.2]Andreas Rumpf2020-10-021-3/+102
| | | | * fixes #15243 [backport:1.2]
* Big compiler Cleanup (#14777)Clyybber2020-08-281-3/+0
|
* Fix #14396 (#14793)Clyybber2020-07-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | * Correct Left-To-Right evaluation of proc args * Fix CPP backend * Add testcase * closes #14396 * closes #14345 * Improve test and optimize * Improve testcase and optimize literals * Fix bug * Expand testcase and use DFA to optimize * Turn genParams into proc * Turn withTmpIfNeeded into a proc * Cleanup * Fix crash * Better analysis * Cleanup * Trailing newline.. * Fix build * Tiny cleanup Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #14279 (#14618)Andreas Rumpf2020-06-091-2/+6
|
* arc optimizations (#13325)Andreas Rumpf2020-03-181-2/+2
| | | | | * scope based destructors * handle 'or' and 'and' expressions properly, see the new test arc/tcontrolflow.nim * make this branch mergable, logic is disabled for now
* make case-object transitions explicit, make unknownLineInfo a const, replace ↵Jasper Jenkins2020-01-171-1/+1
| | | | a few magic numbers with consts (#13170)
* fixes #12956 (#13020)Andreas Rumpf2020-01-031-1/+2
|
* Cosmetic compiler cleanup (#12718)Clyybber2019-11-281-32/+32
| | | | | | | | | | | | | | | | | | * Cleanup compiler code base * Unify add calls * Unify len invocations * Unify range operators * Fix oversight * Remove {.procvar.} pragma * initCandidate -> newCandidate where reasonable * Unify safeLen calls
* Fixed yield in nkCheckedFieldExpr (#12429) [backport]Yuriy Glukhov2019-10-151-2/+3
|
* Fix spellings (#12277) [backport]Federico Ceratto2019-09-271-2/+2
|
* closureiters.nim: finish the bugfixAndreas Rumpf2019-09-101-1/+1
|
* Fixed yield in nnkChckRange (#12160)Yuriy Glukhov2019-09-101-2/+2
|
* Reset closure iter exception before rethrowingYuriy Glukhov2019-08-161-6/+5
|
* int128 on firstOrd, lastOrd and lengthOrd (#11701)Arne Döring2019-08-071-6/+6
| | | | * fixes #11847
* [refactoring] remove unused imports in the compiler and in some stdlib modulesAraq2019-07-181-2/+2
|
* [refactoring] closureiters.nim: style changeAraq2019-06-201-132/+130
|
* more destructor based changes (#10885)Andreas Rumpf2019-03-231-2/+2
| | | | | | | | | | | * mark user defined destructors with sfOverriden to simplify the logic * refactoring in preparation to merge liftings and generic instantiations for destructors * ast: introduce nkHiddenTryStmt for destructor generation in order to be able to optimize better the code later on * renamed 'patterns' switch to 'trmacros' as it was totally misleading before * destructors: introduce tfCheckedForDestructor flag in preparation of strict =destroy checking * test for invalid/too late destructor introductions * liftdestructors: make code robust for nimsuggest * --newruntime works for hello world again * newruntime: code generation for closures
* Fixes 9716 [backport] (#9790)Yuriy Glukhov2018-11-241-8/+9
| | | | | | * reuse temporary variable * fixes #9716 [backport] * Declare local vars in safer place
* Fixed yield in nkObjConstr. Fixes #9694 [backport] (#9744)Yuriy Glukhov2018-11-181-9/+15
| | | | | * Fixed yield in nkObjConstr. Fixes #9694 * Separate expr lowering from state splitting, introduce a clear lowering internal error
* Field checks for everybody (#8957)LemonBoy2018-10-091-5/+5
| | | | | | | | | | | | | | | | | | | | | * Field checks for JS backend * Clean nkCall nodes with no arguments Generating a nkEmpty in place of no arguments makes no sense form the AST point of view and also trips up the VM codegen. * Field checks for VM backend * Test case for #6612 This patchset fixes #6612 * Add test case for LHS double evaluation * Prevent LHS double-eval for JS backend * Prevent double evaluation in VM backend
* Fixes #8243 (#8904)Yuriy Glukhov2018-09-071-0/+19
|
* Fixes #8851 (#8859)Yuriy Glukhov2018-09-041-3/+3
|
* Make sure addGotoOut always inserts its node (#8843)LemonBoy2018-09-031-1/+1
| | | Fixes #8773
* Fixed #8399 (#8401)Yuriy Glukhov2018-07-221-1/+1
|
* fixex merge conflictsAraq2018-06-081-26/+26
|
* Fixes #7985Yuriy Glukhov2018-06-071-9/+8
|
* Fixed yield in nkBlockExprYuriy Glukhov2018-06-071-2/+14
|