Skip to content

CodeGenerator: clean up attribute handling and remove obsolete custom-attribute build properties#9665

Merged
ReubenBond merged 5 commits into
dotnet:mainfrom
Youssef1313:dev/ygerges/sg-cleanup
Feb 15, 2026
Merged

CodeGenerator: clean up attribute handling and remove obsolete custom-attribute build properties#9665
ReubenBond merged 5 commits into
dotnet:mainfrom
Youssef1313:dev/ygerges/sg-cleanup

Conversation

@Youssef1313

@Youssef1313 Youssef1313 commented Aug 30, 2025

Copy link
Copy Markdown
Member

Related to #9664, but doesn't fix it.

Microsoft Reviewers: Open in CodeFlow

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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() to HasAttribute() in modified files
  • Removed dead code (unused referencedAssemblies variable, unused GenerateSerializerAttributes property)
  • 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();

Comment thread src/Orleans.CodeGenerator/LibraryTypes.cs
@ReubenBond ReubenBond force-pushed the dev/ygerges/sg-cleanup branch from da76c2d to cedf7ed Compare February 15, 2026 13:55
Youssef1313 and others added 5 commits February 15, 2026 06:06
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>
@ReubenBond ReubenBond force-pushed the dev/ygerges/sg-cleanup branch from cedf7ed to 2c61635 Compare February 15, 2026 14:06
@ReubenBond ReubenBond enabled auto-merge February 15, 2026 14:08
@ReubenBond ReubenBond changed the title Very little source generator cleanup CodeGenerator: clean up attribute handling and remove obsolete custom-attribute build properties Feb 15, 2026
@ReubenBond ReubenBond added this pull request to the merge queue Feb 15, 2026
Merged via the queue into dotnet:main with commit e81a265 Feb 15, 2026
59 checks passed
@Youssef1313 Youssef1313 deleted the dev/ygerges/sg-cleanup branch February 15, 2026 19:59
rkargMsft pushed a commit to rkargMsft/orleans that referenced this pull request Feb 27, 2026
…-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>
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants