-
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
Params side of the design changes around Add methods #72771
Params side of the design changes around Add methods #72771
Conversation
dc3e2b1
to
6b30a4f
Compare
} | ||
|
||
return parameters[paramNum].TypeWithAnnotations; | ||
BoundExpression bindInterpolatedStringHandlerInMemberCall( |
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.
@@ -873,227 +873,5 @@ private ImmutableArray<BoundExpression> BindInterpolatedStringParts(BoundUnconve | |||
positionInfo.Free(); | |||
return (builderAppendCallsArray.ToImmutableAndFree(), builderPatternExpectsBool ?? false, positionInfoArray.ToImmutableAndFree(), baseStringLength, numFormatHoles); | |||
} | |||
|
|||
private BoundExpression BindInterpolatedStringHandlerInMemberCall( |
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.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
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.
diagnostics); | ||
} | ||
|
||
Debug.Assert(arguments is not null); |
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.
Debug.Assert(paramsArgsBuilder.Count == 0); | ||
|
||
firstParamsArgument = i; | ||
paramsArgsBuilder.Add(argumentsBuilder[i]); |
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.
return coercedArgument; | ||
} | ||
|
||
ArrayBuilder<BoundExpression> collectParamsArgs( |
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.
ImmutableArray<BoundExpression> collectionArgs = paramsArgsBuilder.ToImmutableAndFree(); | ||
int collectionArgsLength = collectionArgs.Length; | ||
|
||
TypeSymbol collectionType = parameters[paramsIndex].Type; |
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.
@@ -1900,6 +1741,116 @@ static int getArgumentIndex(int parameterIndex, ImmutableArray<int> argsToParams | |||
|
|||
} | |||
|
|||
private BoundExpression CreateParamsCollection(SyntaxNode node, ParameterSymbol paramsParameter, ImmutableArray<BoundExpression> collectionArgs, BindingDiagnosticBag diagnostics) |
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.
Debug.Assert(!haveDefaultArguments || collectionArgsLength == 1); | ||
Debug.Assert(collectionArgsLength == 1 || firstParamsArgument + collectionArgsLength == argumentsBuilder.Count); | ||
|
||
for (var i = firstParamsArgument + collectionArgsLength - 1; i != firstParamsArgument; i--) |
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.
argsToParamsBuilder.AddRange(argsToParamsOpt); | ||
} | ||
|
||
for (var i = firstParamsArgument + collectionArgs.Length - 1; i != firstParamsArgument; i--) |
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.
@cston, @RikkiGibson, @333fred Please review |
return coercedArgument; | ||
} | ||
|
||
ArrayBuilder<BoundExpression> collectParamsArgs( |
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.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting a local function for use here and inside the while
loop. #Resolved
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.
Consider extracting a local function for use here and inside the
while
loop.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
coerceArgument
cannot be static, this disallows createParamsCollection
to be static.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -9435,7 +9816,7 @@ private BoundExpression BindIndexedPropertyAccess(SyntaxNode syntax, BoundExpres | |||
PropertySymbol property = resolutionResult.Member; | |||
|
|||
var isExpanded = resolutionResult.Result.Kind == MemberResolutionKind.ApplicableInExpandedForm; | |||
var argsToParams = resolutionResult.Result.ArgsToParamsOpt; | |||
ImmutableArray<int> argsToParams; |
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.
Nit: consider moving this declaration closer to the usage, or inline. #Resolved
@@ -873,227 +873,5 @@ private ImmutableArray<BoundExpression> BindInterpolatedStringParts(BoundUnconve | |||
positionInfo.Free(); | |||
return (builderAppendCallsArray.ToImmutableAndFree(), builderPatternExpectsBool ?? false, positionInfoArray.ToImmutableAndFree(), baseStringLength, numFormatHoles); | |||
} | |||
|
|||
private BoundExpression BindInterpolatedStringHandlerInMemberCall( |
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 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.
@@ -651,7 +651,8 @@ class Program | |||
Assert.True(attributeData.HasErrors); | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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