Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Experimental documentation generation tool #253

Conversation

cgranade
Copy link
Contributor

@cgranade cgranade commented Jun 13, 2020

This PR opens for early feedback a possible path towards solving microsoft/qsharp-compiler#277, namely outputting documentation Markdown directly rather than as YAML. This PR packages that effort as an IRewriteStep that can be controlled by the IRewriteStep.AssemblyConstants property, and that can be included as an IsQscReference. The step also attaches documentation information as attributes that can be used by other parts of the Quantum Development Kit, such as IQ#.

Improvements over the existing approach:

  • Can display Q# syntax for UDT named items.
  • Extensible with new Q# features.
  • Can be used more easily by third-party libraries.
  • Attaches documentation data to the AST for reuse by other tools.

Remaining work:

  • Currently does not filter by the current compilation unit, such that all symbols included from references are documented as well.
  • Does not yet provide special support for @Deprecated(); this is currently supported by the non-experimental documentation generator.
  • Does not yet provide special support for @Attribute(), making it hard to learn how attributes should be used.
  • Missing unit tests.
  • Missing explanatory comments.
  • Named items don't yet have a dedicated Markdown section; this will require additions to the DocumentationParser in the qsharp-compiler repo.
  • Need to add comments to output Markdown files indicating that they are auto-generated.
  • Does not yet support making or merging toc.yml and index.md files.
  • Does not yet resolve unqualified names in /// # See Also blocks.

@cgranade
Copy link
Contributor Author

Adding @tcNickolas and @KittyYeungQ for reference documentation impact, @anpaz-msft for build pipeline impact. If you have any time to offer feedback on the early prototype / experiment and the broader approach, I'd really appreciate it. Thank you!

)
);

internal static IAttributeBuilder<T> WithDocumentationAttributesFromDictionary<T>(
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you might want to use the tools in this PR: microsoft/qsharp-compiler#463
Let me know what attribute related things are missing, and we can see if it makes sense to add it to that static class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I'll take a look at that, then. One thing I ran into was that a lot of the documentation attributes take a similar form on UDTs and callables, but even though QsCallable and QsCustomType both have an AddAttribute method, there's no common interface that allows calling AddAttribute on both. The AttributeBuilder class here was a hack around that to reduce code duplication.

this.Namespaces = new ProcessDocComments.NamespaceTransformation(this, outputPath);
}

public QsCompilation OnCompilation(QsCompilation compilation) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Apply (inherited from the base class) would do that too.

Copy link
Contributor

Choose a reason for hiding this comment

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

renamed to OnCompilation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that imply that this method can be safely deleted?


private static QsCallable AddSummaryAttribute(QsCallable callable, string summary) =>
callable.AddAttribute(
new QsDeclarationAttribute(
Copy link
Contributor

Choose a reason for hiding this comment

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

See the tools in the PR I mentioned in another comment.

)
);

private async Task MaybeWriteOutput(QsCustomType type, DocComment docComment)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put these writers etc into a separate file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I agree; this was convenient when quickly prototyping, but is not the most maintainable.

Copy link
Contributor

@bettinaheim bettinaheim left a comment

Choose a reason for hiding this comment

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

What was the reason to put this on the runtime repo rather than the compiler repo? I believe you could just have a reference to the source code version of the compiler to build the rewrite step, couldn't you?

@cgranade
Copy link
Contributor Author

Thanks for your feedback, @bettinaheim!

What was the reason to put this on the runtime repo rather than the compiler repo? I believe you could just have a reference to the source code version of the compiler to build the rewrite step, couldn't you?

My thinking was that this is similar in principle to how the C# generation app works, and thus to put it there, but I'm happy to move this to the compiler instead if that makes more sense.

@anpaz
Copy link
Member

anpaz commented Jul 1, 2020

I think it makes sense on the compiler repo, as Bettina suggested.

Could you provide more information about usage? If I understand correctly these are Q# attributes that get added to the code directly and that would replace the current markdown docs, is that correct, are you planning to replace comments with attributes, or are these attributes go inside the comments?
I personally like much better using comments and markdown to write the documentation as we do today. I rather make enhancement to the YAML parser we use that to embed the documentation directly into the code.
Maybe you can give a couple of samples on how the new documentation would look?

Also, will these changes be backwards compatible? Switching all the documentation will be a huge PITA.

@cgranade
Copy link
Contributor Author

cgranade commented Jul 1, 2020

Thanks for your comments, @anpaz-msft! Please see responses inline below.

I think it makes sense on the compiler repo, as Bettina suggested.

Sounds good, I'll move it there then and close this PR.

Could you provide more information about usage? If I understand correctly these are Q# attributes that get added to the code directly and that would replace the current markdown docs, is that correct, are you planning to replace comments with attributes, or are these attributes go inside the comments?

The new attributes are added automatically by the IRewriteStep in this PR, such that no change to Markdown documentation comments is required.

I personally like much better using comments and markdown to write the documentation as we do today. I rather make enhancement to the YAML parser we use that to embed the documentation directly into the code.

Agreed, hence this PR doesn't target changing that workflow at all, but makes the result of parsing those comments more widely available to other parts of the Quantum Development Kit (e.g.: IQ#) via attributes.

Maybe you can give a couple of samples on how the new documentation would look?

Also, will these changes be backwards compatible? Switching all the documentation will be a huge PITA.

So far the only backwards-incompatible change posed is to finally fix the casing convention for API reference UIDs to not require all-lowercase.

@cgranade
Copy link
Contributor Author

Moved logic to compiler repo, closing this PR in favor of new approach.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants