Skip to content

Extend dartdoc options to begin to handle experiment flags #1884

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

Merged
merged 10 commits into from
Jan 7, 2019

Conversation

jcollins-g
Copy link
Contributor

The beginnings of experiment flag implementation for https://github.com/dart-lang/sdk/blob/master/docs/process/experimental-flags.md.

Initial non-generated options list borrowed from the analyzer for consistency (https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/src/dart/analysis/experiments.dart).

@googlebot googlebot added the cla: yes Google CLA check succeeded. label Jan 3, 2019
@coveralls
Copy link

coveralls commented Jan 3, 2019

Coverage Status

Coverage increased (+0.02%) to 92.666% when pulling ec85e3d on experiment-control into 27ae7bf on master.

@jcollins-g jcollins-g requested review from bwilkerson and stereotype441 and removed request for bwilkerson January 3, 2019 18:36
@stereotype441
Copy link
Member

Clarifying question: the long term plan with pkg/analyzer/lib/src/dart/analysis/experiments.dart is that it will be code-generated from a yaml description file in the SDK repo specifying what experiments are available, and metadata about them. The motivation for this is to make sure that when an experiment is created or retired, we don't forget to update all the tools. Given dartdoc's place in the ecosystem (and the fact that it's developed outside the SDK repo), it seems like it's more at risk of being forgotten than some of the other tools. Is your long term plan to generate lib/src/experiment_options.dart as well, or do you want it to stay hand-coded?

I'm wondering if it would be better for us to define an analyzer API that would let dartdoc ask about what experiments are available so that this information doesn't need to be duplicated in dartdoc source code. Or perhaps we should define an API to allow analyzer clients to access some of the experimental options parsing code in pkg/analyzer/lib/src/dart/analysis/experiments_impl.dart, so that you don't need to replicate this logic in dartdoc.

@jcollins-g
Copy link
Contributor Author

@stereotype441 All good questions. First, the easier one: I was planning longer term to generate key parts of the code from a yaml file (DartdocExperimentOptionContext and createExperimentOptions), and have that generated against different yamls in the SDK vs in dartdoc's standalone mode.

The harder question you're getting at is the problem of synchronizing dartdoc and analyzer's configuration. Dartdoc has the possibility to have experiments turned off and on based on its dartdoc_options.yaml and that doesn't necessarily sync with the analyzer's configuration. I don't know what kind of API would be useful to synchronize options, but coming up with something here would be a good idea. In the past we just force-switched on analyzer flags we might at some point depend on with a dartdoc feature...

@jcollins-g
Copy link
Contributor Author

Oh, as far as sharing the API for option validation, that seems like a more obviously good idea. I did wind up reimplementing what you did slightly differently with different behavior. For example, I took a last conflicting flag wins approach vs returning an error and I'm sure there's more subtlety in there that is really unnecessary.

@stereotype441
Copy link
Member

The harder question you're getting at is the problem of synchronizing dartdoc and analyzer's configuration. Dartdoc has the possibility to have experiments turned off and on based on its dartdoc_options.yaml and that doesn't necessarily sync with the analyzer's configuration. I don't know what kind of API would be useful to synchronize options, but coming up with something here would be a good idea. In the past we just force-switched on analyzer flags we might at some point depend on with a dartdoc feature...

@jcollins-g The analyzer already has the problem of synchronizing options between the command-line and analysis_options.yaml files. The way I plan to handle it is by using validateFlagCombination to validate that the options specified in the two places are compatible, and then simply concatenate the options. You might consider a similar approach. (Note that validateFlagCombination is written and unit tested but I haven't yet written the code that uses it).

Another possibility would be to decide that dartdoc_options.yaml is not allowed to turn experiments on and off; it must be done either via the command line or analysis_options.yaml. This would have the advantage of being less work, and I think it's compatible with the intention of these experimental options (i.e. the fact that they allow the user to opt into experimental and potentially buggy behavior, don't guarantee backward compatibility, and are not intended to be used in production code). We could always reverse this decision at a later date if it we wind up deciding to support experimental options in a more durable way.

@stereotype441
Copy link
Member

Oh, as far as sharing the API for option validation, that seems like a more obviously good idea. I did wind up reimplementing what you did slightly differently with different behavior. For example, I took a last conflicting flag wins approach vs returning an error and I'm sure there's more subtlety in there that is really unnecessary.

I can see two options for moving forward with this:

  1. Dartdoc starts making use of the code in package:analyzer/src/dart/analysis/experiments.dart now, and once we see what functionality it needs, we can use that information to help us decide on the long-term API the analyzer wants to support; then once that API is implemented we can migrate dartdoc to it.
  2. You could send a CL to the analyzer team proposing the public API that you need, and we can review and land it, then you can start using it.

WDYT?

@jcollins-g
Copy link
Contributor Author

The harder question you're getting at is the problem of synchronizing dartdoc and analyzer's configuration. Dartdoc has the possibility to have experiments turned off and on based on its dartdoc_options.yaml and that doesn't necessarily sync with the analyzer's configuration. I don't know what kind of API would be useful to synchronize options, but coming up with something here would be a good idea. In the past we just force-switched on analyzer flags we might at some point depend on with a dartdoc feature...

@jcollins-g The analyzer already has the problem of synchronizing options between the command-line and analysis_options.yaml files. The way I plan to handle it is by using validateFlagCombination to validate that the options specified in the two places are compatible, and then simply concatenate the options. You might consider a similar approach. (Note that validateFlagCombination is written and unit tested but I haven't yet written the code that uses it).

Yes. The PR handles this already with a strict override of what's in the file because that's what's simple and already supported through DartdocOptionArgFile, but it would be quite possible to change.

Another possibility would be to decide that dartdoc_options.yaml is not allowed to turn experiments on and off; it must be done either via the command line or analysis_options.yaml. This would have the advantage of being less work, and I think it's compatible with the intention of these experimental options (i.e. the fact that they allow the user to opt into experimental and potentially buggy behavior, don't guarantee backward compatibility, and are not intended to be used in production code). We could always reverse this decision at a later date if it we wind up deciding to support experimental options in a more durable way.

I think subordinating Dartdoc's options to analyzer's was what I was trying to avoid, but perhaps that's not reasonable. It would be simpler to implement if we did it this way.

@jcollins-g
Copy link
Contributor Author

Oh, as far as sharing the API for option validation, that seems like a more obviously good idea. I did wind up reimplementing what you did slightly differently with different behavior. For example, I took a last conflicting flag wins approach vs returning an error and I'm sure there's more subtlety in there that is really unnecessary.

I can see two options for moving forward with this:

  1. Dartdoc starts making use of the code in package:analyzer/src/dart/analysis/experiments.dart now, and once we see what functionality it needs, we can use that information to help us decide on the long-term API the analyzer wants to support; then once that API is implemented we can migrate dartdoc to it.
  2. You could send a CL to the analyzer team proposing the public API that you need, and we can review and land it, then you can start using it.

WDYT?

@jcollins-g jcollins-g closed this Jan 4, 2019
@jcollins-g jcollins-g reopened this Jan 7, 2019
@jcollins-g
Copy link
Contributor Author

Reopening with fixes based on our discussion. We now use ExperimentStatus class from analyzer to assemble options from the command line, and directly pass those in from our configuration to AnalysisOptions.

Copy link
Member

@stereotype441 stereotype441 left a comment

Choose a reason for hiding this comment

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

lgtm, thank you!

@jcollins-g jcollins-g merged commit 7930d89 into master Jan 7, 2019
@jcollins-g jcollins-g deleted the experiment-control branch January 7, 2019 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA check succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants