Skip to content

Replace unscoped with UnscopedRefAttribute#6329

Merged
cston merged 4 commits intodotnet:mainfrom
cston:UnscopedRefAttribute
Jul 29, 2022
Merged

Replace unscoped with UnscopedRefAttribute#6329
cston merged 4 commits intodotnet:mainfrom
cston:UnscopedRefAttribute

Conversation

@cston
Copy link
Contributor

@cston cston commented Jul 28, 2022

No description provided.

@cston cston requested a review from a team as a code owner July 28, 2022 16:37
Impact of this change is discussed more deeply [below](#examples-method-arguments-must-match). Overall this will allow developers to make call sites more flexible by annotating non-escaping ref-like values with `scoped`.

The `scoped` modifier on parameters also impacts our object overriding, interface implementation and `delegate` conversion rules. The signature for an override, interface implementation or `delegate` conversion can:
The `scoped` modifier and `[UnscopedRef]` attribute (see [below](#rules-unscoped)) on parameters also impacts our object overriding, interface implementation and `delegate` conversion rules. The signature for an override, interface implementation or `delegate` conversion can:
Copy link
Member

@jcouv jcouv Jul 28, 2022

Choose a reason for hiding this comment

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

What are the rules for [UnscopedRef] in OHI? Is any variance allowed? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Added.

<a name="rules-unscoped"></a>

To fix this the language will provide the opposite of the `scoped` lifetime annotation in the syntax `unscoped`. The keyword `unscoped` will be used to expand the lifetime of a value. It can be applied to any `ref` which is implicitly `unscoped` and has the impact of changing its *ref-safe-to-escape* to *calling method*.
To fix this the language will provide the opposite of the `scoped` lifetime annotation by supporting an `UnscopedRefAttribute`. The attribute can be used to expand the lifetime of a value. It can be applied to any `ref` which is implicitly `scoped` and has the impact of changing its *ref-safe-to-escape* to *calling method*.
Copy link
Member

@jcouv jcouv Jul 28, 2022

Choose a reason for hiding this comment

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

any ref which is implicitly scoped

Consider enumerating those implicitly scoped ref cases if it's easy. #Closed

Copy link
Member

Choose a reason for hiding this comment

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

Also, is it an error to place [UnscopedRef] on some location that doesn't qualify per above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider enumerating those implicitly scoped ref cases if it's easy.

Added a link to the cases described earlier.

Also, is it an error to place [UnscopedRef] on some location that doesn't qualify per above?

Added as an error.

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.

Done with review pass (iteration 2). Looks good except for a question on OHI. Thanks much!

@jcouv jcouv self-assigned this Jul 28, 2022
To fix this the language will provide the opposite of the `scoped` lifetime annotation in the syntax `unscoped`. The keyword `unscoped` will be used to expand the lifetime of a value. It can be applied to any `ref` which is implicitly `unscoped` and has the impact of changing its *ref-safe-to-escape* to *calling method*.
To fix this the language will provide the opposite of the `scoped` lifetime annotation by supporting an `UnscopedRefAttribute`.
The attribute can be used to expand the lifetime of a value. It can be applied to any `ref` which is [implicitly `scoped`](#implicitly-scoped) and has the impact of changing its *ref-safe-to-escape* to *calling method*.
An error is reported if `[UnscopedRef]` is applied to a parameter passed by value or to a `ref` that is not considered scoped.
Copy link
Member

@jcouv jcouv Jul 28, 2022

Choose a reason for hiding this comment

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

not considered scoped.

"not considered implicitly scoped"? That will cover the [UnscopedRef] scoped scenario as well (line 500). Can this line (448) be moved to line 500 for various errors reported on misused [UnscopedRef]? #Closed

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 4)

@cston cston merged commit e367f90 into dotnet:main Jul 29, 2022
@cston cston deleted the UnscopedRefAttribute branch July 29, 2022 00:03
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.

2 participants