stdlib: load the standard library from S-lineage lib/StLib sources#37
Merged
Conversation
Retire the community stlib.kl overlay. Tarver's S41.2 (2026-07-11) refresh no longer ships the standard library as a precompiled KLambda blob; it ships Shen sources under Lib/StLib that the SBCL distribution loads into the image at install time. shen-lua now does the equivalent. - Vendor the S-lineage stdlib sources under lib/StLib/ (28 files, byte-identical to the mirror pyrex41/shen-upstream tag s41.2-pristine-20260711 / commit 11fc51b, formerly pyrex41/shen-s41.1). See lib/StLib/PROVENANCE.md. - Delete klambda/stlib.kl and drop it from the boot FILES list. - boot.lua load_stdlib(): run upstream's own install.shen (file order, factorise toggles, the package + systemf externals block) with two mechanical rewrites — relative (load "…") paths made absolute (no chdir needed), and (tc +) neutralised to (tc -) so the stdlib loads without typechecking. Called from initialise(), the single chokepoint every boot path runs (CLI, port specs, kernel certification). SHEN_NO_STDLIB=1 opts out; SHEN_STDLIB_DIR overrides the location. - Loading through the kernel's define pipeline (not raw stlib.kl defuns) registers each function's arity + shen.*lambdatable* entry, which FIXES the long-standing quirk where a bare (fn filter) / top-level (filter …) raised "fn: filter is undefined" (the old stlib.kl never called stlib.initialise, so those functions had runtime arity -1). - Single-file bundle: make-bundle.lua embeds the lib/StLib tree; load_stdlib materialises it to a temp dir at boot, so the bundle stays self-contained (and is smaller — the compact .shen sources replace the 366 KB stlib.kl). - Tests: new test/stdlib_spec.lua locks the (fn filter) / bare-(filter …) regression; library_spec.lua's "filter/take absent" assertions flipped to present-and-correct. Loaded with (tc -), so stdlib functions carry no registered type signatures — unchanged from the pre-refresh overlay. A typed stdlib (tc +) is a deliberate future option; it is slower and eagerly initialises the native typecheck drivers. Tests (LuaJIT 2.1): port specs 482/0 across 13 specs; kernel certification 134/134; bundle builds + boots standalone with stdlib live. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Retire the community
klambda/stlib.kloverlay and make the S-lineageLib/StLibShen sources the standard-library source of truth, matching how Tarver's S41.2 (2026-07-11) refresh actually ships the stdlib (as sources loaded into the image at install time, not as a precompiled KLambda blob). This is the follow-up logged by the kernel-refresh PR (#36).Headline fix: loading the stdlib through the kernel's own
(load)/definepipeline registers each function'sarityproperty +shen.*lambdatable*entry, so a bare top-level(filter …)and a first-class(fn filter)now resolve instead of raising"fn: filter is undefined". The oldstlib.klbooted as raw KL defuns and never calledstlib.initialise, so those functions had runtimearity= -1.Mechanism (chosen: load-from-source at boot)
boot.luaload_stdlib()runs upstream's owninstall.shen— its file order,factorisetoggles, and the(package stlib …)+(map (fn systemf) …)externals block — with two mechanical rewrites:(load "Sub/file.shen")paths are made absolute against the vendored dir, so no processchdiris needed (a chdir would invalidate theKLDIR-relative reads the fasl kernel-key hashing does — a real trap I hit).(tc +)toggles are neutralised to(tc -): the stdlib loads without typechecking. This matches the pre-refresh behaviour (the oldstlib.klregistered no stdlib type signatures either), is markedly faster, and keeps the native typecheck drivers deferred at boot. Functions are still fully defined and arity-registered.load_stdlib()is called frominitialise()— the single post-kernel-init chokepoint every boot path runs (CLI, port specs, kernel certification) — so the stdlib is present for all of them.SHEN_NO_STDLIB=1opts out (kernel-only embed);SHEN_STDLIB_DIRoverrides the location.Why not build-time bake / fasl cache?
I investigated caching the loaded stdlib. It is not fasl-serialisable on the refreshed kernel: the refresh registers lambda entries via
set(shen.*lambdatable*, …)/set(shen.*sigf*, …)with function-valued globals, which the faslsetrecorder can'tkdata_ser. (The old kernel usedput(name, shen.lambda-form, …), which the fasl special-cases via its "lf" record.) Rather than rewrite core fasl machinery, load-from-source at boot is the low-risk choice; each CI suite boots once, so the cost is a non-issue there. Making stdlib fasl-cacheable is a clean future optimisation.What changed
lib/StLib/(28 files, byte-identical to mirrorpyrex41/shen-upstreamtags41.2-pristine-20260711/ commit11fc51b, formerlypyrex41/shen-s41.1). Seelib/StLib/PROVENANCE.md.klambda/stlib.kl; dropped it from the bootFILESlist (kernel is now 19 vendored.kl).boot.lua:load_stdlib()+find_stdlib_dir(); wired intoinitialise().make-bundle.luaembeds thelib/StLibtree;load_stdlibmaterialises it to a temp dir at boot, so the bundle stays self-contained (and is smaller — the compact.shensources replace the 366 KBstlib.kl; kernel blob 1.48 MB → 652 KB, bundle 5.3 MB → 2.6 MB).test/stdlib_spec.lualocks the(fn filter)/ bare-(filter …)regression;test/library_spec.lua's "filter/take absent" assertions flipped to present-and-correct; registered the new spec inscripts/run-tests.lua.lib/StLib/PROVENANCE.md(new),klambda/PROVENANCE.md,klambda/README.md,README.md.Test status (LuaJIT 2.1)
make test)make certify)(fn filter)/ top-level(filter …)test/stdlib_spec.lua)bin/shen -e '(filter …)')typecheck_lazy_specNotes / trade-offs
tc -): atc +program calling e.g.filterwon't seefilter's type. Unchanged from the pre-refresh overlay. A typed stdlib (tc +) is a deliberate future option — slower, and it eagerly initialises the native typecheck drivers.load_stdlibadds ~0.6–0.9 s to a cold boot (it is not cached; see "Why not build-time bake"). Each CI suite and CLI start pays it once. Making it cacheable is the natural follow-up.Note for sibling ports
Any port tracking this kernel that loaded a precompiled
stlib.klshould switch to loading theLib/StLibsources through its owndefinepath — that is what registers arities/lambda entries and makes(fn <stdlib-fn>)work. Load withtc -for parity/speed unless a typed stdlib is wanted. Watch for thechdirvs relative-kernel-path trap if your loader chdirs.🤖 Generated with Claude Code