microsoft / microsoft/typespec
[http-client-csharp] Avoid sharing ParameterProvider instances across generated methods
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
## Problem
Some C# generator method builders reuse `ParameterProvider` instances across multiple generated methods. That makes it unsafe to update a parameter in place for one method because the mutation can leak into sibling methods that reuse the same parameter object.
This came up while investigating partial method signature customization. There are currently two timing paths:
- Early method builders can clone parameters before constructing the body.
- Late customization filtering must rename existing parameters in place because the body may already hold cached `VariableExpression`/declaration references from those exact `ParameterProvider` instances.
The distinction exists largely because parameter ownership is ambiguous.
## Proposal
Generated methods should not share `ParameterProvider` instances. Each method should own its signature parameters, and body construction should use those method-owned parameter instances.
## Advantages
- Partial method customization can use one simpler model: rename the method-owned parameters in place before or during final signature resolution.
- Renaming parameters becomes safer because changes cannot leak from one generated method to another.
- Default-value stripping for partial method implementations cannot accidentally affect sibling overloads.
- Method bodies, XML docs, validation, and invocation expressions all continue to reference the same parameter declarations.
- Downstream emitters do not need to know whether a customization happens before or after body construction.
- It reduces hidden coupling in method builders and makes future visitors/refactorings safer.
## Related context
This was observed in the C# partial method customization flow, where cloned parameters are safe only before body construction, while late customization requires in-place renaming to keep body references valid.
Contributor guide
Research direction
Start by tracing the C# generator method builders and the partial method customization flow described in the issue, comparing early parameter cloning with late in-place renaming. Verify how method bodies, XML docs, validation, and invocation expressions reference ParameterProvider instances. Done means each generated method owns its signature parameters without sibling mutations or broken body references.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100