janet: Can't build when using top level `ev/chan` due to unable to marshal core/channel

Am on Janet 1.16.1-87f8fe14 linux/x64

main.janet

(def c (ev/chan 1))

(defn main [& args]
  (pp c))

project.janet

(declare-project
  :name "chan")

(declare-executable
  :name "chan"
  :entry "main.janet")
jpm build
generating executable c source...
error: try to marshal unregistered abstract type, cannot marshal <core/channel 0x56054A7DB030>
  in marshal
  in <anonymous> [/usr/local/bin/jpm] on line 748, column 20
  in do-rule [/usr/local/bin/jpm] on line 273, column 26
  in do-rule [/usr/local/bin/jpm] (tailcall) on line 269, column 44
  in _thunk [/usr/local/bin/jpm] on line -1, column -1
  in cli-main [boot.janet] on line 3559, column 39

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

That does have a nice summary – here’s a direct link.

Perhaps one of the things being referred to is:

It’s important to remember that code at the top level will run when you invoke jpm build, not at executable runtime. This is because in order to create the executable, we marshal the main function of the app and write it to an image. In order to create the main function, we need to actually compile and run everything that it references, in the above case mylib1 and mylib2.

@sogaiu, thank you! I was on the phone and have not found the way how to copy anchor href.

I would recommend to read https://janet-lang.org/docs/jpm.html Creating an executable.

I would argue it doesn’t really make sense to be able to marshal channels since at any given moment they also contain information about which fibers are waiting on them. I suppose we could just marshal the capacity and all of the values in the channel though. Or perhaps only allow marshalling an empty channel for this specific use case of initialization.