[FEAT][RUST] Add rust structural_visit and structural_walk. - #693
Merged
tqchen merged 20 commits intoAug 3, 2026
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Seven-Streams
force-pushed
the
main-dev/2026-07-29/rust_visitor
branch
2 times, most recently
from
July 30, 2026 17:43
600aa48 to
3163906
Compare
tlopex
approved these changes
Jul 30, 2026
Seven-Streams
force-pushed
the
main-dev/2026-07-29/rust_visitor
branch
2 times, most recently
from
July 31, 2026 01:10
baca00f to
d8a7452
Compare
tlopex
force-pushed
the
main-dev/2026-07-29/rust_visitor
branch
from
July 31, 2026 01:37
8c2314f to
bc5d8f9
Compare
Seven-Streams
force-pushed
the
main-dev/2026-07-29/rust_visitor
branch
4 times, most recently
from
August 1, 2026 02:19
1ee5724 to
00a3229
Compare
Signed-off-by: yuchuan <yuchuan.7streams@gmail.com>
Signed-off-by: tlopex <820958424@qq.com>
Signed-off-by: yuchuan <yuchuan.7streams@gmail.com>
Seven-Streams
force-pushed
the
main-dev/2026-07-29/rust_visitor
branch
from
August 2, 2026 16:46
00a3229 to
65c5a68
Compare
Signed-off-by: yuchuan <yuchuan.7streams@gmail.com>
Signed-off-by: yuchuan <yuchuan.7streams@gmail.com>
Signed-off-by: yuchuan <yuchuan.7streams@gmail.com>
Signed-off-by: yuchuan <yuchuan.7streams@gmail.com>
The walk-chain tests asserted lossless numeric matching, but VisitValue::cast matches on the FFI type tag and converts with `as` semantics. Remove the two tests and fix the WalkChainLink rustdoc that claimed exact-value matching, recommending i64/f64 links unless a deliberate narrowing is wanted. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…apache#693) Callgrind on the nested-array shape showed two per-visit costs C++ does not pay: reject_foreign_structural_visit stayed a real call (~20% of the container fast path) because its cold error-formatting body defeated the inline hint, and the split Result/WalkResult matches in visit_raw left a partially-moved temporary whose drop glue could not fold away. Split the cold body behind #[cold] #[inline(never)] and match the handler results by value in one step. Nested-array walks drop from ~1.26-1.30x of C++ to ~1.09-1.17x; reflected-object and map shapes stay at or below parity. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Seven-Streams
marked this pull request as ready for review
August 2, 2026 22:28
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
tqchen
reviewed
Aug 2, 2026
Remove test_dispatch.rs (its downstream-path and cfg checks duplicate coverage in test_structural_visit.rs; the mixed-arity handler case moves into GenericDispatchProbe as a trailing DefRegionKind argument) and drop two closure-walk tests whose behavior is already asserted by the sequence fallback, interrupt-payload, and error-context tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A refreshed summary of the API as it now stands, since it has moved since the description above was written.
structural_walk(root, walker, order)walks a value graph and dispatches typed handlers in pre- or post-order; handlers steer the traversal through the returnedWalkResult(Advance,Skip,Interrupt/InterruptWith(payload)) and may returnResult<WalkResult>to propagate errors with?. The walker can be:&mut#[dispatch(visit)]visitor (or a hand-writtenVisitDispatch) — itsvisit_*methods dispatch on argument type in source order;T(value cast), a borrowed object node&N(refcount-free subtype check), or the&VisitValuecatch-all;&mutvisitors mixed freely — tried in order with the first matching argument type winning, the analog of the variadic C++StructuralWalk(root, callbacks...)chain.Every handler shape may declare a trailing
DefRegionKindargument to receive the definition-region state:structural_visit(root, visitor)drives a hand-writtenStructuralVisitorwhen recursion itself is part of the analysis, mirroring a C++StructuralVisitorObj:visitruns for each value and controls all descent throughdefault_visit_childrenorvisit_child(child, kind), whose explicit kind argument plays the role ofWithDefRegionKind. Both entry points returnResult<Option<VisitInterrupt>>:Ok(None)means the whole graph was visited, and an interrupting handler's payload comes back inOk(Some(interrupt)):Performance
Re-measured on the current branch with the shared benchmark: Rust
structural_visit(pre-order) andstructural_walk(post-order) against the equivalent C++StructuralWalktraversals on identical object graphs, all language x style combinations checksum-asserted before timing. Medians of 30 pinned reps.Rust / C++ time ratio (lower is better; < 1 means Rust is faster):
Every combination is within 1.16x of C++, at an absolute cost of ~7-21 ns per visited value, matching C++.