-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Tailstrict causes stack overflow #115
Comments
Thank you for the report! Do you build jrsonnet in the release mode? Which version of jrsonnet do you use? Can you run this code with For me, this code fails with SIGABRT in debug mode (Due to stack overflow, and this is ok, as most stack size optimizations are targeted for the release mode) and works correctly in release on x86_64-linux-gnu, jrsonnet 0.5.0-pre9, rustc 1.71.0-nightly 2023-05-06. |
It was release mode, but it still broke. After a LOT more looking around, I've managed to reduce it to: local new_visit_thing(
value
) =
local recurse(value) =
recurse(value) tailstrict;
recurse(value);
new_visit_thing("") It has something to do with |
So it was an SIGABRT, not a SEGFAULT? tailstrict evaluates function without counting against stack depth limit so that it may cause a stack overflow in any jsonnet implementation (except C++ one, which implements tail-call optimization correctly) by design. The problem with Rust is an inability to format os stack overflow messages correctly: rust-lang/rust#51405 I'll think about providing some handling for this error, but for now, it is better to resort to using os-stack in cases where optimising code for stack size usage is impossible. Maybe I should adjust some things to make this code fail as with You may also solve this issue by switching from the manually-written reduce function to std.foldl/std.foldr, which are written in native, and will not overflow the stack. It is always better to use native functions where possible in jsonnet. |
While this isn't looking good, this is just how tailstrict works, this is the reason it isn't even documented in jrsonnet docs. While it is possible to implement proper TCO, both go-jsonnet and sjsonnet doesn't implement it, and even with partial TCO (As I implemented in #121) it would be still possible to overflow the stack. |
I can provide an example that reproduces the segfault, but for the life of me, I have no idea how to start looking into it.
Let me know if it works for you, or if I can provide any other info.
Crashing Jsonnet code
The text was updated successfully, but these errors were encountered: