janet
janet copied to clipboard
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
Here's a repository for my attempt at reproducing: https://github.com/sogaiu/janet-marshal-channel
Not totally sure, but it might be that channels in certain states are too complicated to marshal, but an unused or newly constructed channel seems like a simpler case.
I guess a solution is to create a var and set it inside main instead then. That feels a bit off though.
I would recommend to read https://janet-lang.org/docs/jpm.html Creating an executable.
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 understand why this happens, but the question is does it have to happen or should (fresh) channels be marshallable?
I am not sure, but abstract C types can't be marshaled, open files or streams works the same. And there is no big difference between fresh and used channels I guess.
@pepe Isn't it the case that if appropriate things are defined for an abstract C type, it can be marshaled?
At least that was my impression looking at this: https://github.com/janet-lang/janet/blob/master/src/include/janet.h#L1049-L1050
@pepe they can be marshalled, files are different because they point to OS state that can't be marshalled, lots of other C types can be marshalled.
The difference between a fresh and used channel is a fresh one is not tied up in an active event loop so does not need to marshal the state of the event loop to resume.
@sogaiu I bet it can, but I was talking about the current state.
@andrewchambers, you know better than anyone that this stuff is above my expertise, yet I guess fresh channel is already tied to the ev
as it can be used straight away without any more initialization. I could be wrong tho.
Anyway I think, this is not that big issue and needs just a small adjustment on the side of the programmer.
Imo the issue arises when you're new and have no clue why this error occurs. I don't think it's strange that someone would put a global ev/chan
somewhere. Perhaps it could at least give an error message that shows which line the ev/chan
is called.
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.
Would it be possible then to show where in the code the marshalling breaks? I think either solution would be fine.
Den lör 24 juli 2021 19:54Calvin Rose @.***> skrev:
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.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/janet-lang/janet/issues/710#issuecomment-886087896, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAS46ZZHWBQ23AJRZ5SXQRDTZL437ANCNFSM46SXSSOQ .
I encountered something similar today for ev/thread-chan
The content for this comment has been moved to a new issue: https://github.com/janet-lang/janet/issues/801