Skip to content

Commit

Permalink
Rename collection literal to collection expression (#69114)
Browse files Browse the repository at this point in the history
  • Loading branch information
cston authored Jul 20, 2023
1 parent 71b07c9 commit 5005650
Show file tree
Hide file tree
Showing 48 changed files with 664 additions and 664 deletions.
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private BoundExpression CheckValue(BoundExpression expr, BindValueKind valueKind
}
break;

case BoundKind.UnconvertedCollectionLiteralExpression:
case BoundKind.UnconvertedCollectionExpression:
if (valueKind == BindValueKind.RValue)
{
return expr;
Expand Down Expand Up @@ -3959,7 +3959,7 @@ internal uint GetValEscape(BoundExpression expr, uint scopeOfTheContainingExpres
var switchExpr = (BoundSwitchExpression)expr;
return GetValEscape(switchExpr.SwitchArms.SelectAsArray(a => a.Value), scopeOfTheContainingExpression);

case BoundKind.CollectionLiteralExpression:
case BoundKind.CollectionExpression:
return CallingMethodScope;

default:
Expand Down Expand Up @@ -4488,7 +4488,7 @@ internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint escapeF

return true;

case BoundKind.CollectionLiteralExpression:
case BoundKind.CollectionExpression:
return true;

default:
Expand Down
78 changes: 39 additions & 39 deletions src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static bool filterConversion(Conversion conversion)
return !conversion.IsInterpolatedString &&
!conversion.IsInterpolatedStringHandler &&
!conversion.IsSwitchExpression &&
!conversion.IsCollectionLiteral &&
!conversion.IsCollectionExpression &&
!(conversion.IsTupleLiteralConversion || (conversion.IsNullable && conversion.UnderlyingConversions[0].IsTupleLiteralConversion)) &&
(!conversion.IsUserDefined || filterConversion(conversion.UserDefinedFromConversion));
}
Expand Down Expand Up @@ -231,11 +231,11 @@ BoundExpression createConversion(
return ConvertObjectCreationExpression(syntax, (BoundUnconvertedObjectCreationExpression)source, conversion, isCast, destination, conversionGroupOpt, wasCompilerGenerated, diagnostics);
}

if (source.Kind == BoundKind.UnconvertedCollectionLiteralExpression)
if (source.Kind == BoundKind.UnconvertedCollectionExpression)
{
Debug.Assert(conversion.IsCollectionLiteral || !conversion.Exists);
source = ConvertCollectionLiteralExpression(
(BoundUnconvertedCollectionLiteralExpression)source,
Debug.Assert(conversion.IsCollectionExpression || !conversion.Exists);
source = ConvertCollectionExpression(
(BoundUnconvertedCollectionExpression)source,
destination,
wasCompilerGenerated,
diagnostics);
Expand Down Expand Up @@ -526,58 +526,58 @@ static BoundExpression bindObjectCreationExpression(
}
}

private BoundExpression ConvertCollectionLiteralExpression(
BoundUnconvertedCollectionLiteralExpression node,
private BoundExpression ConvertCollectionExpression(
BoundUnconvertedCollectionExpression node,
TypeSymbol targetType,
bool wasCompilerGenerated,
BindingDiagnosticBag diagnostics)
{
TypeSymbol? elementType;
var collectionTypeKind = ConversionsBase.GetCollectionLiteralTypeKind(Compilation, targetType, out elementType);
var collectionTypeKind = ConversionsBase.GetCollectionExpressionTypeKind(Compilation, targetType, out elementType);
switch (collectionTypeKind)
{
case CollectionLiteralTypeKind.CollectionInitializer:
return BindCollectionInitializerCollectionLiteral(node, collectionTypeKind, targetType, wasCompilerGenerated: wasCompilerGenerated, diagnostics);
case CollectionLiteralTypeKind.Array:
case CollectionLiteralTypeKind.Span:
case CollectionLiteralTypeKind.ReadOnlySpan:
return BindArrayOrSpanCollectionLiteral(node, targetType, wasCompilerGenerated: wasCompilerGenerated, collectionTypeKind, elementType!, diagnostics);
case CollectionLiteralTypeKind.ListInterface:
return BindListInterfaceCollectionLiteral(node, targetType, wasCompilerGenerated: wasCompilerGenerated, elementType!, diagnostics);
case CollectionLiteralTypeKind.None:
return BindCollectionLiteralForErrorRecovery(node, targetType, diagnostics);
case CollectionExpressionTypeKind.CollectionInitializer:
return BindCollectionInitializerCollectionExpression(node, collectionTypeKind, targetType, wasCompilerGenerated: wasCompilerGenerated, diagnostics);
case CollectionExpressionTypeKind.Array:
case CollectionExpressionTypeKind.Span:
case CollectionExpressionTypeKind.ReadOnlySpan:
return BindArrayOrSpanCollectionExpression(node, targetType, wasCompilerGenerated: wasCompilerGenerated, collectionTypeKind, elementType!, diagnostics);
case CollectionExpressionTypeKind.ListInterface:
return BindListInterfaceCollectionExpression(node, targetType, wasCompilerGenerated: wasCompilerGenerated, elementType!, diagnostics);
case CollectionExpressionTypeKind.None:
return BindCollectionExpressionForErrorRecovery(node, targetType, diagnostics);
default:
throw ExceptionUtilities.UnexpectedValue(collectionTypeKind);
}
}

private BoundCollectionLiteralExpression BindArrayOrSpanCollectionLiteral(
BoundUnconvertedCollectionLiteralExpression node,
private BoundCollectionExpression BindArrayOrSpanCollectionExpression(
BoundUnconvertedCollectionExpression node,
TypeSymbol targetType,
bool wasCompilerGenerated,
CollectionLiteralTypeKind collectionTypeKind,
CollectionExpressionTypeKind collectionTypeKind,
TypeSymbol elementType,
BindingDiagnosticBag diagnostics)
{
var syntax = (CSharpSyntaxNode)node.Syntax;

switch (collectionTypeKind)
{
case CollectionLiteralTypeKind.Span:
case CollectionExpressionTypeKind.Span:
_ = GetWellKnownTypeMember(WellKnownMember.System_Span_T__ctor_Array, diagnostics, syntax: syntax);
break;
case CollectionLiteralTypeKind.ReadOnlySpan:
case CollectionExpressionTypeKind.ReadOnlySpan:
_ = GetWellKnownTypeMember(WellKnownMember.System_ReadOnlySpan_T__ctor_Array, diagnostics, syntax: syntax);
break;
}

var elements = node.Elements;
if (elements.Any(e => e is BoundCollectionLiteralSpreadElement))
if (elements.Any(e => e is BoundCollectionExpressionSpreadElement))
{
// The array initializer includes at least one spread element, so we'll create an intermediate List<T> instance.
// 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(
var result = BindCollectionInitializerCollectionExpression(
node,
collectionTypeKind,
GetWellKnownType(WellKnownType.System_Collections_Generic_List_T, diagnostics, syntax).Construct(elementType),
Expand All @@ -592,7 +592,7 @@ private BoundCollectionLiteralExpression BindArrayOrSpanCollectionLiteral(
{
builder.Add(convertArrayElement(element, elementType, diagnostics));
}
return new BoundCollectionLiteralExpression(
return new BoundCollectionExpression(
syntax,
collectionTypeKind,
implicitReceiver,
Expand Down Expand Up @@ -628,9 +628,9 @@ BoundExpression convertArrayElement(BoundExpression element, TypeSymbol elementT
}
}

private BoundCollectionLiteralExpression BindCollectionInitializerCollectionLiteral(
BoundUnconvertedCollectionLiteralExpression node,
CollectionLiteralTypeKind collectionTypeKind,
private BoundCollectionExpression BindCollectionInitializerCollectionExpression(
BoundUnconvertedCollectionExpression node,
CollectionExpressionTypeKind collectionTypeKind,
TypeSymbol targetType,
bool wasCompilerGenerated,
BindingDiagnosticBag diagnostics,
Expand Down Expand Up @@ -666,7 +666,7 @@ private BoundCollectionLiteralExpression BindCollectionInitializerCollectionLite
var result = element switch
{
BoundBadExpression => element,
BoundCollectionLiteralSpreadElement spreadElement => BindCollectionInitializerSpreadElementAddMethod(
BoundCollectionExpressionSpreadElement spreadElement => BindCollectionInitializerSpreadElementAddMethod(
(SpreadElementSyntax)spreadElement.Syntax,
spreadElement,
collectionInitializerAddMethodBinder,
Expand All @@ -683,7 +683,7 @@ private BoundCollectionLiteralExpression BindCollectionInitializerCollectionLite
result.WasCompilerGenerated = true;
builder.Add(result);
}
return new BoundCollectionLiteralExpression(
return new BoundCollectionExpression(
syntax,
collectionTypeKind,
implicitReceiver,
Expand All @@ -694,25 +694,25 @@ private BoundCollectionLiteralExpression BindCollectionInitializerCollectionLite
{ WasCompilerGenerated = wasCompilerGenerated };
}

private BoundCollectionLiteralExpression BindListInterfaceCollectionLiteral(
BoundUnconvertedCollectionLiteralExpression node,
private BoundCollectionExpression BindListInterfaceCollectionExpression(
BoundUnconvertedCollectionExpression node,
TypeSymbol targetType,
bool wasCompilerGenerated,
TypeSymbol elementType,
BindingDiagnosticBag diagnostics)
{
// https://github.com/dotnet/roslyn/issues/68785: Emit [] as Array.Empty<T>() rather than a List<T>.
var result = BindCollectionInitializerCollectionLiteral(
var result = BindCollectionInitializerCollectionExpression(
node,
CollectionLiteralTypeKind.ListInterface,
CollectionExpressionTypeKind.ListInterface,
GetWellKnownType(WellKnownType.System_Collections_Generic_List_T, diagnostics, node.Syntax).Construct(elementType),
wasCompilerGenerated: wasCompilerGenerated,
diagnostics);
return result.Update(result.CollectionTypeKind, result.Placeholder, result.CollectionCreation, result.Elements, targetType);
}

private BoundCollectionLiteralExpression BindCollectionLiteralForErrorRecovery(
BoundUnconvertedCollectionLiteralExpression node,
private BoundCollectionExpression BindCollectionExpressionForErrorRecovery(
BoundUnconvertedCollectionExpression node,
TypeSymbol targetType,
BindingDiagnosticBag diagnostics)
{
Expand All @@ -722,9 +722,9 @@ private BoundCollectionLiteralExpression BindCollectionLiteralForErrorRecovery(
{
builder.Add(BindToNaturalType(element, diagnostics, reportNoTargetType: !targetType.IsErrorType()));
}
return new BoundCollectionLiteralExpression(
return new BoundCollectionExpression(
syntax,
collectionTypeKind: CollectionLiteralTypeKind.None,
collectionTypeKind: CollectionExpressionTypeKind.None,
placeholder: null,
collectionCreation: null,
elements: builder.ToImmutableAndFree(),
Expand Down
26 changes: 13 additions & 13 deletions src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,13 @@ internal BoundExpression BindToNaturalType(BoundExpression expression, BindingDi
result = RebindSimpleBinaryOperatorAsConverted(unconvertedBinaryOperator, diagnostics);
}
break;
case BoundUnconvertedCollectionLiteralExpression expr:
case BoundUnconvertedCollectionExpression expr:
{
if (reportNoTargetType && !expr.HasAnyErrors)
{
diagnostics.Add(ErrorCode.ERR_CollectionLiteralNoTargetType, expr.Syntax.GetLocation());
diagnostics.Add(ErrorCode.ERR_CollectionExpressionNoTargetType, expr.Syntax.GetLocation());
}
result = BindCollectionLiteralForErrorRecovery(expr, CreateErrorType(), diagnostics);
result = BindCollectionExpressionForErrorRecovery(expr, CreateErrorType(), diagnostics);
}
break;
default:
Expand Down Expand Up @@ -774,7 +774,7 @@ private BoundExpression BindExpressionInternal(ExpressionSyntax node, BindingDia
return BadExpression(node);

case SyntaxKind.CollectionExpression:
return BindCollectionLiteralExpression((CollectionExpressionSyntax)node, diagnostics);
return BindCollectionExpression((CollectionExpressionSyntax)node, diagnostics);

case SyntaxKind.NullableType:
// Not reachable during method body binding, but
Expand Down Expand Up @@ -2747,11 +2747,11 @@ private void GenerateExplicitConversionErrors(
GenerateImplicitConversionError(diagnostics, operand.Syntax, conversion, operand, targetType);
return;
}
case BoundKind.UnconvertedCollectionLiteralExpression:
case BoundKind.UnconvertedCollectionExpression:
{
if (operand.Type is null)
{
Error(diagnostics, ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, syntax, targetType);
Error(diagnostics, ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, syntax, targetType);
return;
}
break;
Expand Down Expand Up @@ -4650,16 +4650,16 @@ BoundExpression bindObjectCreationExpression(ObjectCreationExpressionSyntax node
}

#nullable enable
private BoundExpression BindCollectionLiteralExpression(CollectionExpressionSyntax syntax, BindingDiagnosticBag diagnostics)
private BoundExpression BindCollectionExpression(CollectionExpressionSyntax syntax, BindingDiagnosticBag diagnostics)
{
MessageID.IDS_FeatureCollectionLiterals.CheckFeatureAvailability(diagnostics, syntax, syntax.OpenBracketToken.GetLocation());
MessageID.IDS_FeatureCollectionExpressions.CheckFeatureAvailability(diagnostics, syntax, syntax.OpenBracketToken.GetLocation());

var builder = ArrayBuilder<BoundExpression>.GetInstance(syntax.Elements.Count);
foreach (var element in syntax.Elements)
{
builder.Add(bindElement(element, diagnostics));
}
return new BoundUnconvertedCollectionLiteralExpression(syntax, builder.ToImmutableAndFree(), this);
return new BoundUnconvertedCollectionExpression(syntax, builder.ToImmutableAndFree(), this);

BoundExpression bindElement(CollectionElementSyntax syntax, BindingDiagnosticBag diagnostics)
{
Expand All @@ -4679,7 +4679,7 @@ BoundExpression bindSpreadElement(SpreadElementSyntax syntax, BindingDiagnosticB
builder.IsIncomplete;
if (hasErrors)
{
return new BoundCollectionLiteralSpreadElement(
return new BoundCollectionExpressionSpreadElement(
syntax,
expression,
enumeratorInfoOpt: null,
Expand All @@ -4698,7 +4698,7 @@ BoundExpression bindSpreadElement(SpreadElementSyntax syntax, BindingDiagnosticB
diagnostics.Add(syntax.Expression, useSiteInfo);
expression = ConvertForEachCollection(expression, conversion, collectionType, diagnostics);
var elementPlaceholder = new BoundValuePlaceholder(syntax.Expression, enumeratorInfo.ElementType);
return new BoundCollectionLiteralSpreadElement(
return new BoundCollectionExpressionSpreadElement(
syntax,
expression,
enumeratorInfo,
Expand Down Expand Up @@ -5809,9 +5809,9 @@ private BoundExpression BindCollectionInitializerElementAddMethod(
}

#nullable enable
private BoundCollectionLiteralSpreadElement BindCollectionInitializerSpreadElementAddMethod(
private BoundCollectionExpressionSpreadElement BindCollectionInitializerSpreadElementAddMethod(
SpreadElementSyntax syntax,
BoundCollectionLiteralSpreadElement element,
BoundCollectionExpressionSpreadElement element,
Binder collectionInitializerAddMethodBinder,
BoundObjectOrCollectionValuePlaceholder implicitReceiver,
BindingDiagnosticBag diagnostics)
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,10 +2362,10 @@ protected void GenerateImplicitConversionError(
Debug.Assert(reportedError);
return;
}
case BoundKind.UnconvertedCollectionLiteralExpression:
case BoundKind.UnconvertedCollectionExpression:
{
Debug.Assert(operand.Type is null);
Error(diagnostics, ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, syntax, targetType);
Error(diagnostics, ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, syntax, targetType);
return;
}
case BoundKind.AddressOfOperator when targetType.IsFunctionPointer():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Microsoft.CodeAnalysis.CSharp
{
internal enum CollectionLiteralTypeKind
internal enum CollectionExpressionTypeKind
{
None = 0,
Array,
Expand Down
Loading

0 comments on commit 5005650

Please sign in to comment.