News for hackers. Stuff that matters.
Re:Dealing with Out-of-Memory Conditions in Rust by 1f60c on Saturday August 14, 2021 @09:05AM (#28180300)
I'm pretty sure catching this in all cases would involve solving the Halting Problem.
Re:Dealing with Out-of-Memory Conditions in Rust by oconnor663 on Saturday August 14, 2021 @09:51AM (#28180606)
If you're allowed to have false positives, it's not so hard. Like "this function allocates if A or B is true" just becomes "this function can allocate". It's not so different from finding functions that can panic.
Re:Dealing with Out-of-Memory Conditions in Rust by Xylakant on Saturday August 14, 2021 @11:06AM (#28181209)
I’m fairly certain that this does not require solving the halting problem. Fundamentally, every line of code can be transformed to the underlying code constructs, and those could be checked for allocations. Doing this in an efficient manner is probably hard, but certainly not impossible
Re:Dealing with Out-of-Memory Conditions in Rust by umanwizard on Sunday August 15, 2021 @12:07AM (#28186190)

    fn maybe_alloc() -> Vec<usize> {
        if collatz_conjecture_is_true() {
            vec![42]
        } else {
            vec![]
        }
    }

    fn main() {
        let v = maybe_alloc(); // Does this allocate?
    }
Re:Dealing with Out-of-Memory Conditions in Rust by wtetzner on Sunday August 15, 2021 @09:35AM (#28188662)
You would just assume it does. Really you want to detect all places that might allocate.
Re:Dealing with Out-of-Memory Conditions in Rust by umanwizard on Sunday August 15, 2021 @10:49AM (#28189196)
You are right. It’s definitely possible if you accept false positives.
Re:Dealing with Out-of-Memory Conditions in Rust by Waterluvian on Saturday August 14, 2021 @09:25AM (#28180420)
I think if we wanted a concrete answer you’d be right.

But I feel like a static analyzer could clearly identify “this line can allocate” just by knowing what language features can allocate. And for third party library methods “does this function have anything inside of it that could allocate?”

Re:Dealing with Out-of-Memory Conditions in Rust by wtetzner on Sunday August 15, 2021 @09:34AM (#28188657)
You can absolutely statically determine where allocations happen.

You can't know for sure if all of those places are reachable in a running program, but that's not necessary to solve this problem.