You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ImportPSModule on InitialSessionState should be params. #6005
Committee-ReviewedPS-Committee has reviewed this and made a decisionResolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtime
Yeah. I meant more for the sake of developers. Regardless of the number of times PowerShell 6 calls it, writing an app which hosts PowerShell needs to explicitly new up a string[], which is not syntactically preferred.
FWIW, I believe adding params is a breaking change if you don't recompile your code - you could end up with a missing method exception. This might be a non-issue as there are so few hosts that this might affect.
A better change that might be sufficient is to add some overloads that take 1, 2, or 3 parameters. These overloads would avoid creating an array and cover the most common cases.
That line will still compile with params. How often do developers upgrade their packages and not recompile? Also, I would need to look at the IL, but my impression was that adding params would not change the signature of the method: it would simply allow the caller to use the syntactic sugar. In the end, only the caller needs to take params into account when using the syntactic sugar call: in the case of a method that already news up an
It is totally cool to make methods that take 1, 2, or 3 parameters, but that only solves part of the problem, as their may be developers that need more. The BCL does this by providing methods with 1, 2, or 3 parameters, and then a fourth overload that takes a params as its fourth parameter.
@PowerShell/powershell-committee reviewed this. We believe this is the right change and we should look at all the other public apis to see if this is applicable elsewhere. It doesn't appear to be a breaking change based on the discussion.
Committee-ReviewedPS-Committee has reviewed this and made a decisionResolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtime
Activity
iSazonov commentedon Jan 24, 2018
It seems we get extra allocation.
/cc Jason Shirk (@lzybkr) Dongbo Wang (@daxian-dbw)
twitchax commentedon Jan 24, 2018
Ilya (@iSazonov), what do you mean you get extra allocation?
iSazonov commentedon Jan 24, 2018
In both cases we do
new string[]. Although it is so critical - we call this method rarely.twitchax commentedon Jan 24, 2018
Yeah. I meant more for the sake of developers. Regardless of the number of times PowerShell 6 calls it, writing an app which hosts PowerShell needs to explicitly new up a
string[], which is not syntactically preferred.lzybkr commentedon Jan 24, 2018
FWIW, I believe adding
paramsis a breaking change if you don't recompile your code - you could end up with a missing method exception. This might be a non-issue as there are so few hosts that this might affect.A better change that might be sufficient is to add some overloads that take 1, 2, or 3 parameters. These overloads would avoid creating an array and cover the most common cases.
twitchax commentedon Jan 24, 2018
How is adding
paramsa breaking change?Any caller will have to do
That line will still compile with
params. How often do developers upgrade their packages and not recompile? Also, I would need to look at the IL, but my impression was that addingparamswould not change the signature of the method: it would simply allow the caller to use the syntactic sugar. In the end, only the caller needs to takeparamsinto account when using the syntactic sugar call: in the case of a method that already news up anIt is totally cool to make methods that take 1, 2, or 3 parameters, but that only solves part of the problem, as their may be developers that need more. The BCL does this by providing methods with 1, 2, or 3 parameters, and then a fourth overload that takes a
paramsas its fourth parameter.twitchax commentedon Jan 24, 2018
Actually, it looks like the IL method signature is the same...there is just an attribute applied for syntactic purposes (I would guess).
goes to
And with
params, thisgoes to
So, even if a developer did not rebuild against new binaries with
params, it should still work exactly the same.lzybkr commentedon Jan 24, 2018
I'm assuming that the callsig in the reference will look different because of the attribute on the parameter.
For example, C++/CLI uses an attribute to distinguish between
intandlongwhen they map to the same CLI type.twitchax commentedon Jan 25, 2018
It seems to work fine. I just tried this scenario, and the call works fine, even if you do not rebuild after a dependency updates to use
params.twitchax commentedon Jan 25, 2018
This change is obviously not required, it is just normally expected that methods like this take
paramssince it just makes life easier for developers.lzybkr commentedon Jan 25, 2018
Thanks for checking, my memory was fuzzy. I might have been remembering modopt/modreq which is on the signature, not on the references.
iSazonov commentedon Jan 25, 2018
It is public API - we should PowerShell Committee conclusion.
/cc Steve Lee (@SteveL-MSFT)
powercode commentedon Jan 25, 2018
Maybe not on topic, but related:
Is is possible to filter the imported commands when adding a module to the
InitialSessionState?Like we have on
Import-Modulewith for example-Cmdlet?Otherwise I'd like an overload on
ImportPSModulewith filtering options.iSazonov commentedon Jan 25, 2018
Internally we use
Import-Modulecmdlet to import a module inInitialSessionState.SteveL-MSFT commentedon Feb 21, 2018
@PowerShell/powershell-committee reviewed this. We believe this is the right change and we should look at all the other public apis to see if this is applicable elsewhere. It doesn't appear to be a breaking change based on the discussion.
iSazonov commentedon Feb 22, 2018
I found only
public static void RemoveKeyHandler(string[] key)andpublic static int Main(string[] args). The first has still another overload. So I believe there's nothing more to fix.