summary refs log tree commit diff stats
path: root/compiler/lambdalifting.nim
Commit message (Collapse)AuthorAgeFilesLines
* disable closure iterator changes in #23787 unless `-d:nimOptIters` is ↵metagn2024-09-161-3/+33
| | | | | | | | | | | | | | enabled (#24108) refs #24094, soft reverts #23787 #23787 turned out to cause issues as described in #24094, but the changes are still positive, so it is now only enabled if compiling with `-d:nimOptIters`. Unfortunately the changes are really interwoven with each other so the checks for this switch in the code are a bit messy, but searching for `nimOptIters` should give the necessary clues to remove the switch properly later on. Locally tested that nimlangserver works but others can also check.
* Optimize closure iterator locals (#23787)Yuriy Glukhov2024-07-031-47/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* implement `legacy:jsNoLambdaLifting` for compatibility (#23727)ringabout2024-06-171-1/+9
|
* fixes #23522; fixes pre-existing wrong type for iter in `liftIterSym` (#23538)ringabout2024-04-261-2/+1
| | | fixes #23522
* fixes #4695; closure iterators support for JS backend (#23493)ringabout2024-04-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | 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 #4299 #12492 #10849; lambda lifting for JS backend (#23484)ringabout2024-04-111-13/+1
| | | | | | | | fixes #4299 fixes #12492 fixes #10849 It binds `function` with `env`: `function.bind(:env)` to ease codegen for now
* fixes #15924; Tuple destructuring is broken with closure iterators (#23205)ringabout2024-01-131-5/+8
| | | fixes #15924
* Types: Refactorings; step 1 (#23055)Andreas Rumpf2023-12-121-4/+5
|
* IC: progress and refactorings (#22961)Andreas Rumpf2023-11-201-5/+5
|
* prepare for the enforcement of `std` prefix (#22873)ringabout2023-10-291-2/+4
| | | follow up https://github.com/nim-lang/Nim/pull/22851
* NIR: progress (#22817)Andreas Rumpf2023-10-121-4/+4
| | | | | | Done: - [x] Implement conversions to openArray/varargs. - [x] Implement index/range checking.
* fix #22548;environment misses for type reference in iterator access n… ↵Bung2023-08-271-5/+19
| | | | | | | | | | | | | (#22559) * fix #22548;environment misses for type reference in iterator access nested in closure * fix #21737 * Update lambdalifting.nim * remove containsCallKinds * simplify
* modernize lambdalifting (#22449)ringabout2023-08-111-9/+6
| | | | | * modernize lambdalifting * follow @beef331's suggestions
* fix #20891 Illegal capture error of env its self (#22414)Bung2023-08-091-3/+7
| | | | | * fix #20891 Illegal capture error of env its self * fix innerClosure too earlier, make condition shorter
* use strictdefs for compiler (#22365)ringabout2023-08-061-1/+6
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* refactoring in preparation for better, simpler name mangling that wor… ↵Andreas Rumpf2023-04-241-9/+9
| | | | | | | | | | | (#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
* Force lambda lifting for getImplTransformed. Hacky. Fixes #19818 (#21031)Yuriy Glukhov2023-01-191-2/+2
|
* fix #20152 Illegal capture of closure iterator, when should be legal (#20607)Bung2022-10-211-1/+1
|
* fixes #20572 (#20585)Andreas Rumpf2022-10-171-1/+1
| | | | | * fixes #20572 * added a test case
* refactorings (#20536)Andreas Rumpf2022-10-101-2/+2
| | | | | | | * refactoring * refactoring: removed unused macroUsagesSection * enum instead of bool for better readability
* cleanup nfFirstWrite flags (#20500)Andreas Rumpf2022-10-051-1/+1
|
* new move analyser2 (#20471)Andreas Rumpf2022-10-011-4/+12
| | | | | | | | * produce better code for closure environment creation * new 'first write' analysis; * scope based move analyser * code cleanup Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
* Friendlier error message with solution (#19880)Carlo Capocasa2022-06-111-1/+2
| | | | | | | | | | | | | * Add helpful suggestion, should always apply * mention var param limitation in async docs * Update compiler/lambdalifting.nim whoops thanks Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com> Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
* Fix bug in freshVarForClosureIter. Fixes #18474 (#19675) [backport]flywind2022-04-041-9/+4
| | | | | | | | | | * Fix bug in freshVarForClosureIter. Fixes #18474. freshVarForClosureIter was returning non-fresh symbols sometimes. Fixed by making addField return the generated PSym. * remove discardable Co-authored-by: Nick Smallbone <nick@smallbone.se>
* move assertions out of system (#19599)flywind2022-03-231-0/+3
|
* closes #18690; make view types stricter [backport] (#18891)Andreas Rumpf2021-09-241-4/+2
| | | | | * closes #18690 * don't allow capturing of view types [backport]
* use more meaningful name than "workaround14447" (#18237)Miran2021-06-111-1/+1
|
* fixes #11225; generic sandwich problems; [backport:1.2] (#17255)Andreas Rumpf2021-03-091-2/+3
| | | | | * fixes #11225; generic sandwich problems; [backport:1.2] * progress * delegating these symbols must be done via 'bind'
* big steps torwards an efficient, simple IC implementation (#16543)Andreas Rumpf2021-01-021-14/+14
| | | | | | | | | | | | | | | | | | | * 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>
* fix #15043 (#16441) [backport:1.4]cooldome2020-12-271-5/+7
| | | | | * fix #15043 * Trigger build
* Use modern enums in compiler (#15775)cooldome2020-11-021-1/+1
|
* explicit ID generation for easier IC (#15559)Andreas Rumpf2020-10-251-67/+71
| | | | | | | | | | | | | | | | | * 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)
* Use typeflag insteadClyybber2020-08-101-2/+3
|
* Make explicit {.nimcall.} a seperate calling conventionClyybber2020-08-081-2/+2
|
* fix #14421 items uses lent T (#14447)Timothee Cour2020-05-291-1/+2
| | | | | * fix #14421 items uses lent T for seq + openArray * add -d:nimWorkaround14447 * fix test
* `nim doc --backend:js`, `nim doc --doccmd:-d:foo`, `nim r --backend:js`, ↵Timothee Cour2020-05-111-3/+3
| | | | | | | | | | `--doccmd:skip` + other improvements (#14278) * `nim doc --backend:js|cpp...` `nim doc --doccmd:'-d:foo --threads:on'` `nim r --backend:cpp...` (implies --run --usenimcache) * --usenimcache works with all targets * --docCmd:skip now skips compiling snippets; 50X speedup for doc/manual.rst
* make case-object transitions explicit, make unknownLineInfo a const, replace ↵Jasper Jenkins2020-01-171-3/+3
| | | | a few magic numbers with consts (#13170)
* ARC: cycle detector (#12823)Andreas Rumpf2019-12-171-0/+1
| | | | | | | | | | | | | * first implementation of the =trace and =dispose hooks for the cycle collector * a cycle collector for ARC: progress * manual: the .acyclic pragma is a thing once again * gcbench: adaptations for --gc:arc * enable valgrind tests for the strutils tests * testament: better valgrind support * ARC refactoring: growable jumpstacks * ARC cycle detector: non-recursive algorithm * moved and renamed core/ files back to system/ * refactoring: --gc:arc vs --gc:orc since 'orc' is even more experimental and we want to ship --gc:arc soonish
* ARC: implemented a simple cycle detectorAraq2019-11-281-4/+6
|
* Cosmetic compiler cleanup (#12718)Clyybber2019-11-281-41/+40
| | | | | | | | | | | | | | | | | | * 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
* ARC: closure bugfixes (#12677)Andreas Rumpf2019-11-181-2/+9
| | | | | | | | * ARC: closure bugfixes * progress * ARC closures: create =hooks for captured parameters * ARC: always destroy constructions like tuples, arrays properly, even in edge cases * fixes a regression
* ARC: fixes leaking new() statement (#12665)Andreas Rumpf2019-11-151-6/+9
|
* ARC: solves phase ordering problems (#12654)Andreas Rumpf2019-11-141-7/+4
|
* ARC: use the new .cursor annotation for 'up' pointersAraq2019-11-131-2/+6
|
* fixes #12577 [backport] (#12584)Andreas Rumpf2019-11-031-8/+4
|
* --gc:destructors: simple closures workAndreas Rumpf2019-11-021-9/+13
|
* --gc:destructors now means Nim uses pure refcounting (#12557)Andreas Rumpf2019-10-301-1/+2
|
* proof that refcounting can handle Nim's async (#12533)Andreas Rumpf2019-10-281-18/+18
|
* some progress on bug #12443Andreas Rumpf2019-10-271-1/+1
|
* refactoring: use the new strings and seqs when optSeqDestructors is activeAraq2019-10-201-3/+3
|