4 ms·
Looks like constant folding to me. What’s the difference exactly?
by e-dant 3y ago
Looks like constant folding to me. What’s the difference exactly?
- tuukkah 3y agoConstant folding means you calculate the result of an expression at compile time. In-place updating means you re-use the memory location of an earlier variable that's not needed anymore. Simple example in pseudo-C: BigInt increment_twice(const BigInt x) { const BigInt y = x + 1; const BigInt z = y + 1; return z; } There are no compile-time constant expressions that could be folded here. But since y is not used after z is assigned, we can re-use the memory location of y for the memory location of z. And if the caller is not using the argument after the function returns, the memory location of the argument can be used to store the return value. This means the function call does not need to allocate memory at all, not even on the stack.
- jimsimmons 3y agoOne is for stack allocated objects and the other for heap
- GrygrFlzr 3y agoDoes this make it more difficult to reason about the program memory usage over its lifetime, or can all potential cases be statically analyzed?
- tuukkah 3y agoSeems easy and clear: they introduce a keyword "fip" that you use to mark a function as being fully in-place, and they statically check it.
- kmill 3y agoThe paper is about trying to statically analyze this. As I understand it, fip-annotated functions are ones that are checked to neither allocate nor deallocate.