-
Notifications
You must be signed in to change notification settings - Fork 805
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
Inline functions in a referenced project optimized incorrectly #17903
Comments
What's the exception? What's yielded in the nightly 9.0 sdk? Does it change with realsig off? It could also be related to the additional equality generated. |
To be clear the last equality check reads |
I see, thanks. It appears that it's failing in SDK 6.0, could've been there forever. |
That's some awkward codegen. We will need to see whether it's a recent regression. If it is, we need to fix it for 9.0.200 |
Update, the new minimal repro: Library.fs (this file should be in a separate project): namespace Library
#nowarn "346"
[<Struct>]
type ID (value : string) =
member _.Value = value
member inline this.Hello(other: ID) = System.Console.WriteLine(this.Value + " " + other.Value)
type ID2 = { Value : ID } with
member inline this.Hello(other: ID2) = this.Value.Hello other.Value Program.fs: open Library
[<EntryPoint>]
let main _ =
let aBar = { Value = ID "a" }
let bBar = { Value = ID "b" }
aBar.Hello(bBar)
0
It is also not the case with static members. So the issue is that local seems not to be introduced for the Something must be missing in the optimization data/environment, since this doesn't happen if any of the following are met:
|
TLDR of the issue is that we reuse locals when we shouldn't be . |
So it seems that we don't mark |
So, the issue is that we leak address of this defensive copy out of its scope, one immediate solution would be is to never realloc for
|
In the attached example, we create three types;
In each of these we override equality and comparison operators, using inline functions to improve performance for ID3. (Note that this repro is a minimal example from more complicated code where this makes more sense!)
We create instances of each in the console app. and check that two unequal values of each type are reported as unequal by the compiler.
In Release mode only, the third assertion, that two obviously different instances of ID3 are unequal fails.
To repro, please run the attached program.
repro.zip
Expected behavior
I expect the program to exit with code 0.
Actual behavior
An exception is thrown in the last equality check, for
aBarBar
versusbBarBar
Known workarounds
Running this in debug mode fixes the issue.
Putting the definitions of ID and ID2 in the same project as ID3 fixes the issue. Because of this, I suspect this issue is something to do with incorrect optimisations around inlining functions from other projects.
Changing ID from a struct into a class by removing all the attributes associated with it fixes the issue.
Related information
Tested in .NET 8, SDKs 8.0.100 and 8.0.403
Windows 10.
VS 2022 for editing.
The text was updated successfully, but these errors were encountered: