Skip to content
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

Merged
merged 4 commits into from
Jan 25, 2018

Conversation

alrz
Copy link
Member

@alrz alrz commented Jan 11, 2018

Fixes #24174

@alrz alrz requested a review from a team as a code owner January 11, 2018 19:13
Copy link
Member

@VSadov VSadov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Nice change!

@VSadov VSadov requested a review from OmarTawfik January 11, 2018 22:11
@VSadov
Copy link
Member

VSadov commented Jan 11, 2018

@dotnet/roslyn-compiler - please review

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks!

Copy link
Contributor

@OmarTawfik OmarTawfik left a 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!

@jcouv jcouv added this to the 15.8 milestone Jan 11, 2018
@jcouv jcouv added Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Jan 11, 2018
@VSadov
Copy link
Member

VSadov commented Jan 11, 2018

Also, what happens if it does not fit? Like Span<int> s = stackalloc int[int.MaxValue]

I would expect it to still emit a checked mul and throw at run time.
Can we have a test for this to be sure it does not regress?

@alrz
Copy link
Member Author

alrz commented Jan 12, 2018

I would expect it to still emit a checked mul and throw at run time.

Shouldn't that produce a warning then (for constants)? or an error since it always throw (similar to #8456).

Copy link
Contributor

@AlekseyTs AlekseyTs left a 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 alrz closed this Jan 12, 2018
@alrz alrz reopened this Jan 12, 2018
@VSadov
Copy link
Member

VSadov commented Jan 12, 2018

@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:

  • is the case likely to happen? (i.e. no point to add code to detect cases that will never happen in reality)
  • is there a chance the code is intentional? (then we should not warn)
  • introducing a new warning is breaking when /warnaserror is used and that is very common. Are the potential benefits worth the potential grief when code that used to compile no longer does.

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.

@alrz
Copy link
Member Author

alrz commented Jan 12, 2018

Filed dotnet/roslyn-analyzers#6232 for a warning candidate in warning waves

@VSadov
Copy link
Member

VSadov commented Jan 12, 2018

@dotnet-bot test windows_release_unit64_prtest please

@VSadov
Copy link
Member

VSadov commented Jan 12, 2018

runs just keep timing out for no reasons (other runs too) will reopen

@VSadov VSadov closed this Jan 12, 2018
@VSadov VSadov reopened this Jan 12, 2018
@VSadov VSadov closed this Jan 12, 2018
@VSadov VSadov reopened this Jan 12, 2018
@alrz
Copy link
Member Author

alrz commented Jan 14, 2018

@dotnet-bot test windows_release_unit64_prtest please

@alrz
Copy link
Member Author

alrz commented Jan 14, 2018

@dotnet-bot test windows_debug_unit64_prtest please

@VSadov
Copy link
Member

VSadov commented Jan 16, 2018

@dotnet-bot test windows_release_unit64_prtest please

@VSadov
Copy link
Member

VSadov commented Jan 16, 2018

@dotnet-bot test windows_debug_unit64_prtest please

@VSadov VSadov closed this Jan 17, 2018
@VSadov VSadov reopened this Jan 17, 2018
@VSadov
Copy link
Member

VSadov commented Jan 17, 2018

there are actually real failures.

tests are failing with StackOverflowException

@VSadov
Copy link
Member

VSadov commented Jan 19, 2018

@dotnet-bot test this please

@VSadov
Copy link
Member

VSadov commented Jan 19, 2018

I do not see anything in this change that could cause SO. Perhaps it was a problem in the branch..

@alrz
Copy link
Member Author

alrz commented Jan 20, 2018

looking at test results,

this-is-fine 0

@alrz
Copy link
Member Author

alrz commented Jan 20, 2018

this is driving me nuts, anything I can do locally to make sure things are ok?

@jaredpar
Copy link
Member

@alrz are the tests passing locally?

@alrz
Copy link
Member Author

alrz commented Jan 22, 2018

On my machine just the ones that require ilasm tool. No stackoverflow.

@jcouv
Copy link
Member

jcouv commented Jan 22, 2018

@alrz To repro CI-only problems, we have commands that are the same that CI uses. Look at build\scripts\cibuild.cmd. You can use that command with additional parameters (such as -testDesktop) to run tests.

@alrz
Copy link
Member Author

alrz commented Jan 22, 2018

OK, all green except for tests fixed in #24323.

local:

Roslyn.Compilers.CSharp.Emit.UnitTests.dll.2                           FAILED 00:02:04.8871981
Roslyn.Compilers.VisualBasic.Semantic.UnitTests.dll                    FAILED 00:05:08.1064356

CI (excluding timeouts):

Roslyn.Compilers.CSharp.Emit.UnitTests.dll.3                           FAILED 00:02:30.0768996

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.

@VSadov
Copy link
Member

VSadov commented Jan 25, 2018

I wonder if all required fixes have reached the branch

@VSadov VSadov closed this Jan 25, 2018
@VSadov VSadov reopened this Jan 25, 2018
{
M();
}
catch (OverflowException)
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

@alrz alrz Jan 25, 2018

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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):...
}

@VSadov
Copy link
Member

VSadov commented Jan 25, 2018

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/

@VSadov
Copy link
Member

VSadov commented Jan 25, 2018

@dotnet-bot test windows_release_unit64_prtest please

@VSadov
Copy link
Member

VSadov commented Jan 25, 2018

Thanks!!

@VSadov VSadov merged commit a68d632 into dotnet:master Jan 25, 2018
@alrz alrz deleted the stackalloc-fix branch January 25, 2018 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants