Skip to content

[SymbolGraph] add sourceOrigin for synthesized symbols even if no docs exist #37248

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 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/SymbolGraphGen/Edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ void Edge::serialize(llvm::json::OStream &OS) const {
if (Target.getSymbolDecl() == ID || Source.getSynthesizedBaseTypeDecl())
InheritingDecl = ID;
}

if (!InheritingDecl && Source.getSynthesizedBaseTypeDecl())
InheritingDecl = Source.getSymbolDecl();

// If our source symbol is a inheriting decl, write in information about
// where it's inheriting docs from.
Expand Down
12 changes: 12 additions & 0 deletions test/SymbolGraph/Relationships/Synthesized/InheritedDocs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes IMPL
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS-DOCS
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes EXTRA

// RUN: %target-swift-symbolgraph-extract -module-name InheritedDocs -I %t -pretty-print -output-dir %t -skip-inherited-docs
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes CHECK,SKIP
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes IMPL
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes BONUS-SKIP
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes EXTRA

// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -module-name InheritedDocs -emit-module -emit-module-path %t/InheritedDocs.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t/ -skip-inherited-docs
Expand Down Expand Up @@ -46,6 +48,14 @@
// BONUS-NEXT: "identifier": "s:13InheritedDocs1PPAAE9bonusFuncyyF"
// BONUS-NEXT: "displayName": "P.bonusFunc()"

// synthesized symbols that don't have docs to inherit still need to have the sourceOrigin field

// EXTRA: "source": "s:13InheritedDocs1PPAAE9extraFuncyyF::SYNTHESIZED::s:13InheritedDocs1SV"
// EXTRA-NEXT: "target": "s:13InheritedDocs1SV"
// EXTRA-NEXT: "sourceOrigin"
// EXTRA-NEXT: "identifier": "s:13InheritedDocs1PPAAE9extraFuncyyF"
// EXTRA-NEXT: "displayName": "P.extraFunc()"

/// Protocol P
public protocol P {
/// Some Function
Expand All @@ -57,6 +67,8 @@ public extension P {

/// Bonus docs!
func bonusFunc() {}

func extraFunc() {} // no docs, but still needs sourceOrigin
}

public struct S: P {
Expand Down