starcoinorg / move

Apache License 2.0
3 stars 57 forks source link

Refactor move runtime #72

Closed simonjiao closed 2 months ago

simonjiao commented 3 months ago

Motivation

(Write your motivation for proposed changes here.)

Have you read the Contributing Guidelines on pull requests?

(Write your answer here.)

Test Plan

(Share your test plan here. If you changed code, please provide us with clear instructions for verifying that your changes work.)

Summary by CodeRabbit

coderabbitai[bot] commented 3 months ago

[!IMPORTANT]

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update introduces significant enhancements across multiple components of the Move programming language ecosystem. Key changes include the addition of identifier location tracking in function entries, improved caching mechanisms for compiled scripts and modules, and refined module and function loading processes. These modifications aim to enhance performance, debugging capabilities, and the overall modular architecture of the Move VM runtime.

Changes

Files Change Summary
language/move-model/src/builder/model_builder.rs, module_builder.rs, model.rs Added id_loc field for tracking function identifier locations, enhancing debugging and metadata management.
language/move-vm/runtime/Cargo.toml Added typed-arena dependency to optimize memory management.
language/move-vm/runtime/src/data_cache.rs Improved caching for compiled scripts and modules, reducing deserialization costs.
language/move-vm/runtime/src/lib.rs, loader.rs, module_traversal.rs Modified module visibility, added new module for traversal, and enhanced loading functions.
language/move-vm/runtime/src/runtime.rs, session.rs Introduced new methods for executing instantiated functions, verifying modules, and enhanced session capabilities.
rust-toolchain Updated Rust version from 1.67.0 to 1.75.0 for new features and improvements.

Sequence Diagram(s)

sequenceDiagram
    participant A as User
    participant B as Move VM
    participant C as Module Loader
    participant D as Data Cache

    A ->> B: Call execute_instantiated_function
    B ->> C: Load function and parameters
    C ->> D: Check cache for compiled module
    D -->> C: Return cached module if available
    C -->> B: Return loaded function
    B -->> A: Return result of execution
sequenceDiagram
    participant A as User
    participant B as Move VM
    participant C as Session
    participant D as Module

    A ->> C: Call load_script
    C ->> D: Load module and function
    D -->> C: Return function and instantiation
    C -->> A: Return loaded function and instantiation

Poem

🐰 In the fields so bright and fair,
New changes hop with gentle flair.
With id_loc, we trace each name,
Caching scriptsβ€”oh, what a game!
In the garden of code, we cheer,
For the Move VM's path is clear! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
nkysg commented 3 months ago

@coderabbitai full review

coderabbitai[bot] commented 3 months ago
Actions performed Full review triggered.
nkysg commented 3 months ago

@coderabbitai review

coderabbitai[bot] commented 3 months ago

@nkysg, I have reviewed the changes in the PR based on the gathered information. Here is a detailed summary of the modifications:

Summary of Changes

  1. language/move-model/src/builder/model_builder.rs:

    • Struct FunEntry: Added a new field id_loc to hold location information specific to the function identifier.
    • Method define_fun: Updated to include the new parameter id_loc.
  2. language/move-model/src/builder/module_builder.rs:

    • Method define_fun: Updated to include the new parameter id_loc.
  3. language/move-model/src/model.rs:

    • Struct FunctionData: Added a new field id_loc to hold the location of the function identifier.
    • New Method get_id_loc: Added to return the id_loc field.
  4. language/move-vm/runtime/src/data_cache.rs:

    • Struct TransactionDataCache: Added new fields compiled_scripts and compiled_modules for caching mechanisms.
    • New Methods: load_compiled_script_to_cache and load_compiled_module_to_cache added for efficient handling of deserialized data.
  5. language/move-vm/runtime/src/lib.rs:

    • Module Visibility Changes: Changed loader and runtime modules to public. Added a new public module module_traversal.
  6. language/move-vm/runtime/src/loader.rs:

    • Function Signature Changes: Updated methods to include additional parameters and return types.
    • New Functionality: Added functions for loading scripts and functions with type argument inference.
  7. language/move-vm/runtime/src/module_traversal.rs:

    • New File: Implements TraversalStorage and TraversalContext for managing the traversal of Move modules and scripts.
  8. language/move-vm/runtime/src/runtime.rs:

    • New Method execute_function_instantiation: Added to encapsulate the logic for loading and executing a function instantiation.
  9. language/move-vm/runtime/src/session.rs:

    • New Methods: Added several methods to enhance functionality related to module and function management.
  10. rust-toolchain:

    • Version Update: Updated Rust version from 1.67.0 to 1.75.0.

Review Comments

Overall, the changes appear to be well-structured and aimed at improving the performance, maintainability, and usability of the Move runtime. If you have any specific areas you would like me to focus on or any additional questions, please let me know.

Analysis chain ---
Scripts executed The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Gathering information about the changes in the PR # Fetch the modifications in the `model_builder.rs` file ast-grep --lang rust --pattern $'struct FunEntry { pub loc: Loc, pub id_loc: Loc, pub module_id: ModuleId, pub fun_id: FunId, pub visibility: FunctionVisibility, }' language/move-model/src/builder/model_builder.rs # Fetch the modifications in the `module_builder.rs` file ast-grep --lang rust --pattern $'impl ModuleBuilder { pub fn define_fun(&mut self, loc: Loc, id_loc: Loc, ...) { $$$ } }' language/move-model/src/builder/module_builder.rs # Fetch the modifications in the `model.rs` file ast-grep --lang rust --pattern $'struct FunctionData { $$$ pub id_loc: Loc, $$$ }' language/move-model/src/model.rs # Fetch the modifications in the `data_cache.rs` file ast-grep --lang rust --pattern $'struct TransactionDataCache { $$$ compiled_scripts: BTreeMap<[u8; 32], Arc>, compiled_modules: BTreeMap, usize, [u8; 32])>, $$$ }' language/move-vm/runtime/src/data_cache.rs # Fetch the modifications in the `lib.rs` file ast-grep --lang rust --pattern $'pub mod loader; pub mod runtime; pub mod module_traversal; ' language/move-vm/runtime/src/lib.rs # Fetch the modifications in the `loader.rs` file ast-grep --lang rust --pattern $'impl Loader { pub fn load_script(&self, script_blob: &[u8], ty_args: &[TypeTag]) -> VMResult> { $$$ } }' language/move-vm/runtime/src/loader.rs # Fetch the modifications in the `module_traversal.rs` file ast-grep --lang rust --pattern $'struct TraversalStorage { $$$ pub fn new() -> Self { $$$ } }' language/move-vm/runtime/src/module_traversal.rs # Fetch the modifications in the `runtime.rs` file ast-grep --lang rust --pattern $'impl VMRuntime { pub(crate) fn execute_function_instantiation( &self, module: Arc, func: Arc, loaded_func: LoadedFunctionInstantiation, serialized_args: Vec>, data_store: &mut impl MoveResolver, gas_meter: &mut impl GasMeter, extensions: &mut impl ExtensionStore, bypass_declared_entry_check: bool, ) -> VMResult { $$$ } }' language/move-vm/runtime/src/runtime.rs # Fetch the modifications in the `session.rs` file ast-grep --lang rust --pattern $'impl Session { pub fn execute_instantiated_function( &mut self, module: Arc, func: Arc, instantiation: LoadedFunctionInstantiation, args: Vec>, gas_meter: &mut impl GasMeter, ) -> VMResult { $$$ } }' language/move-vm/runtime/src/session.rs # Fetch the modifications in the `rust-toolchain` file cat rust-toolchain ``` Length of output: 2665 --- Script: ```shell #!/bin/bash # Adjusting the pattern for the `lib.rs` file and rerunning the script # Fetch the modifications in the `lib.rs` file with adjusted pattern ast-grep --lang rust --pattern $'pub mod loader;' language/move-vm/runtime/src/lib.rs ast-grep --lang rust --pattern $'pub mod runtime;' language/move-vm/runtime/src/lib.rs ast-grep --lang rust --pattern $'pub mod module_traversal;' language/move-vm/runtime/src/lib.rs ``` Length of output: 447
Actions performed Review triggered. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.