Surface IOperation info to allow analyzers to detect shadow copies for non-readonly methods over in params #58539
Labels
Area-Analyzers
Concept-API
This issue involves adding, removing, clarification, or modification of an API.
Feature Request
Milestone
Follow up from the conversation with @jaredpar and @CyrusNajmabadi in #roslyn in the C# Discord server.
Background and Motivation
A big issue with
in
parameters today is that they can introduce shadow copies when:in struct
parameter.in T
generic parameter, regardless of whether the runtime type/member is readonly.There currently is no way to spot them, you just have to know, and even then, it's easy to accidentally introduce copies without noticing, as there is zero compiler help here. Introducing copies can at best still defeat the whole point of using
in
, which is to avoid copies and improve performance, and at worst just flat out break the code, in case it relied on being invoked on the original value.Proposal
There should be enough info on
IOperation
to allow analyzer authors to spot all hidden copies done by Roslyn. Not familiar with the API surface there so I don't have an exact API proposal here, but I know Jared will be able to fill the blanks here 😄Risks
None that I can see.
The text was updated successfully, but these errors were encountered: