-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Type inference for Select-Object, Group-Object, PSObject and Hashtable #7231
Conversation
…rred types This reduces allocations and makes the code easier to debug.
da09520
to
b0f840e
Compare
I don't intend to fix the remaining CodeFactor issues. |
Adding the concept of a PSSyntheticTypeName, derived from PSTypeName, that extends it with a list of synthetic members. This allows us to express the inferred type of [pscustomobject] @{ A = 1 B = "2" } as a "PSObject#A:B" and with information about the types of A and B. This is also used to annotate the output of Select-Object -Property Select-Object -ExcludeProperty Select-Object -ExpandProperty Finally, it adds information about the types of the Group and Value properties of the output of Group-Object
Ping |
Sorry for delaying so long. Will review in a day or two. |
@powercode, @daxian-dbw is on vacation |
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.
Sorry for being late on the code review. Left a few comments.
src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs
Outdated
Show resolved
Hide resolved
@daxian-dbw Thanks for your review! Very constructive as usual! |
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.
LGTM. Left two non-blocking comments.
@powercode Thanks for the great contribution, again!
src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/parser/TypeInferenceVisitor.cs
Outdated
Show resolved
Hide 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.
Thanks for addressing the non-blocking comments!
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 are a few little things that we can change later. Otherwise it looks OK to me.
} | ||
} | ||
|
||
private static bool IsPSTypeName(PSMemberNameAndType member) => string.Compare("PSTypeName", member.Name, StringComparison.CurrentCultureIgnoreCase) == 0; |
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.
Why not use string.Equals()
here? It's faster than string.Compare()
.
|
||
foreach (var propertyName in properties) | ||
{ | ||
if (string.Compare(name, propertyName, StringComparison.CurrentCultureIgnoreCase) == 0) |
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.
Again - should use string.Equals()
/// </summary> | ||
/// <param name="name">The name of the type.</param> | ||
/// <param name="type">The real type.</param> | ||
internal PSTypeName(string name, Type 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.
This looks like it should be public but we can do that in a future PR.
return; | ||
if (astParameterArgumentPair is AstPair astPair) | ||
{ | ||
object ToWildCardOrString(string value) => WildcardPattern.ContainsWildcardCharacters(value) ? (object)new WildcardPattern(value) : value; |
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 using PSPropertyExpression - it already handles wildcards in property names.
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.
Maybe even use the ParameterProcessor? So we can handle hashtable arguments also?
I'll leave that to a future PR.
Add Committee review for new public interface |
@PowerShell/powershell-committee reviewed the public constructor for PSTypeName and likes the proposal |
PR Summary
Fixes #7230.
Adding the concept of a PSSyntheticTypeName, derived from PSTypeName,
that extends it with a list of synthetic members.
This allows us to express the inferred type of
as a "PSObject#A:B" and with information about the types of A and B.
This is also used to annotate the output of
Finally, it adds information about the types of the
Group
andValue
properties of the output ofGroup-Object
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
to the beginning of the title and remove the prefix when the PR is ready.[feature]
if the change is significant or affects feature tests]