-
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 |
|---|---|---|
|
|
@@ -9,12 +9,29 @@ | |
| 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 | ||
| { | ||
| 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. |
||
| Debug.Assert(ContainingSymbol.OriginalDefinition == _underlyingTypeParameter.ContainingSymbol.OriginalDefinition); | ||
| } | ||
|
|
||
| internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes) | ||
| { | ||
| } | ||
|
|
||
| public override TypeParameterSymbol OriginalDefinition | ||
| => _underlyingTypeParameter.OriginalDefinition; | ||
| } | ||
|
|
||
| internal abstract class SubstitutedTypeParameterSymbolBase : WrappedTypeParameterSymbol | ||
| { | ||
| private readonly Symbol _container; | ||
| private readonly TypeMap _map; | ||
|
|
@@ -25,7 +42,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; | ||
|
|
@@ -46,17 +63,7 @@ public override Symbol ContainingSymbol | |
| } | ||
| } | ||
|
|
||
| public override TypeParameterSymbol OriginalDefinition | ||
| { | ||
| get | ||
| { | ||
| // A substituted type parameter symbol is used as a type parameter of a frame type for lambda-captured | ||
| // variables within a generic method. In that case the frame's own type parameter is an original. | ||
| return | ||
| ContainingSymbol.OriginalDefinition != _underlyingTypeParameter.ContainingSymbol.OriginalDefinition ? this : | ||
| _underlyingTypeParameter.OriginalDefinition; | ||
| } | ||
| } | ||
| public abstract override TypeParameterSymbol OriginalDefinition { get; } | ||
|
|
||
| public override TypeParameterSymbol ReducedFrom | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,17 +14,19 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols | |
| /// <summary> | ||
| /// A type parameter for a synthesized class or method. | ||
| /// </summary> | ||
| internal sealed class SynthesizedSubstitutedTypeParameterSymbol : SubstitutedTypeParameterSymbol | ||
| internal sealed class SynthesizedTypeParameterSymbol : 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. |
||
| { | ||
| /// <summary> | ||
| /// Indicates whether the synthesized type parameter should keep the original attributes by default | ||
| /// (ie. when the attribute definition doesn't have CompilerLoweringPreserveAttribute) | ||
| /// </summary> | ||
| private readonly bool _propagateAttributes; | ||
|
|
||
| public SynthesizedSubstitutedTypeParameterSymbol(Symbol owner, TypeMap map, TypeParameterSymbol substitutedFrom, int ordinal, bool propagateAttributes) | ||
| public SynthesizedTypeParameterSymbol(Symbol owner, TypeMap map, TypeParameterSymbol substitutedFrom, int ordinal, bool propagateAttributes) | ||
| : base(owner, map, substitutedFrom, ordinal) | ||
| { | ||
| Debug.Assert(ContainingSymbol.OriginalDefinition != _underlyingTypeParameter.ContainingSymbol.OriginalDefinition); | ||
|
|
||
| Debug.Assert(this.TypeParameterKind == (ContainingSymbol is MethodSymbol ? TypeParameterKind.Method : | ||
| (ContainingSymbol is NamedTypeSymbol ? TypeParameterKind.Type : | ||
| TypeParameterKind.Cref)), | ||
|
|
@@ -40,6 +42,8 @@ public override bool IsImplicitlyDeclared | |
|
|
||
| public override TypeParameterKind TypeParameterKind => ContainingSymbol is MethodSymbol ? TypeParameterKind.Method : TypeParameterKind.Type; | ||
|
|
||
| public override TypeParameterSymbol OriginalDefinition => this; | ||
|
|
||
| internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes) | ||
| { | ||
| if (ContainingSymbol.Kind == SymbolKind.NamedType && !PropagateAttributes) | ||
|
|
@@ -57,8 +61,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,8 +124,8 @@ internal TypeMap WithAlphaRename(ImmutableArray<TypeParameterSymbol> oldTypePara | |
| int ordinal = 0; | ||
| foreach (var tp in oldTypeParameters) | ||
| { | ||
| var newTp = synthesized ? | ||
| new SynthesizedSubstitutedTypeParameterSymbol(newOwner, result, tp, ordinal, propagateAttributes) : | ||
| 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 SynthesizedTypeParameterSymbol(newOwner, result, tp, ordinal, propagateAttributes) : | ||
| new SubstitutedTypeParameterSymbol(newOwner, result, tp, ordinal); | ||
| result.Mapping.Add(tp, TypeWithAnnotations.Create(newTp)); | ||
| newTypeParametersBuilder.Add(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,9 @@ internal override bool HasRuntimeSpecialName | |
| return _underlyingEvent.HasRuntimeSpecialName; | ||
| } | ||
| } | ||
|
|
||
| // If we need to un-seal this method, we should make it abstract. | ||
| 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(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Since we are keeping the name, we should check all type tests and conversions performed against this type and confirm that they are still good (i.e. shouldn't be changed to targeting
SubstitutedTypeParameterSymbolBaseinstead). #ClosedThere 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.
There are no type tests or conversions using
SubstitutedTypeParameterSymbol