samdze / playdate-nim

Nim bindings with extra features for the Playdate SDK
61 stars 3 forks source link

How to deal with "declared lock level is 0, but real lock level is <unknown> [LockLevel]" #55

Open ninovanhooff opened 4 months ago

ninovanhooff commented 4 months ago
proc getLevelPaths(): seq[string] {.locks:0.} =
  playdate.file.listFiles("levels")

The above code snippet triggers a declared lock level is 0, but real lock level is <unknown> [LockLevel] warning. Can be fixed by adding {.locks:0.} to the listFiles function.

But I wonder: can we disable this check altogether, since lck are for thread-safeness and we don't have threads on Playdate?

If that is not acceptable, can we add locks:0 to the {.push} pragma in all the api files?

ninovanhooff commented 4 months ago

Note that this lock check seems deprecated in in nim 2 https://forum.nim-lang.org/t/10487

samdze commented 4 months ago

Do you get that warning in the IDE or in the command line during compilation? I'm not getting that warning for some reason.

ninovanhooff commented 4 months ago

Command line

/bin/zsh -c "nimble simulate"
  Executing task simulate in /Users/ninovanhooff/PlaydateProjects/wheelsprung/wheelsprung.nimble
  Executing task simulator in /Users/ninovanhooff/PlaydateProjects/wheelsprung/wheelsprung.nimble
  Verifying dependencies for wheelsprung@0.2.0
    Reading official package list
   Checking for https://github.com/ninovanhooff/playdate-nim@#develop
      Info: Dependency on https://github.com/ninovanhooff/playdate-nim@#develop already satisfied
  Verifying dependencies for playdate@#develop
    Reading official package list
   Checking for https://github.com/ninovanhooff/nim-chipmunk-playdate@any version
      Info: Dependency on https://github.com/ninovanhooff/nim-chipmunk-playdate@any version already satisfied
  Verifying dependencies for chipmunk7@7.0.3
   Building wheelsprung/wheelsprung using c backend
  Executing /Users/ninovanhooff/.nimble/bin/nim c --colors:on --noNimblePath -d:simulator -d:debug -d:NimblePkgVersion=0.2.0 --path:'/Users/ninovanhooff/.nimble/pkgs/playdate-#develop' --path:/Users/ninovanhooff/.nimble/pkgs/chipmunk7-7.0.3 -o:/Users/ninovanhooff/PlaydateProjects/wheelsprung/wheelsprung /Users/ninovanhooff/PlaydateProjects/wheelsprung/src/wheelsprung.nim
Hint: used config file '/Users/ninovanhooff/.choosenim/toolchains/nim-1.6.16/config/nim.cfg' [Conf]
Hint: used config file '/Users/ninovanhooff/.choosenim/toolchains/nim-1.6.16/config/config.nims' [Conf]
Hint: used config file '/Users/ninovanhooff/PlaydateProjects/wheelsprung/config.nims' [Conf]
..........................................................................................................................................................
/Users/ninovanhooff/PlaydateProjects/wheelsprung/src/screens/game/game_view.nim(124, 6) Warning: declared lock level is 0, but real lock level is <unknown> [LockLevel]
.
/Users/ninovanhooff/.choosenim/toolchains/nim-1.6.16/lib/system/repr_v2.nim(102, 7) Hint: 'firstElement' is declared but not used [XDeclaredButNotUsed]
/Users/ninovanhooff/PlaydateProjects/wheelsprung/src/screens/game/game_screen.nim(260, 8) Warning: method has lock level <unknown>, but another method has 0 [LockLevel]
.
/Users/ninovanhooff/PlaydateProjects/wheelsprung/src/screens/level_select/level_select_screen.nim(16, 6) Warning: declared lock level is 0, but real lock level is <unknown> [LockLevel]
/Users/ninovanhooff/PlaydateProjects/wheelsprung/src/screens/level_select/level_select_screen.nim(22, 6) Warning: declared lock level is 0, but real lock level is <unknown> [LockLevel]
/Users/ninovanhooff/PlaydateProjects/wheelsprung/src/screens/level_select/level_select_screen.nim(72, 8) Warning: method has lock level 0, but another method has <unknown> [LockLevel]
CC: ../../../.nimble/pkgs/playdate-#develop/playdate/graphics.nim
CC: screens/game/game_view.nim

Note that Screen is an object defined here: https://github.com/ninovanhooff/wheelsprung/blob/8a4ad17ffaca0e504de5c6a77a4f07c3d206ca6c/src/navigation/screen.nim#L1

Also note that this file has a push pragma for locks.

Used here: https://github.com/ninovanhooff/wheelsprung/blob/8a4ad17ffaca0e504de5c6a77a4f07c3d206ca6c/src/screens/level_select/level_select_screen.nim#L72

General remark: not really sure what I'm doing here. My goal with all of the "locks" pragmas / annnotations was To Make The Warnings Go Away

edit: got slightly mixed up with what line of code I started this issue for. That's line 16. In addition, there are some warnings for the Screen methods