Make SCCs and graph traversals reusable#12590
Make SCCs and graph traversals reusable#12590fitzgen wants to merge 3 commits intobytecodealliance:mainfrom
Conversation
cfallin
left a comment
There was a problem hiding this comment.
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.
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.
8732572 to
5f8d308
Compare
Yeah I think probably in an ideal world it would be like Anyways, we can always move things around if we find that we need to down the line. |
This moves our existing SCC computation and DFS graph traversals out of
wasmtime::compileand intowasmtime_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 aGraphtrait.In the process, I also moved the
NonMaxU32type towasmtime_internal_coreand 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.