You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 01137b8
Browse filesBrowse the repository at this point in the historyBrowse files
test(ast): diff the c and c++ decoders against the golden capture
Both were listed in `bindings.rb` as unrunnable, and both reasons were
wrong — as descriptions of the bindings, not just of this machine. The c
one said a dumper "would have to re-encode the same traversal as the
decoder, which is a second decoder to get wrong rather than a check", and
the cpp one said the C++ AST was "the C header's union tree under RAII
wrappers". Neither is true of the repository as it stands. `cpp` has its
own 1987-line typed AST in `cpp/include/kcl_ast.hpp` with its own inline
decoder and a `virtual const char* tag()` per variant, sharing nothing
with the C header but the language. Neither has a serializer, so both are
`:reflect`, and neither has runtime reflection, so both dumpers are a
second hand-written statement of what the header declares — which is the
same bargain the C++ `cmake` build already makes and the diff is what
catches the two drifting.
The reduction counts say the two models do land on the wire. c and cpp
differ only where the C decoder's grouping is genuinely deeper than the
Rust one: c fires R8 7 more times than cpp, all of it `Expr::Identifier`,
`Expr::Target` and `Expr::Keyword`, whose newtype payloads the C struct
holds in a named field of its own where the C++ variant holds them
directly. c fires R7 3 more times, once per `MemberOrIndex` in the
golden, because the C decoder unpacks that union into a `kind` plus a
`member` or an `index` field and the wire's `value` key has no counterpart
in it.
Three naming decisions in the c dumper are worth stating here rather than
only in its header, because each is a place where the dump could have been
made to agree by renaming something the binding owns:
* `@cls` is the C name with the `kcl_` prefix and the `_t` suffix off.
That decoration is a convention, not part of the name, and stripping
it is what keeps 24 C spellings out of `CLASS_TAGS` — a table whose
entries only undo a prefix is not an independent claim about
anything. CLASS_TAGS gains two entries instead, for the arms the C
decoder names after the union field rather than the variant.
* `LiteralType`'s four arms and `NumberLitValue`'s two are an enum and
a `value` field inside a union, not types, so they carry `@tag` and
nothing else. For `LiteralType::Int` the payload's fields are spread
as siblings of `value` rather than nested one level deeper as the
struct groups them, which is R15.
* `MemberOrIndex` keeps its own `member` / `index` field names instead
of being re-tagged into the wire's `value`. R7 (ii) is the rule that
reconciles a payload the binding kept in a single wrapper field of
its own, and firing it is the evidence the field really is the
payload's.
Neither binding introduces a real difference against the golden. Both
reach 1012/1012 objects and 3657 leaves, and both probes now resolve the
same three compiler names the scripts fall back through, so a runner
that ships only clang or only g++ is not reported as a missing toolchain.
The CI legs need no toolchain step: both decoders are self-contained, so
`hack/dump/{c,cpp}.sh` compile their sources against a stock cc / c++
already on the runner image — not `cargo build`, not `libkcl`, and not
either binding's Makefile or cmake, which build the protobuf and JNI
layers around the parts that were never in question.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
0 commit comments