Adds `zig build bench` (bench/pp_bench.zig): lexes / preprocesses / prints
a file list in-process, best of N, files served from memory.
On the 4764-file, 13.1 MB DXC test corpus (Apple M-series, ReleaseFast,
interleaved A/B against the previous commit):
lex 13.3 -> 11.2 ms (-16%)
pp 49.7 -> 40.1 ms (-19%)
print 68.6 -> 53.2 ms (-22%)
Kept:
- src/front/scan.zig: portable @Vector scans (width from
std.simd.suggestVectorLength). Comment bodies are skipped with vector
searches; line-start tables are built from per-block newline bitmasks.
- An identifier character table for the (short) identifier scans.
- A line cursor for -P printing: O(1) per token instead of a binary search.
- A 1024-bit filter over macro names so most identifiers skip hashing;
the macro table is presized.
Tried and dropped (no gain): vector skipping of blank runs (2% slower;
gaps between tokens are mostly a single space) and fusing splice detection
into the newline scan.
- '#' not followed by a parameter in a function-like macro is an error
(object-like macros keep '#' literally), as in dxc.
- _Pragma("...") is destringized and handled like a #pragma line;
"#pragma once in main file" now warns instead of registering.
- GNU line markers (`# 40 "file" 1 3`, `#40`) work like #line.
- Macro-argument pre-expansion and #if parentheses are limited to 512
levels of nesting with a diagnostic, instead of overflowing the stack
(dxc segfaults at a few thousand levels).
- Quoted includes now search the directory of every file on the include
stack (innermost first) before -I, and angled includes search only -I
and the compiled-in headers, matching dxc. Angled lookups that only a
quoted include would find get dxc's "use quotes" diagnostic.
- #if evaluation short-circuits &&, || and ?:; division by zero in an
unevaluated operand is no longer an error (dxc accepts these).
- File contents are read once per path (with negative caching); each
inclusion still gets its own FileId so #line state stays per inclusion.
- Include-guarded files (#ifndef X / #if !defined(X) wrapping the whole
file) are not re-entered once X is defined. 2000 guarded includes:
65 ms -> 2 ms per run (dxc: 3 ms).
- Skipped lines are now skipped token by token, so "/*" inside a string
in an #if 0 block no longer swallows the #endif.
- Source manager (line splicing, UTF-8 BOM) and clang-style diagnostics.
- Lexer producing preprocessing tokens.
- Preprocessor modelled on clang's: object and function-like macros, #/##,
variadics with GNU comma elision, painted recursion blocking, nested
argument pre-expansion, #if/#elif expressions, #include with -I and
#pragma once, #line, #error/#warning, pass-through #pragma, and dxc's
predefined macros (__HLSL_VERSION, __SHADER_TARGET_*, __spirv__, ...).
- dxc's compiled-in HLSL headers (<dx/linalg.h>, <vk/spirv.h>, ...) are
vendored as data and used as the fallback for angled includes.
- -P/-Fi/-D/-I/-HV 2021/-enable-16bit-types options; profiles now cover
lib_, ms_, as_ and SM 6.0-6.11.
- `zig build oracle-pp`: token-for-token comparison with dxc -P. 2060 of
2060 corpus files dxc accepts match.
- Port of DXC's container hash (ComputeHashRetail); matches dxc-signed
containers on both padding paths.
- DXIL container reader/writer that signs its output.
- LLVM bitstream writer and a minimal LLVM 3.7 IR model that encodes types,
constants, functions, core instructions and metadata as bitcode.
- An empty compute shader that dxv accepts for SM 6.0 through 6.9.
- SPIR-V builder; the empty compute module passes spirv-val (Vulkan 1.0).
- `zig build oracle` runs these checks against the DXC build.