Proposal: Fixed Sized Buffers should support formatted value types that contain only the already supported types. #78
Replies: 17 comments 2 replies
-
This is a very good suggestion. |
Beta Was this translation helpful? Give feedback.
-
I had a very rough implementation of this proposal here: dotnet/roslyn#13064 (I should probably clean it up). |
Beta Was this translation helpful? Give feedback.
-
FYI. @jaredpar, we had talked about this briefly over lunch one time (I think it fits into the bigger picture of supporting blittable at a language level). |
Beta Was this translation helpful? Give feedback.
-
@MadsTorgersen or @gafter, for finding a champion for a proposal... Are we able to champion them ourselves (and what would that entail) or do we have to find someone on the actual compiler team to champion it? Does championing only involve taking it through LDM or does it also involve finding someone to implement it (even if that means implementing it yourself)? |
Beta Was this translation helpful? Give feedback.
-
@tannergooding A "champion" is a member of the LDM who believes we should do the proposal and is willing to drive the process through all of the steps to get it designed, specified, agreed, implemented, and scheduled for inclusion in a particular version of the compiler. For this particular proposal I suggest @jaredpar is likely to be interested. |
Beta Was this translation helpful? Give feedback.
-
I was making this proposal primitive struct as primitive dotnet/roslyn#16095 And I think it's more generalized |
Beta Was this translation helpful? Give feedback.
-
@Thaina, dotnet/roslyn#16095 would not cover this scenario if implemented, and likewise, this proposal would not cover your scenario if implemented. This proposal is suggesting that fixed-sized arrays be extended to support the full-set of blittable types and types composed of blittable types. While your proposal is suggesting that literals be extended to additionally support types composed of other literal types. |
Beta Was this translation helpful? Give feedback.
-
@tannergooding I think in general fixed size buffer just work on any primitive type? |
Beta Was this translation helpful? Give feedback.
-
@Thaina, not exactly... Fixed-sized buffers, today, work on the following blittable types: Constants today work on the following blittable types: Enums today work on a subset of the constant types: Additionally, anything that is not a Instead, it is a |
Beta Was this translation helpful? Give feedback.
-
@tannergooding Thanks for your clarification But then what I proposed is, in general, whatever the category it is, if any struct contains only things of that category, it should automatically be that category if possible So in your case, if any struct contains only blittable type it should also be blittable type. Then if fixed size buffer look for blittable type it should just accept that struct. I just take this logic to apply with anything include |
Beta Was this translation helpful? Give feedback.
-
I'm not sure your proposal makes that very clear. My understanding from reading it, and the examples provided, was that it was directly related to extending constant support. In any case, I don't think overly generic proposal are good or likely to be picked up. I would think the language team needs something fairly concrete in order to properly weigh its value. That is, proposing something like: "any type composed of types that are useable in a scenario should also be useable in that scenario" is generic and covers a ton of stuff, but it isn't likely something that can be taken to a design meeting and properly discussed (and even if it were, a ton of stuff would likely get missed). I think this proposal covers a very specific area, with very specific examples, a fairly explicit use-case, and with clear benefits/drawbacks. I think your proposal (as I understood it) does the same. |
Beta Was this translation helpful? Give feedback.
-
@tannergooding I was in process of trying to port that proposal into this repo. And your case is another one I look for to added for making that proposal be more generalized But you have a good point about being specific. I might rethink about it |
Beta Was this translation helpful? Give feedback.
-
With the existence of @jaredpar, If I update the proposal, is this something you would be willing to champion? |
Beta Was this translation helpful? Give feedback.
-
@tannergooding yes. Not sure what release but agree it should, can be done. |
Beta Was this translation helpful? Give feedback.
-
Proposal is here: #685 |
Beta Was this translation helpful? Give feedback.
-
Related but different take on the issue #749 jointly with #653 with some modifications. Implemented together with 'fixed-size-buffers' takes C# expressiveness to new level. |
Beta Was this translation helpful? Give feedback.
-
I thought |
Beta Was this translation helpful? Give feedback.
-
Ported from dotnet/roslyn#11018
At present, fixed size buffers only support
bool
,byte
,char
,short
,int
,long
,sbyte
,ushort
,uint
,ulong
,float
, anddouble
.This should be expanded to also support formatted value types (structs) that contain only the above supported types.
This would allow interop code, such as the following, to be written:
Other Thoughts:
The existing
backing structure
that is emitted by the compiler to support fixed sized buffers would likely need to be modified to support this.With the current 'backing structure' a modification to the private fields in a struct would cause a break in the generated code. For example:
Assembly A:
Assembly B:
The above code will generate something akin to the following:
Assembly A:
Assembly B:
Then, modifying Assembly A in the following manner will cause a break (the fixed buffer has a size of 40, when it should have a size of 80, due to the additional field added).
This could be worked around, by modifying the generated structure in the following manner:
Under the newly generated code, the modification to Assembly A would allow Assembly B to still work. This is because the size is computed dynamically, based on the number of elements.
Another interesting scenario is that, with the new system, the emitted structure could be modified even further, so-as to provide a type of 'safe' fixed buffer.
Doing this allows validating the index is within the bounds of the fixed array (which is known).
Having this support for fixed buffer structs (especially in a safe manner) would greatly improve the ability to create/work with
SOA
(structure of arrays) andAOSOA
(array of structure of arrays).It is probably also worth noting, that if the fixed buffers where modified to emit a backing structure in the last manner, they could be extended to support all blittable types (including those that do not have a fixed size, such as
IntPtr
andUIntPtr
).Beta Was this translation helpful? Give feedback.
All reactions