Skip to content

Commit

Permalink
Rename BoundNode flag for clarity (#72235)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyTs authored Feb 23, 2024
1 parent 05cf517 commit 8085621
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 54 deletions.
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/Binder/Binder_Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ ImmutableArray<int> makeSourceIndices()
return default;
}

Debug.Assert(arguments.Count(a => a.IsParamsCollection) == (boundAttribute.ConstructorExpanded ? 1 : 0));
Debug.Assert(arguments.Count(a => a.IsParamsArrayOrCollection) == (boundAttribute.ConstructorExpanded ? 1 : 0));

// make source indices if we have anything that doesn't map 1:1 from arguments to parameters:
// 1. implicit default arguments
Expand Down Expand Up @@ -380,12 +380,12 @@ ImmutableArray<int> makeSourceIndices()
constructorArgumentSourceIndices.Count = lengthAfterRewriting;
for (int argIndex = 0; argIndex < lengthAfterRewriting; argIndex++)
{
Debug.Assert(!arguments[argIndex].IsParamsCollection || arguments[argIndex] is BoundArrayCreation);
Debug.Assert(!arguments[argIndex].IsParamsArrayOrCollection || arguments[argIndex] is BoundArrayCreation);

int paramIndex = argsToParamsOpt.IsDefault ? argIndex : argsToParamsOpt[argIndex];
constructorArgumentSourceIndices[paramIndex] =
defaultArguments[argIndex] ||
(arguments[argIndex].IsParamsCollection && arguments[argIndex] is BoundArrayCreation { Bounds: [BoundLiteral { ConstantValueOpt.Value: 0 }] }) ?
(arguments[argIndex].IsParamsArrayOrCollection && arguments[argIndex] is BoundArrayCreation { Bounds: [BoundLiteral { ConstantValueOpt.Value: 0 }] }) ?
-1 : argIndex;
}
return constructorArgumentSourceIndices.ToImmutableAndFree();
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ private BoundCollectionExpression ConvertCollectionExpression(
node,
builder.ToImmutableAndFree(),
targetType)
{ WasCompilerGenerated = node.IsParamsCollection, IsParamsCollection = node.IsParamsCollection };
{ WasCompilerGenerated = node.IsParamsArrayOrCollection, IsParamsArrayOrCollection = node.IsParamsArrayOrCollection };

BoundNode bindSpreadElement(BoundCollectionExpressionSpreadElement element, TypeSymbol elementType, Conversion elementConversion, BindingDiagnosticBag diagnostics)
{
Expand Down Expand Up @@ -1327,7 +1327,7 @@ private BoundCollectionExpression BindCollectionExpressionForErrorRecovery(
elements: builder.ToImmutableAndFree(),
targetType,
hasErrors: true)
{ WasCompilerGenerated = node.IsParamsCollection, IsParamsCollection = node.IsParamsCollection };
{ WasCompilerGenerated = node.IsParamsArrayOrCollection, IsParamsArrayOrCollection = node.IsParamsArrayOrCollection };
}

private void GenerateImplicitConversionErrorForCollectionExpression(
Expand Down
12 changes: 6 additions & 6 deletions src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ internal void BindDefaultArgumentsAndParamsCollection(
int paramsIndex = parameters.Length - 1;
var paramsArgsBuilder = expanded ? ArrayBuilder<BoundExpression>.GetInstance() : null;

Debug.Assert(!argumentsBuilder.Any(a => a.IsParamsCollection));
Debug.Assert(!argumentsBuilder.Any(a => a.IsParamsArrayOrCollection));

var visitedParameters = BitVector.Create(parameters.Length);
for (var i = 0; i < argumentsBuilder.Count; i++)
Expand Down Expand Up @@ -1583,7 +1583,7 @@ internal void BindDefaultArgumentsAndParamsCollection(
ImmutableArray.Create(arraySize),
new BoundArrayInitialization(node, isInferred: false, collectionArgs) { WasCompilerGenerated = true },
collectionType)
{ WasCompilerGenerated = true, IsParamsCollection = true };
{ WasCompilerGenerated = true, IsParamsArrayOrCollection = true };
}
else
{
Expand All @@ -1592,7 +1592,7 @@ internal void BindDefaultArgumentsAndParamsCollection(
MessageID.IDS_ParamsCollections.CheckFeatureAvailability(diagnostics, node);
}

var unconvertedCollection = new BoundUnconvertedCollectionExpression(node, ImmutableArray<BoundNode>.CastUp(collectionArgs)) { WasCompilerGenerated = true, IsParamsCollection = true };
var unconvertedCollection = new BoundUnconvertedCollectionExpression(node, ImmutableArray<BoundNode>.CastUp(collectionArgs)) { WasCompilerGenerated = true, IsParamsArrayOrCollection = true };
CompoundUseSiteInfo<AssemblySymbol> useSiteInfo = GetNewCompoundUseSiteInfo(diagnostics);
Conversion conversion = Conversions.ClassifyImplicitConversionFromExpression(unconvertedCollection, collectionType, ref useSiteInfo);
diagnostics.Add(node, useSiteInfo);
Expand Down Expand Up @@ -1626,7 +1626,7 @@ internal void BindDefaultArgumentsAndParamsCollection(
if (!paramsType.IsSZArray())
{
var discardedUseSiteInfo = CompoundUseSiteInfo<AssemblySymbol>.Discarded;
emptyCollection ??= new BoundUnconvertedCollectionExpression(node, ImmutableArray<BoundNode>.CastUp(ImmutableArray<BoundExpression>.Empty)) { WasCompilerGenerated = true, IsParamsCollection = true };
emptyCollection ??= new BoundUnconvertedCollectionExpression(node, ImmutableArray<BoundNode>.CastUp(ImmutableArray<BoundExpression>.Empty)) { WasCompilerGenerated = true, IsParamsArrayOrCollection = true };
Conversion nextConversion = Conversions.ClassifyImplicitConversionFromExpression(emptyCollection, paramsType, ref discardedUseSiteInfo);

if (nextConversion.Exists &&
Expand Down Expand Up @@ -1671,10 +1671,10 @@ internal void BindDefaultArgumentsAndParamsCollection(
conversionGroupOpt: null,
constantValueOpt: null,
type: collectionType)
{ WasCompilerGenerated = true, IsParamsCollection = true };
{ WasCompilerGenerated = true, IsParamsArrayOrCollection = true };
}

Debug.Assert(collection.IsParamsCollection);
Debug.Assert(collection.IsParamsArrayOrCollection);

if (collectionArgsLength != 0)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/BoundTree/BoundArrayCreation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace Microsoft.CodeAnalysis.CSharp
{
internal partial class BoundArrayCreation
{
public new bool IsParamsCollection
public new bool IsParamsArrayOrCollection
{
get
{
return base.IsParamsCollection;
return base.IsParamsArrayOrCollection;
}
init
{
base.IsParamsCollection = value;
base.IsParamsArrayOrCollection = value;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ internal bool HasSpreadElements(out int numberIncludingLastSpread, out bool hasK
return numberIncludingLastSpread > 0;
}

public new bool IsParamsCollection
public new bool IsParamsArrayOrCollection
{
get
{
return base.IsParamsCollection;
return base.IsParamsArrayOrCollection;
}
init
{
base.IsParamsCollection = value;
base.IsParamsArrayOrCollection = value;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,15 +496,15 @@ internal bool ConversionHasSideEffects()
return true;
}

public new bool IsParamsCollection
public new bool IsParamsArrayOrCollection
{
get
{
return base.IsParamsCollection;
return base.IsParamsArrayOrCollection;
}
init
{
base.IsParamsCollection = value;
base.IsParamsArrayOrCollection = value;
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/Compilers/CSharp/Portable/BoundTree/BoundNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ private enum BoundNodeAttributes : short
/// </summary>
WasConverted = 1 << 8,

ParamsCollection = 1 << 9,
ParamsArrayOrCollection = 1 << 9,

AttributesPreservedInClone = HasErrors | CompilerGenerated | IsSuppressed | WasConverted | ParamsCollection,
AttributesPreservedInClone = HasErrors | CompilerGenerated | IsSuppressed | WasConverted | ParamsArrayOrCollection,
}

protected new BoundNode MemberwiseClone()
Expand Down Expand Up @@ -152,9 +152,9 @@ protected void CopyAttributes(BoundNode original)
Debug.Assert(original is BoundExpression || !original.IsSuppressed);
this.IsSuppressed = original.IsSuppressed;

if (original.IsParamsCollection)
if (original.IsParamsArrayOrCollection)
{
this.IsParamsCollection = true;
this.IsParamsArrayOrCollection = true;
}

#if DEBUG
Expand Down Expand Up @@ -327,28 +327,28 @@ protected set
}
#endif

public bool IsParamsCollection
public bool IsParamsArrayOrCollection
{
get
{
return (_attributes & BoundNodeAttributes.ParamsCollection) != 0;
return (_attributes & BoundNodeAttributes.ParamsArrayOrCollection) != 0;
}
protected set
{
Debug.Assert((_attributes & BoundNodeAttributes.ParamsCollection) == 0, $"{nameof(BoundNodeAttributes.ParamsCollection)} flag should not be set twice or reset");
Debug.Assert(value || !IsParamsCollection);
Debug.Assert((_attributes & BoundNodeAttributes.ParamsArrayOrCollection) == 0, $"{nameof(BoundNodeAttributes.ParamsArrayOrCollection)} flag should not be set twice or reset");
Debug.Assert(value || !IsParamsArrayOrCollection);
Debug.Assert(!value ||
this is BoundArrayCreation { Bounds: [BoundLiteral { WasCompilerGenerated: true }], InitializerOpt: BoundArrayInitialization { WasCompilerGenerated: true }, WasCompilerGenerated: true } or
BoundUnconvertedCollectionExpression { WasCompilerGenerated: true } or
BoundCollectionExpression { WasCompilerGenerated: true, UnconvertedCollectionExpression.IsParamsCollection: true } or
BoundConversion { Operand: BoundCollectionExpression { IsParamsCollection: true } });
BoundCollectionExpression { WasCompilerGenerated: true, UnconvertedCollectionExpression.IsParamsArrayOrCollection: true } or
BoundConversion { Operand: BoundCollectionExpression { IsParamsArrayOrCollection: true } });
Debug.Assert(!value ||
this is not BoundUnconvertedCollectionExpression collection ||
ImmutableArray<BoundNode>.CastUp(collection.Elements.CastArray<BoundExpression>()) == collection.Elements);

if (value)
{
_attributes |= BoundNodeAttributes.ParamsCollection;
_attributes |= BoundNodeAttributes.ParamsArrayOrCollection;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void Verify(ImmutableDictionary<BoundExpression, (NullabilityInfo

private void VerifyExpression(BoundExpression expression, bool overrideSkippedExpression = false)
{
if (expression.IsParamsCollection)
if (expression.IsParamsArrayOrCollection)
{
// Params collections are processed element wise.
Debug.Assert(!_analyzedNullabilityMap.ContainsKey(expression), $"Found unexpected {expression} `{expression.Syntax}` in the map.");
Expand Down Expand Up @@ -100,7 +100,7 @@ private void VerifyExpression(BoundExpression expression, bool overrideSkippedEx

public override BoundNode? VisitArrayCreation(BoundArrayCreation node)
{
if (node.IsParamsCollection)
if (node.IsParamsArrayOrCollection)
{
// Synthesized params array is processed element wise.
this.Visit(node.InitializerOpt);
Expand All @@ -112,7 +112,7 @@ private void VerifyExpression(BoundExpression expression, bool overrideSkippedEx

public override BoundNode? VisitCollectionExpression(BoundCollectionExpression node)
{
if (node.IsParamsCollection)
if (node.IsParamsArrayOrCollection)
{
// Synthesized params collection is processed element wise.
this.VisitList(node.UnconvertedCollectionExpression.Elements);
Expand Down Expand Up @@ -322,7 +322,7 @@ private void VisitBinaryOperatorChildren(BoundBinaryOperatorBase node)
{
Visit(node.Operand.GetInterpolatedStringHandlerData().Construction);
}
else if (node.IsParamsCollection)
else if (node.IsParamsArrayOrCollection)
{
// Synthesized params collection is processed element wise.
this.Visit(node.Operand);
Expand Down
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6605,7 +6605,7 @@ private ImmutableArray<VisitResult> VisitArguments(
}
else
{
Debug.Assert(!arguments.Any(a => a.IsParamsCollection));
Debug.Assert(!arguments.Any(a => a.IsParamsArrayOrCollection));
}

(ImmutableArray<BoundExpression> argumentsNoConversions, ImmutableArray<Conversion> conversions) = RemoveArgumentConversions(arguments, refKindsOpt);
Expand Down Expand Up @@ -6817,12 +6817,12 @@ static void expandParamsCollection(ref ImmutableArray<BoundExpression> arguments
// At the moment, there is only one test that gets here like that - Microsoft.CodeAnalysis.CSharp.UnitTests.AttributeTests.TestBadParamsCtor.
// And we get here for the erroneous attribute application, constructor is inaccessible.
// Perhaps that shouldn't cancel the default values / params array processing?
Debug.Assert(arguments.Count(a => a.IsParamsCollection) <= 1);
Debug.Assert(arguments.Count(a => a.IsParamsArrayOrCollection) <= 1);

for (int a = 0; a < arguments.Length; ++a)
{
BoundExpression argument = arguments[a];
if (argument.IsParamsCollection)
if (argument.IsParamsArrayOrCollection)
{
Debug.Assert(parametersOpt.IsDefault || arguments.Length == parametersOpt.Length);
ImmutableArray<BoundExpression> elements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ private ImmutableArray<BoundExpression> MakeArguments(
BoundExpression? optimized;

Debug.Assert(expanded ? rewrittenArguments.Length == parameters.Length : rewrittenArguments.Length >= parameters.Length);
Debug.Assert(rewrittenArguments.Count(a => a.IsParamsCollection) <= (expanded ? 1 : 0));
Debug.Assert(rewrittenArguments.Count(a => a.IsParamsArrayOrCollection) <= (expanded ? 1 : 0));

if (CanSkipRewriting(rewrittenArguments, methodOrIndexer, argsToParamsOpt, invokedAsExtensionMethod, false, out var isComReceiver))
{
Expand Down Expand Up @@ -1104,7 +1104,7 @@ private ImmutableArray<BoundExpression> MakeArguments(

private bool TryOptimizeParamsArray(BoundExpression possibleParamsArray, [NotNullWhen(true)] out BoundExpression? optimized)
{
if (possibleParamsArray.IsParamsCollection && !_inExpressionLambda && ((BoundArrayCreation)possibleParamsArray).Bounds is [BoundLiteral { ConstantValueOpt.Value: 0 }])
if (possibleParamsArray.IsParamsArrayOrCollection && !_inExpressionLambda && ((BoundArrayCreation)possibleParamsArray).Bounds is [BoundLiteral { ConstantValueOpt.Value: 0 }])
{
optimized = CreateArrayEmptyCallIfAvailable(possibleParamsArray.Syntax, ((ArrayTypeSymbol)possibleParamsArray.Type!).ElementType);
if (optimized is { })
Expand Down Expand Up @@ -1230,7 +1230,7 @@ private static ImmutableArray<RefKind> GetRefKindsOrNull(ArrayBuilder<RefKind> r
private delegate BoundExpression ParamsArrayElementRewriter<TArg>(BoundExpression element, ref TArg arg);
private static BoundExpression RewriteParamsArray<TArg>(BoundExpression paramsArray, ParamsArrayElementRewriter<TArg> elementRewriter, ref TArg arg)
{
Debug.Assert(paramsArray.IsParamsCollection);
Debug.Assert(paramsArray.IsParamsArrayOrCollection);

if (paramsArray is BoundArrayCreation { Bounds: [BoundLiteral] bounds, InitializerOpt: BoundArrayInitialization { Initializers: var elements } initialization } creation)
{
Expand Down Expand Up @@ -1287,7 +1287,7 @@ private void BuildStoresToTemps(
Debug.Assert(refKinds.Count == arguments.Length);
Debug.Assert(storesToTemps.Count == 0);
Debug.Assert(rewrittenArguments.Length == parameters.Length);
Debug.Assert(rewrittenArguments.Count(a => a.IsParamsCollection) <= (expanded ? 1 : 0));
Debug.Assert(rewrittenArguments.Count(a => a.IsParamsArrayOrCollection) <= (expanded ? 1 : 0));

for (int a = 0; a < rewrittenArguments.Length; ++a)
{
Expand All @@ -1298,7 +1298,7 @@ private void BuildStoresToTemps(

Debug.Assert(arguments[p] == null);

if (argument.IsParamsCollection)
if (argument.IsParamsArrayOrCollection)
{
Debug.Assert(expanded);
Debug.Assert(p == parameters.Length - 1);
Expand All @@ -1321,7 +1321,7 @@ private void BuildStoresToTemps(
arg.rewriter.StoreArgumentToTempIfNecessary(arg.forceLambdaSpilling, arg.storesToTemps, element, RefKind.None, RefKind.None),
ref arg);

Debug.Assert(arguments[p].IsParamsCollection);
Debug.Assert(arguments[p].IsParamsArrayOrCollection);
}

continue;
Expand Down Expand Up @@ -1482,7 +1482,7 @@ private static int MergeArgumentsAndSideEffects(
{
var argument = arguments[a];

if (argument.IsParamsCollection)
if (argument.IsParamsArrayOrCollection)
{
(ArrayBuilder<BoundAssignmentOperator> tempStores, int tempsRemainedInUse, int firstUnclaimedStore) arg = (tempStores, tempsRemainedInUse, firstUnclaimedStore);
arguments[a] = RewriteParamsArray(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private BoundIndexerAccess TransformIndexerAccessContinued(
refKinds,
storesToTemps);

if (expanded && actualArguments[actualArguments.Length - 1] is { IsParamsCollection: true } array)
if (expanded && actualArguments[actualArguments.Length - 1] is { IsParamsArrayOrCollection: true } array)
{
Debug.Assert(array is BoundArrayCreation);

Expand Down
Loading

0 comments on commit 8085621

Please sign in to comment.