Skip to content

Create params arrays during binding#70762

Merged
AlekseyTs merged 3 commits intodotnet:mainfrom
AlekseyTs:Issue49602
Nov 14, 2023
Merged

Create params arrays during binding#70762
AlekseyTs merged 3 commits intodotnet:mainfrom
AlekseyTs:Issue49602

Conversation

@AlekseyTs
Copy link
Copy Markdown
Contributor

Closes #49602.

@AlekseyTs AlekseyTs requested a review from a team as a code owner November 10, 2023 15:45
@ghost ghost added the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 10, 2023
@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler Please review.

1 similar comment
@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler Please review.

@RikkiGibson RikkiGibson self-assigned this Nov 13, 2023
{
internal partial class BoundArrayCreation
{
public new bool IsParamsArray
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the effect of declaring a 'new' member in this type versus using the member in the base type? #Resolved

Copy link
Copy Markdown
Contributor Author

@AlekseyTs AlekseyTs Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the effect of declaring a 'new' member in this type versus using the member in the base type?

The setter in the base type is intentionally protect. The new property allows setting it for BoundArrayCreation from outside the type.

// Params methods can be invoked in normal form, so the strongest assertion we can make is that, if
// we're in an expanded context, the last param must be params. The inverse is not necessarily true.
Debug.Assert(!expanded || parameters[^1].IsParams);
// Params array is filled in the local rewriter
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should probably be deleted #Resolved

private ImmutableArray<TypedConstant> GetRewrittenAttributeConstructorArguments(
MethodSymbol attributeConstructor,
ImmutableArray<TypedConstant> constructorArgsArray,
ImmutableArray<string?> constructorArgumentNamesOpt,
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider also deleting the <remarks> for this method. #Resolved

{
reorderedArgument = constructorArgsArray[i];
}
TypedConstant reorderedArgument = reorderedArgument = constructorArgsArray[i];
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we unintentionally assigned twice to this variable. #Resolved

/// arguments based on <paramref name="argsToParamsOpt"/> map, inserting arguments for optional parameters, etc.
/// </summary>
private ImmutableArray<BoundExpression> MakeArguments(
SyntaxNode syntax,
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc comment could also be adjusted to remove "generating a params array". #Resolved

ImmutableArray<ParameterSymbol> parameters = methodOrIndexer.GetParameters();
BoundExpression? optimized;

Debug.Assert(expanded ? rewrittenArguments.Length == parameters.Length : rewrittenArguments.Length >= parameters.Length);
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it only in arglist scenarios where expanded is false and rewrittenArguments.Length > parameters.Length? #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it only in arglist scenarios where expanded ...

I think so.

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler For the second review.

// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
Copy link
Copy Markdown
Member

@jjonescz jjonescz Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unused. #Resolved

}

arrayArgsBuilder.Add(argumentsBuilder[remainingArgument]);
i++;
Copy link
Copy Markdown
Member

@jjonescz jjonescz Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we could use i in this loop directly instead of remainingArgument since we are incrementing it here anyway. #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we could use i in this loop directly instead of remainingArgument since we are incrementing it here anyway.

I do not think so. The i is incremented conditionally.

return default(ImmutableArray<RefKind>);
}

private delegate BoundExpression ParamsArrayElementRewriter<TArg>(BoundExpression element, ref TArg arg);
Copy link
Copy Markdown
Member

@jjonescz jjonescz Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using in for arg instead. #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using in for arg instead.

Ref is intentional, the argument is not read-only.

getEnumeratorInfo = new MethodArgumentInfo(
getEnumeratorInfo.Method,
builder.ToImmutableAndFree(),
defaultArguments: default,
Copy link
Copy Markdown
Member

@jjonescz jjonescz Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we pass getEnumeratorInfo.DefaultArguments here? #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we pass getEnumeratorInfo.DefaultArguments here?

Values in getEnumeratorInfo.DefaultArguments are obsolete since it is a map for the original argument list and we mutated it. We could, of course, adjust the map as well, but it will be a throw away effort because the map is not used for lowering, the arguments are already in place.

@AlekseyTs AlekseyTs merged commit 31bb536 into dotnet:main Nov 14, 2023
@ghost ghost added this to the Next milestone Nov 14, 2023
@RikkiGibson RikkiGibson modified the milestones: Next, 17.9 P2 Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Params arrays should be created during binding

3 participants