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,9 @@ 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)
{
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

}
}
}
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,23 @@ internal sealed override bool HasAsyncMethodBuilderAttribute(out TypeSymbol? bui
return _originalMethod.HasAsyncMethodBuilderAttribute(out builderArgument);
}

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?

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

{
internal RewrittenMethodParameterSymbol(RewrittenMethodSymbol containingMethod, ParameterSymbol originalParameter)
: base(containingMethod, originalParameter)
{
}

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 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,25 @@
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

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

{
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

}

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

internal abstract class SubstitutedTypeParameterSymbolBase : WrappedTypeParameterSymbol
{
private readonly Symbol _container;
private readonly TypeMap _map;
Expand All @@ -25,7 +38,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// <summary>
/// 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.

{
/// <summary>
/// Indicates whether the synthesized type parameter should keep the original attributes by default
Expand Down Expand Up @@ -57,8 +57,6 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r
}
}

base.AddSynthesizedAttributes(moduleBuilder, ref attributes);

if (this.HasUnmanagedTypeConstraint)
{
AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeIsUnmanagedAttribute(this));
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Symbols/TypeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ internal TypeMap WithAlphaRename(ImmutableArray<TypeParameterSymbol> oldTypePara
int ordinal = 0;
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.

new SynthesizedSubstitutedTypeParameterSymbol(newOwner, result, tp, ordinal, propagateAttributes) :
new SubstitutedTypeParameterSymbol(newOwner, result, tp, ordinal);
result.Mapping.Add(tp, TypeWithAnnotations.Create(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,8 @@ internal override bool HasRuntimeSpecialName
return _underlyingEvent.HasRuntimeSpecialName;
}
}

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

=> 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,8 @@ public override bool IsStatic
}

internal sealed override bool IsRequired => _underlyingField.IsRequired;

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,8 @@ internal override bool GetGuidString(out string guidString)
{
return _underlyingType.GetGuidString(out guidString);
}

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 @@ -71,10 +71,7 @@ public override ImmutableArray<CSharpAttributeData> GetAttributes()
return _underlyingParameter.GetAttributes();
}

internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes)
{
_underlyingParameter.AddSynthesizedAttributes(moduleBuilder, ref attributes);
}
internal abstract override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes);

internal sealed override ConstantValue? ExplicitDefaultConstantValue
{
Expand Down
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 @@ -190,5 +192,8 @@ internal override bool HasRuntimeSpecialName
}

internal override int TryGetOverloadResolutionPriority() => _underlyingProperty.OverloadResolutionPriority;

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.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 @@ -179,5 +181,7 @@ public override ImmutableArray<CSharpAttributeData> GetAttributes()
{
return _underlyingTypeParameter.GetAttributes();
}

internal abstract override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, ref ArrayBuilder<CSharpAttributeData> attributes);
}
}
Loading