-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Collection literals: address comments #68793
Merged
cston
merged 7 commits into
dotnet:features/CollectionLiterals
from
cston:collections-comments
Jun 29, 2023
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a207dec
Resolve PROTOTYPE comments
cston 796e5fc
Update test
cston e83cf63
Merge remote-tracking branch 'upstream/features/CollectionLiterals' i…
cston 365729d
Update ids
cston bd9e485
Merge remote-tracking branch 'upstream/features/CollectionLiterals' i…
cston a4bcd23
Merge remote-tracking branch 'upstream/features/CollectionLiterals' i…
cston 85684de
Address feedback from IOperation change
cston 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -464,7 +464,7 @@ private BoundCollectionLiteralExpression BindArrayOrSpanCollectionLiteral( | |
if (elements.Any(e => e is BoundCollectionLiteralSpreadElement)) | ||
{ | ||
// The array initializer includes at least one spread element, so we'll create an intermediate List<T> instance. | ||
// PROTOTYPE: Avoid the intermediate list if the compile-time type of the spread element includes a length. | ||
// https://github.com/dotnet/roslyn/issues/68785: Avoid intermediate List<T> if all spread elements have Length property. | ||
_ = GetWellKnownTypeMember(WellKnownMember.System_Collections_Generic_List_T__ToArray, diagnostics, syntax: syntax); | ||
var result = BindCollectionInitializerCollectionLiteral( | ||
node, | ||
|
@@ -531,7 +531,7 @@ private BoundCollectionLiteralExpression BindCollectionInitializerCollectionLite | |
if (targetType is NamedTypeSymbol namedType) | ||
{ | ||
var analyzedArguments = AnalyzedArguments.GetInstance(); | ||
// PROTOTYPE: Should we use List<T>(int capacity) constructor when the size is known? | ||
// https://github.com/dotnet/roslyn/issues/68785: Use ctor with `int capacity` when the size is known. | ||
collectionCreation = BindClassCreationExpression(syntax, namedType.Name, syntax, namedType, analyzedArguments, diagnostics); | ||
collectionCreation.WasCompilerGenerated = true; | ||
analyzedArguments.Free(); | ||
|
@@ -548,18 +548,13 @@ private BoundCollectionLiteralExpression BindCollectionInitializerCollectionLite | |
} | ||
|
||
var implicitReceiver = new BoundObjectOrCollectionValuePlaceholder(syntax, isNewInstance: true, targetType) { WasCompilerGenerated = true }; | ||
// PROTOTYPE: When generating a List<T>, should we use the well-known | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added open issue to test plan #66418. |
||
// member List<T>.Add() rather than relying on lookup? | ||
var collectionInitializerAddMethodBinder = this.WithAdditionalFlags(BinderFlags.CollectionInitializerAddMethod); | ||
var builder = ArrayBuilder<BoundExpression>.GetInstance(node.Elements.Length); | ||
foreach (var element in node.Elements) | ||
{ | ||
var result = element switch | ||
{ | ||
BoundBadExpression => element, | ||
// PROTOTYPE: Should spread elements support target type? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added open issue to test plan #66418. |
||
// string[] a = [..b ? [null] : []]; | ||
// See CollectionLiteralTests.SpreadElement_05, _06. | ||
BoundCollectionLiteralSpreadElement spreadElement => BindCollectionInitializerSpreadElementAddMethod( | ||
(SpreadElementSyntax)spreadElement.Syntax, | ||
spreadElement, | ||
|
@@ -595,7 +590,7 @@ private BoundCollectionLiteralExpression BindListInterfaceCollectionLiteral( | |
TypeSymbol elementType, | ||
BindingDiagnosticBag diagnostics) | ||
{ | ||
// PROTOTYPE: Improve perf. For instance, emit [] as Array.Empty<T>() rather than a List<T>. | ||
// https://github.com/dotnet/roslyn/issues/68785: Emit [] as Array.Empty<T>() rather than a List<T>. | ||
var result = BindCollectionInitializerCollectionLiteral( | ||
node, | ||
CollectionLiteralTypeKind.ListInterface, | ||
|
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.
We have a test plan #66418 item tracking this now.