○
Planned This feature is planned but not yet implemented.
Glob patterns + |variant syntax - NOT just targets, also PROPERTY TESTING!
Code
// Test: Glob patterns combined with |variant syntax
//
// Variants are NOT just for different targets (GPU/CPU/WASM).
// They're for ANY alternative implementation:
//
// ~proc sort|zig(reference) - obviously correct, slow
// ~proc sort|zig(optimized) - fast, complex, needs verification
//
// This enables PROPERTY TESTING:
// For random inputs, reference == optimized
//
// Syntax forms:
// ~proc event|target - target variant (gpu, js, wasm)
// ~proc event|target(qualifier) - qualified variant (zig(reference))
// ~proc event.*|variant - glob + variant combined
// === USE CASE 1: Property Testing ===
~pub event sort { items: []i32 }
| sorted { items: []i32 }
// Reference implementation - simple, obviously correct
~proc sort|zig(reference) {
// Bubble sort - O(n²) but trivially correct
var result = items;
for (0..result.len) |i| {
for (i + 1..result.len) |j| {
if (result[j] < result[i]) {
const tmp = result[i];
result[i] = result[j];
result[j] = tmp;
}
}
}
return .{ .sorted = .{ .items = result } };
}
// Optimized implementation - complex, needs testing
~proc sort|zig(optimized) {
// Introsort with median-of-three pivot - fast but subtle
return .{ .sorted = .{ .items = std.sort.sort(items) } };
}
// Property test: both variants produce same output
// ~test(sort variants equivalent) {
// const input = random_array(1000);
// ~sort|zig(reference) = (items: input)
// | sorted ref |>
// sort|zig(optimized)(items: input)
// | sorted opt |> assert.eq(ref.items, opt.items)
// }
// === USE CASE 2: Target-Specific Implementations ===
~[transform]pub event image.transform.* {
event_name: []const u8,
pixels: []u8,
width: u32,
height: u32,
}
| transformed { pixels: []u8 }
~proc image.transform.*|cpu {
return .{ .transformed = .{ .pixels = pixels } };
}
~proc image.transform.*|gpu {
// GLSL compute shader dispatch
return .{ .transformed = .{ .pixels = pixels } };
}
~proc image.transform.*|wasm {
// WebAssembly-friendly, no SIMD
return .{ .transformed = .{ .pixels = pixels } };
}
// === USE CASE 3: Glob + Variant + Property Test ===
// ALL image transforms can be property-tested:
// ~test(image.transform.* cpu == gpu) {
// ~image.transform.blur|cpu = (pixels: test_image, ...)
// | transformed cpu_result |>
// image.transform.blur|gpu(pixels: test_image, ...)
// | transformed gpu_result |>
// assert.pixels_close(cpu_result.pixels, gpu_result.pixels, epsilon: 0.001)
// }