-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack traces on exceptions & assert #82
Comments
@krypt-n Do you have an opinion on the |
It's a bit hard to use, since we can't look at the call site during stack unwinding. Only the return adress is known. My current solution emits additional src_pos at the first instruction of the return block. But maybe I should add call site information to the stack somehow?
The central question seems to be whether we want to keep an The other question is what the assert-statement in plush maps to in the vm. Allowing any library to completely abort the execution of the entire vm if there is an otherwise unnoticable bug doesn't seem to be user friendly (depends, of course, on the usage of the asserts). Throwing an exception from libraries seems much more useful, compared to my experiences with assertion failure in closed-source c libraries. |
This is why I added a
I think you're right that this is the important question. At this point I'm not worried about backwards incompatibility. Zeta is too young and not-fully-fleshed-out to worry about avoiding breaking changes IMO. We're still at a stage where we should be trying to figure out what's the best design long-term. I'm intentionally being careful about how much I promote Zeta to avoid drawing too many people before the basics are well-defined.
That rings true. Historically speaking, I implemented So, I think we should remove |
Multiple calls could return to the same block. A possiblity would be to always store the latest call instruction in the RetEntry, but I am sure that one could construct a recursive control flow where this causes wrong stacktraces. Pseudo edit: I just noticed that callFun pushes the call instruction to the stack, funCall does not. |
Ah! Thanks for pointing out this issue. I actually want to make it so each return address maps to a different call site. I can force the internal codegen to behave that way. It should simplify things a bit.
And I think I should probably rename one of these functions to avoid the naming confusion :O |
Plush asserts now use exceptions. I removed the |
Great. Should a stacktrace object/array be attached to the exception value, if it is catched? This would allow manual printing and/or introspection by the user or the runtime. A language runtime could for example look at the |
Hmm. I suppose we could. The minor complication here is that Zeta exception objects have to be converted into For illustration: Sidenote: we should probably specifically test annoying/complicated corner cases like this, importing a module which throws an exception during initialization. |
Once again, I have to apologise for my absence. I should have at least shared my progress on this issue before staying silent for two months. https://github.com/krypt-n/zetavm/commit/82c0995e97ca5dad5dcbbbae7d39fc0fc3f5ba2b test.pls:
TODO:
|
Hi @krypt-n. Welcome back. That seems like good progress. More than halfway there. Is there anything you're stuck on, need help with? |
Nothing in particular. Is |
|
Yes, I believe so.
In the case of RunError -> zeta object, we need to create a zeta object, we can't pass a pointer to a C++ object. In the case of zeta exception -> RunError, I'm not sure. We technically could wrap zeta exceptions I suppose, but I think at the moment I'm unwrapping them so the rest of the code doesn't have to deal with them. Are you asking because you'd like to preserve the stack trace information?
My plan is to eventually compile everything with the Plush language package, but I guess I've been slacking off with making that transition happen.
I think you could just say "at test.pls@3:9" ? |
In the current prototype, I am storing the zeta throw object and stack information inside of a RunError such that we can get stack information across host functions. (The stack trace from last week shows that) |
|
Seems good to me.
That's probably a good idea, because we can run in a situation where Plush code calls into ZetaVM code (C++), which calls back into Plush code. If we can just wrap the Plush exceptions and unwrap them, it seems better than converting to a C++ exception, and then back into a Plush one. |
Currently, every call site has an src_pos attribute which we can report in the stack trace.
@krypt-n pointed out that we may want to make sure to set the
name
attribute on every function, as much as possible. This will have to be handled at the parser level.Another issue we need to discuss is that currently,
assert
maps to theabort
instruction in the VM, which halts program execution. We have to decide whether we want to make assert simply throw an exception as in Python or keep the current behavior. The current behavior is based on the idea thatassert
is for circumstances which we really expect to be impossible, for sanity checks, whereas exceptions are for errors which we anticipate people could trigger.If we make
assert
simply map to exceptions, things may be simpler, implementation-wise, because we wouldn't have to add stack traces toabort
. However, if we keep theabort
instruction, we probably want stack traces anyway, so there is also a discussion to be had as to whether that instruction should be kept or not.The text was updated successfully, but these errors were encountered: