fitzgen opened PR #1901 from ref-func
to master
.
fitzgen requested alexcrichton for a review on PR #1901.
alexcrichton submitted PR Review.
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
FWIW this pattern with
#[cfg]
might be good to encapsulate somewhere with something likeir::types::rsize()
fitzgen updated PR #1901 from ref-func
to master
.
fitzgen updated PR #1901 from ref-func
to master
.
fitzgen updated PR #1901 from ref-func
to master
.
fitzgen requested alexcrichton for a review on PR #1901.
fitzgen updated PR #1901 from ref-func
to master
.
fitzgen updated PR #1901 from ref-func
to master
.
alexcrichton submitted PR Review.
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
The fallout from this change seems quite large (affecting the C API and many callers of the default API), but I can't figure out why this changed?
While this makes sense for
Val
I don't think this makes sense forExtern
which is acquired from an instance, and I don't think that instances can export anull
funcref, right?
alexcrichton created PR Review Comment:
I think there's a safe conversion from
&T
toNonNull<T>
to use here?
alexcrichton created PR Review Comment:
I saw somewhere else that this was store-local, but it's also here per-instance? Could this perhaps be
*mut
and stored in theStore
instad?
alexcrichton created PR Review Comment:
Could
u64::from
be used still to avoidas
?
alexcrichton created PR Review Comment:
"b"
alexcrichton created PR Review Comment:
"c"
alexcrichton created PR Review Comment:
This expression happens a lot in this block, so perhaps this could do this at the top?
let anyfunc = self.export.anyfunc.as_ref(); // ...
alexcrichton created PR Review Comment:
"a"
alexcrichton created PR Review Comment:
Since there's already a lifetime here, perhaps this could be
&'a Store
?
alexcrichton created PR Review Comment:
I think this answers my question about where the
None
came from, but I think that we're guaranteedExportFunction
is never a "null function", right?
alexcrichton created PR Review Comment:
This got a little gnarly, mind annotating the
_
here?
alexcrichton created PR Review Comment:
Nice :+1:
alexcrichton created PR Review Comment:
An idle thought, but we could perhaps have something like:
impl Func { pub(crate) fn into_raw(self, dst: &Store) -> Result<NonNull<VMCallerCheckedAnyfunc>> { // ... } }
to bake in how you can't access the raw value without using the right store. Anyway not necessary to do here, just a thought!
alexcrichton created PR Review Comment:
I think this should write the store "null funcref" singleton instead of a null pointer, right?
alexcrichton created PR Review Comment:
Another passing though, perhaps
fn is_null(&self) -> bool
could be added toVMCallerCheckedAnyfunc
alexcrichton created PR Review Comment:
Is
NonNull::new
here necessary? This is related to my question above too I think.I figured that
ref.null
would be implemented as returning the null singleton rather than a literal null pointer. (to maketable.set
a simple store instead of having a branch to store a non-null value)
alexcrichton created PR Review Comment:
Ah it looks like there is indeed a null funcref per-store, but perhaps this could be reused for each
Instance
?
alexcrichton created PR Review Comment:
Could this perhaps go through the
Store
instead? One day if we ever support cross-compilation this'd be through that instead ofwasmtime-runtime
fitzgen submitted PR Review.
fitzgen created PR Review Comment:
wasmtime-environ
is the thing that should handle the cross compilation as it is about the environment of the compilation target, whilewasmtime-runtime
is always compiled into the target. So if we put it inwasmtime-runtime
, then it is always going to reflect the compilation target.If we wanted to support cross compilation at the
wasmtime
API level, then we would have to stop linkingwasmtime-runtime
directly, which would force us to (correctly) revisit calls to this function from thewasmtime
crate. So I think we should be good here.
fitzgen submitted PR Review.
fitzgen created PR Review Comment:
I... think you are correct. I'll look into it.
fitzgen submitted PR Review.
fitzgen created PR Review Comment:
I didn't realize that
NonNull<T>
implementsFrom<&T>
!
fitzgen submitted PR Review.
fitzgen created PR Review Comment:
FWIW, we don't use pointer equality for
VMCallerCheckedAnyfunc
s, so this would just be a memory optimization that saves two words per instance.
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
Ah yeah that's all I'm imagining, fewer small allocations here-and-there. It also sort of helps the case of "I precompiled my wasm" since we'd presumably statically allocate this anyfunc instead of trying to dynamically allocate it.
alexcrichton created PR Review Comment:
It's true yeah we're a long way away from wasmtime supporting AOT compilation, but I just figured this'd be a relatively easy future-proofing.
alexcrichton submitted PR Review.
fitzgen submitted PR Review.
fitzgen created PR Review Comment:
I think we are as future proofed as it makes sense to be given that this function is safely inside
wasmtime-runtime
, as mentioned above.I think our best path forward for AOT cross compilation is a
wasmtime-aot
crate.
fitzgen updated PR #1901 from ref-func
to master
.
fitzgen requested alexcrichton for a review on PR #1901.
fitzgen updated PR #1901 from ref-func
to master
.
fitzgen updated PR #1901 from ref-func
to master
.
fitzgen updated PR #1901 from ref-func
to master
.
alexcrichton submitted PR Review.
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
I think the
return
here can go away, or this may also benefit from a early-returnmatch
:let anyfunc = match NonNull:new(anyfunc) { Some(f) => f, None => return Val::FuncRef(None), }; // ... ~~~
fitzgen updated PR #1901 from ref-func
to master
.
fitzgen updated PR #1901 from ref-func
to master
.
fitzgen updated PR #1901 from ref-func
to master
.
fitzgen merged PR #1901.
Last updated: Dec 23 2024 at 12:05 UTC