Skip to content
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

Merged
merged 2 commits into from
May 25, 2021

Conversation

alaviss
Copy link
Contributor

@alaviss alaviss commented May 24, 2021

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.

Copy link
Contributor

@disruptek disruptek left a 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
Copy link
Contributor

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
Copy link
Contributor

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.
@alaviss
Copy link
Contributor Author

alaviss commented May 24, 2021

There are a few major issues left:

  • Exception raised and handled within the exception handler will replace the handler's current exception
  • Even with the latest commit, the exception might leak if an unhandled exception is raised (we may have to decide how unhandled exceptions affect a running continuation)

@alaviss alaviss requested a review from disruptek May 24, 2021 16:41
@disruptek
Copy link
Contributor

There are a few major issues left:

  • Exception raised and handled within the exception handler will replace the handler's current exception

Okay, but isn't that correct behavior?

  • Even with the latest commit, the exception might leak if an unhandled exception is raised (we may have to decide how unhandled exceptions affect a running continuation)

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?

@alaviss
Copy link
Contributor Author

alaviss commented May 24, 2021

Okay, but isn't that correct behavior?

https://play.nim-lang.org/#ix=3nFm <-- apparently not

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?

I worry about this: nim-lang/Nim#18070

@disruptek
Copy link
Contributor

https://play.nim-lang.org/#ix=3nFm <-- apparently not

I guess we have to store all exceptions in the locals. This is feeling the original handwritten transform, right?

I worry about this: nim-lang/Nim#18070

Looks like the pointer isn't cleared but that should be an easy fix. Did you look at the codegen?

@disruptek disruptek merged commit 9cb9189 into nim-works:master May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants