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

🎁 Update to wasmtime 22.0.0 #392

Merged
merged 4 commits into from
Jun 26, 2024
Merged

🎁 Update to wasmtime 22.0.0 #392

merged 4 commits into from
Jun 26, 2024

Conversation

elliottt
Copy link
Contributor

Update to wasmtime 22.0.0.

This included some pretty substantial changes to the wiggle crate, which removes
runtime borrow checking of guest memory. This is a huge ergonomic improvement,
as the borrows are all tracked as rrust borrows instead.

One piece of functionality that's missing after the wiggle changes is the
ability to interact with a slice of guest memory that's not &[u8]. To work
around this, I'm copying memory over to the host, but in future releases of
wiggle we should have the ability to interact with slices that aren't just to
u8.

@elliottt elliottt marked this pull request as ready for review June 24, 2024 19:31
Comment on lines 29 to 32
// TODO: wiggle only supports slices of u8 in 22.0.0
.to_vec(handles)?
.into_iter()
.map(|i| AsyncItemHandle::from(i).into()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a limitation implied here, like we can only support 256 async item handles rather than the full u32 range of handles previously supported?

Copy link
Contributor

Choose a reason for hiding this comment

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

OH, is the limitation that we can only have slices of u8s, but we can have full Vecs of other scalar types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's exactly it. I'm going to fix wiggle so that we can have slices of other things, and this comment was mostly a reminder to me that this should be updated to not copy in the future.

acfoltzer
acfoltzer previously approved these changes Jun 25, 2024
Copy link
Contributor

@acfoltzer acfoltzer left a comment

Choose a reason for hiding this comment

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

There's quite a few lines in this diff, but they're pleasantly straightforward and mechanical. I had feared this would be a more disruptive transition than it actually turned out to be, and I'm really happy to have more of the ownership properties now checked statically.

The only thing I might be tempted to change here is the comment in the code about only supporting slices of u8. It's a bit ambiguous to the reader, and it might cause some surprise until they figure out that we're using a Vec instead of a slice rather than a u8 instead of some other type.

Copy link
Contributor

@acw acw left a comment

Choose a reason for hiding this comment

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

I think there are two comments that could use at least a bit more explanation, but otherwise this looks good. I tried to be pretty careful in looking at the diffs, but I have to admit that my eyes starting glazing over at some points. I can confirm that the tests still pass locally, though.

.iter()
.copied()
memory
// TODO: wiggle only supports slices of u8 in 22.0.0
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is confusing me a bit. Based on the comment, I would guess that memory.to_vec(handles) returns a Vec<u8>, which would be a problem because that would mean we'd be creating AsyncItemHandles from bytes instead of 32-bit values. But if I look at the wiggle docs, it looks like memory_to_vec(handles) is going to keep the type T (in this case, u32), so we'll be doing the right thing here.

So ... what's up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, this needs to be reworded. The issue is that the as_slice function on GuestMemory will only handle GuestPtr<[u8]>, and not GuestPtr<[T]>. This was just an oversight, and in the future we can avoid copying with to_vec here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Just to be really clear: this does the right thing when producing a vector of u32, but it copies in the process)

.iter()
.map(|handle| PendingRequestHandle::from(*handle).into()),
memory
// TODO: wiggle only supports slices of u8 in 22.0.0
Copy link
Contributor

Choose a reason for hiding this comment

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

See previous TODO comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

@elliottt
Copy link
Contributor Author

I've updated the comment to hopefully clarify the situation with the use of GuestMemory::to_vec.

Copy link
Contributor

@acw acw left a comment

Choose a reason for hiding this comment

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

Yay!

Copy link
Contributor

@acfoltzer acfoltzer left a comment

Choose a reason for hiding this comment

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

I am pleased to see the Adams are in alignment on this PR

@elliottt elliottt merged commit 53de99d into main Jun 26, 2024
7 checks passed
@elliottt elliottt deleted the trevor/wasmtime-22 branch June 26, 2024 16:55
GeeWee pushed a commit to GeeWee/Viceroy that referenced this pull request Jul 25, 2024
Update to wasmtime 22.0.0.

This included some pretty substantial changes to the wiggle crate, which removes
runtime borrow checking of guest memory. This is a huge ergonomic improvement,
as the borrows are all tracked as rrust borrows instead.

One piece of functionality that's missing after the wiggle changes is the
ability to interact with a slice of guest memory that's not &[u8]. To work
around this, I'm copying memory over to the host, but in future releases of
wiggle we should have the ability to interact with slices that aren't just to
u8.
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