Polyfill [InlineArray]
with a new Source Generator
#4473
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.
BizHawk/src/BizHawk.Common/Util.cs
Lines 14 to 26 in 4d3e1cc
generates:
BizHawk.Common.cs
The final challenge to solve is computing the width of a struct at compile-time. (To allow elements to be of any unmanaged type, which is required for this to be more useful than anIt was working fine,unsafe fixed
field.)Guid
is just weird. Now that's working, I don't see why I couldn't also allow for extra fields before the array part, which not even[InlineArray]
can do.Also the Source Generator wouldn't detect any applications of
[InlineArray]
for some reason, so I had to make a custom attribute.Based on scattered docs I've assumed that
[StructLayout(Size = ...)]
will be sufficient for the unmanaged side, and I'm fairly confident that theUnsafe
/Span
hacks will work for the managed side. If it turns out[StructLayout(Size = ...)]
doesn't work and it's some extra metadata in the IL, I could just generate more fields_element1
through_elementN
to get the right size.see also #3393