Skip to content

Clojure WAM P3 port: maplist/predsort, shim encodings, G1 index (///2) - #4219

Open
s243a wants to merge 8 commits into
claude/peerhailer-exploratory-docs-aodas5from
grok/pkg-resolver-cljs-p3
Open

s243a wants to merge 8 commits into
claude/peerhailer-exploratory-docs-aodas5from
grok/pkg-resolver-cljs-p3

Conversation

@s243a

@s243a s243a commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Port uw-resolve P3 onto the Clojure WAM / nbb lane (mirrors D61 Go).

Builtin inventory (this resolver build)

Builtin Found in generated WAM? Implemented Classified
maplist/2 yes (:builtin-call) yes — meta-calls user preds yes (direct-builtin + lowered emit)
maplist/3,4 not referenced here yes yes
predsort/3 yes yes — comparator isolated yes
string_codes/2 not referenced already present (empty ''[] probed) yes
functor/3, arg/3, =../2 not referenced (arg/3 had 1 unresolved :call in an earlier emit; builtin already existed) already present yes (A3 class)
memberchk/2 not referenced already present yes

UW_WAM_WARN_UNKNOWN landed (off by default). nbb sink is js/console.error because *err* is unbound.

Runtime / register-CP hygiene

Clojure WAM state is an immutable map. invoke-at-pc-isolated clears :regs, :stack, :env-stack, unify/build stacks, :choice-points, :cut-bar, :cut-bars. Copy-back is only bindings/trail/heap/intern/next-var-id/instr-count. Last-goal :execute of maplist/predsort succeed-states so advance cannot walk into the next predicate (D61 lesson).

Compiler bug beyond builtins

  • Symptom: 54 differential divergences, all G1-sized catalogs; index_catalog failed.
  • Cause: functor_arity_string split on / and required exactly two parts. ///2 from NL is (N-1)//2 became :raw → backtrack.
  • Fix: last /<digits> segment (wam_clojure_target.pl + lowered pred-key parse).
  • Probe: gdiv in tests/core/test_clojurescript_wam_maplist_predsort.pl.

Gates

  • Corpus 51/51, B1 wall 2.078s
  • Differential 2600 cases / 0 divergences / 0 crashes — SWI 2.427s, cljs 62.332s
  • CLI 142/153 vs frozen expected.json; 66/66 cljs==js. The 11 misses are install-plan on teaching/frozen_base — live SWI resolve_layered also fails those catalogs. cli/ is frozen.
  • D49 + D54 + maplist/predsort probes green
  • All tests/core/test_clojurescript_*.pl green
  • test_wam_clojure_lowered_* green; generator lmdb.h + benchmark Cargo.toml + runtime_smoke timeout are the known env failures
  • Shared lane: 4 JS suites, CONFORMANCE_TARGETS=javascript, cli_args cljs 17/17 + 25/25, wamjs corpus 51/51

B3 index verdict

5k catalog, seed 0xc0ffee01, resolve_layered p30:

  • cljs: load 0.291s, resolve 17.619s, 2,676,284 instr = build 2,648,879 + query 27,405 (~6.6 µs/instr)
  • SWI: load 0.437s, resolve 0.018s, same 10 packages
  • vs D54 pre-P3 (~39–42s / 7.56M): ~2.2× wall. Query is ~276× fewer steps; 99% of remaining instructions are interpreted index build. Honest number: G1 wins on this slow baseline (unlike Go’s 1.04×); not wamjs’s 9.2×.

B3 census

Base: claude/peerhailer-exploratory-docs-aodas5

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

cursoragent and others added 7 commits September 5, 2026 16:33
Isolate nested goal invocation so comparator and maplist user
predicates cannot leak registers or choice points into the caller.
Rewrite unmatched call/execute of known builtins to :builtin-call
and add a loud unknown-builtin diagnostic behind UW_WAM_WARN_UNKNOWN.

Co-authored-by: johns243a <johns243a@gmail.com>
Encode and decode deb versions, alternatives groups, 3/4-ary
provides, catalog/10, and the extended blocked shapes. Scale
catalogs keep provides; bench_scale reports index-build vs query
instruction census.

Co-authored-by: johns243a <johns243a@gmail.com>
The generated core now includes catalog/10, index_catalog, and
predsort/maplist builtin-calls against the updated runtime.

Co-authored-by: johns243a <johns243a@gmail.com>
Covers maplist/2-3, predsort with compare/3 and a user comparator,
string_codes empty edge, and UW_WAM_WARN_UNKNOWN=1.

Co-authored-by: johns243a <johns243a@gmail.com>
functor_arity_string now takes the trailing /<digits> segment so
put_structure ///2 (from `(N-1)//2` in build_tree) is a real
instruction instead of :raw. wam_int_token accepts number/string/atom
so last-goal execute predsort/3 compiles on SWI 9. Execute of a
direct builtin stays :execute (rewriting it to :builtin-call made
advance walk into the next predicate). Lowered emit classifies
maplist/2-4 and predsort/3 and warns on a missing call/execute label.
nbb's unbound *err* is rewritten to js/console.error so
UW_WAM_WARN_UNKNOWN reaches the process stderr pipe.

Co-authored-by: johns243a <johns243a@gmail.com>
invoke-at-pc-isolated now clears env-stack, unify/build stacks, and
cut-bars so maplist/predsort user goals cannot leak Y-slots or stale
choice points into the caller (D61, persistent-map restatement).
Last-goal :execute of maplist/predsort succeed-states after the
builtin; unmatched execute is no longer rewritten to :builtin-call
at resolve time.

Co-authored-by: johns243a <johns243a@gmail.com>
Generated core now emits put_structure ///2; runtime carries the
isolated meta-call path and console.error warn sink. The maplist
probe also asserts `NL is (3-1)//2` and that UW_WAM_WARN_UNKNOWN
prints on an unresolved goal.

Co-authored-by: johns243a <johns243a@gmail.com>
@cursor cursor Bot changed the title Port uw-resolve P3 to Clojure WAM (maplist/predsort, shim, G1 index) Clojure WAM P3 port: maplist/predsort, shim encodings, G1 index (///2) Sep 5, 2026
Corpus 51/51, differential 2600/0, B3 17.6s with index-build vs
query instruction split. CLI residual vs frozen expected.json is
live-SWI-identical. A3 execute path now covers maplist/predsort.

Co-authored-by: johns243a <johns243a@gmail.com>
@s243a
s243a marked this pull request as ready for review September 5, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants