2 ms·
Zig basically does plan to disallow recursion: https://github.com/ziglang/zig/issues/1006#issuecomment-534660820 https://github.com/ziglang/zig/issues/1006#issu
by csande17 4y ago
Zig basically does plan to disallow recursion: https://github.com/ziglang/zig/issues/1006#issuecomment-534660820 https://github.com/ziglang/zig/issues/1006#issuecomment-5346...
More specifically, it'll force you to allocate memory for your recursive functions on the heap (and thus handle the possible resulting OOM condition).
- pcwalton 4y agoDo you disallow function pointers/closures/virtual methods too, since these can be used to smuggle recursion into the semantics without the compiler being able to statically detect it? You'd have to heap allocate every call to a function pointer, which would be very slow (see how much benefit apps get from PGO which for a long time mostly amounted to optimizing virtual calls).
- csande17 4y ago> Do you disallow function pointers/closures/virtual methods too [...] Maybe? Of these features, AFAIK Zig only has function pointers, and they already don't seem to interact very well with other parts of the language. I wouldn't be surprised if they restricted them to comptime-only usage or made "how much stack space does the function need" part of the pointer type or something.