-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add initial Cranelift interpreter #1223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial Cranelift interpreter #1223
Conversation
|
@bnjbvr, I had to commit 1bed1db to get this back in a working state. If the barrier to merging is that we only want to expose features that are complete, we could remove the |
Subscribe to Label ActionThis issue or pull request has been labeled: "c", "r", "a", "n", "e", "l", "i", "f", "t" To subscribe or unsubscribe from this label, edit the |
2 similar comments
Subscribe to Label ActionThis issue or pull request has been labeled: "c", "r", "a", "n", "e", "l", "i", "f", "t" To subscribe or unsubscribe from this label, edit the |
Subscribe to Label ActionThis issue or pull request has been labeled: "c", "r", "a", "n", "e", "l", "i", "f", "t" To subscribe or unsubscribe from this label, edit the |
Subscribe to Label ActionThis issue or pull request has been labeled: "cranelift" Users Subscribed to "cranelift"To subscribe or unsubscribe from this label, edit the |
d4d8432 to
0923bb5
Compare
bnjbvr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments below; I really have looked only at the first commit, and realized it wouldn't compile locally (because the parser module doesn't exist as of this commit, it seems to be introduced later). I think the commits need to be rearranged; it'd be nice if changes introduced by the latest commit could also be absorbed in the relevant commits that introduced the lines they're changing (it would definitely help the review!).
I'm happy to give it a second look once my first comments have been addressed. When this is ready, please re-request a new review, and I'll do my best to do it promptly this time (sorry about the slow review time!). Cheers!
| ControlFlow::ContinueAt(ebb, old_names) => { | ||
| let new_names = frame.function.dfg.ebb_params(ebb); | ||
| frame.rename(&old_names, new_names); | ||
| return self.block(frame, ebb); // TODO check that TCO happens |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the recursion be avoided by having an infinite loop above the for loop, remembering what the next BB will be, and breaking when the next BB differs from the current BB?
(also nit: we do have BB and not EBBs now :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rebased commits have block instead of ebb. My TCO comment (now removed) was in hopes that Rust was somehow smart enough to avoid recursive calls... is there an easy way to check if that is happening?
0923bb5 to
f3287d6
Compare
199342d to
d4f9147
Compare
d4f9147 to
8c6d933
Compare
|
Sorry, I am swamped in reviews again, and I don't know when I'd be able to do this; forwarding to other people. |
fitzgen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good start on an interpreter! Happy to land this now and then iterate on it further in-tree. Some suggestions inline below as well -- feel free to merge once they are addressed without re-requesting review.
It would be cool if rather than panicking on unknown opcodes, we returned an error that could be matched upon. Then we would be able to do things like differential fuzzing between the interpreter and compiler (with an early exit if the interpreter doesn't support sine particular opcode yet).
| /// any old references that are not in `old_names`. TODO This performs an extra allocation that | ||
| /// could be removed if we copied the values in the right order (i.e. when modifying in place, | ||
| /// we need to avoid changing a value before it is referenced). | ||
| pub fn rename(&mut self, old_names: &[ValueRef], new_names: &[ValueRef]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_eq!(old_names.len(), new_names.len());
Also, it isn't valid to clear every other value, since blocks are free to access variables defined in other blocks that dominate them, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But those variables would be in another frame and I am using a frame per block; we can't access SSA values from another block (I just checked). I guess the naming is confusing because normally one would expect a "frame per function" scheme. I'll leave it for now but I'll try to think of some better name... BlockEnvironment? And rename Environment to something like FunctionEnvironment? Suggestions welcome.
Also, returns a `Result` in the `RunCommand::run` helper.
This is an incomplete version of a Cranelift IR interpreter: only a small subset of instructions are implemented and (known) missing parts are marked with TODO or FIXME.
8c6d933 to
de27153
Compare
See bytecodealliance/cranelift#1351.