Stream: git-wasmtime

Topic: wasmtime / issue #4138 Consufing type of `wasmtime::store...


view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 11:28):

jlkiri opened issue #4138:

I am struggling with applying a limiter to the wasmtime store by using the limiter API.

Here's the code I have.

    let engine = Engine::default();
    let module = Module::new(&engine, module_bytes)?;
    let store_limits = StoreLimits::default();
    let mut store = Store::new(&engine, ());
    store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);

It doesn't compile and gives me the error:

error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
   --> src/handler.rs:140:45
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                             ^^^^^^^^^^^^^^^^^
    |
note: first, the lifetime cannot outlive the lifetime `'_` as defined here...
   --> src/handler.rs:140:19
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that closure can access `store_limits`
   --> src/handler.rs:140:45
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                             ^^^^^^^^^^^^^^^^^
note: but, the lifetime must be valid for the anonymous lifetime #1 defined here...
   --> src/handler.rs:140:19
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that the declared lifetime parameter bounds are satisfied
   --> src/handler.rs:140:35
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0495`.

I know that my usage might be wrong but I just can't make it work so I would appreciate an example.

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 11:32):

jlkiri edited issue #4138:

I am struggling with applying a limiter to the wasmtime store by using the limiter API.

Here's the code I have.

    let engine = Engine::default();
    let module = Module::new(&engine, module_bytes)?;
    let store_limits = StoreLimits::default();
    let mut store = Store::new(&engine, ());
    store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);

It doesn't compile and gives me the error:

error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
   --> src/handler.rs:140:45
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                             ^^^^^^^^^^^^^^^^^
    |
note: first, the lifetime cannot outlive the lifetime `'_` as defined here...
   --> src/handler.rs:140:19
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that closure can access `store_limits`
   --> src/handler.rs:140:45
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                             ^^^^^^^^^^^^^^^^^
note: but, the lifetime must be valid for the anonymous lifetime #1 defined here...
   --> src/handler.rs:140:19
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that the declared lifetime parameter bounds are satisfied
   --> src/handler.rs:140:35
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0495`.

I know that my usage might be wrong but I just can't make it work so I would appreciate an example.

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 11:34):

jlkiri edited issue #4138:

I am struggling with applying a limiter to the wasmtime store by using the limiter API.

Here's the code I have.

    let engine = Engine::default();
    let module = Module::new(&engine, module_bytes)?;
    let store_limits = StoreLimits::default();
    let mut store = Store::new(&engine, ());
    store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);

StoreLimits is wasmtime's [StoreLimits](https://docs.rs/wasmtime/0.36.0/wasmtime/struct.StoreLimits.html
It doesn't compile and gives me the error:

error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
   --> src/handler.rs:140:45
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                             ^^^^^^^^^^^^^^^^^
    |
note: first, the lifetime cannot outlive the lifetime `'_` as defined here...
   --> src/handler.rs:140:19
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that closure can access `store_limits`
   --> src/handler.rs:140:45
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                             ^^^^^^^^^^^^^^^^^
note: but, the lifetime must be valid for the anonymous lifetime #1 defined here...
   --> src/handler.rs:140:19
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that the declared lifetime parameter bounds are satisfied
   --> src/handler.rs:140:35
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0495`.

I know that my usage might be wrong but I just can't make it work so I would appreciate an example.

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 11:34):

jlkiri edited issue #4138:

I am struggling with applying a limiter to the wasmtime store by using the limiter API.

Here's the code I have.

    let engine = Engine::default();
    let module = Module::new(&engine, module_bytes)?;
    let store_limits = StoreLimits::default();
    let mut store = Store::new(&engine, ());
    store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);

StoreLimits is wasmtime's StoreLimits
It doesn't compile and gives me the error:

error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
   --> src/handler.rs:140:45
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                             ^^^^^^^^^^^^^^^^^
    |
note: first, the lifetime cannot outlive the lifetime `'_` as defined here...
   --> src/handler.rs:140:19
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that closure can access `store_limits`
   --> src/handler.rs:140:45
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                             ^^^^^^^^^^^^^^^^^
note: but, the lifetime must be valid for the anonymous lifetime #1 defined here...
   --> src/handler.rs:140:19
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that the declared lifetime parameter bounds are satisfied
   --> src/handler.rs:140:35
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0495`.

I know that my usage might be wrong but I just can't make it work so I would appreciate an example.

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 11:34):

jlkiri edited issue #4138:

I am struggling with applying a limiter to the wasmtime store by using the limiter API.

Here's the code I have.

    let engine = Engine::default();
    let module = Module::new(&engine, module_bytes)?;
    let store_limits = StoreLimits::default();
    let mut store = Store::new(&engine, ());
    store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);

StoreLimits is wasmtime's StoreLimits. It doesn't compile and gives me the error:

error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
   --> src/handler.rs:140:45
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                             ^^^^^^^^^^^^^^^^^
    |
note: first, the lifetime cannot outlive the lifetime `'_` as defined here...
   --> src/handler.rs:140:19
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that closure can access `store_limits`
   --> src/handler.rs:140:45
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                             ^^^^^^^^^^^^^^^^^
note: but, the lifetime must be valid for the anonymous lifetime #1 defined here...
   --> src/handler.rs:140:19
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that the declared lifetime parameter bounds are satisfied
   --> src/handler.rs:140:35
    |
140 |     store.limiter(|data: &mut ()| lim(data, &mut store_limits));
    |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0495`.

I know that my usage might be wrong but I just can't make it work so I would appreciate an example.

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 11:35):

jlkiri edited issue #4138:

I am struggling with applying a limiter to the wasmtime store by using the limiter API.

Here's the code I have.

    let engine = Engine::default();
    let module = Module::new(&engine, module_bytes)?;
    let store_limits = StoreLimits::default();
    let mut store = Store::new(&engine, ());
    store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);

StoreLimits is wasmtime's StoreLimits. It doesn't compile and gives me the error:

error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
   --> src/handler.rs:139:23
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                       ^^^^^^^^^^^^^^^^^
    |
note: first, the lifetime cannot outlive the lifetime `'_` as defined here...
   --> src/handler.rs:139:19
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that closure can access `store_limits`
   --> src/handler.rs:139:23
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                       ^^^^^^^^^^^^^^^^^
note: but, the lifetime must be valid for the anonymous lifetime #1 defined here...
   --> src/handler.rs:139:19
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that the types are compatible
   --> src/handler.rs:139:23
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected `&mut dyn wasmtime::ResourceLimiter`
               found `&mut dyn wasmtime::ResourceLimiter`

For more information about this error, try `rustc --explain E0495`.

I know that my usage might be wrong but I just can't make it work so I would appreciate an example.

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 11:35):

jlkiri commented on issue #4138:

Why can't the API just take StoreLimits itself?

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 11:36):

jlkiri edited a comment on issue #4138:

Why can't the API just take StoreLimits itself, direcly?

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 11:36):

jlkiri edited a comment on issue #4138:

Why can't the API just take an owned / reference of StoreLimits itself, direcly?

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 11:37):

bjorn3 commented on issue #4138:

I believe you are supposed to store the ResourceLimiter implementation in the Store state and then return a reference to it from the closure you pass to limiter.

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 14:38):

alexcrichton commented on issue #4138:

Indeed the limits are intended to live within the T of the store, and the main reason for this is to avoid plumbing a generic U for the limiter everywhere in wasmtime. When working with dyn trait objects in this case the closure can't return impl ResourceLimiter or something like that.

I think the documentation could be improved here, though, with better examples and more words about how to use the API for sure!

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 14:39):

alexcrichton labeled issue #4138:

I am struggling with applying a limiter to the wasmtime store by using the limiter API.

Here's the code I have.

    let engine = Engine::default();
    let module = Module::new(&engine, module_bytes)?;
    let store_limits = StoreLimits::default();
    let mut store = Store::new(&engine, ());
    store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);

StoreLimits is wasmtime's StoreLimits. It doesn't compile and gives me the error:

error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
   --> src/handler.rs:139:23
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                       ^^^^^^^^^^^^^^^^^
    |
note: first, the lifetime cannot outlive the lifetime `'_` as defined here...
   --> src/handler.rs:139:19
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that closure can access `store_limits`
   --> src/handler.rs:139:23
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                       ^^^^^^^^^^^^^^^^^
note: but, the lifetime must be valid for the anonymous lifetime #1 defined here...
   --> src/handler.rs:139:19
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that the types are compatible
   --> src/handler.rs:139:23
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected `&mut dyn wasmtime::ResourceLimiter`
               found `&mut dyn wasmtime::ResourceLimiter`

For more information about this error, try `rustc --explain E0495`.

I know that my usage might be wrong but I just can't make it work so I would appreciate an example.

view this post on Zulip Wasmtime GitHub notifications bot (May 11 2022 at 14:39):

github-actions[bot] commented on issue #4138:

Subscribe to Label Action

cc @peterhuene

<details>
This issue or pull request has been labeled: "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.

Learn more.
</details>

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2022 at 14:47):

jlkiri commented on issue #4138:

@alexcrichton @bjorn3 Thanks! Putting the limiter in the store solved the problem

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2022 at 14:47):

jlkiri edited a comment on issue #4138:

@alexcrichton @bjorn3 Thanks! Putting the limiter in the store solved the immediate problem

view this post on Zulip Wasmtime GitHub notifications bot (May 20 2022 at 17:06):

alexcrichton closed issue #4138:

I am struggling with applying a limiter to the wasmtime store by using the limiter API.

Here's the code I have.

    let engine = Engine::default();
    let module = Module::new(&engine, module_bytes)?;
    let store_limits = StoreLimits::default();
    let mut store = Store::new(&engine, ());
    store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);

StoreLimits is wasmtime's StoreLimits. It doesn't compile and gives me the error:

error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
   --> src/handler.rs:139:23
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                       ^^^^^^^^^^^^^^^^^
    |
note: first, the lifetime cannot outlive the lifetime `'_` as defined here...
   --> src/handler.rs:139:19
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that closure can access `store_limits`
   --> src/handler.rs:139:23
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                       ^^^^^^^^^^^^^^^^^
note: but, the lifetime must be valid for the anonymous lifetime #1 defined here...
   --> src/handler.rs:139:19
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that the types are compatible
   --> src/handler.rs:139:23
    |
139 |     store.limiter(|_| &mut store_limits as &mut dyn ResourceLimiter);
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected `&mut dyn wasmtime::ResourceLimiter`
               found `&mut dyn wasmtime::ResourceLimiter`

For more information about this error, try `rustc --explain E0495`.

I know that my usage might be wrong but I just can't make it work so I would appreciate an example.


Last updated: Dec 23 2024 at 12:05 UTC