Newbie question:
How hard would it be for a text editor to highlight all lines that do or might allocate? Can they be known statically?
How hard would it be for a text editor to highlight all lines that do or might allocate? Can they be known statically?
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?”
fn maybe_alloc() -> Vec<usize> {
if collatz_conjecture_is_true() {
vec![42]
} else {
vec![]
}
}
fn main() {
let v = maybe_alloc(); // Does this allocate?
}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.