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

nimvm: CritBitTree does not work: "limited VM support for 'addr'" #14339

Closed
akavel opened this issue May 13, 2020 · 3 comments · Fixed by #16002
Closed

nimvm: CritBitTree does not work: "limited VM support for 'addr'" #14339

akavel opened this issue May 13, 2020 · 3 comments · Fixed by #16002

Comments

@akavel
Copy link

akavel commented May 13, 2020

The CritBitTree type does not work at compile time.

Example

import critbits
static:
  var strings: CritBitTree[int]
  discard strings.containsOrIncl("foo", 1)
  echo strings["foo"]

Current Output

stack trace: (most recent call last)
C:\prog\dali\q_ct01.nim(5, 15) q_ct01
C:\Users\Mateusz\.choosenim\toolchains\nim-1.2.0\lib\pure\collections\critbits.nim(196, 3) []
C:\Users\Mateusz\.choosenim\toolchains\nim-1.2.0\lib\pure\collections\critbits.nim(196, 3) Error: limited VM support for 'addr'

Expected Output

1

Additional Information

  • I am using CritBitTree in my project dali, which allows emitting Android .dex files from Nim. I would like to be able to emit .dex files at compile time, when writing Android apps in Nim. Currently, I have to instead:

Nim version:

C:\prog\dali>nim -v
Nim Compiler Version 1.2.0 [Windows: amd64]
Compiled at 2020-04-03
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 7e83adff84be5d0c401a213eccb61e321a3fb1ff
active boot switches: -d:release
akavel added a commit to akavel/jnim that referenced this issue May 13, 2020
This change makes it possible to use `jexport` together with `jnimDexWrite` to
emit .dex files. The `jnimDexWrite` proc builds a .nim file, which can then be
compiled using package dali to generate a .dex file.

Currently, the intermediate step of generating a .nim file is required, as
Nim's compile-time has a lot of limitations. In this particular case, see e.g.:
- nim-lang/Nim#14339
- nim-lang/Nim#14340
akavel added a commit to akavel/jnim that referenced this issue May 13, 2020
This change makes it possible to use `jexport` together with `jnimDexWrite` to
emit .dex files. The `jnimDexWrite` proc builds a .nim file, which can then be
compiled using package dali to generate a .dex file.

Currently, the intermediate step of generating a .nim file is required, as
Nim's compile-time has a lot of limitations. In this particular case, see e.g.:
- nim-lang/Nim#14339
- nim-lang/Nim#14340
yglukhov pushed a commit to yglukhov/jnim that referenced this issue May 13, 2020
This change makes it possible to use `jexport` together with `jnimDexWrite` to
emit .dex files. The `jnimDexWrite` proc builds a .nim file, which can then be
compiled using package dali to generate a .dex file.

Currently, the intermediate step of generating a .nim file is required, as
Nim's compile-time has a lot of limitations. In this particular case, see e.g.:
- nim-lang/Nim#14339
- nim-lang/Nim#14340
@ringabout
Copy link
Member

@akavel
Workaround:

import critbits

proc getKey*[T](c: CritBitTree[T], key: string): T {.inline.} =
  c[key]

static:
  var strings: CritBitTree[int]
  discard strings.containsOrIncl("foo", 1)
  echo strings.getKey("foo")

https://play.nim-lang.org/#ix=2rsd

@timotheecour
Copy link
Member

reduced without stdlib:

when true:
  type
    Node = ref object
      val: int
  proc bar(c: Node): var int =
    var n = c # Error: limited VM support for 'addr'
    c.val
  proc main =
    var a = Node()
    discard a.bar()
  static: main()
  main()

@akavel
Copy link
Author

akavel commented Nov 16, 2020

@timotheecour ❤️ thanks for working on this!

timotheecour added a commit to timotheecour/Nim that referenced this issue Nov 16, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Nov 25, 2020
Araq pushed a commit that referenced this issue Nov 25, 2020
* fix #14339: fixes limited VM support for addr

* strengthen test

* reference bug #16003

* also fixes #13511

* also fixes #14420
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
…support for addr (nim-lang#16002)

* fix nim-lang#14339: fixes limited VM support for addr

* strengthen test

* reference bug nim-lang#16003

* also fixes nim-lang#13511

* also fixes nim-lang#14420
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
…support for addr (nim-lang#16002)

* fix nim-lang#14339: fixes limited VM support for addr

* strengthen test

* reference bug nim-lang#16003

* also fixes nim-lang#13511

* also fixes nim-lang#14420
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 a pull request may close this issue.

3 participants