Skip to content

feat(codegen): support stable field naming and hot reload - #10932

Merged
ReubenBond merged 5 commits into
dotnet:mainfrom
koenbeuk:feature/hot-reload-safe-codegen
Sep 2, 2026
Merged

feat(codegen): support stable field naming and hot reload#10932
ReubenBond merged 5 commits into
dotnet:mainfrom
koenbeuk:feature/hot-reload-safe-codegen

Conversation

@koenbeuk

@koenbeuk koenbeuk commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Problem

Adding serialized members can change generated serializer and copier fields. Existing generated instances have already run their constructors, so newly added dependencies must remain addressable and initialize on first use for Hot Reload to succeed.

Solution

  • Give generated accessor fields stable names based on [Id] and generated codec/copier fields stable 64-bit type-identity names.
  • Enable the Hot Reload generation shape explicitly with <OrleansHotReload>true</OrleansHotReload> so normal builds retain eager readonly initialization.
  • Keep ICodecProvider available and lazily resolve dependencies added to existing serializer and copier instances.
  • Preserve eager initialization for newly constructed instances and the normal optimized generation shape when the feature is disabled.
  • Verify a real Roslyn metadata update against an existing generated copier, including a serialized member and concrete serializable type added in the same update.
  • Document the supported additive workflow and serializer-manifest restart boundary.

Supported updates add strongly typed [Id] members to [GenerateSerializer] classes and records. A restart rebuilds serializer metadata after updates which introduce new types through polymorphic declarations or container element types. Grain interfaces and generated invokable types retain their existing compatibility requirements.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings August 31, 2026 00:27
@koenbeuk
koenbeuk requested a review from ReubenBond as a code owner August 31, 2026 00:27

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.

🔵 Needs a closer look

Pull request overview

Updates the Orleans code generator to produce Hot Reload–friendlier generated serializers/copiers by stabilizing generated field naming and (optionally) enabling lazy, self-healing resolution paths in Debug/HotReloadSafe builds.

Changes:

  • Introduces stable generated field/accessor naming keyed by [Id] and by member type (with hash suffixes for collisions).
  • Adds Hot Reload–safe codegen mode (defaulting to Debug optimization level, overridable via OrleansHotReload) which stores an ICodecProvider and uses lazy ??= initialization patterns for codecs/copiers/accessors.
  • Adds targeted unit tests and refreshes source-generator snapshot baselines accordingly.
File summaries
File Description
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs Snapshot update for hot-reload-safe ctor/field shape.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs Snapshot update for hot-reload-safe ctor/field shape.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecordsWithParameterIdAttributes.verified.cs Snapshot update for stable accessor naming and lazy accessors/codecs.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecords.verified.cs Snapshot update for stable type-keyed codec/copier field names and lazy init.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs Snapshot update (formatting/line shifts) from generator changes.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs Snapshot update for codec/copier ctor signature changes and stored codec provider.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs Snapshot update (formatting/line shifts) from generator changes.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs Snapshot update for codec/copier ctor signature changes and stored codec provider.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs Snapshot update for stable field naming (e.g., _copier_ComplexData) and codec-provider storage.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.verified.cs Snapshot update for type-keyed codec/copier fields and hot-reload-safe ??= access.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClass.verified.cs Snapshot update for type-keyed codec/copier fields and hot-reload-safe ??= access.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestCompoundTypeAlias.verified.cs Snapshot update for codec-provider storage in codec/copier.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithParameterizedConstructor.verified.cs Snapshot update for codec/copier ctor signature changes and type-keyed fields.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs Snapshot update for stable accessor naming and lazy accessors.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs Snapshot update for codec/copier ctor signature changes and codec-provider storage.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs Snapshot update for type-keyed codec/copier fields and hot-reload-safe ??= access.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs Snapshot update for type-keyed codec fields and codec-provider storage.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs Snapshot update (formatting/line shifts) from generator changes.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassReferenceProperties.verified.cs Snapshot update for stable accessor naming and lazy accessors.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypesUsingFullName.verified.cs Snapshot update for type-keyed codec/copier fields and hot-reload-safe ??= access.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypes.verified.cs Snapshot update for type-keyed codec/copier fields and hot-reload-safe ??= access.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassNestedTypes.verified.cs Snapshot update for stable type-keyed codec/copier fields and lazy init.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithGeneratedActivatorConstructorAnnotation.verified.cs Snapshot update for codec-provider storage in codec/copier.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicStruct.verified.cs Snapshot update for codec-provider storage in value serializer.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs Snapshot update for codec/copier ctor signature changes and codec-provider storage.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs Snapshot update for codec-provider storage in codec/copier.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs Snapshot update for codec-provider storage and stable generated field naming.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs Snapshot update for codec-provider storage in codec/copier.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs Snapshot update for stable accessor naming and lazy accessors.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClass.verified.cs Snapshot update for codec-provider storage in codec/copier.
test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestAlias.verified.cs Snapshot update for codec-provider storage in value serializer.
test/Orleans.CodeGenerator.Tests/HotReloadCodegenTests.cs Adds tests validating Hot Reload–safe shapes, lazy init behavior, and property override behavior.
test/Orleans.CodeGenerator.Tests/GeneratedFieldNamesTests.cs Adds unit tests for stable accessor/type-keyed naming and collision handling.
src/Orleans.CodeGenerator/SyntaxGeneration/GeneratedFieldNames.cs Adds stable field/accessor naming helpers (with collision hashing).
src/Orleans.CodeGenerator/SourceGeneratorOptionsParser.cs Adds Orleans_HotReload option parsing and defaults HotReloadSafe based on optimization level.
src/Orleans.CodeGenerator/SerializerGenerator.cs Implements hot-reload-safe serializer shape (codec provider storage, lazy ??= usage, stable naming).
src/Orleans.CodeGenerator/SerializableSourceOutputGenerator.cs Wires compilation into options creation so optimization level can drive HotReloadSafe.
src/Orleans.CodeGenerator/ReferenceAssemblyDataProvider.cs Wires compilation into options creation so optimization level can drive HotReloadSafe.
src/Orleans.CodeGenerator/ProxySourceOutputGenerator.cs Wires compilation into options creation so optimization level can drive HotReloadSafe.
src/Orleans.CodeGenerator/Model/SerializableTypeDescription.cs Declares serializable types as supporting hot-reload member addition.
src/Orleans.CodeGenerator/Model/ProxyMethodDescription.cs Marks generated invokables as not supporting hot-reload member addition.
src/Orleans.CodeGenerator/Model/ISerializableTypeDescription.cs Adds SupportsHotReloadMemberAddition contract for generators.
src/Orleans.CodeGenerator/Model/GeneratedInvokableDescription.cs Marks generated invokables as not supporting hot-reload member addition.
src/Orleans.CodeGenerator/CopierGenerator.cs Implements hot-reload-safe copier shape (codec provider storage, lazy ??= usage, stable naming).
src/Orleans.CodeGenerator/CodeGeneratorOptions.cs Adds HotReloadSafe option controlling hot-reload-safe generation paths.
src/Orleans.CodeGenerator/build/Microsoft.Orleans.CodeGenerator.props Exposes OrleansHotReload (via compiler-visible Orleans_HotReload) to the generator.
Review details
  • Files reviewed: 43/46 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Orleans.CodeGenerator/SyntaxGeneration/GeneratedFieldNames.cs
Copilot AI review requested due to automatic review settings August 31, 2026 00:31

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.

🔵 Needs a closer look

Review details
  • Files reviewed: 43/46 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 31, 2026 00:41
@koenbeuk koenbeuk changed the title Enhance Orleans Code Generation with Stable Field Naming and Hot Reload Support Enhance Orleans code generation with stable field naming and Hot Reload support Aug 31, 2026

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.

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 43/46 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/Orleans.CodeGenerator/SyntaxGeneration/GeneratedFieldNames.cs Outdated
Copilot AI review requested due to automatic review settings August 31, 2026 09:16
@ReubenBond ReubenBond changed the title Enhance Orleans code generation with stable field naming and Hot Reload support feat(codegen): support stable field naming and hot reload Aug 31, 2026

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.

🔵 Needs a closer look

Review details
  • Files reviewed: 43/46 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 1, 2026 17:58

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.

🔵 Needs a closer look

Review details
  • Files reviewed: 29/46 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@ReubenBond
ReubenBond merged commit 2361237 into dotnet:main Sep 2, 2026
74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants