Type inference for Select-Object, Group-Object, PSObject and Hashtable#7231
Type inference for Select-Object, Group-Object, PSObject and Hashtable#7231TravisEz13 merged 5 commits intoPowerShell:masterfrom
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 |
daxian-dbw
left a comment
There was a problem hiding this comment.
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
|
@daxian-dbw Thanks for your review! Very constructive as usual! |
daxian-dbw
left a comment
There was a problem hiding this comment.
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
daxian-dbw
left a comment
There was a problem hiding this comment.
Thanks for addressing the non-blocking comments!
BrucePay
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
Consider using PSPropertyExpression - it already handles wildcards in property names.
There was a problem hiding this comment.
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
GroupandValueproperties of the output ofGroup-ObjectPR Checklist
.h,.cpp,.cs,.ps1and.psm1files 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]