Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Expanding ref support #7555
Expanding ref support #7555
Changes from 2 commits
0cd8cd0
ca9c976
5a323d8
e048a9b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this true even for a
ref readonly
field?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that
readonly
could allow us to relax the restriction a bit here. At the same time it's something we'd have to really map out to make sure we weren't missing anything.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's hard to get use out of this document now because you have to have the other document at hand to cross-reference everything that has changed in later versions of C#.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point I do need to put together a unified doc that we can reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a critical concept. The implementation currently, by representing lifetimes as
uint
, requires every lifetime to be comparable to every other lifetime. It's equivalent to it being impossible to declarevoid M<T, U>() {}
without also sayingwhere T : U
orwhere U : T
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need to do something similar for value-
scoped
parameters, once we permit RTRS fields? Since it feels like it will be possible to declare a similar signature, just usingvoid Swap(RefSpanWrapper<int> p1, RefSpanWrapper<int> p2)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree our current implementation does not lend itself to this type of validation. This was one of the motivations I had in wanting us to refactor the implementation significantly in C# 12.0 to better match the existing spec. That would've made the transition to this much easier. As is though we effectively need to do that work before we can do this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that all lifetimes
$current_field_N
and$current_ref_field_N
must also be convertible to lifetime$this
. In the absence of this constraint, it would be possible for thethis
variable to hold references to fields with narrower lifetimes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, depending on how you look at it, it simply wouldn't be possible to declare any 'ref scoped' fields in ref structs, because the field's lifetime would not be convertible to the lifetime of the containing 'this' variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree. Logically yes I agree that the lifetimes must be convertible to
$this
. The moment you allow that though in all contexts, suddenly it's notscoped
anymore, it's returnableThe way this works is that at construction time the rules ensure that the lifetimes of both the
ref
and the value are convertible to$this
. That just falls out from our existing method args rules. Given that the fields lifetimes are invariant there is no need to keep that relationship alive for correctness after that. The only thing we have to worry about is how they are interpreted in the context of a method.Note: if these were
ref unscoped
fields then you are 100% correct we'd put that relationship in place at the decl of the type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we assume updates to the following don't indicate anything other than clarity on their semantics rather than changing anything about their "officially supported" state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. This is just about getting clarity on the semantics. Particularly I know the runtime team has wanted to leverage
TypedReference
more and this would provide clarity on what can and cannot be done safely.