-
Notifications
You must be signed in to change notification settings - Fork 8.1k
WIP: Add ProgressPreference to SpecialVariables var and type arrays #24571
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
Conversation
@microsoft-github-policy-service agree |
iSazonov
left a comment
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 finding and patching the issue.
I suggest to discuss replacing Progress = 16, with Progress = 8, in internal enum PreferenceVariable for performance reason (with the PR the tuple size jumps from 16 to 32).
| } | ||
|
|
||
| Context "ProgressAction" { | ||
| It "Silences with no parameters/variables" { |
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.
Please reword tests names. "Silence" is not explain that test checks.
If I understand correctly, the enum value must be unique within the combination of both internal enum AutomaticVariable
{
Underbar = 0,
Args = 1,
This = 2,
Input = 3,
PSCmdlet = 4,
PSBoundParameters = 5,
MyInvocation = 6,
PSScriptRoot = 7,
PSCommandPath = 8,
NumberOfAutomaticVariables // 1 + the last, used to initialize global scope.
}
internal enum PreferenceVariable
{
Debug = 9,
Verbose = 10,
Error = 11,
WhatIf = 12,
Warning = 13,
Information = 14,
Confirm = 15,
Progress = 16,
} |
Yes, I see. Could you please add new Assert like in line 718 for If we can not use value less 16 we will allocate double size tuples so we have to think about whether we need to fix the performance issue and how. |
While we should think about this the damage is already done by accepting and implementing the new parameter in 7.4 . We should fix this issue first then investigate the performance side after not hold off a bugfix for a problem today. |
What is this in reference to? Neither of the changed files are above 500 lines; searching for 'Assert' in either returned no results for me. |
Ah, sorry! PowerShell/src/System.Management.Automation/engine/parser/VariableAnalysis.cs Lines 718 to 721 in c2f1ff0
Currently we haven't the performance issue because the feature doesn't work. We should either revert #18887 or fix without any (perf) regression. |
It works just fine for binary cmdlets, it’s advanced functions where it fails and this fixes. We only loose out on the size 16 tuple if the function didn’t have any paramaters or variables (or was un-optimisable). I would say the vast majority of advanced functions will have at least one parameter or one variable making it go beyond 16 in even without this addition. |
Are you looking for something like this (@iSazonov)? Asserts that the enums match the associated array names/types lengths. Diagnostics.Assert(AutomaticVariable.NumberOfAutomaticVariables == SpecialVariables.AutomaticVariables.Length
&& AutomaticVariable.NumberOfAutomaticVariables == SpecialVariables.AutomaticVariableTypes.Length,
"automatic variable enum length does not match both automatic variable and automatic variable types length.");
Diagnostics.Assert(SpecialVariables.PreferenceVariable.Length == SpecialVariables.PreferenceVariables.Length
&& SpecialVariables.PreferenceVariable.Length == SpecialVariables.PreferenceVariableTypes.Length,
"preference variable enum length does not match both preference variable and preference variable types length."). |
Yes. We should add check for types you change in the PR. Have you checked the existing assert in DEBUG mode? I guess it will throw now. |
The debug statements Do not throw as they are just checking that the slots used for the automatic vars and action preferences match up together. In this case the enum wasn't populated with the progress preference var so the slots still match up with what was in the enum. If we wanted to add a debug assertion we could potentially do add something to the below which somehow checks the enums defined here. I don't know off a good check for this off the top of my head though. PowerShell/src/System.Management.Automation/engine/parser/VariableAnalysis.cs Lines 154 to 159 in c2f1ff0
|
If the second debug statement I proposed existed in the current codebase (pre-merge), it should have thrown, if I understand correctly. Edit: accidentally copied the same section twice 🙃 // Enum, length of 8
internal enum PreferenceVariable
{
Debug = 9,
Verbose = 10,
Error = 11,
WhatIf = 12,
Warning = 13,
Information = 14,
Confirm = 15,
Progress = 16,
};
// Array of preference values, length of 7
internal static readonly string[] PreferenceVariables =
{
SpecialVariables.DebugPreference,
SpecialVariables.VerbosePreference,
SpecialVariables.ErrorActionPreference,
SpecialVariables.WhatIfPreference,
SpecialVariables.WarningPreference,
SpecialVariables.InformationPreference,
SpecialVariables.ConfirmPreference,
};
// Array of preference variable types, length of 7
internal static readonly Type[] PreferenceVariableTypes =
{
/* DebugPreference */ typeof(ActionPreference),
/* VerbosePreference */ typeof(ActionPreference),
/* ErrorPreference */ typeof(ActionPreference),
/* WhatIfPreference */ typeof(SwitchParameter),
/* WarningPreference */ typeof(ActionPreference),
/* InformationPreference */ typeof(ActionPreference),
/* ConfirmPreference */ typeof(ConfirmImpact),
};
// Debug assert, effectively becomes "Assert 8 == 7 && 8 == 7"
Diagnostics.Assert(SpecialVariables.PreferenceVariable.Length == SpecialVariables.PreferenceVariables.Length
&& SpecialVariables.PreferenceVariable.Length == SpecialVariables.PreferenceVariableTypes.Length,
"preference variable enum length does not match both preference variable and preference variable types length."). |
|
Ah my apologies I misread things. |
Add assertion to prevent automatic or preference variable enums from being misaligned with their associated string and type arrays
…rite-Progress inside to verify no output
Add assertion to prevent automatic or preference variable enums from being misaligned with their associated string and type arrays
|
@cmkb3 I wonder why do you change nuget configs? Do you use |
…erShell into ProgressPreference_Fix
Yes, I'm a git idiot and accidentally pushed those configs when trying to not do that. Tried to undo it and I've only made it worse so far, I'm afraid 😩 |
|
@cmkb3 You can close the PR and open new one with clean commit. |
|
📣 Hey @cmkb3, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
PR Summary
This fixes an array out of bounds/type error that occurs when using the -ProgressAction common parameter in advanced functions. The reference variable and variable type arrays are missing the ProgressPreference entry which causes various engine errors including index out of bounds and invalid typecast from index collision.
PR Context
Fixes: #21074 'The -ProgressAction parameter doesn't work (PowerShell 7.4.1 only)'
Fixes: #20657 'The new -ProgressAction common parameter breaks calls to advanced scripts and functions. '
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.- [ ] Issue filed:
(which runs in a different PS Host).