/zig-comptime
Zig comptime skill for compile-time evaluation and metaprogramming. Use when using comptime parameters, comptime types, generics via anytype, comptime reflection with @typeInfo, or metaprogramming patterns that replace C++ templates. Activates on queries about Zig comptime,
$ npx -y skills add mohitmishra786/low-level-dev-skills --skill zig-comptime --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/zig-comptime
Context preview
The summary Claude sees to decide when to auto-load this skill.
Zig comptime skill for compile-time evaluation and metaprogramming. Use when using comptime parameters, comptime types, generics via anytype, comptime reflection with @typeInfo, or metaprogramming patterns that replace C++ templates. Activates on queries about Zig comptime,
SKILL.md
zig-comptime.SKILL.mdname: zig-comptime
description: Zig comptime skill for compile-time evaluation and metaprogramming. Use when using comptime parameters, comptime types, generics via anytype, comptime reflection with @typeInfo, or metaprogramming patterns that replace C++ templates. Activates on queries about Zig comptime, compile-time evaluation, Zig generics, anytype, @typeInfo, comptime types, or Zig metaprogramming.
Zig comptime
Purpose
Guide agents through Zig's `comptime` system: compile-time function evaluation, comptime type parameters, generics via `anytype`, type reflection with `@typeInfo`, and metaprogramming patterns that replace C++ templates and macros.
Triggers
- "How does comptime work in Zig?"
- "How do I write a generic function in Zig?"
- "How do I use @typeInfo for reflection?"
- "How do I generate code at compile time in Zig?"
- "How does anytype work in Zig?"
- "How do Zig generics compare to C++ templates?"
Workflow
1. comptime basics
// comptime keyword forces compile-time evaluation
const x: comptime_int = 42; // comptime integer (arbitrary precision)
const y: comptime_float = 3.14159; // comptime float (arbitrary precision)
// comptime block — runs at compile time
comptime {
const val = fibonacci(20); // computed at compile time
std.debug.assert(val == 6765); // compile-time assertion
}
// comptime parameter — caller must provide a comptime-known value
fn makeArray(comptime T: type, comptime n: usize) [n]T {
return [_]T{0} ** n; // array of n zeros of type T
}
const arr = makeArray(f32, 8); // [8]f32 computed at compile time2. Generic functions with comptime type parameters
const std = @import("std");
// Generic max function — T must be comptime-known
fn max(comptime T: type, a: T, b: T) T {
return if (a > b) a else b;
}
// Usage: T is inferred from arguments or specified explicitly
const r1 = max(i32, 3, 7); // 7
const r2 = max(f64, 2.5, 1.8); // 2.5
// Generic Stack data structure
fn Stack(comptime T: type) type {
return struct {
items: []T,
top: usize,
allocator: std.mem.Allocator,
const Self = @This();
pub fn init(allocator: std.mem.Allocator) !Self {
return Self{
.items = try allocator.alloc(T, 64),
.top = 0,
.allocator = allocator,
};
}
pub fn push(self: *Self, value: T) void {
self.items[self.top] = value;
self.top += 1;
}
pub fn pop(self: *Self) ?T {
if (self.top == 0) return null;
self.top -= 1;
return self.items[self.top];
}
pub fn deinit(self: *Self) void {
self.allocator.free(self.items);
}
};
}
// Usage: Stack(i32) and Stack(f64) are distinct types
var int_stack = try Stack(i32).init(allocator);
defer int_stack.deinit();
int_stack.push(42);3. anytype — duck-typed comptime parameters
`anytype` accepts any type and the compiler infers it at the call site:
// anytype: function works for any type with .len field
fn printLength(thing: anytype) void {
std.debug.print("Length: {}\n", .{thing.len});
}
printLength("hello"); // string literal — works
printLength([_]u8{1, 2, 3}); // array — works
printLength(std.ArrayList(u32){}); // ArrayList — works
// anytype with comptime checks for better errors
fn serialize(writer: anytype, value: anytype) !void {
// Verify writer has write method at comptime
if (!@hasDecl(@TypeOf(writer), "write")) {
@compileError("writer must have a write method");
}
try writer.write(std.mem.asBytes(&value));
}
// anytype in struct methods (used throughout std library)
pub fn format(
self: MyType,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype, // any writer: file, buffer, etc.
) !void {
try writer.print("{} {}", .{self.x, self.y});
}4. Type reflection with @typeInfo
`@typeInfo` returns a tagged union describing a type's structure at comptime:
const std = @import("std");
const TypeInfo = std.builtin.Type;
fn printTypeInfo(comptime T: type) void {
const info = @typeInfo(T);
switch (info) {
.Int => |i| std.debug.print("Int: {} bits, {s}\n",
.{i.bits, @tagName(i.signedness)}),
.Float => |f| std.debug.print("Float: {} bits\n", .{f.bits}),
.Struct => |s| {
std.debug.print("Struct with {} fields:\n", .{s.fields.len});
inline for (s.fields) |field| {
std.debug.print(" {s}: {}\n", .{field.name, field.type});
}
},
.Enum => |e| {
std.debug.print("Enum with {} values:\n", .{e.fields.len});
inline for (e.fields) |field| {
std.debug.print(" {s} = {}\n", .{field.name, field.value});
}
},
.Optional => |o| std.debug.print("Optional({s})\n", .{@typeName(o.child)}),
.Array => |a| std.debug.print("[{}]{s}\n", .{a.len, @typeName(a.child)}),
else => std.debug.print("Other type: {s}\n", .{@typeName(T)}),
}
}
// Usage at comptime
comptime { printTypeInfo(u32); } // Int: 32 bits, unsigned
comptime { printTypeInfo(f64); } // Float: 64 bits5. Comptime-generated code patterns
// Generate a lookup table at comptime
const sin_table = blk: {
const N = 256;
var table: [N]f32 = undefined;
@setEvalBranchQuota(10000); // increase for expensive comptime eval
for (0..N) |i| {
const angle = @as(f32, @floatFromInt(i)) * (2.0 * std.math.pi / N);
table[i] = @sin(angle);
}
break :blk table;
};
// Comptime string processing
fn upperCase(comptime s: []const u8) [s.len]u8 {
var result: [s.len]u8 = undefined;
for (s, 0..) |c, i| {
result[i] = std.ascii.toUpper(c);
}
return result;
}
const HELLORead more
name: zig-comptime description: Zig comptime skill for compile-time evaluation and metaprogramming. Use when using comptime parameters, comptime types, generics via anytype, comptime reflection with @typeInfo, or metaprogramming patterns that replace C++ templates. Activates on queries about Zig comptime, compile-time evaluation, Zig generics, anytype, @typeInfo, comptime types, or Zig metaprogramming.
Zig comptime
Purpose
Guide agents through Zig's `comptime` system: compile-time function evaluation, comptime type parameters, generics via `anytype`, type reflection with `@typeInfo`, and metaprogramming patterns that replace C++ templates and macros.
Triggers
- "How does comptime work in Zig?"
- "How do I write a generic function in Zig?"
- "How do I use @typeInfo for reflection?"
- "How do I generate code at compile time in Zig?"
- "How does anytype work in Zig?"
- "How do Zig generics compare to C++ templates?"
Workflow
1. comptime basics
// comptime keyword forces compile-time evaluation
const x: comptime_int = 42; // comptime integer (arbitrary precision)
const y: comptime_float = 3.14159; // comptime float (arbitrary precision)
// comptime block — runs at compile time
comptime {
const val = fibonacci(20); // computed at compile time
std.debug.assert(val == 6765); // compile-time assertion
}
// comptime parameter — caller must provide a comptime-known value
fn makeArray(comptime T: type, comptime n: usize) [n]T {
return [_]T{0} ** n; // array of n zeros of type T
}
const arr = makeArray(f32, 8); // [8]f32 computed at compile time2. Generic functions with comptime type parameters
const std = @import("std");
// Generic max function — T must be comptime-known
fn max(comptime T: type, a: T, b: T) T {
return if (a > b) a else b;
}
// Usage: T is inferred from arguments or specified explicitly
const r1 = max(i32, 3, 7); // 7
const r2 = max(f64, 2.5, 1.8); // 2.5
// Generic Stack data structure
fn Stack(comptime T: type) type {
return struct {
items: []T,
top: usize,
allocator: std.mem.Allocator,
const Self = @This();
pub fn init(allocator: std.mem.Allocator) !Self {
return Self{
.items = try allocator.alloc(T, 64),
.top = 0,
.allocator = allocator,
};
}
pub fn push(self: *Self, value: T) void {
self.items[self.top] = value;
self.top += 1;
}
pub fn pop(self: *Self) ?T {
if (self.top == 0) return null;
self.top -= 1;
return self.items[self.top];
}
pub fn deinit(self: *Self) void {
self.allocator.free(self.items);
}
};
}
// Usage: Stack(i32) and Stack(f64) are distinct types
var int_stack = try Stack(i32).init(allocator);
defer int_stack.deinit();
int_stack.push(42);3. anytype — duck-typed comptime parameters
`anytype` accepts any type and the compiler infers it at the call site:
// anytype: function works for any type with .len field
fn printLength(thing: anytype) void {
std.debug.print("Length: {}\n", .{thing.len});
}
printLength("hello"); // string literal — works
printLength([_]u8{1, 2, 3}); // array — works
printLength(std.ArrayList(u32){}); // ArrayList — works
// anytype with comptime checks for better errors
fn serialize(writer: anytype, value: anytype) !void {
// Verify writer has write method at comptime
if (!@hasDecl(@TypeOf(writer), "write")) {
@compileError("writer must have a write method");
}
try writer.write(std.mem.asBytes(&value));
}
// anytype in struct methods (used throughout std library)
pub fn format(
self: MyType,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype, // any writer: file, buffer, etc.
) !void {
try writer.print("{} {}", .{self.x, self.y});
}4. Type reflection with @typeInfo
`@typeInfo` returns a tagged union describing a type's structure at comptime:
const std = @import("std");
const TypeInfo = std.builtin.Type;
fn printTypeInfo(comptime T: type) void {
const info = @typeInfo(T);
switch (info) {
.Int => |i| std.debug.print("Int: {} bits, {s}\n",
.{i.bits, @tagName(i.signedness)}),
.Float => |f| std.debug.print("Float: {} bits\n", .{f.bits}),
.Struct => |s| {
std.debug.print("Struct with {} fields:\n", .{s.fields.len});
inline for (s.fields) |field| {
std.debug.print(" {s}: {}\n", .{field.name, field.type});
}
},
.Enum => |e| {
std.debug.print("Enum with {} values:\n", .{e.fields.len});
inline for (e.fields) |field| {
std.debug.print(" {s} = {}\n", .{field.name, field.value});
}
},
.Optional => |o| std.debug.print("Optional({s})\n", .{@typeName(o.child)}),
.Array => |a| std.debug.print("[{}]{s}\n", .{a.len, @typeName(a.child)}),
else => std.debug.print("Other type: {s}\n", .{@typeName(T)}),
}
}
// Usage at comptime
comptime { printTypeInfo(u32); } // Int: 32 bits, unsigned
comptime { printTypeInfo(f64); } // Float: 64 bits5. Comptime-generated code patterns
// Generate a lookup table at comptime
const sin_table = blk: {
const N = 256;
var table: [N]f32 = undefined;
@setEvalBranchQuota(10000); // increase for expensive comptime eval
for (0..N) |i| {
const angle = @as(f32, @floatFromInt(i)) * (2.0 * std.math.pi / N);
table[i] = @sin(angle);
}
break :blk table;
};
// Comptime string processing
fn upperCase(comptime s: []const u8) [s.len]u8 {
var result: [s.len]u8 = undefined;
for (s, 0..) |c, i| {
result[i] = std.ascii.toUpper(c);
}
return result;
}
const HELLOA curated suite of AI agent skills for systems and low-level programming — C/C++, Rust, Zig, GPU, bare-metal firmware, Linux kernel/driver development, computer architecture, compiler internals, HPC, and more.
Repo: mohitmishra786/low-level-dev-skills
Other skills on low-level-dev-skills.
- /custom-allocators
Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator,
Open skill - /numa-programming
NUMA programming skill for multi-socket memory locality. Use when detecting NUMA topology, binding processes with numactl, using libnuma API, building NUMA-aware data structures, or measuring remote access penalties. Activates on queries about numactl, libnuma, NUMA topology,
Open skill - /af-xdp
AF_XDP skill for high-performance XDP sockets. Use when creating AF_XDP sockets, configuring UMEM and XSK rings, XDP_REDIRECT programs, copy vs zero-copy mode, or comparing with DPDK. Activates on queries about AF_XDP, xsk_umem, XDP_REDIRECT, libbpf xsk, or zero-copy XDP.
Open skill - /dpdk
DPDK skill for userspace packet I/O. Use when initializing EAL, configuring PMD drivers, using mbuf pools and rte_ring, setting up huge pages, RSS, or testpmd validation. Activates on queries about DPDK, EAL, rte_eth_rx_burst, hugepages, PMD, or testpmd.
Open skill - /io-uring
io_uring skill for Linux async I/O. Use when building high-performance servers with liburing, multi-shot operations, provided buffers, fixed files, zero-copy send, or tokio-uring. Activates on queries about io_uring, SQE/CQE, liburing, IORING_OP_PROVIDE_BUFFERS, or io_uring vs
Open skill - /adc-dac-baremetal
Bare-metal ADC and DAC skill. Use when configuring analog sampling, DMA-driven ADC, calibration, or DAC output on MCUs. Activates on queries about ADC bare-metal, sampling time, DMA ADC, or DAC channel setup.
Open skill

