Skip to content

Conversation

@daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Apr 23, 2018

PR Summary

Clean up code related to the uses of CommandTypes.Workflow and WorkflowInfo in System.Management.Automation. This change mainly affects help provider code.

This PR includes a few minor breaking changes:

  • Change the public constructors of WorkflowInfo to internal. We don't support workflow in PSCore, so I think it makes sense to not allow people to create Workflow instances.
  • Remove the type System.Management.Automation.DebugSource since it's only used for workflow debugging.
  • Remove the overload of SetParent from the abstract class Debugger that is only used for workflow debugging.
  • Remove the same overload of SetParent from the derived class RemotingJobDebugger.

PR Checklist

MamlPossibleValueControl,
MamlTrueFalseShortControl,
MamlIndentedSyntaxControl,
CommonWorkflowParametersControl,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entry is with the index 16 in the array sharedControls, so for an index that is greater than 16, we need to adjust it by subtracting 1. This is why you will see many index changes below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could leave null in this entry.
In another PR - you could introduce names for each shared control to make the file more friendly to human editing now that we no longer use a tool to generate it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in a separate PR #6712

}

sessionState.ExportedFunctions.Add(entry.Value);
string message = StringUtil.Format(Modules.ExportingFunction, entry.Key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR - but the result of this format call is typically thrown away. It should be possible to check if methods like WriteVerbose will do anything before formatting, or at least add overloads that do the formatting only after deciding the formatted string is needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be the best to add a few overloads to WriteVerbose, which take a format string and arguments. So we can defer the construction of message until we know for sure we are going to write out verbose messages. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be easiest to adopt.

Best is to use an if before the call, but folks tend to not like that style because it's verbose.

Accepting a delegate is also a clean solution, but that can allocate as well, so might not be an improvement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open #6740 to track this investigation.

_context.EngineHostInterface.ExternalHost,
_context.SessionState.Path.CurrentLocation,
GetFunctionToSourceMap());
new Dictionary<string, DebugSource>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious from the diffs, but it looks like this dictionary might not be needed anymore.
If it's needed and clear elsewhere in the code, then fine, but if it's not needed or unclear, a comment would be good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I noticed that too. The implementation of SetParent in RemotingJobDebugger just throws away all the arguments. However, SetParent is a virtual method, theoretically, someone could derive the Debugger class and implement SetParent that actually use the dictionary ... So, it's a breaking change that I'm not sure if I can make.

@PaulHigin Is it OK to remove the functionSourceMap parameter from public virtual void SetParent?
If it's OK, I can clean up the DebugSource type as a whole.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PaulHigin Could you please take a look and weigh in? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the GetFunctionToSourceMap() is only for the workflow debugger. You can remove the dictionary from SetParent() and also the GetFunctionSource() private method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @PaulHigin for the insight!
I have addressed your comment. Also removed the DebugSource type, which is not used anywhere else.

@lzybkr
Copy link
Contributor

lzybkr commented Apr 23, 2018

Assuming ModuleInfo.ExportedWorkflows will remain forever - it would be good to decide what to do about it - throwing an error seems unwise, but what about warning that it is ignore? And should it return the entries in the psd1 (reflecting the psd1 contents) or should it always return an empty array, reflecting what is actually imported? The property name would imply the former, but in reality, it typically is what is imported.

@iSazonov
Copy link
Collaborator

Seems if we return an empty array it will be a breaking change - in the case a throw is better then a warning.
If we want remove this in future we could mark this with [obsolete] and write a warning in scripts.

@daxian-dbw
Copy link
Member Author

Currently, ModuleInfo.ExportedWorkflows returns an empty Dictionary<string, FunctionInfo> (not changed in this PR). I think the current behavior makes sense. We don't support XAML module and don't support the workflow keyword in the script, so there is no way to import a module that declares any workflow in it.

As to Get-Module -list, for a script module that has workflow foo {} defined in it, the module analysis does find foo as an exported module member, but consider foo to be a function (this seems wrong to me, module analysis probably shouldn't return any exported commands in case a workflow definition is found in AST, because that module won't be able to be loaded). The ExportedWorkflows property of the returned PSModuleInfo object is still an empty dictionary.

_context.EngineHostInterface.ExternalHost,
_context.SessionState.Path.CurrentLocation,
GetFunctionToSourceMap());
new Dictionary<string, DebugSource>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the GetFunctionToSourceMap() is only for the workflow debugger. You can remove the dictionary from SetParent() and also the GetFunctionSource() private method.

@daxian-dbw daxian-dbw requested a review from mirichmo as a code owner April 27, 2018 00:38
@daxian-dbw daxian-dbw merged commit 8aec158 into PowerShell:master Apr 28, 2018
@daxian-dbw daxian-dbw deleted the cleanup-workflow branch April 28, 2018 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants