Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upList IR #114
List IR #114
Conversation
This is going to need to be completely overhauled for the new IR, so it is easier to just remove it outright and then add it back once we have the new IR in place.
We had plans to build a find/replace style API with this, but that never materialized, and nothing is taking advantage of this API, so let's just remove it.
Instead of an AST, we have lists of instructions. This is more similar to raw Wasm itself, and should make supporting multi-value even easier. There is still nesting, in that each `block ... end`, `loop ... end`, and `if ... else ... end` recursively contain new instruction sequences, rather than having their bodies inlined into the current instruction sequence. I suspect this will make it easier to slice, dice, and splice functions.
This comment has been minimized.
This comment has been minimized.
Take a look at the Visitors are really not that different. Although I'd also like to replace them with something that isn't recursive. |
This comment has been minimized.
This comment has been minimized.
This looks great to me, thanks for taking this on @fitzgen! I think we'll probably want to flesh out the non-recursive visitation before this lands though to ensure we've got a working strategy for it. Also would you be up for prototyping a patch to |
This comment has been minimized.
This comment has been minimized.
Yeah for sure |
This commit changes the way IR traversal is done, notably: * Visitors are no longer recursive, and should never recursively call `self.visit_foo()` from inside `self.visit_bar()`. Not in the default provided trait methods and not in any user-written overrides of those trait methods. * The `Visit` trait is no longer exported in the public API. Calling `my_instruction.visit(visitor)` will call *all* of the `visit_foo_id` methods of the visitor that are relevant for that instruction *but not recursively through nested instruction sequences*. For example, calling `visit` on a `Block` will call `visitor.visit_instr_seq_id`, but will not recursively visit the referenced `InstrSeq`. * There are now *traversal functions* which take a visitor, a `LocalFunction`, and a start `InstrSeqId`, and then perform some kind of traversal over the function's IR from the given start sequence. These traversal functions are *not* recursive, and are implemented with explicit work lists and while loops. This avoids blowing the stack on deeply nested Wasm inputs. Although we can still OOM, we leave fixing that to future PRs. Right now there are only two traversals, because that is all we've needed so far: an in-order DFS for immutable visitors (needs to be in-order so we can encode instructions in the right order) and a pre-order DFS for mutable visitors (pre-order is the easiest traversal to implement iteratively). We can add more traversals as we need them.
This comment has been minimized.
This comment has been minimized.
@alexcrichton ok, I added some non-recursive traversals. See the latest commit. Still working on re-implementing graphviz support. |
Looks reasonable to me! |
This is new and improved dot support. Instead of being specific to a single function, this allows encoding the whole module as a dot file, including all functions.
fitzgen commentedAug 1, 2019
Still need to re-add graphviz dot support, so not quite ready to land yet. But the most important bits are already here, so I figured you might want to take a look now, @alexcrichton.