Commit Graph

35033 Commits

Author SHA1 Message Date
e275e9bb76 Replace copy-based Air export with zero-copy in-place comparison
Pass C-side SemaFuncAir arrays into zig_compare_air so the callback
can compare Air tags/datas/extra directly against the Zig compiler's
in-memory arrays, eliminating 4 heap allocations + 3 memcpys per
function.

Fix the early-return guard in PerThread.zig to also check
verbose_air_callback, so the callback fires even when
enable_debug_extensions is false (ReleaseFast).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 17:57:58 +00:00
59b11a3be4 Replace text-based Air comparison with raw array memcmp
Export raw Air arrays (tags, datas, extra) from the Zig compiler via a
RawAirCallback on Compilation, and memcmp them against C-produced arrays
instead of comparing formatted text output. This is more robust (catches
any byte-level divergence) and eliminates the need for the C-side text
formatter.

- Add RawAirCallback type and field to Compilation
- Rewrite src/verbose_air.zig: raw array export instead of text capture
- Update stage0 tests to use compareAir with expectEqualSlices
- Delete stage0/verbose_air.{c,h} (no longer needed)
- Remove verbose_air.c/h from build.zig file lists

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 16:52:58 +00:00
9adc6fb5fe Replace structural Air/IP comparison with text-based dumpers
Remove all @import("zig_internals") from stage0/ so that test_obj
compilation is independent of the Zig compiler (~6min). The sema
comparison now uses text-based dumpers:

- Zig side (src/verbose_air.zig): compiles source through the full Zig
  pipeline, captures verbose_air output, exports zig_dump_air() as a C
  function. Compiled as a separate dumper_obj that is cached
  independently.

- C side (stage0/verbose_air.c): formats C Air structs to text in the
  same format as Zig's Air/print.zig.

Changing stage0 code no longer triggers Zig compiler recompilation:
C compile + cached test_obj + cached dumper + link = seconds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 14:48:40 +00:00
47c9dd8636 stages_test: full per-function Air comparison between C and Zig sema
Replace the count-only check with a faithful textual comparison,
analogous to how expectEqualZir compares AstGen output:

- Export Zcu from test_exports so tests can construct a PerThread
- Parse Zig verbose_air output into per-function sections keyed by FQN
- For each C function Air, render it as text via air.write() using
  the Zig PerThread (InternPool indices must match between C and Zig
  for the same source), then compare against the Zig reference text

For the current corpus (codecs.zig, no functions), both sides produce
zero entries so the comparison loop is empty. When zirFunc is ported
and a corpus file with functions is added, this will exercise real
per-function Air matching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 13:04:30 +00:00
5d05f3633f stages_test: compare per-function Air count between C and Zig sema
Parse the captured Zig verbose_air output to count per-function Air
sections and verify that C sema produces the same number. For the
current corpus (codecs.zig, no functions), both sides produce zero
entries. When zirFunc is ported and functions appear, per-function
textual Air comparison will be added.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 12:39:40 +00:00
218da7ec7c sema: capture per-function Air text via verbose_air_output
Enable verbose_air in the Zig Compilation and use a Writer.Allocating
to capture per-function Air text for later comparison with C sema output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 12:27:50 +00:00
4dc832f0fa sema: return per-function Air list instead of flat module-wide Air
Change semaAnalyze to return SemaFuncAirList (a list of per-function Air
structs) instead of a single flat Air. This mirrors the Zig compiler's
per-function Air architecture. Currently returns an empty list since
zirFunc is not yet ported; module-level Air arrays are freed directly.

Update sema_c.zig, sema_test.zig, stages_test.zig, and zig0.c to use
the new types. Remove expectEqualAir (replaced by textual comparison
in a subsequent commit).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 12:15:04 +00:00
1345b72e69 Merge branch 'zig1' into zig0-0.15.2 2026-02-19 12:00:06 +00:00
689999c395 build: split zig0 test into compile + link to fix caching
The zig test step previously compiled Zig code and linked C objects in
a single invocation. Since the Zig compiler hashes all link inputs
(including .o file content) into one cache key, changing -Dzig0-cc or
editing any C file invalidated the 6-minute Zig compilation cache.

Split into two steps: emit the Zig test code as an object (cached
independently of C objects), then link it with the C objects in a
separate executable step. Manually set up the test runner IPC protocol
via enableTestRunnerMode() to preserve build summary integration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 11:59:43 +00:00
b8a3164b0d Compilation: add verbose_air_output for programmatic Air capture
Add a verbose_air_output field to Compilation that redirects verbose Air
dumps to a caller-provided writer instead of stderr. When set, liveness
is omitted from the output to support textual comparison in stage0 tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 11:49:03 +00:00
b755eeb5ba sema: use real zig caches and fix thread pool lifetime
- Use Directories.init() to resolve ~/.cache/zig (global) and
  .zig-cache (local) instead of a temp dir, re-using the same
  resolution logic as src/main.zig (introspect module).

- Point zig_lib at zig-out/lib/zig/ (installed copy) instead of lib/
  (source tree) to avoid "file exists in modules 'root' and 'std'"
  when compiling files that live under lib/.

- Heap-allocate the thread pool to keep its address stable. Worker
  threads reference the Pool's condvar/mutex; a by-value copy into
  ZigSemaResult left them waiting on the original stack address while
  deinit broadcast on the copy, causing a deadlock.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 10:43:13 +00:00
7c767fade4 WIP: wire up Zig Compilation for reference sema in stage0 tests
Add zigSema helper (stage0/sema.zig) that creates a Compilation,
points it at a source file, and runs the full Zig sema pipeline.
Export Compilation and Package from test_exports.zig. Wire up in
stagesCheck to run Zig sema alongside C sema.

Not yet working: files under lib/ conflict with the auto-created
std module ("file exists in modules 'root' and 'std'"). The fix
(using .root = .none with absolute path) needs testing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 09:14:28 +00:00
1c681e3a18 stages_test: verify C→Zig Air conversion in stagesCheck
Add expectEqualAir() that validates the converted Zig Air matches
the original C Air (instruction count, tags, and extra data). Use it
in stagesCheck to verify the conversion is faithful for all corpus
files processed through the sema stage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 08:02:47 +00:00
4834879295 sema_c: extract cSema pipeline function and update all tests
Extract cSema(gpa, c_zir) as a reusable function that runs the full
C sema pipeline (init IP → init sema → analyze → convert to Zig Air)
and returns a SemaResult owning all resources. Update all sema tests
in sema_test.zig and stages_test.zig to use it, removing duplicated
pipeline setup code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 07:47:20 +00:00
613ab41353 sema_c: add C Air → Zig Air conversion module
Add stage0/sema_c.zig that converts C Sema output (Air struct) to Zig's
Air type via MultiArrayList, with per-tag data dispatch. Update
stagesCheck to use the conversion, and extend the const x = 42 test to
verify both Air structure and InternPool contents.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 07:26:09 +00:00
db33d34d6d sema: handle struct_decl declarations and ZIR_INST_INT
Add enough C sema handling so that `const x = 42;` interns the integer
value 42 in the InternPool, matching the Zig reference implementation.

- Add Declaration.Flags.Id helper functions (hasName, hasLibName,
  hasTypeBody, hasValueBody, hasSpecialBodies) ported from Zir.zig
- Add zirInt handler to intern comptime integer values
- Add zirStructDecl handler to parse struct_decl extra payload,
  iterate declarations, and analyze their value bodies
- Add cross-check test comparing C and Zig InternPool entries

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 06:56:42 +00:00
9504050c84 stages_test: add Zig InternPool cross-check for pre-interned entries
Wire src/test_exports.zig through build.zig so zig0 tests can import
the real Zig InternPool. Add a test that initializes both the C and Zig
InternPools and compares all 124 pre-interned entries index by index.

Also add rule to skill file: never run `zig build test` or bare
`zig build` (they test upstream Zig and take ages).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 06:19:39 +00:00
58f69f46b5 skills: replace port-astgen + fix-stages with unified enable-tests
Combine two specialized skills (port-astgen for astgen_test.zig,
fix-stages for stages_test.zig) into a single parameterized skill
that takes any test file as input. Improvements over the originals:

- Config table maps test files to modifiable/reference files
- Flush accumulated passing tests before dispatching worker
- Fast test-zig0 for per-iteration verification, valgrind only in final check
- Worker budget (~15 cycles) to avoid context exhaustion
- Guard rail: skip test after 2 consecutive no-progress
- Worker truncates output (tail -50) and never reads whole reference files
- Handles all failure types: parser, AstGen, and sema

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 21:10:42 +00:00
665ffcb149 disable most corpus testS 2026-02-18 22:55:13 +02:00
0f320bf971 remove some duplicated tests 2026-02-18 22:49:36 +02:00
d66789e045 stages_test.zig: change-over files 2026-02-18 18:22:16 +02:00
70a9f8b2e7 we have zig-out/bin/zig 2026-02-18 16:46:31 +02:00
4ea0bca702 Merge remote-tracking branch 'refs/remotes/motiejus/zig0-0.15.2' into zig0-0.15.2 2026-02-17 20:43:34 +00:00
b992036987 stage0: implement first Sema instruction handlers (Phase D)
Add core Sema analysis infrastructure:
- InstMap operations: ensureSpaceForBody, get, put
- resolveInst: maps ZIR refs to AIR refs (pre-interned + inst_map)
- addAirInst: appends AIR instructions with auto-growth
- SemaBlock helpers: init, deinit, blockAddInst
- zirDbgStmt handler with comptime elision and coalescing

Implement analyzeBodyInner dispatch loop handling:
- dbg_stmt, break_inline, ret_implicit, extended (stub),
  block_inline (recursive body analysis), declaration (skip)
- Default case maps unhandled instructions to void_type

Update semaAnalyze to set up root block, verify ZIR instruction 0
is struct_decl, exercise dispatch infrastructure, and transfer AIR
array ownership to returned Air struct.

Add smoke test for "fn foo() void {}" declarations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-17 20:36:25 +00:00
6f33cdb5e7 improve zig3 2026-02-17 22:10:58 +02:00
ed2d9b4d25 stage0: add sema test framework skeleton (Phase C)
Create sema_test.zig with:
- InternPool unit tests: pre-interned types/values, ipTypeOf,
  ipIntern deduplication, new key interning, vector/pointer types
- Sema smoke tests: empty source and "const x = 0;" through
  full C pipeline (parse → astgen → sema) without crashing

Wire sema_test.zig into test_all.zig.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-17 20:04:31 +00:00
25db8d160e stage0: implement InternPool core (Phase B)
Pre-populate 124 entries matching upstream InternPool.Index enum:
- Integer types (u0-u256, i0-i128), simple types, float types
- Pointer types (*usize, [*]u8, []const u8, etc.) with flag encoding
- All 47 vector types in exact upstream order
- Values: undef/zero/one variants, void/null/true/false/unreachable

Add hash table with open addressing + linear probing for dedup.
Implement ipIntern (lookup-or-insert), ipIndexToKey, ipTypeOf.
Add TypedInt struct and PTR_FLAGS_* defines to intern_pool.h.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-17 19:56:05 +00:00
11fe8a5228 stage0: add Sema data structures (Phase A)
Create header files and minimal .c stubs for the Sema pipeline:
- intern_pool.h/c: InternPool types, pre-interned indices (0-123),
  SimpleType/SimpleValue enums, Key tagged union, init/deinit
- air.h/c: AIR instruction tags (X-macro), Ref encoding (MSB tag),
  InstData union, extra payload structs, init/deinit
- type.h/c: TypeIndex typedef, stub query functions
- value.h/c: ValueIndex typedef, conversion functions
- sema.h/c: Sema/Block/InstMap/Merges structs, init/deinit/analyze stubs

Wire up build.zig and integrate sema step into zig0.c pipeline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-17 19:42:24 +00:00
1ac6c59020 cppcheck: remove all suppressions, fix all warnings
Split cppcheck into per-file checks (warning,style,performance,portability)
and a combined unusedFunction check across all C files. Remove dead code
(addExtraU32, rvalueDiscard, wipMembersNextDecl, wipMembersBodiesAppend,
findNextContainerMember, NodeContainerField). Wire up zig0Run to actually
call astParse/astGen and print stats, eliminating unusedFunction warnings
for the public API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 18:13:52 +00:00
19b233e29b unify error handling: SET_ERROR(ctx, msg) for both parser and astgen
Replace parser's fail() and astgen's flag-only SET_ERROR(ag) with a
single SET_ERROR(ctx, msg) macro in common.h that stores the error
message in ctx->err_buf and sets ctx->has_compile_errors.  Both Parser
and AstGenCtx now carry the same err_buf[ERR_BUF_SIZE] field.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 17:02:00 +00:00
50ef00a8ec fix syntax errors with -O3 2026-02-17 14:55:22 +00:00
7da312498c stages_test: use C-based parser. 2026-02-17 14:26:29 +00:00
5dcc294143 parser: add warn, assign destructure, fix statement bodies; enable CodeGen.zig
- Add warn() for non-fatal parse errors (like Zig's Parse.warn)
- Implement finishAssignDestructureExpr for destructuring assignments
- Use parseBlockExpr instead of parseBlock in for/while statement bodies
- Use parseSingleAssignExpr in switch prongs
- Enable x86_64/CodeGen.zig corpus entry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 12:17:18 +00:00
884dbdad1e Merge branch 'zig1' into zig0-0.15.2 2026-02-17 10:58:14 +00:00
47542b533c use C parser in AstGen 2026-02-17 10:56:11 +00:00
a8cbad9d80 stages_test: enable main.zig, git.zig
Both were blocked by the container_field extra_data bug fixed in c1bba6d5.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:27:57 +00:00
dabecdbe46 astgen: fix @unionInit context propagation, enable Assemble.zig
The @unionInit handler in builtinCallMultiArg was propagating the parent's
result info context (e.g. RI_CTX_RETURN) to the init value expression.
Upstream Zig creates a fresh ResultInfo with .ctx = .none. This caused
call flags mismatch (pop_error_return_trace) in return expressions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:22:54 +00:00
94ff055d53 astgen: handle @frameAddress in rlBuiltinCall, enable debug.zig
rlBuiltinCall was always returning false (not consuming result location).
The Zig reference marks @frameAddress as consuming the RL (workaround for
llvm/llvm-project#68409), which affects declaration codegen path (pointer
vs value based). Match the upstream behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 07:13:25 +00:00
c1bba6d5c2 astgen: fix container_field extra_data guard, enable aes_ocb, SmpAllocator, Mir
The AST_NODE_CONTAINER_FIELD case in structDeclInner had an incorrect guard
`if (nd.rhs != 0)` before reading align/value from extra_data. Since rhs is
an extra_data index (not a node), 0 is a valid index. Removing the guard
fixes 3-5 missing instructions in files where the first extra_data entry
happens to be a container_field's align+value.

Also fix clang-format: addBuiltinValue arg wrapping, for-loop semicolons.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 06:56:06 +00:00
80dead078d stages_test: enable exp, atan, expm1, gamma, log1p, zon/parse
All float-tag mismatches resolved by the 128-bit decimal_float_fits_f64.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 06:27:13 +00:00
3f8eed8a60 stages_test: enable 22 more corpus files; upgrade decimal_float_fits_f64 to 128-bit
Upgrade decimal_float_fits_f64() to use 128-bit integer arithmetic for the
algebraic round-trip test, handling mantissas up to ~38 significant digits.
This fixes float128-vs-float tag mismatches for values that fit in 128-bit
mantissa but overflow 64-bit.

Newly enabled: gpu, memmove, mulf3, udivmodei4, udivmod, scalar, ff,
p256_64, p256_scalar_64, p384_64, p384_scalar_64, secp256k1_64,
secp256k1_scalar_64, sha2, sha3, Decompress, testing, log10, log2, log,
rem_pio2f, rem_pio2_large, rem_pio2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 06:15:26 +00:00
f9a3d39552 astgen: fix decimal_float_fits_f64 for non-zero underflow, enable divtf3_test, divxf3_test
decimal_float_fits_f64() incorrectly returned true when a non-zero mantissa
(that had overflowed uint64_t) was converted to 0.0 by strtod. These values
do not fit in f64 and need f128 representation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 05:50:38 +00:00
4cfde11ef0 astgen: fix ptrTypeExpr addrspace, do_err_trace check, switchExpr capture, blockExprStmts heap alloc
- ptrTypeExpr: use addBuiltinValue + RL_COERCED_TY for addrspace (matching
  AstGen.zig:3880-3881) instead of RL_NONE_VAL
- do_err_trace: check ag->fn_block != NULL instead of ag->fn_ret_ty != 0 in
  ifExpr, orelseCatchExpr, switchExprErrUnion (matching Zig semantics)
- switchExpr: don't reset capture for underscore discards (AstGen.zig:7870)
- nodeIsTriviallyZero: handle prefixed zero forms (0b0, 0o0, 0x0, with
  underscores)
- blockExprStmts: heap-allocate scope arrays sized to stmt_count instead of
  fixed 128, fixing compile errors on large blocks (e.g. scalar.zig)
- build.zig: increase default test timeout from 10s to 300s
- Remove debug fprintf counters

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 05:30:35 +00:00
fbba8b99fd astgen: fix decimal_float_fits_f64 underflow and enable 700+ corpus files
Fix strtod underflow/overflow edge cases in decimal_float_fits_f64.
Enables 707 files across lib/std/, lib/compiler_rt/, src/, and more.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 04:47:13 +00:00
99d615e4b4 astgen: fix fnProtoExprInner lparen computation for named fn protos
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 03:23:19 +00:00
f1e0ec3926 astgen: use plain expr instead of comptimeExpr for @setRuntimeSafety operand
Enables 326 files from compiler/, compiler_rt/, and more.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 23:39:04 +00:00
e9fa136c58 astgen.c: fix forExpr to use nodeIsTriviallyZero for range start check
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 22:47:52 +00:00
cfaa83f991 parser: fix extra_data write ordering in parseSwitchProng for multi-item switch cases
Enables 39 files from compiler/aro/.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 22:36:07 +00:00
ad3ecc9900 stages_test: enable time_report.zig, common.zig, inttypes.zig, and 6 files from compiler/aro/
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 22:11:17 +00:00
a54f963b66 astgen.c: port @trap builtin handler from upstream AstGen.zig
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 22:01:36 +00:00