-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Experiment: Change Pony errors to use return flags (internally) rather than exceptions #4443
Comments
Note that I have already done this experiment in the Savi compiler, so I am familiar with the areas of code that need to change in the Pony compiler to make this work. Here are my raw notes that I wrtoe up in a call with @SeanTAllen today where we went over what needs to be done:
|
When getting rid of time.c: ponyint_formattimeThe windows version uses format_invalid_parameter_handler to set up an invalid format handler which will do a pony_error. Instead of doing pony_error, we can consider returning an empty string. We already return empty string for "potentially problematic format codes": // Bail out on strftime formats that can produce a zero-length string.
if((fmt[0] == '\0') || !strcmp(fmt, "%p") || !strcmp(fmt, "%P"))
{
buffer = (char*)pony_alloc(ctx, 1);
buffer[0] = '\0';
return buffer;
} On Windows, instead of using the handler function that has a void return type, we can (on windows only) check if This would make When can consider leaving socket.c: multiple functionsWe have two options.
Although it is more work, I am leaning towards 2 being a better option. |
I suggest an intermediary step. Add a TLS variable in order to indicate an error, basically an errno like approach. It may not be the most elegant solution but this enables that Using this you don't have to change the current FFI interface and also switch back and forth between exceptions/error variable in order to test things and compare. |
We were discussing background of this during sync and I brought up a point that wasn't recorded here. When we had this conversation, Sylvan had come around to being in favor this general approach for handling errors. I am adding now as Joe asked me to add so he could remember that point going forward. |
We should put this through the RFC process. The key point would be "getting rid of allowing FFI functions to be partial". We need to make sure we are ok with that change. |
Regarding the comment about using a thread-local variable, please note that this wouldn't be enough to preserve the current behavior of I'm in favor of just removing I briefly did a GitHub search and found no usage of this feature outside the standard library. |
We are looking at maybe changing the way that Pony errors work internally. Specifically, we are looking at using return flags (internally) rather than exceptions and LLVM invokes.
These changes would be almost entirely invisible to Pony users except in the following ways:
The
pony_error
C function would be removed, and any C code which currently uses it must be refactored use another approach to convey failures to the caller.pony_error
to raise a Pony-specific exceptions (C++ exceptions are already not supported today)Performance may be impacted (for better and/or worse, depending on the application.
The text was updated successfully, but these errors were encountered: