9339279181
Terminal iteration of the kernel-extension-mechanics milestone. Ships
the four language-level mechanisms named in the spec's § Goal:
Module.kernel + TypeDef.param-in schema, their Form-A surface,
flag-driven kernel-tier auto-injection, and generic param-in checker
enforcement with a new diagnostic.
Schema (Tasks 1+2). Module gains a `kernel: bool` field
(skip_serializing_if = is_false), TypeDef gains a
`param_in: BTreeMap<String, BTreeSet<String>>` field
(skip-if-empty, kebab-renamed to "param-in"). Both fields are
strictly additive — every pre-existing fixture's canonical-JSON hash
is bit-stable except `prelude.ail`, which intentionally gains
`(kernel)`. The struct-literal sweep covered ~104 Module sites and
~35 TypeDef sites across the workspace; the additive serde-default
covers JSON deserialise paths, only Rust struct literals broke.
Form-A surface (Tasks 3+4). `(kernel)` is a bare module-header
attribute; `(param-in (a Int Float) (b Str))` is one outer
TypeDef-body clause carrying one or more inner var-lists (OQ1
decision — mirrors `(ctors …)`, one parser arm, deterministic
BTreeMap iteration). Both round-trip Form-A → JSON → Form-A
bit-identical.
Workspace-load migration (Task 5). The hardcoded `&["prelude"]`
literal at loader.rs:108 became a `modules.values().filter(|m|
m.kernel)` derivation; `parse_prelude()` injection stays because
the prelude has no on-disk manifest in user workspaces. Prelude
now carries `(kernel)` in its source, so the new filter picks it
up automatically. Code-path migration only — observable behaviour
is identical (prelude_free_fns.rs stays green). prelude hash
re-pinned (af372f28c726f29f) with Honesty-Rule provenance comment.
WorkspaceLoadError::ReservedModuleName diagnostic prose
repurposed: any built-in kernel module name is reserved
(currently prelude + kernel_stub), not specifically prelude. CLI
mapping at main.rs updated in lockstep.
Stub crate (Task 6). New `crates/ailang-kernel-stub/` is a
zero-dependency leaf crate carrying only `pub const STUB_AIL:
&str` with the Form-A source of the kernel_stub module (one
parametric TypeDef with param-in, one ctor). The parse hop —
`parse_kernel_stub()` — lives in ailang-surface next to
parse_prelude, keeping the crate-dependency graph acyclic
(`ailang-surface → ailang-kernel-stub → ailang-core`, no
back-edge). The stub is injected unconditionally in all builds as
the ratifying fixture for the kernel-extension mechanism; future
base extensions may add more or retire the stub. Drift-pinned by
`kernel_stub_module_round_trips`.
Checker (Task 7). New `CheckError::ParamNotInRestrictedSet`
variant + code() + ctx() arms + enforcement in
`check_type_well_formed`'s Type::Con arm — generic, data-driven
from the TypeDef, mentions no specific extension type. Two
in-source tests pin both the rejection (`Str` outside `{Int,
Float}`) and the acceptance (`Int` inside) paths.
Workspace-load integration tests (Task 8). New
`workspace_kernel.rs` integration-test crate with three tests:
auto-import without explicit `(import …)` declaration, two
kernel-tier modules co-load, explicit-import-overrides-auto-
import precedence preserved. Loader is import-tree-only so the
auto-import tests use a bridge module that brings the kernel
module into the workspace via the import graph — docstring
captures the reachability nuance for future readers.
Doc-state transitions (Task 9). INDEX.md kernel-extensions row
annotation transitions from "design accepted 2026-05-28; impl in
progress" to "mechanisms milestone closed 2026-05-28; raw-buf and
series milestones pending". Whitepaper STATUS + auto-import +
param-in sections transitioned forward→present for shipped
mechanisms; forward-tense survives only in sections describing
the still-pending raw-buf/series milestones (per Honesty-Rule).
data-model contract gains anchor blocks for both new schema
fields.
Side-effect: every binary's IR snapshot now contains ~52 lines
for `drop_kernel_stub_StubT` because the stub is auto-injected
into every workspace load. Snapshots refreshed; e2e expects 4
modules per workspace (prelude + kernel_stub + entry + zero or
more user modules) instead of the previous 3.
Plan defects scrubbed in the implementation (folded back into
the planner template via the planner's self-review checklist
next time): Task 4 sample test src used fictional
`(ctors (MkT a))` list form (project grammar is per-`(ctor MkT
a)`); Task 6 original wiring would have created a cycle
ailang-surface → ailang-kernel-stub → ailang-surface (inverted —
stub crate is zero-dep, parse hop lives in surface); Task 7 in-
source tests referenced a fictional `check_type_in_module`
helper (used the existing Workspace + check_workspace
convention); Task 8 first integration test expected loader to
auto-load kernel modules from disk (loader is import-tree-only;
tests use a bridge module).
Concern-5 fix folded in pre-commit: workspace.rs ReservedModuleName
doc-prose initially said "in test/dev builds" for kernel_stub —
but stub is unconditionally injected in all builds. Doc copy
tightened to present-state per Honesty-Rule.
Stats: 0 spec-review-loops, 0 quality-review-loops, 2 sweep-script
retries on Task 2 (brace-depth bug on nested vec![Ctor{…}],
recovered via per-file checkout + rewritten anchor-on-existing-
field sweep), 1 e2e-snapshot refresh on Task 6.
154 lines
8.1 KiB
Plaintext
154 lines
8.1 KiB
Plaintext
(module prelude
|
|
(kernel)
|
|
(data Ordering
|
|
(doc "Result of a three-way comparison: LT (less than), EQ (equal), GT (greater than). Ships in milestone 23 as the codomain of Ord.compare.")
|
|
(ctor LT)
|
|
(ctor EQ)
|
|
(ctor GT))
|
|
(class Eq
|
|
(param a)
|
|
(doc "Structural equality. The class-method `eq` is the surface-level comparator; `==` as a surface name is not part of the language. Primitive instances Eq Int / Bool / Str / Unit are lowered via try_emit_primitive_instance_body in the codegen.")
|
|
(method eq
|
|
(type (fn-type (params (borrow a) (borrow a)) (ret (con Bool))))))
|
|
(instance
|
|
(class Eq)
|
|
(type (con Int))
|
|
(doc "Eq Int. Body is placeholder for round-trip stability; codegen intercept try_emit_primitive_instance_body::eq__Int emits `icmp eq i64` with the alwaysinline attribute.")
|
|
(method eq
|
|
(body (lam (params (typed x a) (typed y a)) (ret (con Bool)) (body false)))))
|
|
(instance
|
|
(class Eq)
|
|
(type (con Bool))
|
|
(doc "Eq Bool. Body is placeholder for round-trip stability; codegen intercept try_emit_primitive_instance_body::eq__Bool emits `icmp eq i1` with the alwaysinline attribute.")
|
|
(method eq
|
|
(body (lam (params (typed x a) (typed y a)) (ret (con Bool)) (body false)))))
|
|
(instance
|
|
(class Eq)
|
|
(type (con Str))
|
|
(doc "Eq Str. Body is placeholder for round-trip stability; codegen intercept try_emit_primitive_instance_body::eq__Str overrides it with a call to `@ail_str_eq` and attaches the alwaysinline attribute.")
|
|
(method eq
|
|
(body (lam (params (typed x a) (typed y a)) (ret (con Bool)) (body false)))))
|
|
(instance
|
|
(class Eq)
|
|
(type (con Unit))
|
|
(doc "Eq Unit. Unit is single-inhabitant so all values compare equal. Body is placeholder; codegen intercept try_emit_primitive_instance_body::eq__Unit emits `ret i1 1`.")
|
|
(method eq
|
|
(body (lam (params (typed x a) (typed y a)) (ret (con Bool)) (body true)))))
|
|
(class Ord
|
|
(param a)
|
|
(superclass (class Eq) (type a))
|
|
(doc "Total ordering. Ships in milestone 23 alongside Eq. `compare x y` returns LT, EQ, or GT (the three-ctor Ordering ADT also in the prelude). Decision 11's single-superclass closure requires `instance Eq T` for every `instance Ord T` — the three Ord instances below pair with the three Eq instances shipped in iter 23.2.3.")
|
|
(method compare
|
|
(type (fn-type (params (borrow a) (borrow a)) (ret (con Ordering))))))
|
|
(instance
|
|
(class Ord)
|
|
(type (con Int))
|
|
(doc "Ord Int. The lambda body shape is a placeholder for round-trip stability; the codegen intercept `try_emit_primitive_instance_body::\"compare__Int\"` emits a three-way `icmp slt` / `icmp eq` branch ladder constructing LT / EQ / GT.")
|
|
(method compare
|
|
(body (lam (params (typed x a) (typed y a)) (ret (con Ordering)) (body (term-ctor Ordering EQ))))))
|
|
(instance
|
|
(class Ord)
|
|
(type (con Bool))
|
|
(doc "Ord Bool. Body lowered via `try_emit_primitive_instance_body::\"compare__Bool\"` — `icmp ult i1` LT-test, `icmp eq i1` EQ-test, GT default.")
|
|
(method compare
|
|
(body (lam (params (typed x a) (typed y a)) (ret (con Ordering)) (body (term-ctor Ordering EQ))))))
|
|
(instance
|
|
(class Ord)
|
|
(type (con Str))
|
|
(doc "Ord Str. Body lowered via `try_emit_primitive_instance_body::\"compare__Str\"` — `call i32 @ail_str_compare(ptr, ptr)` then branch on slt-0 / eq-0 against the normalised {-1, 0, +1} return.")
|
|
(method compare
|
|
(body (lam (params (typed x a) (typed y a)) (ret (con Ordering)) (body (term-ctor Ordering EQ))))))
|
|
(class Show
|
|
(param a)
|
|
(doc "Producer of a human-readable Str representation. Ships in milestone 24 with primitive instances for Int/Bool/Str/Float; user types declare their own instance.")
|
|
(method show
|
|
(type (fn-type (params (borrow a)) (ret (own (con Str)))))))
|
|
(instance
|
|
(class Show)
|
|
(type (con Int))
|
|
(method show
|
|
(body (lam (params (typed x (con Int))) (ret (con Str)) (body (app int_to_str x))))))
|
|
(instance
|
|
(class Show)
|
|
(type (con Bool))
|
|
(method show
|
|
(body (lam (params (typed x (con Bool))) (ret (con Str)) (body (app bool_to_str x))))))
|
|
(instance
|
|
(class Show)
|
|
(type (con Str))
|
|
(method show
|
|
(body (lam (params (typed x (con Str))) (ret (con Str)) (body (app str_clone x))))))
|
|
(instance
|
|
(class Show)
|
|
(type (con Float))
|
|
(method show
|
|
(body (lam (params (typed x (con Float))) (ret (con Str)) (body (app float_to_str x))))))
|
|
(fn ne
|
|
(doc "Polymorphic disequality. `ne x y` ≡ not (eq x y). Ships in milestone 23 as the Eq-class free helper.")
|
|
(type (forall (vars a) (constraints (constraint Eq a)) (fn-type (params (borrow a) (borrow a)) (ret (con Bool)))))
|
|
(params x y)
|
|
(body (app not (app eq x y))))
|
|
(fn lt
|
|
(doc "Polymorphic strict-less-than. `lt x y` ≡ case compare x y of LT -> True; _ -> False. Ships in milestone 23 as the Ord-class free helper.")
|
|
(type (forall (vars a) (constraints (constraint Ord a)) (fn-type (params (borrow a) (borrow a)) (ret (con Bool)))))
|
|
(params x y)
|
|
(body (match (app compare x y)
|
|
(case (pat-ctor LT) true)
|
|
(case _ false))))
|
|
(fn le
|
|
(doc "Polymorphic less-than-or-equal. `le x y` ≡ case compare x y of GT -> False; _ -> True. Ships in milestone 23 as the Ord-class free helper.")
|
|
(type (forall (vars a) (constraints (constraint Ord a)) (fn-type (params (borrow a) (borrow a)) (ret (con Bool)))))
|
|
(params x y)
|
|
(body (match (app compare x y)
|
|
(case (pat-ctor GT) false)
|
|
(case _ true))))
|
|
(fn gt
|
|
(doc "Polymorphic strict-greater-than. `gt x y` ≡ case compare x y of GT -> True; _ -> False. Ships in milestone 23 as the Ord-class free helper.")
|
|
(type (forall (vars a) (constraints (constraint Ord a)) (fn-type (params (borrow a) (borrow a)) (ret (con Bool)))))
|
|
(params x y)
|
|
(body (match (app compare x y)
|
|
(case (pat-ctor GT) true)
|
|
(case _ false))))
|
|
(fn ge
|
|
(doc "Polymorphic greater-than-or-equal. `ge x y` ≡ case compare x y of LT -> False; _ -> True. Ships in milestone 23 as the Ord-class free helper.")
|
|
(type (forall (vars a) (constraints (constraint Ord a)) (fn-type (params (borrow a) (borrow a)) (ret (con Bool)))))
|
|
(params x y)
|
|
(body (match (app compare x y)
|
|
(case (pat-ctor LT) false)
|
|
(case _ true))))
|
|
(fn print
|
|
(doc "Polymorphic console-print helper. `print x` ≡ `do io/print_str (show x)` with an explicit let-binder around `show x` for heap-Str RC discipline per eob.1 Str carve-out. Ships in milestone 24 as the second half of the Show prelude.")
|
|
(type (forall (vars a) (constraints (constraint Show a)) (fn-type (params (borrow a)) (ret (con Unit)) (effects IO))))
|
|
(params x)
|
|
(body (let s (app show x) (do io/print_str s))))
|
|
(fn float_eq
|
|
(doc "IEEE Float equality. `float_eq x y` returns true iff both operands are non-NaN and bit-equal. Lowered to `fcmp oeq double` via try_emit_primitive_instance_body::float_eq with alwaysinline. Replaces the milestone-deleted polymorphic `==` on Float.")
|
|
(type (fn-type (params (con Float) (con Float)) (ret (con Bool))))
|
|
(params x y)
|
|
(body false))
|
|
(fn float_ne
|
|
(doc "IEEE Float disequality. `float_ne nan nan` returns true (unordered-or-not-equal per IEEE-754). Lowered to `fcmp une double`.")
|
|
(type (fn-type (params (con Float) (con Float)) (ret (con Bool))))
|
|
(params x y)
|
|
(body false))
|
|
(fn float_lt
|
|
(doc "IEEE Float strict less-than. `float_lt nan x` returns false for any x (unordered). Lowered to `fcmp olt double`.")
|
|
(type (fn-type (params (con Float) (con Float)) (ret (con Bool))))
|
|
(params x y)
|
|
(body false))
|
|
(fn float_le
|
|
(doc "IEEE Float less-than-or-equal. Lowered to `fcmp ole double`.")
|
|
(type (fn-type (params (con Float) (con Float)) (ret (con Bool))))
|
|
(params x y)
|
|
(body false))
|
|
(fn float_gt
|
|
(doc "IEEE Float strict greater-than. Lowered to `fcmp ogt double`.")
|
|
(type (fn-type (params (con Float) (con Float)) (ret (con Bool))))
|
|
(params x y)
|
|
(body false))
|
|
(fn float_ge
|
|
(doc "IEEE Float greater-than-or-equal. Lowered to `fcmp oge double`.")
|
|
(type (fn-type (params (con Float) (con Float)) (ret (con Bool))))
|
|
(params x y)
|
|
(body false)))
|