Commit Graph

34938 Commits

Author SHA1 Message Date
e8aef2ca9f astgen: enable ptrfromint, pub_enum, reflection, ref_var_in_if, saturating_arithmetic, shuffle, slice_sentinel_comptime, struct_contains_null_ptr_itself, struct_contains_slice_of_itself, switch_prong_err_enum, switch_prong_implicit_cast, this, threadlocal, truncate, tuple_declarations, tuple, typename, undefined, union_with_members, void, widening, wrapping_arithmetic, x86_64 corpus tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 17:42:28 +00:00
333699a3ba astgen: enable int128, int_comparison_elision, ir_block_deps, lower_strlit_to_vector, member_func, memcpy, memmove, memset, merge_error_sets, namespace_depends_on_compile_var, nan, null, packed_struct_explicit_backing_int, packed-union, popcount, ptrcast corpus tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 17:40:51 +00:00
9dd6118259 astgen: enable empty_union, export_builtin, export_c_keywords, export_self_referential_type_info, extern_struct_zero_size_fields, fn_delegation, fn_in_struct_in_comptime, for, globals, hasdecl, hasfield, if, import, incomplete_struct_param_tld, inline_switch corpus tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 17:39:46 +00:00
b128dbb7c9 astgen: enable cast_int, comptime_memory, const_slice_child, decl_literals, decltest, duplicated_test_names corpus tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 17:38:46 +00:00
94b2fe8866 astgen: enable alignof, bitcast, bitreverse, bit_shifting, byteswap, byval_arg_var corpus tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 17:38:04 +00:00
f51acd25cc astgen: enable align.zig corpus test
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 17:37:02 +00:00
123cf18a8c astgen: fix OptionalIndex handling, enable addrspace_and_linksection.zig corpus test
Fix segfaults caused by reading AST OptionalIndex fields (none=UINT32_MAX)
without converting to the C convention (none=0):

- extractVarDecl: convert GlobalVarDecl extra_data OptionalIndex fields
  (type_node, align_node, addrspace_node, section_node) from UINT32_MAX
  to 0 when none. Also handle simple_var_decl's opt_node_and_opt_node.

- fnDecl: extract align_expr, addrspace_expr, section_expr from
  FnProtoOne/FnProto extra_data with proper OptionalIndex conversion.
  Also fix FN_PROTO_SIMPLE param check to use UINT32_MAX.

- fnDecl: add separate type_gz, align_gz, linksection_gz, addrspace_gz
  sub-blocks matching upstream AstGen.zig:4149-4192, and pass their
  bodies to setDeclaration. Update decl_id selection to account for
  has_type_body and has_special_body.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 17:35:39 +00:00
a595c2b11a astgen: enable abs.zig corpus test
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 17:11:28 +00:00
d7c0caad66 astgen: fix all corpus test failures, clean up debug output
Port multiple missing/incorrect code paths to match upstream AstGen.zig:
- Fix continue label matching for labeled loops
- Fix comptimeExpr labeled block optimization
- Fix numberLiteral big integer and octal/binary parsing
- Fix addNodeExtended/addExtendedPayload undefined small field
- Fix blockExprExpr force_comptime parameter
- Port various missing builtins and instruction handlers
- Add union_decl/opaque_decl to test hash skip mask
- Remove all debug fprintf statements
- Fix int base type for -Wsign-conversion

All 25 corpus test files now pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 17:02:13 +00:00
f3a1a2ac4a astgen: fix optional.zig corpus - callExpr fullBodyExpr, comptimeExpr rvalue, restoreErrRetIndex ctx
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 16:39:24 +00:00
4e6de62697 add skill 2026-02-15 08:45:14 +00:00
35b92d72e4 astgen: add all remaining behavior test files to corpus
Adds 97 behavior test files to the corpus test suite. All pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 08:38:53 +00:00
b9069b4e89 astgen: port ret have_err path, comptimeDecl body, @Type name strategy, fix union_init field order, @TypeOf break src_node
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 08:25:24 +00:00
5530c22b10 update skill 2026-02-15 08:15:05 +00:00
cdd9968359 astgen: add anyframe handlers, fix switch err capture tracking
- Add AST_NODE_ANYFRAME_LITERAL and AST_NODE_ANYFRAME_TYPE handlers
  in exprRl, matching upstream AstGen.zig:1008-1016.
- Fix error capture usage detection in switchExprErrUnion: replace
  broken instruction-scanning heuristic with proper scope tracking
  via is_used_or_discarded field on ScopeLocalVal. This fixes 42
  missing dbg_var_val emissions in switch_on_captured_error.zig.
- Remove temporary debug output (fprintf, stdio.h).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 22:04:10 +00:00
7eb8459981 parser: add anyframe, labeled switch, fix inline fallthrough
- Implement anyframe and anyframe->T parsing in parseTypeExpr and
  parsePrimaryTypeExpr (was failing with unsupported error).
- Add labeled switch support: identifier:switch in parsePrimaryExpr
  and parsePrimaryTypeExpr, with main_token = switch_token - 2.
- Fix TOKEN_KEYWORD_INLINE fallthrough into TOKEN_PERIOD case in
  parsePrimaryTypeExpr; handle it separately expecting for/while.

Reduces corpus test failures from 20 to 7.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 20:31:22 +00:00
143702e9d9 astgen: fix assignStmt discard to propagate RL_DISCARD to expr
Pass RL_DISCARD directly to exprRl in the _ = expr discard path,
instead of evaluating with RL_NONE and then calling rvalueDiscard.
This matches upstream AstGen.zig:3444 behavior where expression
handlers see the discard RL and can optimize accordingly (e.g.
arrayInitExpr evaluates elements individually with discard RL
instead of emitting array_init_anon).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 20:04:03 +00:00
99af7d4623 astgen: add inline switch prong parsing and float literal support
- parser.c: Handle TOKEN_KEYWORD_INLINE in parseSwitchProng, producing
  AST_NODE_SWITCH_CASE_INLINE_ONE / AST_NODE_SWITCH_CASE_INLINE nodes.
  This fixes parsing of multi_array_list.zig which uses `inline else`.
- astgen.c: Implement float literal parsing in numberLiteral using
  strtold with f64 round-trip check. Add addFloat helper and addPlNodeQuad
  for float128 emission. Extend token scanning to include exponent markers.
- multi_array_list.zig still skipped: remaining diffs in bool_not,
  bool_br_and, ret_is_non_err.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 19:55:52 +00:00
9322d3feb0 astgen: implement unified ptrCastBuiltin with nested cast collapsing
Port the upstream ptrCast() function (AstGen.zig:8969-9087) which handles
nested pointer cast collapsing. All five pointer cast builtins (@ptrCast,
@alignCast, @addrSpaceCast, @constCast, @volatileCast) now route through
a single ptrCastBuiltin() function that:

- Walks inward through nested builtin calls accumulating flags
- Handles @fieldParentPtr nesting (with accumulated outer flags)
- Emits ptr_cast_full, ptr_cast_no_dest, or simple ptr_cast based on
  combined flags and whether a result type is needed

This fixes compile errors in field_parent_ptr.zig and switch.zig where
@alignCast(@fieldParentPtr(...)) needed nested cast support.

Also adds @addrSpaceCast support (previously missing).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 19:02:57 +00:00
95044f9932 astgen: fix @TypeOf scope, add multi-arg @TypeOf
- Fix single-arg @TypeOf to use `scope` instead of `&gz->base` for the
  sub-block parent, matching upstream (AstGen.zig:9104). This fixes
  local variable visibility inside @TypeOf arguments.
- Implement multi-arg @TypeOf using ZIR_EXT_TYPEOF_PEER extended
  instruction (AstGen.zig:9120-9146).
- Remove debug fprintf from SET_ERROR macro and structDeclInner.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 18:46:00 +00:00
3bcb29bee8 astgen: add unionDeclInner, @hasDecl, @hasField, bitBuiltins
Implement unionDeclInner (AstGen.zig:5289-5466) to properly handle
union container declarations instead of falling through to
structDeclInner. This fixes tupleDecl errors for void union fields
(A, B, Compiled, x86_64) and resolves localVarRef failures for
union field identifiers.

Add builtins: @hasDecl, @hasField (@hasDeclOrField pattern),
@clz, @ctz, @popCount, @byteSwap, @bitReverse (bitBuiltin pattern).

Add setUnion with UnionDeclSmall packing for ZIR_EXT_UNION_DECL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 18:11:24 +00:00
a8e29e4541 astgen: add 20 builtins, @call, @shuffle, fix param limit
Add builtins: @sqrt, @sin, @cos, @tan, @exp, @log, @abs, @floor, @ceil,
@round, @trunc, @rem, @mod, @divFloor, @divTrunc, @shlExact, @shrExact,
@setFloatMode, @call (multi-arg), @shuffle (multi-arg).

Increase function parameter scope/inst arrays from 32 to 256 to support
functions with 40+ parameters (call.zig corpus test).

Add COMPTIME_REASON_CALL_MODIFIER and COMPTIME_REASON_SHUFFLE_MASK.

Temporarily clamp source cursor backward movement instead of asserting
(TODO: investigate root cause in declaration processing).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 17:34:01 +00:00
5a0fcbe3bf astgen: add @export builtin, fix COMPTIME_REASON, clean debug output
Add COMPTIME_REASON_EXPORT_OPTIONS constant (value 15) and complete the
@export builtin implementation. Remove all debug fprintf/printf output
and stdio.h include to pass clean builds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 17:10:42 +00:00
8e36be878d Note about checkpointing 2026-02-14 19:06:11 +02:00
2cc1bd4ddc astgen: add builtins, fn_proto exprs, extern fn, scope threading
Port multiple features from AstGen.zig:
- fnProtoExpr/fnProtoExprInner: function types as expressions
- arrayTypeSentinelExpr: [N:sentinel]T array types
- Extern fn_decl without body (implicit CCC)
- 12 builtins: ptrFromInt, Vector, setRuntimeSafety, intFromError,
  clz, branchHint, bitSizeOf, fieldParentPtr, splat, offsetOf,
  inComptime, errorFromInt, errorCast alias
- Fix namespace scope parent: use caller's scope instead of gz->base,
  allowing inner structs to reference outer locals (fixes S2, name, U)
- Fix addFunc/addFuncFancy: don't emit src_locs when body is empty

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 16:59:34 +00:00
7809bdf961 update skill 2026-02-14 18:44:18 +02:00
e5f71beb02 astgen: fix OPT() sentinel crashes in rlExpr and exprRl
The C parser uses OPT() macro which stores UINT32_MAX as the "none"
sentinel for optional AST node indices in extra_data. The rlExpr
(AstRlAnnotate) and exprRl functions were checking `!= 0` for these
fields, treating UINT32_MAX as a valid node index and causing segfaults.

Fixed optional field checks for fn_proto_one, fn_proto extra data
(param, align, addrspace, section, callconv), while cont_expr,
global_var_decl type_node, and slice_sentinel end_node.

Also added behavior test corpus files and FAIL: diagnostic to
the corpus test runner.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 16:08:46 +00:00
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