Skip to content

Conversation

@abrown
Copy link
Member

@abrown abrown commented Mar 4, 2020

@abrown abrown requested a review from bnjbvr March 4, 2020 04:17
@abrown
Copy link
Member Author

abrown commented Mar 4, 2020

@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 clif-util interpret ... functionality. We have to start somewhere, though, so I recommend we merge this as-is--missing instructions and all--and add a log message to clif-util interpret ... like This is an unstable feature and a work in progress implementation.

@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label Mar 11, 2020
@github-actions
Copy link

Subscribe to Label Action

This 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 .github/subscribe-to-label.json configuration file.

Learn more.

2 similar comments
@github-actions
Copy link

Subscribe to Label Action

This 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 .github/subscribe-to-label.json configuration file.

Learn more.

@github-actions
Copy link

Subscribe to Label Action

This 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 .github/subscribe-to-label.json configuration file.

Learn more.

@github-actions
Copy link

Subscribe to Label Action

This issue or pull request has been labeled: "cranelift"

Users Subscribed to "cranelift"

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@abrown abrown force-pushed the upstream-interpreter-in-wasmtime branch 2 times, most recently from d4d8432 to 0923bb5 Compare March 28, 2020 00:16
Copy link
Member

@bnjbvr bnjbvr left a 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
Copy link
Member

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 :))

Copy link
Member Author

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?

@abrown abrown mentioned this pull request Mar 30, 2020
@abrown abrown force-pushed the upstream-interpreter-in-wasmtime branch from 0923bb5 to f3287d6 Compare April 21, 2020 22:02
@github-actions github-actions bot added the cranelift:meta Everything related to the meta-language. label Apr 21, 2020
@abrown abrown force-pushed the upstream-interpreter-in-wasmtime branch 4 times, most recently from 199342d to d4f9147 Compare April 21, 2020 23:51
@abrown
Copy link
Member Author

abrown commented Apr 22, 2020

@bnjbvr, I think is ready for another review but it would be best if we took a look at #1517 first since this uses some of the changes that PR made to RunCommand.

@bnjbvr bnjbvr self-requested a review April 22, 2020 10:12
@abrown abrown force-pushed the upstream-interpreter-in-wasmtime branch from d4f9147 to 8c6d933 Compare May 1, 2020 04:08
@bnjbvr
Copy link
Member

bnjbvr commented May 5, 2020

Sorry, I am swamped in reviews again, and I don't know when I'd be able to do this; forwarding to other people.

@bnjbvr bnjbvr requested review from fitzgen and sunfishcode and removed request for bnjbvr May 5, 2020 09:38
Copy link
Member

@fitzgen fitzgen left a 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]) {
Copy link
Member

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?

Copy link
Member Author

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.

abrown added 4 commits May 7, 2020 15:31
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.
@abrown abrown force-pushed the upstream-interpreter-in-wasmtime branch from 8c6d933 to de27153 Compare May 7, 2020 22:46
@abrown
Copy link
Member Author

abrown commented May 7, 2020

Stuff I'm going to make a note to work on later:

  • a Trap variant for unknown opcodes instead of using unimplemented!, from @fitzgen
  • convert the block() method to use a loop instead of recursing, from @bnjbvr
  • think about renaming Frame and Environment, from a comment to @fitzgen

@abrown abrown merged commit b65bd1c into bytecodealliance:master May 7, 2020
@abrown abrown deleted the upstream-interpreter-in-wasmtime branch May 7, 2020 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:meta Everything related to the meta-language. cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants