-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Constant evaluation related to Float-> Int conversion are somehow broken in Roslyn #54994
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
I suspect this is expected behavior. Cast from Quite a while ago, Roslyn was changed to always return I can also say that the results you see for this cast at runtime is because of the fact that the Jit compiler decomposes |
I understand that undefined behavior will give different results on different platforms. Anyway, I expected that no one would break the legacy behavior of compiler. At least I expected a compiller warning in this case. In my case only tests have broken, someone might have a working code broken. |
We could consider this as part of a warning wave. What do you think @jaredpar ? We were willing to change behavior (Which caused a runtime break), so i think adding a source time warning seems fine. |
Just to clarify, the behavior was already "broken". If you ran the compiler on a given platform, the result was dependent on what the underlying hardware did which could (and did) differ between x64 and Arm64. It might also have already differed between x86/x64 using SSE2 and the legacy x87 FPU unit or other scenarios. |
My instinct is no here for a couple of reasons. As @tannergooding points out this was always a broken scenario and didn't have deterministic output. The other reason is that we've actually changed floating point behavior a number of times (at both the compiler and runtime level) over the lifetime of Roslyn. In this one particular case yes we could issue a warning wave but in the general case we cannot. This particular change doesn't feel compelling enough to be the one case we add a warning wave for. |
It doesn't seem like this is specific to Expression Evaluation, but also occurs when compiling code in cs file. Moving to the compiler. |
I guess i'm not asking about the general case :) I'm asking about this specific case. If the user is generally just going to be broken in some fashion (i mean, we're detecting this and clearly just collapsing to 0), we might as well warn right? Or are you saying that this shouldn't even be a warning wave, it should be a pure warning? |
The compiler would only be able to detect the constant case and there are other "issues" with floating-point that are likely more prominent. For example, converting Likewise, conversion of Users also frequently hit issues with doing things like There isn't really an action the user can take either, outside maybe putting it in |
That already seems helpful :-) |
Description
Prior to unknown version of CS compiler this expression evaluates to 24:
Now it evaluates to
0
.Mono/old .NET Framework compiler evaluates it to 24.
If you do this conversion in runtime like this:
You get a right result. So something is broken in constant evaluation for Roslyn compiler.
Configuration
Regression?
Yes, but I don't know which version did broke it.
The text was updated successfully, but these errors were encountered: