Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
F# System.TypeLoadException : The generic type 'System.Tuple`2' was used with an invalid instantiation in assembly #558
In this SO question the minimum example of a bug in Debug mode.
This code works perfectly in Release mode, but throws in Debug mode with:
In Debug mode, ILSpy shows this:
And this is ILSpy output in Release mode:
When I ran into it seemed that the compiler generated a tuple to hold the Foo parameters. This works fine for Release mode as the tuple is optimized away (I think)
Decompiled debug mode:
Decompiled release mode:
One way around this I guess would make sure the tuple removal optimization is applied in debug mode as well? Or better yet why is the extra tuple created in the first place?
For non-inline functions no tuple is generated in debug or release mode:
I haven't got very far, but I think this is a good place to start: https://github.com/Microsoft/visualfsharp/blob/master/src/fsharp/Optimizer.fs#L1431
I think part of it is because in Debug mode, dead binding elimination is disabled, and the compiler creates an invalid tuple type
I don't know if that made sense or if I'm on the right track. Maybe a way to fix it would be to have a special case for the dead code elimination to enable itself if the binding types are referencing this bad tuple type.