Commit Graph

17090 Commits

Author SHA1 Message Date
0419146858 bring src/ to 0.15.2
Since we now are at arms' length with the upstream compiler.
2026-02-24 10:04:04 +02:00
5d5f377986 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
079d14b34f Zcu.saveZirCache: mark safety buffer defined for valgrind
In safety-checked builds, Zir.Inst.Data is a tagged union where
@sizeOf(Data) > 8 due to the safety tag. saveZirCache strips these
tags by reinterpreting each Data as a HackDataLayout and copying the
first 8 bytes into a safety_buffer.

Union variants that use fewer than 8 bytes of payload leave the
remaining bytes uninitialised. The bulk copy propagates these
uninitialised V-bits into safety_buffer, causing valgrind to report:

  Syscall param pwritev(vector[...]) points to uninitialised byte(s)

when the buffer is written to the cache file. This is harmless:
loadZirCache reconstructs the safety tag from the tag array, and each
variant only reads its own fields — the padding is never interpreted.

@memset before the copy does not help: the assignment
`safety_buffer[i] = as_struct.data` copies all 8 bytes from the
source union, and valgrind propagates the per-byte defined/undefined
status (V-bits) from source to destination, re-tainting the padding.

Use makeMemDefined after the copy loop to inform valgrind that the
padding contents are intentional. This compiles to a no-op when not
running under valgrind.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 19:51:25 +00:00
002bc56be7 sema_test: show human-readable AIR tag names in mismatch diagnostics
Export air_tag_name from verbose_air.zig to convert AIR tag u8 values
to their string names (e.g. "arg", "ret", "block"). Use it in
sema_test.zig error messages so mismatches show readable names instead
of raw numbers. Also add refKindStr to distinguish ip/inst refs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 20:01:30 +00:00
93b49123cc 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
21b91fb556 verbose_air: add callback_count canary to detect skipped sema
Defense-in-depth for the cache_mode fix: track how many times the
verbose_air_callback fires and fail the test if C sema produced
functions but the Zig callback was never invoked.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 13:20:21 +02:00
67235b6c72 verbose_air: use incremental cache mode to avoid stale results
With .cache_mode = .whole, comp.update() returns immediately on a
cache hit, skipping sema entirely.  The verbose_air_callback never
fires, so the collector returns 0 functions.  This causes spurious
test passes when the C sema also returns 0 functions (e.g. for
unported @export), because 0 == 0 looks like a match.

Switch to .incremental so that sema always runs and the callback
always fires, making test results deterministic across runs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 10:49:46 +00:00
67f4770835 sema_test: compare AIR data per-instruction using tag-aware sizes
Move padding awareness from collection (verbose_air.zig) to the test
comparison (sema_test.zig).  Air.Inst.Data is an 8-byte union where
some variants (un_op, no_op, ty, repeat) use fewer bytes; the rest is
uninitialised padding.  Instead of zeroing padding at collection time,
compare only the meaningful bytes per tag in the test harness.

This reverts the verbose_air.zig zeroing from 67b821e925 and
replaces the bulk std.mem.eql in airCompareOne with a per-instruction
loop that also gives better diagnostics on mismatch (instruction
index, tag, byte count).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 10:24:33 +00:00
67b821e925 verbose_air: zero padding in Air.Inst.Data when collecting
Air.Inst.Data is a union; variants smaller than 8 bytes (un_op,
no_op, ty, repeat) leave padding bytes uninitialised.  Zero the
destination buffer and copy only the meaningful bytes per instruction
so that byte-level comparisons in tests are deterministic and
valgrind-clean.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 08:42:53 +00:00
a787650d54 verbose_air: use caller-provided error buffer instead of heap allocation
Replace the heap-allocated error_msg with a fixed-size caller-provided
buffer, making error reporting infallible. All error paths now write
into the buffer via bufPrint with truncation on overflow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 08:11:17 +00:00
a560752410 sema: port zirFunc for exported void functions
Port zirFunc to C sema so that `export fn f() void {}` produces
matching AIR on both the C and Zig sides. Configure verbose_air.zig
to use the self-hosted wasm backend (use_llvm=false) with ReleaseFast,
which eliminates error tracing and safety-check instructions.

Enable the "sema air: empty void function" test case.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 08:04:00 +00:00
d371303f4f verbose_air: enable emit_bin so exported functions produce AIR
With emit_bin=false, the compiler never queued functions for analysis,
making the verbose_air_callback a no-op — all corpus files produced 0
AIR functions on both C and Zig sides, so Stage 3 comparison was
vacuous.

Set emit_bin=true so that `export fn` and `@export` trigger function
analysis. Disable 5 compiler_rt corpus files that now expose the
Zig-vs-C mismatch (they use @export but C sema doesn't port zirFunc
yet). Add 3 skipped export-fn test tiers in sema_test.zig as targets
for incremental zirFunc porting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 07:22:20 +00:00
02ff3b93fe verbose_air: fix index-out-of-bounds when shrinking func collector array
Use allocatedSlice() instead of .items to get the full [0..capacity]
slice for realloc. .items only covers [0..len] which causes an
out-of-bounds access when capacity > len.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 22:18:33 +00:00
9ae160a5f2 use wasi target 2026-02-19 22:13:41 +00:00
bdf753eaf8 Move Air comparison from src/ to stage0/
src/verbose_air.zig now only collects Air data (zig_compile_air) instead
of comparing it (zig_compare_air). The comparison logic lives in
stage0/sema_test.zig, keeping testing infrastructure in stage0/.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 21:58:08 +00:00
7189403042 zig_compare_air: add module_root parameter to widen import resolution
Hardcoding the module root to dirname(src_path) caused "import of file
outside module path" for any @import("../...") in corpus files. Add an
optional module_root parameter so stages_test can symlink to the repo
root, allowing all relative imports to resolve within the module path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 21:34:39 +00:00
507867a480 remove some leftover exports 2026-02-19 21:21:05 +00:00
0259a61152 disable debug logging 2026-02-19 21:05:41 +00:00
63a4e708ee stages_test: use directory symlink for Air comparison source files
Instead of writing file content to /tmp (which broke relative imports
like codecs/asn1.zig), symlink the original file's directory into
.zig-cache/tmp/zig0_test. This keeps the module root outside lib/std/
(avoiding module path conflicts) while preserving subdirectory import
resolution through the symlink.

In verbose_air.zig, use Compilation.Path.fromUnresolved to construct the
module root so it gets the same canonical root enum (.local_cache, etc.)
as file paths computed during import resolution, avoiding isNested
root mismatches.

Fixes the codecs.zig test failure (434/434 tests now pass).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 19:13:08 +00:00
882ad78257 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
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
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
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
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
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
d8b3451f12 x86_64: fix RoundMode immediate encoding for vroundss/vcvtps2ph
The RoundMode packed struct had Direction as enum(u4) occupying bits 3:0,
which pushed the precision exception suppress field to bit 4. Per Intel
SDM, the ROUNDSS/VROUNDSS/VCVTPS2PH immediate layout is:

  bits 1:0 = rounding mode
  bit 2    = rounding source (MXCSR.RC vs immediate)
  bit 3    = precision exception suppress
  bits 7:4 = reserved (must be 0)

The old encoding emitted e.g. vroundss $0x12 for ceil-suppress (bit 4
set, reserved), which CPUs silently ignore but valgrind 3.26.0 correctly
rejects with SIGILL. Fix by changing Direction to enum(u3) so precision
lands at bit 3, producing the correct $0x0a encoding.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 20:41:19 +00:00
Alex Rønne Petersen
bc7cdc2b6b libcxxabi: don't build cxa_noexception.cpp if exceptions are enabled 2025-10-06 23:28:58 +02:00
Alex Rønne Petersen
03078bfa41 libcxxabi: sort file list according to upstream CMakeLists.txt 2025-10-06 23:28:52 +02:00
Alex Rønne Petersen
b2591d50c7 libcxxabi: define _LIBCPP_BUILDING_LIBRARY in addition to _LIBCXXABI_BUILDING_LIBRARY 2025-10-06 23:28:39 +02:00
xdBronch
cfb5350ed4 don't pass zero-length @memset to the backend 2025-10-06 23:26:05 +02:00
Jacob Young
7de67e6802 InternPool: use sequential string indices instead of byte offsets
This allows more bytes to be referenced by a smaller index range.

Closes #22867
Closes #25297
Closes #25339
2025-10-05 00:27:39 -04:00
Jacob Young
2700af2aeb x86_64: fix bool vector init register clobber
Closes #25439
2025-10-03 23:26:21 -04:00
mlugg
e6e93d82b0 Lld: fix implib emit path
Resolves: https://github.com/ziglang/zig/issues/24993
2025-10-02 10:55:16 +02:00
Jacob
ab6dbfe1a3 translate_c: fix ternary operator output in C macros 2025-10-01 14:23:54 +02:00
Timothy Bess
0795e2b2ef Fix zig build lazy -> eager dependency promotion
Before, this had a subtle ordering bug where duplicate
deps that are specified as both lazy and eager in different
parts of the dependency tree end up not getting fetched
depending on the ordering. I modified it to resubmit lazy
deps that were promoted to eager for fetching so that it will
be around for the builds that expect it to be eager downstream
of this.
2025-10-01 04:36:15 +02:00
Alex Rønne Petersen
4fd78f9c26 libcxx: respond to some feature macro changes in LLVM 20
ba87515fea

closes #25376
2025-09-28 15:31:22 +02:00
Andrew Kelley
135f1915da Compilation: --debug-rt always Debug
--debug-rt previously would make rt libs match the root module. Now they
are always debug when --debug-rt is passed. This includes compiler-rt,
fuzzer lib, and others.
2025-09-28 08:19:39 +02:00
Ryan Liptak
c40dbd6ff0 Update descriptions of -f[no-]error-tracing to match the actual behavior
Before https://github.com/ziglang/zig/pull/18160, error tracing defaulted to true in ReleaseSafe, but that is no longer the case. These option descriptions were never updating accordingly.
2025-09-28 08:18:45 +02:00
Alex Rønne Petersen
6b1d94c539 musl: add missing fenv C dummy functions for loongarch64-linux-muslsf
https://www.openwall.com/lists/musl/2025/09/27/1

closes #25367
2025-09-28 08:18:18 +02:00
Alex Rønne Petersen
a1c410d512 Revert "x86_64: improve support for large enums"
This reverts commit 8520e4e286.
2025-09-26 00:19:47 +02:00
Jacob Young
8520e4e286 x86_64: improve support for large enums
Closes #25247
2025-09-25 07:44:58 +02:00
Jacob Young
a430be097b x86_64: support more in/out forms
Closes #25303
2025-09-25 01:11:05 +02:00
alexrp
e526d65f5e compiler: don't use self-hosted backend on any BSD yet
There are some blocking bugs in the self-hosted ELF linker.
2025-09-24 01:11:42 +02:00
Alex Rønne Petersen
9694c83b95 Revert "frontend: another packedStructFieldPtrInfo fix"
This reverts commit 3ab845e028.
2025-09-22 04:56:46 +02:00
Alex Rønne Petersen
d07b67a55c Revert "x86_64: fix safety crashes in storeRegs"
This reverts commit 37985613c7.
2025-09-21 21:42:39 +02:00
Jacob Young
e647d1a570 x86_64: rewrite vector element pointer access 2025-09-21 21:36:23 +02:00
Jacob Young
80eacd6003 aarch64: fix behavior failures 2025-09-21 21:08:52 +02:00