Skip to content

Follow-up to "Local function attributes emit"#39830

Merged
RikkiGibson merged 9 commits intodotnet:features/local-function-attributesfrom
RikkiGibson:inherit-basemethod-attributes
Nov 16, 2019
Merged

Follow-up to "Local function attributes emit"#39830
RikkiGibson merged 9 commits intodotnet:features/local-function-attributesfrom
RikkiGibson:inherit-basemethod-attributes

Conversation

@RikkiGibson
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson commented Nov 14, 2019

Follow up to #39226

I merged before all of @AlekseyTs's comments were addressed. This PR is meant to address those comments.

I think emitting local function type parameters is actually working at least in some scenarios:

var attrs4 = localFn4.TypeParameters.Single().GetAttributes();

I'll take another look over the tests and try to remember where I thought the gap was. (Edit: it was that all synthesized methods were inheriting type parameter attributes from their base method. This PR corrects that so the type parameter attributes are only inherited when expected.)

@RikkiGibson RikkiGibson added this to the Compiler.Next milestone Nov 14, 2019
@RikkiGibson RikkiGibson requested a review from a team as a code owner November 14, 2019 19:54
return _underlyingTypeParameter.GetAttributes();
}

return ImmutableArray<CSharpAttributeData>.Empty;
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Nov 14, 2019

Choose a reason for hiding this comment

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

return ImmutableArray.Empty; [](start = 12, length = 49)

This doesn't feel right. A type parameter of a generic type nested into a constructed type should return attributes from the original definition of the type parameter (please add a test). I think this logic should be moved to SynthesizedSubstitutedTypeParameterSymbol. Please check if VB has the same problem around emitting attributes when not supposed to. #Closed

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.

I ended up moving the GetAttributes() to the WrappedTypeParameterSymbol, it seems to better resemble what WrappedParameterSymbol does, and it felt like a similar default behavior was appropriate.

I added the test SubstitutedTypeParameter_Attributes which demonstrates that we carry over the type parameter attributes from the declaration after constructing the containing type.

I added a VB test which shows that the base method and return attributes are not inherited on a synthesized method. Type parameter attributes seem a little trickier because type parameter attributes don't seem to be available in VB. I could maybe try having the VB program override a method with a type parameter attribute which is defined somewhere else.


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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I could maybe try having the VB program override a method with a type parameter attribute which is defined somewhere else.

Yes please define the base class in C#. We have a helper called CreateCSharpCompilation (or similar) that VB tests use for scenarios like this. It should be possible to find examples.


In reply to: 346624109 [](ancestors = 346624109,346603239)

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.

Added the test in d933f55.


In reply to: 346949985 [](ancestors = 346949985,346624109,346603239)

[Theory]
[MemberData(nameof(OptimizationLevelTheoryData))]
[WorkItem(38801, "https://github.com/dotnet/roslyn/issues/38801")]
public void BaseMethodWrapper_DoNotInheritAttributes_TypeParameter(OptimizationLevel optimizationLevel)
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Nov 14, 2019

Choose a reason for hiding this comment

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

BaseMethodWrapper_DoNotInheritAttributes_TypeParameter [](start = 20, length = 54)

Is this test failing without the change in SubstitutedTypeParameterSymbol? #Closed

Copy link
Copy Markdown
Member Author

@RikkiGibson RikkiGibson Nov 14, 2019

Choose a reason for hiding this comment

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

Yes #Closed

@AlekseyTs
Copy link
Copy Markdown
Contributor

AlekseyTs commented Nov 14, 2019

Done with review pass (iteration 5). #Closed

@AlekseyTs
Copy link
Copy Markdown
Contributor

AlekseyTs commented Nov 15, 2019

Done with review pass (iteration 7) #Closed

{"CompilerGeneratedAttribute", "CompilerGeneratedAttribute", "DebuggerHiddenAttribute"})

AssertEx.SetEqual(expectedNames, GetAttributeNames(baseWrapper.GetAttributes()))
AssertEx.SetEqual({}, GetAttributeNames(baseWrapper.GetReturnTypeAttributes()))
Copy link
Copy Markdown
Contributor

@AlekseyTs AlekseyTs Nov 15, 2019

Choose a reason for hiding this comment

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

SetEqual [](start = 65, length = 8)

Consider using Assert.Empty here and in the test below. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And there is no reason to call GetAttributeNames when we expect no attributes.


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

Copy link
Copy Markdown
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 8)

Copy link
Copy Markdown
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

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

:shipit:

@RikkiGibson RikkiGibson merged commit 73ce1fb into dotnet:features/local-function-attributes Nov 16, 2019
@RikkiGibson RikkiGibson deleted the inherit-basemethod-attributes branch November 16, 2019 20:10
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