Skip to content

feat(rpc-types-trace): add depth-first iterator for CallFrame#3768

Merged
mattsse merged 4 commits intoalloy-rs:mainfrom
TanayK07:feat/callframe-iterator
Apr 8, 2026
Merged

feat(rpc-types-trace): add depth-first iterator for CallFrame#3768
mattsse merged 4 commits intoalloy-rs:mainfrom
TanayK07:feat/callframe-iterator

Conversation

@TanayK07
Copy link
Copy Markdown
Contributor

@TanayK07 TanayK07 commented Mar 3, 2026

Motivation

CallFrame is a recursive structure where each frame can contain nested child calls. Traversing this tree currently requires manual recursion. This PR adds an ergonomic iterator with subtree-skipping support.

Solution

Added CallFrame::iter() which returns a CallFrameIter that traverses the call tree in depth-first pre-order using an internal stack.

API

// Iterate over all frames
for call in frame.iter() {
    println!("{} -> {:?}", call.from, call.to);
}

// Skip child calls selectively
let mut iter = frame.iter();
while let Some(call) = iter.next() {
    if call.is_static_call() {
        iter.skip_children(); // don't descend into static calls
    }
}

skip_children()

Removes the children of the most recently yielded frame from the internal stack, so iteration continues with the next sibling or ancestor. This is useful for filtering out subtrees (e.g. skipping delegate calls, or only inspecting top-level calls in a trace).

Closes #2775

Add `CallFrame::iter()` which returns a `CallFrameIter` that traverses
the call tree in depth-first pre-order. The iterator supports
`skip_children()` to avoid descending into the children of the most
recently yielded frame, enabling selective subtree skipping.

Closes alloy-rs#2775
Copy link
Copy Markdown
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed locally; the iterator API, traversal behavior, docs, and tests look good.

@mattsse mattsse disabled auto-merge April 8, 2026 09:42
@mattsse mattsse merged commit 3a0aafa into alloy-rs:main Apr 8, 2026
@github-project-automation github-project-automation Bot moved this from Reviewed to Done in Alloy Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Feature] Add helper iterator for Callframe

2 participants