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

Add WasiCtxBuilder setters for the two clock types #6669

Merged
merged 4 commits into from
Jun 30, 2023

Conversation

rylev
Copy link
Contributor

@rylev rylev commented Jun 29, 2023

This allows users to set individual clock types on the WasiCtxBuilder.

Before

let mut clocks = clocks_ctx();
clocks.wall = Box::new(MyWallClock);
builder.set_clocks(clocks)

After

builder.set_wall_clock(MyWallClock)

I didn't add any documentation because most of the other setters don't have any, and I was unsure what form the documentation should take.

Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
@rylev rylev requested a review from a team as a code owner June 29, 2023 11:29
@rylev rylev requested review from alexcrichton and removed request for a team June 29, 2023 11:29
@github-actions github-actions bot added the wasi Issues pertaining to WASI label Jun 29, 2023
@alexcrichton
Copy link
Member

Could this perhaps remove the set_clocks configuration method as well? I think it could otherwise be a bit surprising that set_clocks could override set_monotonic_clock for example, but if it doesn't exist then configuration should still be possible and there shouldn't be odd interactions between methods in theory.

@pchickey
Copy link
Contributor

We should drop the WasiClocks intermediate struct entirely and just have two members of WasiCtx for the wall and monotonic clock - would you be willing to do that?

Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

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

Looks good - thank you. One last suggestion if you're up to it - in the past I used the convention WasiThing to name the host types, but as we shifted to the component model, I've preferred HostThing instead - would you mind renaming these HostMonotonicClock and HostWallClock?

Also I'm not sure if the +Send+Sync in each box is required since those traits already require send and sync, maybe those could have been removed a while ago...

Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
@rylev
Copy link
Contributor Author

rylev commented Jun 30, 2023

@pchickey I've renamed the traits. Unfortunately, the compiler seems to require the Send and Sync bounds. I was surprised by this as well...

error[E0308]: mismatched types
  --> crates/wasi/src/preview2/ctx.rs:50:30
   |
50 |             monotonic_clock: monotonic_clock(),
   |                              ^^^^^^^^^^^^^^^^^ expected trait `HostMonotonicClock + std::marker::Send + Sync`, found trait `HostMonotonicClock`
   |
   = note: expected struct `Box<(dyn HostMonotonicClock + std::marker::Send + Sync + 'static)>`
              found struct `Box<(dyn HostMonotonicClock + 'static)>`

@sunfishcode
Copy link
Member

@rylev The PR here is good, but separately, I'm curious; would you mind saying a little more about what your use case looks like? I'm interested in learning about who's using non-default clocks and what they're using them for.

@rylev
Copy link
Contributor Author

rylev commented Jun 30, 2023

@sunfishcode unfortunately it's not too interesting - just doing some testing around ABI conformance of wasm binaries built with old versions of wit-bindgen that have been adapted to run against the latest version of wasmtime. You can see the code here.

@alexcrichton alexcrichton added this pull request to the merge queue Jun 30, 2023
Merged via the queue into bytecodealliance:main with commit b741f7c Jun 30, 2023
@rylev rylev deleted the clock-setters branch July 1, 2023 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants