Skip to content

Support SkipLocalsInitAttribute in local functions#41183

Merged
RikkiGibson merged 7 commits intodotnet:features/local-function-attributesfrom
RikkiGibson:lfa-skiplocalsinit
Jan 29, 2020
Merged

Support SkipLocalsInitAttribute in local functions#41183
RikkiGibson merged 7 commits intodotnet:features/local-function-attributesfrom
RikkiGibson:lfa-skiplocalsinit

Conversation

@RikkiGibson
Copy link
Member

Related to #38801

@RikkiGibson RikkiGibson force-pushed the lfa-skiplocalsinit branch 5 times, most recently from 7f7133b to 5cd9fbf Compare January 24, 2020 19:06
Copy link
Member Author

@RikkiGibson RikkiGibson Jan 24, 2020

Choose a reason for hiding this comment

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

Deleted redundant implementation that was inadvertently left around after a merge. The implementation was already in SourceMethodSymbolWithAttributes. #ByDesign

@RikkiGibson RikkiGibson marked this pull request as ready for review January 24, 2020 19:29
@RikkiGibson RikkiGibson requested a review from a team as a code owner January 24, 2020 19:29
@RikkiGibson RikkiGibson added this to the Compiler.Next milestone Jan 24, 2020
}

// PROTOTYPE(local-function-attributes): test local function with SkipLocalsInit
public override bool AreLocalsZeroed
Copy link
Contributor

@AlekseyTs AlekseyTs Jan 27, 2020

Choose a reason for hiding this comment

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

override [](start = 15, length = 8)

Can we seal this implementation? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we need to override it in SynthesizedMethodBaseSymbol.


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

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to override it in SynthesizedMethodBaseSymbol.

SynthesizedMethodBaseSymbol inherits from SourceMemberMethodSymbol


In reply to: 371421097 [](ancestors = 371421097,371410335)

int y = 4;
y = y + y + y;

void LF()
Copy link
Contributor

@AlekseyTs AlekseyTs Jan 27, 2020

Choose a reason for hiding this comment

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

void LF() [](start = 12, length = 9)

It looks like we are missing a positive test for a scenario when a local function is nested into a lambda. #Closed

}
}

protected bool AreContainingSymbolLocalsZeroed
Copy link
Member

@agocke agocke Jan 27, 2020

Choose a reason for hiding this comment

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

You could do

protected bool AreContainingSymbolLocalsZeroed => ContainingSymbol switch
{
    SourceMethodSymbol m => m.AreLocalsZeroed,
    SourceNamedTypeSymbol t => t.AreLocalsZeroed,
    _ => true
};

#Resolved

Copy link
Member Author

@RikkiGibson RikkiGibson Jan 27, 2020

Choose a reason for hiding this comment

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

Does this handle the scenario where the ContainingSymbol is a SourceFieldSymbolFromDeclarator and the containing type has SkipLocalsInitAttribute? #Resolved

Copy link
Member Author

@RikkiGibson RikkiGibson Jan 27, 2020

Choose a reason for hiding this comment

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

I think when I was triaging this I was surprised to find this as the ContainingSymbol for some scenario or other, but I tried to create a test that would create a bad behavior here and couldn't do it, so I'm good with taking your suggestion. #Resolved

Copy link
Member Author

@RikkiGibson RikkiGibson Jan 28, 2020

Choose a reason for hiding this comment

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

Aleksey came up with a test case involving a field initializer containing a lambda, where the ContainingSymbol is a FieldSymbol and we have to instead look up to the ContainingType. So I reverted the suggestion. #Closed

Copy link
Member

@agocke agocke Jan 28, 2020

Choose a reason for hiding this comment

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

Were you thinking of a lambda inside a field initializer? #Resolved

Copy link
Member

@agocke agocke Jan 28, 2020

Choose a reason for hiding this comment

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

I could see that as being a reasonable scenario that would be broken with my code. #Resolved

public void M()
{
[System.Runtime.CompilerServices.SkipLocalsInitAttribute]
void F()
Copy link
Contributor

@AlekseyTs AlekseyTs Jan 27, 2020

Choose a reason for hiding this comment

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

void F() [](start = 8, length = 8)

I think we should also test scenarios when the attribute is applied to a containing member (including events/properties if allowed), or containing type, or containing module. #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Some of these scenarios already had tests, such as SkipLocalsInitAttributeOnMethodPropagatesToLocalFunction, but I added tests for the other scenarios you mentioned.


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

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Jan 27, 2020

Done with review pass (iteration 1) #Closed

@RikkiGibson
Copy link
Member Author

RikkiGibson commented Jan 28, 2020

@dotnet/roslyn-compiler Please review #Closed

}

[Fact]
public void SkipLocalsInitFieldInitializer()
Copy link
Contributor

@AlekseyTs AlekseyTs Jan 28, 2020

Choose a reason for hiding this comment

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

SkipLocalsInitFieldInitializer [](start = 20, length = 30)

It doesn't look like this test actually tests anything in field initializer. However, I think this is an interesting scenario to test. We could have a lambda with a local function within a field initializer. We also could have two constructors: one with an attribute and one without. It feels like the attributes on the constructors shouldn't have any effect on the lambda and the local function. But the attribute on the type/module should have an effect. Please add a test like this. #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

What's a more appropriate term for this test? "ImplicitConstructor"?


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

Copy link
Contributor

Choose a reason for hiding this comment

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

What's a more appropriate term for this test? "ImplicitConstructor"?

Yes, I think this term will describe the purpose of the test more accurately.


In reply to: 371989150 [](ancestors = 371989150,371973916)

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 4), with test suggestion

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

LGTM

@RikkiGibson RikkiGibson merged commit 053f572 into dotnet:features/local-function-attributes Jan 29, 2020
@RikkiGibson RikkiGibson deleted the lfa-skiplocalsinit branch January 29, 2020 03:21
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.

3 participants