with-open breaks when `debug` module unavailable

I came across this somewhat accidentally: the mlua Rust bindings (which are used by, among others, WezTerm for its lua config) doesn't expose the debug module, at least by default.

Fennel still runs fine in it for the most part (especially doing AOT compilation), but with-open breaks due to the assumption that it's there.

I think "no debug" is worth supporting, since there are a number of usecases for sandboxing it out (in mlua's case, because it's not memory safe), and in the case of with-open it should be easy enough to add a check and fallback.

#side note: debug.getinfo & fennel.traceback

This also means fennel.traceback breaks; this may also be worth exploring fallback behaviors but I'm not sure that can be done as cleanly without looking into it. Might just be a case of having it give up and spit out lua stacktraces with a "welp, guess we'll have to enable correlate"

Assigned to
10 months ago
10 months ago

~jaawerth 10 months ago

This one should be pretty friendly for someone new to hacking on the compiler, since it's mostly just a matter of formulating a decent fallback value for traceback in the let binding here.

(let [; ...stuff
      traceback `(. (or package.loaded.fennel debug) :traceback)] ; ...etc

We could just pass an identity function there to prevent an error and let it spit out the message as-is, which would be good for starters anyway, and only tweak if further if we think we think the incremental improvement is worth the extra complexity.

~jaawerth 10 months ago

Thinking about it more, I'm actually not immediately sure how much we can improve things when traceback is missing. Might just have to have an unfriendly error in the absence of debug, but if nobody else takes it on I'll mess with it when I'm more awake at some point. In the meantime, the identity fallback would at least allow the macro to work.

Register here or Log in to comment, or comment via email.