koute / polkavm

A fast and secure RISC-V based virtual machine
Apache License 2.0
234 stars 47 forks source link

explicitly annotate type of `wrap_on_hostcall` #93

Closed lcnr closed 7 months ago

lcnr commented 7 months ago

wrap_on_hostcall has a generic parameter S. When calling the function this parameter is instantiated with some inference variable - _ - Let's call it ?unknown for now.

When calling exec_args.set_on_hostcall we end up equating for<'r> <S as SandBox>::Access<'r> with for<'r> <?unknown as SandBox>::Access<'r>. This currently constrains ?unknown to S, even though this may not strictly be the case.

There could theoretically exist an impl like

impl<S: Sandbox> Sandbox for Wrapper<S> {
    type Access<'r> = S::Access<'r>; 
}

with this using wrap_on_hostcall::<Wrapper<S>>(on_hostcall); would also compile.

Your code previously compiled due to a shortcoming of rustc when handling higher ranked regions. This will be fixed in https://github.com/rust-lang/rust/pull/119849 at which point your code will fail with ambiguity.

koute commented 7 months ago

Thanks!