Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Proposal: Unsafe.IsNullRef(ref readonly) #73608

Closed
hez2010 opened this issue Aug 9, 2022 · 5 comments
Closed

API Proposal: Unsafe.IsNullRef(ref readonly) #73608

hez2010 opened this issue Aug 9, 2022 · 5 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime.CompilerServices
Milestone

Comments

@hez2010
Copy link
Contributor

hez2010 commented Aug 9, 2022

Background and motivation

Currently we cannot test whether a ref readonly is null ref or not because Unsafe.IsNullRef() takes a ref parameter instead of ref readonly parameter.
Given that Unsafe.IsNullRef doesn’t need mutability, the signature should be changed from IsNullRef(ref) to IsNullRef(ref readonly).

API Proposal

namespace System.Runtime.CompilerServices;

public static class Unsafe
{
-    public bool IsNullRef(ref value);
+    public bool IsNullRef(ref readonly value); // or in value
}

API Usage

ref readonly int Foo() {}
ref readonly int x = ref Foo();
Unsafe.IsNullRef(in x);

Alternative Designs

No response

Risks

No response

@hez2010 hez2010 added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Aug 9, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Aug 9, 2022
@ghost
Copy link

ghost commented Aug 9, 2022

Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

Currently we cannot test whether a ref readonly is null ref or not because Unsafe.IsNullRef() takes a ref parameter instead of ref readonly parameter.
Given that Unsafe.IsNullRef doesn’t need the ability of mutability, the signature should be changed from IsNullRef(ref) to IsNullRef(ref readonly).

API Proposal

namespace System.Runtime.CompilerServices;

public static class Unsafe
{
-    public bool IsNullRef(ref value);
+    public bool IsNullRef(ref readonly value); // or in value
}

API Usage

ref readonly int Foo() {}
ref readonly int x = ref Foo();
Unsafe.IsNullRef(in x);

Alternative Designs

No response

Risks

No response

Author: hez2010
Assignees: -
Labels:

api-suggestion, area-System.Runtime.CompilerServices

Milestone: -

@hez2010 hez2010 changed the title API Proposal: Unsafe.IsNullRef(in) API Proposal: Unsafe.IsNullRef(ref readonly) Aug 9, 2022
@sakno
Copy link
Contributor

sakno commented Aug 9, 2022

@hez2010 , you can but with a bit more verbose code:

ref readonly int x = ref Foo();
Unsafe.IsNullRef(ref Unsafe.AsRef(in x));

@stephentoub
Copy link
Member

the signature should be changed from IsNullRef(ref) to IsNullRef(ref readonly).

The language doesn't currently support that, changing the current signature to in instead of ref would be breaking, and we can't overload on ref vs in.

This would require dotnet/csharplang#6010, at which point there are a bunch of methods including this one we'd be looking to change over.

@buyaa-n buyaa-n added this to the Future milestone Aug 10, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Aug 10, 2022
@jkotas
Copy link
Member

jkotas commented Nov 5, 2023

Superseded by #73608.

@jkotas jkotas closed this as completed Nov 5, 2023
@hez2010
Copy link
Contributor Author

hez2010 commented Nov 5, 2023

I think you mean by #85911?

@ghost ghost locked as resolved and limited conversation to collaborators Dec 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime.CompilerServices
Projects
None yet
Development

No branches or pull requests

5 participants