bytecodealliance / wasmtime-dotnet

.NET embedding of Wasmtime https://bytecodealliance.github.io/wasmtime-dotnet/
Apache License 2.0
422 stars 51 forks source link

Remove slow reflection-based fallback for function callbacks. #213

Closed peterhuene closed 1 year ago

peterhuene commented 1 year ago

This PR removes the slow reflection-based fallback that is performed when a callback delegate is provided that does not conform to the (up to) 12 parameter and (up to) 4 results overloads of Function.FromCallback and Linker.DefineFunction.

As a result, functions that take more than 12 parameters or return more than 4 results must use an untyped callback where the parameters and results are passed as spans of ValueBox.

The callbacks will no longer be invoked via reflection under any circumstances.

peterhuene commented 1 year ago

@kpreisser Thanks for the feedback! You're right, the change to guide users towards an untyped callback in cases where there were too many results inadvertently let the invalid types slip through to type conversion causing the more confusing error message.

Your suggestion makes the most sense and provides a really great error message. I'll push a fix.

peterhuene commented 1 year ago

@kpreisser I've pushed up the suggested change. Would you mind reviewing if you have the time?