Skip to content

When a synthetic ref local is captured, variables referenced in its initializer must be captured too#38196

Merged
gafter merged 3 commits intodotnet:masterfrom
gafter:dev16.4-preview1-36443
Aug 30, 2019
Merged

When a synthetic ref local is captured, variables referenced in its initializer must be captured too#38196
gafter merged 3 commits intodotnet:masterfrom
gafter:dev16.4-preview1-36443

Conversation

@gafter
Copy link
Copy Markdown
Member

@gafter gafter commented Aug 21, 2019

Fixes #36443

@gafter gafter added Area-Compilers Test Test failures in roslyn-CI labels Aug 21, 2019
@gafter gafter requested review from 333fred and jcouv August 21, 2019 23:46
@gafter gafter requested a review from a team as a code owner August 21, 2019 23:46
@gafter gafter self-assigned this Aug 21, 2019
Copy link
Copy Markdown
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

This still repros locally in both master and release/dev16.4-preview1 when I run csc.exe with /target:library /debug- /optimize+ test.cs, copying and pasting from my original repro. When I build csc.exe in debug mode itself, it hits the assertion in the UnexpectedValue method, and in release mode it just hits the windows error reporting.

@gafter gafter added Investigation Required PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. labels Aug 22, 2019
@gafter gafter changed the base branch from release/dev16.4-preview1 to master August 24, 2019 16:58
@gafter gafter changed the title Add tests to demonstrate that absence of a reported bug When a synthetic ref local is captured, variables referenced in its initializer must be captured too Aug 28, 2019
@gafter gafter removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Aug 28, 2019
@gafter gafter requested a review from 333fred August 28, 2019 23:51
@gafter
Copy link
Copy Markdown
Member Author

gafter commented Aug 28, 2019

@333fred @jcouv I think I've really fixed the bug now. Could you please re-review? #Resolved

@gafter gafter added Bug and removed Investigation Required Test Test failures in roslyn-CI labels Aug 28, 2019
@gafter gafter added this to the 16.4 milestone Aug 28, 2019
else
{
_variablesToHoist.Add(variable);
if (_variablesToHoist.Add(variable) && variable is LocalSymbol local && _boundRefLocalInitializers.TryGetValue(local, out var variableInitializer))
Copy link
Copy Markdown
Member

@jcouv jcouv Aug 29, 2019

Choose a reason for hiding this comment

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

_boundRefLocalInitializers [](start = 88, length = 26)

I didn't understand: where do we add values into _boundRefLocalInitializers? Never mind. Found it #Closed

case BoundParameter { ParameterSymbol: var symbol }:
CaptureVariable(symbol, syntax);
break;
case BoundFieldAccess { FieldSymbol: { IsStatic: false, ContainingType: var containingType }, ReceiverOpt: { } receiver } when containingType.IsValueType:
Copy link
Copy Markdown
Member

@jcouv jcouv Aug 29, 2019

Choose a reason for hiding this comment

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

{ } [](start = 123, length = 3)

nit: should probably use type name here #Pending

case BoundLocal { LocalSymbol: var symbol }:
CaptureVariable(symbol, syntax);
break;
case BoundParameter { ParameterSymbol: var symbol }:
Copy link
Copy Markdown
Member

@jcouv jcouv Aug 29, 2019

Choose a reason for hiding this comment

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

BoundParameter [](start = 21, length = 14)

do we have a test for the parameter case? #Pending

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not one that would crash currently (without the fix), as I believe we always capture parameters that are used in any way. That's because the state machine starts in a "cold" state, so hoisting the parameter is necessary for it to reach its use site. So there is no way to construct an observable crash in the current compiler.

Though, hang on, I guess I could assign to the parameter before its use to repro the issue. I will attempt to construct a case that crashes currently and exercises this to fix it.


In reply to: 318840878 [](ancestors = 318840878)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, we hoist any parameter that is written to as well. I will add a test in any case so if we stop hoisting parameters just because they are written then this won't be a problem.


In reply to: 319306652 [](ancestors = 319306652,318840878)

@jcouv jcouv self-assigned this Aug 29, 2019
Copy link
Copy Markdown
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 (iteration 2)

Copy link
Copy Markdown
Member

@333fred 333fred 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 2), but could use a test case for the parameter as Julien mentioned.

@gafter gafter merged commit 7a8222a into dotnet:master Aug 30, 2019
@jcouv jcouv modified the milestones: 16.4, 16.4.P1 Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compound Assignment when ref temps are required crashes the compiler

3 participants