Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closure iterators are not supported by VM #15818

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

ringabout
Copy link
Member

I can raise error messages in JS backend too.
Are there some plans or ideas to implement closure iterators in VM or JS backend.

@timotheecour
Copy link
Member

Are there some plans or ideas to implement closure iterators in VM or JS backend.

At call site, the only difference with you need to add an explicit iterate:

for k,v in myIter2(2,5):
  echo k, v
  if k == 0: continue
  if k == 1: break
  
=>
for k,v in iterate myIter2(2,5):
  echo k, v
  if k == 0: continue
  if k == 1: break

At declaration site, you use a regular proc instead of an iterator to implement it, see details in #15655

This is already useful today, for code that needs functionality equivalent to closure iterators in VM or js.
And with some syntax sugar, the compiler could maybe map the existing syntax (iterator myIter() ...) to this, and not have to implement those for all backends, thus simplifying the language. Note that with alias PR (#11992),you'll also be able to define inline iterators the same way.

@timotheecour timotheecour changed the title Closure iterators are not supported by VM Closure iterators are not supported by VM or js Nov 2, 2020
@timotheecour timotheecour added VM see also `const` label Javascript labels Nov 2, 2020
@Araq
Copy link
Member

Araq commented Nov 2, 2020

I've shown in #15655 that you can implement the same thing as a closure iterator using a pure library solution, and it works with all backends (c, js, vm etc) without special support needed.

Yes but "moved feature X from the compiler to the libraries" always causes lots of work for anybody involved and plenty of subtle regressions. We should simply fix the compiler so that closure iterators are supported in the VM etc. Let's fix what we have.

@Araq Araq merged commit 5b4c17b into nim-lang:devel Nov 2, 2020
@timotheecour timotheecour changed the title Closure iterators are not supported by VM or js Closure iterators are not supported by VM Nov 2, 2020
ringabout added a commit to ringabout/Nim that referenced this pull request Nov 2, 2020
Araq pushed a commit that referenced this pull request Nov 2, 2020
* follow #15818 and close #7109

* Update compiler/jsgen.nim

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
narimiran pushed a commit that referenced this pull request Nov 5, 2020
narimiran pushed a commit that referenced this pull request Nov 5, 2020
* follow #15818 and close #7109

* Update compiler/jsgen.nim

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
(cherry picked from commit fde17b1)
PMunch pushed a commit to PMunch/Nim that referenced this pull request Jan 6, 2021
PMunch pushed a commit to PMunch/Nim that referenced this pull request Jan 6, 2021
* follow nim-lang#15818 and close nim-lang#7109

* Update compiler/jsgen.nim

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
mildred pushed a commit to mildred/Nim that referenced this pull request Jan 11, 2021
mildred pushed a commit to mildred/Nim that referenced this pull request Jan 11, 2021
* follow nim-lang#15818 and close nim-lang#7109

* Update compiler/jsgen.nim

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
Araq added a commit that referenced this pull request Feb 18, 2021
irdassis pushed a commit to irdassis/Nim that referenced this pull request Mar 16, 2021
irdassis pushed a commit to irdassis/Nim that referenced this pull request Mar 16, 2021
* follow nim-lang#15818 and close nim-lang#7109

* Update compiler/jsgen.nim

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
* follow nim-lang#15818 and close nim-lang#7109

* Update compiler/jsgen.nim

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
@ringabout ringabout deleted the vmclosureiterator branch April 1, 2024 14:46
Araq pushed a commit that referenced this pull request Apr 18, 2024
fixes #4695

ref #15818

Since `nkState` is only for the main loop state labels and `nkGotoState`
is used only for dispatching the `:state` (since
#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 #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???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Javascript VM see also `const` label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants