Skip to content

Conversation

@fitzgen
Copy link
Member

@fitzgen fitzgen commented Jul 15, 2025

This commit implements Tarjan's algorithm for finding strongly-connected components.

This algorithm takes O(V+E) time and uses O(V+E) space.

Tarjan's algorithm is usually presented as a recursive algorithm, but we do not trust the input and cannot recurse over it for fear of blowing the stack. Therefore, this implementation is iterative.

This will be used to do bottom-up inlining in Wasmtime's compilation orchestration.

@fitzgen fitzgen requested review from a team as code owners July 15, 2025 01:12
@fitzgen fitzgen requested review from alexcrichton and removed request for a team July 15, 2025 01:12
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator wasmtime:api Related to the API of the `wasmtime` crate itself labels Jul 15, 2025
This commit implements [Tarjan's algorithm] for finding strongly-connected
components.

This algorithm takes `O(V+E)` time and uses `O(V+E)` space.

Tarjan's algorithm is usually presented as a recursive algorithm, but we do not
trust the input and cannot recurse over it for fear of blowing the
stack. Therefore, this implementation is iterative.

This will be used to do bottom-up inlining in Wasmtime's compilation
orchestration.

[Tarjan's algorithm]: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
@alexcrichton
Copy link
Member

I'm feeling a bit overwhelmed recently so I'm going to re-roll review.

@alexcrichton alexcrichton requested review from a team and abrown and removed request for a team and alexcrichton July 15, 2025 14:23
@cfallin
Copy link
Member

cfallin commented Jul 15, 2025

(I'm happy to cover this one as a "core compiler algorithms PR" unless you really want it, Andrew!)

@abrown
Copy link
Member

abrown commented Jul 15, 2025

Go for it!

Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Very nice! A few thoughts below but overall LGTM.

@fitzgen fitzgen enabled auto-merge July 15, 2025 17:21
@fitzgen fitzgen added this pull request to the merge queue Jul 15, 2025
Merged via the queue into bytecodealliance:main with commit 3da19a9 Jul 15, 2025
42 checks passed
@fitzgen fitzgen deleted the tarjan-scc branch July 15, 2025 17:58
bongjunj pushed a commit to prosyslab/wasmtime that referenced this pull request Oct 20, 2025
…lliance#11239)

* Implement Tarjan's strongly-connected components algorithm

This commit implements [Tarjan's algorithm] for finding strongly-connected
components.

This algorithm takes `O(V+E)` time and uses `O(V+E)` space.

Tarjan's algorithm is usually presented as a recursive algorithm, but we do not
trust the input and cannot recurse over it for fear of blowing the
stack. Therefore, this implementation is iterative.

This will be used to do bottom-up inlining in Wasmtime's compilation
orchestration.

[Tarjan's algorithm]: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm

* address review feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants