Commit Graph

612 Commits

Author SHA1 Message Date
8dd28c9a92 stage0: add wyhash and replace boost hash combine in InternPool
Port Zig's std.hash.Wyhash to C (same secret constants, CONDOM=0 mum)
and replace ipHashCombine (boost golden ratio) with Wyhash in ipHashKey.
This aligns the C InternPool's hashing strategy with upstream Zig, which
uses Wyhash for all key hashing including NamespaceType keys.

Tests verify C and Zig Wyhash produce identical results for all standard
test vectors, streaming in various chunk sizes, autoHash equivalence for
u32/u64, and a large 8KB buffer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-01 17:45:50 +00:00
0047dc8086 sema: unify corpus — one array, one counter, all stages
Merge sema_unit_tests into the main corpus.files array. All files now
go through the full stages_test.zig pipeline: parser → ZIR → sema,
with bidirectional AIR comparison.

This fixes a gap where sema unit tests skipped ZIR validation and
used a different sema setup (no source_dir), hiding bugs.

Changes:
- corpus.zig: merge sema_unit_tests into files, remove
  num_sema_passing
- stages_test.zig: handle stage0/ paths (no module_root)
- sema_test.zig: remove corpus test (now in stages_test)
- build.zig: remove sema_unit_tests loop from addAirGen
- sema.c: remove is_exported filter from zirFunc — analyze all
  functions with bodies

num_passing = 3 (first 3 lib/ files with no functions).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-01 13:53:08 +00:00
22f6b25a1a Reuse thread pool and shared state across air_gen compilations
Create SharedState struct holding thread_pool, resolved_target, and config
so they are initialized once instead of per-file (~289 times). Remove C
exports (zig_compile_air, zig_compile_air_free) and dump.h since AIR data
now flows through Zig-only processSource. Use arena-based allocation in
AirCollector instead of manual free.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-27 00:35:42 +02:00
50bafdb2c9 stage0: lower C standard requirement from C11 to C99
zig0 doesn't use any C11-specific features. Lowering to C99
enables bootstrapping on platforms with only C99 compilers,
such as OpenBSD on exotic architectures (GCC 4.2.1).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-25 22:39:26 +00:00
a3f64d280a stage0: remove GNU C extensions for strict C11 compliance
Replace GNU statement expressions ({...}) in common.h with a static
inline function and do...while(0) macros. Expand case range expressions
(case 'a' ... 'z') in tokenizer.c to individual case labels. Replace
empty initializer braces {} with {0} in parser.c. Add a dummy member
to the empty struct in ast.h. Add -pedantic to zig0_cflags in build.zig
to prevent future regressions.

zig0 now compiles with any C11-conforming compiler, not just those
supporting GNU extensions. This enables bootstrapping with MSVC,
cproc, and other strict C11 compilers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-25 22:32:10 +00:00
5700b742d2 stage0: add --verbose-intern-pool flag and IP dumper
Add verbose_intern_pool.c/h for dumping the C sema's InternPool
entries. Integrate as --verbose-intern-pool flag in zig0, mirroring
the Zig compiler's flag.

Fix InternPool.zig dump crash on locals with zero-capacity items
(skip empty locals in dumpStatsFallible and dumpAllFallible).

Update CLAUDE.md with IP debugging tools documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-25 20:37:34 +00:00
7f58c766f8 compile std as root + unidirectional AIR comparison + exact FQN matching
air_gen: replace per-file symlink workaround with two-pass compilation.
Pass 1 compiles lib/std/std.zig as root with use_root_as_std=true
(one compilation, all lib/std/ functions). Pass 2 compiles non-lib/std/
files standalone. Symlink workaround eliminated entirely.

build.zig: pass all corpus.files (not 0..num_passing) to air_gen,
skipping lib/std/ files. Bumping num_passing no longer invalidates
the air_gen cache.

air_data.zig: route lib/std/ paths to the combined std.zig.air file.

sema_test.zig: switch to unidirectional comparison (C→Zig only) and
exact FQN matching. Remove stripModulePrefix, bare-name fallback, and
unused cNameSpan. Add pathToModulePrefix and pathStem helpers.

sema.h/sema.c: add root_fqn, module_prefix, and is_test fields to
Sema struct. Function names use "{root_fqn}[.{prefix}].{name}" format
to match Zig's FQN convention.

stages_test.zig: set root_fqn and module_prefix on C sema so FQNs
match Zig's naming. Remove symlink workaround — C sema uses real
paths directly. Set is_test=false to match air_gen.

corpus.zig: remove lib/init/src/main.zig (template file with
@import(".NAME") that cannot compile standalone).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-25 07:38:35 +00:00
ad993716bd air_gen: ReleaseSafe is ok 2026-02-24 10:01:23 +02:00
ce953b71ee fix deps 2026-02-24 09:48:22 +02:00
43938abe0b airgen: don't use llvm, make a separate step 2026-02-24 09:24:55 +02:00
b6babde053 Merge branch 'zig1' into zig0-0.15.2
# Conflicts:
#	build.zig
#	stage0/sema.c
#	stage0/stages_test.zig
2026-02-23 18:21:30 +00:00
6d8cfa834e pre-compute AIR at build time instead of linking Zig internals into test binary
Replace the old approach of linking verbose_air.zig (and the full Zig
compiler internals) into the test binary with a build-time generator
(verbose_air_gen.zig) that pre-computes AIR data for corpus files.

The generator runs as a build step, compiling each corpus file through
the Zig compiler and serializing the resulting AIR to binary files.
It produces air_data.zig and tag_names.zig bridge files that the test
binary imports as anonymous modules. This removes the heavyweight
zig_compile_air extern dependency from the test binary.

Key changes:
- build.zig: add air_gen executable build+run step, anonymous imports
- verbose_air_gen.zig (new): build-time AIR generator with symlink
  workaround to avoid lib/std/ module path conflicts
- corpus.zig (new): centralized corpus file list with num_passing
- sema_test.zig: replace zig_compile_air extern with parsePrecomputedAir
- stages_test.zig: use corpus.zig and @import("air_data")
- sema.c: zero dead block data in comptime switch handler so the
  dead-block skip rule fires correctly with precomputed data

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 18:03:24 +00:00
c06f13f823 sema: fix valgrind use-after-free and ReleaseSafe issues
- Fix use-after-free in cross-module call handling: copy import path
  strings from ZIR string_bytes into local buffers before freeing the
  ZIR via zirDeinit(). Affects findFuncInModuleZir and three call sites
  in zirCall (2-level, 3-level, and 4-level import chains).
- Fix dead switch block data: use memset(0) instead of memset(0xaa) so
  the test comparison skip logic can handle dead BLOCKs consistently.
- Fix GCC -Werror=empty-body: remove dead loop in registerStructTypeFromZir.
- Fix verbose_dumper ReleaseSafe crash: always compile with ReleaseFast
  to avoid upstream Zig codegen bug in MultiArrayList.slice().
- Fix sema_test dead BLOCK comparison to avoid reading uninitialized
  Zig data (valgrind "uninitialised value" warnings).
- Disable shell_parameters corpus test (pre-existing regression).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 10:45:27 +00:00
31eb5e59f0 enable valgrind for zig builds
It doesn't _have_ to run under valgrind, but will cause less rebuilds
regardless of how it's invoked.
2026-02-23 10:10:37 +02:00
6c5eae996a zig0: fix valgrind false positives and clang-analyzer warning
Enable .valgrind module option on test_mod and dumper_mod in
addZig0TestStep so that std.mem.indexOfSentinel uses a scalar
fallback when running under valgrind. Guard comptime CLZ against
bits==0 to fix clang-analyzer shift warning. Auto-format sema.c.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 19:51:31 +00:00
3c118e1e0d verbose_air: add human-readable AIR printer and --verbose-air CLI flag
Add verbose_air.c/h implementing a human-readable AIR printer for
debugging the C sema, ported from src/Air/print.zig. Types print as
human-readable names (u32, *const u8, fn (...) noreturn) instead of
raw IP indices. Add --verbose-air flag to zig0 CLI and a `zig build
zig0` target for building the standalone executable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 21:17:06 +02:00
689b6b901d fmt 2026-02-20 10:30:47 +02:00
eaab079bd6 always build with valgrind 2026-02-19 20:58:30 +00:00
149e611688 Fix test-zig0 cache invalidation on every commit
The git-describe version string (including commit hash) was passed via
exe_options to zig_internals_mod, causing verbose_dumper to recompile
(~7 min) after every commit. Create separate zig0_exe_options with a
fixed version "0.15.2-zig0-dev" for test-zig0/all-zig0 targets.

Also verify matched_count against c_func_count in Air comparisons to
catch spurious extra functions from the C pipeline.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 20:22:51 +00:00
905ea3a3f7 Remove unimplemented InternPool dump stubs
Both zig_dump_intern_pool and c_dump_intern_pool were unimplemented stubs
with no callers. InternPool correctness is validated by unit tests and Air
comparison.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 18:32:46 +00:00
2516d3a46a 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
00a6cb4fd4 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
42afa9a451 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
4ebbc9047f 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
0b041e0c70 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
9d438d5674 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
d3d76d59a6 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
d2c301cc95 astgen: fix cppcheck warnings for err_scope_used and param_insts
Use memset initialization to satisfy cppcheck's data flow analysis:
- err_scope_used: cppcheck can't track writes through is_used_or_discarded pointer
- param_insts: cppcheck warns about potentially uninitialized array elements

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 19:50:05 +00:00
3f315398fc simplify zig0 test setup: single test module, remove zig0_test.zig
Consolidate the two separate test modules (test_mod via
lib/std/zig/zig0_test.zig + astgen_test_mod via stage0_test_root.zig)
into a single test module rooted at stage0_test_root.zig.

The zig0_test.zig bridge approach ran std's parser/tokenizer tests with
C comparison enabled, but the stage0/ test files already do the same
C-vs-Zig comparison directly via @cImport. The only "lost" tests are an
unnamed root test block and a Zig-only fuzz test — no zig0 coverage lost.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 14:19:15 +00:00
82e0d9a445 move module up 2026-02-14 10:53:08 +02:00
df78083c0f build: fix valgrind zig0 tests by disabling all AVX-512 features
Valgrind doesn't support AVX-512 instructions (EVEX prefix 0x62).
The zig CC generates them for large struct copies on native x86_64
targets even at -O0 (e.g. vmovdqu64 with zmm registers).

Previously only avx512f was subtracted, which was insufficient —
the .evex512 feature (and other AVX-512 sub-features) also need
to be disabled to prevent EVEX-encoded 512-bit instructions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 08:28:24 +00:00
7875cc66f4 bump version 2026-02-14 01:48:19 +02:00
ae5da9de14 bump to dev 2026-02-14 01:33:42 +02:00
8756145090 Merge tag '0.15.2' into zig0-0.15.2
Release 0.15.2
2026-02-14 01:33:08 +02:00
069d61d239 stage0-specific changes 2026-02-14 00:03:26 +02:00
Andrew Kelley
409b194d6d start the 0.15.2 release cycle 2025-08-19 16:21:17 -07:00
Andrew Kelley
f54f061fb3 start the 0.15.1 release cycle 2025-08-19 16:01:09 -07:00
Andrew Kelley
749f10af49 std.ArrayList: make unmanaged the default 2025-08-11 15:52:49 -07:00
Alex Rønne Petersen
7ee6dab39f Revert "Sema: Stop adding Windows implib link inputs for extern "..." syntax."
This reverts commit b461d07a54.

After some discussion in the team, we've decided that this is too disruptive,
especially because the linker errors are less than helpful. That's a fixable
problem, so we might reconsider this in the future, but revert it for now.
2025-08-06 06:15:13 +02:00
Alex Rønne Petersen
bcaae562d6 build: add -Dskip-compile-errors option
Skips tests in test/cases/compile_errors.
2025-08-02 09:34:55 +02:00
Andrew Kelley
0e37ff0d59 std.fmt: breaking API changes
added adapter to AnyWriter and GenericWriter to help bridge the gap
between old and new API

make std.testing.expectFmt work at compile-time

std.fmt no longer has a dependency on std.unicode. Formatted printing
was never properly unicode-aware. Now it no longer pretends to be.

Breakage/deprecations:
* std.fs.File.reader -> std.fs.File.deprecatedReader
* std.fs.File.writer -> std.fs.File.deprecatedWriter
* std.io.GenericReader -> std.io.Reader
* std.io.GenericWriter -> std.io.Writer
* std.io.AnyReader -> std.io.Reader
* std.io.AnyWriter -> std.io.Writer
* std.fmt.format -> std.fmt.deprecatedFormat
* std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape
* std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape
* std.fmt.fmtSliceHexLower -> {x}
* std.fmt.fmtSliceHexUpper -> {X}
* std.fmt.fmtIntSizeDec -> {B}
* std.fmt.fmtIntSizeBin -> {Bi}
* std.fmt.fmtDuration -> {D}
* std.fmt.fmtDurationSigned -> {D}
* {} -> {f} when there is a format method
* format method signature
  - anytype -> *std.io.Writer
  - inferred error set -> error{WriteFailed}
  - options -> (deleted)
* std.fmt.Formatted
  - now takes context type explicitly
  - no fmt string
2025-07-07 22:43:51 -07:00
Andrew Kelley
a59c35cbf8 build.zig: bump maxrss for behavior tests 2025-07-07 13:39:16 -07:00
Alex Rønne Petersen
b461d07a54 Sema: Stop adding Windows implib link inputs for extern "..." syntax.
Closes #23971.
2025-07-06 01:00:18 +02:00
Alex Rønne Petersen
9ef4bdf234 test: Respect various test skip options in test-cases 2025-07-03 22:18:12 +02:00
Jacob Young
917640810e Target: pass and use locals by pointer instead of by value
This struct is larger than 256 bytes and code that copies it
consistently shows up in profiles of the compiler.
2025-06-19 11:45:06 -04:00
Jacob Young
16d78bc0c0 Build: add install commands to --verbose output 2025-06-19 11:45:06 -04:00
Andrew Kelley
5a52da1b7a CI: skip llvm backend tests in the script for testing x86 backend 2025-06-06 23:42:15 -07:00
Andrew Kelley
125a9aa82b restore debug llvm CI coverage
and reduce redundant coverage in slow runs to save time
2025-06-06 23:42:15 -07:00
Jacob Young
5986bdf868 Compilation: enable the x86_64 backend by default for debug builds
Closes #22257
2025-06-06 23:42:14 -07:00
Jacob Young
6a63c8653a build: bump behavior max_rss 2025-06-01 11:58:58 -04:00