Help with method handles

I’m trying to write some libraries to make use of project panama’s foreign function stuff, but I can’t get the best performance out of it because it seems like scala doesn’t support the most important functions on method handles.

So I’m trying to use Java method handles, and it’s not going well in scala 2 or 3. I’m getting a class cast error along the lines of “Can’t cast [LObject to MemoryAddress when using invoke and invokeExact from scala, but not if I pass the data into a Java function and invoke from there.

I believe this is because the invokes are special methods in Java, acting kinda like Scala inline methods. I’ve found that invokeWithArguments works in scala, but has a 10x performance loss compared to invoke (which itself is slower than invokeExact). It’s easy enough to write generators for n argument invoke helpers in Java and have these used by a special macro in scala 3, but it’d be better if I could use invokeExact, and I can’t write helper methods for those cause just 4 parameters and a return type would require over 110k helper methods to be generated (invokeExact is… exact about types).

Are you using the latest compiler version (2.13.6)? Cause some things were recently improved in this area. Scala 3 doesn’t seem to support those kinds of methods yet though.

This does seem to work in scala 2. Any idea when this fix might be ported to scala 3?