koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.16k stars 151 forks source link

internal error: Map.!: given key is not an element in the map #501

Open Caid11 opened 2 months ago

Caid11 commented 2 months ago

I found this while trying to reduce my reproducer for #500. It's very similar, and could be related or a duplicate.

When I try to compile my code, I see this error:

parse   : .../bb.kk
check   : bb
bb(1, 1): internal error: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
  error, called at libraries\containers\containers\src\Data\Map\Internal.hs:617:17 in containers-0.6.7:Data.Map.Internal

Failed to compile bb.kk

Similar to #500, passing --rebuild avoids the failure. I found that removing the bleh : duration member of the server struct and updating its constructor calls fixes the issue.

Notes:

Failing code is here: https://github.com/Caid11/Functional-Program-Studio/tree/internal-compile-error-map/blockbuilder

anfelor commented 1 month ago

I managed to reproduce this error. It is tricky to minify and often instead runs into the linked #500 instead (eg. not being able to look up world/gameWorld). On linux, you can reproduce this using my stub implementation of socket.kk and raylib.kk.

The bug occurs since modmapRead is passed a module with name nameNil:

bb(1, 1): internal error: modmapRead: empty modname
CallStack (from HasCallStack):
  error, called at src/Compile/Build.hs:218:32 in koka-3.1.2-7SWN83ElxwDEblvTDAD6Nq:Compile.Build
  modmapRead, called at src/Compile/Build.hs:347:25 in koka-3.1.2-7SWN83ElxwDEblvTDAD6Nq:Compile.Build
  moduleWaitForImports, called at src/Compile/Build.hs:307:19 in koka-3.1.2-7SWN83ElxwDEblvTDAD6Nq:Compile.Build
  moduleCodeGen, called at src/Compile/Build.hs:262:18 in koka-3.1.2-7SWN83ElxwDEblvTDAD6Nq:Compile.Build
  moduleCompile, called at src/Compile/Build.hs:107:25 in koka-3.1.2-7SWN83ElxwDEblvTDAD6Nq:Compile.Build
anfelor commented 1 month ago

I added tracing for all modmap(Try)Put and modmapRead operations -- the full log is at https://gist.github.com/anfelor/57e63dc6f2b7933bb40a2753c6b54b71 for a minified version of the code that only imports raylib/raylib, socket/socket, server, ui.