-
Notifications
You must be signed in to change notification settings - Fork 21
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
ReadOnlySpan
initialization from static data
#1350
Comments
If not erased by the suggested optimization step, what shall it do? |
Oh, I just meant the let data = new ReadOnlySpan<byte> [| 1uy; 2uy |] let data = new ReadOnlySpan<int> [| 1; 2 |] But you can omit |
Understood. |
Yes. Basically, if we know the contents of the collection literal are constant, and we know at compile time that the collection literal is immediately wrapped in, and thus only ever accessible through, a |
Compare dotnet/csharplang#5295 and dotnet/roslyn#24621, ultimately subsumed by dotnet/csharplang#5354.
I propose that we add compiler support for translating
=
and/or
and/or, potentially (this would imply some kind of invocation of
op_Implicit
or else type-direction à la #1086)to non-allocating code that bakes the constant data into the assembly as a binary blob and creates a
ReadOnlySpan
at runtime that points to that data.C# has done this for a while for
and now does it for collection expressions as well (SharpLab):
The F# compiler is essentially already halfway there for statically-initialized arrays — it emits static blobs holding the data, but a new array is created and initialized with the data from the blob at runtime (SharpLab).
The proposal here is to update the compiler to emit code for accessing the static data directly via a
ReadOnlySpan
, with no runtime array allocation or initialization, when the static array is directly bound or consumed as aReadOnlySpan
.Pros and Cons
The advantages of making this adjustment to F# are
The disadvantages of making this adjustment to F# are
[|…|]
doesn't preclude later making it also work with type-directed[…]
. All the rules about how the resulting span can be used are already in place and would still apply.Extra information
Estimated cost (XS, S, M, L, XL, XXL):
Related suggestions:
Affidavit (please submit!)
Please tick these items by placing a cross in the box:
Please tick all that apply:
For Readers
If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.
The text was updated successfully, but these errors were encountered: