Commit Graph

17075 Commits

Author SHA1 Message Date
e475c2d651 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
03fb8ae879 remove some leftover exports 2026-02-19 21:21:05 +00:00
077ce2cc57 disable debug logging 2026-02-19 21:05:41 +00:00
d9fa43159d 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
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
1ed1e8ddfc 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
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
0d15ca3dd4 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
22d0f41c88 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
33e3e5475d 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
9d827509ee 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
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
ef619fdec8 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
Frank Denis
798acd932e aarch64/zonCast: don't return a pointer to a stack element
Elements are computed at comptime, so don't declare them as "var".
2025-09-21 21:08:52 +02:00
Andrew Kelley
3da6a19011 x86 codegen: handle spilled tuples 2025-09-21 21:08:52 +02:00
Jacob Young
37985613c7 x86_64: fix safety crashes in storeRegs 2025-09-21 21:08:52 +02:00
Andrew Kelley
670c4fae61 frontend: additionally handle C pointers in ptrOptPayload 2025-09-21 21:08:52 +02:00
Andrew Kelley
4d102751b6 frontend: fix too strict assertion
field ptr can be based on C pointer
2025-09-21 21:08:52 +02:00
Andrew Kelley
3ab845e028 frontend: another packedStructFieldPtrInfo fix
it was calculating host integer size in a wrong way. just use integer
abi size
2025-09-21 21:08:52 +02:00
mlugg
b4394412bb Zcu: fix analysis of type of decl with inferred type
If the `nav_ty` is resolved by the `nav_val`, then we need to also mark
the `nav_ty` as in progress when we begin resolving the `nav_val`.
2025-09-21 21:08:51 +02:00
Frank Denis
c15f8b9fc9 Fix duplicate LC_RPATH entries on macOS Tahoe
When building on macOS Tahoe, binaries were getting duplicate LC_RPATH
load commands which caused dyld to refuse to run them with a
"duplicate LC_RPATH" error that has become a hard error.

The duplicates occurred when library directories were being added
to rpath_list twice:

- from lib_directories
- from native system paths detection which includes the same dirs
2025-09-19 16:39:56 +02:00
Frank Denis
7d8a954578 zig fmt help: mention that the argument can be a directory
I’ve been typing `zig fmt **/.zig` for a long time, until I discovered
that the argument can actually be a directory.

Mention this feature explicitly in the help message.
2025-09-19 12:12:49 +02:00
Andrew Kelley
35de86906d Merge pull request #25201 from jacobly0/x86_64-addsat
x86_64: fix strictness edge cases in `+|`
2025-09-18 12:47:18 +02:00
Jacob Young
b8bf2780a0 Elf: implement linksection
Closes #24330
2025-09-18 12:47:18 +02:00
Silver
e14540399c fix handling of comptime-only union fields in Type.getUnionLayout (#25182)
Fixes #25180
2025-09-18 12:47:17 +02:00
mlugg
87ca304a02 llvm: fix tagged union payload size in debug info
Resolves: #24415
2025-09-18 00:01:28 +01:00
mlugg
4cfb58342a frontend: fix reference tracking through coerced function bodies
This bug was manifesting for user as a nasty link error because they
were calling their application's main entry point as a coerced function,
which essentially broke reference tracking for the entire ZCU, causing
exported symbols to silently not get exported.

I've been a little unsure about how coerced functions should interact
with the unit graph before, but the solution is actually really obvious
now: they shouldn't! `Sema` is now responsible for unwrapping
possibly-coerced functions *before* queuing analysis or marking unit
references. This makes the reference graph optimal (there are no
redundant edges representing coerced versions of the same function) and
simplifies logic elsewhere at the expense of just a few lines in Sema.
2025-09-15 11:29:54 +01:00
Ryan Liptak
76e2764eb1 Fix -M and --dep splitting on every = instead of just the first
Before this commit, -Mfoo=bar=baz would be incorrectly split into mod_name: `foo` and root_src_orig: `bar`
After this commit, -Mfoo=bar=baz will be correctly split into mod_name: `foo` and root_src_orig: `bar=baz`

Closes #25059
2025-09-02 22:35:01 +02:00