Repository navigation
Shen/Scheme-style KL mappings and kernel overrides - #22
Merged
Merged
Conversation
The kernel ships portable-but-slow bodies so a port can boot; Shen/Scheme (and the old SBCL port) get their speed by mapping KLambda onto host operations and replacing those bodies. Do the same here: - Native overrides (dual-registered into aot_direct) for hash, integer?, symbol?/variable?/analyse-symbol?, tuples, vectors, empty?/not/boolean?, and reader leaves. hash is re-asserted after sys.kl so put/get use the same algorithm when *property-vector* is populated. - klcompile: intern of string literals, value/set of free symbols, trap-error of value/<-address to value/or and <-address/or, more inlined primitives. Kernel symbol? is no longer inlined to is_sym(). - Regenerated kernel AOT. --kernel-tests 134/0. Do not quote a kernel-tests factor until a paired interleaved A/B against this commit's parent; same-machine mins look faster than the Sep 1 S42 baseline but that is not the repo's measurement protocol.
Soundness: - trap-error → value/or / <-address/or / <-vector/or only when the handler ignores E and operands cannot raise (no leaked ? out of the trap). - intern "true"/"false" is Bool on both the primitive and rt::intern. - hash agrees with shen_eq (Bool↔true/false, 1↔1.0); reject bound < 1. - freeze-continuation inlining refuses lambda/freeze that capture the continuation (escaping G no longer emits an unbound Rust local). - same-module seal is kernel-AOT only; overlays keep apply_direct. - native get/put distinguish uninit buckets vs assoc miss; malformed lists error instead of being rewritten. Also: native get/put/unput, <-vector/or, = specialisation, intern_kl. Kernel AOT regenerated. --kernel-tests 134/0.
Runtime cases Astra called out (trap-error using E, raising operands, hash agreeing with =, get miss, freeze captured by lambda) live in tests/scheme_mapping_soundness.rs. PERFORMANCE.md records an interleaved min-of-5 vs kernel/shen-42: min wall 11.59s → 7.29s, NEW won 4/5 pairs, high variance — directional, not a scoreboard factor.
t-star heap freezes were success continuations thawed immediately by when, shen.cut, shen.bind!, and bind. Lower those calls to run the frozen body directly instead of allocating a Shen freeze. t_star freeze closures 103 to 39. kernel-tests 134/0.
This was referenced Sep 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Shen/Scheme (and the old SBCL port that reused its compiler) is fast not only because Chez/SBCL are fast, but because:
The kernel is deliberately inefficient on hot functions so a new port can boot. Once the port is up, those bodies are cheap wins. This PR does the same two things on shen-rust.
What
Native kernel overrides (after AOT install, dual-registered into
aot_direct):hash— live beforedeclarations.klfills*property-vector*(same algorithm at populate and lookup; 0-guard so slot 0 stays the vector length)integer?(kernel is recursivemagless/integer-test?)symbol?/variable?/shen.analyse-symbol?@p/tuple?/fst/sndvector/<-vector/vector->/limitempty?/not/boolean?hdstr,shen.digit?,shen.byte->digit, case predicatesvalue/orand<-address/orare now realfns on the direct tableklcompile mappings:
(intern "foo")→intern_static(value unbound-sym)→rt::global_value(set unbound-sym V)→rt::set_global(trap-error (value X) (lambda E H))→value/or(same for<-address)empty?,cn, string ops,<-address/address->,not,boolean?,fail,intern)symbol?is not inlined tois_sym()(that was the KL primitive, not the kernel predicate)Kernel AOT regenerated (Gate 6).
Tests
--kernel-tests134/0global_value, trap-error →value/or,empty?inlinePerformance (honest)
No paired interleaved A/B against this commit's parent (repo protocol). Same-machine mins after this binary look faster than the 2026-09-01 S42 baseline (~7.9s wall / ~6.4s suite → ~4.4s / ~3.2s), but that is a cross-session comparison, not a quoteable factor. Do not put a × in the scoreboard until someone interleaves this branch vs
kernel/shen-42.Still on the same playbook
Equality specialization (
null?/eq?vs fullshen_eq),yields-boolean?so AOTifcan skipis_truthy, static globals as real Ruststatics,<-vector/orforput/get.