X Tutup
The Wayback Machine - https://web.archive.org/web/20220518161355/https://github.com/PowerShell/PowerShell/pull/16963
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

Improve type inference and completions #16963

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MartinGC94
Copy link
Contributor

@MartinGC94 MartinGC94 commented Mar 6, 2022

PR Summary

Fixes #15811
Fixes #9949
Fixes #11803
Fixes #15885
Fixes #17257

Improves the type inference in the following scenarios:

  1. Index access on an Ilist like [System.Collections.Generic.IList[System.Text.StringBuilder]]$null)[0]
  2. "as" operator like ($var -as [ICloneable]) (Note it only works with type literals, it still doesn't work with other expression types)
  3. $_ inside method invocations that use a scriptblock, like the magic foreach/where methods: (0..10).ForEach{$_}

Improves tab completion in the following ways:

  1. Allow methods to be shown in completion results for ForEach-Object -MemberName
  2. Prevents completion on expressions that return void like ([void]("")).
  3. Allow non-default Class constructors to show up when class completion is based on the AST
  4. Update the tooltip to show multiple overloads for methods when completing class methods from the AST

Fixes a failed assertion due to a missing null check.

PR Context

PR Checklist

@MartinGC94
Copy link
Contributor Author

@MartinGC94 MartinGC94 commented Mar 6, 2022

The Cannot convert the "ns_70262529219d4bdfa518523ef9b4fae9.E_sbyte" value of type "System.String" to type "System.Type". error seems like a random error. It doesn't happen on my system when I test it.
The Tab expansion in constrained language mode.Verifies that tab expansion cannot convert disallowed IntPtr type test failure is related to my changes but only because it's relying on the type inference not working properly for "as" statements.
I don't know how to fix that test so it still tests against disallowed conversions in constrained language mode so some assistance would be nice.

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Mar 7, 2022

It doesn't happen on my system when I test it.

If it is persistent on CI you can temporary add test code (in tests or Engine itself) :-)

@MartinGC94 MartinGC94 closed this Mar 7, 2022
@MartinGC94 MartinGC94 reopened this Mar 7, 2022
@MartinGC94
Copy link
Contributor Author

@MartinGC94 MartinGC94 commented Mar 7, 2022

Looks like I was right about that test but now a different unrelated test is failing...

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Mar 9, 2022

Looks like I was right about that test but now a different unrelated test is failing...

But the test doesn't fail on other PRs or daily builds.

@MartinGC94 MartinGC94 closed this Mar 9, 2022
@MartinGC94 MartinGC94 reopened this Mar 9, 2022
@pull-request-quantifier
Copy link

@pull-request-quantifier pull-request-quantifier bot commented Mar 9, 2022

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


Quantification details

Label      : Medium
Size       : +90 -31
Percentile : 44.2%

Total files changed: 5

Change summary by file extension:
.cs : +67 -31
.ps1 : +23 -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? 👍  👌  👎 (Email)
Customize PullRequestQuantifier for this repository.

@MartinGC94
Copy link
Contributor Author

@MartinGC94 MartinGC94 commented Mar 9, 2022

These are the 3 runs I've had on this PR:

  1. https://dev.azure.com/powershell/PowerShell/_build/results?buildId=95571&view=ms.vss-test-web.build-test-results-tab
  2. https://dev.azure.com/powershell/PowerShell/_build/results?buildId=95594&view=ms.vss-test-web.build-test-results-tab
  3. https://dev.azure.com/powershell/PowerShell/_build/results?buildId=95659&view=ms.vss-test-web.build-test-results-tab

First run had the Enum out of range error due to bad RNG luck. The next 2 runs replaced that error with a different error Clean up open Runspaces when exit powershell process.PowerShell process should not freeze at exit. I've seen that error show up in some of my other PRs so I know it's unstable but even if we assume it's my code, why wouldn't it fail the first time?

The tabexpansion error that is there in all 3 runs is perfectly legit but like I said earlier it only exists because the test is designed around type inference not working. We need a different test to test if the completion code is correctly blocked from doing conversions.

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Mar 10, 2022

Yes, I see the same errors in other PRs.

@msftbot msftbot bot added the Review - Needed label Mar 18, 2022
@msftbot
Copy link

@msftbot msftbot bot commented Mar 18, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Medium Review - Needed
Projects
None yet
3 participants
X Tutup