roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Update method invocation escape analysis to match spec changes

Open cston opened this issue 2 years ago • 1 comments

Update the C#11 escape analysis rules for method invocation to match the recent spec changes.

Method invocation:

For a given argument a that is passed to parameter p:

  1. If p is scoped ref then a does not contribute ref-safe-to-escape when considering arguments.
  2. If p is scoped then a does not contribute safe-to-escape when considering arguments.

A value resulting from a method invocation e1.M(e2, ...) is safe-to-escape from the smallest of the following scopes:

  1. The calling method
  2. The safe-to-escape contributed by all argument expressions
  3. When the return is a ref struct then ref-safe-to-escape contributed by all ref arguments

A value resulting from a method invocation ref e1.M(e2, ...) is ref-safe-to-escape the smallest of the following scopes:

  1. The safe-to-escape of the rvalue of e1.M(e2, ...)
  2. The ref-safe-to-escape contributed by all ref arguments

Method arguments must match:

For any method invocation e.M(a1, a2, ... aN)

  1. Calculate the safe-to-escape of the method return (for this rule assume it has a ref struct return type)
  2. All ref or out arguments of ref struct types must be assignable by a value with that safe-to-escape. This applies even when the ref argument matches a scoped ref parameter.

cston avatar Jul 20 '22 17:07 cston

See also https://github.com/dotnet/roslyn/issues/62327.

cston avatar Jul 20 '22 18:07 cston