Skip to content

Commit

Permalink
respond to feedback
Browse files Browse the repository at this point in the history
Ref like fields do have storage, but that storage may refer to a variable that is a struct parameter or varialbe.
  • Loading branch information
BillWagner committed Feb 27, 2023
1 parent e33380f commit 0072dcf
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion standard/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,12 @@ Reads and writes of the following data types shall be atomic: `bool`, `char`, `b

A *reference variable* is a local variable declared with the `ref` modifier, or an instance of a `ref struct` type. A ref local does not create a new storage location. Instead, a ref local represents the same storage location as its initializing expression. Thus, the value of a reference variable is always the same as the underlying variable.

A `ref struct` may include `ref struct` or ref-like fields. A ref-like field does not create a new storage location. Instead, if refers to the same storage as its initializing expression. Ref struct types include `Span<T>`, `ReadOnlySpan<T>`, and other types that include an unmanaged pointer as a member.
A `ref struct` may include `ref struct` or ref-like fields. A ref-like field refers to the same storage as its initializing expression. Its storage size in the ref struct is the same storage size of a reference field. Unlike a reference field, a ref-like field may refer to a `struct` whose storage may be on the execution stack. Ref struct types include `Span<T>`, `ReadOnlySpan<T>`, and other types that include an unmanaged pointer as a member.

A *reference return* is the expression returned by reference from a method whose return type includes the `ref` or `ref readonly` modifiers (§14.6.1). The return refers to the same storage as its expression.

All reference variables must obey safety rules that ensure the lifetime of the reference variable is not greater than the lifetime of the storage it refers to.

### §ref-span-safety-escape-scopes Safe to escape scopes

At compile-time, each expression is associated with a scope that expression is permitted to escape to, its *safe-to-escape-scope*. Each variable is associated with the scope a reference to it is permitted to escape to, *ref-safe-to-escape-scope*. For a given variable expression, these may be different. When the *ref-safe-to-escape-scope* scope is *caller-scope*, the variable is *safe-to-return*. A variable that is *safe-to-return* may escape the enclosing method as a whole. In other words, the variable can *returned-by-ref*.
Expand Down

0 comments on commit 0072dcf

Please sign in to comment.