Skip to content
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

pulley: Fix interpreter push/pop #9644

Merged

Conversation

alexcrichton
Copy link
Member

  • Add stack-overflow checking to push and other decrements of sp.
  • Fix the up/down direction of push/pop (push goes down, pop goes up).
  • Fix the order of operation sin push, first decrement then write.
  • Move methods to Interpreter to use ControlFlow more heavily.

@alexcrichton alexcrichton requested a review from a team as a code owner November 21, 2024 02:25
@alexcrichton alexcrichton requested review from cfallin and removed request for a team November 21, 2024 02:25
@alexcrichton
Copy link
Member Author

Review-wise this is stacked on #9629

@github-actions github-actions bot added the pulley Issues related to the Pulley interpreter label Nov 21, 2024
Copy link

Subscribe to Label Action

cc @fitzgen

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

Thus the following users have been cc'd because of the following labels:

  • fitzgen: pulley

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

Learn more.

* Add stack-overflow checking to `push` and other decrements of `sp`.
* Fix the up/down direction of push/pop (`push` goes down, `pop` goes up).
* Fix the order of operation sin `push`, first decrement then write.
* Move methods to `Interpreter` to use `ControlFlow` more heavily.
@alexcrichton
Copy link
Member Author

rebased!

/// `sp -= size_of::<T>(); *sp = val;`
#[must_use]
fn push<T>(&mut self, val: T) -> ControlFlow<Done> {
let new_sp = self.state[XReg::sp].get_ptr::<T>().wrapping_sub(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're switching the direction of growth, is there something that needs to be done to flip where sp starts at when we create the interpreter state?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess MachineState::with_stack already does that but Pulley was just incorrectly pushing and popping?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah I don't believe it was ever the intentional to reverse the order of the stack with respect to native stacks, so I believe this was just a copy/paste error. (you can tell we don't run the interpreter much right now)

@alexcrichton alexcrichton added this pull request to the merge queue Nov 26, 2024
Merged via the queue into bytecodealliance:main with commit 8e8ad73 Nov 26, 2024
39 checks passed
@alexcrichton alexcrichton deleted the fix-pulley-push-pop branch November 26, 2024 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pulley Issues related to the Pulley interpreter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants