Invalidate the full constructor with the constructor cache - #11745
Invalidate the full constructor with the constructor cache#11745JoshLove-msft wants to merge 1 commit into
Conversation
Ensure ModelProvider clears its cached FullConstructor whenever TypeProvider invalidates the constructor list, including same-value identity updates. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
|
No changes needing a change description found. |
There was a problem hiding this comment.
Pull request overview
This PR refines constructor caching in the C# generator’s provider layer by centralizing constructor-cache invalidation and ensuring ModelProvider.FullConstructor is rebuilt whenever the constructor list is invalidated (including “same identity” updates). This prevents repeated application of constructor mutations when providers rebuild constructors without changing name/namespace.
Changes:
- Introduces a constructor-reset hook in
TypeProviderand routes constructor invalidation through it. - Clears
ModelProvider’s cachedFullConstructorwhenever constructors are reset. - Extends regression coverage to include same-value identity updates that still force constructor rebuilds.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/TypeProvider.cs | Centralizes constructor invalidation through a dedicated reset hook used by Reset() and identity-based updates. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/ModelProvider.cs | Hooks constructor invalidation to also clear the cached FullConstructor, simplifying FullConstructor caching logic. |
| packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelProviderTests.cs | Adds regression assertions for same-identity Update calls to ensure FullConstructor is rebuilt and mutations aren’t duplicated. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Validated this fix against the downstream management generator path from Azure/azure-sdk-for-net#61958:
Restoring the published 20260821.2 core generator reproduces the duplicate assignments, propagator calls, and pragmas. --generated by Copilot |
|
Jorge Rangel (@jorgerangel-msft) this is the follow-up to #11737 for the same-value identity update path that the identity tuple does not catch. Full CI is green, and I validated it end-to-end against Azure/azure-sdk-for-net#61958 with the local workaround removed: 42 focused tests pass and regeneration is unchanged. When you have a chance, could you review this follow-up? --generated by Copilot |
Summary
Context
Follow-up to #11737. That fix keys FullConstructor only on name and namespace, but Update(name: provider.Name) still invalidates Constructors while preserving that identity. Derived providers that mutate FullConstructor during BuildConstructors then apply those mutations repeatedly. This is exercised downstream by Azure/azure-sdk-for-net#61958 while fixing Azure/azure-sdk-for-net#61851.
Validation