-
Notifications
You must be signed in to change notification settings - Fork 17
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
cps/xfrm: cleanup exception rewrite and fix bugs #124
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not merge?
proc rewriteExcept(cont, ex, n: NimNode): tuple[cont, excpt: NimNode] = | ||
## Rewrite the exception branch `n` to use `ex` as the "current" exception | ||
## and move its body into a continuation | ||
doAssert n.kind == nnkExceptBranch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of this line? Seriously. 😆
proc setContException(n: NimNode): NimNode = | ||
## If `n` is a continuation, set the exception to `ex` before | ||
## running any other code | ||
# XXX: need a way to prevent multiple insertions of this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could annotate the composed AST with a discard "exception wuz fixerated"
and then have a check for that, but a better solution would be @saem's NimNode types.
Fixed one main issue where the "current" exception is not refreshed every bounce and that the exception is not voided after completion of the except clauses. Need more tests.
While the continuation is not executing, we do not want anything to touch the exception via the exception leaked via setCurrentException(). This is likely inadequate and can't handle an exception being raised in the exception handler, so we will need `finally` for this. This commit also consume the exception right before a scope change.
There are a few major issues left:
|
Okay, but isn't that correct behavior?
I don't know why we'd want to catch unhandled exceptions. Ideally, exceptions don't touch the state so that the user can simply invoke the continuation again -- kinda like quirky exceptions, right? |
https://play.nim-lang.org/#ix=3nFm <-- apparently not
I worry about this: nim-lang/Nim#18070 |
I guess we have to store all exceptions in the locals. This is feeling the original handwritten transform, right?
Looks like the pointer isn't cleared but that should be an easy fix. Did you look at the codegen? |
Fixed one main issue where the "current" exception is not refreshed
every bounce and that the exception is not voided after completion
of the except clauses.
Also moved the except rewrite outside of
cpsTryExcept
.Need more tests.