authorgravatar for contact@robbyzambito.meRobby Zambito <contact@robbyzambito.me> 2026-01-27 16:42:58-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-03-03 21:10:30+01:00
logd2db1d45f1651d25c779651378b002b027e5f8e4
treea8699156951aaf135970fda38874744364802203
parent2d88a5a10334bddf3bd0b8bc98744ea6f239ce3a

fix: inline to propagate comptime-ness to call site

See conversation at: https://ziggit.dev/t/why-is-the-comptime-keyword-needed-in-this-inline-for-loop-condition/14090

2 files changed, 3 insertions(+), 2 deletions(-)

lib/std/enums.zig+2-1
...@@ -42,6 +42,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def...@@ -42,6 +42,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def
42/// The result array is in the same order as the input.42/// The result array is in the same order as the input.
43pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumField) []const E {43pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumField) []const E {
44 comptime {44 comptime {
45 @setEvalBranchQuota(@typeInfo(E).@"enum".fields.len + eval_branch_quota_cushion);
45 var result: [fields.len]E = undefined;46 var result: [fields.len]E = undefined;
46 for (&result, fields) |*r, f| {47 for (&result, fields) |*r, f| {
47 r.* = @enumFromInt(f.value);48 r.* = @enumFromInt(f.value);
...@@ -53,7 +54,7 @@ pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumFi...@@ -53,7 +54,7 @@ pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumFi
5354
54/// Returns the set of all named values in the given enum, in55/// Returns the set of all named values in the given enum, in
55/// declaration order.56/// declaration order.
56pub fn values(comptime E: type) []const E {57pub inline fn values(comptime E: type) []const E {
57 return comptime valuesFromFields(E, @typeInfo(E).@"enum".fields);58 return comptime valuesFromFields(E, @typeInfo(E).@"enum".fields);
58}59}
5960
src/codegen/x86_64/CodeGen.zig+1-1
...@@ -177113,7 +177113,7 @@ fn airBr(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -177113,7 +177113,7 @@ fn airBr(self: *CodeGen, inst: Air.Inst.Index) !void {
177113}177113}
177114177114
177115fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {177115fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
177116 @setEvalBranchQuota(1_100);177116 @setEvalBranchQuota(1_100 + @typeInfo(Mir.Inst.Fixes).@"enum".fields.len);
177117 const pt = self.pt;177117 const pt = self.pt;
177118 const zcu = pt.zcu;177118 const zcu = pt.zcu;
177119 const unwrapped_asm = self.air.unwrapAsm(inst);177119 const unwrapped_asm = self.air.unwrapAsm(inst);