5 ms·
It can't be addressed at compile time. That's the whole point of the uncomputability of the Halting Problem. The Zig compiler would have to have perfect knowle
by gavinhoward 4y ago
It can't be addressed at compile time. That's the whole point of the uncomputability of the Halting Problem.
The Zig compiler would have to have perfect knowledge of all functions that can be called anywhere. At compile time. Alan Turing proved that this is impossible.
In other words, Zig cannot address it. Ever.
- throwawaymaths 4y agoOk? The universe of all code that can be created by the zig compiler is strictly bounded for any given project at any given time, the halting problem does not apply. At worst, you can do an exhaustive search. The context that you're running the code in can ultimately be known, and the pointer can be set to the appropriate version based on calling context.
- gavinhoward 4y agoNo, you can't do an exhaustive search. Say you're a library author. You distribute pre-built library files. You've already lost because the compiler does not know your clients' code when it compiles your library. I am not kidding when I say it's provably impossible.
- throwawaymaths 4y ago"pre-built library files" are not a thing in zig right now, unless you use the c abi, which doesn't have async? Even supposing zig had prebuilding someday, you would probably have to extern it using async directly declared in the callconv (.async is an option in callconv) and so yes, the compiler would know. It's just that currently zig has a lot of "let the compiler figure out". Maybe that's what's making you uncomfortable? I'm pretty sure the zig compiler is finite and deterministic, so sophistry around the halting problem doesn't apply.
- gavinhoward 4y agoWat. The Zig compiler is finite and deterministic, yes, but that's not the problem. The problem is that user code is not finite nor deterministic. Even worse, Zig's compiler may be deterministic and finite, but the language is not, by far. In fact, the language is one of the most infinite languages in existence because just the type system is uncomputable! [1] (In this context, the word "undecidable" used by that source means "uncomputable".) If the type system is uncomputable, then the type system will never be able to resolve all uses of function pointers everywhere. The whole point of the Halting Problem is that you could have a finite and deterministic Turing Machine that runs other Turing Machines, and that finite and deterministic Turing Machine could run into situation where it never halts. I never say this when people ask (because most people don't understand), but the real reason I don't like Zig is because of how infinite the language is, starting with its uncomputable type system. This makes Zig one of the most unreasonable [2] programming languages in existence. If you don't believe me, ask the Zig team how they plan to solve this problem. Don't ask them if they plan to solve it; ask them how. Then if they reply, email me [3] with their proposed solution, and I will destroy it. I will do that no matter how many solutions they come up with because math says I will always win. But if they say they can't, will you believe them? [1]: https://3fx.ch/typing-is-hard.html#zig https://3fx.ch/typing-is-hard.html#zig [2]: https://fsharpforfunandprofit.com/posts/is-your-language-unreasonable/ https://fsharpforfunandprofit.com/posts/is-your-language-unr... [3]: https://gavinhoward.com/contact/ https://gavinhoward.com/contact/
- kristoff_it 4y ago> If you don't believe me, ask the Zig team how they plan to solve this problem. Don't ask them if they plan to solve it; ask them how. The Zig compiler has a counter that describes the maximum allowed amount of branching that the compiler can do while evaluating comptime code. The counter can be manually set to a higher value but all compilations will eventually fail if your comptime logic is too loopy. In practice the guideline is to not overuse comptime and instead create a dedicated build step for things like creating pre-computed value tables. > Then if they reply, email me [3] with their proposed solution, and I will destroy it. I will do that no matter how many solutions they come up with because math says I will always win. cringe