Repository navigation
Closed
Description
Source: PROOF-NARRATIVE.md §3 KR-6 (added in PR #23).
Claim
For every input string s, KRLAdapter.jl::parse_krl(s) and quandledb/server/krl/Parser.jl::parse_any(s) either both succeed with equal ASTs or both fail.
Why valuable
Two implementations exist by design — one for end-user code (KRLAdapter.jl, canonical), one for query-time parsing (quandledb/server/krl/, server-side). If they accept different languages, the server can run queries the canonical parser rejects, and vice versa. Soundness regression.
Assumptions
[[A-KR-6.1]]Both implementations target the same EBNF grammar (spec/grammar.ebnfv0.1.0).[[A-KR-6.2]]Both implementations share the sameTokenenumeration: keyword set, identifier shape, integer/string literal shapes.
Acceptance criteria
- Add
KRLAdapter.jl/test/differential_test.jl(or inquandledb/server/krl/test/— pick one canonical home and cross-reference). - Test corpus must include:
- Every program in
krl/examples/*.krl(4 known + any added). - Every test input from
KRLAdapter.jl/test/parser_test.jl. - Every test input from
quandledb/server/krl/test/parser_test.jl. - Random byte strings (1000 trials, length 1-200, MersenneTwister seed for reproducibility).
- Every program in
- For each input
s:r1 = try (true, KRLAdapter.parse_krl(s)) catch e (false, e) end r2 = try (true, QuandleDB.KRL.parse_any(s)) catch e (false, e) end @test r1[1] == r2[1] # same success/failure if r1[1] && r2[1] @test ast_equal(r1[2], r2[2]) # same AST shape end
-
ast_equalhelper must canonicalise across the two AST representations (the two implementations have slightly different node types — seeKRLAdapter.jl/src/parser/ast.jlvsquandledb/server/krl/Ast.jl). Either pick a common canonical form or define an explicit isomorphism. - Failures must report the smallest input that distinguishes the two parsers.
Effort
~1 day. The hard part is the ast_equal canonicaliser; both parsers produce structurally similar but not byte-equal ASTs.
Cross-references
- PROOF-NARRATIVE.md §3 KR-6
- ASSUMPTIONS.md A-KR-6.1, A-KR-6.2
- Cross-repo:
hyperpolymath/quandledbQD-10 (same obligation, mirrored).
Out of scope
- Semantic equivalence after lowering. KR-6 is about the surface ASTs only.
- Performance comparison. Worth doing separately; not in scope here.
Metadata
Metadata
Assignees
Labels
No labels
Activity
hyperpolymath commentedon Jun 1, 2026
Scoping update from KR-6 design agent (2026-06-01)
Audit revealed that the two implementations target different grammar versions:
KRLAdapter.jl— strict v0.1.0 parser. ~14 AST node types, all fromspec/grammar.ebnfv0.1.0.quandledb/server/krl/Parser.jl— v0.2+ superset parser. ~50+ AST node types including pipeline queries (KRLSource*,KRLPipeStage), 9-level expression precedence, type annotations (KRLTypehierarchy), graph patterns, etc. Not in the EBNF v0.1.0 yet.This dramatically narrows the differential test scope. The common subset is ~7 node types:
KRLProgramKRLProgramKRLBindingKRLLetStmttype_annfieldKRLGeneratorKRLGeneratorKRLIdentifierKRLVarKRLComposeKRLTensorKRLPrefixOpKRLCall(KRLVar("close"), [...])The QuandleDB parser treats
close(expr)as a function call instead of a prefix operator. That's a real semantic difference inside the v0.1.0 subset — if KRLAdapter parsesclose xasKRLPrefixOp(:close, x)but QuandleDB parses it asKRLCall(KRLVar("close"), [x]), then the canonicaliser must map them to the same form or the test should report it as a known scope difference.Updated acceptance criteria
docs/v0.1.0-subset.mdor similar that fixes which nodes are in-scope for KR-6 and which are scope-extensions on either side.ast_canonical(node)projects both into a canonical form (Vector{Tuple} with position info stripped). For the prefix-vs-call divergence, choose one canonical form and document the projection.Where the test lives
Updated recommendation:
quandledb/server/krl/test/differential_test.jl— because:krl/has no Julia project infrastructure for testing.Effort revision
Previously estimated 1 day. Revised:
ast_canonicaldesign: 1 day.The harder part is now the canonicaliser, given the prefix-vs-call divergence.
hyperpolymath commentedon Jun 1, 2026
KR-6 implementation deferral (2026-06-01)
Following the design audit (above), the implementation hit a structural blocker that doesn't change the test design but does change how/where to land it.
Blocker: cross-project Julia dependency
The differential test needs to call both
KRLAdapter.jl::parse_krlandquandledb/server/krl::Parser.jl::parse_anyfrom the same Julia process. Three options surveyed:Add KRLAdapter.jl as a path dep in
quandledb/server/Project.toml— works, mirrors howKnotTheory.jl/Skein.jlare already wired. Cost: 1-line Project.toml change + brings KRLAdapter into the server test environment. Risk: dragging KRLAdapter's full dep tree into the server build.Subprocess fan-out — write a shell harness that runs Julia twice (
julia --project=KRLAdapter.jlthenjulia --project=quandledb/server), serialises ASTs to JSON, and compares withdiff. Cost: ~50 LoC of shell. Risk: AST-shape isn't directly comparable across implementations (the agent design'sast_canonicalprojection is the right answer, but doing it via JSON serialise on each side complicates the canonicaliser).Land the canonical projection upstream in
KRLAdapter.jl— addKRLAdapter.canonical_v01(node)that any v0.1.0-subset AST projects through. Thenquandledb/server/krlcan implement the matching projection and the differential test is a simple==check. Cost: ~100 LoC across both repos. Cleanest long-term.Recommendation: Option 3
Option 3 is the right level of abstraction — the canonical projection is a SHARED contract, not a test artefact. Once
KRLAdapter.canonical_v01exists, anyone (KR-6 differential test, future v0.1.0 lints, IDE support) can use it.But it's a 2-PR sequence (upstream first, downstream after) and depends on landing changes in
KRLAdapter.jloutside the krl + quandledb + tangle focus. That makes it follow-up scope.Revised acceptance criteria
Upstream (KRLAdapter.jl)
KRLAdapter.canonical_v01(node) :: Vector{Tuple}— projects an AST node into the canonical v0.1.0 form. Strips position info; normalises naming (KRLIdentifier→Identifier); maps prefix-op vs function-call to a canonical form.canonical_v01(parse_krl(s))is deterministic.Downstream (quandledb/server/krl/test/differential_test.jl)
canonical_v01onserver/krl/Ast.jlnode types.krl/examples/*.krlfiles + every input fromKRLAdapter.jl/test/parser_test.jlthat's in the v0.1.0 subset.Effort revision
This issue stays open. The audit Agent's design is preserved above and remains the implementation reference.