You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/design/features/byreflike-generics.md
+38-42Lines changed: 38 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,37 +28,61 @@ The expansion of ByRefLike types as Generic parameters does not relax restrictio
28
28
29
29
## API Proposal
30
30
31
-
Support for the following will be indicated by a new property. For .NET 7, the feature will be marked with `RequiresPreviewFeaturesAttribute` to indicate it is in [preview](https://github.com/dotnet/designs/blob/main/accepted/2021/preview-features/preview-features.md).
31
+
A new `GenericParameterAttributes` value will be defined which also represents metadata defined in the `CorGenericParamAttr` enumeration.
32
32
33
33
```diff
34
-
namespace System.Runtime.CompilerServices
34
+
namespace System.Reflection
35
35
{
36
-
public static partial class RuntimeFeature
36
+
[Flags]
37
+
public enum GenericParameterAttributes
37
38
{
38
-
+ /// <summary>
39
-
+ /// Represents a runtime feature where byref-like types can be used in Generic parameters.
40
-
+ /// </summary>
41
-
+ public const string GenericsAcceptByRefLike = nameof(GenericsAcceptByRefLike);
39
+
+ AcceptByRefLike = 0x0020
42
40
}
43
41
}
44
42
```
45
43
46
-
The compiler will need an indication for existing troublesome APIs where ByRefLike types will be permissable, but where the failure will be handled at runtime. An attribute will be created and added to these APIs.
44
+
```diff
45
+
typedef enum CorGenericParamAttr
46
+
{
47
+
+ gpAcceptByRefLike = 0x0020 // type argument can be ByRefLike
48
+
} CorGenericParamAttr;
49
+
```
50
+
51
+
The expansion of metadata will impact at least the following:
If existing types are expected to add ByRefLike support, it is possible they contain previously valid APIs that will become invalid when ByRefLike types are permitted. A potential mitigation for this would be create an attribute to indicate to compilers that specific APIs are validated at run-time not compile-time. What follows is a potential solution.
62
+
63
+
The compiler will be imbued with knowledge of an API that tells it where ByRefLike types will be permissable and where the failure will be handled by the runtime. The compiler will only respect the attribute that is defined in the same assembly containing `System.Object`.
47
64
48
65
```csharp
49
66
namespaceSystem.Runtime.CompilerServices
50
67
{
51
68
/// <summary>
52
-
/// Indicates to the compiler that constraint checks should be suppressed
53
-
/// and will instead be enforced at run-time.
69
+
/// Indicates to the compiler the ByRefLike constraint check should be suppressed.
An API that is a JIT-time intrinsic will be needed to determine if a parameter is ByRefLike. This API would represent a check to occur at JIT time to avoid taking paths that would be invalid for some values of `T`. The existing `Type.IsByRefLike` property will be made an intrinsic (e.g., `typeof(T).IsByRefLike`).
0 commit comments