Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
@tailcall annotation doesn't show warning for non-tailcall #7856
Original bug ID: 7856
When calling loop inside List.iter the compiler doesn't recognize that this call is not a tailcall, even when annotated with the @tailcall attribute.
Steps to reproduce
Reproduced on OCaml 4.06.1 and OCaml 4.07.0
Comment author: @edwintorok
Fair enough, what we actually wanted to know here is: is this recursive call guaranteed to not consume more stack space (including stack space already consumed by its immediate callers)?
Would be nice if there was another attribute that checked the tailcall property of all callers up to the recursive function itself: that might've helped catch bugs like this (we could manually add those annotations, but it would be error-prone when the code around it changes). This might not be easy to do, but if such an attribute is added it could err on the side of caution: if it cannot prove that the call doesn't consume more stack space, then it warns.
I think this would even work for recursive calls in Lwt, e.g.:
which would be equivalent to:
(fun v -> (loop[@recnostack]) v) --> OK, tail position, adds [@recnostack] annotation to (>>=) internally
(Of course you can still have an infinite loop that doesn't overflow the stack, but that is outside of scope for a compiler warning)
What do you think?
Feel free to close this issue, perhaps a warning in the documentation would suffice: