Repository navigation
c_import: preserve type-alias macros across selective imports and diagnose unsupported constructs - #1872
Conversation
…s; three refusal tests pin what the omissions say at a use Review of #1872: the loud side of both fixes was untested — the behavior tests only show the rest of the header importing. Verified with this branch's stage1: calling the omitted vector function reports "c_import symbol 'vadd' was omitted: untranslatable: vector type"; building the opaque record reports "cannot create value of opaque type"; using the untranslated `~M_CALL(1)` macro reports "symbol 'M_MIN' was omitted: untranslated macro". Pinned as compile_errors tests. The new `t[0] == 126 or 45 or 43 or 33` chain becomes ci_is_unary_prefix_op with '~' '-' '+' '!' (no magic-number byte chains).
|
Review (verified by building this branch's stage1 and probing, not by reading alone). Correct as written. A C vector has no With spelling and an array would lie about its ABI (vector registers), so The loud side, verified: with this branch's stage1 —
Two fixes pushed to the branch (c75add5):
Filed: #1874 — a language-level SIMD vector type, so c_import can eventually present these types instead of omitting them (Zig Windows: not confirmed here (needs the win10 VM's SDL import); the darwin evidence and the test are sufficient for the darwin battery; I'll run the SDL import on win10 separately. Process: this PR is folded in as the bottom layer of stack #1871 so one battery covers it with the rest; it is marked ready when that battery is green. |
|
Windows check (win10, seed-driven build of c75add5): confirmed — the |
|
Battery on The flagged annotations are all in files this PR doesn't touch: I rebased a local copy of this branch onto current I haven't touched this branch on GitHub. Should it be rebased onto |
|
Battery GREEN on this branch rebased onto current
The first run's red ( |
…s; three refusal tests pin what the omissions say at a use Review of #1872: the loud side of both fixes was untested — the behavior tests only show the rest of the header importing. Verified with this branch's stage1: calling the omitted vector function reports "c_import symbol 'vadd' was omitted: untranslatable: vector type"; building the opaque record reports "cannot create value of opaque type"; using the untranslated `~M_CALL(1)` macro reports "symbol 'M_MIN' was omitted: untranslated macro". Pinned as compile_errors tests. The new `t[0] == 126 or 45 or 43 or 33` chain becomes ci_is_unary_prefix_op with '~' '-' '+' '!' (no magic-number byte chains).
A typedef-named macro target was swallowed by the type-like skip before the alias branch. Emit its actual type alias when the target is available. LLDB on main stage2 observed raw=my_int_t, x0=1 from ci_object_macro_value_is_type_like, and the taken tbnz at ci_translate_macros (CImport.w:3370; out/handoff-alias-lldb.log). Selective-then-full imports exposed a second cause: Frontend filtered the first import's type, but its emitted-name reservation survived. LLDB on stage1 stopped at CImport.w:2648's return with x0=1 on the second import (out/handoff-selective-lldb.log). Frontend now releases discarded names, including escaped C names and type keys. The bridge deletion preserves colliding entries, including clusters wrapping the end of the table. Emitted macro aliases claim their ordinary name so full imports dedup them. Both new behavior tests fail before and pass after: scalar/record aliases print 5 7; selective-then-full types print 5 7 11 13 17 and pin hash collisions and the escaped match name. Alias-chain, callback typedef and repeated-full-import probes check successfully. The diagnostic companion commit shares the green source tree: seed-driven :gate passes; all 93 c_import fixtures pass with the release compiler, including macro scale and variable-extent runner tests. Stack battery still pending. Refs #1872
Share the structured omission diagnostic between identifier lookup and unknown-type reporting. Selective imports now identify their only: list as the remedy instead of recommending an unrelated C representation. The hidden type-alias fixture fails against main's compiler with an unknown-type diagnostic and passes with the explicit selective omission. Seed-driven :gate and all 93 c_import fixtures pass on the combined tree. The stack battery is still pending. Refs #1872
cd13240 to
513fce8
Compare
|
Finished the alias review fixes at LLDB confirmed two failures: the type-like check returned true for Pinned-seed The PR description now reflects the final behavior. It remains draft until the assembled stack's battery is green; no battery result is claimed here. |
… Mask[N, W], splat where one meaning is forced, swizzles, .bits(); c_import maps C vector types (#1874) Eric ruled the design 2026-09-29 and blessed the words. §4.3d Vector Types, §16.1 C vector types, D78 in the decision log. The compiler is NON-COMPLIANT until the implementation lands; #1872's omission of C vector types stays loud until then.
…eps an object macro untranslated With has no SIMD vector type, but c_import rendered a C vector as `Vector(N, T)`, which no With parser accepts. MSVC's <intrin.h>, reached from SDL3 on Windows, declares vector typedefs (AMX's _tile1024i), so any full import of SDL.h there failed to parse. A vector is now __UNSUPPORTED like other unexpressible types: its typedef is omitted, a record holding one is opaque, and a function using one is omitted. An object macro whose value is a call is left untranslated once semantic translation fails, because C re-evaluates it at each use. The check saw only a value that starts with the callee, so SDL3's `#define SDL_MIN_SINT64 ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF)` became a global naming the function-like macro (undefined variable), and broke every full import of SDL.h on macOS. Leading unary operators are now skipped before the check.
…s; three refusal tests pin what the omissions say at a use Review of #1872: the loud side of both fixes was untested — the behavior tests only show the rest of the header importing. Verified with this branch's stage1: calling the omitted vector function reports "c_import symbol 'vadd' was omitted: untranslatable: vector type"; building the opaque record reports "cannot create value of opaque type"; using the untranslated `~M_CALL(1)` macro reports "symbol 'M_MIN' was omitted: untranslated macro". Pinned as compile_errors tests. The new `t[0] == 126 or 45 or 43 or 33` chain becomes ci_is_unary_prefix_op with '~' '-' '+' '!' (no magic-number byte chains).
… a value MSVC's <stdlib.h> declares `#define onexit_t _onexit_t`. _onexit_t is a typedef from a system header, so it is not among the macro translator's known type names, and the macro fell through to the bare-reference path as `let onexit_t = _onexit_t`: an undefined variable that broke every full import of <stdlib.h>, and so of SDL3's SDL.h, on Windows. A macro whose whole value is an identifier naming an emitted or declared type is now skipped like any other type-like macro value.
… macro test reproduces
… do, so the type-alias macro test reproduces
A typedef-named macro target was swallowed by the type-like skip before the alias branch. Emit its actual type alias when the target is available. LLDB on main stage2 observed raw=my_int_t, x0=1 from ci_object_macro_value_is_type_like, and the taken tbnz at ci_translate_macros (CImport.w:3370; out/handoff-alias-lldb.log). Selective-then-full imports exposed a second cause: Frontend filtered the first import's type, but its emitted-name reservation survived. LLDB on stage1 stopped at CImport.w:2648's return with x0=1 on the second import (out/handoff-selective-lldb.log). Frontend now releases discarded names, including escaped C names and type keys. The bridge deletion preserves colliding entries, including clusters wrapping the end of the table. Emitted macro aliases claim their ordinary name so full imports dedup them. Both new behavior tests fail before and pass after: scalar/record aliases print 5 7; selective-then-full types print 5 7 11 13 17 and pin hash collisions and the escaped match name. Alias-chain, callback typedef and repeated-full-import probes check successfully. The diagnostic companion commit shares the green source tree: seed-driven :gate passes; all 93 c_import fixtures pass with the release compiler, including macro scale and variable-extent runner tests. Stack battery still pending. Refs #1872
Share the structured omission diagnostic between identifier lookup and unknown-type reporting. Selective imports now identify their only: list as the remedy instead of recommending an unrelated C representation. The hidden type-alias fixture fails against main's compiler with an unknown-type diagnostic and passes with the explicit selective omission. Seed-driven :gate and all 93 c_import fixtures pass on the combined tree. The stack battery is still pending. Refs #1872
513fce8 to
1ddcf35
Compare
… Mask[N, W], splat where one meaning is forced, swizzles, .bits(); c_import maps C vector types (#1874) Eric ruled the design 2026-09-29 and blessed the words. §4.3d Vector Types, §16.1 C vector types, D78 in the decision log. The compiler is NON-COMPLIANT until the implementation lands; #1872's omission of C vector types stays loud until then.
|
Stack battery GREEN on the top commit 5666aea (spec-simd-vectors), after re-folding onto main a4505ea (seed nightly-20260929-local-1-2fa54a7197df, picks up #1908).
Layer repairs for the previous red (1fa5fbd1): seed-driver (fix-sdk: sdk-canary seed pin), internals-tests (fix-literals: a repr enum is no join target for an untyped literal), cli-selfhost-build-w-tests (fix-comptime-str: project-relative evaluator-seed copies), pcre2-wo-drift/wo-drift (fix-globals c21cf63: writes-clause names count as interface mentions in the frontend .wi merge and in Sema's lazy demand; test behav_writes_clause_only_mention_of_bundle_global). |
…bundle writes clauses (#1874 #1829 #1827) (#1901) * Spec v7.11 (D78): SIMD vectors — Vector[N, T] with one-token aliases, Mask[N, W], splat where one meaning is forced, swizzles, .bits(); c_import maps C vector types (#1874) Eric ruled the design 2026-09-29 and blessed the words. §4.3d Vector Types, §16.1 C vector types, D78 in the decision log. The compiler is NON-COMPLIANT until the implementation lands; #1872's omission of C vector types stays loud until then. * Spec v7.12: the unsafe callable type is spelled `unsafe fn(A) -> R` / `unsafe extern "C" fn(A) -> R`; it never coerces to the safe type of the same signature (§16.11, #1829) Eric blessed the sentence 2026-09-29; the parser already spells it (src/Parser.w), the fixture fix on fix-cfn (86410379) follows it. * Spec v7.13 (D79): a bundle function's global writes are a declared, checked trailing `writes` clause; absent means none, verified (#1827) Eric ruled B and the spelling, and blessed the words 2026-09-29. Refines D39: a legality fact never enters an interface by inference. --------- Co-authored-by: Eric Hartford <[email protected]>
…m.select, masks, c_import of C vectors (spec v7.11, v7.14, v7.16) (#1927) * SIMD vectors: Vector[N, T], Mask[N, W], the aliases, lane-wise operators, splat, swizzles (§4.3d, D78; #1874) Sema owns every vector fact (src/SemaVector.w): TypeKind.TY_VECTOR (d0 lane, d1 N) and TY_MASK (d0 W, d1 N), the one-token aliases (f32x4 … u8x64, m8x16 … m64x8) registered for the native widths, `Vector[N, T]` / `Mask[N, W]` in type and expression position, construction (exactly N lanes), `T.splat(s)`, `T.from_bits(u)`, `.bits()`, `select(m, a, b)`, `.all()`/`.any()`, the seven reductions, `.x`…`.wzyx` swizzles for N <= 4, `v[i]` lane reads and writes (a constant index checked at compile time), lane-wise `+ - * / %`, `& | ^ << >> ~`, wrapping and saturating operators, comparisons yielding Mask[N, width(T)], lane-wise `as`, lossless lane widening under §4.2.6 and refused narrowing. A scalar broadcasts only where one meaning is forced: a literal in a vector context and a scalar operand of a lane-wise operator; `let v: f32x4 = s` is refused with the `f32x4.splat(s)` spelling. `select(` is the keyword `select` followed by `(`, so `select await` is unchanged. MIR materializes the decisions (src/MirVector.w): construction, splat and swizzle are RK_AGGREGATE of the vector type, conversions RK_CAST, and select / reductions / bitcasts SIMD_* intrinsic calls. Codegen (src/CodegenVector.w) lowers to LLVM `<N x T>` (a mask `<N x iW>` of all-ones lanes); integer lanes follow §4.2 per lane (a lane overflow panics under the default mode), and a runtime lane index out of range panics. Layout (TypeLayout.w): N x size(T) rounded up to a power of two; alignment the target's — the size, capped at 16 bytes on AArch64 as clang does, and a record holding such a vector gets the packed, padded body that places it there. C ABI (FnAbi.w, compute_fn_abi): up to 16 bytes direct in a vector register; larger, AAPCS64 passes a pointer to a caller copy and returns via sret, SysV x86_64 passes byval. Checked against clang's IR for arm64-apple-macos, aarch64-linux-gnu, x86_64-linux-gnu and x86_64-pc-windows-msvc, and on this host by calling Apple libm's _simd_cos_f4 / _simd_cos_d2 (behav_1874_simd_c_abi_darwin). with-abi.sha256 re-recorded (FnAbi.w, TypeLayout.w changed). --emit-c refuses vector types loudly; a global vector folds to a constant when its splat or construction folds (build_default_value now zero-fills a vector instead of falling back to i32 0). Not implemented, pending a ruling: a type parameter as the lane count (`fn dot[N](a: Vector[N, f32])`) — there are no value generic parameters — is refused with a diagnostic naming the gap. * c_import: C vector types import as Vector[N, T], printed as the alias (§16.1, D78; #1874, retires #1872's omission) A `vector_size` / `ext_vector_type` type translates to the With alias for the native widths (`__m128` -> f32x4, `long long` x2 -> i64x2) and to `Vector[N, T]` otherwise (`ext_vector_type(3)` -> Vector[3, f32]); the lane is the exact primitive of the C element's width and signedness. A lane With has no vector of (bool, half, long double) fails loudly as unsupported. Spec v7.11 retires the omission these tests pinned: the typedef, a record holding a vector and a function taking one now import. behav_c_import_vector_types_are_unsupported becomes behav_c_import_vector_types_import (the record is built by value and the lane read); err_c_import_vector_fn_use_is_omitted and err_c_import_vector_record_is_opaque are removed, their premise retired. behav_1874_simd_c_import checks layout against clang's sizeof/_Alignof (including a record holding a 32-byte vector, whose alignment is the target's) and calls translated inline functions taking and returning vectors. * SIMD: generic lane counts, component writes, lane widening, 128-bit lanes (§4.3d; #1874) Four places the implementation fell short of §4.3d's words: - `fn dot[N](a: Vector[N, f32], b: Vector[N, f32])` compiles and runs: a generic parameter used as a lane count binds, from the arguments, to a compile-time integer (TypeKind.TY_CONST_INT, a generic substitution only); each lane count is its own specialization. A second argument with another count is "cannot infer one lane count". Arrays `[T; N]` do not get this (no parser or Sema path for a named array length). - `v.x = 5` writes lane 0: a single component is the lane's place (MirVector.lower_vector_component_place). A multi-lane swizzle write stays refused (not specified). - Lanes follow §4.2 per lane: vectors of one lane count, kind and signedness meet at the wider lane (i32x4 + i64x4 is i64x4, f32x4 * f64x4 is f64x4; the narrower operand converts); different signedness is refused with an `as` hint, as for scalars. - i128/u128 lanes are vectors (arithmetic, bitwise, reductions, `.bits()` as u128); codegen builds lane limits at any width (Overflow's i64 helpers stop at 64 bits). * SIMD masks and lane selection per D80: m.select(a, b), mask construction, indexing and operators, W = 128 (§4.3d; #1874) - `m.select(a, b)` is a method on the mask; the `select(` parser special case is gone, so `select` is the `select await` keyword alone again (examples/async-auction.w checks; err_1874_simd_select_is_a_method pins that `select(...)` is not a call). - Masks construct (`m32x4(true, false, true, true)`, `m32x4.splat(true)`), index (`m[i]` reads a bool: SIMD_MASK_LANE, range-checked), combine with `& | ^` (a bool operand broadcasts; different widths refused with an `as` hint), negate with `not`, and convert width with `m as Mask[4, 8]`. `and`/`or` on a mask are refused (they short-circuit). Writing `m[i]` is not specified and refused. - W includes 128: Mask[N, 128] and the m128x1/2/4 aliases (and i128x1..u128x4 vector aliases for the native widths), so 128-bit lanes compare and select. - A scalar broadcasts on either side of every lane-wise operator (already so; now the spec's words): `s * v`, `0.0 < v`, `0xff & v`, `v >> 2`. * SIMD: a scalar shifted by a vector broadcasts, `2 << v` (§4.2.4, §4.3d D80; #1874) §4.2.4 lists << and >> among the bitwise operators and D80 broadcasts a scalar on either side of a lane-wise operator, so a scalar shifted by a vector is the broadcast scalar shifted lane by lane. The refusal is gone; the scalar must fit the lane without loss (a scalar shift amount stays any integer), and a literal left operand takes the vector's lane type. * SIMD mask rulings per spec v7.16 (D80 amendment); ABI v9 records vectors and masks (§4.3d; #1874) - `m[i] = b` writes a mask lane: MIR stores the mask with lane i set (SIMD_MASK_LANE_SET, range-checked; a true lane all ones). - A `bool` literal in a mask context broadcasts (`let m: m32x4 = true`). - A scalar `a` or `b` of `m.select(a, b)` broadcasts as an operator's scalar operand does, the vector type coming from the other operand or the context; two scalars with no vector context stay refused. - Refused with a diagnostic naming why: `m == n` (spell `(m ^ n).any()` or `not (m ^ n)`), mask<->vector casts and `.bits()`/`.from_bits` on a mask (a true lane is 1 or -1), `.x` components on a mask (its lanes are `m[i]`), `~m` (`not m` is the one spelling). - err_1874_simd_mask_lane_write retired (the write is now the spec's). - docs/spec/abi/with-abi.md records the vector/mask layout (§2) and the C vector call rule (§4); WITH_ABI_VERSION 9 with its history entry; with-abi.sha256 re-recorded. --------- Co-authored-by: Eric Hartford <[email protected]>
Fix three classes of
c_importfailures found while importing SDL3 headers:only:are released from the shared emitted-name table so a later full import can emit them, including escaped names. Repeated full imports deduplicate the aliases. Type-position omissions now explain the import gap, with anonly:-specific remedy for selective omissions.The selective-then-full regression is covered on every host using inline headers, alongside the original Windows UCRT fixture. Its emitted-name collisions also test deletion through a hash-table cluster and across the table boundary.
Validation on Darwin arm64, final source tree at
513fce89:src/main build :gate: green.test/behavior/*c_import*.wandtest/compile_errors/*c_import*.wfixtures pass with the fresh release compiler (host directives honored).This remains a draft in the modeled-C close-out batch. The complete stack must be assembled and its one pinned-seed battery must pass before the PR is marked ready. The latest alias/bookkeeping fixes have not yet been verified on Windows or Linux.