Skip to content

Conversation

@vexx32
Copy link
Collaborator

@vexx32 vexx32 commented Apr 21, 2020

PR Summary

Adds support for specifying type arguments for generic methods.

For example:

[Array]::Empty[int]()
$dictionary = [System.Collections.Concurrent.ConcurrentDictionary[string, int]]::new()
$dictionary.AddOrUpdate[float]($Key, $addEntryScript, $updateEntryScript, $FloatValue)

Many thanks to @dlwyatt for the initial parsing implementation! 😊 💖

PR Context

Resolves #5146

/cc @lzybkr @daxian-dbw

/cc @TylerLeonhardt would this necessitate an update to language spec like the dispose{} one did?
This may affect tools not using an actual PS parser, but in general I think the impact will be minor overall, likely requiring some updates to any regex recognition patterns for some syntax highlighting rules.

PR Checklist

@TylerLeonhardt
Copy link
Member

This may affect tools not using an actual PS parser, but in general I think the impact will be minor overall, likely requiring some updates to any regex recognition patterns for some syntax highlighting rules.

Yeah this will possibly need a change to EditorSyntax.

@iSazonov
Copy link
Collaborator

@vexx32 There are many formatting and style issue. Please fix issues for changed code and move unrelated ones to another PR (I mean specially build.psm1 and some in other code). It will very help reviewers!

@vexx32
Copy link
Collaborator Author

vexx32 commented Apr 22, 2020

@iSazonov ah, you're right. I'll have to do a bit of a rebase to clear that up, give me a few moments. I think a lot of those came from Dave's original code here, so I'll pare out what's needed and drop the unrelated style changes. Thanks! 💖

@vexx32
Copy link
Collaborator Author

vexx32 commented Apr 22, 2020

@iSazonov that should do it. Time for bed. 😁

@TravisEz13
Copy link
Member

@rjmholt Can you review?

@rjmholt rjmholt self-requested a review April 30, 2020 19:04
@ghost ghost added the Review - Needed The PR is being reviewed label May 27, 2020
@ghost
Copy link

ghost commented May 27, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Mainainer, Please provide feedback and/or mark it as Waiting on Author

@adityapatwardhan
Copy link
Member

@rjmholt Could you review this please?

@ghost ghost removed the Review - Needed The PR is being reviewed label Jun 1, 2020
@pull-request-quantifier-deprecated

This comment has been minimized.

1 similar comment
@pull-request-quantifier-deprecated

This PR has 472 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Large
Size       : +396 -76
Percentile : 82.4%

Total files changed: 9

Change summary by file extension:
.cs : +250 -76
.resx : +6 -0
.ps1 : +140 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detetcted.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

Copy link
Collaborator Author

@vexx32 vexx32 left a comment

Choose a reason for hiding this comment

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

Had a quick look over your edits and they look good to me, thanks for helping sort those out!

Also pushed a commit adding some tests for the tab completion, modelled after the existing tab completion tests for normal type token completions.

@IISResetMe
Copy link
Collaborator

IISResetMe commented Jan 27, 2022

I realize this question is probably beyond the scope of this PR, but I feel it's still relevant:

Does it make sense to attempt coercion of enumerables passed as arguments to method parameters constrained by generic type parameters when overload resolution is not otherwise ambiguous?

Take the following example:

$linq = [System.Linq.IEnumerable]

# this fails because [object[]] doesn't implement [IEnumerable[int]] (not because of ambiguous overload resolution)
$linq::Distinct[int](@(1,2,3,1,2,3))

# this succeeds
$linq::Distinct[int]([int[]]@(1,2,3,1,2,3))

Edit: as soon as I posted this I realized what I'm really asking for is "can we have better coercion semantics for downcasting to interfaces with covariant generic type parameters?" which is sorta orthogonal to this change and should be chased separately, please ignore this :)

@vexx32
Copy link
Collaborator Author

vexx32 commented Jan 27, 2022

@IISResetMe I agree we should have that, and agree it's out of this scope... but I would really love to have that. Because yeah, in some method calls it does feel like casts should not be necessary. Maybe would be good to file a follow up issue with that? I think it'll be easier to manage with the changes from this PR actually defining some of the types needed for the method call, so PS has less to infer from just the arguments.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

LGTM

@andyleejordan
Copy link
Member

We need @andschwa review too (for possible PSES breaking).

What are the concerns around breaking PSES?

@iSazonov
Copy link
Collaborator

We need @andschwa review too (for possible PSES breaking).

What are the concerns around breaking PSES?

Changes in Parser.

@daxian-dbw daxian-dbw merged commit 8c53252 into PowerShell:master Jan 27, 2022
@vexx32 vexx32 deleted the GenericMethods branch January 27, 2022 17:56
@daxian-dbw
Copy link
Member

daxian-dbw commented Jan 27, 2022

Thanks @vexx32 for your contribution!

can we have better coercion semantics for downcasting to interfaces with covariant generic type parameters?

@IISResetMe Feel free to open an issue for discussion about this 😄

@andschwa I guess EditorSyntax would need updates? If so, can you please open an issue tracking that?
@JamesWTruher Not sure how much this would affect PSSA. It would be great if you can help evaluate and open tracking issue as needed.

@daxian-dbw daxian-dbw removed Breaking-Change breaking change that may affect users Review - Maintainer The PR/issue needs a review from the PowerShell repo Maintainers labels Jan 27, 2022
@daxian-dbw
Copy link
Member

Just noticed no documentation issue was filed. @vexx32 can you please open a documentation issue for this feature?

@vexx32
Copy link
Collaborator Author

vexx32 commented Jan 27, 2022

Aye, will do!

EDIT: Doc issue filed: MicrosoftDocs/PowerShell-Docs#8533

@oising
Copy link
Contributor

oising commented Jan 27, 2022

w00000000.

Congrats @vexx32

@kborowinski
Copy link
Contributor

@vexx32 Finally! This is awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Documentation Needed in this repo Documentation is needed in this repo Extra Large WG-Engine core PowerShell engine, interpreter, and runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Ability to invoke generic methods with explicit type parameters when PowerShell cannot figure out <T> from the context