Params side of the design changes around Add methods#72771
Params side of the design changes around Add methods#72771AlekseyTs merged 7 commits intodotnet:features/CollectionAddfrom
Conversation
dc3e2b1 to
6b30a4f
Compare
| } | ||
|
|
||
| return parameters[paramNum].TypeWithAnnotations; | ||
| BoundExpression bindInterpolatedStringHandlerInMemberCall( |
| return (builderAppendCallsArray.ToImmutableAndFree(), builderPatternExpectsBool ?? false, positionInfoArray.ToImmutableAndFree(), baseStringLength, numFormatHoles); | ||
| } | ||
|
|
||
| private BoundExpression BindInterpolatedStringHandlerInMemberCall( |
There was a problem hiding this comment.
I would have a slight leaning towards keeping this where it is. I won't block on it, but I did put this here intentionally, rather than making it a local function in CoerceArguments, because I wanted to keep all the interpolation logic together.
There was a problem hiding this comment.
I would have a slight leaning towards keeping this where it is. I won't block on it, but I did put this here intentionally, rather than making it a local function in CoerceArguments, because I wanted to keep all the interpolation logic together.
The primary reason for the move is to constrain access to MemberAnalysisResult,.ArgsToParamsOpt to as few helpers that anyone can call in the future as possible. I was able make other helper(s) local functions, I wouldn't be able otherwise. I find that more important than a desire to keep interpolation logic in a separate file.
| BoundExpression bindInterpolatedStringHandlerInMemberCall( | ||
| BoundExpression unconvertedString, | ||
| TypeSymbol handlerType, | ||
| ArrayBuilder<BoundExpression>? arguments, |
| diagnostics); | ||
| } | ||
|
|
||
| Debug.Assert(arguments is not null); |
| Debug.Assert(paramsArgsBuilder.Count == 0); | ||
|
|
||
| firstParamsArgument = i; | ||
| paramsArgsBuilder.Add(argumentsBuilder[i]); |
| return coercedArgument; | ||
| } | ||
|
|
||
| ArrayBuilder<BoundExpression> collectParamsArgs( |
| ImmutableArray<BoundExpression> collectionArgs = paramsArgsBuilder.ToImmutableAndFree(); | ||
| int collectionArgsLength = collectionArgs.Length; | ||
|
|
||
| TypeSymbol collectionType = parameters[paramsIndex].Type; |
There was a problem hiding this comment.
|
|
||
| } | ||
|
|
||
| private BoundExpression CreateParamsCollection(SyntaxNode node, ParameterSymbol paramsParameter, ImmutableArray<BoundExpression> collectionArgs, BindingDiagnosticBag diagnostics) |
| Debug.Assert(!haveDefaultArguments || collectionArgsLength == 1); | ||
| Debug.Assert(collectionArgsLength == 1 || firstParamsArgument + collectionArgsLength == argumentsBuilder.Count); | ||
|
|
||
| for (var i = firstParamsArgument + collectionArgsLength - 1; i != firstParamsArgument; i--) |
| argsToParamsBuilder.AddRange(argsToParamsOpt); | ||
| } | ||
|
|
||
| for (var i = firstParamsArgument + collectionArgs.Length - 1; i != firstParamsArgument; i--) |
|
@cston, @RikkiGibson, @333fred Please review |
| return coercedArgument; | ||
| } | ||
|
|
||
| ArrayBuilder<BoundExpression> collectParamsArgs( |
There was a problem hiding this comment.
Can this local function be
static?
Yes, changing.
| (BoundKind.OutVariablePendingInference or BoundKind.OutDeconstructVarPendingInference or BoundKind.DiscardExpression or BoundKind.ArgListOperator)); | ||
|
|
||
| // Conversions to elements of collection are applied in the process of collection construction | ||
| paramsArgsBuilder.Add(arguments[arg]); |
There was a problem hiding this comment.
Consider extracting a local function for use here and inside the while loop. #Resolved
There was a problem hiding this comment.
Consider extracting a local function for use here and inside the
whileloop.
Are you referring to paramsArgsBuilder.Add(arguments[arg]);? If so, I do not believe it is worth the trouble. There isn't enough "critical mass" in combined complexity and volume to gain much from sharing. A call would look as complicated as the current code, in my opinion.
There was a problem hiding this comment.
After a closer look, I ended up refactoring the loop and avoiding the duplication.
| } | ||
|
|
||
| // Note, this function is going to free paramsArgsBuilder | ||
| void createParamsCollection( |
There was a problem hiding this comment.
coerceArgument cannot be static, this disallows createParamsCollection to be static.
333fred
left a comment
There was a problem hiding this comment.
Nothing blocking, so I'm signing off.
| } | ||
|
|
||
| /// <summary> | ||
| /// A bit vector representing whose true bits indicate indices of bad arguments |
There was a problem hiding this comment.
| /// A bit vector representing whose true bits indicate indices of bad arguments | |
| /// A bit vector whose true bits indicate indices of bad arguments | |
| ``` #WontFix |
There was a problem hiding this comment.
The comment was copied from below. I have no intent fixing it in this PR. Feel free to fix both comments after the PR is merged.
|
|
||
| var isExpanded = resolutionResult.Result.Kind == MemberResolutionKind.ApplicableInExpandedForm; | ||
| var argsToParams = resolutionResult.Result.ArgsToParamsOpt; | ||
| ImmutableArray<int> argsToParams; |
There was a problem hiding this comment.
Nit: consider moving this declaration closer to the usage, or inline. #Resolved
| return (builderAppendCallsArray.ToImmutableAndFree(), builderPatternExpectsBool ?? false, positionInfoArray.ToImmutableAndFree(), baseStringLength, numFormatHoles); | ||
| } | ||
|
|
||
| private BoundExpression BindInterpolatedStringHandlerInMemberCall( |
There was a problem hiding this comment.
I would have a slight leaning towards keeping this where it is. I won't block on it, but I did put this here intentionally, rather than making it a local function in CoerceArguments, because I wanted to keep all the interpolation logic together.
| Assert.Equal("AAttribute..ctor(params System.Int32[] args)", attributeData.AttributeConstructor.ToTestDisplayString()); | ||
| Assert.Equal(1, attributeData.AttributeConstructor.ParameterCount); | ||
| Assert.Equal(new object[] { 1, 2, 3 }, attributeData.ConstructorArguments.Select(arg => arg.Value)); | ||
| Assert.Equal(TypedConstantKind.Array, attributeData.ConstructorArguments.Single().Kind); |
There was a problem hiding this comment.
Is this a meaningful change to the public API behavior for
AttributeData.ConstructorArguments?
Yes. In some error conditions we are actually manage to create an array. The behavior is close to the success case now, see the other test I modified in this file
The main observable change - the original (unconverted) params arguments are used in the process of populating target collection.
Spec changes: dotnet/csharplang#8022
Fixes #72098