Putting aside issues of compiler implementation and language design, what you re asking for is provably undecidable (unless you only care about detecting 100% identical programs). Deciding if two programs compute the same function is equivalent to solving the halting problem. This is a classic consequence of Rice s Theorem: Any "interesting" property of Turing machines is undecidable, where "interesting" just means that it s true for some machines and false for others.
Just for fun, here s the proof. Assume we can create a function to decide if two blocks are equivalent, called EQ(b1, b2). Now we ll use that function to solve the halting problem. We create a new function HALT(M, I) that tells us if Turing machine M will halt on input I like so:
BOOL HALT(M,I) {
return EQ(
^(int) {return 0;},
^(int) {M(I); return 0;}
);
}
If M(I) halts then the blocks are equivalent, so HALT(M,I) returns YES. If M(I) doesn t halt then the blocks are not equivalent, so HALT(M,I) returns NO. Note that we don t have to execute the blocks -- our hypothetical EQ function can compute their equivalence just by looking at them.
We have now solved the halting problem, which we know is not possible. Therefore, EQ cannot exist.