Skip to content
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

Feature / Architecture Discussion: Optional and Named arguments #1083

Closed
siegfriedpammer opened this issue Mar 5, 2018 · 2 comments
Closed

Comments

@siegfriedpammer
Copy link
Member

siegfriedpammer commented Mar 5, 2018

Language Feature(s):

  • C# 4.0 optional arguments
  • C# 4.0 named arguments
  • C# 7.2 non-trailing named arguments

These features should be implemented in one go, because they depend on each other.

Affected areas:

  • ILAst
  • ILInlining
  • CallBuilder

1) Optional Arguments:

Optional values can only be: ldnull, ldstr, ldc.*, default.value

  1. CallBuilder: Remove optional arguments, if overload resolution allows it.

2) Named Arguments:

CallInstruction currently does not distinguish between the argument evaluation order, and the parameter order. The CallInstruction.Arguments collection must be in evaluation order. But we can extend CallInstruction to allow more flexible mapping of arguments to parameters.

  1. Extend CallInstruction: Add int[] argumentToParameterMap. For each argument index, this would specify the corresponding parameter index in the method's parameter collection.
    • The this parameter (which isn't present in the method's parameter collection) could be represented as -1. It must remain argument 0.
    • CallInstruction.CheckInvariant should check that the mapping between arguments and parameters is 1-to-1.
    • All code that deals with call arguments+parameters will need adjustment!
  2. Add some ILAst transform that reorders both the call arguments and adjusts the argumentToParameterMap in order to open up new inlining possibilities (maybe as extension to ILInlining? or as a new StatementTransform?)
  3. CallBuilder: use named arguments when argument order differs from parameter order
    • When using named arguments, emit NamedArgumentExpression
    • Also report the argument names to the resolver.

3) Non-trailing Named Arguments:

  1. CallBuilder: Add NamedArgumentExpression for any constants

Related:

  • Support for nameof in well-known cases (Exception ctors, CallerMemberNameAttribute)
  • CallerMemberNameAttribute: Remove ldstr arguments if optional and value == CurrentMember.Name
pentp pushed a commit to pentp/ILSpy that referenced this issue Mar 10, 2018
siegfriedpammer added a commit that referenced this issue May 23, 2018
… call arguments are now prefixed with the parameter index they correspond to, if the mapping is different from the default.
dgrunwald added a commit that referenced this issue Jun 1, 2018
…t output call arguments are now prefixed with the parameter index they correspond to, if the mapping is different from the default."

This reverts commit 60ace84.
@dgrunwald
Copy link
Member

"2) Named Arguments" is now implemented.
3) would be easy to do now.

  1. will first require some refactoring of the CallBuilder...

@siegfriedpammer
Copy link
Member Author

Optional arguments are implemented as of 4776331

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants