dotnet / linker

388 stars 127 forks source link

Create `ParameterProxy` to wrap logic surrounding parameters and use one `ParameterIndex` enum to index #3059

Closed jtschuster closed 1 year ago

jtschuster commented 1 year ago

Creates ParameterProxy to represent parameters as a pair of method + parameter index. IParameterSymbol and ParameterDefinition don't usually include the implicit 'this' parameter, so this lets us treat the implicit 'this' parameter as the same as any other parameter. This also should help put all the HasImplicitThis() ? 1 : 0 in a limited number of places (ParameterProxy and the extensions methods that produce them).

ParameterIndex represents 'this' as the 0 index. See the code docs for more info. I found it was best to represent the 'this' as 0 and provide a property on the ParameterProxy for indexing int the Parameters collection (int MetadataIndex).

"Metadata Parameter" is what I used to name the index in the .parameters metadata section, which corresponds to the SourceParamterIndex from before.

In the process, I found an issue in the analyzer where some properties were indexers but were not being passed the index value in HandleCallAction. Since we previously only iterated over the arguments, no issues arose, but after changing to iterate over the parameters in the called method signature, the issue showed up. LocalDataflowVisitor has been updated to visit the indexer argument and pass the value to HandleCallAction.