Commit Graph

34911 Commits

Author SHA1 Message Date
23beb0aad2 astgen: enable array_list.zig corpus test
Fix multiple bugs found via the array_list.zig corpus test:

- Fix anytype param ref/index double-conversion (addStrTok returns
  a ref, don't add ZIR_REF_START_INDEX again)
- Implement is_generic param tracking via is_used_or_discarded
  pointer in ScopeLocalVal
- Fix globalVarDecl declaration src_line: use type_gz.decl_line
  instead of ag->source_line (which was advanced by init expression)
- Fix cppcheck warning: remove redundant (0u << 2) in bitmask
- Implement fetchRemoveRefEntries and ret_param_refs in addFunc
- Add func_fancy case to buildHashSkipMask in test
- Fix valgrind: zero elem_val_imm padding, skip addNodeExtended
  undefined small field, handle more padding-sensitive tags

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 15:08:48 +00:00
17f44db36f Merge branch 'zig1' into zig0-0.15.2 2026-02-14 16:26:21 +02:00
143234146e 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:24:20 +00:00
7104f89af2 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
9bc6ac6679 astgen: assign_destructure, u0 int type, slice_length optimization
- Implement assignDestructure() and assignDestructureMaybeDecls() with
  RL_DESTRUCTURE result location, DestructureComponent types, rvalue
  handling for validate_destructure/elem_val_imm/store_node, and array
  init optimization.
- Fix tryResolvePrimitiveIdent to allow bit_count==0 (u0/i0 types) and
  reject leading zeros (u01, i007).
- Add nodeIsTriviallyZero and slice_length optimization for
  arr[start..][0..len] patterns in AST_NODE_SLICE and
  AST_NODE_SLICE_SENTINEL cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 14:04:06 +00:00
84c578d31b update skill 2026-02-14 15:27:28 +02:00
a263259b1e astgen: implement namespace scopes, identifier resolution across scope boundaries
Add ScopeNamespace struct with per-namespace declaration tables and
capture storage, replacing the flat decl_table on AstGenCtx. Implement
tunnelThroughClosure for cross-namespace captures (closure_get ZIR
instruction). Modify identifierExpr to walk past namespace scopes,
checking namespace decls and tracking num_namespaces_out for proper
closure tunneling.

Key changes:
- ScopeNamespace with decl_names/decl_nodes, capture_keys/capture_vals
- scanContainer populates per-namespace decls instead of flat table
- structDeclInner/enumDeclInner create namespace scopes, write captures
- globalVarDecl/fnDecl/testDecl/comptimeDecl receive scope parameter
- localVarRef properly tunnels through namespace boundaries
- scopeParent helper for generic scope chain walking

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 12:51:38 +00:00
285935bd41 astgen: implement 20+ builtins, multi-arg dispatch, extended helpers
Add builtins: @sizeOf, @alignOf, @typeInfo (simpleUnOpType pattern),
@compileError, @setEvalBranchQuota, @typeName (simpleUnOp pattern),
@This (addNodeExtended), @memmove, @FieldType, @reduce,
@addWithOverflow/@subWithOverflow/@mulWithOverflow/@shlWithOverflow
(overflowArithmetic), @alignCast/@constCast/@volatileCast (ptrCast
family), @errSetCast, @Type (reify), @TypeOf (typeof_builtin block),
@unionInit (3-arg via builtinCallMultiArg), @intFromPtr, @intFromBool,
@floatFromInt, @intFromFloat, @floatCast.

Add helper functions: addNodeExtended, addExtendedPayload,
addExtendedPayloadSmall. Add is_typeof field to GenZir.
Add AST_NODE_BUILTIN_CALL dispatch for 3+ arg builtins.
Add COMPTIME_REASON_COMPILE_ERROR_STRING and UNION_FIELD_NAME.

Add skipped corpus tests for array_list.zig, multi_array_list.zig,
Sema.zig (blocked on identifier resolution across namespace scopes).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 12:25:39 +00:00
b10557306d astgen: blockExpr rvalue, local_ptr rvalue, array_mult
- blockExpr: call rvalue on void result for unlabeled blocks, matching
  upstream AstGen.zig:2431. This was causing a missing STORE_NODE when
  empty blocks like {} were used as struct field values with pointer RL.
- identifierExpr: call rvalueNoCoercePreRef after LOAD in local_ptr case,
  matching upstream AstGen.zig:8453-8454.
- Implement AST_NODE_ARRAY_MULT (** operator) with ArrayMul payload,
  matching upstream AstGen.zig:774-785.
- Enable parser_test.zig and astgen_test.zig corpus tests.
- Enable combined corpus test (all 5 files pass).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 10:19:36 +00:00
28ee5d40b7 astgen: switchExprErrUnion, decl_val rvalue, identAsString ordering
Port switchExprErrUnion optimization for both catch and if patterns,
fix missing rvalue call in decl table lookup, fix identAsString
ordering for underscore error captures, and fill value_placeholder
with 0xaa to match upstream undefined pattern.

Enables corpus build.zig test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 09:54:28 +00:00
b2592f40be astgen: catch error capture, @panic, @errorName, @field, larger block scopes
- Add error capture scope to orelseCatchExpr (catch |err| now creates
  a ScopeLocalVal for the captured error variable)
- Add @panic, @errorName, @field builtins
- Increase blockExprStmts scope arrays from 64 to 128 entries
  (build.zig has 93 var decls in a single block)

corpus build.zig still skipped: needs switchExprErrUnion optimization
(catch |err| switch(err) pattern).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 09:15:14 +00:00
3aced7124e skip build.zig astgen test 2026-02-14 10:58:12 +02:00
bafa089ed5 move module up 2026-02-14 10:53:08 +02:00
5682dc0313 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
ef184ddff0 update skill 2026-02-14 10:27:59 +02:00
7e6398a4e4 Merge commit '6204bb245b4a05e0f4f00bb48d83b76ebcd899e2' into zig0-0.15.2 2026-02-14 10:05:42 +02:00
6204bb245b astgen: fix structDeclInner layout, coercion, fn_proto handling, and error diagnostics
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 01:01:21 +00:00
d08206471b astgen: fix switchExpr captures, underscore prong, switch_block_ref, labels, and body fixups
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:46:39 +00:00
81ddc5c989 astgen: fix whileExpr condition coercion, payload handling, else/continue, result info, and labels
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:34:26 +00:00
f14f47424d astgen: fix structInitExpr rvalue, RL handling, sentinel coercion, and empty init
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:18:25 +00:00
657ee8bd36 astgen: fix forExpr result info, else handling, instruction order, labels, and diagnostics
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:13:14 +00:00
0fbd1d257a astgen: fix ifExpr payload_is_ref, bool coercion, ensure_err_union_payload_void, and discard handling
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 00:04:53 +00:00
9345c89d43 astgen: fix globalVarDecl coercion, nameStratExpr, and error diagnostics
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 23:58:59 +00:00
1fd8dace86 astgen: fix lastToken for deref, compound assigns, call_one, container_decl, for_range, var_decl, asm, and more
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 23:48:40 +00:00
75759cc163 bump version 2026-02-14 01:48:19 +02:00
6703c40f48 astgen: add func_fancy, noalias_bits, varargs, and callconv support in fnDecl
Implement several interconnected features for function declarations:

- noalias_bits: Track which parameters have the noalias keyword by setting
  corresponding bits in a uint32_t (supports up to 32 parameters)
- is_var_args: Detect ellipsis3 (...) token in parameter list
- is_noinline/has_inline_keyword: Detect noinline/inline modifiers
- callconv handling: Extract callconv_expr from fn_proto variants, create
  cc_gz sub-block, emit builtin_value for explicit callconv() or inline
- func_fancy instruction: When any of cc_ref, is_var_args, noalias_bits,
  or is_noinline are present, emit func_fancy instead of func/func_inferred
  with the appropriate FuncFancy payload layout
- fn_var_args: Track in AstGenCtx for body code that checks it
- BuiltinValue constants: Add all ZIR_BUILTIN_VALUE_* defines to zir.h
- addBuiltinValue helper: Emit extended builtin_value instructions

Generic tracking (any_param_used, ret_ty_is_generic, ret_body_param_refs)
is not yet implemented as it requires is_used_or_discarded support in
ScopeLocalVal scope lookups.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 23:42:15 +00:00
df33cfafde rm check_test_order.py 2026-02-14 01:40:13 +02:00
d3e1e8e0d5 bump to dev 2026-02-14 01:33:42 +02:00
33e7f559bf Merge tag '0.15.2' into zig0-0.15.2
Release 0.15.2
2026-02-14 01:33:08 +02:00
324c6101f4 astgen: fix fnDecl anytype params, type coercion, and export linkage
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 23:30:47 +00:00
3c55dcc3b8 astgen: fix firstToken for container_decl, switch_case, asm, while/for, assign_destructure
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 23:24:12 +00:00
2d4d3e0695 astgen: fix exprRl error_value, ptr variants, negation, and missing node types
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 23:18:23 +00:00
e010fa0347 astgen: rewrite enumDeclInner to match upstream enum handling
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 23:09:34 +00:00
ece6f69054 astgen: fix builtinCall rvalue, operand coercion, and result type handling
- Move rvalue calls inside builtinCall (all builtins now call rvalue
  internally, matching upstream) and remove outer rvalue wrap from
  call site
- Add rlResultTypeForCast that errors when no result type is available,
  used by @bitCast, @intCast, @truncate, @ptrCast, @enumFromInt
- Fix @import to compute res_ty from result location instead of
  hardcoding ZIR_REF_NONE
- Fix @embedFile to evaluate operand with coerced_ty=slice_const_u8_type
- Fix @cInclude/simpleCBuiltin to check c_import scope and use
  comptimeExpr with coerced_ty=slice_const_u8_type
- Fix @cImport to pass actual block_result to ensure_result_used instead
  of hardcoded ZIR_REF_VOID_VALUE

Not fixed: Issue 14 (ptrCast nested pointer cast collapsing) — upstream
routes @ptrCast through a dedicated ptrCast() function that walks nested
pointer cast builtins. Currently uses simple typeCast path only.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:58:47 +00:00
2a1df547d6 astgen: fix arrayInitExpr sentinel, discard RL, and non-inferred typed init
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:48:48 +00:00
91e1d1bd2e astgen: add reachableExprComptime and comptime_token handling in varDecl
Port two missing features from upstream AstGen.zig varDecl:

1. Add reachableExprComptime (AstGen.zig:418-438) which wraps init
   expressions in comptimeExpr when force_comptime is set, and checks
   for noreturn results. Replace plain exprRl calls in all three varDecl
   paths (const rvalue, const alloc, var) with reachableExprComptime.

2. Extract comptime_token by scanning backwards from mut_token (matching
   Ast.zig fullVarDeclComponents). For const path, set force_comptime to
   wrap init in comptime block. For var path, use comptime_token to set
   is_comptime which selects alloc_comptime_mut/alloc_inferred_comptime_mut
   tags and sets maybe_comptime on the scope.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:42:31 +00:00
52ce6ea81a astgen: add decltest support and within_fn flag in testDecl/fnDecl
Port two missing features from upstream AstGen.zig:

1. Handle identifier-named tests (decltest): when the token after `test`
   is an identifier, set decl_id to DECL_ID_DECLTEST and record the
   identifier string as the test name. Upstream performs full scope
   resolution for validation which is skipped here.

2. Add `within_fn` field to AstGenCtx (mirrors AstGen.within_fn). Save,
   set to true, and restore in both testDecl and fnDecl. This flag
   propagates to maybe_generic on namespace scopes for container
   declarations inside function/test bodies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:38:56 +00:00
ff99a5157e astgen: add any_defer_node check and reachableExpr to retExpr
Port two missing features from upstream AstGen.zig ret() function:

1. Add any_defer_node field to GenZir (AstGen.zig:11812) to track
   whether we're inside a defer expression. Set it in defer body
   generation and propagate via makeSubBlock. retExpr now checks
   this field and errors with "cannot return from defer expression"
   (AstGen.zig:8127-8135). Also reorder retExpr checks to match
   upstream: fn_block null check first, then any_defer_node check,
   then emitDbgNode.

2. Add reachableExpr wrapper (AstGen.zig:408-416) that calls exprRl
   and checks refIsNoReturn to detect unreachable code. Use it in
   retExpr instead of plain exprRl for the return operand
   (AstGen.zig:8185-8186). nameStratExpr is left as TODO since
   containerDecl does not yet accept a name_strategy parameter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:34:37 +00:00
257236be4c astgen: fix ptrTypeExpr C-pointer allowzero error and source cursor save/restore
Add two fixes from audit of ptrTypeExpr against upstream AstGen.zig ptrType:

1. Reject `[*c]allowzero T` with a compile error matching upstream
   (AstGen.zig:3840-3842). C pointers always allow address zero, so
   the allowzero modifier is invalid on them.

2. Save source_offset/source_line/source_column before typeExpr and
   restore them before evaluating each trailing expression (sentinel,
   addrspace, align). This ensures correct debug info source locations
   matching upstream (AstGen.zig:3844-3846, 3859-3861, 3876-3878,
   3885-3887).

Issue 3 (addrspace RL using addBuiltinValue) is skipped as
addBuiltinValue is not yet implemented.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:25:39 +00:00
2fc7e81d49 astgen: add shift assignment operators and grouped_expression unwrapping
Port assignShift (AstGen.zig:3786) and assignShiftSat (AstGen.zig:3812)
from upstream, handling <<=, >>=, and <<|= operators as both statements
in blockExprStmts and expressions in exprRl. Previously these fell
through to SET_ERROR.

Add grouped_expression unwrapping loop in blockExprStmts (matching
AstGen.zig:2569-2630) so that parenthesized statements like `(x += 1)`
are correctly dispatched to assignment handlers instead of going through
the default unusedResultExpr path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:23:04 +00:00
f54d3f94a3 astgen: fix rlExpr bugs for inline while/for labels, assign_destructure, and @-quoted identifiers
Fix three issues in the RL annotation pre-pass (rlExpr):

1. Label detection for `inline while`/`inline for` now accounts for
   the `keyword_inline` token before checking for `identifier colon`,
   matching upstream fullWhileComponents/fullForComponents logic.

2. `assign_destructure` now recurses into variable nodes and the value
   expression with RL_RI_NONE, matching upstream behavior instead of
   returning false without visiting sub-expressions.

3. `rlTokenIdentEqual` now handles @"..."-quoted identifiers by comparing
   the quoted content rather than stopping at the `@` character, which
   previously caused all @-quoted identifiers to compare as equal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:16:41 +00:00
1c1407adb8 astgen: fix double rvalue wrapping for block expressions in exprRl
The exprRl function was wrapping blockExprExpr's return value in an
extra rvalue() call, but blockExprExpr already applies rvalue internally
for labeled blocks when need_result_rvalue=true. The upstream expr()
function at AstGen.zig:991 returns blockExpr's result directly without
extra rvalue wrapping. This could produce duplicate coercion/store
instructions for non-trivial result locations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:12:43 +00:00
811672be4b astgen: add isAlwaysVoid and endsWithNoReturn checks to rvalue
Port two missing checks from upstream AstGen.zig rvalueInner to the C
rvalue function:

1. isAlwaysVoid (Zir.zig:1343-1608): When the result refers to an
   instruction that always produces void (e.g., dbg_stmt, store_node,
   export, memcpy, etc.), replace the result with void_value before
   proceeding. This prevents emitting unnecessary type coercions or
   stores on always-void instructions.

2. endsWithNoReturn (AstGen.zig:11068): When the current GenZir block
   ends with a noreturn instruction, return the result immediately
   without emitting any rvalue instructions. This avoids emitting dead
   ZIR instructions after noreturn.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:11:01 +00:00
bb0b04c575 Merge commit '0b12e027a3628e26a765126d9937a2366b638ff3' into zig0-0.15.1 2026-02-14 00:07:36 +02:00
0b12e027a3 astgen: add \u{...} unicode escape sequence handling
Port the \u{NNNNNN} unicode escape parsing from upstream Zig's
string_literal.zig:parseEscapeSequence into both strLitAsString
(string literal decoding with UTF-8 encoding) and char_literal
(codepoint value extraction). Without this, \u escapes fell through
to the default branch which wrote a literal 'u' character, producing
incorrect ZIR string bytes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:07:23 +00:00
5672cd73bc astgen: fix builtin_call ensure_result_used bit position
BuiltinCall.Flags has ensure_result_used at bit 1, not bit 3 like
Call/FieldCall. Separate the case to use the correct bit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:05:01 +00:00
52bfd87de7 astgen: fix defer RL annotation, compile_error noreturn, block force_comptime
Three bugs found by auditing against upstream AstGen.zig/AstRlAnnotate.zig:

1. rlExpr: defer was recursing into nd.rhs (always 0) instead of nd.lhs
   (the actual deferred expression), so the RL annotation pass never
   visited defer bodies.

2. addEnsureResult: compile_error was missing from the noreturn
   instruction list, causing spurious ensure_result_used instructions
   to be emitted after @compileError calls.

3. blockExprExpr: force_comptime was derived from gz->is_comptime,
   but upstream blockExpr always passes force_comptime=false to
   labeledBlockExpr. This caused labeled blocks in comptime contexts
   to incorrectly emit BLOCK_COMPTIME + BREAK_INLINE instead of
   BLOCK + BREAK.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 22:03:41 +00:00
7c8248c241 stage0-specific changes 2026-02-14 00:03:26 +02:00
b81f72bab3 Add 'stage0/' from commit 'b3d106ec971300a9c745f4681fab3df7518c4346'
git-subtree-dir: stage0
git-subtree-mainline: 3db960767d
git-subtree-split: b3d106ec97
2026-02-13 23:32:08 +02:00
befbe18ebc parser: fix while-type-expr continue parsing and comptime labeled blocks
Fix two parser bugs found by auditing against upstream Parse.zig:

1. In parseTypeExpr's while case, the continue expression was parsed
   inline as `eatToken(COLON) ? expectExpr : 0` which missed the
   required parentheses. Use parseWhileContinueExpr(p) instead,
   matching what parseWhileExpr already does.

2. In expectStatement, comptime blocks used parseBlock() which only
   matches `{ ... }`. Use parseBlockExpr() to also recognize labeled
   blocks like `comptime label: { ... }`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 21:22:53 +00:00