CodeGenerator: clean up attribute handling and remove obsolete custom-attribute build properties#9665
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request simplifies the Orleans source generator by removing support for configurable attribute lists and hardcoding the well-known Orleans attributes. The changes convert CodeGeneratorOptions from having mutable List<string> properties to const and static readonly fields, and update LibraryTypes to store single INamedTypeSymbol references instead of arrays.
Changes:
- Removed MSBuild property reading for customizable attribute lists (ImmutableAttributes, IdAttributes, AliasAttributes, GenerateSerializerAttributes) from OrleansSourceGenerator.cs
- Converted CodeGeneratorOptions from mutable Lists to const/readonly values
- Changed LibraryTypes properties from arrays to single symbols (IdAttributeTypes → IdAttributeType, ImmutableAttributes → ImmutableAttribute, GenerateSerializerAttributes → GenerateSerializerAttribute)
- Updated method calls from
HasAnyAttribute()toHasAttribute()in modified files - Removed dead code (unused
referencedAssembliesvariable, unusedGenerateSerializerAttributesproperty) - Optimized attribute retrieval by moving it outside the symbol loop
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Orleans.CodeGenerator/OrleansSourceGenerator.cs | Removed code that reads customizable attribute MSBuild properties; simplified to only read GenerateFieldIds and GenerateCompatibilityInvokers options |
| src/Orleans.CodeGenerator/CodeGenerator.cs | Changed CodeGeneratorOptions from mutable Lists to const/readonly values; updated calls to use singular attribute properties; removed dead code |
| src/Orleans.CodeGenerator/LibraryTypes.cs | Converted plural attribute property arrays to singular properties; removed unused GenerateSerializerAttributes property |
| src/Orleans.CodeGenerator/SyntaxGeneration/FSharpUtils.cs | Updated calls from HasAnyAttribute to HasAttribute for ImmutableAttribute |
Comments suppressed due to low confidence (1)
src/Orleans.CodeGenerator/OrleansSourceGenerator.cs:58
- The OrleansSourceGenerator.cs removed code that reads MSBuild properties (orleans_immutableattributes, orleans_idattributes, orleans_aliasattributes, orleans_generateserializerattributes), but the build props file at src/Orleans.CodeGenerator/build/Microsoft.Orleans.CodeGenerator.props still defines these properties.
If these properties are no longer supported, they should be removed from the build props file to avoid confusion. If they're kept for backward compatibility, consider adding comments explaining they're no longer used.
var options = new CodeGeneratorOptions();
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.orleans_generatefieldids", out var generateFieldIds) && generateFieldIds is { Length: > 0 })
{
if (Enum.TryParse(generateFieldIds, out GenerateFieldIds fieldIdOption))
{
options.GenerateFieldIds = fieldIdOption;
}
}
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.orleansgeneratecompatibilityinvokers", out var generateCompatInvokersValue)
&& bool.TryParse(generateCompatInvokersValue, out var genCompatInvokers))
{
options.GenerateCompatibilityInvokers = genCompatInvokers;
}
var codeGenerator = new CodeGenerator(context.Compilation, options);
var syntax = codeGenerator.GenerateCode(context.CancellationToken);
var sourceString = syntax.NormalizeWhitespace().ToFullString();
da76c2d to
cedf7ed
Compare
Update remaining LibraryTypes call sites, remove unused compiler-visible attribute properties, and add regression coverage for ignored custom attribute build properties. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
cedf7ed to
2c61635
Compare
…-attribute build properties (dotnet#9665) * Avoid GetAttributes in a loop unnecessarily * Cleanup attributes * Cleanup unnecessary hash set * Fix build * Fix codegen attribute cleanup follow-ups Update remaining LibraryTypes call sites, remove unused compiler-visible attribute properties, and add regression coverage for ignored custom attribute build properties. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Reuben Bond <reuben.bond@gmail.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Related to #9664, but doesn't fix it.
Microsoft Reviewers: Open in CodeFlow