I want to know how do I find source for those functions to read them since LSP doesn’t go into it
(post deleted by author)
I only know of the builtin functions be listed online, or in your installed zig directory under doc/langref.html
This is a common question. The builtin functions aren’t functions, per se. Instead they’re essentially just language syntax which looks like function calls. So for example how @addWithOverflow works is a lot like how + works, it’s the compiler outputting machine code. Other builtins are implemented in different parts across the compiler. This is why some builtins get away with special syntax rules that typical functions don’t, such as @min being varargs, or @import only taking string literals. So if you really want to dive into things, you need to dive into the compiler. The language reference covers most of what anyone will ever need to know.
@builtin functions exist for one of two reasons:
- They do something that cannot be expressed with regular zig code alone:
@import()@This()@Vector()
- They do a simple operation, that can be lowered to 0 or 1 instructions on most targets, but does not justify having a dedicated symbol (+ - * /). Having them as a
@builtinis easier for the compiler to process than if they were in the standard library.@ctz()@atomicStore()@truncate()
They don’t have source code, in the same way that = and const don’t have source code.
If you want to know more about how they work under the hood, I suggest compiling test programs and inspecting the assembly code they produce.