From d837b304f42e1dffd7678c92a19ee1171181f2ba Mon Sep 17 00:00:00 2001 From: Yogthos Date: Sun, 14 Jun 2026 22:33:53 -0400 Subject: [PATCH] Refactor phase 0: dead code + isolated bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pure cleanup ahead of the structural phases (docs/architecture-refactor-plan.md). No behavior change except the two bug fixes, which are covered by a regression row. Dead code (all verified zero-reference or overridden): - core-resolve / core-satisfies? / core-type->str seed stubs + bindings — resolve and satisfies? are interned by install-stateful-fns! (the seed copies were shadowed); type->str was an inert SCI stub with no callers. - find defined twice in 20-coll.clj; the dead copy returned a plain vector (wrong — the live def at :787 returns a real map-entry) with a comment that contradicted it. - mark-hint (passes.clj), phs-to-struct (phm), shape-vals / ns-imports-fn (types) — unreferenced. - redundant local pad2 in javatime (module-level one already in scope). Bugs: - File.toURL stored :url but every :jolt/url method reads :spec, so a URL from (.toURL file) returned nil from all its methods. Now stores :spec (+ spec row). - pl-rest had a no-op (if (plist? r) r r); collapsed to r. - :map-shapes? was missing from the deps-image cache key — two runs differing only in map-shapes could reuse each other's image. Also dropped read-quote's unused pos param. Full gate green. --- jolt-core/clojure/core/20-coll.clj | 4 ---- jolt-core/jolt/passes.clj | 1 - src/jolt/core.janet | 10 ++-------- src/jolt/javatime.janet | 4 ++-- src/jolt/main.janet | 5 +++-- src/jolt/phm.janet | 3 --- src/jolt/plist.janet | 3 +-- src/jolt/reader.janet | 18 +++++++++--------- src/jolt/types.janet | 7 ------- test/spec/host-interop-spec.janet | 2 ++ 10 files changed, 19 insertions(+), 38 deletions(-) diff --git a/jolt-core/clojure/core/20-coll.clj b/jolt-core/clojure/core/20-coll.clj index 881aeee..95bb17d 100644 --- a/jolt-core/clojure/core/20-coll.clj +++ b/jolt-core/clojure/core/20-coll.clj @@ -343,10 +343,6 @@ ;; qualified-/simple- keyword?/symbol? moved above qualified-ident? (forward ;; references are analysis errors now — jolt-2o7.3). -;; find: the map entry [k v] when k is present (nil values included), nil -;; otherwise. contains? gives vectors-by-index for free, matching Clojure. -(defn find [m k] - (when (contains? m k) [k (get m k)])) ;; realized?: defined on the pending types only (delay/lazy-seq/future read ;; Tagged-value predicates. The constructors (atom/volatile!/...) stay in Janet, diff --git a/jolt-core/jolt/passes.clj b/jolt-core/jolt/passes.clj index 8f50542..b87afff 100644 --- a/jolt-core/jolt/passes.clj +++ b/jolt-core/jolt/passes.clj @@ -833,7 +833,6 @@ ;; tag a node (any expression, not just a :local) so the back end can specialize ;; a lookup whose SUBJECT is that node — this is what makes nested access work: ;; (:direction ray) is tagged struct, so (:r (:direction ray)) drops its guard. -(defn- mark-hint [node h] (assoc node :hint h)) ;; tag a lookup subject as a struct, carrying the complete shape when known ;; (so the back end bare-indexes) — jolt-t34 (defn- mark-struct [node t] diff --git a/src/jolt/core.janet b/src/jolt/core.janet index 6bd1f6c..7fe3376 100644 --- a/src/jolt/core.janet +++ b/src/jolt/core.janet @@ -2361,8 +2361,6 @@ # with `count`, discard the result. # assert — (assert x) / (assert x message). Throws when x is falsy. -# resolve stub — returns nil (symbols not found in Jolt's clojure.core) -(defn core-resolve [sym] nil) # shadowed by the resolve special form (needs ctx) # ns-name now lives in the Clojure collection tier (pure over get + symbol). # update lives in the Clojure kernel tier — core/00-kernel.clj. update-in stays @@ -2409,11 +2407,8 @@ :name {:jolt/type :symbol :ns nil :name name-str} :methods methods}) -(def core-satisfies? (fn [proto-sym obj] false)) - # extends? is a real overlay fn now (30-macros, over extenders). (def core-implements? (fn [& args] false)) -(def core-type->str (fn [& args] "")) # ============================================================ # Additional clojure.core functions (conformance batch) @@ -2936,14 +2931,13 @@ "not" core-not "Object" core-Object "make-protocol" core-make-protocol - "satisfies?" core-satisfies? + # satisfies?/resolve are interned by install-stateful-fns! (ctx-capturing); + # type->str was an inert SCI stub with no callers. "implements?" core-implements? - "type->str" core-type->str "volatile!" core-volatile! "Thread" core-Thread "ThreadLocal" core-ThreadLocal "IllegalStateException" core-IllegalStateException - "resolve" core-resolve "copy-core-var" core-copy-core-var "copy-var" core-copy-var "macrofy" core-macrofy diff --git a/src/jolt/javatime.janet b/src/jolt/javatime.janet index 2dcf199..2b874f7 100644 --- a/src/jolt/javatime.janet +++ b/src/jolt/javatime.janet @@ -513,7 +513,7 @@ (register-class-statics! "java.util.TimeZone" @{"getTimeZone" (fn [id] (make-tz id))}) # java.text.SimpleDateFormat: minimal formatter supporting y M d H m s tokens. - (defn- pad2 [n] (if (< n 10) (string "0" n) (string n))) + # (pad2 is the module-level helper above.) (defn- sdf-format [pattern ms utc?] (def d (os/date (math/floor (/ ms 1000)) (not utc?))) (def out @"") @@ -627,7 +627,7 @@ (when (= :directory (os/stat p :mode)) (os/dir p)))) "toPath" (fn [self] @{:jolt/type :jolt/nio-path :s (get self :path)}) "toURI" (fn [self] (string "file:" (jfile-abs (get self :path)))) - "toURL" (fn [self] @{:jolt/type :jolt/url :url (string "file:" (jfile-abs (get self :path)))}) + "toURL" (fn [self] @{:jolt/type :jolt/url :spec (string "file:" (jfile-abs (get self :path)))}) "delete" (fn [self] (let [r (protect (os/rm (get self :path)))] (truthy? (r 0)))) "mkdir" (fn [self] (truthy? ((protect (os/mkdir (get self :path))) 0))) "mkdirs" (fn [self] (truthy? ((protect (os/mkdir (get self :path))) 0))) diff --git a/src/jolt/main.janet b/src/jolt/main.janet index 46cdb54..48224fc 100644 --- a/src/jolt/main.janet +++ b/src/jolt/main.janet @@ -440,10 +440,11 @@ (defn- deps-image-path [ns-name] (def dir (or (os/getenv "JOLT_IMAGE_CACHE_DIR") (os/getenv "TMPDIR") "/tmp")) (def env (ctx :env)) - (def key (string/format "%q|%q|%q|%q|%q|%q|%q|%q" + (def key (string/format "%q|%q|%q|%q|%q|%q|%q|%q|%q" jolt-version ns-name (os/getenv "JOLT_PATH") (get env :direct-linking?) (get env :inline?) - (get env :shapes?) (get env :whole-program?) + (get env :shapes?) (get env :map-shapes?) + (get env :whole-program?) (os/getenv "JOLT_FEATURES"))) (string dir "/jolt-deps-" (band (hash key) 0x7FFFFFFF) ".jimg")) diff --git a/src/jolt/phm.janet b/src/jolt/phm.janet index 83f28f5..4d581ba 100644 --- a/src/jolt/phm.janet +++ b/src/jolt/phm.janet @@ -298,6 +298,3 @@ (defn phs-get [s x &opt default] (default default nil) (if (phm-contains? (s :phm) x) x default)) - -(defn phs-to-struct [s] - (phm-to-struct (s :phm))) diff --git a/src/jolt/plist.janet b/src/jolt/plist.janet index 066c8a2..680f3b0 100644 --- a/src/jolt/plist.janet +++ b/src/jolt/plist.janet @@ -59,8 +59,7 @@ [p] (if (or (= 0 (get p :count)) (nil? (get p :rest))) @[] - (let [r (get p :rest)] - (if (plist? r) r r)))) + (get p :rest))) (defn pl-from-indexed "Build a plist from a Janet array/tuple, preserving order. O(n)." diff --git a/src/jolt/reader.janet b/src/jolt/reader.janet index af38533..93d8690 100644 --- a/src/jolt/reader.janet +++ b/src/jolt/reader.janet @@ -605,7 +605,7 @@ (string? form) (buffer? form) (keyword? form) (and (struct? form) (= :jolt/char (form :jolt/type))))) -(defn read-quote [s pos new-pos token-sym] +(defn read-quote [s new-pos token-sym] (let [[form final-pos] (read-form s new-pos)] # Spec 02-reader S25: syntax-quote of a self-evaluating literal is the # literal, collapsed at READ time (matching Clojure's reader) — so nested @@ -702,21 +702,21 @@ # quote (= c 39) - (read-quote s pos (+ pos 1) (sym "quote")) - + (read-quote s (+ pos 1) (sym "quote")) + # syntax-quote / backtick (= c 96) - (read-quote s pos (+ pos 1) (sym "syntax-quote")) - + (read-quote s (+ pos 1) (sym "syntax-quote")) + # unquote ~ (= c 126) (if (and (< (+ pos 1) (length s)) (= (s (+ pos 1)) 64)) - (read-quote s pos (+ pos 2) (sym "unquote-splicing")) - (read-quote s pos (+ pos 1) (sym "unquote"))) - + (read-quote s (+ pos 2) (sym "unquote-splicing")) + (read-quote s (+ pos 1) (sym "unquote"))) + # deref (= c 64) - (read-quote s pos (+ pos 1) (sym "deref")) + (read-quote s (+ pos 1) (sym "deref")) # metadata (= c 94) diff --git a/src/jolt/types.janet b/src/jolt/types.janet index 998376b..591f7c5 100644 --- a/src/jolt/types.janet +++ b/src/jolt/types.janet @@ -524,12 +524,6 @@ (let [ns (ctx-find-ns ctx (ctx-current-ns ctx))] (ns :aliases))) -(defn ns-imports-fn - "Return the import map of the current namespace." - [ctx] - (let [ns (ctx-find-ns ctx (ctx-current-ns ctx))] - (ns :imports))) - (defn find-var "Resolve a symbol to a var in the current context. Looks in current namespace first, then clojure.core." @@ -652,7 +646,6 @@ (let [t @{}] (each kk (desc :jolt/shape) (put t kk (shape-get rec kk nil))) (put t k v) (table/to-struct t)))) (defn shape-count [rec] (- (length rec) 1)) (defn shape-contains? [rec k] (not (nil? (get ((in rec 0) :idx) k)))) -(defn shape-vals [rec] (tuple/slice rec 1)) # a struct snapshot of a shape-rec — the reusable bridge for ops that already # handle structs (dissoc, vals, seq, equality, print, ...) without per-op code (defn shape->struct [rec] diff --git a/test/spec/host-interop-spec.janet b/test/spec/host-interop-spec.janet index 39d228f..ad6ebaf 100644 --- a/test/spec/host-interop-spec.janet +++ b/test/spec/host-interop-spec.janet @@ -107,6 +107,8 @@ "(do (require (quote clojure.java.io)) (janet/spit \"/tmp/jolt-lineseq-spec.txt\" \"a\\nb\\n\") (vec (line-seq (clojure.java.io/reader \"/tmp/jolt-lineseq-spec.txt\"))))"] ["with-open closes shim" "97" "(with-open [r (StringReader. \"a\")] (.read r))"] + ["File.toURL methods read it back" "\"file:/tmp/x\"" + "(do (require (quote clojure.java.io)) (.toString (.toURL (clojure.java.io/file \"/tmp/x\"))))"] ["vector :import shares deftype ctor" "\"hi!\"" "(do (ns spec.nodea) (defprotocol SpecP (spec-pm [this])) (deftype SpecTN [t] SpecP (spec-pm [this] (str t \"!\"))) (ns spec.nodeb (:import [spec.nodea SpecTN])) (.spec-pm (SpecTN. \"hi\")))"])