Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Expose Index and Range types #20899

Merged
merged 4 commits into from
Nov 10, 2018
Merged

Expose Index and Range types #20899

merged 4 commits into from
Nov 10, 2018

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Nov 9, 2018

This change is exposing Index and Range types for C# 8.0 compiler support

@tarekgh
Copy link
Member Author

tarekgh commented Nov 9, 2018

@jkotas
Copy link
Member

jkotas commented Nov 9, 2018

Have we looked at how this representation of Index and Range interacts with JIT optimizations?

cc @AndyAyersMS

private readonly int _value;

public int Value => _value < 0 ? ~_value : _value;
public bool FromEnd => _value < 0;
Copy link
Member

Choose a reason for hiding this comment

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

Did we have an API review for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

}

public static implicit operator Index(int value)
=> new Index(value, fromEnd: false);
Copy link
Member

Choose a reason for hiding this comment

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

Should these types have overridden Equals/GetHashCode/ToString like other core structs ?

Copy link
Member

Choose a reason for hiding this comment

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

LDM hasn't talked about this that I can find, but I think it's a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add these. any suggestion for ToString return values?

I assume for Index we should return the index and ^ for from end, something like "1" and "^1"

For Range, we can return x..y and add ^ before the number if any of the indexes is from end.

what you think?

Copy link
Member

Choose a reason for hiding this comment

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

I think that sounds good. cc @MadsTorgersen I'll bring this to LDM for confirmation, but you're good to put it in for preview 1.

Copy link
Member

Choose a reason for hiding this comment

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

Should they implement IEquatable<T>?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll go ahead and implement it.

@tarekgh
Copy link
Member Author

tarekgh commented Nov 9, 2018

CC @MadsTorgersen

@joshfree joshfree added this to the 3.0 milestone Nov 9, 2018
@tarekgh
Copy link
Member Author

tarekgh commented Nov 9, 2018

please let me know if there is any more feedback. thanks.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Please make sure that we have follow up items to look at the performance of this

@tarekgh
Copy link
Member Author

tarekgh commented Nov 9, 2018

@jkotas

Please make sure that we have follow up items to look at the performance of this

I have logged the issue https://github.com/dotnet/corefx/issues/33376 to track that.

@tarekgh
Copy link
Member Author

tarekgh commented Nov 9, 2018

Thanks @stephentoub I have addressed all your feedback

}

return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Now that you've added the strongly typed Equals, this can just be:

public override bool Equals(object value) => value is Range && Equals((Range)value);

but don't block your PR on it.

@tarekgh tarekgh merged commit 3464b60 into dotnet:master Nov 10, 2018
dotnet-maestro-bot pushed a commit to dotnet-maestro-bot/corefx that referenced this pull request Nov 10, 2018
* Expose Index and Range types

* Address Review Comments

* Address more feedback

* Addressing more comments

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
stephentoub pushed a commit to dotnet/corefx that referenced this pull request Nov 10, 2018
* Expose Index and Range types

* Address Review Comments

* Address more feedback

* Addressing more comments

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
dotnet-maestro-bot pushed a commit to dotnet-maestro-bot/corert that referenced this pull request Nov 12, 2018
* Expose Index and Range types

* Address Review Comments

* Address more feedback

* Addressing more comments

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
MichalStrehovsky pushed a commit to dotnet/corert that referenced this pull request Nov 12, 2018
* Expose Index and Range types

* Address Review Comments

* Address more feedback

* Addressing more comments

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>

namespace System
{
public readonly struct Index : IEquatable<Index>
Copy link
Member

Choose a reason for hiding this comment

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

No XML comments for docs?

@@ -154,6 +154,24 @@ internal ReadOnlySpan(ref T ptr, int length)
#endif
}

public ref readonly T this[Index index]
Copy link
Member

Choose a reason for hiding this comment

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

Same here/elsewhere. Public APIs need documentation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add the documentation later. thanks @ahsonkhan


public override int GetHashCode()
{
return _value;
Copy link

Choose a reason for hiding this comment

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

Should this GetHashCode() related to the FromEnd property?

Copy link
Member Author

Choose a reason for hiding this comment

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

_value already include the from end info. look at how we initialize _value when having from end set.

marek-safar pushed a commit to mono/corefx that referenced this pull request Feb 12, 2019
* Expose Index and Range types

* Address Review Comments

* Address more feedback

* Addressing more comments

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
(cherry picked from commit b730b3c)
@tarekgh tarekgh deleted the IndexAndRange branch March 25, 2019 15:29
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Expose Index and Range types

* Address Review Comments

* Address more feedback

* Addressing more comments


Commit migrated from dotnet/coreclr@3464b60
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants