-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Inconsistent recursive fn call elimination #125698
Comments
This seems to be a duplicate of #102952 and many others like that one. |
Weirdly enough, I tried this with #112788 #![feature(explicit_tail_calls)]
const fn inf() -> ! {
become inf()
}
fn main() {
inf();
} It still overflows the stack! Even though the (unofficial) docs claim it must not. I've been reading about the RFC, and it seems the syntax is the only thing that got implemented |
interesting. |
The llvm ir correctly contains ; playground::inf
; Function Attrs: nofree noreturn nosync nounwind nonlazybind memory(none) uwtable
define internal fastcc void @_ZN10playground3inf17hbbe49911b1985149E() unnamed_addr #3 {
start:
; call playground::inf
tail call fastcc void @_ZN10playground3inf17hbbe49911b1985149E() #7
unreachable
} |
weird. |
In my view, the code behavior initially mentioned in the issue is reasonable. I want to know why you expect it won't overflow the stack, |
The behavior in #125698 (comment) is definitively wrong. It uses |
What I actually find surprising is that the compiler was eager to obliterate
I know, I just wanted to "add emphasis" (I'm unsure if this is the correct terminology?) |
Although both will result in a stack overflow at runtime,
I think maybe your meaning is similar. |
Correct! It makes sense. But (I may be getting into philosophical territory here) an OOM panic could be considered a side-effect, at least from the POV of a system (doesn't apply to From the POV of a Rust program, OOM panics can't exist (in the same way
Thanks for explaining! I just had some problems communicating my thoughts. My intention was to add "emphasis" both for humans and |
That's not really true at all. We have a defined set of behaviors in response to out-of-memory errors. The language has semantics for allocations, and it has a semantic for failing to allocate (some of the APIs represent this as returning nullptr, some of them as Result). You are referring to the behavior of very specific datatypes which effectively
|
Indeed, I've just read about
I should've said something along the lines of "unreachable code", since a guaranteed panic is equivalent to |
|
I tried this code:
I expected to see this happen: prints
"✅"
fast and successfully, then hangs in an infinite loop.Instead, this happened: prints
"✅"
fast and panics withstderr
:It seems commenting-out the attributes is no-op here.
Meta
https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=ed0941cd328e49d8737fdff01cd4a4aa
rustc --version --verbose
:Backtrace
Apologies in advance, if this issue is a dupe. I tried my best to find similar ones
The text was updated successfully, but these errors were encountered: