Skip to content

Commit cdde99e

Browse files
committed
fix(analyzer): D-430 — (var alias/x) resolves NS aliases + findNsOrAlias consolidation
Smell-audited: 1: corpus line infeasible for analysis-time alias semantics (a (do ...)-wrapped expr fails identically in BOTH runtimes) — e2e is the guarantee layer, noted in the D-430 row. The `var` special form's qualified path only consulted real ns names (env.findNs), so `(var al/x)` through a `:require [a :as al]` alias raised "Unable to resolve var" — the instaparse.core load blocker (core.cljc:361 `#'gll/TRACE`). Fix: alias-then-real-ns precedence (ADR-0035 D3), same as symbol resolution. Step-4 refactor: the 2-step idiom was duplicated at 5 sites (symbol/resolveQualified/binding/set!/var) — consolidated into Env.findNsOrAlias; syntax-quote + ::alias/kw excluded (alias-only, distinct semantics). e2e: var_alias / var_alias_reader / var_alias_deref / var_fqn. instaparse verified: load + parser-build + string-literal grammars parse == clj ([:S "a"]). New frontier (D-430 re-narrowed): Segment count — RT.countFrom CharSequence fallback.
1 parent 47633f0 commit cdde99e

6 files changed

Lines changed: 36 additions & 22 deletions

File tree

‎.dev/debt.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,10 +1315,10 @@ active:
13151315
barrier: "blocked-by: a reliable reproducer. 2026-06-13 attempts: 200 iterations in-process = 0 mismatches; 3000 iterations under 6x `yes` CPU load = 0 mismatches. So the race needs the gate's SPECIFIC contention (≈16 parallel cljw processes + the e2e harness preempting the agent worker vs main thread vs a cross-thread GC collect), not mere in-process concurrency or coarse CPU load. LEAD for the next attempt: agent.zig docstring flags the `send` FABRICATION WINDOW (the `[f & args]` action vector is a Zig local, not yet GC-rooted, before the queue lock — GC-ROOT note ~:35) — a cross-thread collect during that window is the prime suspect for how `await`'s completion Promise (a heap value) displaces the first action's arg. NOTE: the leaked arg `1` is an IMMEDIATE (not heap), so the corruption is at the action-VECTOR level (the vector's slot/memory), not the int — re-read fabrication-window rooting + the await barrier-action injection order. Fix only with a reproducer in hand (a rare race fixed blind cannot be verified)."
13161316
last_reviewed: "2026-06-13"
13171317
- id: "D-430"
1318-
status: "NARROWED FURTHER 2026-07-02 (session close): the core.cljc:361 failure is EXACTLY the `var` special form not resolving NS ALIASES — minimal repro `(ns a) (def x 1) (ns b (:require [a :as al])) (var al/x)` -> Unable to resolve var. Fix site: special_forms.zig analyzeVar (line ~763: `env.findNs(ns_name)` misses `current_ns` alias table; FQN + current-ns work). S-sized fix + corpus line; unblocks instaparse.core load. RE-NARROWED 2026-07-02 (was: instaparse mis-tokenization hunt). The per-run-varying garbage-bytes symbol NameError that had OVERTAKEN this row was a 3-layer GC-rooting bug family, ALL FIXED via ADR-0169 + same-arc residuals: (1) analysis/compile/deserialize-time constants unrooted until execution (AnalysisFrame + 9 seam brackets + 5 producers); (2) formToValue builder accumulators unrooted (the D-253 Form->Value asymmetry; EvalFrame'd); (3) TypeDescriptor method_table/meta had NO GC trace (= gc_rooting C8's root cause; .type_descriptor trace + markDescriptorValues). instaparse require+parser-build is now byte-DETERMINISTIC across runs. REMAINING (the actual current frontier): `(insta/parser \"S = 'a'\")` fails at instaparse core.cljc:361:21 with a deterministic Name error (the enable-tracing defn body; likely the `#'gll/TRACE` alias var-ref or :reload arg at analysis) — a plain parity gap, NOT memory-unsafe. Repro: cljw -cp ~/.gitlibs/libs/instaparse/instaparse/<sha>/src + (require 'instaparse.core). The ORIGINAL mis-tokenization investigation (GLL parse-tree divergence) is MOOT until this load-blocking gap clears — re-derive after core.cljc loads."
1318+
status: "NARROWED AGAIN 2026-07-06: the var-alias gap is FIXED (analyzeVar consults current_ns.aliases first, ADR-0035 D3 precedence; e2e phase14_var_special var_alias/var_alias_reader/var_alias_deref/var_fqn — corpus line infeasible: `(var alias/x)` is analysis-time so a `(do …)`-wrapped corpus expr fails in BOTH runtimes identically; cljw top-level-do sequential eval verified matching clj). instaparse.core now LOADS, `(insta/parser \"S = 'a'\")` builds, and string-literal grammars PARSE correctly (`[:S \"a\"]`, nested parens, == clj) — the ORIGINAL mis-tokenization divergence is GONE (was the GC-rooting family, ADR-0169). NEW FRONTIER (deterministic, reproduced 2026-07-06): grammars exercising regexp-full-parse (e.g. `A = 'a'+`) fail at gll.cljc:774 `(count text)` — text is instaparse's Segment deftype (declares CharSequence, defines length); cljw countFn's typed_instance arm lacks clj RT.countFrom's `instanceof CharSequence -> .length()` fallback -> protocol_no_satisfies. Fix: after the isPersistentCollection walk check, dispatch `-cs-length` (protocol CharSequence, host_interface.zig:175 remap) when the descriptor declares CharSequence. AFTER count: probe re-matcher/re-find with a Segment arg (clj Matcher accepts any CharSequence; cljw regex surface expects string — likely needs a toString coercion at the regex boundary). PRIOR HISTORY: 3-layer GC-rooting family fixed via ADR-0169 (AnalysisFrame; formToValue accumulators; TypeDescriptor trace); load-blocking var-alias fixed 2026-07-06."
13191319
category: "interop"
1320-
barrier: "none — repro in hand. NOT a regex-engine gap (terminals compile + match == clj, disproven). The instaparse GLL parse of the grammar string diverges from clj (mis-tokenizes 'a' as :regexp) — an open-ended instaparse-internals / GLL-engine debug (dump+diff the cfg `:rules` tree cljw vs clj). The instaparse chain's deep end; a substantial focused future push."
1321-
last_reviewed: "2026-07-02"
1320+
barrier: "none — repro in hand: cljw -cp ~/.gitlibs/libs/instaparse/instaparse/da886e71a4afa80f8b83d1d67f058b2f02cdc0e3/src, grammar `S = AB* ; AB = A B ; A = 'a'+ ; B = 'b'+`, input aaabbab. Next unit = count-on-CharSequence-deftype (S-sized, clj RT.countFrom parity), then the re-matcher CharSequence boundary probe."
1321+
last_reviewed: "2026-07-06"
13221322
- id: "D-435"
13231323
status: "open (2026-06-14, user-flagged via D-434). The dual-backend differential oracle (ADR-0005; src/lang/diff_test.zig's Fixture) is the project's correctness oracle for VM↔TreeWalk parity, BUT the Fixture is a MINIMAL runtime: it does `primitive.registerAll` + macro registration only, NOT the core.clj bootstrap. So `*out*`, `print`, `with-out-str`, and the whole clojure.core .clj surface are absent — any FULL-RUNTIME form cannot be dual-backend-diff-tested there. Today such behavior is verified single-backend (clj_corpus via `cljw -e`, which runs ONE backend) + structural arguments ('both backends call the same shared helper'). That is a real oracle-coverage HOLE: full-runtime dual-backend parity is UNVERIFIED except by hand-argument. Surfaced when D-434 (*out* writer-interop) could not get a diff case — the workaround (remove the diff test, lean on clj_corpus) is the bad smell the user caught. FINISHED FORM: a diff Fixture that bootstraps core.clj once (shared/cached so per-test cost stays low) OR a separate full-runtime dual-backend harness (run a form through both backends with the real runtime + compare), so ANY form — not just primitives — is parity-checked. Part of the D-436 大整理 epic."
13241324
category: "testing"

‎src/eval/analyzer/analyzer.zig‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -680,15 +680,12 @@ fn analyzeSymbol(
680680
}
681681
}
682682
}
683-
// Global Var resolution. Qualified symbols `s/name` first
684-
// consult the current ns's alias table (ADR-0035 D3) — alias
685-
// names take precedence over real ns names (= JVM semantics:
686-
// `(alias 'str 'clojure.string)` shadows any literal `str` ns).
683+
// Global Var resolution. Qualified symbols `s/name` resolve via
684+
// alias-then-real-ns (ADR-0035 D3 — alias names take precedence over
685+
// real ns names, = JVM semantics: `(alias 'str 'clojure.string)`
686+
// shadows any literal `str` ns).
687687
const ns = if (sym.ns) |ns_name| ns_blk: {
688-
if (env.current_ns) |here| {
689-
if (here.aliases.get(ns_name)) |aliased| break :ns_blk aliased;
690-
}
691-
if (env.findNs(ns_name)) |found| break :ns_blk found;
688+
if (env.findNsOrAlias(ns_name)) |found| break :ns_blk found;
692689
// ADR-0061: bare `Class/FIELD` static field read (no parens). The
693690
// ns head is not a Clojure ns/alias; resolve it as a Java surface
694691
// (same `resolveJavaSurface` the static-METHOD path uses) and, if
@@ -923,12 +920,7 @@ fn resolveMaybe(env: *Env, sym: SymbolRef) ?*Var {
923920
// to a plain call and its raw args were analyzed as symbols — found via
924921
// verified_projects/qbits.ex's `ex/try+`.)
925922
if (sym.ns) |ns_name| {
926-
const ns = ns_blk: {
927-
if (env.current_ns) |here| {
928-
if (here.aliases.get(ns_name)) |aliased| break :ns_blk aliased;
929-
}
930-
break :ns_blk env.findNs(ns_name) orelse return null;
931-
};
923+
const ns = env.findNsOrAlias(ns_name) orelse return null;
932924
return ns.resolveQualified(sym.name);
933925
}
934926
const ns = env.current_ns orelse return null;

‎src/eval/analyzer/bindings.zig‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ pub fn analyzeBinding(
381381
// findNs, else current ns), mirroring analyzeSymbol's global path.
382382
// `binding` rebinds an existing Var; it never declares a slot.
383383
const target_ns = if (name_sym.ns) |ns_name|
384-
(if (env.current_ns) |here| here.aliases.get(ns_name) else null) orelse
385-
env.findNs(ns_name) orelse
384+
env.findNsOrAlias(ns_name) orelse
386385
return error_catalog.raise(.namespace_unknown, binding_forms[fi].location, .{ .ns = ns_name })
387386
else
388387
env.current_ns orelse

‎src/eval/analyzer/special_forms.zig‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,10 @@ pub fn analyzeVar(
760760
if (target.data != .symbol)
761761
return error_catalog.raise(.var_arg_not_symbol, form.location, .{ .actual = target.typeName() });
762762
const sym = target.data.symbol;
763+
// Qualified `(var s/name)` resolves via alias-then-real-ns (ADR-0035 D3
764+
// precedence, same as symbol resolution) — D-430.
763765
const ns: *env_mod.Namespace = if (sym.ns) |ns_name|
764-
(env.findNs(ns_name) orelse return error_catalog.raise(.var_unresolved, form.location, .{ .sym = sym.name }))
766+
(env.findNsOrAlias(ns_name) orelse return error_catalog.raise(.var_unresolved, form.location, .{ .sym = sym.name }))
765767
else
766768
(env.current_ns orelse return error_catalog.raise(.var_unresolved, form.location, .{ .sym = sym.name }));
767769
const var_ptr = ns.resolve(sym.name) orelse
@@ -1396,8 +1398,7 @@ pub fn analyzeSetBang(
13961398
// Resolve the target Var exactly as `binding` does (qualified → alias
13971399
// then findNs, else current ns). `set!` mutates an existing Var.
13981400
const target_ns = if (name_sym.ns) |ns_name|
1399-
(if (env.current_ns) |here| here.aliases.get(ns_name) else null) orelse
1400-
env.findNs(ns_name) orelse
1401+
env.findNsOrAlias(ns_name) orelse
14011402
return error_catalog.raise(.namespace_unknown, items[1].location, .{ .ns = ns_name })
14021403
else
14031404
env.current_ns orelse

‎src/runtime/env.zig‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,19 @@ pub const Env = struct {
522522
return self.namespaces.get(name);
523523
}
524524

525+
/// Resolve a qualified symbol's ns part: the current ns's alias table
526+
/// first, then real ns names (ADR-0035 D3 — alias-over-real-ns
527+
/// precedence, matching JVM symbol resolution). The shared helper for
528+
/// every analysis site that resolves `s/name`-shaped prefixes (symbol /
529+
/// var / binding / set!); callers layer their own fallback (Java
530+
/// surface, error) on a null return.
531+
pub fn findNsOrAlias(self: *Env, name: []const u8) ?*Namespace {
532+
if (self.current_ns) |here| {
533+
if (here.aliases.get(name)) |aliased| return aliased;
534+
}
535+
return self.namespaces.get(name);
536+
}
537+
525538
/// Copy every **non-private** mapping in `from` into `to.refers`.
526539
/// Idempotent — duplicate names are silently skipped. ADR-0035 D4:
527540
/// `^:private` Vars are silently filtered (JVM `:refer :all`

‎test/e2e/phase14_var_special.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ assert_last 'var_ifn_resolve' '((resolve (quote inc)) 5)' '6'
4444
assert_last 'var_ifn_apply' '(apply (var +) [1 2 3])' '6'
4545
assert_last 'var_ifn_hof' '((resolve (quote map)) inc [1 2 3])' '(2 3 4)'
4646

47+
# --- (var alias/x): the ns part consults the current ns's alias table
48+
# first (ADR-0035 D3, same precedence as symbol resolution) — D-430.
49+
# clj: (var al/x) through a :as alias resolves and prints the REAL ns. ---
50+
assert_last 'var_alias' '(ns a) (def x 1) (ns b (:require [a :as al])) (var al/x)' "#'a/x"
51+
assert_last 'var_alias_reader' '(ns a) (def x 1) (ns b (:require [a :as al])) #'"'"'al/x' "#'a/x"
52+
assert_last 'var_alias_deref' '(ns a) (def x 1) (ns b (:require [a :as al])) (deref (var al/x))' '1'
53+
# FQN through the same path still resolves (alias precedence must not break it).
54+
assert_last 'var_fqn' '(ns a) (def x 1) (ns b) (var a/x)' "#'a/x"
55+
4756
# `@x` reader is NS-qualified so a local `deref` binding cannot capture it
4857
# (reader hygiene). cljw qualifies to the `rt` primitive ns (AD-038; clj uses
4958
# clojure.core/deref — same hygiene, cljw's canonical core ns is `rt`).

0 commit comments

Comments
 (0)