This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Extensions for immutable collection builders (#21055) #31071
Merged
safern
merged 6 commits into
dotnet:master
from
davidkaya:origin/immutable-builder-extensions
Oct 1, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
137e445
Extensions for immutable builders (#21055)
davidkaya fd9f13e
Extension for immutable sorted dictionary builder (#21055)
davidkaya ee9e1d3
Extensions for immutable builders in the reference api (#21055)
davidkaya bbdfc66
Tests for immutable builder extensions (#21055)
davidkaya 4f9efa4
Null check in extensions for immutable collection builders (#21055)
davidkaya 1a339db
Merge branch 'master' into origin/immutable-builder-extensions
davidkaya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that
[Pure]
has no runtime impact, why isn't the attribute included in the ref assemblies so that analyzers can do their work based on it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at it (and not the author) I'd guess that it's because none of the other definitions in the ref assembly have them and he followed the existing pattern on the assumption that someone in the past had good reason to do this.
Adding them in ref would require a dependency on
System.Diagnostics.Contracts
which would seem an odd thing to do.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed: this PR itself looks consistent with precedent. So my question was perhaps more directed at the authors of the ref assemblies in general. @danmosemsft @csharpfritz perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I was included incorrectly on this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Pure]
is part of Contracts, right? We don't use or enforce those and generally have been removing contract annotations. I believe we discussed this before in the context of immutable collections in fact and @AArnott did you indicate you didn't believe in them either? In which case I guess these can all be removed unless they are somehow still useful to .NET Framework consumers even though they're not on the ref assembly and probably not consistent either.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Based on the past experiments with Code Contracts, it is very hard to get a return on investment with this. The annotations do catch a few bugs, but they require a prohibitive amount of manual work to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotations aside, if the compiler included an analyzer with a hard coded list of most commonly misused pure functions (even just those on String) it would provide non zero value with ?no false positives. 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Contracts preceded roslyn analyzers, and required custom build steps, VS extensions, and/or post-compilation IL-rewriting . Roslyn analyzers are proven to be effective and popular. Let's not let Code Contracts' failure deter us from tapping Analyzers for solving this simple issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Pure attribute is checked by Rule CA1806 in Microsoft.CodeQuality.Analyzers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for redrawing attention to this, @Grauenwolf. I've filed a separate issue to track the issue: https://github.com/dotnet/corefx/issues/34778