Skip to content

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Nov 17, 2025

Closes #78655

@jcouv jcouv self-assigned this Nov 17, 2025
foreach (var tp in oldTypeParameters)
{
var newTp = synthesized ?
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.

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
internal class SubstitutedTypeParameterSymbol : WrappedTypeParameterSymbol
internal sealed class SubstitutedTypeParameterSymbol : SubstitutedTypeParameterSymbolBase
Copy link
Contributor

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).

/// A type parameter for a synthesized class or method.
/// </summary>
internal sealed class SynthesizedSubstitutedTypeParameterSymbol : SubstitutedTypeParameterSymbol
internal sealed class SynthesizedSubstitutedTypeParameterSymbol : SubstitutedTypeParameterSymbolBase
Copy link
Contributor

Choose a reason for hiding this comment

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

SynthesizedSubstitutedTypeParameterSymbol

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then adding synthesized attributes would totally make sense for this symbol.

@AlekseyTs
Copy link
Contributor

    {

I suggest asserting the following condition in this constructor:

ContainingSymbol.OriginalDefinition != _underlyingTypeParameter.ContainingSymbol.OriginalDefinition

Refers to: src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSubstitutedTypeParameterSymbol.cs:27 in 4b84820. [](commit_id = 4b84820, deletion_comment = False)

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

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

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Nov 19, 2025

    public override TypeParameterSymbol OriginalDefinition

Since we are splitting types, I suggest to keep going and splitting implementation of this method as well by doing the following:

  • Making it abstract override here
  • Returning _underlyingTypeParameter.OriginalDefinition from implementation in SubstitutedTypeParameterSymbol
  • Returning this from implementation in SynthesizedSubstitutedTypeParameterSymbol

Refers to: src/Compilers/CSharp/Portable/Symbols/SubstitutedTypeParameterSymbol.cs:62 in 4b84820. [](commit_id = 4b84820, deletion_comment = False)

}
}

internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
Copy link
Contributor

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

}

internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
{
Copy link
Contributor

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

}

protected class RewrittenMethodParameterSymbol : RewrittenParameterSymbol
protected class RewrittenMethodParameterSymbol : RewrittenMethodParameterSymbolBase
Copy link
Contributor

Choose a reason for hiding this comment

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

class

sealed?

}

internal sealed override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
{
Copy link
Contributor

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

}

protected class RewrittenMethodParameterSymbol : RewrittenParameterSymbol
protected class RewrittenMethodParameterSymbol : RewrittenMethodParameterSymbolBase
Copy link
Contributor

Choose a reason for hiding this comment

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

RewrittenMethodParameterSymbol

Similar suggestion for type checks/conversions since we are splitting the type and keeping the name

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid virtual implementations for AddSynthesizedAttributes

2 participants