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
Create inline-arrays.md #7064
Create inline-arrays.md #7064
Changes from 11 commits
47f5c9a
1e15e61
6ca5ef5
ecaa0c6
178356d
ffffc7b
6604a84
26e058c
38d3217
f92dadb
7d40dc1
79099cd
a3ffcad
8b8a86a
2924ee1
1426407
77e6a30
f793250
211cad3
b57d7e3
368c395
6df9506
1b85bcd
5d23036
9b8924a
c4d683d
b7acdb8
a9abf26
884c33a
39e641b
bda99a6
30cc4ad
e264575
938151a
0858400
fc9b629
b01c730
8606658
874228a
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.
This is another case that would benefit if we ended up implementing the changes around
in
andref readonly
parameters that were approved last year. Would allow us to make changes like the following that would make this code legal.dotnet/runtime#83191
Think the spec is fine here, it's more of an implementation detail that we should be able to work around. But wanted to give some visibility to real world places this pops up to @tannergooding, @stephentoub
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.
Yes, this is one of the APIs we'd immediately switch from taking
ref
toref readonly
when that's allowed. In the meantime, developers can achieve it by adding in use ofUnsafe.AsRef
, or if the length is 1 usingReadOnlySpan<T>
's ctor that takes anin
.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.
Agree they should be speakable. I was thinking about what the best namespace would be for these types when the compiler generates them. Ended up thinking that
System.Runtime.CompilerServices
is a good candidate. Mostly cause that is the likely place the libraries team would want to put the predefined types. That would meanMy other thought was
Microsoft.CodeAnalysis
.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.
From the BCL point of view, I do not think we want the compiler to ever auto-generate types in the
System.Runtime.CompilerServices
namespace. That would be a factory for type-name collisions.Can we make the physicial type of the field a hidden internal implementation detail and only expose these fields publicly via the Span and ReadOnlySpan accessors?
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.
This is my preference as well. Basically mirror what we do today for unsafe fixed buffers: a developer writes
fixed int buffer[10]
, the compiler generates an unspeakable type for that, and the effective type visible to consuming code isint*
. For safe buffers, it could be the same approach: the developer writesint buffer[10]
, the compiler generates an unspeakable type for that, and the effective type visible to consuming code is eitherSpan<int>
orReadOnlySpan<int>
depending on whether the field is readonly.Handcoding these is trivial. If we wanted to expose any publicly for size/sharing reasons, it would be easy to do so without the compiler feature. As noted earlier, I'd also be concerned about using the compiler feature to implement these, as it would either be limiting for what the compiler could emit on them in the future (any additions the compiler made here would implicitly impact core library public surface area), or if we didn't want to constrain the compiler in that fashion (I don't want to), we wouldn't use it for this, anyway.