3 ms·
> I don't see what the halting problem has to do it. Is the following code safe? function_xyz(); let p = 0x1234 as *mut u32; p.write(5); It is sa
by adwn 6y ago
> I don't see what the halting problem has to do it.
Is the following code safe?
function_xyz();
let p = 0x1234 as *mut u32;
p.write(5);
It is safe iff function_xyz() does not terminate. To determine whether the code is safe in the general case, the Rust compiler would have to solve the halting problem.
Since that is impossible, the compiler uses a heuristic, which defaults to "not safe". It could use a better heuristic, like "Does function_xyz() contain an infinite loop? If yes, the code is safe." But that's of dubious value.
- moonchild 6y agoTreating otherwise unsafe code as safe because nontermination makes it dead doesn't strike me as particularly useful. Is there any other case where knowing the termination status of a function is helpful in proving safety?
- adwn 6y ago> Treating otherwise unsafe code as safe because nontermination makes it dead doesn't strike me as particularly useful. It doesn't matter whether it's useful or not. What matters is that the compiler can't determine whether it's safe or not.