uniquify duplicate fn params (macro _ _ expanders)

Chez rejects duplicate lambda formals, so any (fn [_ _] ...) failed to compile
— including every macro expander, whose &form/&env slots both expand to _. The
analyzer now renames each earlier duplicate param to a fresh name (Clojure binds
the last occurrence, so the earlier ones are shadowed and unreferenceable). SCI
load 162 -> 186/218.
This commit is contained in:
Yogthos 2026-06-22 00:35:16 -04:00
parent 3721423a64
commit 86aa89c832
3 changed files with 38 additions and 20 deletions

View file

@ -1,11 +1,11 @@
;; run-sci.ss — SCI conformance: load borkdude/sci's own source (vendor/sci) through
;; joltc and require its forms to compile+eval. A real-world Clojure-compatibility
;; stress test. Pure Chez, no Janet. Floor-gated like the corpus: a regression below
;; the floor (or the count today, 160/218) fails. Raise the floor as host gaps close
;; the floor (or the count today, 186/218) fails. Raise the floor as host gaps close
;; (the tail is genuine gaps — set! on vars, some macro/def shapes).
;;
;; chez --script host/chez/run-sci.ss
;; JOLT_SCI_FLOOR=N override the floor (default 160)
;; JOLT_SCI_FLOOR=N override the floor (default 186)
;; SCI_VERBOSE=1 print each failing form's error
(import (chezscheme))
@ -74,7 +74,7 @@
load-order)
(printf "\nSCI load: ~a/~a forms ok (~a fail)\n" total-ok (+ total-ok total-fail) total-fail)
(define floor (let ((s (getenv "JOLT_SCI_FLOOR"))) (if s (string->number s) 160)))
(define floor (let ((s (getenv "JOLT_SCI_FLOOR"))) (if s (string->number s) 186)))
(when (< total-ok floor)
(printf "REGRESSION: ~a forms loaded < floor ~a\n" total-ok floor))
(flush-output-port)

File diff suppressed because one or more lines are too long

View file

@ -114,9 +114,25 @@
(if ph (conj phints [nm ph]) phints)))))
{:fixed fixed :rest rest-name :hints hints :phints phints})))
;; Clojure lets a later param shadow an earlier same-named one (a macro expander
;; uses _ for both its &form and &env slots, so its param list is (_ _ …)); the
;; body binds the LAST occurrence. Chez rejects duplicate formals, so rename every
;; earlier duplicate to a fresh name — it is shadowed and unreferenceable.
(defn- uniquify-params [names]
(let [n (count names)]
(loop [i 0 out []]
(if (< i n)
(let [nm (nth names i)
dup? (loop [j (inc i)]
(cond (>= j n) false
(= nm (nth names j)) true
:else (recur (inc j))))]
(recur (inc i) (conj out (if dup? (gen-name (str nm "_")) nm))))
out))))
(defn- analyze-arity [ctx pvec body env fn-name]
(let [pp (parse-params ctx (vec (form-vec-items pvec)))
fixed (:fixed pp)
fixed (uniquify-params (:fixed pp))
rst (:rest pp)
;; Always a recur target, variadic included: the back end gives the rest
;; param an ordinary positional slot (holding the collected seq), so recur