Skip to content

Commit dd39496

Browse files
do not synthesize subclass methods
rdar://80091081
1 parent b158666 commit dd39496

File tree

3 files changed

+11
-51
lines changed

3 files changed

+11
-51
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ void SymbolGraph::recordNode(Symbol S) {
196196
// with this declaration.
197197
recordMemberRelationship(S);
198198
recordConformanceSynthesizedMemberRelationships(S);
199-
recordSuperclassSynthesizedMemberRelationships(S);
200199
recordConformanceRelationships(S);
201200
recordInheritanceRelationships(S);
202201
recordDefaultImplementationRelationships(S);
@@ -259,45 +258,6 @@ void SymbolGraph::recordMemberRelationship(Symbol S) {
259258
}
260259
}
261260

262-
void SymbolGraph::recordSuperclassSynthesizedMemberRelationships(Symbol S) {
263-
if (!Walker.Options.EmitSynthesizedMembers) {
264-
return;
265-
}
266-
// Via class inheritance...
267-
if (const auto *C = dyn_cast<ClassDecl>(S.getSymbolDecl())) {
268-
// Collect all superclass members up the inheritance chain.
269-
SmallPtrSet<const ValueDecl *, 32> SuperClassMembers;
270-
const auto *Super = C->getSuperclassDecl();
271-
while (Super) {
272-
for (const auto *SuperMember : Super->getMembers()) {
273-
if (const auto *SuperMemberVD = dyn_cast<ValueDecl>(SuperMember)) {
274-
SuperClassMembers.insert(SuperMemberVD);
275-
}
276-
}
277-
Super = Super->getSuperclassDecl();
278-
}
279-
// Remove any that are overridden by this class.
280-
for (const auto *DerivedMember : C->getMembers()) {
281-
if (const auto *DerivedMemberVD = dyn_cast<ValueDecl>(DerivedMember)) {
282-
if (const auto *Overridden = DerivedMemberVD->getOverriddenDecl()) {
283-
SuperClassMembers.erase(Overridden);
284-
}
285-
}
286-
}
287-
// What remains in SuperClassMembers are inherited members that
288-
// haven't been overridden by the class.
289-
// Add a synthesized relationship.
290-
for (const auto *InheritedMember : SuperClassMembers) {
291-
if (canIncludeDeclAsNode(InheritedMember)) {
292-
Symbol Source(this, InheritedMember, C);
293-
Symbol Target(this, C, nullptr);
294-
Nodes.insert(Source);
295-
recordEdge(Source, Target, RelationshipKind::MemberOf());
296-
}
297-
}
298-
}
299-
}
300-
301261
bool SymbolGraph::synthesizedMemberIsBestCandidate(const ValueDecl *VD,
302262
const NominalTypeDecl *Owner) const {
303263
const auto *FD = dyn_cast<FuncDecl>(VD);

lib/SymbolGraphGen/SymbolGraph.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,6 @@ struct SymbolGraph {
145145
*/
146146
void recordConformanceSynthesizedMemberRelationships(Symbol S);
147147

148-
/**
149-
If a declaration has members by subclassing, record a symbol with a
150-
"synthesized" USR to disambiguate from the superclass's real implementation.
151-
152-
This makes it more convenient
153-
to curate symbols on a subclass's documentation.
154-
*/
155-
void recordSuperclassSynthesizedMemberRelationships(Symbol S);
156-
157148
/**
158149
Record InheritsFrom relationships for every class from which the
159150
declaration inherits.

test/SymbolGraph/Relationships/Synthesized/SuperclassImplementation.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@
33
// RUN: %target-swift-symbolgraph-extract -module-name SuperclassImplementation -I %t -pretty-print -output-dir %t
44
// RUN: %FileCheck %s --input-file %t/SuperclassImplementation.symbols.json
55

6+
// This test references code that has been removed. The implementation that synthesized superclass
7+
// methods was inconsistent; it failed to generate symbols for superclasses from another module.
8+
// From a symbol-relation perspective, the `inheritsFrom` relation from a subclass to its superclass
9+
// still exists, which already implies that all of the superclass's methods are available on the
10+
// subclass. The synthesized methods for subclasses were removed to provide consistency between
11+
// superclasses from the same module and those from a different one. If the implementation is
12+
// brought back, ensure that it consistently adds synthesized methods for superclasses from
13+
// different modules.
14+
615
public class Base {
716
public init() {}
817
public func foo() {}
918
}
1019

1120
public class Derived: Base {
12-
// CHECK-DAG: "precise": "s:24SuperclassImplementation4BaseC3fooyyF::SYNTHESIZED::s:24SuperclassImplementation7DerivedC"
21+
// CHECK-NOT: "precise": "s:24SuperclassImplementation4BaseC3fooyyF::SYNTHESIZED::s:24SuperclassImplementation7DerivedC"
1322
}
1423

1524
public class DerivedDerived: Derived {
16-
// CHECK-DAG: "precise": "s:24SuperclassImplementation4BaseC3fooyyF::SYNTHESIZED::s:24SuperclassImplementation07DerivedC0C"
25+
// CHECK-NOT: "precise": "s:24SuperclassImplementation4BaseC3fooyyF::SYNTHESIZED::s:24SuperclassImplementation07DerivedC0C"
1726
}

0 commit comments

Comments
 (0)