Skip to content

Make SCCs and graph traversals reusable#12590

Open
fitzgen wants to merge 2 commits intobytecodealliance:mainfrom
fitzgen:make-scc-reusable
Open

Make SCCs and graph traversals reusable#12590
fitzgen wants to merge 2 commits intobytecodealliance:mainfrom
fitzgen:make-scc-reusable

Conversation

@fitzgen
Copy link
Member

@fitzgen fitzgen commented Feb 13, 2026

This moves our existing SCC computation and DFS graph traversals out of wasmtime::compile and into wasmtime_environ::graphs, where they can be reused elsewhere in the workspace. These functions and types were already generally generic over an iterator of nodes and/or an edge function to get a particular node's successors, but I've gone one step further and packaged up those two things together into a Graph trait.

In the process, I also moved the NonMaxU32 type to wasmtime_internal_core and made it so we have other non-max integer types as well.

This will let us reuse SCC computation in our GC ops fuzzer, where we need SCCs to figure out how to merge fuzzer-generated rec groups, if necessary, since cyclic type references are constrained to within the same rec group. The GC ops fuzzer can also reuse the DFS traversal code in its topological sorting of supertypes and subtypes as well.

This is mostly, but not quite completely, code motion and fixups of paths and such.

@cfallin, I'm flagging you for review on this one because you reviewed the initial PRs that landed this code.

This moves our existing SCC computation and DFS graph traversals out of
`wasmtime::compile` and into `wasmtime_environ::graphs`, where they can be
reused elsewhere in the workspace. These functions and types were already
generally generic over an iterator of nodes and/or an edge function to get a
particular node's successors, but I've gone one step further and packaged up
those two things together into a `Graph` trait.

In the process, I also moved the `NonMaxU32` type to `wasmtime_internal_core`
and made it so we have other non-max integer types as well.

This will let us reuse SCC computation in our GC ops fuzzer, where we need SCCs
to figure out how to merge fuzzer-generated rec groups, if necessary, since
cyclic type references are constrained to within the same rec group. The GC ops
fuzzer can also reuse the DFS traversal code in its topological sorting of
supertypes and subtypes as well.
@fitzgen fitzgen requested a review from cfallin February 13, 2026 21:12
@fitzgen fitzgen requested a review from a team as a code owner February 13, 2026 21:12
@fitzgen fitzgen mentioned this pull request Feb 13, 2026
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.

Seems reasonable!

I was idly wondering whether it would make more sense to put the graph-related bits in crates/core/ since that is becoming a home for data structures in general, but I guess the focus there is more on foundational containers (with explicit OOM handling) than algorithms, and also the bits here are not adapted for OOM so we'd be mixing universes if we did that? I'm fine either way honestly.

@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants