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

Local function attributes emit #39226

Merged

Conversation

RikkiGibson
Copy link
Contributor

@RikkiGibson RikkiGibson commented Oct 10, 2019

Related to #38801

This PR includes emitting the attributes in metadata, but not compiler recognition of most well-known attributes for local functions in source.

@RikkiGibson RikkiGibson added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Oct 10, 2019
@RikkiGibson RikkiGibson removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Oct 16, 2019
@RikkiGibson RikkiGibson marked this pull request as ready for review October 16, 2019 23:21
@RikkiGibson RikkiGibson requested a review from a team as a code owner October 16, 2019 23:21
@RikkiGibson RikkiGibson added this to the Compiler.Next milestone Oct 16, 2019
@RikkiGibson RikkiGibson requested a review from a team October 17, 2019 18:15
@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented Oct 17, 2019

Could I please get a second sign-off @dotnet/roslyn-compiler #Closed

@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented Oct 23, 2019

Ping @dotnet/roslyn-compiler #Closed

@@ -163,6 +165,10 @@ protected override ImmutableArray<TypeSymbol> ExtraSynthesizedRefParameters
internal override bool IsExpressionBodied => false;
internal MethodSymbol TopLevelMethod => _topLevelMethod;

public override ImmutableArray<CSharpAttributeData> GetAttributes() => _originalMethod.GetAttributes();
Copy link
Member

@agocke agocke Oct 23, 2019

Choose a reason for hiding this comment

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

Hmm, I wonder if we should just override this for CCI. Maybe this should throw Unreachable? Who is asking for the attributes on a synthesized symbol? #Resolved

Copy link
Contributor Author

@RikkiGibson RikkiGibson Nov 12, 2019

Choose a reason for hiding this comment

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

This is used when emitting the synthesized symbol's attributes. #Resolved

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Oct 24, 2019

It doesn't look like we are emitting attributes on type parameters. Also, what about other attributes normally synthesized by the compiler (dynamic, nullable, etc.) Do we emit those? Should we? #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Oct 24, 2019

Done with review pass (Iteration 9) #Closed

@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented Nov 7, 2019

I was depending on NamedTypeSymbol implementing INamedTypeSymbol in some of the tests, will fix. #Closed

@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented Nov 12, 2019

Could I please get a second review @dotnet/roslyn-compiler #Closed

@agocke
Copy link
Member

agocke commented Nov 13, 2019

I'm still not clear on why we're overriding GetAttributes, which I view as a binding-level method, for retrieving attributes on synthesized symbols, instead of either IReference.GetAttributes(EmitContext) or GetAttributesToEmit.

I feel like any point where we are actually calling GetAttributes on a synthesized symbol is probably a bug, and if it wants to know the emit attributes it should call GetAttributesToEmit. #Resolved

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 13, 2019

@agocke

I'm still not clear on why we're overriding GetAttributes, which I view as a binding-level method

I am not sure why you would view things this way. The GetAttributes API doesn't imply any binding and we override it in many scenarios. Let's discuss this offline. #Closed

@agocke
Copy link
Member

agocke commented Nov 13, 2019

Talked with @AlekseyTs offline. The invariant that I thought should hold doesn't really hold. In that case, GetAttributes seems like the right thing to use. #Resolved

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 6af5960 into dotnet:features/local-function-attributes Nov 14, 2019
@RikkiGibson RikkiGibson deleted the lfa-attrs-emit branch November 14, 2019 00:43
/// <summary>
/// Indicates whether synthesized methods derived from this method should inherit the attributes of this method, its parameters, return type, and type parameters.
/// </summary>
internal virtual bool SynthesizedMethodsInheritAttributes => false;
Copy link
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.

internal virtual bool SynthesizedMethodsInheritAttributes => false; [](start = 8, length = 67)

I find this approach very fragile and error prone. There could be multiple synthesized methods of different nature associated with the same "base" method. The property whether attributes should be inherited belongs to the specific synthesized method instead. Please make the change. #Closed

@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented Nov 14, 2019

Follow up to #39226 (comment)

It doesn't look like we are emitting attributes on type parameters. Also, what about other attributes normally synthesized by the compiler (dynamic, nullable, etc.) Do we emit those? Should we?

It looks like there is still a gap for emitting the attributes of type parameters. Will make sure to address this in follow-up. #Resolved

comp.VerifyDiagnostics();
var verifier = CompileAndVerify(comp);

// PROTOTYPE: EnumeratorCancellation attribute should produce a combinedTokens field and modify codegen
Copy link
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.

PROTOTYPE [](start = 15, length = 9)

We usually add feature name after the "PROTOTYPE" word in parens. I.e. PROTOTYPE(<feature name here>). #Closed

@@ -130,6 +137,20 @@ private ImmutableArray<ParameterSymbol> MakeParameters()
return builder.ToImmutableAndFree();
}

public override ImmutableArray<CSharpAttributeData> GetAttributes()
Copy link
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.

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

sealed? #Closed

: ImmutableArray<CSharpAttributeData>.Empty;
}

public override ImmutableArray<CSharpAttributeData> GetReturnTypeAttributes()
Copy link
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.

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

sealed? #Closed


var localFn4 = cClass.GetMethod("<M>g__local4|0_3");
var attrs4 = localFn4.TypeParameters.Single().GetAttributes();
Assert.Equal("A", attrs4.Single().AttributeClass.Name);
Copy link
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.

attrs4.Single() [](start = 34, length = 15)

I don't see any change that would enable inheritance of attributes for type parameters. It looks like this is done unconditionally and unintentionally (we do want this for local functions, but not for any other case). #Closed

[Theory]
[MemberData(nameof(OptimizationLevelTheoryData))]
[WorkItem(431, "https://github.com/dotnet/roslyn/issues/431")]
public void BaseMethodWrapper_DoNotInheritAttributes(OptimizationLevel optimizationLevel)
Copy link
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 [](start = 20, length = 40)

Please include coverage for attributes on type parameters as well. #Closed

@AlekseyTs
Copy link
Contributor

Done with review pass (iteration 16)

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.

6 participants