caa3618c3e
Second and final iteration of the intrinsic-bodies milestone. Migrates
the 13 authored prelude dummy bodies to (intrinsic), rebaselines the two
hash pins that move, and locks the registry to the source with a
bijection. Behaviour-preserving: the codegen intercepts emit identical
IR; the prelude placeholder bodies were already dead (intercepted by
name before lower_term, since raw-buf.1).
What landed (4 tasks):
Task 1 — examples/prelude.ail: 13 authored dummy bodies → (intrinsic).
7 Eq/Ord instance methods (eq Int/Bool/Str/Unit, compare
Int/Bool/Str) keep their lambda shell (params/ret = the method's
local signature, Design X); the inner (body false)/(body true)/
(body (term-ctor Ordering EQ)) becomes (intrinsic). 6 float_* fns
((body false) → (intrinsic) in the fn body slot). The honesty-rule
infraction the milestone exists to fix is now closed: no prelude
body lies about what runs.
Task 2 — hash rebaselines (the prelude bytes changed):
prelude module hash af372f28c726f29f → 2ea61ef21ebc1913
eq__Int 86ed4988438924d3 → cc7b99b63d1e44ae
eq__Bool d62d4d8c51f433f8 → fd0412f127986512
eq__Str 3d32f377c66b03e0 → fa269285754a52da
compare__Int 6d6c20520766368b → 0a02bd9effc9746c
compare__Bool 02b64e8fadc913eb → d0dc108dacf4e543
compare__Str 9645929d53cd3cc9 → d1419595dc52a456
The 4 show__* mono pins did NOT move (Show bodies are real).
Task 3 — intercepts.rs: registry_contains_all_legacy_arms (one-
directional, hardcoded 18-name list) replaced by
intercepts_bijection_with_intrinsic_markers. The in-source test
walks prelude + kernel_stub pre-mono for Term::Intrinsic markers,
recovers each marker's codegen symbol (mono_symbol(method, type) for
instance methods; the fn name for top-level float_*/answer), and
asserts a bijection over the intrinsic-backed class: (A) every
marker resolves to an INTERCEPTS entry, (B) every INTERCEPTS entry
not on the optimisation-only allowlist has a marker, plus a guard
that the allowlist names are themselves registered. The allowlist is
the 5 *__Int icmp-family entries, which intercept the monomorphised
specialisation of the real-bodied polymorphic lt/le/gt/ge/ne — an
optimisation, not a compiler-supplied body, so no marker. The pin
passing independently confirms Task 1 missed no prelude site.
Task 4 — confirmed no codegen path lowers an intercepted body (already
true since raw-buf.1: try_emit_primitive_instance_body matches by
name before f.body is inspected). Refreshed the now-accurate comment
at lib.rs:1310-1319. design/contracts/0007-honesty-rule.md needed NO
edit — it is a general present-tense rule and does not name the
prelude dummies (confirmed by grep), so editing it would have been
invented work.
Verification:
cargo test --workspace → 669 passed, 0 failed (post-.1 baseline held;
one test replaced net-0).
Behaviour-preservation ratifiers GREEN (the safety net):
eq_primitives_smoke_compiles_and_runs,
compare_primitives_smoke_prints_1_2_3_thrice (e2e.rs);
float_compare_smoke_prints_true_true_false (float_compare_smoke_e2e.rs);
eq_ord_polymorphic_runs_end_to_end (eq_ord_e2e.rs).
Bijection pin GREEN. Both hash pins GREEN at the new baselines.
bench/check.py + compile_check.py → 0 regressed.
Plan-text imprecision (no outcome impact, noted for the record): Task 1
Step 5 wrote `--test e2e` for all four ratifiers, but
float_compare_smoke_prints_true_true_false and
eq_ord_polymorphic_runs_end_to_end live in their own test targets
(float_compare_smoke_e2e.rs, eq_ord_e2e.rs). The verification-filter
self-review checked that the fn names exist, not that they sit in the
named target — a sharper form of the filter-zero discipline. The
implementer ran each in its real target; all four green.
Milestone intrinsic-bodies is now feature-complete (.1 mechanism +
.2 migration+lock). Audit + close follow.
154 lines
8.0 KiB
Plaintext
154 lines
8.0 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)) (intrinsic)))))
|
|
(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)) (intrinsic)))))
|
|
(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)) (intrinsic)))))
|
|
(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)) (intrinsic)))))
|
|
(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)) (intrinsic)))))
|
|
(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)) (intrinsic)))))
|
|
(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)) (intrinsic)))))
|
|
(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)
|
|
(intrinsic))
|
|
(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)
|
|
(intrinsic))
|
|
(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)
|
|
(intrinsic))
|
|
(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)
|
|
(intrinsic))
|
|
(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)
|
|
(intrinsic))
|
|
(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)
|
|
(intrinsic)))
|