Hello,
I’ve got a few questions on comptime that I’m looking to gain a deeper/better understanding of:
-
The zig website says something like: “call any function at comptime”. Not to be pedantic but I feel like this is actually not true. For example if you invoke a function at comptime that makes use of system calls it won’t work correctly right? It’s my understanding that comptime functions need to largely be pure and deterministic.
-
It’s not entirely clear to me but is it true that “anytype” is a comptime evaluated marker? I was trying to create a struct that has a field that is a callback. The callback definition had one argument marked as “anytype” because I’m trying to support “a variadic style” argument. I was not able to do this because the compiler said something about it failing to evaluate the code at comptime. I tracked it down to “anytype” being the culprit here. I can’t seem to track down docs for “anytype”.
-
If it’s true that comptime functions must be pure. I still feel like it’s reasonable for example to want to use a hashmap (or other datastructure) at comptime. The problem though is that when you pass in an allocator if it’s internally using syscalls to grab some heap memory this is a problem. Is there a way to still make this work? I saw something online about the possibility of a comptime allocator for such purposes. What I’d like to do is have a function that can process some data using a datastructure, and build some kind of final, static result set at comptime. Then, at runtime my program uses the final result set.
Thanks to anyone who’s willing to shed some light!