Skip to content

Commit 6cc106c

Browse files
authored
Flatten SourceMethodSymbol hierarchy (#76107)
Once upon a time, there were source method symbols that didn't have attributes, and thus we had `SourceMethodSymbol` and `SourceMethodSymbolWithAttributes`, to simplify/save on symbol size for such methods. Today, there is no such difference, and the only direct implementor of `SourceMethodSymbol` is `SourceMethodSymbolWithAttributes`. Therefore, I've cleaned up the hierarchy by removing the dead intermediate class.
1 parent 47c27db commit 6cc106c

File tree

8 files changed

+11
-11
lines changed

8 files changed

+11
-11
lines changed

src/Compilers/CSharp/Portable/Symbols/Source/LambdaSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Microsoft.CodeAnalysis.CSharp.Symbols
1414
{
15-
internal sealed class LambdaSymbol : SourceMethodSymbolWithAttributes
15+
internal sealed class LambdaSymbol : SourceMethodSymbol
1616
{
1717
private readonly Binder _binder;
1818
private readonly Symbol _containingSymbol;

src/Compilers/CSharp/Portable/Symbols/Source/LocalFunctionOrSourceMemberMethodSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Microsoft.CodeAnalysis.CSharp.Symbols
99
{
10-
internal abstract class LocalFunctionOrSourceMemberMethodSymbol : SourceMethodSymbolWithAttributes
10+
internal abstract class LocalFunctionOrSourceMemberMethodSymbol : SourceMethodSymbol
1111
{
1212
private TypeWithAnnotations.Boxed? _lazyIteratorElementType;
1313

src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected SourceComplexParameterSymbolBase(
7979
_lazyDefaultSyntaxValue = ConstantValue.Unset;
8080
}
8181

82-
private Binder WithTypeParametersBinderOpt => (ContainingSymbol as SourceMethodSymbolWithAttributes)?.WithTypeParametersBinder;
82+
private Binder WithTypeParametersBinderOpt => (ContainingSymbol as SourceMethodSymbol)?.WithTypeParametersBinder;
8383

8484
internal sealed override SyntaxReference SyntaxReference => _syntaxRef;
8585

src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
1414
/// things like ordinary methods and constructors, and functions
1515
/// like lambdas and local functions.
1616
/// </summary>
17-
internal abstract class SourceMethodSymbol : MethodSymbol
17+
internal abstract partial class SourceMethodSymbol : MethodSymbol
1818
{
1919
/// <summary>
2020
/// If there are no constraints, returns an empty immutable array. Otherwise, returns an immutable

src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
2424
/// <summary>
2525
/// A source method that can have attributes, including a member method, accessor, or local function.
2626
/// </summary>
27-
internal abstract class SourceMethodSymbolWithAttributes : SourceMethodSymbol, IAttributeTargetSymbol
27+
internal abstract partial class SourceMethodSymbol : IAttributeTargetSymbol
2828
{
2929
private CustomAttributesBag<CSharpAttributeData> _lazyCustomAttributesBag;
3030
private CustomAttributesBag<CSharpAttributeData> _lazyReturnTypeCustomAttributesBag;
3131

3232
// some symbols may not have a syntax (e.g. lambdas, synthesized event accessors)
3333
protected readonly SyntaxReference syntaxReferenceOpt;
34-
protected SourceMethodSymbolWithAttributes(SyntaxReference syntaxReferenceOpt)
34+
protected SourceMethodSymbol(SyntaxReference syntaxReferenceOpt)
3535
{
3636
this.syntaxReferenceOpt = syntaxReferenceOpt;
3737
}
@@ -1106,7 +1106,7 @@ private void DecodeInterceptsLocationChecksumBased(DecodeWellKnownAttributeArgum
11061106
DeclaringCompilation.AddInterception(matchingTree.FilePath, position, attributeLocation, this);
11071107

11081108
// Caller must free the returned builder.
1109-
static ArrayBuilder<string> getNamespaceNames(SourceMethodSymbolWithAttributes @this)
1109+
static ArrayBuilder<string> getNamespaceNames(SourceMethodSymbol @this)
11101110
{
11111111
var namespaceNames = ArrayBuilder<string>.GetInstance();
11121112
for (var containingNamespace = @this.ContainingNamespace; containingNamespace?.IsGlobalNamespace == false; containingNamespace = containingNamespace.ContainingNamespace)
@@ -1424,7 +1424,7 @@ static void checkAndReportManagedTypes(TypeSymbol type, RefKind refKind, SyntaxN
14241424
}
14251425
}
14261426

1427-
static UnmanagedCallersOnlyAttributeData DecodeUnmanagedCallersOnlyAttributeData(SourceMethodSymbolWithAttributes @this, CSharpAttributeData attribute, Location location, BindingDiagnosticBag diagnostics)
1427+
static UnmanagedCallersOnlyAttributeData DecodeUnmanagedCallersOnlyAttributeData(SourceMethodSymbol @this, CSharpAttributeData attribute, Location location, BindingDiagnosticBag diagnostics)
14281428
{
14291429
Debug.Assert(attribute.AttributeClass is not null);
14301430
ImmutableHashSet<CodeAnalysis.Symbols.INamedTypeSymbolInternal>? callingConventionTypes = null;

src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbolBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ private SynthesizedSealedPropertyAccessor MakeSynthesizedSealedAccessor()
12551255

12561256
/// <summary>
12571257
/// Symbol to copy bound attributes from, or null if the attributes are not shared among multiple source property symbols.
1258-
/// Analogous to <see cref="SourceMethodSymbolWithAttributes.BoundAttributesSource"/>.
1258+
/// Analogous to <see cref="SourceMethodSymbol.BoundAttributesSource"/>.
12591259
/// </summary>
12601260
protected abstract SourcePropertySymbolBase BoundAttributesSource { get; }
12611261

src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ static void checkMethodOverride(
18901890
{
18911891
if (implementedMethod.HasUnscopedRefAttributeOnMethodOrProperty())
18921892
{
1893-
if (!implementingMethod.IsExplicitInterfaceImplementation && implementingMethod is SourceMethodSymbolWithAttributes &&
1893+
if (!implementingMethod.IsExplicitInterfaceImplementation && implementingMethod is SourceMethodSymbol &&
18941894
implementedMethod.ContainingModule != implementingMethod.ContainingModule)
18951895
{
18961896
checkRefStructInterfacesFeatureAvailabilityOnUnscopedRefAttribute(implementingMethod.HasUnscopedRefAttribute ? implementingMethod : implementingMethod.AssociatedSymbol, diagnostics);

src/Compilers/CSharp/Test/Semantic/Semantics/InterceptorsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6876,7 +6876,7 @@ static void Main()
68766876
Assert.Equal(locationSpecifier.GetHashCode(), model.GetInterceptableLocation(node)!.GetHashCode());
68776877

68786878
// If Data changes it might be the case that 'SourceText.GetContentHash()' has changed algorithms.
6879-
// In this case we need to adjust the SourceMethodSymbolWithAttributes.DecodeInterceptsLocationAttribute impl to remain compatible with v1 and consider introducing a v2 which uses the new content hash algorithm.
6879+
// In this case we need to adjust the SourceMethodSymbol.DecodeInterceptsLocationAttribute impl to remain compatible with v1 and consider introducing a v2 which uses the new content hash algorithm.
68806880
AssertEx.Equal("xRCCFCvTOZMORzSr/fZQFlIAAABQcm9ncmFtLmNz", locationSpecifier.Data);
68816881
AssertEx.Equal("""[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "xRCCFCvTOZMORzSr/fZQFlIAAABQcm9ncmFtLmNz")]""", locationSpecifier.GetInterceptsLocationAttributeSyntax());
68826882

0 commit comments

Comments
 (0)