Uh oh!
There was an error while loading. Please reload this page.
Design to support ByRefLike types in Generics - #67129
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
danmoseley
commented
Mar 25, 2022
Cc @steveharter |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
AaronRobinsonMSFT
commented
Mar 28, 2022
@lambdageek for mono and @tgani-msft for C++/CLI FYI. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Record APIs where compiler constraint analysis should be suppressed. Defined analysis suppression attribute.
Co-authored-by: Jared Parsons <jaredpparsons@gmail.com>
a5c4b95 to
75fd91bCompareAaronRobinsonMSFT
commented
Apr 8, 2022
Any other feedback on this design? |
tgani-msft
left a comment
There was a problem hiding this comment.
Are these types importable via the COM metadata APIs? The C++ compiler uses only these.
@tgani-msft As in, can they be acquired through the |
tgani-msft
commented
Apr 20, 2022
I'll send you a link to the source code directly, via email. |
RikkiGibson
commented
Apr 21, 2022
I think this came up elsewhere (maybe from @teo-tsirpanis), but is there any need to take special effort to make types "conditionally by-ref-like" depending on their type arguments? For example, imagine if we wanted to let people use nullable ref structs. It would be good to allow things like boxing, heap escape, etc. depending on the type arguments. refstructRS{publicrefintX;}namespaceSystem{// somehow we denote here that this is "only a ref struct if T is a ref struct".publicstructNullable<T>whereT:struct allow T :refstruct// or whatever syntax we use{Tvalue;// ...}}voidM(RS?maybeRs,refintX){if(maybeRs!=null){maybeRs.Value.X=refX;}objectobj=maybeRs;// error}voidM2(int?maybeInt){objectobj=maybeInt;// ok}It's possible the answer here is no, don't bother doing this, or punt it to something further down the line, but seems worth considering as part of this whole area. |
AaronRobinsonMSFT
commented
Apr 22, 2022
That seems like a much broader feature given |
AaronRobinsonMSFT
commented
Apr 22, 2022
The only prior art I can think of for this sort of thing is in Interop when a |
FWIW, there are a few existing places in the compiler where the types of fields after substitution affect usage of a struct. For example: SharpLab. (it sounds like this might be very similar/related to blittability.) structS<T>{publicTfield;}classProgram{unsafevoidM1(S<int>*ptr){}// okunsafevoidM2(S<object>*ptr){}// error} |
AaronRobinsonMSFT
commented
Apr 23, 2022
Agreed, but not metadata. For example, the following might be unintuitive from a reflection standpoint: structS<T> allow T:refstructrefstructwhen T :refstruct{}Console.WriteLine(typeof(S<>).IsByRefLike);// FalseConsole.WriteLine(typeof(S<int>).IsByRefLike);// FalseConsole.WriteLine(typeof(S<Span<int>>).IsByRefLike);// True |
hez2010
commented
May 10, 2022
How about enabling overload by generic constraints so we can have both |
stephentoub
commented
Nov 3, 2022
@AaronRobinsonMSFT, can this be merged? Presumably we're fine updating the design doc as the design evolves and we don't need to block the PR on having 100% of the answers set in stone? |
AaronRobinsonMSFT
commented
Nov 3, 2022
I think so. It is accurate regarding the current state of support in the runtime.
Agreed. |
Adding in a proposal to support ByRefLike type in Generics. This work is supported by #63768 and contributes toward #65112.
/cc @jkotas@davidwrighton@jaredpar@cston@RikkiGibson@AlekseyTs