-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Local function attributes emit #39226
Conversation
b4a8560
to
31b8a27
Compare
src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedParameterSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedParameterSymbol.cs
Outdated
Show resolved
Hide resolved
Could I please get a second sign-off @dotnet/roslyn-compiler #Closed |
Ping @dotnet/roslyn-compiler #Closed |
src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/SynthesizedClosureMethod.cs
Outdated
Show resolved
Hide resolved
@@ -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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/SynthesizedClosureMethod.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedParameterSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedParameterSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs
Outdated
Show resolved
Hide resolved
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 |
Done with review pass (Iteration 9) #Closed |
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedParameterSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenLocalFunctionTests.cs
Outdated
Show resolved
Hide resolved
…utes' into lfa-attrs-emit
I was depending on NamedTypeSymbol implementing INamedTypeSymbol in some of the tests, will fix. #Closed |
Could I please get a second review @dotnet/roslyn-compiler #Closed |
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 |
I am not sure why you would view things this way. The |
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 |
src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/SynthesizedClosureMethod.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/SynthesizedClosureMethod.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/// <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; |
There was a problem hiding this comment.
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
Follow up to #39226 (comment)
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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
Done with review pass (iteration 16) |
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.