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

[vm rewrite] Swap to a more step-driven interpreter #19219

Merged
merged 3 commits into from
Sep 12, 2024

Conversation

cgswords
Copy link
Contributor

@cgswords cgswords commented Sep 5, 2024

Description

This splits up the interpreter to be more step-by-step than the previous loop with control flags approach. It also closes some of the circuit on ArenaPointer usage.

The move-execution changes are just due to cargo fmt --all.

Test plan

All tests still pass


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • REST API:

Copy link

vercel bot commented Sep 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2024 5:53pm
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Sep 12, 2024 5:53pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Sep 12, 2024 5:53pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Sep 12, 2024 5:53pm

Comment on lines +836 to +843
if !control_flow_instruction(instruction) {
state.current_frame.pc += 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on instead early returning from the control flow instructions?

Here we could then debug_assert that the state.current_frame.pc hadn't changed yet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The profiling code would make that quite a bit noisier, which seems more-likely to introduce errors.

let resolver = fun_ref.get_resolver(link_context, loader);

let return_values = eval::call_native_with_args(
None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense for this to be None? Especially since it holds VMRuntimeLimitsConfig. Should we instead make an empty state of some sort?

Copy link
Contributor

Choose a reason for hiding this comment

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

I had the same initial reaction, though for me looking at the code and try to change that made it more clear why we are doing it.
But all of that (including our NativeContext definition) made me think we really need to review native invocation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could pass the limits separately. The only place this was used is in printing the stack trace.

Comment on lines +18 to +22
pub(crate) fn run(
function: ArenaPointer<Function>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Lots to think about here for me. At some point in the far future, it would be very interesting to basically call step, or at least "run" here to invoke a function, with a given state, instead of having the custom execution engine we have today for PTBs

Copy link
Contributor

@dariorussi dariorussi left a comment

Choose a reason for hiding this comment

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

This is great!
Just some comments. I am going to finish the review later today.
I want to look at Tim's PR before the meeting so just leaving you a note right now

let resolver = fun_ref.get_resolver(link_context, loader);

let return_values = eval::call_native_with_args(
None,
Copy link
Contributor

Choose a reason for hiding this comment

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

I had the same initial reaction, though for me looking at the code and try to change that made it more clear why we are doing it.
But all of that (including our NativeContext definition) made me think we really need to review native invocation

Comment on lines +158 to +172
let charge_result = gas_meter.charge_simple_instr(SimpleInstruction::Ret);
profile_close_instr!(gas_meter, format!("{:?}", instruction));

partial_error_to_error(state, run_context, charge_result)?;
let non_ref_vals = state
.current_frame
.locals
.drop_all_values()
.map(|(_idx, val)| val);

// TODO: Check if the error location is set correctly.
gas_meter
.charge_drop_frame(non_ref_vals.into_iter())
.map_err(|e| state.set_location(e))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

this may very well be a "fix all things gas" issue, but I do not believe we charge anything for dropping a frame (lines 162-171) and yet we got calls and check and a TODO....
thedrop_all_values part may actually do something useful (maybe not sure) but...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This TODO was there in the old code -- not sure what to do about it. Let's revisit gas in the future.

Copy link
Contributor

@dariorussi dariorussi left a comment

Choose a reason for hiding this comment

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

really like this and I am good with it.
Let's get this in!
Some of the CI failures should be easy to fix, not sure if this is supposed to be clean or not

Base automatically changed from cgswords/arena_loader_1 to vm_2024_rewrite September 12, 2024 17:34
@cgswords cgswords force-pushed the cgswords/state_machine_interpreter branch from 1ca0e7a to 7f1ad8c Compare September 12, 2024 17:46
@cgswords cgswords merged commit ca4297c into vm_2024_rewrite Sep 12, 2024
41 of 46 checks passed
@cgswords cgswords deleted the cgswords/state_machine_interpreter branch September 12, 2024 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants