Skip to content

[5.5] [SymbolGraph] add sourceOrigin info for all protocol implementations #37815

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
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
22 changes: 17 additions & 5 deletions lib/SymbolGraphGen/Edge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ const ValueDecl *getForeignProtocolRequirement(const ValueDecl *VD, const Module
requirements.pop();
}
}

const ValueDecl *getProtocolRequirement(const ValueDecl *VD) {
auto reqs = VD->getSatisfiedProtocolRequirements();

if (!reqs.empty())
return reqs.front();
else
return nullptr;
}
} // end anonymous namespace

void Edge::serialize(llvm::json::OStream &OS) const {
Expand Down Expand Up @@ -79,10 +88,8 @@ void Edge::serialize(llvm::json::OStream &OS) const {
}

const ValueDecl *InheritingDecl = nullptr;
if (const auto *ID = Source.getDeclInheritingDocs()) {
if (Target.getSymbolDecl() == ID || Source.getSynthesizedBaseTypeDecl())
InheritingDecl = ID;
}
if (const auto *ID = Source.getDeclInheritingDocs())
InheritingDecl = ID;

if (!InheritingDecl && Source.getSynthesizedBaseTypeDecl())
InheritingDecl = Source.getSymbolDecl();
Expand All @@ -91,7 +98,12 @@ void Edge::serialize(llvm::json::OStream &OS) const {
if (const auto *ID = getForeignProtocolRequirement(Source.getSymbolDecl(), &Graph->M))
InheritingDecl = ID;
}


if (!InheritingDecl) {
if (const auto *ID = getProtocolRequirement(Source.getSymbolDecl()))
InheritingDecl = ID;
}

// If our source symbol is a inheriting decl, write in information about
// where it's inheriting docs from.
if (InheritingDecl) {
Expand Down
28 changes: 28 additions & 0 deletions test/SymbolGraph/Relationships/Synthesized/InheritedDocs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
// 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: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes LOCAL
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes SUPER

// 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: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes LOCAL
// RUN: %FileCheck %s --input-file %t/InheritedDocs.symbols.json --check-prefixes SUPER

// 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 @@ -56,10 +60,31 @@
// EXTRA-NEXT: "identifier": "s:13InheritedDocs1PPAAE9extraFuncyyF"
// EXTRA-NEXT: "displayName": "P.extraFunc()"

// local implementations of a local protocol still need to a relation to that protocol

// LOCAL: "source": "s:13InheritedDocs1SV9localFuncyyF"
// LOCAL-NEXT: "target": "s:13InheritedDocs1SV"
// LOCAL-NEXT: "sourceOrigin"
// LOCAL-NEXT: "identifier": "s:13InheritedDocs1PP9localFuncyyF"
// LOCAL-NEXT: "displayName": "P.localFunc()"

// ...both with and without docs

// SUPER: "source": "s:13InheritedDocs1SV9superFuncyyF"
// SUPER-NEXT: "target": "s:13InheritedDocs1SV"
// SUPER-NEXT: "sourceOrigin"
// SUPER-NEXT: "identifier": "s:13InheritedDocs1PP9superFuncyyF"
// SUPER-NEXT: "displayName": "P.superFunc()"

/// Protocol P
public protocol P {
/// Some Function
func someFunc()

/// It's a local function!
func localFunc()

func superFunc()
}

public extension P {
Expand All @@ -72,4 +97,7 @@ public extension P {
}

public struct S: P {
public func localFunc() {}

public func superFunc() {}
}