Skip to content
Open
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 @@ -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
{
Expand Down Expand Up @@ -37,5 +39,8 @@ internal override ImmutableArray<int> InterpolatedStringHandlerArgumentIndexes
}

internal override bool HasInterpolatedStringHandlerArgumentError => _underlyingParameter.HasInterpolatedStringHandlerArgumentError;

internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis.CSharp.Symbols
Expand Down Expand Up @@ -37,5 +38,8 @@ protected override ImmutableArray<ParameterSymbol> MakeParameters()
{
return ImmutableArray<ParameterSymbol>.CastUp(_originalMethod.Parameters.SelectAsArray(static (p, @this) => new RewrittenMethodParameterSymbol(@this, p), this));
}

internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -115,11 +117,22 @@ internal sealed override bool HasAsyncMethodBuilderAttribute(out TypeSymbol? bui
return _originalMethod.HasAsyncMethodBuilderAttribute(out builderArgument);
}

protected class RewrittenMethodParameterSymbol : RewrittenParameterSymbol
protected sealed class RewrittenMethodParameterSymbol : RewrittenMethodParameterSymbolBase
{
internal RewrittenMethodParameterSymbol(RewrittenMethodSymbol containingMethod, ParameterSymbol originalParameter)
: base(containingMethod, originalParameter)
{
}

internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public override string GetDocumentationCommentXml(CultureInfo? preferredCulture
return result;
}

private sealed class ExtensionMetadataMethodParameterSymbol : RewrittenMethodParameterSymbol
private sealed class ExtensionMetadataMethodParameterSymbol : RewrittenMethodParameterSymbolBase
{
public ExtensionMetadataMethodParameterSymbol(SourceExtensionImplementationMethodSymbol containingMethod, ParameterSymbol sourceParameter) :
base(containingMethod, sourceParameter)
Expand All @@ -205,8 +205,6 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r
valueParameter.AddSynthesizedFlowAnalysisAttributes(ref attributes);
}

// Synthesized nullability attributes are context-dependent, so we intentionally do not call base.AddSynthesizedAttributes here
// as that would delegate to underlying parameter symbol
SourceParameterSymbolBase.AddSynthesizedAttributes(this, moduleBuilder, ref attributes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.Collections;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;

Expand Down Expand Up @@ -423,6 +424,9 @@ internal sealed override bool HasAsyncMethodBuilderAttribute(out TypeSymbol? bui

internal override int TryGetOverloadResolutionPriority()
=> UnderlyingMethod.TryGetOverloadResolutionPriority();

internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}

internal sealed class NativeIntegerParameterSymbol : WrappedParameterSymbol
Expand Down Expand Up @@ -466,6 +470,9 @@ internal NativeIntegerParameterSymbol(NativeIntegerTypeSymbol containingType, Na

public override int GetHashCode() => _underlyingParameter.GetHashCode();

internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();

#if !DEBUG
void Cci.IReference.Dispatch(Cci.MetadataVisitor visitor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Globalization;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;

Expand Down Expand Up @@ -702,6 +703,9 @@ public sealed override int GetHashCode()
{
return Hash.Combine(ContainingSymbol, _underlyingParameter.Ordinal);
}

internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,8 @@ internal sealed override bool HasAsyncMethodBuilderAttribute(out TypeSymbol buil
builderArgument = null;
return false;
}

internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis.CSharp.Symbols.Retargeting
{
Expand Down Expand Up @@ -159,6 +160,9 @@ internal sealed override int CallerArgumentExpressionParameterIndex
{
get { return _underlyingParameter.CallerArgumentExpressionParameterIndex; }
}

internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}

internal sealed class RetargetingMethodParameterSymbol : RetargetingParameterSymbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using Roslyn.Utilities;
using System.Diagnostics;
using System.Globalization;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis.CSharp.Symbols.Retargeting
{
Expand Down Expand Up @@ -113,5 +115,8 @@ internal override TypeSymbol GetDeducedBaseType(ConsList<TypeParameterSymbol> in
{
get { return null; }
}

internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics;
using System.Threading;
using Microsoft.CodeAnalysis.Collections;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;

Expand Down Expand Up @@ -486,5 +487,8 @@ internal sealed override bool HasAsyncMethodBuilderAttribute(out TypeSymbol buil
{
return _underlyingMethod.HasAsyncMethodBuilderAttribute(out builderArgument);
}

internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -127,5 +129,8 @@ public sealed override int GetHashCode()
{
return Roslyn.Utilities.Hash.Combine(ContainingSymbol, _underlyingParameter.Ordinal);
}

internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 19, 2025

Choose a reason for hiding this comment

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

SubstitutedTypeParameterSymbol

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 SubstitutedTypeParameterSymbolBase instead). #Closed

Copy link
Member Author

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

{
internal SubstitutedTypeParameterSymbol(Symbol newContainer, TypeMap map, TypeParameterSymbol substitutedFrom, int ordinal)
: base(newContainer, map, substitutedFrom, ordinal)
{
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 19, 2025

Choose a reason for hiding this comment

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

{

I suggest asserting the following condition in this constructor:

ContainingSymbol.OriginalDefinition == _underlyingTypeParameter.ContainingSymbol.OriginalDefinition
``` #Closed

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;
Expand All @@ -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;
Expand All @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

SynthesizedTypeParameterSymbol

Consider renaming the file as well

{
/// <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)),
Expand All @@ -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)
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Symbols/TypeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 19, 2025

Choose a reason for hiding this comment

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

TypeParameterSymbol

It looks like this is the only change in this file, and it is mostly stylistic. Consider reverting. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Contributor

@AlekseyTs AlekseyTs Nov 19, 2025

Choose a reason for hiding this comment

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

sealed

Consider adding a comment saying that, if we need to un-seal this method, we should make it abstract. And in other similar places #Closed

=> throw ExceptionUtilities.Unreachable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Diagnostics;
using System.Globalization;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
Expand Down Expand Up @@ -206,5 +208,9 @@ public override bool IsStatic
}

internal sealed override bool IsRequired => _underlyingField.IsRequired;

// If we need to un-seal this method, we should make it abstract.
internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Collections.Immutable;
using System.Globalization;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
Expand Down Expand Up @@ -364,5 +366,7 @@ internal override bool GenerateDebugInfo
internal sealed override bool HasUnscopedRefAttribute => UnderlyingMethod.HasUnscopedRefAttribute;

internal sealed override bool UseUpdatedEscapeRules => UnderlyingMethod.UseUpdatedEscapeRules;

internal abstract override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Globalization;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
Expand Down Expand Up @@ -258,5 +260,9 @@ internal override bool GetGuidString(out string guidString)
{
return _underlyingType.GetGuidString(out guidString);
}

// If we need to un-seal this method, we should make it abstract.
internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
=> throw ExceptionUtilities.Unreachable();
}
}
Loading
Loading