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

ref fields spec updates #6539

merged 6 commits into from
Oct 12, 2022

Conversation

jaredpar
Copy link
Member

@jaredpar jaredpar commented Oct 12, 2022

Couple of items:

  • Clarifying the rules around ref reassignment.
  • Affirming the safe-to-escape of non ref struct. This needed clarifying after the introduction of return only
  • Affirming the cut line for features in C# 11

closes dotnet/roslyn#64671
related dotnet/roslyn#62618

Couple of items:

- Clarifying the rules around ref reassignment.
- Affirming the *safe-to-escape* of non `ref struct`. This needed
  clarifying after the introduction of *return only*
- Affirming the cut line for features in C# 11
@jaredpar jaredpar requested a review from a team as a code owner October 12, 2022 20:36
> 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.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 1)

Span<int> local = stackalloc int[42];
ref Span<int> refLocal = ref local;

// The rule above prevent this because the safe-to-escape of the two values is
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// The rule above prevent this because the safe-to-escape of the two values is
// The rule above prevents this because the safe-to-escape of the two values is

@jaredpar jaredpar merged commit b117e71 into dotnet:main Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ref fields spec on re-assignments can be simplified
3 participants