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

[SymbolGraphGen] Automatically use new generics notation #70588

Open
karwa opened this issue Nov 20, 2022 · 2 comments
Open

[SymbolGraphGen] Automatically use new generics notation #70588

karwa opened this issue Nov 20, 2022 · 2 comments
Labels
ASTPrinter Area → compiler: The AST printer feature A feature request or implementation generic constraints Feature → generics: generic constraints SymbolGraphGen The swiftSymbolGraphGen library, responsible for gathering and emitting symbol graphs.

Comments

@karwa
Copy link
Contributor

karwa commented Nov 20, 2022

Feature Name

Use new generics notation

Description

It would be nice if DocC had the ability to rewrite function signatures using the new generics notation. Package developers who need to support older versions of the compiler may need to keep using the angle-bracket notation, even in cases where it would be possible to use some types or primary associated types instead.

But for documentation, we still want to present the clearest interface to users, and both notations have equivalent meaning.
For example, if I write:

func foo<T: BinaryInteger>(_ value: T)

It would be nice if it appeared in documentation as:

func foo(_ value: some BinaryInteger)

Similarly, for primary associated types. I write:

func foo<Source: Collection>(_ value: Source) where Source.Element == UInt8

But that's long and wraps to multiple lines in the topics list. It's not very readable - type names ("Source") get introduced at the start, used in the middle, then explained using constraints at the end.

And it would be nice if DocC could present this as:

func foo(_ value: some Collection<UInt8>)

Even if I need to keep writing it the old way for compatibility purposes.

Motivation

No response

Importance

No response

Alternatives Considered

No response

@karwa karwa changed the title Use new generics notation Automatically use new generics notation Nov 20, 2022
@d-ronnqvist
Copy link
Contributor

DocC itself isn't tied to any specific language so it wouldn't rewrite function signatures. Instead the symbol information that's displayed in DocC comes from the source language's compilers.

In order for DocC to display a Swift function defined like

func foo<Source: Collection>(_ value: Source) where Source.Element == UInt8

as some other format, for example

func foo(_ value: some Collection<UInt8>)

the Swift compiler would need to emit that declaration in the symbol graph file it passes to DocC. I'm not sure if that's a syntax transformation that possible to do on the AST.

@d-ronnqvist d-ronnqvist changed the title Automatically use new generics notation [SymbolGraphGen] Automatically use new generics notation Dec 21, 2023
@d-ronnqvist d-ronnqvist transferred this issue from apple/swift-docc Dec 21, 2023
@d-ronnqvist
Copy link
Contributor

cc @QuietMisdreavus

@QuietMisdreavus QuietMisdreavus added feature A feature request or implementation SymbolGraphGen The swiftSymbolGraphGen library, responsible for gathering and emitting symbol graphs. generic constraints Feature → generics: generic constraints ASTPrinter Area → compiler: The AST printer labels Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASTPrinter Area → compiler: The AST printer feature A feature request or implementation generic constraints Feature → generics: generic constraints SymbolGraphGen The swiftSymbolGraphGen library, responsible for gathering and emitting symbol graphs.
Projects
None yet
Development

No branches or pull requests

3 participants