fibers: rename ABI variant .pure -> .naked
"pure" universally means side-effect-free (GCC __attribute__((pure)), FP purity, D's pure) — the opposite of a register-clobbering context switch. The concept is "naked": no compiler-generated prologue/epilogue, body is raw asm that emits its own ret. That is the established term everywhere (LLVM's naked function attribute — which we literally emit — plus Zig callconv(.naked), Rust #[naked], GCC/Clang __attribute__ ((naked))). Rename the keyword + everything keyed off it so concept, surface, field, and the emitted LLVM attribute all agree. - ast.zig: ABI enum variant pure -> naked (+ doc). - parser: accept abi(.naked); error text updated. - IR Function.is_pure -> is_naked; type_resolver/decl/generic/pack/ emit_llvm references updated; diagnostics say abi(.naked). - examples 1800-1803 renamed *-pure-* -> *-naked-* (source + expected/ snapshots; .ir/.exit/.stdout/.stderr are byte-identical — the emitted IR is unchanged, only the keyword spelling differs). - docs (PLAN-FIBERS, CHECKPOINT-FIBERS, PLAN-POST-METATYPE, the design roadmap, the compiler-API checkpoint/design) updated; the naming rationale now records why .naked over .pure. No semantic change — pure cosmetics. Suite green (725/0).
This commit is contained in:
@@ -351,7 +351,7 @@ linkage keyword are two orthogonal annotations.
|
||||
- `abi(.x)` — ABI / calling-convention annotation in the slot **before**
|
||||
`extern`/`export`. **Unified replacement for `callconv(...)`, which is removed.**
|
||||
`ABI = { default, c, zig, pure }`: `.c` (C ABI), `.zig` (Zig-layout weld → the
|
||||
`compiler` library), `.pure` (naked asm), `.default` (unannotated). Can appear
|
||||
`compiler` library), `.naked` (naked asm), `.default` (unannotated). Can appear
|
||||
standalone (no extern) on any fn / fn-type / lambda.
|
||||
- `extern <lib>` — linkage keyword + binding source (named library).
|
||||
|
||||
@@ -363,12 +363,12 @@ What landed:
|
||||
- **Lexer/token** (`src/token.zig`, `src/lexer.zig`): `kw_callconv` → `kw_abi`,
|
||||
keyword string `"callconv"` → `"abi"`.
|
||||
- **Parser** (`src/parser.zig`): `parseOptionalCallConv` → `parseOptionalAbi`
|
||||
(parses `abi(.c|.zig|.pure)`); wired in the fn-decl postfix slot (before
|
||||
(parses `abi(.c|.zig|.naked)`); wired in the fn-decl postfix slot (before
|
||||
`extern`/`export`), the function-type-expr slot, and the lambda slot;
|
||||
`isFunctionDef`/`hasFnBodyAfterArrow` recognise `kw_abi`.
|
||||
- **AST→IR map** (`src/ir/type_resolver.zig`, `src/ir/lower/decl.zig`, `sema.zig`,
|
||||
`closure.zig`): the AST `.abi == .c` reads kept their C-ABI meaning; the
|
||||
function-type resolver maps `.zig`/`.pure` → IR `.default` (no fn-pointer-type
|
||||
function-type resolver maps `.zig`/`.naked` → IR `.default` (no fn-pointer-type
|
||||
CC for those decl-level ABIs; neither occurs in a function-TYPE position yet).
|
||||
- **CC-mismatch diagnostic** (`src/ir/lower/expr.zig`, `src/sema.zig`): the
|
||||
user-facing text `callconv(.c)` → `abi(.c)`.
|
||||
@@ -379,7 +379,7 @@ What landed:
|
||||
- **Tests**: parser unit tests in `src/parser.test.zig` — `abi(.zig) extern <lib>`
|
||||
on a fn decl (asserts `abi == .zig`, `extern_export == .extern_`, `extern_lib ==
|
||||
"compiler"`); bare `extern` leaves `abi == .default`; standalone `abi(.c)` /
|
||||
`abi(.pure)`. lexer/sema tests updated.
|
||||
`abi(.naked)`. lexer/sema tests updated.
|
||||
|
||||
`zig build` + `zig build test` green (450/450 unit + 685 corpus).
|
||||
|
||||
@@ -1656,7 +1656,7 @@ when reached (sentinels or accessor fns; see the design doc Risks).
|
||||
after `struct`. Parser unit tests (welded `Field` + plain struct), break-verified.
|
||||
Build + suite green. Parse-only sub-step (fns + structs) of Phase 1.1 complete.
|
||||
- **Phase 1.1 first sub-step + `callconv`→`abi` unification.** Parsed `abi(.zig)
|
||||
extern <lib>` on fn decls; unified `callconv` into `abi(.c|.zig|.pure)` (removed
|
||||
extern <lib>` on fn decls; unified `callconv` into `abi(.c|.zig|.naked)` (removed
|
||||
the `callconv` keyword), migrated 52 sx files + compiler diagnostics + docs +
|
||||
snapshots. Build + suite green. The original design's `extern(.zig)` single
|
||||
qualifier was split into `abi(.zig)` (ABI/layout, before extern) + `extern
|
||||
|
||||
@@ -4,57 +4,57 @@ Companion to [PLAN-FIBERS.md](PLAN-FIBERS.md). Update after every step (one step
|
||||
per the cadence rule). New corpus category: `18xx` concurrency.
|
||||
|
||||
## Last completed step
|
||||
**B1.0b (`abi(.pure)` real emission) — DONE. B1.0 complete.** Replaced the emit bail with
|
||||
**B1.0b (`abi(.naked)` real emission) — DONE. B1.0 complete.** Replaced the emit bail with
|
||||
real LLVM `naked` emission:
|
||||
- `emit_llvm` declaration pass: for `func.is_pure`, add the LLVM `naked` + `noinline` +
|
||||
- `emit_llvm` declaration pass: for `func.is_naked`, add the LLVM `naked` + `noinline` +
|
||||
`nounwind` attributes and **skip** the `frame-pointer=all` attribute (incompatible with a
|
||||
frameless function). Pass 2 now emits the `.pure` body normally — `naked` makes the
|
||||
frameless function). Pass 2 now emits the `.naked` body normally — `naked` makes the
|
||||
backend emit it verbatim (the inline asm + its own `ret`) with no prologue/epilogue.
|
||||
- IR shape (verified): `; Function Attrs: naked noinline nounwind` / `define internal i64
|
||||
@answer() #0 { entry: call void asm sideeffect "…ret…", ""() unreachable }` /
|
||||
`attributes #0 = { naked noinline nounwind }`. The caller invokes it as an ordinary
|
||||
`() -> i64` call (`.pure` is `call_conv == .default`).
|
||||
- `examples/1800-concurrency-pure-asm.sx` — now GREEN, aarch64-pinned (`.build {"target":
|
||||
`() -> i64` call (`.naked` is `call_conv == .default`).
|
||||
- `examples/1800-concurrency-naked-asm.sx` — now GREEN, aarch64-pinned (`.build {"target":
|
||||
"macos"}`): runs end-to-end → **exit 42** on this host, ir-only on a mismatch; `.ir`
|
||||
snapshot captured.
|
||||
- `examples/1801-concurrency-pure-generic.sx` (renamed from `-bail`) — the generic `.pure`
|
||||
- `examples/1801-concurrency-naked-generic.sx` (renamed from `-bail`) — the generic `.naked`
|
||||
now emits a correct naked `answer__i64` (exit 42), proving generic.zig produces a naked
|
||||
body, not a framed one. aarch64-pinned.
|
||||
- `examples/1802-concurrency-pure-asm-x86.sx` — x86_64 cross sibling (`.build {"target":
|
||||
- `examples/1802-concurrency-naked-asm-x86.sx` — x86_64 cross sibling (`.build {"target":
|
||||
"x86_64-linux"}`, ir-only here): `.ir` locks `naked` + `movl $42, %eax` / `ret`.
|
||||
- Unit test `emit: abi(.pure) function gets the naked attribute (no frame-pointer)` in
|
||||
- Unit test `emit: abi(.naked) function gets the naked attribute (no frame-pointer)` in
|
||||
`emit_llvm.test.zig` (asserts `naked` present, `frame-pointer` absent).
|
||||
- **B1.0c (review-hardening):** a param-bearing `.pure` fn emitted invalid LLVM (loud
|
||||
- **B1.0c (review-hardening):** a param-bearing `.naked` fn emitted invalid LLVM (loud
|
||||
verifier error "cannot use argument of naked function") because the param-alloca loop
|
||||
wasn't gated. Fixed forward (this *enables* the B1.3 context-switch use case rather than
|
||||
rejecting it): gated the param-alloca loop on `fd.abi != .pure` in decl.zig (both paths) +
|
||||
rejecting it): gated the param-alloca loop on `fd.abi != .naked` in decl.zig (both paths) +
|
||||
generic.zig; a naked fn's args stay in registers (read by asm), declared-but-unused in
|
||||
LLVM. Locked by `examples/1803-concurrency-pure-asm-param.sx` (`add(a,b)` → x0+x1 → 42).
|
||||
LLVM. Locked by `examples/1803-concurrency-naked-asm-param.sx` (`add(a,b)` → x0+x1 → 42).
|
||||
- `zig build && zig build test` green: **725 ran, 0 failed** + unit tests.
|
||||
|
||||
### Earlier — B1.0a (lock + review hardening)
|
||||
Plumbed `Function.is_pure` (set from `fd.abi == .pure` at both decl sites + generic.zig +
|
||||
pack.zig); `funcWantsImplicitCtx` skips `.pure` (no synthetic ctx, like `.c`); all
|
||||
body-lowering paths bypass `lowerValueBody` for `.pure` (asm body + `unreachable` cap — no sx
|
||||
Plumbed `Function.is_naked` (set from `fd.abi == .naked` at both decl sites + generic.zig +
|
||||
pack.zig); `funcWantsImplicitCtx` skips `.naked` (no synthetic ctx, like `.c`); all
|
||||
body-lowering paths bypass `lowerValueBody` for `.naked` (asm body + `unreachable` cap — no sx
|
||||
return); `emit_llvm` Pass 2 bailed loudly (since flipped to real emission). Adversarial
|
||||
review caught the generic/pack `is_pure` gap (a generic `.pure` silently shipped a framed
|
||||
body); closed + locked. The review's `.pure`-lambda CRITICAL was a false positive
|
||||
review caught the generic/pack `is_naked` gap (a generic `.naked` silently shipped a framed
|
||||
body); closed + locked. The review's `.naked`-lambda CRITICAL was a false positive
|
||||
(unparseable — `isLambda` breaks on the `abi` keyword).
|
||||
|
||||
## Current state
|
||||
Stream A (atomics) is feature-complete (✅). Stream B1: **B1.0 complete** — `abi(.pure)`
|
||||
Stream A (atomics) is feature-complete (✅). Stream B1: **B1.0 complete** — `abi(.naked)`
|
||||
emits a real LLVM `naked` function end-to-end (decl, generic, pack paths), the substrate for
|
||||
the fiber context-switch. No fibers/Io/scheduler code yet. Grounded floor facts:
|
||||
- `context` is already an implicit `*Context` param (slot 0) + `push Context` is a stack
|
||||
`alloca` ⇒ **fiber-local for free**. Only shared root = `__sx_default_context` global
|
||||
(entry-point bind). B1.1 expected to be a **library convention** (spawn trampoline
|
||||
snapshots the spawner's ctx into slot 0), **likely zero compiler change** — probe first.
|
||||
- Inline asm works end-to-end (lower→emit→JIT, aarch64 + x86_64) — the `.pure` body reuses it.
|
||||
- **`.pure` with PARAMS works** (B1.0c, the B1.3 substrate): the param-alloca loop is gated
|
||||
on `fd.abi != .pure` in decl.zig (both paths) + generic.zig — a naked fn's args stay in
|
||||
- Inline asm works end-to-end (lower→emit→JIT, aarch64 + x86_64) — the `.naked` body reuses it.
|
||||
- **`.naked` with PARAMS works** (B1.0c, the B1.3 substrate): the param-alloca loop is gated
|
||||
on `fd.abi != .naked` in decl.zig (both paths) + generic.zig — a naked fn's args stay in
|
||||
ABI registers (read by the asm body), declared-but-unused in LLVM (verifier-legal).
|
||||
Example `1803-concurrency-pure-asm-param.sx` (`add(a,b)` reads x0/x1). **Unsupported (loud,
|
||||
not silent):** a `.pure` *variadic-pack* fn (pack.zig's param loop is intertwined with
|
||||
Example `1803-concurrency-naked-asm-param.sx` (`add(a,b)` reads x0/x1). **Unsupported (loud,
|
||||
not silent):** a `.naked` *variadic-pack* fn (pack.zig's param loop is intertwined with
|
||||
comptime-param/`#insert` handling, and a naked fn can't read a runtime-sized pack from
|
||||
registers anyway) → loud LLVM-verifier error for that nonsensical construct. Acceptable
|
||||
boundary; a sharper sx diagnostic for it is a candidate polish, not a blocker.
|
||||
@@ -80,20 +80,21 @@ a checkpoint note on the convention. Only if the probe surfaces a real gap (a pa
|
||||
|
||||
## Decisions (Stream B1 specifics; surface locked in design §4 / §4.6)
|
||||
- **The async runtime is sx LIBRARY code.** The compiler provides only: the general
|
||||
primitives (inline asm ✅, `abi(.pure)` naked [B1.0], atomics ✅) + fiber-safe codegen
|
||||
primitives (inline asm ✅, `abi(.naked)` naked [B1.0], atomics ✅) + fiber-safe codegen
|
||||
(`context` already fiber-local — B1.1). Schedulers, fibers, channels, futures, `Io`
|
||||
vtables, `mmap` stacks are all sx.
|
||||
- **`abi(.pure)` is the real spelling of the design's `callconv(.naked)`** — postfix slot,
|
||||
`name :: (sig) -> Ret abi(.pure) { asm { … }; }`. B1.0 = carry it into IR + emit LLVM
|
||||
- **`abi(.naked)` is the real spelling of the design's `callconv(.naked)`** — postfix slot,
|
||||
`name :: (sig) -> Ret abi(.naked) { asm { … }; }`. B1.0 = carry it into IR + emit LLVM
|
||||
`naked` + skip prologue/ctx (mirror the existing `.c` skip), NOT extend the enum (it's
|
||||
already there, just inert).
|
||||
- **`.pure` ≠ `.c`:** a `.c` epilogue would restore SP from the wrong stack across a context
|
||||
switch (SP-in ≠ SP-out by design). `.pure` = no prologue/epilogue/frame; the asm emits its
|
||||
own `ret`. This is why the switch must be `.pure`.
|
||||
- **Naming:** sx-facing name is **`pure`** (field `is_pure`, the diagnostic). LLVM's `naked`
|
||||
function attribute is only the lowering mechanism (B1.0b) — do not call the function
|
||||
"naked" (user direction).
|
||||
- **B1.0 snapshot scope:** a `.pure` body is raw per-arch asm; LLVM's `naked` attr text is
|
||||
- **`.naked` ≠ `.c`:** a `.c` epilogue would restore SP from the wrong stack across a context
|
||||
switch (SP-in ≠ SP-out by design). `.naked` = no prologue/epilogue/frame; the asm emits its
|
||||
own `ret`. This is why the switch must be `.naked`.
|
||||
- **Naming:** sx-facing name is **`naked`** (keyword `abi(.naked)`, field `is_naked`, the
|
||||
diagnostic), matching LLVM's `naked` attribute and the industry term (Zig/Rust/GCC/Clang).
|
||||
The ABI variant was renamed `.pure → .naked` (user direction): "pure" universally means
|
||||
*side-effect-free*, the opposite of a register-clobbering context switch.
|
||||
- **B1.0 snapshot scope:** a `.naked` body is raw per-arch asm; LLVM's `naked` attr text is
|
||||
arch-invariant. **B1.0a** = one host example locked to the emit bail (host-independent —
|
||||
fires before instruction selection; no `.build` pin). **B1.0b** = pin aarch64 + add an
|
||||
x86_64 cross sibling (`.build` target-gated, ir-only on mismatch), like the asm corpus
|
||||
@@ -111,34 +112,34 @@ a checkpoint note on the convention. Only if the probe surfaces a real gap (a pa
|
||||
|
||||
## Log
|
||||
- **carve** — wrote PLAN-FIBERS.md + CHECKPOINT-FIBERS.md. Grounded the B1 compiler floor:
|
||||
`ABI.pure` inert (type_resolver.zig:237), IR `Function` has no naked flag (inst.zig:605),
|
||||
`ABI.naked` inert (type_resolver.zig:237), IR `Function` has no naked flag (inst.zig:605),
|
||||
attribute API pattern (emit_llvm.zig:1339 nounwind), `.c` ctx-skip precedent
|
||||
(decl.zig:515), `push Context` stack-alloca + slot-0 implicit ctx (stmt.zig:1263,
|
||||
lower.zig:259), `__sx_default_context` root (decl.zig:2667/2815), inline-asm corpus
|
||||
(1645/1651). Corrected the design's `callconv(.naked)` → real `abi(.pure)` spelling and
|
||||
(1645/1651). Corrected the design's `callconv(.naked)` → real `abi(.naked)` spelling and
|
||||
the B1.0 snapshot story. B1.1 grounded as likely library-only. Baseline green (721/0).
|
||||
- **B1.0a** — plumbed `Function.is_pure` (set from `fd.abi == .pure` at both decl sites);
|
||||
`funcWantsImplicitCtx` skips `.pure` (no implicit ctx, like `.c`); both body-lowering
|
||||
paths bypass `lowerValueBody` for `.pure` (asm body + `unreachable` cap — no sx return);
|
||||
`emit_llvm` Pass 2 bails loudly on `func.is_pure`. `examples/1800-concurrency-pure-asm.sx`
|
||||
locked to the bail (exit 1 + diagnostic). Renamed `is_naked`→`is_pure` per user direction
|
||||
(sx says `pure`, not "naked"; LLVM `naked` attr is only the B1.0b mechanism). Suite green
|
||||
(722/0).
|
||||
- **B1.0a** — plumbed `Function.is_naked` (set from `fd.abi == .naked` at both decl sites);
|
||||
`funcWantsImplicitCtx` skips `.naked` (no implicit ctx, like `.c`); both body-lowering
|
||||
paths bypass `lowerValueBody` for `.naked` (asm body + `unreachable` cap — no sx return);
|
||||
`emit_llvm` Pass 2 bails loudly on `func.is_naked`. `examples/1800-concurrency-naked-asm.sx`
|
||||
locked to the bail (exit 1 + diagnostic). Suite green (722/0). (ABI variant later renamed
|
||||
`.pure → .naked` — see the Naming decision above — so all `is_*`/`abi(.*)`/example names
|
||||
here read `naked`.)
|
||||
- **B1.0a review-hardening** — adversarial review found generic/pack Function-creation paths
|
||||
left `is_pure` false (silent framed body for a generic `.pure` instance — returned 42 but
|
||||
corrupted the stack). Fixed generic.zig + pack.zig (set `is_pure` + asm-only `unreachable`
|
||||
cap); locked by `examples/1801-concurrency-pure-generic-bail.sx`. The review's `.pure`-
|
||||
left `is_naked` false (silent framed body for a generic `.naked` instance — returned 42 but
|
||||
corrupted the stack). Fixed generic.zig + pack.zig (set `is_naked` + asm-only `unreachable`
|
||||
cap); locked by `examples/1801-concurrency-naked-generic-bail.sx`. The review's `.naked`-
|
||||
lambda CRITICAL was a false positive (unparseable — `isLambda` breaks on `abi`). Suite
|
||||
green (723/0).
|
||||
- **B1.0b** — real `naked` emission: emit_llvm declaration pass adds LLVM `naked`/`noinline`/
|
||||
`nounwind` + skips `frame-pointer` for `func.is_pure`; Pass 2 emits the body verbatim (no
|
||||
`nounwind` + skips `frame-pointer` for `func.is_naked`; Pass 2 emits the body verbatim (no
|
||||
prologue). `1800` green aarch64-pinned (exit 42 + `.ir`); renamed `1801` → `-generic`
|
||||
(generic `.pure` emits a naked body, exit 42); added x86_64 sibling `1802` (ir-only, `.ir`
|
||||
(generic `.naked` emits a naked body, exit 42); added x86_64 sibling `1802` (ir-only, `.ir`
|
||||
locks `naked` + `movl $42, %eax`). Unit test asserts `naked` present + `frame-pointer`
|
||||
absent. Suite green (724/0).
|
||||
- **B1.0c** — review-hardening: param-bearing `.pure` emitted invalid LLVM (loud verifier
|
||||
error). Gated the param-alloca loop on `fd.abi != .pure` (decl.zig both paths + generic.zig)
|
||||
- **B1.0c** — review-hardening: param-bearing `.naked` emitted invalid LLVM (loud verifier
|
||||
error). Gated the param-alloca loop on `fd.abi != .naked` (decl.zig both paths + generic.zig)
|
||||
— naked args stay in registers, read by the asm body (the B1.3 context-switch shape).
|
||||
Locked by `examples/1803-concurrency-pure-asm-param.sx`. Pack `.pure` left unsupported
|
||||
Locked by `examples/1803-concurrency-naked-asm-param.sx`. Pack `.naked` left unsupported
|
||||
(loud, nonsensical). **B1.0 complete.** Suite green (725/0). **Next: B1.1 (per-fiber
|
||||
context, probe-first).**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# PLAN-FIBERS — Stream B1 (fibers + Io + M:1 scheduler)
|
||||
|
||||
> **STATUS: 🚧 in progress.** B1.0 (`abi(.pure)` codegen) ✅ complete — emits a real LLVM
|
||||
> **STATUS: 🚧 in progress.** B1.0 (`abi(.naked)` codegen) ✅ complete — emits a real LLVM
|
||||
> `naked` function end-to-end (decl / generic / pack paths; examples 1800/1801/1802 + unit
|
||||
> test). Next step = **B1.1** (per-fiber `context` root — probe-first, likely library-only).
|
||||
|
||||
@@ -12,7 +12,7 @@ separate carve ([PLAN-CHANNELS.md], when reached) and depends on this + atomics
|
||||
|
||||
**Goal:** the colorblind, stackful, **pure-sx** async runtime — fibers behind an `Io`
|
||||
interface, an M:1 scheduler, blocking + deterministic-sim + event-loop `Io` impls. The
|
||||
**compiler floor is small and net-new**: make `abi(.pure)` actually emit an LLVM `naked`
|
||||
**compiler floor is small and net-new**: make `abi(.naked)` actually emit an LLVM `naked`
|
||||
function (B1.0), and confirm/close the per-fiber `context` root (B1.1). **Everything
|
||||
else — the context-switch asm, fiber bootstrap, `mmap` stacks, the scheduler, futures,
|
||||
the `Io` vtables — is ordinary sx library code** (design §4, §4.4). The irreducible FFI
|
||||
@@ -30,25 +30,27 @@ authorization.
|
||||
|
||||
## Design (grounded against the tree)
|
||||
|
||||
### B1.0 — `abi(.pure)` codegen (the one genuinely net-new compiler piece in B1)
|
||||
### B1.0 — `abi(.naked)` codegen (the one genuinely net-new compiler piece in B1)
|
||||
|
||||
The design doc spells this `callconv(.naked)`; the **real sx surface is `abi(.pure)`** —
|
||||
written in the postfix slot, `name :: (sig) -> Ret abi(.pure) { asm { … }; }` (cf.
|
||||
The design doc spells this `callconv(.naked)`; the **real sx surface is `abi(.naked)`** —
|
||||
written in the postfix slot, `name :: (sig) -> Ret abi(.naked) { asm { … }; }` (cf.
|
||||
`build_options :: () -> BuildOptions abi(.compiler);` in [build.sx:28](../library/modules/build.sx#L28)).
|
||||
The sx-facing name is **pure** throughout (field, flag, diagnostics); LLVM's `naked`
|
||||
function attribute is only the *lowering mechanism* (B1.0b), not what we call the function.
|
||||
The sx-facing name is **`naked`** throughout (keyword, field `is_naked`, diagnostics) —
|
||||
matching LLVM's `naked` attribute (the lowering mechanism) and the industry term
|
||||
(Zig/Rust/GCC/Clang). The ABI variant was renamed `.pure → .naked`: "pure" universally
|
||||
means *side-effect-free*, the opposite of a register-clobbering context switch.
|
||||
|
||||
**Grounding (verified — do not re-derive):**
|
||||
- The `ABI` enum **already carries `.pure`** — `ABI = enum { default, c, compiler, pure }`
|
||||
([ast.zig:142](../src/ast.zig#L142)), documented "pure / naked function (inline asm
|
||||
- The `ABI` enum **already carries `.naked`** — `ABI = enum { default, c, compiler, naked }`
|
||||
([ast.zig:142](../src/ast.zig#L142)), documented "naked function (inline asm
|
||||
body), no calling-convention prologue/epilogue." So B1.0 is **NOT** "extend the enum."
|
||||
- `.pure` is **inert today**: [type_resolver.zig:237](../src/ir/type_resolver.zig#L237)
|
||||
maps `.compiler, .pure → .default` CC, and `emit_llvm` emits **no LLVM `naked`
|
||||
attribute**. So the net-new work is exactly: **carry `abi == .pure` into the IR
|
||||
- `.naked` is **inert today**: [type_resolver.zig:237](../src/ir/type_resolver.zig#L237)
|
||||
maps `.compiler, .naked → .default` CC, and `emit_llvm` emits **no LLVM `naked`
|
||||
attribute**. So the net-new work is exactly: **carry `abi == .naked` into the IR
|
||||
`Function`, emit LLVM's `naked` attr, and skip the implicit-`Context` / prologue
|
||||
lowering** so the body is just the asm block + its own `ret`.
|
||||
- The IR `Function` struct ([inst.zig:605](../src/ir/inst.zig#L605)) carries `call_conv`
|
||||
(default/c) + `is_compiler_domain`, but **no pure flag** — add one (`is_pure: bool`).
|
||||
(default/c) + `is_compiler_domain`, but **no naked flag** — add one (`is_naked: bool`).
|
||||
- Attribute API is in-tree: `nounwind` is set at
|
||||
[emit_llvm.zig:1339](../src/ir/emit_llvm.zig#L1339) via
|
||||
`LLVMGetEnumAttributeKindForName("nounwind", 8)` → `LLVMCreateEnumAttribute(ctx, id, 0)`
|
||||
@@ -56,24 +58,24 @@ function attribute is only the *lowering mechanism* (B1.0b), not what we call th
|
||||
is the same shape: `LLVMGetEnumAttributeKindForName("naked", 5)`.
|
||||
- The `.c` ABI **already skips the implicit ctx** at lowering — `lam.abi == .c` /
|
||||
`fd.abi == .c` gates (closure.zig:171, [decl.zig:515](../src/ir/lower/decl.zig#L515)).
|
||||
`.pure` must skip it **too** (a `.pure` fn gets no synthetic `__sx_ctx`, no stack frame,
|
||||
`.naked` must skip it **too** (a `.naked` fn gets no synthetic `__sx_ctx`, no stack frame,
|
||||
no prologue — args arrive in ABI registers and are read directly from asm). The
|
||||
implicit-return machinery (`lowerValueBody`) must also be bypassed: a `.pure` body has no
|
||||
implicit-return machinery (`lowerValueBody`) must also be bypassed: a `.naked` body has no
|
||||
sx return (the asm rets itself), so lower its statements and cap the block with
|
||||
`unreachable`.
|
||||
- **Inline asm already works end-to-end** (lower→emit→JIT): aarch64
|
||||
([examples/1645](../examples/1645-platform-asm-aarch64-add.sx)), x86_64
|
||||
([examples/1651](../examples/1651-platform-asm-x86-syscall-write.sx)), global asm, JIT
|
||||
([1653](../examples/1653-platform-asm-global-jit.sx)). `emitInlineAsm` /
|
||||
`LLVMGetInlineAsm` at [ops.zig:915](../src/backend/llvm/ops.zig#L915). The `.pure` body
|
||||
`LLVMGetInlineAsm` at [ops.zig:915](../src/backend/llvm/ops.zig#L915). The `.naked` body
|
||||
is a single asm block reusing this path.
|
||||
|
||||
**`.pure` ≠ `.c` (design §4.6 context-switch note):** a `.c` epilogue restores SP from the
|
||||
**`.naked` ≠ `.c` (design §4.6 context-switch note):** a `.c` epilogue restores SP from the
|
||||
frame; a context switch deliberately makes SP-in ≠ SP-out, so the `.c` epilogue would
|
||||
restore from the *wrong* stack. `.pure` = no prologue/epilogue/frame — the asm emits its
|
||||
own `ret`. This is *why* the switch must be `.pure`, not `.c`.
|
||||
restore from the *wrong* stack. `.naked` = no prologue/epilogue/frame — the asm emits its
|
||||
own `ret`. This is *why* the switch must be `.naked`, not `.c`.
|
||||
|
||||
**Snapshot story (per the atomics precedent):** a `.pure` fn's *body is raw per-arch asm*
|
||||
**Snapshot story (per the atomics precedent):** a `.naked` fn's *body is raw per-arch asm*
|
||||
(it can't be portable — that's the point), while LLVM's `naked` attribute text is
|
||||
arch-invariant. **B1.0a** (lock) needs only **one host example** locked to the emit bail —
|
||||
the bail fires at the function level *before* any asm/instruction selection, so it is
|
||||
@@ -133,18 +135,18 @@ compiler work.** Prerequisite of B1.3 (a fiber needs a valid root before it swit
|
||||
don't churn every snapshot.
|
||||
|
||||
### Files the compiler floor touches (B1.0 only; B1.1–B1.5 are library + tests)
|
||||
B1.0 (`.pure`) forces these plumbing sites:
|
||||
- [ast.zig:142](../src/ast.zig#L142) — `ABI.pure` (exists; reference only).
|
||||
- [inst.zig:605](../src/ir/inst.zig#L605) — add `is_pure: bool = false` to `Function`.
|
||||
- [decl.zig](../src/ir/lower/decl.zig) — set `is_pure` from `fd.abi == .pure`; gate the
|
||||
implicit-ctx off for `.pure` in `funcWantsImplicitCtx` (mirror the `.c` skip at
|
||||
decl.zig:515) and bypass `lowerValueBody` for `.pure` bodies (lower statements + cap with
|
||||
`unreachable`, in both body-lowering paths) — a `.pure` fn binds no ctx and has no sx
|
||||
B1.0 (`.naked`) forces these plumbing sites:
|
||||
- [ast.zig:142](../src/ast.zig#L142) — `ABI.naked` (exists; reference only).
|
||||
- [inst.zig:605](../src/ir/inst.zig#L605) — add `is_naked: bool = false` to `Function`.
|
||||
- [decl.zig](../src/ir/lower/decl.zig) — set `is_naked` from `fd.abi == .naked`; gate the
|
||||
implicit-ctx off for `.naked` in `funcWantsImplicitCtx` (mirror the `.c` skip at
|
||||
decl.zig:515) and bypass `lowerValueBody` for `.naked` bodies (lower statements + cap with
|
||||
`unreachable`, in both body-lowering paths) — a `.naked` fn binds no ctx and has no sx
|
||||
return.
|
||||
- [type_resolver.zig:237](../src/ir/type_resolver.zig#L237) — leave CC `.default` (a `.pure`
|
||||
fn-pointer type has no CC of its own; pureness is a decl-level emit attribute).
|
||||
- [type_resolver.zig:237](../src/ir/type_resolver.zig#L237) — leave CC `.default` (a `.naked`
|
||||
fn-pointer type has no CC of its own; nakedness is a decl-level emit attribute).
|
||||
- [emit_llvm.zig:402](../src/ir/emit_llvm.zig#L402) Pass 2 — **B1.0a:** bail loudly when
|
||||
`func.is_pure` (build-gating). **B1.0b:** instead emit LLVM's `naked` attr (shape per
|
||||
`func.is_naked` (build-gating). **B1.0b:** instead emit LLVM's `naked` attr (shape per
|
||||
`nounwind` at emit_llvm.zig:1339) + the asm-only body (no prologue).
|
||||
- Any `.op`/`Function`-field switch the Zig build flags — let the build tell you.
|
||||
|
||||
@@ -152,25 +154,25 @@ B1.0 (`.pure`) forces these plumbing sites:
|
||||
|
||||
## Phases (xfail→green steps)
|
||||
|
||||
### B1.0 — `abi(.pure)` codegen — ✅ COMPLETE
|
||||
- **B1.0a (lock) — ✅ DONE.** Carried `abi == .pure` into IR `Function.is_pure`; threaded
|
||||
through `decl.zig` (`funcWantsImplicitCtx` skips `.pure` like `.c`; all body-lowering paths
|
||||
bypass `lowerValueBody` for `.pure`, lowering the asm body + capping with `unreachable`) +
|
||||
generic.zig + pack.zig; `emit_llvm` Pass 2 bailed loudly on `func.is_pure`. Locked by
|
||||
`examples/1800-concurrency-pure-asm.sx` + the generic regression (review-found gap).
|
||||
### B1.0 — `abi(.naked)` codegen — ✅ COMPLETE
|
||||
- **B1.0a (lock) — ✅ DONE.** Carried `abi == .naked` into IR `Function.is_naked`; threaded
|
||||
through `decl.zig` (`funcWantsImplicitCtx` skips `.naked` like `.c`; all body-lowering paths
|
||||
bypass `lowerValueBody` for `.naked`, lowering the asm body + capping with `unreachable`) +
|
||||
generic.zig + pack.zig; `emit_llvm` Pass 2 bailed loudly on `func.is_naked`. Locked by
|
||||
`examples/1800-concurrency-naked-asm.sx` + the generic regression (review-found gap).
|
||||
- **B1.0b (green) — ✅ DONE.** `emit_llvm` declaration pass adds LLVM `naked` + `noinline` +
|
||||
`nounwind` for `func.is_pure` and skips `frame-pointer=all` (incompatible with a frameless
|
||||
`nounwind` for `func.is_naked` and skips `frame-pointer=all` (incompatible with a frameless
|
||||
function); Pass 2 emits the body normally (`naked` ⇒ verbatim asm + own `ret`, no
|
||||
prologue). `1800` pinned aarch64 → exit 42 + `.ir`; `1801-concurrency-pure-generic.sx`
|
||||
prologue). `1800` pinned aarch64 → exit 42 + `.ir`; `1801-concurrency-naked-generic.sx`
|
||||
(renamed from `-bail`) proves the generic path emits a naked body (exit 42);
|
||||
`1802-concurrency-pure-asm-x86.sx` x86_64 cross sibling (ir-only here, `.ir` locks `naked`
|
||||
+ `movl $42, %eax`). Unit test `emit: abi(.pure) function gets the naked attribute` asserts
|
||||
`1802-concurrency-naked-asm-x86.sx` x86_64 cross sibling (ir-only here, `.ir` locks `naked`
|
||||
+ `movl $42, %eax`). Unit test `emit: abi(.naked) function gets the naked attribute` asserts
|
||||
`naked` present + `frame-pointer` absent. Suite green (724/0).
|
||||
- **B1.0c (review-hardening) — ✅ DONE.** A param-bearing `.pure` fn emitted invalid LLVM
|
||||
(loud verifier error). Gated the param-alloca loop on `fd.abi != .pure` (decl.zig both
|
||||
- **B1.0c (review-hardening) — ✅ DONE.** A param-bearing `.naked` fn emitted invalid LLVM
|
||||
(loud verifier error). Gated the param-alloca loop on `fd.abi != .naked` (decl.zig both
|
||||
paths + generic.zig) so a naked fn's args stay in registers (read by the asm body) — this
|
||||
*enables* B1.3's `swap_context(from, to)`. Locked by `1803-concurrency-pure-asm-param.sx`.
|
||||
Pack `.pure` (variadic + naked, nonsensical) left unsupported → loud verifier error.
|
||||
*enables* B1.3's `swap_context(from, to)`. Locked by `1803-concurrency-naked-asm-param.sx`.
|
||||
Pack `.naked` (variadic + naked, nonsensical) left unsupported → loud verifier error.
|
||||
|
||||
### B1.1 — per-fiber `context` root (probe-first; likely zero compiler change)
|
||||
- **B1.1a (probe + lock)** — write a probe (`.sx-tmp/`) + an `18xx` example that snapshots a
|
||||
@@ -207,7 +209,7 @@ asserting program-emitted ordering contracts.
|
||||
---
|
||||
|
||||
## Gates
|
||||
- **B1.0:** unit `emit_llvm.test.zig` (the `naked` attr present on a `.pure` fn); two
|
||||
- **B1.0:** unit `emit_llvm.test.zig` (the `naked` attr present on a `.naked` fn); two
|
||||
arch-gated examples (aarch64 + x86_64) run end-to-end on a matching host, ir-only on a
|
||||
mismatch (assert `naked` + asm in `.ir`). **OUT of corpus scope, stated loudly:** the
|
||||
*correctness* of any hand-written register save/restore — that's the B1.3 stress harness.
|
||||
@@ -220,24 +222,24 @@ asserting program-emitted ordering contracts.
|
||||
- **B1.5:** `18xx` ordering-contract snapshots under the deterministic `Io`.
|
||||
|
||||
## Kickoff prompt (B1.0b — paste into a fresh session)
|
||||
> Implement Stream B1 step **B1.0b** (`abi(.pure)` real emission) per
|
||||
> Implement Stream B1 step **B1.0b** (`abi(.naked)` real emission) per
|
||||
> `current/PLAN-FIBERS.md`. Verify `zig build && zig build test` is green first (B1.0a is
|
||||
> already landed: `Function.is_pure` plumbed, `decl.zig` skips ctx + bypasses implicit-return
|
||||
> for `.pure`, `emit_llvm` Pass 2 bails loudly, `examples/1800-concurrency-pure-asm.sx`
|
||||
> already landed: `Function.is_naked` plumbed, `decl.zig` skips ctx + bypasses implicit-return
|
||||
> for `.naked`, `emit_llvm` Pass 2 bails loudly, `examples/1800-concurrency-naked-asm.sx`
|
||||
> locked to the bail). Then: (1) in `src/ir/emit_llvm.zig` Pass 2 (~line 402), REPLACE the
|
||||
> `func.is_pure` bail with real emission — set LLVM's `naked` attribute on the function
|
||||
> `func.is_naked` bail with real emission — set LLVM's `naked` attribute on the function
|
||||
> (`LLVMGetEnumAttributeKindForName("naked", 5)` → `LLVMCreateEnumAttribute(ctx, id, 0)` →
|
||||
> `LLVMAddAttributeAtIndex(llvm_func, -1, attr)`; shape per the `nounwind` set at
|
||||
> emit_llvm.zig:1339) and emit the `.pure` body as its asm block only, no prologue/epilogue
|
||||
> emit_llvm.zig:1339) and emit the `.naked` body as its asm block only, no prologue/epilogue
|
||||
> (the body already lowers to the inline-asm op + an `unreachable` terminator). (2) Pin
|
||||
> `examples/1800-concurrency-pure-asm.sx` aarch64 with a `.build` sidecar
|
||||
> `examples/1800-concurrency-naked-asm.sx` aarch64 with a `.build` sidecar
|
||||
> `{"target":"aarch64-macos"}`; on this aarch64 host it runs end-to-end (exit 42), capture
|
||||
> `.ir` + regen (`-Dname=examples/1800-concurrency-pure-asm.sx -Dupdate-goldens`), review the
|
||||
> `.ir` + regen (`-Dname=examples/1800-concurrency-naked-asm.sx -Dupdate-goldens`), review the
|
||||
> diff (assert the `.ir` shows the `naked` attr + `mov x0, #42` / `ret`, NO stray error
|
||||
> text). (3) Add `examples/1802-concurrency-pure-asm-x86.sx` (x86_64 body, `.build
|
||||
> text). (3) Add `examples/1802-concurrency-naked-asm-x86.sx` (x86_64 body, `.build
|
||||
> {"target":"x86_64-linux"}`, ir-only on this host — requires its `.ir`, now producible).
|
||||
> (4) Add a unit test in `src/ir/emit_llvm.test.zig` asserting the `naked` attribute is
|
||||
> present on an `abi(.pure)` function. Confirm `zig build test` green, commit. NOTE: the
|
||||
> present on an `abi(.naked)` function. Confirm `zig build test` green, commit. NOTE: the
|
||||
> `.ir` proves the keyword + asm emitted, NOT register-save correctness (that's the B1.3
|
||||
> switch-stress harness). If you hit an UNRELATED compiler bug, file `issues/NNNN`, mark
|
||||
> `CHECKPOINT-FIBERS.md` BLOCKED, and STOP.
|
||||
|
||||
@@ -61,14 +61,14 @@ The colorblind, stackful, pure-sx async runtime (design §4). Compiler floor is
|
||||
the runtime is sx lib. Likely carved as two PLANs:
|
||||
|
||||
### B1 — Fibers + Io + M:1 (the runtime; `PLAN-FIBERS.md`) · 🚧 **CARVED** (not started; first step B1.0a)
|
||||
- B1.0 **`abi(.naked)` — make the EXISTING `.pure` ABI actually naked.** The enum
|
||||
already carries `.pure` (ast.zig:142, documented "pure/naked, no prologue/epilogue"),
|
||||
but it is an **inert label today**: `type_resolver.zig:237` maps `.pure → .default`
|
||||
- B1.0 **`abi(.naked)` — make the EXISTING `.naked` ABI actually naked.** The enum
|
||||
already carries `.naked` (ast.zig:142, documented "naked, no prologue/epilogue"),
|
||||
but it is an **inert label today**: `type_resolver.zig:237` maps `.naked → .default`
|
||||
CC and there is **zero naked-attribute emission in emit_llvm**. So B1.0 is NOT
|
||||
"extend the enum" (done) — it is "emit the LLVM `naked` attr + skip prologue/epilogue
|
||||
lowering for `.pure`," genuinely net-new. (Roadmap §7-step-4's "extend
|
||||
lowering for `.naked`," genuinely net-new. (Roadmap §7-step-4's "extend
|
||||
`CallConv {default, c}`" is stale — CallConv was renamed ABI and already gained
|
||||
`compiler`/`pure` in the compiler-API stream.) Gates the context-switch.
|
||||
`compiler`/`naked` in the compiler-API stream.) Gates the context-switch.
|
||||
- B1.1 **Per-fiber `context` root + `push Context`-stack storage.** Grounding correction:
|
||||
`context` is **already an implicit `*Context` parameter** (comptime_vm.zig:392,
|
||||
lower.zig:257 "Implicit Context parameter machinery"), **not raw TLS** — so it already
|
||||
@@ -192,7 +192,7 @@ module hazard; S2 TLS + C-constructor JIT test per host OS (the exact prior-spik
|
||||
metatype stream), deterministic-`Io` oracle calibration, `context`-fiber-local/errno
|
||||
(C — gated by the named stress harness), S2 (E), C1 args-buffer layout (D).
|
||||
- **The compiler floor stays small, but deep — net-new pieces, grounded:** atomics
|
||||
(100% net-new, no scaffolding), making `abi(.pure)` actually naked (the enum variant
|
||||
(100% net-new, no scaffolding), making `abi(.naked)` actually naked (the enum variant
|
||||
exists but is inert today), per-fiber `context` root + push-stack storage (`context`
|
||||
is already an implicit param, NOT TLS — so this is smaller/different than "repointable
|
||||
codegen" implied), `declare`/`define`/`type_info` (metatype stream — **done**), the
|
||||
|
||||
Reference in New Issue
Block a user