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

Fixes compilation issues in v3 compatibility mode (-d:chronosHandleException) #545

Merged
merged 9 commits into from
Jun 10, 2024

Conversation

gmega
Copy link
Member

@gmega gmega commented May 22, 2024

fixes #544

This PR adds the missing await calls which fixes the issue I was experiencing without visible ill effects. I've also added (somewhat naively) the ability to run the test suite in compat mode, though not sure this is a desirable change.

test "Cannot raise invalid exception":
checkNotCompiles:
proc test3 {.async: (raises: [IOError]).} = raise newException(ValueError, "hey")
when not chronosHandleException:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this test need to be disabled? the global handleException default should not affect raises-annotated functions..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... apparently it does, as this snippet starts to compile when I enable it; i.e., it seems to relax the raises constraint in raises-annotated procs as well. I thought this was intentional.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, running a simple test with the raises-annotated proc above and looking at the expansions I can see that the global flag does indeed modify the exception handlers (adds handlers for Exception and CatchableError, removes handler for IOError).

Copy link
Member Author

@gmega gmega May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... if I understand the implementation right:

proc decodeParams(params: NimNode): AsyncParams =
  ...
  var
    raw = false
    raises: NimNode = nil
    handleException = chronosHandleException
  ...
  if param[0].eqIdent("raises"):
    ... # doesn't reset handleException to false
  elif param[0].eqIdent("handleException"):
      handleException = param[1].eqIdent("true")

this will indeed simply start from the global value and then override it if handleException is set, but won't set it to false if there's a raises clause (or handle the fact that it was set globally rather than locally in any special way).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm experimenting with fixing this and seeing how it impacts our code.

Copy link
Member Author

@gmega gmega May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK here goes my attempt at fixing this. I've added it to this branch as it sort of fits the overall "compilation issues in v3 compatibility mode" theme, and I'd need the previous changes to be able to compile Chronos with the flag on anyways. I'm compiling/running Codex with this and it seems fine.

@arnetheduck
Copy link
Member

Hm, this looks like it's cycling down the wrong path. Let's revert to what handleExceptions is supposed to do: remap Exception to AsyncExceptionError - this means that for any function where handleExceptions is enabled and it has raises, the raises list also needs to include AsyncExceptionError - of course, in legacy code this is not a problem (because async without raises allows any exception to pass), but the failing tests are likely failing because of this "extra" exception being raised - the solution is to write the tests such that when hndleExceptions is globally enabled, they have a different raises list

@@ -720,7 +720,7 @@ proc newDatagramTransportCommon(cbproc: UnsafeDatagramCallback,
proc wrap(transp: DatagramTransport,
remote: TransportAddress) {.async: (raises: []).} =
try:
cbproc(transp, remote)
await cbproc(transp, remote)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this part is good

@arnetheduck
Copy link
Member

hm, or .. maybe you're right, maybe it doesn't make sense for the global flag to apply to raises-annotated functions in which case the documentation needs to be updated as well.

This makes more sense in the context of upgrading an existing codebase with mixed annotated and non-annotated code - let's go with your proposal, forget my previous comment.

@gmega
Copy link
Member Author

gmega commented May 24, 2024

Yeah, even though my proposal actually comes from my understanding of what I thought was your proposal ( 😄 ), I came to realize that being able to get incremental exception checking as I annotate a legacy codebase doesn't seem bad at all. Gonna take a stab at updating the docs.

@gmega
Copy link
Member Author

gmega commented May 24, 2024

OK, added a tentative update to the docs.

@gmega gmega requested a review from arnetheduck May 28, 2024 13:22
@gmega
Copy link
Member Author

gmega commented Jun 3, 2024

@arnetheduck ping 🙂

@arnetheduck arnetheduck merged commit 7630f39 into status-im:master Jun 10, 2024
12 checks passed
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.

Compilation errors with -d:chronosHandleException
2 participants