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.
Problem
Some C# generator method builders reuse
ParameterProviderinstances 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:
VariableExpression/declaration references from those exactParameterProviderinstances.The distinction exists largely because parameter ownership is ambiguous.
Proposal
Generated methods should not share
ParameterProviderinstances. Each method should own its signature parameters, and body construction should use those method-owned parameter instances.Advantages
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.