Skip to content

Commit 502420d

Browse files
authored
Extensions: propagate attributes on type parameters (#80032)
1 parent 8c96a1e commit 502420d

File tree

14 files changed

+809
-25
lines changed

14 files changed

+809
-25
lines changed

docs/contributing/Compiler Test Plan.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ This document provides guidance for thinking about language interactions and tes
129129
- COM interop
130130
- modopt and modreq
131131
- CompilerFeatureRequiredAttribute
132+
- CompilerLoweringPreserveAttribute
132133
- ref assemblies
133134
- extern alias
134135
- UnmanagedCallersOnly

src/Compilers/CSharp/Portable/Lowering/ClosureConversion/SynthesizedClosureMethod.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ internal SynthesizedClosureMethod(
6060
typeMap = lambdaFrame.TypeMap.WithAlphaRename(
6161
TypeMap.ConcatMethodTypeParameters(originalMethod, stopAt: lambdaFrame.OriginalContainingMethodOpt),
6262
this,
63+
propagateAttributes: false,
6364
out typeParameters);
6465
break;
6566
case ClosureKind.ThisOnly: // all type parameters on method
@@ -68,6 +69,7 @@ internal SynthesizedClosureMethod(
6869
typeMap = TypeMap.Empty.WithAlphaRename(
6970
TypeMap.ConcatMethodTypeParameters(originalMethod, stopAt: null),
7071
this,
72+
propagateAttributes: false,
7173
out typeParameters);
7274
break;
7375
default:

src/Compilers/CSharp/Portable/Lowering/MethodToClassRewriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ internal BaseMethodWrapperSymbol(NamedTypeSymbol containingType, MethodSymbol me
442442
}
443443
else
444444
{
445-
typeMap = typeMap.WithAlphaRename(methodBeingWrapped, this, out typeParameters);
445+
typeMap = typeMap.WithAlphaRename(methodBeingWrapped, this, propagateAttributes: false, out typeParameters);
446446
}
447447

448448
AssignTypeMapAndTypeParameters(typeMap, typeParameters);

src/Compilers/CSharp/Portable/Symbols/Extensions/RewrittenLambdaOrLocalFunctionSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal sealed class RewrittenLambdaOrLocalFunctionSymbol : RewrittenMethodSymb
1313
private readonly RewrittenMethodSymbol _containingMethod;
1414

1515
public RewrittenLambdaOrLocalFunctionSymbol(MethodSymbol lambdaOrLocalFunctionSymbol, RewrittenMethodSymbol containingMethod)
16-
: base(lambdaOrLocalFunctionSymbol, containingMethod.TypeMap, lambdaOrLocalFunctionSymbol.TypeParameters)
16+
: base(lambdaOrLocalFunctionSymbol, containingMethod.TypeMap, lambdaOrLocalFunctionSymbol.TypeParameters, propagateTypeParameterAttributes: false)
1717
{
1818
Debug.Assert(lambdaOrLocalFunctionSymbol.AssociatedSymbol is null);
1919
Debug.Assert(lambdaOrLocalFunctionSymbol.TryGetThisParameter(out var thisParameter) && thisParameter is null);

src/Compilers/CSharp/Portable/Symbols/Extensions/RewrittenMethodSymbol.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ internal abstract class RewrittenMethodSymbol : WrappedMethodSymbol
1515
private readonly ImmutableArray<TypeParameterSymbol> _typeParameters;
1616
private ImmutableArray<ParameterSymbol> _lazyParameters;
1717

18-
protected RewrittenMethodSymbol(MethodSymbol originalMethod, TypeMap typeMap, ImmutableArray<TypeParameterSymbol> typeParametersToAlphaRename)
18+
protected RewrittenMethodSymbol(MethodSymbol originalMethod, TypeMap typeMap, ImmutableArray<TypeParameterSymbol> typeParametersToAlphaRename, bool propagateTypeParameterAttributes)
1919
{
2020
Debug.Assert(originalMethod.IsDefinition);
2121
Debug.Assert(originalMethod.ExplicitInterfaceImplementations.IsEmpty);
2222

2323
_originalMethod = originalMethod;
24-
// Tracked by https://github.com/dotnet/roslyn/issues/78963 : Are we creating type parameters with the right emit behavior? Attributes, etc.
25-
_typeMap = typeMap.WithAlphaRename(typeParametersToAlphaRename, this, out _typeParameters);
24+
_typeMap = typeMap.WithAlphaRename(typeParametersToAlphaRename, this, propagateAttributes: propagateTypeParameterAttributes, out _typeParameters);
2625
}
2726

2827
public TypeMap TypeMap => _typeMap;

src/Compilers/CSharp/Portable/Symbols/Extensions/SourceExtensionImplementationMethodSymbol.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ internal sealed class SourceExtensionImplementationMethodSymbol : RewrittenMetho
1919
private StrongBox<byte?>? lazyNullableContext;
2020

2121
public SourceExtensionImplementationMethodSymbol(MethodSymbol sourceMethod)
22-
: base(sourceMethod, TypeMap.Empty, sourceMethod.ContainingType.TypeParameters.Concat(sourceMethod.TypeParameters))
22+
: base(sourceMethod, TypeMap.Empty, sourceMethod.ContainingType.TypeParameters.Concat(sourceMethod.TypeParameters), propagateTypeParameterAttributes: true)
2323
{
2424
Debug.Assert(sourceMethod.GetIsNewExtensionMember());
2525
Debug.Assert(sourceMethod.IsStatic || sourceMethod.ContainingType.ExtensionParameter is not null);
26-
27-
// Tracked by https://github.com/dotnet/roslyn/issues/78963 : Are we creating type parameters with the right emit behavior? Attributes, etc.
28-
// Also, they should be IsImplicitlyDeclared
2926
}
3027

3128
public override int Arity => TypeParameters.Length;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private ReducedExtensionMethodSymbol(MethodSymbol reducedFrom)
9797
Debug.Assert(reducedFrom.ParameterCount > 0);
9898

9999
_reducedFrom = reducedFrom;
100-
_typeMap = TypeMap.Empty.WithAlphaRename(reducedFrom, this, out _typeParameters);
100+
_typeMap = TypeMap.Empty.WithAlphaRename(reducedFrom, this, propagateAttributes: false, out _typeParameters);
101101
_typeArguments = _typeMap.SubstituteTypes(reducedFrom.TypeArgumentsWithAnnotations);
102102
}
103103

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void EnsureMapAndTypeParameters()
109109
Debug.Assert(ReferenceEquals(_constructedFrom, this));
110110

111111
// We're creating a new unconstructed Method from another; alpha-rename type parameters.
112-
var newMap = _inputMap.WithAlphaRename(this.OriginalDefinition, this, out typeParameters);
112+
var newMap = _inputMap.WithAlphaRename(this.OriginalDefinition, this, propagateAttributes: false, out typeParameters);
113113

114114
var prevMap = Interlocked.CompareExchange(ref _lazyMap, newMap, null);
115115
if (prevMap != null)

src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected SynthesizedContainer(string name, ImmutableArray<TypeParameterSymbol>
2929
Debug.Assert(name != null);
3030
Name = name;
3131
_constructedFromTypeParameters = typeParametersToAlphaRename;
32-
TypeMap = TypeMap.Empty.WithAlphaRename(typeParametersToAlphaRename, this, out _typeParameters);
32+
TypeMap = TypeMap.Empty.WithAlphaRename(typeParametersToAlphaRename, this, propagateAttributes: false, out _typeParameters);
3333
}
3434

3535
protected SynthesizedContainer(string name)

src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedImplementationMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public SynthesizedImplementationMethod(
4343

4444
// alpha-rename to get the implementation's type parameters
4545
var typeMap = interfaceMethod.ContainingType.TypeSubstitution ?? TypeMap.Empty;
46-
typeMap.WithAlphaRename(interfaceMethod, this, out _typeParameters);
46+
typeMap.WithAlphaRename(interfaceMethod, this, propagateAttributes: false, out _typeParameters);
4747

4848
_interfaceMethod = interfaceMethod.ConstructIfGeneric(TypeArgumentsWithAnnotations);
4949
_parameters = SynthesizedParameterSymbol.DeriveParameters(_interfaceMethod, this);

0 commit comments

Comments
 (0)