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

Test VM should use Rc<Blockstore> for consistency with the MockRuntime #1454

Merged
merged 4 commits into from
Oct 25, 2023

Conversation

aarshkshah1992
Copy link
Contributor

@aarshkshah1992 aarshkshah1992 commented Oct 19, 2023

Follow up to #1446 for #1446 (comment).

@aarshkshah1992 aarshkshah1992 changed the title Test vm should use Rc<Blockstore> Test VM should use Rc<Blockstore> for consistency with the MockRuntime Oct 19, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 19, 2023

Codecov Report

Merging #1454 (3b870f9) into master (1e50065) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1454      +/-   ##
==========================================
- Coverage   91.05%   91.00%   -0.06%     
==========================================
  Files         147      147              
  Lines       27982    27986       +4     
==========================================
- Hits        25479    25468      -11     
- Misses       2503     2518      +15     
Files Coverage Δ
test_vm/src/lib.rs 96.11% <100.00%> (+0.04%) ⬆️
test_vm/src/messaging.rs 75.19% <100.00%> (-0.20%) ⬇️

... and 2 files with indirect coverage changes

Copy link
Member

@Stebalien Stebalien 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 reasonable change, just one nit to agree on.

@@ -82,15 +83,15 @@ impl<'bs> TestVM<'bs> {
}
}

pub fn new_with_singletons(store: &'bs MemoryBlockstore) -> TestVM<'bs> {
pub fn new_with_singletons(store: Rc<MemoryBlockstore>) -> TestVM {
Copy link
Member

Choose a reason for hiding this comment

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

I'd consider defining this as store: impl Into<Rc<MemoryBlockstoire>>, allowing the user to pass either a MemoryBlockstore or an Rc<MemoryBlockstore>>. I.e.

Suggested change
pub fn new_with_singletons(store: Rc<MemoryBlockstore>) -> TestVM {
pub fn new_with_singletons(store: impl Into<Rc<MemoryBlockstore>>) -> TestVM {
let store = store.into();

Same with TestVM::new.

But let's wait for @anorth to comment on this before continuing.

Copy link
Member

Choose a reason for hiding this comment

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

This would let us call TestVM::new_with_singletons(store) without having to explicitly wrap in an Rc.

Copy link
Member

Choose a reason for hiding this comment

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

Yes please (for new too)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done for both. Great idea !

Copy link
Contributor Author

@aarshkshah1992 aarshkshah1992 Oct 20, 2023

Choose a reason for hiding this comment

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

@Stebalien @anorth Where is the implementation for

impl Into<Rc<MemoryBlockstore>> for MemoryBlockstore {
}

defined though in the code ? I also don't see a

impl From<MemoryBlockstore> for Rc<MemoryBlockstore>

anywhere. Does the Rust stdlib have come default impl here to convert a MemoryBlockstore to an Rc ?

Copy link
Member

Choose a reason for hiding this comment

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

First, there's also a blanket implementation of Into<U> for T where U: From<T>. That is, you always implement From<T> for U and get an automatic implementation of Into<U> for T. Never implement Into directly. I recommend reading the Into documentation and the From and Into section of the book.

Additionally, there's a blanket implementation of From<T> for Rc<T>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @Stebalien ! Yeah the blanket implementation of From<T> for Rc<T> is what I missing on.

Copy link
Member

@anorth anorth left a comment

Choose a reason for hiding this comment

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

LGTM. @alexytsu please holler if this is going to cause any strife for you.

@@ -82,15 +83,15 @@ impl<'bs> TestVM<'bs> {
}
}

pub fn new_with_singletons(store: &'bs MemoryBlockstore) -> TestVM<'bs> {
pub fn new_with_singletons(store: Rc<MemoryBlockstore>) -> TestVM {
Copy link
Member

Choose a reason for hiding this comment

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

Yes please (for new too)

@alexytsu
Copy link
Contributor

No issues from me

TestVM {
primitives: FakePrimitives {},
store,
store: store,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
store: store,
store,

Copy link
Member

Choose a reason for hiding this comment

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

This is what clippy is complaining about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

let store = Rc::new(MemoryBlockstore::new());
let v = TestVM::new_with_singletons(store);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let store = Rc::new(MemoryBlockstore::new());
let v = TestVM::new_with_singletons(store);
let store = MemoryBlockstore::new();
let v = TestVM::new_with_singletons(store);

Given the changes to the new_with_singletons signature, we shouldn't need to manually wrap in an Rc. Apply below as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here and elsewhere.

@aarshkshah1992 aarshkshah1992 force-pushed the feat/testvm-uses-rc-blockstore branch from 3b870f9 to 3b3b87f Compare October 25, 2023 13:28
@aarshkshah1992 aarshkshah1992 added this pull request to the merge queue Oct 25, 2023
@aarshkshah1992
Copy link
Contributor Author

@Stebalien Addressed your review and put this in the merge queue.

Merged via the queue into master with commit b2721f8 Oct 25, 2023
13 checks passed
@aarshkshah1992 aarshkshah1992 deleted the feat/testvm-uses-rc-blockstore branch October 25, 2023 14:06
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.

5 participants