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

Add IReadOnlySet<T> interface #32488

Merged
merged 13 commits into from
Mar 4, 2020
Merged

Conversation

Jlalond
Copy link
Contributor

@Jlalond Jlalond commented Feb 18, 2020

@stephentoub stephentoub changed the title Readonly set Add IReadOnlySet<T> interface Feb 18, 2020
@Jlalond Jlalond force-pushed the readonly-set branch 2 times, most recently from 0e5ce15 to 91bfff5 Compare February 18, 2020 15:08
@Jlalond
Copy link
Contributor Author

Jlalond commented Feb 18, 2020

@stephentoub Sorry about the naming/rebasing, I dropped when I should've squashed and got myself into trouble. The dangers of not drinking coffee early in the morning

@Jlalond
Copy link
Contributor Author

Jlalond commented Feb 20, 2020

@danmosemsft / @jkotas It's not mentioned in the issue, but should we have IImmutableSet<T> inherit from IReadOnlySet<T> instead of having Immutable hashset/sortedset inherit from IReadOnlySet individually?

@maryamariyan
Copy link
Member

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.

@Jlalond
Copy link
Contributor Author

Jlalond commented Feb 25, 2020

@maryamariyan So I should add to the dev remarks? Even if I haven't actually added a method to the ref/impl

@jkotas
Copy link
Member

jkotas commented Feb 25, 2020

@eiriktsarpalis @layomia You are the area-System.Collections owners according to https://github.com/dotnet/runtime/blob/master/docs/area-owners.md. Could you please provide guidance to @Jlalond with this PR?

@carlossanlop
Copy link
Member

carlossanlop commented Feb 25, 2020

So I should add to the dev remarks? Even if I haven't actually added a method to the ref/impl

@Jlalond You are adding the interface only in the src file. Shouldn't new interfaces be added to ref files as well so they can be exposed publicly?

Yes, please add triple slash comments on top of the interface's type and methods.

We have new official guidance, and not having documentation for new APIs is considered a PR merge blocker.

@Jlalond
Copy link
Contributor Author

Jlalond commented Feb 25, 2020

@carlossanlop I understand that I needed to add this to ref and impl and I did that for hashset and sortedset, as well as their respective ref/impl in Immutable. Is there a ref for private core lib? Because if so, it all makes sense to me now as to why I'm struggling to get this to build. I will add the dev comments for certain, but I wanted to clear up where I'm not implementing in a ref vs an impl

@carlossanlop
Copy link
Member

carlossanlop commented Feb 25, 2020

Is there a ref for private core lib? Because if so, it all makes sense to me now as to why I'm struggling to get this to build.

@jkotas @eiriktsarpalis @layomia do you know in which ref file this interface should be declared?

@Jlalond
Copy link
Contributor Author

Jlalond commented Feb 25, 2020

@carlossanlop I think I found it in System.Runtime, sorry it took me so long to figure that out :(

@carlossanlop
Copy link
Member

No worries, @Jlalond 😸 Glad you found it.

@Jlalond
Copy link
Contributor Author

Jlalond commented Feb 25, 2020

@carlossanlop macosx runtime seemed to fail, are there any flaky tests/can you bump the build one more time?

Looks it failed twice for crypto

/// Determines whether the current set overlaps with the specified collection.
/// </summary>
/// <param name="other">The collection to compare to the current set.</param>
/// <returns>ture if the currnet set and other share at least one common eleemnt; otherwise, false.</returns>
Copy link
Member

@eiriktsarpalis eiriktsarpalis Feb 26, 2020

Choose a reason for hiding this comment

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

Suggested change
/// <returns>ture if the currnet set and other share at least one common eleemnt; otherwise, false.</returns>
/// <returns><see langword="true" />if the current set and other share at least one common element; otherwise, <see langword="false" />.</returns>

Copy link
Member

Choose a reason for hiding this comment

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

@eiriktsarpalis I made a tiny edit to your suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@carlossanlop should I apply these langwords to all instances of true/false while I'm at it?

Copy link
Member

Choose a reason for hiding this comment

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

Yes sure, that would be great, thank you. true, false and also null.

@eiriktsarpalis
Copy link
Member

eiriktsarpalis commented Feb 26, 2020

@danmosemsft / @jkotas It's not mentioned in the issue, but should we have IImmutableSet inherit from IReadOnlySet instead of having Immutable hashset/sortedset inherit from IReadOnlySet individually?

I think it would be a reasonable and useful addition, but it probably needs to go through api review, since it was not scoped in the original proposal. What say you @terrajobst?

@stephentoub
Copy link
Member

stephentoub commented Feb 26, 2020

should we have IImmutableSet inherit from IReadOnlySet

I think it would be a reasonable and useful addition

Wouldn't that be a breaking change?

@Jlalond
Copy link
Contributor Author

Jlalond commented Feb 26, 2020

@stephentoub Can you explain why you think it's a breaking change? Is it because the old call sites would now be defined by an interface?

@stephentoub
Copy link
Member

stephentoub commented Feb 27, 2020

e.g. as a source breaking change example, imagine you have this:

interface A { void Bar(); }
    
public class C : A
{
    void A.Bar() { }
}

Now I come along and add:

interface B { void Bar(); }

and change A to inherit B. C will no longer compile.

@Jlalond
Copy link
Contributor Author

Jlalond commented Feb 27, 2020

@stephentoub Makes absolute sense, as which method to call, I only ask because IImmutableSet only inherits from IReadOnlyCollection. I'm absolutely no expert on this, just wanting to learn.

To clarify what I mean, In your above example, only C is defining Bar() and now is inheriting the declaration of same function from B, is that still a source breaking change?

@stephentoub
Copy link
Member

To clarify what I mean, In your above example, only C is defining Bar() and now is inheriting the declaration of same function from B, is that still a source breaking change?

Sorry, I don't understand the question. Can you write out the code for what you're asking?

@Jlalond
Copy link
Contributor Author

Jlalond commented Feb 27, 2020

@stephentoub
IImmutableSet<T> already exposes contain, and ImmutableHashSet<T> implements both IImmutableSet<T> and ISet<T> which both share contain. This change has ImmutableHashSet<T> inheriting functions from IReadOnlySet<T> which overlaps with ISet<T>. Is having IImmutableSet<T> forwarding the behavior from IReadOnlySet<T> which IImmutableSet<T> is already implementing source breaking?

From:

interface IImmutableSet<T>
{
  bool Contains(T item);
}

To:

interface IImmutableSet<T> : IReadOnlySet<T>
{
   // contains is now defined in read only set
}

@Jlalond
Copy link
Contributor Author

Jlalond commented Feb 28, 2020

@stephentoub Awesome, thank you for explaining. So we're not adding to IImmutableSet? If so I'll get all the edits done

@terrajobst
Copy link
Member

terrajobst commented Feb 28, 2020

@eiriktsarpalis

I think it would be a reasonable and useful addition, but it probably needs to go through api review, since it was not scoped in the original proposal. What say you @terrajobst?

It's listed on the API review feedback already. It's unfortunate that the other immutable interfaces all extend their read-only counterparts because we can't do that for the new IReadOnlySet<T> because it's a breaking change (same reason why the mutable interfaces weren't updated to extend the read-only ones).

I think we should still implement IReadOnlySet<T> on ImmutableHashSet<T> and ImmutableSortedSet<T> though.

@Jlalond
Copy link
Contributor Author

Jlalond commented Mar 3, 2020

@eiriktsarpalis @layomia Hey guys, rebased on top of master and looks like it's building. If I could get another review I'd appreciate it!

Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for your contribution.

@Jlalond
Copy link
Contributor Author

Jlalond commented Mar 3, 2020

@eiriktsarpalis No thank you! Without help of you, Joe and @carlossanlop I wouldn't have figured I needed a ref in System.Runtime!

@oliverjanik
Copy link

What release will this PR make it into?

@eiriktsarpalis
Copy link
Member

What release will this PR make it into?

It should already be available in some of the .NET 5 previews. I run preview 5 on my machine and it's there.

@nawfalhasan
Copy link

Finally... 👏👏

May I suggest Dictionary.KeyCollection should also implement this?

@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
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.

10 participants