-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Avoid virtual implementations for AddSynthesizedAttributes
#81289
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
|
|
||
| using System.Collections.Immutable; | ||
| using System.Diagnostics; | ||
| using Microsoft.CodeAnalysis.CSharp.Emit; | ||
| using Microsoft.CodeAnalysis.PooledObjects; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.CSharp.Symbols | ||
| { | ||
|
|
@@ -115,11 +117,23 @@ internal sealed override bool HasAsyncMethodBuilderAttribute(out TypeSymbol? bui | |
| return _originalMethod.HasAsyncMethodBuilderAttribute(out builderArgument); | ||
| } | ||
|
|
||
| protected class RewrittenMethodParameterSymbol : RewrittenParameterSymbol | ||
| protected class RewrittenMethodParameterSymbol : RewrittenMethodParameterSymbolBase | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| { | ||
| internal RewrittenMethodParameterSymbol(RewrittenMethodSymbol containingMethod, ParameterSymbol originalParameter) | ||
| : base(containingMethod, originalParameter) | ||
| { | ||
| } | ||
|
|
||
| internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes) | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| } | ||
|
|
||
| protected abstract class RewrittenMethodParameterSymbolBase : RewrittenParameterSymbol | ||
| { | ||
| protected readonly RewrittenMethodSymbol _containingMethod; | ||
|
|
||
| public RewrittenMethodParameterSymbol(RewrittenMethodSymbol containingMethod, ParameterSymbol originalParameter) : | ||
| protected RewrittenMethodParameterSymbolBase(RewrittenMethodSymbol containingMethod, ParameterSymbol originalParameter) : | ||
| base(originalParameter) | ||
| { | ||
| _containingMethod = containingMethod; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,12 +9,25 @@ | |
| using System; | ||
| using System.Collections.Immutable; | ||
| using System.Diagnostics; | ||
| using Microsoft.CodeAnalysis.CSharp.Emit; | ||
| using Microsoft.CodeAnalysis.PooledObjects; | ||
| using Roslyn.Utilities; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.CSharp.Symbols | ||
| { | ||
| internal class SubstitutedTypeParameterSymbol : WrappedTypeParameterSymbol | ||
| internal sealed class SubstitutedTypeParameterSymbol : SubstitutedTypeParameterSymbolBase | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| { | ||
| internal SubstitutedTypeParameterSymbol(Symbol newContainer, TypeMap map, TypeParameterSymbol substitutedFrom, int ordinal) | ||
| : base(newContainer, map, substitutedFrom, ordinal) | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| internal abstract class SubstitutedTypeParameterSymbolBase : WrappedTypeParameterSymbol | ||
| { | ||
| private readonly Symbol _container; | ||
| private readonly TypeMap _map; | ||
|
|
@@ -25,7 +38,7 @@ internal class SubstitutedTypeParameterSymbol : WrappedTypeParameterSymbol | |
| private readonly int _mySequence; | ||
| #endif | ||
|
|
||
| internal SubstitutedTypeParameterSymbol(Symbol newContainer, TypeMap map, TypeParameterSymbol substitutedFrom, int ordinal) | ||
| internal SubstitutedTypeParameterSymbolBase(Symbol newContainer, TypeMap map, TypeParameterSymbol substitutedFrom, int ordinal) | ||
| : base(substitutedFrom) | ||
| { | ||
| _container = newContainer; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols | |
| /// <summary> | ||
| /// A type parameter for a synthesized class or method. | ||
| /// </summary> | ||
| internal sealed class SynthesizedSubstitutedTypeParameterSymbol : SubstitutedTypeParameterSymbol | ||
| internal sealed class SynthesizedSubstitutedTypeParameterSymbol : SubstitutedTypeParameterSymbolBase | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should change name of this type. I think it always represents a definition of a synthesized type parameter and "Substituted" in the name adds some confusion. I suggest removing it and use "SynthesizedTypeParameterSymbol" as the name for the class.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then adding synthesized attributes would totally make sense for this symbol. |
||
| { | ||
| /// <summary> | ||
| /// Indicates whether the synthesized type parameter should keep the original attributes by default | ||
|
|
@@ -57,8 +57,6 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r | |
| } | ||
| } | ||
|
|
||
| base.AddSynthesizedAttributes(moduleBuilder, ref attributes); | ||
|
|
||
| if (this.HasUnmanagedTypeConstraint) | ||
| { | ||
| AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeIsUnmanagedAttribute(this)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,7 @@ internal TypeMap WithAlphaRename(ImmutableArray<TypeParameterSymbol> oldTypePara | |
| int ordinal = 0; | ||
| foreach (var tp in oldTypeParameters) | ||
| { | ||
| var newTp = synthesized ? | ||
| TypeParameterSymbol newTp = synthesized ? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, the types no longer inherit from each other, a target type is necessary. |
||
| new SynthesizedSubstitutedTypeParameterSymbol(newOwner, result, tp, ordinal, propagateAttributes) : | ||
| new SubstitutedTypeParameterSymbol(newOwner, result, tp, ordinal); | ||
| result.Mapping.Add(tp, TypeWithAnnotations.Create(newTp)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| using System.Diagnostics; | ||
| using System.Globalization; | ||
| using System.Threading; | ||
| using Microsoft.CodeAnalysis.CSharp.Emit; | ||
| using Microsoft.CodeAnalysis.PooledObjects; | ||
| using Roslyn.Utilities; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.CSharp.Symbols | ||
|
|
@@ -162,5 +164,8 @@ internal override bool HasRuntimeSpecialName | |
| return _underlyingEvent.HasRuntimeSpecialName; | ||
| } | ||
| } | ||
|
|
||
| internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| => throw ExceptionUtilities.Unreachable(); | ||
| } | ||
| } | ||
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 implementation looks suspicious, unless we can throw unreachable in it