-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Capture stackalloc size expression only if needed #24183
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Nice change!
@dotnet/roslyn-compiler - please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Can you please add a test that makes sure we optimize more complex constants as well? stackalloc int[5+6]
Thanks @alrz!
Also, what happens if it does not fit? Like I would expect it to still emit a checked |
Shouldn't that produce a warning then (for constants)? or an error since it always throw (similar to #8456). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (iteration 3)
@alrz - giving a warning should be a separate issue/workitem A general approach is that compiler must handle corner cases predictably even if such corner cases are unlikely. This change keeps such behavior and with better IL, so everyone is 👍 Some corner cases clearly indicate that the code contains an error. In such cases a warning may be considered. That is not as simple. The questions that must be asked are:
IMO the chance of breaking existing code would be low, but the benefits are also not extremely high. It seems worth logging an issue about the warning, but whether it will be accepted/rejected - hard to tell. |
Filed dotnet/roslyn-analyzers#6232 for a warning candidate in warning waves |
@dotnet-bot test windows_release_unit64_prtest please |
runs just keep timing out for no reasons (other runs too) will reopen |
@dotnet-bot test windows_release_unit64_prtest please |
@dotnet-bot test windows_debug_unit64_prtest please |
@dotnet-bot test windows_release_unit64_prtest please |
@dotnet-bot test windows_debug_unit64_prtest please |
there are actually real failures. tests are failing with |
@dotnet-bot test this please |
I do not see anything in this change that could cause SO. Perhaps it was a problem in the branch.. |
this is driving me nuts, anything I can do locally to make sure things are ok? |
@alrz are the tests passing locally? |
On my machine just the ones that require ilasm tool. No stackoverflow. |
@alrz To repro CI-only problems, we have commands that are the same that CI uses. Look at |
OK, all green except for tests fixed in #24323. local:
CI (excluding timeouts):
The VB failure doesn't appear in CI results though so I'm not sure if that's the cause. probably worth to wait for #24323 to reach master first. |
I wonder if all required fixes have reached the branch |
{ | ||
M(); | ||
} | ||
catch (OverflowException) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might not be able to catch this when it actually runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, no it is a regular overflow, not a StackOverflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is the problem. On 64bit this is not an overflow since the native int can take this value, but then it becomes SO when we localloc.
I guess on 64bit we should not run the compiled code, only validate the IL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I repro locally? Does ReleaseExe.WithPlatform(Platform.X86)
help here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or should I skip it for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both build
and test
utilities in the repo root take -test64
switch.
I think build -test64
might do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope :-), just tried build -test64
and it only did a build. Need to run test -test64
after that.
Normally our test failures are not platform specific, so we just rely on CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just make a fix and push the change to the branch.
It should really be something like:
var expectedIL = "....";
if (IntPtr.Size == 4)
{
CompileAndVerify(comp, expectedOutput: "10", verify: Verification.Fails)
. . . Verify (expectedIL):...
}
else
{
// on 64bit the native int does not overflow, so we get StackOverflow instead
// therefore we will just check the IL
CompileAndVerify(comp, verify: Verification.Fails, options:TestOptions.ReleaseDll)
. . . Verify (expectedIL):...
}
Microsoft.CodeAnalysis.Editor.UnitTests.Structure.StructureTaggerTests.OutliningTaggerTooltipText [FAIL] seems like a flaky test https://ci.dot.net/job/dotnet_roslyn/job/master/job/windows_release_unit64_prtest/11891/ |
@dotnet-bot test windows_release_unit64_prtest please |
Thanks!! |
Fixes #24174