Skip to content

Add ImplementationAttributes to IMethodSymbol#50560

Merged
AlekseyTs merged 24 commits intodotnet:masterfrom
Youssef1313:patch-29
Feb 24, 2021
Merged

Add ImplementationAttributes to IMethodSymbol#50560
AlekseyTs merged 24 commits intodotnet:masterfrom
Youssef1313:patch-29

Conversation

@Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Jan 16, 2021

Fixes #7282

@ghost ghost added the Area-Compilers label Jan 16, 2021
@Youssef1313 Youssef1313 marked this pull request as ready for review January 16, 2021 19:25
@Youssef1313 Youssef1313 requested review from a team as code owners January 16, 2021 19:25
@jcouv jcouv added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jan 16, 2021
@jcouv
Copy link
Member

jcouv commented Jan 20, 2021

Tagging @dotnet/roslyn-compiler: I think it's sensible to make the ImplementationAttributes API public. @mavasani had identified some scenarios where that's useful. Any concerns?
Manish, can you confirm those scenarios are still applicable (we didn't already find another solution)?

@Youssef1313 Assuming we can get agreement on design change, a PR that exposes new public APIs needs direct test coverage for those APIs.

@333fred
Copy link
Member

333fred commented Jan 20, 2021

Tagging @dotnet/roslyn-compiler: I think it's sensible to make the ImplementationAttributes API public. @mavasani had identified some scenarios where that's useful. Any concerns?

My main question is: why does this need special handling? It's an attribute, right? You should be able get it through the regular API?

@333fred 333fred closed this Jan 20, 2021
@333fred 333fred reopened this Jan 20, 2021
@333fred
Copy link
Member

333fred commented Jan 20, 2021

(Didn't mean to close, sorry)

@jcouv
Copy link
Member

jcouv commented Jan 20, 2021

@333fred Those are for metadata flags. You can put set them via attributes in source, but they are not emitted as attributes.
See PopulateMethodTableRows and ImplementationAttributes in PE symbols.
Here's a sharplab example to illustrate.

@333fred
Copy link
Member

333fred commented Jan 21, 2021

Thanks for the clarification Julien. So, the main concern here is symbols from metadata, since symbols from source could retrieve the info via the existing attributes APIs?

@jcouv
Copy link
Member

jcouv commented Jan 21, 2021

There seems to be some additional value, even aside from metadata symbols.
Some methods get implementation flags for other reasons than having an MethodImplAttribute on them. See SourceMethodSymbolWithAttributes.ImplementationAttributes, SynthesizedInstanceConstructor and SynthesizedEventAccessorSymbol for example.

@333fred
Copy link
Member

333fred commented Jan 22, 2021

Done review pass (commit 2)

@Youssef1313
Copy link
Member Author

@jcouv Thanks for the ping. I addressed @AlekseyTs's feedback. But not sure why some tests are failing. Failures happens for AggressiveInlining only.

/// Misc implementation metadata flags (ImplFlags in metadata).
/// </summary>
internal abstract System.Reflection.MethodImplAttributes ImplementationAttributes { get; }
internal abstract System.Reflection.MethodImplAttributes MethodImplementationFlags { get; }
Copy link
Contributor

@AlekseyTs AlekseyTs Feb 17, 2021

Choose a reason for hiding this comment

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

MethodImplementationFlags [](start = 65, length = 25)

In my opinion this rename is unnecessary. #Closed

[InlineData("[EnumeratorCancellation] ", "")]
[InlineData("", "[EnumeratorCancellation] ")]
public void AsyncIteratorWithAwaitCompletedAndYield_WithEnumeratorCancellation_ExtendedPartialMethod(string definitionAttributes, string implementationAttributes)
public void AsyncIteratorWithAwaitCompletedAndYield_WithEnumeratorCancellation_ExtendedPartialMethod(string definitionAttributes, string MethodImplementationFlags)
Copy link
Contributor

@AlekseyTs AlekseyTs Feb 17, 2021

Choose a reason for hiding this comment

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

MethodImplementationFlags [](start = 145, length = 25)

The rename looks suspicious. #Closed

End Property

Friend Overrides ReadOnly Property ImplementationAttributes As MethodImplAttributes
Friend Overrides ReadOnly Property MethodImplementationFlags As MethodImplAttributes
Copy link
Contributor

@AlekseyTs AlekseyTs Feb 17, 2021

Choose a reason for hiding this comment

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

MethodImplementationFlags [](start = 39, length = 25)

Similar to C# I think this rename is unnecessary. #Closed

Microsoft.CodeAnalysis.GeneratorPostInitializationContext.AddSource(string hintName, string source) -> void
Microsoft.CodeAnalysis.GeneratorPostInitializationContext.CancellationToken.get -> System.Threading.CancellationToken
Microsoft.CodeAnalysis.GeneratorPostInitializationContext.GeneratorPostInitializationContext() -> void
Microsoft.CodeAnalysis.IMethodSymbol.ImplementationAttributes.get -> System.Reflection.MethodImplAttributes
Copy link
Contributor

@AlekseyTs AlekseyTs Feb 17, 2021

Choose a reason for hiding this comment

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

ImplementationAttributes [](start = 37, length = 24)

Is there an API like that. #Closed

{
var c = module.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
var aggressiveInliningMethod = c.GetMember<MethodSymbol>("M_Aggressive");
Assert.Equal(MethodImplAttributes.AggressiveInlining, aggressiveInliningMethod.MethodImplementationFlags);
Copy link
Contributor

@AlekseyTs AlekseyTs Feb 17, 2021

Choose a reason for hiding this comment

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

aggressiveInliningMethod.MethodImplementationFlags [](start = 70, length = 50)

It looks like this test doesn't actually test the added public API. Rename of the internal API made it hard to spot. I assume the other tests in this file have the same issue. #Closed

Dim validator As Action(Of ModuleSymbol) = Sub([module])
Dim c = [module].GlobalNamespace.GetMember(Of NamedTypeSymbol)("C")
Dim aggressiveInliningMethod = c.GetMember(Of MethodSymbol)("M_Aggressive")
Assert.Equal(MethodImplAttributes.AggressiveInlining, aggressiveInliningMethod.MethodImplementationFlags)
Copy link
Contributor

@AlekseyTs AlekseyTs Feb 17, 2021

Choose a reason for hiding this comment

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

aggressiveInliningMethod.MethodImplementationFlags [](start = 113, length = 50)

Same comment as for C# tests. #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Feb 17, 2021

Done with review pass (commit 17) #Closed

Copy link
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 (commit 23), assuming tests pass.

@333fred 333fred marked this pull request as ready for review February 18, 2021 18:05
Copy link
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.

These should fix the tests. The issue is that the default VB test framework is too old and doesn't have AggressiveInlining, so it doesn't compile.

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Feb 23, 2021

Done with review pass (commit 23), the CI is failing. #Closed

Co-authored-by: Fred Silberberg <fred@silberberg.xyz>
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 (commit 24)

@AlekseyTs AlekseyTs merged commit 12fc3fc into dotnet:master Feb 24, 2021
@ghost ghost added this to the Next milestone Feb 24, 2021
@AlekseyTs
Copy link
Contributor

@Youssef1313 Thanks for the contribution.

@Youssef1313 Youssef1313 deleted the patch-29 branch February 24, 2021 04:40
@allisonchou allisonchou modified the milestones: Next, 16.10.P2 Mar 29, 2021
@HelloKitty
Copy link

What version is this shipped in? Currently getting: System.TypeLoadException: Method 'get_MethodImplementationFlags' in type 'Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationMethodSymbol' from assembly 'Microsoft.CodeAnalysis.Workspaces, Version=3.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.

When referencing it was a transient property in a source generator.

@333fred
Copy link
Member

333fred commented Jun 6, 2021

Should be 3.10.

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.

Expose IMethodSymbol.ImplementationAttributes

7 participants