Skip to content

Adding AllBitsSet to IBinaryNumber Interface - #71356

Merged
dakersnar merged 8 commits into
dotnet:mainfrom
dakersnar:feature-69676
Jun 29, 2022
Merged

dakersnar merged 8 commits into
dotnet:mainfrom
dakersnar:feature-69676

Conversation

@dakersnar

Copy link
Copy Markdown
Contributor

Fixes #69676

Note: there is a trimmer bug that is preventing a DIM of AllBitsSet from being possible. This will be added later once the bug is fixed.

I tried to match the style of the files I was adding to, but feel free to nitpick any style choices. Specifically, there are quite a few ways to hard code in an AllBitsSet constant for each of these types, so happy to tweak as needed.

@ghost

ghost commented Jun 27, 2022

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost

ghost commented Jun 27, 2022

Copy link
Copy Markdown

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

Issue Details

Fixes #69676

Note: there is a trimmer bug that is preventing a DIM of AllBitsSet from being possible. This will be added later once the bug is fixed.

I tried to match the style of the files I was adding to, but feel free to nitpick any style choices. Specifically, there are quite a few ways to hard code in an AllBitsSet constant for each of these types, so happy to tweak as needed.

Author: dakersnar
Assignees: dakersnar
Labels:

area-System.Numerics, new-api-needs-documentation

Milestone: -

where TSelf : IBinaryNumber<TSelf>
{
/// <summary>Gets an instance of the binary type in which all bits are set.</summary>
static abstract TSelf AllBitsSet { get; } // TODO: add the DIM once https://github.com/dotnet/linker/issues/2865 is fixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a runtime issue tracking all of the APIs that need to be made DIMs once this bug is fixed? Presumably this is a must-do for .NET 7?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other APIs are already DIM where relevant. This is a new scenario specific to properties.

@stephentoub stephentoub Jun 28, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other APIs are already DIM where relevant.

Oh. We're not making APIs like IParseable.Parse DIMs? I figured that'd have been implemented in terms of TryParse by default.

static abstract TSelf Parse(string s, IFormatProvider? provider);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't given the current shape because there are multiple possible "failure conditions".

For all the primitive types, we have an internal TryParse method which returns a ParsingStatus that is then used to determine if the issue was overflow or format.

We'd likely need to codify and expose a slightly different shape if we wanted this to be DIM.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or agree that we just always throw FormatException and expect users that need to differentiate to always override).

@dakersnar dakersnar Jun 28, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that I'm the first person to run into this implies this is the first static virtual property somebody has tried to use. This is surprising and suspicious. I wonder if I'm just the first one to realize the DIM isn't being overridden by inheriting classes. Regardless, yes, I think fixing the bug should have relatively high priority.

Edit: for some reason it didn't show me any of Tanner's replies, sorry if some of this was redundant.

@dakersnar dakersnar left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More suggestions from code review

@dakersnar
dakersnar merged commit cd553b7 into dotnet:main Jun 29, 2022
@dakersnar
dakersnar deleted the feature-69676 branch June 29, 2022 19:48
@dakersnar dakersnar mentioned this pull request Jul 27, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add AllBitsSet to the IBinaryNumber Interface

3 participants