f is a global scope variable that can change during the lifetime of your program. Julia has to compile code that does not become invalid if you later set f=0.
You can later on add/redefine methods for the function f1 and julia is capable of tracking which compiled methods need to be invalidated / recompiled. Julia is not willing to track the same for global non-constant variables.