-
Notifications
You must be signed in to change notification settings - Fork 817
Optimisation failure with structs in referenced projects #3923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@saul Yes agreed, the behaviour shouldn't change under optimization However the correct code to mutate the struct is this:
My first question is why we are not getting a "struct is being mutated" warning/error. |
@saul OK, I've looked into this more. First, if your struct types are mutable then the right way to code with them is like this:
etc. That's just the right thing to do. Now, let's consider
As a value-based language where
Now, that leaves us in an awkward situation where we are falsely assuming your .NET struct type to be immutable. As a result, I propose to make the following adjustments:
This is only a warning since it possible the user has I/O operations such as
This is implemented in #3968 |
Structs referenced from other projects have a significant optimisation failure whereby an instance of the struct cannot be passed to functions - it is always re-instantiated to empty just before the function call.
Repro steps
Imagine you have the following C# project with a single file:
The above project is referenced from F#:
Expected behavior
Output of the program is:
Actual behavior
With optimisations enabled (e.g. Release mode), the output is:
Known workarounds
No known workaround.
Related information
Severe bug, stopping me from using a C# library that uses structs.
The IL for the main function looks like:
IL_0017 and IL_0019 have been added by the optimiser - in Debug mode these instructions are not here, and the bad behaviour is not present.
Thanks
The text was updated successfully, but these errors were encountered: