bepu / bepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.
Apache License 2.0
2.4k stars 274 forks source link

Compilation issue when implementing IPoseIntegratorCallbacks in F# #87

Closed harrisse closed 4 years ago

harrisse commented 4 years ago

Hello, I'm not sure if F# is officially supported, but I'm trying to consume BepuPhysics from F# and am having trouble implementing IPoseIntegratorCallbacks. When I write the implementation, I get no Intellisense or normal compiler errors, but when I actually run the build I'm seeing the following exception:

FSC : error FS2014: A problem occurred writing the binary 'project\obj\Debug\netcoreapp3.0\Project.dll': Error in pass3 for type OuterModule, 
error: Error in pass3 for type InnerModule, 
error: Error in pass3 for type PoseIntegratorCallbacks, 
error: Error in GetMethodRefAsMethodDefIdx for mref = ("BepuPhysics-IPoseIntegratorCallbacks-IntegrateVelocity", "PoseIntegratorCallbacks"), 
error: Exception of type 'FSharp.Compiler.AbstractIL.ILBinaryWriter+MethodDefNotFound' was thrown.

Here's the file I'm using to trigger this behavior:

[<AutoOpen>]
module OuterModule

module InnerModule =
    [<Struct>]
    type PoseIntegratorCallbacks =
        interface IPoseIntegratorCallbacks with
            member _.AngularIntegrationMode =
                AngularIntegrationMode.ConserveMomentumWithGyroscopicTorque

            member _.PrepareForIntegration(_) =
                ()

            member _.IntegrateVelocity(_, _, _, _, _) =
                ()

Any ideas on what might be going wrong?

Thanks!

Edit: A similar implementation of INarrowPhaseCallbacks compiles fine though.

RossNordby commented 4 years ago

F# isn't 'officially' supported, in that I haven't tested it, but it would be nice if it worked and there's no fundamental reason why it shouldn't that I'm aware of.

I'm not very familiar with F#, but at a glance, this looks compiler bug-ish. The fact that a similar INarrowPhaseCallbacks works is suspicious. My other attempts at reproducing outside of the engine also failed. Might be some highly contextual issue.

I would recommend finding someone more familiar with F# and the toolchain to verify that it's not some obscure expected behavior, and if it's a bug, report it on the F# compiler repo.

Good luck, sorry I couldn't be more help!

harrisse commented 4 years ago

Ah yeah you were right, it's a compiler bug. If anyone else hits this, it's fixed in https://github.com/dotnet/fsharp/pull/8287 and should hopefully be coming soon! In the mean time I'll just implement those types in a separate C# project. Easy enough. Thanks!