Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref fields spec updates #6539

Merged
merged 6 commits into from
Oct 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions proposals/csharp-11.0/low-level-struct-improvements.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ Next the rules for ref reassignment need to be adjusted for the presence of `ref

The left operand of the `= ref` operator must be an expression that binds to a ref local variable, a ref parameter (other than `this`), an out parameter, **or a ref field**.

> For a ref reassignment in the form ...
> 1. `x.e1 = ref e2`: where `x` is *safe-to-escape* at least *return only* then `e2` must have *ref-safe-to-escape* at least as large as `x`
> 2. `e1 = ref e2`: where `e1` is a `ref` local or `ref` parameter then `e2` must have a *safe-to-escape* equal to *safe-to-escape* for `e1` and `e2` must have *ref-safe-to-escape* at least as large as *ref-safe-to-escape* of the *ref-safe-to-escape* of `e1`
> For a ref reassignment in the form `e1 = ref e2` both of the following must be true:
> 1. e2 must have ref-safe-to-escape at least as large as the ref-safe-to-escape of e1
> 2. e1 must have the same safe-to-escape as e2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: backticks on e1 and e2
nit: I'm okay to keep a side-note on x.e1 case, since I agree it is a bit tricky how it falls out.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah formatting didn't copy correctly. Will add the sample.


That means the desired `Span<T>` constructor works without any extra annotation:

Expand Down Expand Up @@ -322,6 +322,8 @@ Any expression or statement which explicitly returns a value from a method or la

Likewise any assignment to an `out` must have a *safe-to-escape* of at least *return only*. This is not a special case though, this just follows from the existing assignment rules.

Note: An expression whose type is not a `ref struct` type always has a *safe-to-return* of *calling method*.

<a name="rules-method-invocation"></a>

The span safety rules for method invocation will be updated in several ways. The first is by recognizing the impact that `scoped` has on arguments. For a given argument `a` that is passed to parameter `p`:
Expand Down Expand Up @@ -1096,7 +1098,7 @@ The features outlined in this document don't need to be implemented in a single

What gets implemented in which release is merely a scoping exercise.

**Decision** Only (1) and (2) will make C# 11.0. The expectation is (3) and (4) are enabled very early in C# 12.0 to enable dogfooding by runtime throughout the .NET 8 cycle
**Decision** Only (1) and (2) made C# 11.0. The rest will be considered in future versions of C#.

## Future Considerations

Expand Down