Skip to content

Extensions Across Libraries Exposed via @_exported imports with Extension Block Symbols Enabled Produces Invalid Archive #422

@theMomax

Description

@theMomax

Description

Note This issue was first discussed here.

Having Lib1 depending on Lib2, and a third target Main reexporting Lib1 and Lib2, and in Lib1 having the extensions defined to the types declared in Lib2, the variables defined in these extensions, are shown on the root level of the doc archive.

E.g. this code produces a top level symbol func foo() in the documentation archive.

// Lib1
public struct Lib1Struct { }

// Lib2
import Lib1

public extension Lib1Struct {
    func foo() { }
}

// Main
@_exported import Lib1
@_exported import Lib2

Checklist

  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue.

Expected Behavior

The expected behavior depends on the discussion around #331. If we decide to implement #331, and do not emit symbols from @_exported imports entirely, we of course would expect the extensions across the re-exported libraries to disappear as well.

If we reject #331 in favor of the current behavior, the expected behavior would be for the symbols resulting from these cross-re-export extensions to be presented as part of the re-exporting target (Main in the example`). These extensions would not be considered extensions to external types, as the types, as well as the extensions, are all re-exported by the same target. That is, there would be no Extended Module sections under which the extension-based symbols are listed. The expected structure of the archive would be as follows:

- Main:
    - Lib1Struct:
        - foo()

Actual behavior

Currently, the structure generated for the example above is as follows:

- Main:
    - Lib1Struct
- foo()

Steps To Reproduce

  1. Make sure you have a setup ready that can produce extension block symbols, e.g. a recent nightly toolchain.
  2. Build the symbol graph files with -emit-extension-block-symbols: swift build --target Main -Xswiftc -emit-symbol-graph -Xswiftc -emit-symbol-graph-dir -Xswiftc .build/symbol-graphs -Xswiftc -omit-extension-block-symbols -Xswiftc -emit-extension-block-symbols
  3. Preview the documentation as usual with docc. Make sure you use an up to date version (main branch).

Swift-DocC Version Information

b9d9ada

Swift Compiler Version Information

Swift version 5.8-dev (LLVM c10fcd3e640b373, Swift 11d9927b51f90d4)
Target: arm64-apple-macosx12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions