Cross-ns def/require/use/defmethod through the spine (jolt-c2l1)

The per-form eval passed a FIXED compile-ns to every subform of a top-level do,
so a runtime (ns ...)/(in-ns ...) didn't redirect later defs/refs — defs landed
in the wrong ns and qualified refs hit host-static ("Unknown class"). Thread
the current ns: each subform analyzes in (chez-current-ns), which ns/in-ns move.

That exposed two more gaps, now fixed:
- use refers ALL of a target's public vars (a refer-all table consulted by
  chez-resolve-refer) — was bound to plain require (explicit :refer only).
- defmethod on a QUALIFIED multifn (cf.mm/ext from another ns) resolves in the
  symbol's ns, not the current one (was auto-creating a stray multifn).

Corpus 2684->2688, 0 new divergences; floor raised. No re-mint (runtime shims).
This commit is contained in:
Yogthos 2026-06-21 16:56:46 -04:00
parent 76f8274603
commit c788e86f1a
6 changed files with 50 additions and 8 deletions

View file

@ -38,8 +38,19 @@
(define ns-refer-table (make-hashtable equal-hash equal?))
(define (chez-register-refer! cns name target)
(hashtable-set! ns-refer-table (cons cns name) target))
;; refer-all (a bare `use`): cns -> list of fully-referred target ns names. A name
;; not found per-name resolves to the first refer-all target that defines it.
(define ns-refer-all-table (make-hashtable equal-hash equal?))
(define (chez-register-refer-all! cns target)
(let ((cur (hashtable-ref ns-refer-all-table cns '())))
(unless (member target cur)
(hashtable-set! ns-refer-all-table cns (cons target cur)))))
(define (chez-resolve-refer cns name)
(hashtable-ref ns-refer-table (cons cns name) #f))
(or (hashtable-ref ns-refer-table (cons cns name) #f)
(let loop ((ts (hashtable-ref ns-refer-all-table cns '())))
(cond ((null? ts) #f)
((let ((c (var-cell-lookup (car ts) name))) (and c (var-cell-defined? c))) (car ts))
(else (loop (cdr ts)))))))
;; parse a require/use spec FORM and register its :as alias + :refer names under
;; `cns`. spec: [ns :as a :refer [x y] ...] / (ns ...) / bare ns. opts are
;; keyword/value pairs after the ns symbol.