Skip to content

introduce a @_documentation(...) attribute to influence SymbolGraphGen #60242

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 3 commits into from
Sep 6, 2022

Conversation

QuietMisdreavus
Copy link
Contributor

@QuietMisdreavus QuietMisdreavus commented Jul 26, 2022

Resolves rdar://79049241

This PR introduces a new attribute, @_documentation(...), that influences how SymbolGraphGen handles the symbol it's attached to. There are two forms of this attribute:

  • @_documentation(visibility: ...) treats the symbol as the given access level in the symbol graph, allowing you to hide a technically-public implementation detail from public documentation, or reveal a symbol with an underscored name that would otherwise be hidden.
  • @_documentation(metadata: ...) adds an arbitrary identifier to the symbol's "metadata" field, which can then be handled by other tooling.

This PR also fixes a pre-existing issue where symbols that were declared internal in a re-exported module would be included in the symbol graph if it was being requested with an internal access level, and similarly for anything below public.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus QuietMisdreavus changed the title introduce a @_nodoc attribute to hide symbols from the symbol graph introduce a @_documentation(...) attribute to add "documentation categories" Aug 4, 2022
@QuietMisdreavus
Copy link
Contributor Author

Based on discussion in this Swift Forums thread, i've pushed up a couple commits that change how the attribute works. Instead of a single @_nodoc attribute, there is now a general-purpose @_documentation(...) attribute that adds an arbitrary "documentation category" to the symbol. This is then read for two special-case categories: underscored treats the symbol as having an underscored name, hiding it from symbol graphs and docs by default; and ignoreUnderscored does the opposite, taking an underscored symbol and lifting it to its declared visibility (instead of internal), allowing public underscored symbols to appear in public docs.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus QuietMisdreavus force-pushed the QuietMisdreavus/nodoc-attr branch from 569bd2f to 7d9551c Compare August 10, 2022 17:14
@QuietMisdreavus
Copy link
Contributor Author

Based on further discussion on the forums, the @_documentation attribute now has the following structure:

  • @_documentation(visibility: <level>) forces the symbol to act like it has the given access level in symbol graphs and documentation, allowing you to override an underscored name or treat a symbol like an internal one if it's only public for implementation-detail reasons.
  • @_documentation(metadata: ...) adds the given identifier to the symbol graph as a new "metadata" field. This can be used to add arbitrary information to a symbol that can be processed by later tooling.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus QuietMisdreavus changed the title introduce a @_documentation(...) attribute to add "documentation categories" introduce a @_documentation(...) attribute to influence SymbolGraphGen Aug 10, 2022
@@ -117,6 +117,27 @@ extension Text {
}
```

## `@_documentation(metadata: ...)`
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume the value of the metadata parameter is just a string that be specified with or without quotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now it can only be an identifier, but i could see about making it a quoted string as well.

Copy link

Choose a reason for hiding this comment

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

If it's a string in quotes, developers could stick in useful metadata like JSON, CSV, or hex encoded images which would be fun 👌🏼

@@ -2226,6 +2226,28 @@ class BackDeployAttr: public DeclAttribute {
}
};

/// The `@_documentation(...)` attribute, used to note a "category" for a
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the term "category" still correct given the latest changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not, good catch 😅

Adds "documentation metadata" to the symbol. The identifier in the attribute is
added to the symbol graph in the `"metadata"` field of the symbol. This can be
used to add an arbitrary grouping or other indicator to symbols for use in
documentation.
Copy link
Contributor

@franklinsch franklinsch Aug 11, 2022

Choose a reason for hiding this comment

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

Are you able to specify multiple @_documentation(metadata: …) attributes for the same declaration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure; i'll have to check. Offhand, i think the answer is "no" because of checks for duplicate attributes, but i'm not confident about it.

@QuietMisdreavus QuietMisdreavus force-pushed the QuietMisdreavus/nodoc-attr branch from 1461391 to be76de2 Compare August 22, 2022 17:10
@QuietMisdreavus
Copy link
Contributor Author

I've rebased onto the latest main, and squashed down the first few commits to discard the history of the initial implementation (which made rebasing much easier). I also added a tweak to allow quoted strings as doc metadata.

@swift-ci Please test

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus QuietMisdreavus force-pushed the QuietMisdreavus/nodoc-attr branch from be76de2 to 955beff Compare September 1, 2022 21:19
@QuietMisdreavus
Copy link
Contributor Author

Rebased to resolve merge conflicts.

@swift-ci Please test

@QuietMisdreavus QuietMisdreavus force-pushed the QuietMisdreavus/nodoc-attr branch from 955beff to cc55f0e Compare September 6, 2022 15:31
@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

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

Successfully merging this pull request may close these issues.

3 participants