-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Compiler will out-of-memory with noreturn error union #3461
Comments
The
|
I don't think we should try to fit the LLVM detail here, because the message conveyed by
The function will either never return or throw an error, if so. So the whole non-catching part could be marked as unreachable by the compiler and emit the "code unreachable" error message. Use case is pretty much any program that is not designed to ever quit working (like firmware or such), but may throw an error that is not a panic and need a soft-recover the system (as opposed to panics which are by-definition not recoverable) |
#3263 is also a duplicate of this issue. The This is another example where a multi-pass analysis design would have helped: the |
I tried using I looked up to see if this was an existing issue and found this thread. The usecase I had for it is I have an event loop function with sockets that's supposed to run forever unless it fails. If it returns an error, the calling function will re-initialize and then call the function again, i.e. pub fn main() void {
while (true) {
const sock = connect(host);
defer os.close(sock);
eventLoop() catch |e| switch (e) {
error.Disconnected => continue, // ignore error and reconnect
};
}
}
fn eventLoop(fd: fd_t) !noreturn {
// ...
// if we detect disconntion
return error.Disconnected; // caller will connect again and restart the event loop
} |
Would using |
@dbandstra That seems to work to a point. The only issue I'm seeing is that it forces me to maintain the set of errors for each function that does this rather than being able to use inferred error sets. I've been finding that inferred error are a very nice feature. |
Hi, just a thought: Maybe it isn't so much work to detect return type !noreturn and then stop the compiler with a message? |
using the signature |
@nektro: What main signature would you suggest for a program that never should end (e.g. a a small program on a mcu for a room temperature sensor or a web server)? MasterQ32 explained also why !noreturn makes sense: (#3461 (comment)) |
either I use the former in my web server here https://github.com/nektro/aquila/blob/r21/src/main.zig#L27 |
|
Another (longer) way I ran into with specific error types: https://gist.github.com/Techcable/88808f0ff219e22f6bfd02ce1dbae0d9 |
When compiling the following program, the zig compiler will allocate a lot (> 24 GB) memory and will be killed by the OS. This is probably to some infinite loop.
The text was updated successfully, but these errors were encountered: