Skip to content
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

Flatten SourceMethodSymbol hierarchy #76107

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
internal sealed class LambdaSymbol : SourceMethodSymbolWithAttributes
internal sealed class LambdaSymbol : SourceMethodSymbol
{
private readonly Binder _binder;
private readonly Symbol _containingSymbol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
internal abstract class LocalFunctionOrSourceMemberMethodSymbol : SourceMethodSymbolWithAttributes
internal abstract class LocalFunctionOrSourceMemberMethodSymbol : SourceMethodSymbol
{
private TypeWithAnnotations.Boxed? _lazyIteratorElementType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected SourceComplexParameterSymbolBase(
_lazyDefaultSyntaxValue = ConstantValue.Unset;
}

private Binder WithTypeParametersBinderOpt => (ContainingSymbol as SourceMethodSymbolWithAttributes)?.WithTypeParametersBinder;
private Binder WithTypeParametersBinderOpt => (ContainingSymbol as SourceMethodSymbol)?.WithTypeParametersBinder;

internal sealed override SyntaxReference SyntaxReference => _syntaxRef;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// things like ordinary methods and constructors, and functions
/// like lambdas and local functions.
/// </summary>
internal abstract class SourceMethodSymbol : MethodSymbol
internal abstract partial class SourceMethodSymbol : MethodSymbol
{
/// <summary>
/// If there are no constraints, returns an empty immutable array. Otherwise, returns an immutable
Expand Down
Copy link
Member

@jjonescz jjonescz Nov 28, 2024

Choose a reason for hiding this comment

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

Should we also rename the file? Perhaps to SourceMethodSymbol_Attributes.cs

Copy link
Member Author

Choose a reason for hiding this comment

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

The goal with this version was to reduce noise in git history, so I didn't.

Copy link
Member

Choose a reason for hiding this comment

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

Git would likely detect it as rename, so there would be no noise

Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// <summary>
/// A source method that can have attributes, including a member method, accessor, or local function.
/// </summary>
internal abstract class SourceMethodSymbolWithAttributes : SourceMethodSymbol, IAttributeTargetSymbol
internal abstract partial class SourceMethodSymbol : IAttributeTargetSymbol
{
private CustomAttributesBag<CSharpAttributeData> _lazyCustomAttributesBag;
private CustomAttributesBag<CSharpAttributeData> _lazyReturnTypeCustomAttributesBag;

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

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

static UnmanagedCallersOnlyAttributeData DecodeUnmanagedCallersOnlyAttributeData(SourceMethodSymbolWithAttributes @this, CSharpAttributeData attribute, Location location, BindingDiagnosticBag diagnostics)
static UnmanagedCallersOnlyAttributeData DecodeUnmanagedCallersOnlyAttributeData(SourceMethodSymbol @this, CSharpAttributeData attribute, Location location, BindingDiagnosticBag diagnostics)
{
Debug.Assert(attribute.AttributeClass is not null);
ImmutableHashSet<CodeAnalysis.Symbols.INamedTypeSymbolInternal>? callingConventionTypes = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ private SynthesizedSealedPropertyAccessor MakeSynthesizedSealedAccessor()

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

Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,7 @@ static void checkMethodOverride(
{
if (implementedMethod.HasUnscopedRefAttributeOnMethodOrProperty())
{
if (!implementingMethod.IsExplicitInterfaceImplementation && implementingMethod is SourceMethodSymbolWithAttributes &&
if (!implementingMethod.IsExplicitInterfaceImplementation && implementingMethod is SourceMethodSymbol &&
implementedMethod.ContainingModule != implementingMethod.ContainingModule)
{
checkRefStructInterfacesFeatureAvailabilityOnUnscopedRefAttribute(implementingMethod.HasUnscopedRefAttribute ? implementingMethod : implementingMethod.AssociatedSymbol, diagnostics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6876,7 +6876,7 @@ static void Main()
Assert.Equal(locationSpecifier.GetHashCode(), model.GetInterceptableLocation(node)!.GetHashCode());

// If Data changes it might be the case that 'SourceText.GetContentHash()' has changed algorithms.
// 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.
// 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.
AssertEx.Equal("xRCCFCvTOZMORzSr/fZQFlIAAABQcm9ncmFtLmNz", locationSpecifier.Data);
AssertEx.Equal("""[global::System.Runtime.CompilerServices.InterceptsLocationAttribute(1, "xRCCFCvTOZMORzSr/fZQFlIAAABQcm9ncmFtLmNz")]""", locationSpecifier.GetInterceptsLocationAttributeSyntax());

Expand Down
Loading