-
Notifications
You must be signed in to change notification settings - Fork 81
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
C# 7.x: accessing fixed fields without pinning #239
C# 7.x: accessing fixed fields without pinning #239
Conversation
converted to draft: C# 7 feature. |
d48e6b7
to
3c30908
Compare
3c30908
to
640d97e
Compare
This isn't an area I'm particularly expert in, but it does look like this is too permissive. In particular, I think it would imply that the second example in the feature doc should be valid - and it's not. The feature only adds the ability for the first example to become valid without a I honestly don't know how we'd allow the indexing part at the moment. One for discussion, certainly. |
Current compiler behaviour (SharpLab): unsafe struct C {
fixed int buf[9];
void M() {
_ = this.buf[6]; // OK
_ = (this.buf)[6]; // error, needs fixed statement
}
} So this seems to require a new rule that specifically allows the syntax for indexing a fixed-size buffer. |
Fixed-size buffers cannot be nested unsafe struct C {
public fixed int buf[9];
}
unsafe struct D {
fixed C buf2[5]; // error, C not a fixed-size primitive type
void M() {
_ = (this.buf2[1].buf)[3];
}
} so the new rule need not state that the movability of |
For discussion in the meeting. I think this works. (I can't make a suggestion on the PR, because the only change is a deletion): Instead of deleting the single line, modify it as follows: |
@BillWagner problems with that wording:
|
Update based on above comment: For discussion in the meeting. I think this works. (I can't make a suggestion on the PR, because the only change is a deletion): Instead of deleting the single line, modify it as follows:
Note that the last bullet item is in the spec now. I added it to the comment because I thought its presence addresses @KalleOlaviNiemitalo 's second bullet point above. (Namely, if |
ping @jskeet for Meeting agenda |
@BillWagner: Not quite sure what you mean - it's got the "meeting: discuss" label, so I'd expect us to just find it that way. Anything else you wanted me to do? |
Nope. Just hoping we can resolve this one today. |
Results from committee meeting: We think the latest change is close, but may need refinement. @MadsTorgersen and @jskeet tagged for review @KalleOlaviNiemitalo Can you add a comment on the confused emjoi above? |
@BillWagner, §22.6.4 Pointer element access defines the syntax like so: pointer_element_access
: primary_no_array_creation_expression '[' expression ']'
; i.e. it would have to end with ']', which |
Still needs review and refinement. This commit modifies the bullet that was removed in the original commit.
470189f
to
21d9810
Compare
Reading through the other areas in this clause, classifying the newly allowed behavior as an *element_access* worked more smoothly. It doesn't let other syntax "sneak" into the allowed constructs, and it's intuitive to understand: It's evaluated exactly as the pointer-element-access.
Ping @jskeet @MadsTorgersen I've updated this to restore the previous language for member access, and add new text for element_access ( |
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 too permissive as is, it should only capture the case of E.I[J]
.
Current status as of March 20: I think I've addressed all remaining comments from Nigel and Jon. I didn't resolve the conversation from Jon above. It would be good to have additional opinions here. |
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.
Just to be clear, this is two new features:
x.Buffer[index]
&x.Buffer
... neither of which would have been valid before? Assuming that's the case, this is fine.
Only the first is valid without
|
Okay - so leaving aside pinning, was the second valid before now? I'm only mentioning it because it looks like it's new text. |
Yes, that's correct. |
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.
Looks good!
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.
LGTM
While I think my solution allows the newer behavior, it might be too permissive.
See 'The main “challenge discussion in https://github.com/dotnet/csharplang/blob/main/proposals/csharp-7.3/indexing-movable-fixed-fields.md.