logoalt Hacker News

rienbdjtoday at 8:25 AM1 replyview on HN

Question for Zig users:

Can comptime blow up compile times? Does it have arbitrary cutoffs like C++ template depth?


Replies

resonanceltoday at 10:11 AM

You can think of comptime (as of zig 0.16) as an interpreter that evaluates code with very limited optimization. So yes, naive use of comptime can definitely grind compilation to a halt.

Zig tackles the halting problem a bit differently by putting the evaluation cutoff in userspace through the compiler builtin function `@setEvalBranchQuota`. You bump up the quota as you see fit.