From 7ff6cb3bb770faff8a25f007816ebaa68ef98f91 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Tue, 25 Aug 2020 15:48:55 -0700 Subject: [PATCH 1/4] Clarify the rules on UnmanagedCallersOnly --- proposals/csharp-9.0/function-pointers.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/proposals/csharp-9.0/function-pointers.md b/proposals/csharp-9.0/function-pointers.md index da524e7977..d8cf744a69 100644 --- a/proposals/csharp-9.0/function-pointers.md +++ b/proposals/csharp-9.0/function-pointers.md @@ -358,9 +358,12 @@ the attribute: * It is an error to directly call a method annotated with this attribute from C#. Users must obtain a function pointer to the method and then invoke that pointer. -* It is an error to apply the attribute to anything other than a static method. The C# compiler will mark any non-static -methods imported from metadata with this attribute as unsupported by the language. -* It is an error to have managed types as parameters or the return type of a method marked with the attribute. +* It is an error to apply the attribute to anything other than an ordinary static method or ordinary static local function. +The C# compiler will mark any non-static methods imported from metadata with this attribute as unsupported by the language. +* It is an error to have managed types as parameters or the return type of a method marked with the attribute. This includes +types with type parameters, even if those type parameters are constrained to `unmanaged` or substituted with `unmanaged` types. +* It is an error for a method attributed with `UnmanagedCallersOnlyAttribute` to have type parameters, even if those type +parameters are constrained to `unmanaged`. * It is an error to convert a method marked with the attribute to a delegate type. * It is an error to specify any types for `UnmanagedCallersOnly.CallConvs` that do not meet the requirements for calling convention `modopt`s in metadata. From 55df4c7f826cdbe0bc4612e072ee0995dab8aa8f Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Tue, 25 Aug 2020 16:44:57 -0700 Subject: [PATCH 2/4] Update with feedback --- proposals/csharp-9.0/function-pointers.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/proposals/csharp-9.0/function-pointers.md b/proposals/csharp-9.0/function-pointers.md index d8cf744a69..667f1fdda1 100644 --- a/proposals/csharp-9.0/function-pointers.md +++ b/proposals/csharp-9.0/function-pointers.md @@ -360,10 +360,12 @@ the attribute: the method and then invoke that pointer. * It is an error to apply the attribute to anything other than an ordinary static method or ordinary static local function. The C# compiler will mark any non-static methods imported from metadata with this attribute as unsupported by the language. -* It is an error to have managed types as parameters or the return type of a method marked with the attribute. This includes -types with type parameters, even if those type parameters are constrained to `unmanaged` or substituted with `unmanaged` types. -* It is an error for a method attributed with `UnmanagedCallersOnlyAttribute` to have type parameters, even if those type -parameters are constrained to `unmanaged`. +* It is an error to have managed types as parameters or the return type of a method marked with the attribute. If the parameter +or return types are unmanaged except for generic type parameters, they are only allowed if those parameters are substituted +with unmanaged types themselves. +* It is an error for a method marked with the attribute to have type parameters, even if those type parameters are +constrained to `unmanaged`. +* It is an error for a method in a generic type to be marked with the attribute. * It is an error to convert a method marked with the attribute to a delegate type. * It is an error to specify any types for `UnmanagedCallersOnly.CallConvs` that do not meet the requirements for calling convention `modopt`s in metadata. From 3e179c04d4f56a0984eeab0e70383c8262d090c7 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Tue, 25 Aug 2020 17:10:34 -0700 Subject: [PATCH 3/4] Address PR feedback: 1. Simplify the parameter/return requirements. 2. Clarify the intent around invalid imported metadata. --- proposals/csharp-9.0/function-pointers.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/proposals/csharp-9.0/function-pointers.md b/proposals/csharp-9.0/function-pointers.md index 667f1fdda1..c961d52b22 100644 --- a/proposals/csharp-9.0/function-pointers.md +++ b/proposals/csharp-9.0/function-pointers.md @@ -359,10 +359,9 @@ the attribute: * It is an error to directly call a method annotated with this attribute from C#. Users must obtain a function pointer to the method and then invoke that pointer. * It is an error to apply the attribute to anything other than an ordinary static method or ordinary static local function. -The C# compiler will mark any non-static methods imported from metadata with this attribute as unsupported by the language. -* It is an error to have managed types as parameters or the return type of a method marked with the attribute. If the parameter -or return types are unmanaged except for generic type parameters, they are only allowed if those parameters are substituted -with unmanaged types themselves. +The C# compiler will mark any non-static or static non-ordinary methods imported from metadata with this attribute as +unsupported by the language. +* It is an error for a method marked with the attribute to have a parameter or return type that is not an `unmanaged_type`. * It is an error for a method marked with the attribute to have type parameters, even if those type parameters are constrained to `unmanaged`. * It is an error for a method in a generic type to be marked with the attribute. From 3213aa099399aeb1d3ea432fd43be02efe33bfac Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Wed, 26 Aug 2020 10:18:18 -0700 Subject: [PATCH 4/4] Update incorrect examples. --- proposals/csharp-9.0/function-pointers.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/proposals/csharp-9.0/function-pointers.md b/proposals/csharp-9.0/function-pointers.md index c961d52b22..087fd60034 100644 --- a/proposals/csharp-9.0/function-pointers.md +++ b/proposals/csharp-9.0/function-pointers.md @@ -39,8 +39,8 @@ The ECMA-335 definition of method pointers includes the calling convention as pa The default calling convention will be `managed`. Unmanaged calling conventions can by specified by putting an `unmanaged` keyword afer the `delegate*` syntax, which will use the runtime platform default. Specific unmanaged conventions can then be specified in brackets to the `unmanaged` keyword by specifying any type starting with `CallConv` in the -`System.Runtime.CompilerServices` namespace. These types must come from the program's core library, and the set of valid -combinations is platform-dependent. +`System.Runtime.CompilerServices` namespace, leaving off the `CallConv` prefix. These types must come from the program's +core library, and the set of valid combinations is platform-dependent. ``` csharp //This method has a managed calling convention. This is the same as leaving the managed keyword off. @@ -51,10 +51,13 @@ delegate* managed; delegate* unmanaged; // This method will be invoked using the cdecl calling convention -delegate* unmanaged[CallConvCdecl] ; +// Cdecl maps to System.Runtime.CompilerServices.CallConvCdecl +delegate* unmanaged[Cdecl] ; // This method will be invoked using the stdcall calling convention, and suppresses GC transition -delegate* unmanaged[CallConvStdCall, CallConvSuppressGCTransition] ; +// Stdcall maps to System.Runtime.CompilerServices.CallConvStdcall +// SuppressGCTransition maps to System.Runtime.CompilerServices.CallConvSuppressGCTransition +delegate* unmanaged[Stdcall, SuppressGCTransition] ; ``` Conversions between `delegate*` types is done based on their signature including the calling convention.