Skip to content

Commit 5bbb201

Browse files
author
Julien Couvreur
authored
Extensions: change naming convention and update attribute name (#79829)
1 parent 70384b5 commit 5bbb201

38 files changed

+1878
-1832
lines changed

src/Compilers/CSharp/Portable/Emitter/Model/PEAssemblyBuilder.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal abstract class PEAssemblyBuilderBase : PEModuleBuilder, Cci.IAssemblyRe
4545
private SynthesizedEmbeddedNativeIntegerAttributeSymbol _lazyNativeIntegerAttribute;
4646
private SynthesizedEmbeddedScopedRefAttributeSymbol _lazyScopedRefAttribute;
4747
private SynthesizedEmbeddedRefSafetyRulesAttributeSymbol _lazyRefSafetyRulesAttribute;
48-
private SynthesizedEmbeddedExtensionMarkerNameAttributeSymbol _lazyExtensionMarkerNameAttribute;
48+
private SynthesizedEmbeddedExtensionMarkerAttributeSymbol _lazyExtensionMarkerAttribute;
4949

5050
/// <summary>
5151
/// The behavior of the C# command-line compiler is as follows:
@@ -112,7 +112,7 @@ internal sealed override ImmutableArray<NamedTypeSymbol> GetEmbeddedTypes(Bindin
112112
builder.AddIfNotNull(_lazyNativeIntegerAttribute);
113113
builder.AddIfNotNull(_lazyScopedRefAttribute);
114114
builder.AddIfNotNull(_lazyRefSafetyRulesAttribute);
115-
builder.AddIfNotNull(_lazyExtensionMarkerNameAttribute);
115+
builder.AddIfNotNull(_lazyExtensionMarkerAttribute);
116116

117117
return builder.ToImmutableAndFree();
118118
}
@@ -339,18 +339,18 @@ protected override SynthesizedAttributeData TrySynthesizeParamCollectionAttribut
339339
return base.TrySynthesizeParamCollectionAttribute();
340340
}
341341

342-
protected override SynthesizedAttributeData TrySynthesizeExtensionMarkerNameAttribute(string markerName)
342+
protected override SynthesizedAttributeData TrySynthesizeExtensionMarkerAttribute(string markerName)
343343
{
344-
if ((object)_lazyExtensionMarkerNameAttribute != null)
344+
if ((object)_lazyExtensionMarkerAttribute != null)
345345
{
346346
return SynthesizedAttributeData.Create(
347347
Compilation,
348-
_lazyExtensionMarkerNameAttribute.Constructors[0],
348+
_lazyExtensionMarkerAttribute.Constructors[0],
349349
[new TypedConstant(Compilation.GetSpecialType(SpecialType.System_String), TypedConstantKind.Primitive, markerName)],
350350
ImmutableArray<KeyValuePair<string, TypedConstant>>.Empty);
351351
}
352352

353-
return base.TrySynthesizeExtensionMarkerNameAttribute(markerName);
353+
return base.TrySynthesizeExtensionMarkerAttribute(markerName);
354354
}
355355

356356
internal override SynthesizedEmbeddedAttributeSymbol TryGetSynthesizedIsUnmanagedAttribute()
@@ -516,13 +516,13 @@ private void CreateEmbeddedAttributesIfNeeded(BindingDiagnosticBag diagnostics)
516516
CreateRefSafetyRulesAttributeSymbol);
517517
}
518518

519-
if ((needsAttributes & EmbeddableAttributes.ExtensionMarkerNameAttribute) != 0)
519+
if ((needsAttributes & EmbeddableAttributes.ExtensionMarkerAttribute) != 0)
520520
{
521521
CreateAttributeIfNeeded(
522-
ref _lazyExtensionMarkerNameAttribute,
522+
ref _lazyExtensionMarkerAttribute,
523523
diagnostics,
524-
AttributeDescription.ExtensionMarkerNameAttribute,
525-
CreateExtensionMarkerNameAttributeSymbol);
524+
AttributeDescription.ExtensionMarkerAttribute,
525+
CreateExtensionMarkerAttributeSymbol);
526526
}
527527
}
528528

@@ -580,8 +580,8 @@ private SynthesizedEmbeddedRefSafetyRulesAttributeSymbol CreateRefSafetyRulesAtt
580580
GetWellKnownType(WellKnownType.System_Attribute, diagnostics),
581581
GetSpecialType(SpecialType.System_Int32, diagnostics));
582582

583-
private SynthesizedEmbeddedExtensionMarkerNameAttributeSymbol CreateExtensionMarkerNameAttributeSymbol(string name, NamespaceSymbol containingNamespace, BindingDiagnosticBag diagnostics)
584-
=> new SynthesizedEmbeddedExtensionMarkerNameAttributeSymbol(
583+
private SynthesizedEmbeddedExtensionMarkerAttributeSymbol CreateExtensionMarkerAttributeSymbol(string name, NamespaceSymbol containingNamespace, BindingDiagnosticBag diagnostics)
584+
=> new SynthesizedEmbeddedExtensionMarkerAttributeSymbol(
585585
name,
586586
containingNamespace,
587587
SourceModule,

src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,15 +1525,15 @@ internal SynthesizedAttributeData SynthesizeParamCollectionAttribute(ParameterSy
15251525
return TrySynthesizeParamCollectionAttribute();
15261526
}
15271527

1528-
internal SynthesizedAttributeData SynthesizeExtensionMarkerNameAttribute(Symbol symbol, string markerName)
1528+
internal SynthesizedAttributeData SynthesizeExtensionMarkerAttribute(Symbol symbol, string markerName)
15291529
{
15301530
if ((object)Compilation.SourceModule != symbol.ContainingModule)
15311531
{
15321532
// For symbols that are not defined in the same compilation (like NoPia), don't synthesize this attribute.
15331533
return null;
15341534
}
15351535

1536-
return TrySynthesizeExtensionMarkerNameAttribute(markerName);
1536+
return TrySynthesizeExtensionMarkerAttribute(markerName);
15371537
}
15381538

15391539
internal SynthesizedAttributeData SynthesizeIsUnmanagedAttribute(Symbol symbol)
@@ -1754,10 +1754,10 @@ protected virtual SynthesizedAttributeData TrySynthesizeParamCollectionAttribute
17541754
return Compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_ParamCollectionAttribute__ctor);
17551755
}
17561756

1757-
protected virtual SynthesizedAttributeData TrySynthesizeExtensionMarkerNameAttribute(string markerName)
1757+
protected virtual SynthesizedAttributeData TrySynthesizeExtensionMarkerAttribute(string markerName)
17581758
{
17591759
// For modules, this attribute should be present. Only assemblies generate and embed this type.
1760-
return Compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_ExtensionMarkerNameAttribute__ctor,
1760+
return Compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_ExtensionMarkerAttribute__ctor,
17611761
[new TypedConstant(Compilation.GetSpecialType(SpecialType.System_String), TypedConstantKind.Primitive, markerName)]);
17621762
}
17631763

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,9 @@ internal void EnsureScopedRefAttributeExists(BindingDiagnosticBag? diagnostics,
573573
EnsureEmbeddableAttributeExists(EmbeddableAttributes.ScopedRefAttribute, diagnostics, location, modifyCompilation);
574574
}
575575

576-
internal void EnsureExtensionMarkerNameAttributeExists(BindingDiagnosticBag? diagnostics, Location location, bool modifyCompilation)
576+
internal void EnsureExtensionMarkerAttributeExists(BindingDiagnosticBag? diagnostics, Location location, bool modifyCompilation)
577577
{
578-
EnsureEmbeddableAttributeExists(EmbeddableAttributes.ExtensionMarkerNameAttribute, diagnostics, location, modifyCompilation);
578+
EnsureEmbeddableAttributeExists(EmbeddableAttributes.ExtensionMarkerAttribute, diagnostics, location, modifyCompilation);
579579
}
580580

581581
internal bool CheckIfAttributeShouldBeEmbedded(EmbeddableAttributes attribute, BindingDiagnosticBag? diagnosticsOpt, Location locationOpt)
@@ -664,12 +664,12 @@ internal bool CheckIfAttributeShouldBeEmbedded(EmbeddableAttributes attribute, B
664664
WellKnownType.System_Runtime_CompilerServices_ParamCollectionAttribute,
665665
WellKnownMember.System_Runtime_CompilerServices_ParamCollectionAttribute__ctor);
666666

667-
case EmbeddableAttributes.ExtensionMarkerNameAttribute:
667+
case EmbeddableAttributes.ExtensionMarkerAttribute:
668668
return CheckIfAttributeShouldBeEmbedded(
669669
diagnosticsOpt,
670670
locationOpt,
671-
WellKnownType.System_Runtime_CompilerServices_ExtensionMarkerNameAttribute,
672-
WellKnownMember.System_Runtime_CompilerServices_ExtensionMarkerNameAttribute__ctor);
671+
WellKnownType.System_Runtime_CompilerServices_ExtensionMarkerAttribute,
672+
WellKnownMember.System_Runtime_CompilerServices_ExtensionMarkerAttribute__ctor);
673673

674674
default:
675675
throw ExceptionUtilities.UnexpectedValue(attribute);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ internal enum EmbeddableAttributes
2020
RefSafetyRulesAttribute = 0x100,
2121
RequiresLocationAttribute = 0x200,
2222
ParamCollectionAttribute = 0x400,
23-
ExtensionMarkerNameAttribute = 0x800,
23+
ExtensionMarkerAttribute = 0x800,
2424
}
2525
}

src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEMethodSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ public override ImmutableArray<CSharpAttributeData> GetAttributes()
10281028
filteredOutAttribute4: out _,
10291029
filterOut4: (checkForRequiredMembers && ObsoleteAttributeData is null) ? AttributeDescription.ObsoleteAttribute : default,
10301030
filteredOutAttribute5: out _,
1031-
filterOut5: AttributeDescription.ExtensionMarkerNameAttribute,
1031+
filterOut5: AttributeDescription.ExtensionMarkerAttribute,
10321032
filteredOutAttribute6: out _,
10331033
filterOut6: default);
10341034

src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ private PooledDictionary<MethodDefinitionHandle, PEMethodSymbol> CreateMethods(A
23572357
if (isOrdinaryEmbeddableStruct || module.ShouldImportMethod(_handle, methodHandle, moduleSymbol.ImportOptions))
23582358
{
23592359
// Tracked by https://github.com/dotnet/roslyn/issues/78827 : optimization, would it be worth building a map across all methods to optimize this?
2360-
if (isExtension && (!module.HasExtensionMarkerNameAttribute(methodHandle, out string markerName) || markerName != MetadataName))
2360+
if (isExtension && (!module.HasExtensionMarkerAttribute(methodHandle, out string markerName) || markerName != MetadataName))
23612361
{
23622362
// Method doesn't belong to this extension block
23632363
continue;
@@ -2388,7 +2388,7 @@ private void CreateProperties(Dictionary<MethodDefinitionHandle, PEMethodSymbol>
23882388
try
23892389
{
23902390
// Tracked by https://github.com/dotnet/roslyn/issues/78827 : optimization, would it be worth building a map across all properties to optimize this?
2391-
if (isExtension && (!module.HasExtensionMarkerNameAttribute(propertyDef, out string markerName) || markerName != MetadataName))
2391+
if (isExtension && (!module.HasExtensionMarkerAttribute(propertyDef, out string markerName) || markerName != MetadataName))
23922392
{
23932393
// Property doesn't belong to this extension block
23942394
continue;

src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEPropertySymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ public override ImmutableArray<CSharpAttributeData> GetAttributes()
740740
out CustomAttributeHandle required,
741741
AttributeDescription.RequiredMemberAttribute,
742742
out _,
743-
this.GetIsNewExtensionMember() ? AttributeDescription.ExtensionMarkerNameAttribute : default,
743+
this.GetIsNewExtensionMember() ? AttributeDescription.ExtensionMarkerAttribute : default,
744744
out _,
745745
default,
746746
out _,

src/Compilers/CSharp/Portable/Symbols/Source/FieldSymbolWithAttributesAndModifiers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttribut
213213
| ReservedAttributes.NullableAttribute
214214
| ReservedAttributes.NativeIntegerAttribute
215215
| ReservedAttributes.RequiredMemberAttribute
216-
| ReservedAttributes.ExtensionMarkerNameAttribute))
216+
| ReservedAttributes.ExtensionMarkerAttribute))
217217
{
218218
}
219219
else if (attribute.IsTargetAttribute(AttributeDescription.DateTimeConstantAttribute))

src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttribut
812812
ReservedAttributes.NullableAttribute |
813813
ReservedAttributes.NativeIntegerAttribute |
814814
ReservedAttributes.ScopedRefAttribute |
815-
ReservedAttributes.ExtensionMarkerNameAttribute))
815+
ReservedAttributes.ExtensionMarkerAttribute))
816816
{
817817
}
818818
else if (attribute.IsTargetAttribute(AttributeDescription.AllowNullAttribute))

src/Compilers/CSharp/Portable/Symbols/Source/SourceEventSymbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ protected sealed override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownA
354354
ReservedAttributes.NullableAttribute
355355
| ReservedAttributes.NativeIntegerAttribute
356356
| ReservedAttributes.TupleElementNamesAttribute
357-
| ReservedAttributes.ExtensionMarkerNameAttribute))
357+
| ReservedAttributes.ExtensionMarkerAttribute))
358358
{
359359
}
360360
else if (attribute.IsTargetAttribute(AttributeDescription.ExcludeFromCodeCoverageAttribute))

0 commit comments

Comments
 (0)