Alex Kladov
d045eb7a4a
langref: make example more interesting.
...
As written, I think langref's example is actually a poor reason to use
`inline`.
If you have
if (foo(1200, 34) != 1234) {
@compileError("bad");
}
and you want to make sure that the call is executed at compile time, the
right way to fix it is to add comptime
if (comptime foo(1200, 34) != 1234) {
@compileError("bad");
}
and not to make the function `inline`. I _think_ that inlining functions
just to avoid `comptime` at a call-site is an anti-pattern. When the
reader sees `foo(123)` at the call-site, they _expect_ this to be a
runtime call, as that's the normal rule in Zig.
Inline is still necessary when you can't make the _whole_ call
`comptime`, because it has some runtime effects, but you still want
comptime-known result.
A good example here is
inline fn findImportPkgHashOrFatal(b: *Build, comptime asking_build_zig: type, comptime dep_name: []const u8) []const u8 {
from Build.zig, where the `b` argument is runtime, and is used for
side-effects, but where the result is comptime.
I don't know of a good small example to demonstrate the subtelty here,
so I went ahead with just adding a runtime print to `foo`. Hopefully
it'll be enough for motivated reader to appreciate the subtelty!
2025-07-14 16:20:33 +01:00
..
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2025-07-07 22:43:53 -07:00
2024-04-25 00:09:24 -07:00
2025-07-11 08:17:43 +02:00
2024-05-05 09:42:51 -04:00
2024-05-05 09:42:51 -04:00
2024-10-29 17:52:55 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-01-28 04:23:13 +00:00
2025-01-28 04:23:13 +00:00
2025-01-28 04:23:13 +00:00
2025-01-28 04:23:13 +00:00
2025-01-28 04:23:13 +00:00
2025-01-28 04:23:13 +00:00
2024-05-05 09:42:51 -04:00
2025-02-22 21:01:44 +00:00
2024-10-19 19:21:33 +01:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-03-05 03:01:43 +00:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-07-07 22:43:53 -07:00
2025-07-07 22:43:53 -07:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2025-07-14 16:20:33 +01:00
2024-08-28 08:39:59 +01:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-02-22 21:01:44 +00:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-04-15 19:19:23 -07:00
2025-02-22 21:01:44 +00:00
2024-04-25 00:09:24 -07:00
2024-08-28 08:39:59 +01:00
2024-05-05 09:42:51 -04:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-07-01 23:03:15 +02:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2025-02-22 21:01:44 +00:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-05-10 13:56:01 -07:00
2024-04-25 00:09:24 -07:00
2024-06-08 12:39:11 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-05-05 09:42:51 -04:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-07-09 14:25:42 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-03-05 03:01:43 +00:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-08-28 08:39:59 +01:00
2024-07-21 01:26:21 -07:00
2024-08-28 08:39:59 +01:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-08-28 08:39:59 +01:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2025-05-30 01:11:00 +00:00
2025-06-06 23:42:14 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-02-22 21:01:44 +00:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-08-28 08:39:59 +01:00
2024-05-05 09:42:51 -04:00
2024-05-05 09:42:51 -04:00
2024-08-28 08:39:59 +01:00
2024-04-25 00:09:24 -07:00
2025-06-01 12:10:57 +01:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-03-26 11:52:52 +01:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-07-11 08:17:43 +02:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-03-05 03:01:43 +00:00
2024-04-25 00:09:24 -07:00
2024-08-28 08:39:59 +01:00
2024-04-25 00:09:24 -07:00
2024-10-12 20:59:12 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-07-15 18:18:38 +00:00
2024-08-28 08:39:59 +01:00
2024-07-29 16:07:12 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-08-14 10:29:45 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-02-22 21:01:44 +00:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-07-21 00:32:50 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-03-06 07:26:19 +01:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-11-13 15:35:16 -08:00
2024-09-12 20:06:49 -07:00
2024-09-12 20:06:49 -07:00
2025-02-09 11:46:15 +00:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-09-10 20:28:40 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-06-08 12:39:11 -07:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-08-28 08:39:59 +01:00
2024-08-28 08:39:59 +01:00
2024-08-28 08:39:59 +01:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2025-02-22 21:01:44 +00:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-05-05 09:42:51 -04:00
2024-04-25 00:09:24 -07:00
2024-04-25 00:09:24 -07:00
2024-09-12 16:01:23 +01:00
2024-09-12 16:01:23 +01:00
2024-04-25 00:09:24 -07:00