Skip to content

[SymbolGraphGen] Automatically use new generics notation #70588

Open
@karwa

Description

@karwa

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ASTPrinterArea → compiler: The AST printerSymbolGraphGenThe swiftSymbolGraphGen library, responsible for gathering and emitting symbol graphs.featureA feature request or implementationgeneric constraintsFeature → generics: generic constraints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions