Skip to content
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

Add notes and sections covering Incompatibility Mitigations and Static Code Analysis #1

Merged
merged 7 commits into from Feb 23, 2018

Conversation

dantraMSFT
Copy link

  • Fixed a few spelling errors
  • Added notes in sections '> NOTE:'
  • Updated ExperimentalFeatures manifest example to be an array of dictionaries (multiple experimental features)
  • Added section discussing mitigations for incompatible features
  • Added section discussion static code analysis to detect declaration problems and removing references to experiments that are completed.

@daxian-dbw daxian-dbw self-requested a review February 6, 2018 00:55
@daxian-dbw
Copy link
Owner

/cc @SteveL-MSFT @JamesWTruher It would be helpful if you can review.

Copy link

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

A few small changes and I think it's ready for public consumption.

2: Validating references to an experimental feature have been removed.
At some point, the experiment is completed and either removed from or incorporated into the code base. At this point, a tool to scan script or compiled code would be needed to ensure any references to the experiment have been removed.

> NOTE: Will consumers require builds with no experimental code? If so, how to do we ensure this?

Choose a reason for hiding this comment

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

I think it may be sufficient to have policy settings so users cannot enable experimental code if there are concerns for enterprises.

Copy link
Author

Choose a reason for hiding this comment

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

While that works for enterprise, it doesn't address cloud. TBH: I'm more interested in ensuring experiments are declared correctly when added and dead code is removed when the experiment is complete.

Copy link
Owner

Choose a reason for hiding this comment

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

Policy settings can be set in powershell.config.json and take effect without GPO.
On windows, the same policy settings in registry (GPO) take precedence over the settings in powershell.config.json.

@@ -457,6 +470,27 @@ as well as a problem that we have to solve before using the experimental feature

> Not sure how to handle it yet ...

Choose a reason for hiding this comment

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

For testing, I think we can simplify this. Due to the nature of being experimental, I think our regular test passes should run without any experimental features enabled. Separately, we should run the experimental feature tests with all experimental features enabled and all of the CI/Feature tests.

Choose a reason for hiding this comment

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

I'm not sure that this will work. I easily envision conflicting or mutually exclusive experimental features as mentioned. I wonder if we are going to need more tags.

Copy link
Owner

Choose a reason for hiding this comment

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

I agree our regular test pass should run without any experimental feature enabled.

For the experimental features, we need to run test passes for each of them (one per test run) enabled. We will need more tags because tests targeting an experimental feature should be skipped sometimes.

@@ -80,6 +83,7 @@ The `JSON` schema should look like this:
]
}
```
> NOTE: Should we consider reading experimental feature lists also from the per-user configuration file?

PowerShell reads the experimental feature list from the configuration file only once when starting up.

Choose a reason for hiding this comment

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

I think we should be pretty explicit here. The implication is that since we read the config file once during startup, it's implied that changing experimental features at runtime, I think that should be an explicit statement. Also, we should be explicit that the config file is read before engine start

Copy link
Owner

Choose a reason for hiding this comment

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

Updated the words to be more explicit. #closed

@@ -327,8 +337,11 @@ For experimental features in PowerShell engine,
an internal enum `EngineExperimentalFeatures` will be used to track the names of all available engine experimental features.

Choose a reason for hiding this comment

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

internal? Should this be public rather than internal?

Copy link
Owner

Choose a reason for hiding this comment

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

The idea is to add a cmdlet to expose this information to users.
The members of the enum will change consistently, so it would be a consistent breaking change if we make it public.

Copy link
Author

Choose a reason for hiding this comment

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

Consider the possibility of third party experiments relying on engine experiments. For example, an editor experiment that depends on a language experiment. The editor experiment would need to either define it's own then check for the language experiment being enabled or expose it's capabilities as the same experiment.

Scripts and modules may also take dependencies on engine experiments so, whatever the form, the cooperation is likely desirable; especially for new features and capabilities.

Copy link
Owner

Choose a reason for hiding this comment

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

Updated the PR to use a static read-only collection to track all engine experimental features.

For the scenario that third party experiments depending on engine experiments, it's covered in the Experimental Feature Dependency section. A third party experiment can specify a dependency on an engine experimental feature, but the third party experiment needs to be a separate experimental feature.
#closed

such as `XXX-Description` where `XXX` is the feature name.

> NOTE: Do experimental features really need resource strings for the description? They are not likely to be localized and it will simplify declaration since the name and description can be placed in a table as a single unit and avoid misnamed or missing description resources.

Choose a reason for hiding this comment

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

probably not - it's probably ok not to require this.

Copy link
Owner

Choose a reason for hiding this comment

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

as a single unit and avoid misnamed or missing description resources.

I think that make senses. Then the enum could really be a static table instead.

Copy link
Owner

Choose a reason for hiding this comment

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

Updated the PR to use a static read-only collection to track all engine experimental features.
#closed

@@ -457,6 +470,27 @@ as well as a problem that we have to solve before using the experimental feature

> Not sure how to handle it yet ...

Choose a reason for hiding this comment

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

I'm not sure that this will work. I easily envision conflicting or mutually exclusive experimental features as mentioned. I wonder if we are going to need more tags.

@@ -56,6 +56,9 @@ For example:
PSDomainSpecificLanguage
PSFileSystemProviderV2
```
> NOTE: Can external modules participate in an experimental feature defined by the engine or another external module? For the engine: If PowerShell class support were to support exporting a script class from a module, support tools, such as PSScriptAnalyzer would likely participate with experimental rules for these classes.
Copy link
Owner

Choose a reason for hiding this comment

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

Yes, they can, but they won't be part of the engine experimental feature, but experimental features that depend on the engine experimental feature. I think this scenario falls into the Experimental Feature Dependency section, where a module can expose experimentally features that depends on another experimental feature.

@@ -258,6 +264,8 @@ So a `Parameter` attribute can be associated with an experimental feature.
When the experimental feature is enabled,
PowerShell can choose to process or ignore the `Parameter` attribute depending on the `FeatureAction`.

> NOTE: Can a parameter be marked with multiple experiment names? The use case is a new parameter that appears in 2 out of N parameter sets.
Copy link
Owner

Choose a reason for hiding this comment

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

For every parameter set a parameter belongs to, it will have a Parameter attribute declared for that parameter set, whose ParamemterSetName is the name of the parameter set. So it's fine that a parameter can only be marked with one experimental feature name.

Copy link
Author

Choose a reason for hiding this comment

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

Perhaps I didn't phrase the question clearly. Can a given parameter participate in more than one experiments? My use case is primarily UX, where I'm altering existing parameters for better UX. In experiment 1, I define parameters A B and C, in experiment 2 I define A B D E. A and B are common to both experiments.

@@ -308,6 +316,8 @@ As for the type members with the `[Experimental()]` attributes,
[`TypeDefiner`](https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/parser/PSType.cs#L17) needs to be updated to process or skip a type member when processing a `TypeDefinitionAst` node,
depending on whether the experimental feature is enabled and the `FeatureAction` value.

> NOTE: When are errors generated, if any, if an experimental script function or class member is referenced, such as within a script module or within the class implementation?
Copy link
Owner

Choose a reason for hiding this comment

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

The errors will be generated at runtime. For a type reference, powershell will throw "type cannot be found". For a member reference, it will throw "member cannot be found".

Copy link
Author

@dantraMSFT dantraMSFT Feb 6, 2018

Choose a reason for hiding this comment

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

For script functions, are the functions stripped or are stubs used to throw an explicit error. My thought we could end up with unintended false positives resolving to something else.

For classes, we could end up a with class that doesn't compile due to internal references to members that are 'removed' due to the experiment not being enabled.

How these are reported should be a dev experience issue, not an end user issue. (IMHO)

Copy link
Owner

Choose a reason for hiding this comment

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

For script functions, if the associated experimental feature is not enabled, the functions will not be logged in the function table, so any reference to the script function would result in a "function not found" error at runtime.

For classes, if a class is referencing another class that is experimental, then depending on the manner of the reference, the former class itself or members of it should be marked with the same experimental feature.
Scenarios:

  1. class Foo : Bar {...} -- Bar is an experimental feature, then Foo must also be an experimental feature.
  2. class Foo { [Bar] $member } -- Bar is an experimental feature, then $member must also be an experimental feature.

@@ -327,8 +337,11 @@ For experimental features in PowerShell engine,
an internal enum `EngineExperimentalFeatures` will be used to track the names of all available engine experimental features.
Copy link
Owner

Choose a reason for hiding this comment

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

The idea is to add a cmdlet to expose this information to users.
The members of the enum will change consistently, so it would be a consistent breaking change if we make it public.

such as `XXX-Description` where `XXX` is the feature name.

> NOTE: Do experimental features really need resource strings for the description? They are not likely to be localized and it will simplify declaration since the name and description can be placed in a table as a single unit and avoid misnamed or missing description resources.
Copy link
Owner

Choose a reason for hiding this comment

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

as a single unit and avoid misnamed or missing description resources.

I think that make senses. Then the enum could really be a static table instead.

@@ -89,6 +93,8 @@ PowerShell reads the experimental feature list from the configuration file only
and read the list if not yet.
This is to make sure experimental features can be enabled when an application is hosting PowerShell.

> NOTE: Current command-line parsing may make some experimental features difficult to flag due to the amount of work that occurs before parsing is completed. This is seen on Linux with Logging overrides. It may be necessary to move parsing earlier in the startup call-path.
Copy link
Owner

Choose a reason for hiding this comment

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

By looking at the code, at least the CommandLineParameterParser needs to be instantiated before parsing the command-line, so if there is an experimental feature added to CommandLineParameterParser, it may cause the configuration file overriding with -settingsfile to not work anyways.

I start to think that maybe we shouldn't use -settingsfile to override the configuration file at PSHome. Instead, we probably should use an environment variable, so that it can be checked and enforced the first thing when console starts up.

Copy link
Author

Choose a reason for hiding this comment

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

We should consider moving command-line parsing as early in startup as possible. For the case where the CommandLineParser is introducing an experimental feature, it could internally parse a second time if the experimental feature is enabled by the settings file. This may require the CommandLine parser to populate the hashset or build the hash set and populate it at the end of parsing. Finally, for the few cases where updates are made as a side-effect of parsing, such as with log settings, these updates should be performed after parsing completes. In short, distinguishing between parse an apply.

@@ -81,14 +84,19 @@ The `JSON` schema should look like this:
}
```

PowerShell reads the experimental feature list from the configuration file only once when starting up.
> NOTE: Should we consider reading experimental feature lists also from the per-user configuration file?
Copy link
Owner

Choose a reason for hiding this comment

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

Good question. If we should, which one takes precedence?

Copy link
Author

Choose a reason for hiding this comment

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

I would expect the per-user configuration to take precedence.

- An example of an unintended incompatibility can occur when two experimental features prove to be incompatible through usage.

A minimal implementation will support defining a list of experimental feature pairs in the `powershell.config.json` file.
At startup, attempts to use incompatible features would produce warnings and consider both as disabled.
Copy link
Owner

Choose a reason for hiding this comment

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

We need to be more explicit on how conflicting features would be described, both in ExperimentalFeature and in PrivateData.ExperimentalFeatures from a module manifest.

Copy link
Owner

Choose a reason for hiding this comment

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

Dan and I discussed this and decided to not get into details on this section.

@daxian-dbw daxian-dbw merged commit 1a3d4df into daxian-dbw:experimental Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants