go-interpreter / wagon

wagon, a WebAssembly-based Go interpreter, for Go.
BSD 3-Clause "New" or "Revised" License
902 stars 150 forks source link

Fix type conversion panic for host-provided funcs #178

Open ericflo opened 4 years ago

ericflo commented 4 years ago

It was panicking because it's of type goFunction, not *goFunction as the line is checking for.

ericflo commented 4 years ago

I'll look into adding a new test, but one way to test it would be to run the existing host-provided func test with AOT enabled

sbinet commented 4 years ago

ping?

fabian-z commented 4 years ago

I can confirm that using host provided functions with the AOT backend enabled causes a panic for me that is fixed by this change (I tested with rebasing on top of master). If needed, I can share a minimal reproducer.

The panic happens here: https://github.com/go-interpreter/wagon/blob/dc6758ca7262efb2ef987e32e09f648300b4d007/exec/native_compile.go#L98

Stack trace:

panic: interface conversion: exec.function is exec.goFunction, not exec.compiledFunction

goroutine 1 [running]:
github.com/go-interpreter/wagon/exec.(*VM).tryNativeCompile(0xc0007fc000, 0xc00006f770, 0x0)
    /home/fabian/go/pkg/mod/github.com/go-interpreter/wagon@v0.6.1-0.20200313144839-dc6758ca7262/exec/native_compile.go:98 +0x85d
github.com/go-interpreter/wagon/exec.NewVM(0xc00013c000, 0xc0007e7f30, 0x1, 0x1, 0x0, 0x0, 0x0)
    /home/fabian/go/pkg/mod/github.com/go-interpreter/wagon@v0.6.1-0.20200313144839-dc6758ca7262/exec/vm.go:175 +0x4cd
main.main()
    /home/fabian/playground/wasm-runtime/main.go:285 +0x1a8