Skip to content

Conversation

Vindaar
Copy link
Contributor

@Vindaar Vindaar commented Apr 27, 2018

On my current Nim devel branch (from yesterday 26/04/18)

Nim Compiler Version 0.18.1 [Linux: amd64]
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: 397e1731393be598991df302006ec3634baa3583
active boot switches: -d:release

Link to commit: nim-lang/Nim@397e173

loopfusion raises an illegal capture error, if forZip is used within a proc. To take a simple example from the loopfusion tests:

import loopfusion
    
proc main() =
  let a = @[1, 2, 3]
  let b = @[11, 12, 13]
  let c = @[10, 10, 10]

  forZip x in a, y in b, z in c:
    echo (x + y) * z

when isMainModule:
  main()

raises

~/.nimble/pkgs/loopfusion-0.0.1/loopfusion.nim(122, 15) Error: illegal capture 'a' because 'loopfusion_zipImpl_3_' has the calling convention: <inline>

while the same code, if placed directly below when isMainModule, compiles just fine.

The error refers to the usage of quote do here:

zipBody.add quote do:
   let `size0` = `container0`.len

By exchanging the usage of quote do with manual AST generation, the problem disappears.

Vindaar added 2 commits April 27, 2018 10:10
Move the tests defined in loopfusion under `when isMainModule` to
tests into a `main` proc, in order to test for an `illegal capture`
error, which is raised if forZip is used within a proc..
Replaces the `quote do` usage to in `generateZip` when assigning the
0th container size to `size0` by manual AST generation to fix an
`illegal capture` error, which is raised otherwise if forZip is called
within a proc.
@mratsim
Copy link
Owner

mratsim commented Apr 27, 2018

Awesome, thanks

@mratsim mratsim merged commit 1b928f2 into mratsim:master Apr 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants