Okay, here's a solution. It's already implemented. Nice.
Now let me destroy it.
You said those compilations "fail"; I presume there's an error that kicks in.
In that case, then some valid Zig programs will be rejected, but your type system is now not technically Turing-complete. It's also less powerful; there are going to be things that Zig's type system cannot express.
But wait; that's a user-defined setting? This means that either users will increase that setting when they need to and run into the same problem, or follow your guideline:
> In practice the guideline is to not overuse comptime and instead create a dedicated build step for things like creating pre-computed value tables.
It sounds like a dedicated build step would be the better option than comptime, to be honest.
Also, if you step out to dedicated build steps, then the compiler no longer has complete visibility into that code when analyzing. At that point, the Halting Problem applies again.
Also, what do you do if a user needs to pass a function pointer to a C function? I presume they must use a sync function? If so, that seems like a direct application of the function colors definition; some functions are unusable in certain places. If not, I'd be interested in what Zig does there.