You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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, inline(always) doesn't guarantee that inline will definitely occur.
What I actually find surprising is that the compiler was eager to obliterate deep(usize::MAX) as if it was never there, but inf() didn't get the same similar treatment.
inline(always) doesn't guarantee that inline will definitely occur.
I know, I just wanted to "add emphasis" (I'm unsure if this is the correct terminology?)
What I actually find surprising is that the compiler was eager to obliterate deep(usize::MAX) as if it was never there, but inf() didn't get the same similar treatment.
Although both will result in a stack overflow at runtime, deep is a non-infinite recursive function without side effects, which the compiler can completely eliminate.
inline(always) doesn't guarantee that inline will definitely occur.
I know, I just wanted to "add emphasis" (I'm unsure if this is the correct terminology?)
I think maybe your meaning is similar. inline(always) means to inline whenever possible. inline should adjust the threshold for the inlining cost.
deep is a non-infinite recursive function without side effects
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 no_std lib crates).
From the POV of a Rust program, OOM panics can't exist (in the same way ! is a "never type") so Rust as a lang is allowed to "ignore" them. But rustc should know that a call-stack cannot have the same size as the entire address-space of any target-triple (except Harvard machines), otherwise the program itself cannot fit in memory, so an OOM panic should happen anyways.
inline should adjust the threshold for the inlining cost.
Thanks for explaining! I just had some problems communicating my thoughts. My intention was to add "emphasis" both for humans and rustc, if that makes sense 😅
From the POV of a Rust program, OOM panics can't exist (in the same way ! is a "never type") so Rust as a lang is allowed to "ignore" them.
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 .unwrap() those Results. No one says "unwrap() can't exist". Instead, things that don't exist in Rust include the set of, e.g.
dereferenced null pointers
individual allocations larger than isize::MAX bytes
two active &mut T to the same T
Reacted by Ricardo Fernández Serrata and Yerkebulan Tulibergenov
I've been reading about the RFC, and it seems the syntax is the only thing that got implemented
This example now no longer overflows. We have a test for the bounded variant here, I'll make a PR to check the codegen for the infinite loop, it also no longer grows the stack: https://godbolt.org/z/7eKbnePx5
Activity
workingjubilee commentedon May 29, 2024
This seems to be a duplicate of #102952 and many others like that one.
Rudxain commentedon May 29, 2024
Weirdly enough, I tried this with #112788
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
workingjubilee commentedon May 29, 2024
interesting.
bjorn3 commentedon May 29, 2024
The llvm ir correctly contains
workingjubilee commentedon May 29, 2024
weird.
dianqk commentedon May 29, 2024
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,
inline(always)doesn't guarantee that inline will definitely occur.bjorn3 commentedon May 29, 2024
The behavior in #125698 (comment) is definitively wrong. It uses
becomewhich should force a tail call, yet doesn't get tail called.the8472 commentedon May 29, 2024
The tail call feature (#112788) is still in progress, e.g. #113128 has not been merged yet.
Rudxain commentedon May 29, 2024
What I actually find surprising is that the compiler was eager to obliterate
deep(usize::MAX)as if it was never there, butinf()didn't getthe samesimilar treatment.I know, I just wanted to "add emphasis" (I'm unsure if this is the correct terminology?)
WaffleLapkin commentedon May 29, 2024
Also note that #113128 by itself won't implement the feature correctly either, since it does not include llvm lowering.
dianqk commentedon May 31, 2024
Although both will result in a stack overflow at runtime,
deepis a non-infinite recursive function without side effects, which the compiler can completely eliminate.I think maybe your meaning is similar.
inline(always)means to inline whenever possible.inlineshould adjust the threshold for the inlining cost.Rudxain commentedon May 31, 2024
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
no_stdlib crates).From the POV of a Rust program, OOM panics can't exist (in the same way
!is a "never type") so Rust as a lang is allowed to "ignore" them. Butrustcshould know that a call-stack cannot have the same size as the entire address-space of any target-triple (except Harvard machines), otherwise the program itself cannot fit in memory, so an OOM panic should happen anyways.Thanks for explaining! I just had some problems communicating my thoughts. My intention was to add "emphasis" both for humans and
rustc, if that makes sense 😅workingjubilee commentedon Jun 1, 2024
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
.unwrap()those Results. No one says "unwrap()can't exist". Instead, things that don't exist in Rust include the set of, e.g.isize::MAXbytes&mut Tto the sameTRudxain commentedon Jun 1, 2024
Indeed, I've just read about
try_reserve, and this crate which hastry_push(I wish that was instd)I should've said something along the lines of "unreachable code", since a guaranteed panic is equivalent to
FnOnce() -> !. Thanks for the correction 👍programmerjake commentedon Jun 13, 2024
tailmeans it may or may not become a tail call; to require LLVM to generate a tail call, you need to usemusttail call ...insteadfolkertdev commentedon Nov 13, 2025
This example now no longer overflows. We have a test for the bounded variant here, I'll make a PR to check the codegen for the infinite loop, it also no longer grows the stack: https://godbolt.org/z/7eKbnePx5
Rollup merge of rust-lang#148907 - folkertdev:tail-call-infinite-recu…
Rollup merge of rust-lang#148907 - folkertdev:tail-call-infinite-recu…
Rollup merge of rust-lang#148907 - folkertdev:tail-call-infinite-recu…
Unrolled build for #148907