From b20b642c22dcff3026d3c3e0c4fd1d22c4791bb4 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Mon, 26 Sep 2022 15:16:10 -0700 Subject: [PATCH 1/2] Relax all scenarios with pointer type to managed type --- proposals/low-level-struct-improvements.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/proposals/low-level-struct-improvements.md b/proposals/low-level-struct-improvements.md index bffbd7faae..07cf24d941 100644 --- a/proposals/low-level-struct-improvements.md +++ b/proposals/low-level-struct-improvements.md @@ -727,9 +727,14 @@ For a `new` expression with initializers, the initializer expressions count as a ## Changes in unsafe context -Pointer types are extended to allow managed types as referent type, but only in casts. +Pointer types (section 22.3) are extended to allow managed types as referent type. Such pointer types are written as a managed type followed by a `*` token. They produce a warning. -The address-of operator is relaxed to accept a variable with a managed type as its operand. + +The address-of operator (section 22.6.5) is relaxed to accept a variable with a managed type as its operand. + +The `fixed` statement (section 22.7) is relaxed to accept _fixed_pointer_initializer_ that is the address of a variable of managed type `T` or that is an expression of an _array_type_ with elements of a managed type `T`. + +The stack allocation initializer (section 22.9) is similarly relaxed. ## Considerations There are considerations other parts of the development stack should consider when evaluating this feature. @@ -1648,4 +1653,4 @@ The set of returnable input to the method are: Given that there is at least one input with a smaller *escape scope* (`ref y` argument) than one of the outputs (`x` argument) the method call is illegal. -This is the logic that the method arguments must match rule is trying to encompass. It goes further as it considers both `scoped` as a way to remove inputs from consideration and `readonly` as a way to remove `ref` as an output (can't assign into a `readonly ref` so it can't be a source of output). These special cases do add complexity to the rules but it's done so for the benefit of the developer. The compiler seeks to remove all inputs and outputs it knows can't contribute to the result to give developers maximum flexibility when calling a member. Much like overload resolution it's worth the effort to make our rules more complex when it creates more flexibility for consumers. \ No newline at end of file +This is the logic that the method arguments must match rule is trying to encompass. It goes further as it considers both `scoped` as a way to remove inputs from consideration and `readonly` as a way to remove `ref` as an output (can't assign into a `readonly ref` so it can't be a source of output). These special cases do add complexity to the rules but it's done so for the benefit of the developer. The compiler seeks to remove all inputs and outputs it knows can't contribute to the result to give developers maximum flexibility when calling a member. Much like overload resolution it's worth the effort to make our rules more complex when it creates more flexibility for consumers. From 7d5876c3d3b52038760001953e6a240023122a66 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Wed, 28 Sep 2022 13:15:33 -0700 Subject: [PATCH 2/2] Update low-level-struct-improvements.md --- proposals/low-level-struct-improvements.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/proposals/low-level-struct-improvements.md b/proposals/low-level-struct-improvements.md index 07cf24d941..e59b127734 100644 --- a/proposals/low-level-struct-improvements.md +++ b/proposals/low-level-struct-improvements.md @@ -727,14 +727,14 @@ For a `new` expression with initializers, the initializer expressions count as a ## Changes in unsafe context -Pointer types (section 22.3) are extended to allow managed types as referent type. +Pointer types ([section 22.3](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/unsafe-code.md#223-pointer-types)) are extended to allow managed types as referent type. Such pointer types are written as a managed type followed by a `*` token. They produce a warning. -The address-of operator (section 22.6.5) is relaxed to accept a variable with a managed type as its operand. +The address-of operator ([section 22.6.5](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/unsafe-code.md#2265-the-address-of-operator)) is relaxed to accept a variable with a managed type as its operand. -The `fixed` statement (section 22.7) is relaxed to accept _fixed_pointer_initializer_ that is the address of a variable of managed type `T` or that is an expression of an _array_type_ with elements of a managed type `T`. +The `fixed` statement ([section 22.7](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/unsafe-code.md#227-the-fixed-statement)) is relaxed to accept _fixed_pointer_initializer_ that is the address of a variable of managed type `T` or that is an expression of an _array_type_ with elements of a managed type `T`. -The stack allocation initializer (section 22.9) is similarly relaxed. +The stack allocation initializer ([section 22.9](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/unsafe-code.md#229-stack-allocation)) is similarly relaxed. ## Considerations There are considerations other parts of the development stack should consider when evaluating this feature.