Skip to content
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

Support for Inline arrays in C# 12 preview? #78

Closed
sdcb opened this issue Jul 12, 2023 · 5 comments
Closed

Support for Inline arrays in C# 12 preview? #78

sdcb opened this issue Jul 12, 2023 · 5 comments

Comments

@sdcb
Copy link

sdcb commented Jul 12, 2023

https://devblogs.microsoft.com/dotnet/new-csharp-12-preview-features/#inline-arrays

@ds5678
Copy link

ds5678 commented Jul 24, 2023

Is anyone working on this? I may be willing to do so, but I'm hesitant because I don't have much experience with source generators.

@Sergio0694
Copy link
Owner

This is planned (along with all other new polyfills for C# 12), just waiting for the language to be stable first 🙂
The design of several of the new attribute types has changed over time, so I want them to stabilize before adding polyfills.

@optiks
Copy link

optiks commented Nov 14, 2023

Hey Sergio, I love your work!

Following on from the C#12 theme, with .NET 8 now released I can’t wait to start using it!

Are you able to share the plans for C#12 support? Is there anything the community can do to help?

Thanks :)

@eduarddejong
Copy link

eduarddejong commented Nov 24, 2023

Hmm, today I was curious how we can do things by ourselves. So I decided to play around with things myself in order to see how far I can get, and what happened was actually quite interesting.

After setting my csproj TFM to net481 I got several errors, but most obviously that the InlineArray attribute was missing.
So I just decided to copy the official InlineArrayAttribute.cs .NET source file into my project.
Which solved that part of the problems.

Another error shown about missing System.Runtime.InteropServices.MemoryMarshal.CreateSpan was shown by IntelliSense (but somehow not by the compiler output itself) at that point on my code where I assigned values to my internal array for all the indices.
I was eventually able to remove it by making my own public static partial class MemoryMarshal implementation with a CreateSpan method and modify that a bit so that it could compile on .NET Framework as well.

However, after these actions, the following more serious compiler error still remained:

error CS9171: Target runtime doesn't support inline array types.

To me, that suggests that the current situation is that inline arrays are actually impossible on .NET Framework at all, or at least that the Roslyn compiler itself does not allow you to do this at least.

So in that case PolySharp alone will not be able to solve it either I guess...

@Sergio0694
Copy link
Owner

Oh, I forgot this one. Actually completed by #81.

"inline arrays are actually impossible on .NET Framework at all"

That is correct, it requires runtime support. This is why it's part of the "runtime supported" attributes which are dummy and don't actually do anything (like eg. [UnmanagedCallersOnly]), and are opt-in. They're only meant to make multi-targeted code cleaner.

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

No branches or pull requests

5 participants