Skip to content

Commit f1d2986

Browse files
Merge pull request #40841 from apple/QuietMisdreavus/5.6/symgraph-regr
[5.6] Multiple symbol-graph regressions rdar://85280786, rdar://85230067
2 parents abd64c3 + f2142a4 commit f1d2986

File tree

13 files changed

+117
-25
lines changed

13 files changed

+117
-25
lines changed

include/swift/AST/FileUnit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/AST/Module.h"
1717
#include "swift/AST/RawComment.h"
1818
#include "swift/Basic/BasicSourceInfo.h"
19+
#include "swift/Basic/Debug.h"
1920

2021
#include "llvm/ADT/PointerIntPair.h"
2122

@@ -308,6 +309,9 @@ class FileUnit : public DeclContext, public ASTAllocated<FileUnit> {
308309
return getParentModule()->getRealName().str();
309310
}
310311

312+
SWIFT_DEBUG_DUMPER(dumpDisplayDecls());
313+
SWIFT_DEBUG_DUMPER(dumpTopLevelDecls());
314+
311315
/// Traverse the decls within this file.
312316
///
313317
/// \returns true if traversal was aborted, false if it completed

include/swift/AST/Module.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/AST/Type.h"
2727
#include "swift/Basic/BasicSourceInfo.h"
2828
#include "swift/Basic/Compiler.h"
29+
#include "swift/Basic/Debug.h"
2930
#include "swift/Basic/OptionSet.h"
3031
#include "swift/Basic/STLExtras.h"
3132
#include "swift/Basic/SourceLoc.h"
@@ -856,6 +857,9 @@ class ModuleDecl
856857
/// transferred from module files to the dSYMs, remove this.
857858
bool isExternallyConsumed() const;
858859

860+
SWIFT_DEBUG_DUMPER(dumpDisplayDecls());
861+
SWIFT_DEBUG_DUMPER(dumpTopLevelDecls());
862+
859863
SourceRange getSourceRange() const { return SourceRange(); }
860864

861865
static bool classof(const DeclContext *DC) {

include/swift/AST/SourceFile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ class SourceFile final : public FileUnit {
288288

289289
~SourceFile();
290290

291+
bool hasImports() const {
292+
return Imports.hasValue();
293+
}
294+
291295
/// Retrieve an immutable view of the source file's imports.
292296
ArrayRef<AttributedImport<ImportedModule>> getImports() const {
293297
return *Imports;

lib/AST/Module.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,22 @@ void SourceFile::lookupObjCMethods(
780780
results.append(known->second.begin(), known->second.end());
781781
}
782782

783+
static void collectParsedExportedImports(const ModuleDecl *M, SmallPtrSetImpl<ModuleDecl *> &Imports) {
784+
for (const FileUnit *file : M->getFiles()) {
785+
if (const SourceFile *source = dyn_cast<SourceFile>(file)) {
786+
if (source->hasImports()) {
787+
for (auto import : source->getImports()) {
788+
if (import.options.contains(ImportFlags::Exported)) {
789+
if (!Imports.contains(import.module.importedModule)) {
790+
Imports.insert(import.module.importedModule);
791+
}
792+
}
793+
}
794+
}
795+
}
796+
}
797+
}
798+
783799
void ModuleDecl::getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const {
784800
FORWARD(getLocalTypeDecls, (Results));
785801
}
@@ -788,6 +804,24 @@ void ModuleDecl::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const {
788804
FORWARD(getTopLevelDecls, (Results));
789805
}
790806

807+
void ModuleDecl::dumpDisplayDecls() const {
808+
SmallVector<Decl *, 32> Decls;
809+
getDisplayDecls(Decls);
810+
for (auto *D : Decls) {
811+
D->dump(llvm::errs());
812+
llvm::errs() << "\n";
813+
}
814+
}
815+
816+
void ModuleDecl::dumpTopLevelDecls() const {
817+
SmallVector<Decl *, 32> Decls;
818+
getTopLevelDecls(Decls);
819+
for (auto *D : Decls) {
820+
D->dump(llvm::errs());
821+
llvm::errs() << "\n";
822+
}
823+
}
824+
791825
void ModuleDecl::getExportedPrespecializations(
792826
SmallVectorImpl<Decl *> &Results) const {
793827
FORWARD(getExportedPrespecializations, (Results));
@@ -908,8 +942,23 @@ SourceFile::getExternalRawLocsForDecl(const Decl *D) const {
908942
}
909943

910944
void ModuleDecl::getDisplayDecls(SmallVectorImpl<Decl*> &Results) const {
945+
if (isParsedModule(this)) {
946+
SmallPtrSet<ModuleDecl *, 4> Modules;
947+
collectParsedExportedImports(this, Modules);
948+
for (const ModuleDecl *import : Modules) {
949+
import->getDisplayDecls(Results);
950+
}
951+
}
911952
// FIXME: Should this do extra access control filtering?
912953
FORWARD(getDisplayDecls, (Results));
954+
955+
#ifndef NDEBUG
956+
llvm::DenseSet<Decl *> visited;
957+
for (auto *D : Results) {
958+
auto inserted = visited.insert(D).second;
959+
assert(inserted && "there should be no duplicate decls");
960+
}
961+
#endif
913962
}
914963

915964
ProtocolConformanceRef
@@ -3060,6 +3109,22 @@ void FileUnit::getTopLevelDeclsWhereAttributesMatch(
30603109
Results.erase(newEnd, Results.end());
30613110
}
30623111

3112+
void FileUnit::dumpDisplayDecls() const {
3113+
SmallVector<Decl *, 32> Decls;
3114+
getDisplayDecls(Decls);
3115+
for (auto *D : Decls) {
3116+
D->dump(llvm::errs());
3117+
}
3118+
}
3119+
3120+
void FileUnit::dumpTopLevelDecls() const {
3121+
SmallVector<Decl *, 32> Decls;
3122+
getTopLevelDecls(Decls);
3123+
for (auto *D : Decls) {
3124+
D->dump(llvm::errs());
3125+
}
3126+
}
3127+
30633128
void swift::simple_display(llvm::raw_ostream &out, const FileUnit *file) {
30643129
if (!file) {
30653130
out << "(null)";

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ PrintOptions SymbolGraph::getDeclarationFragmentsPrintOptions() const {
9999
ExcludeAttrs.insert(std::make_pair("DAK_Postfix", DAK_Postfix));
100100
ExcludeAttrs.insert(std::make_pair("DAK_Infix", DAK_Infix));
101101

102+
// In "emit modules separately" jobs, access modifiers show up as attributes,
103+
// but we don't want them to be printed in declarations
104+
ExcludeAttrs.insert(std::make_pair("DAK_AccessControl", DAK_AccessControl));
105+
102106
for (const auto &Entry : ExcludeAttrs) {
103107
Opts.ExcludeAttrList.push_back(Entry.getValue());
104108
}

test/SourceKit/CursorInfo/cursor_symbol_graph.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,6 @@ enum MyEnum {
182182
// CHECKY: "symbols": [
183183
// CHECKY: {
184184
// CHECKY: "accessLevel": "private",
185-
// CHECKY: "declarationFragments": [
186-
// CHECKY: {
187-
// CHECKY: "kind": "keyword",
188-
// CHECKY: "spelling": "private"
189-
// CHECKY: },
190-
// CHECKY: {
191-
// CHECKY: "kind": "text",
192-
// CHECKY: "spelling": " "
193-
// CHECKY: },
194185
// CHECKY: {
195186
// CHECKY: "kind": "keyword",
196187
// CHECKY: "spelling": "var"

test/SourceKit/CursorInfo/cursor_symbol_graph_referenced.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,6 @@ extension Parent {
237237
// PRIVATE: "declarationFragments": [
238238
// PRIVATE-NEXT: {
239239
// PRIVATE-NEXT: "kind": "keyword",
240-
// PRIVATE-NEXT: "spelling": "private"
241-
// PRIVATE-NEXT: },
242-
// PRIVATE-NEXT: {
243-
// PRIVATE-NEXT: "kind": "text",
244-
// PRIVATE-NEXT: "spelling": " "
245-
// PRIVATE-NEXT: },
246-
// PRIVATE-NEXT: {
247-
// PRIVATE-NEXT: "kind": "keyword",
248240
// PRIVATE-NEXT: "spelling": "func"
249241
// PRIVATE-NEXT: },
250242
// PRIVATE-NEXT: {
@@ -302,14 +294,6 @@ extension Parent {
302294
// SPI: "declarationFragments": [
303295
// SPI-NEXT: {
304296
// SPI-NEXT: "kind": "keyword",
305-
// SPI-NEXT: "spelling": "internal"
306-
// SPI-NEXT: },
307-
// SPI-NEXT: {
308-
// SPI-NEXT: "kind": "text",
309-
// SPI-NEXT: "spelling": " "
310-
// SPI-NEXT: },
311-
// SPI-NEXT: {
312-
// SPI-NEXT: "kind": "keyword",
313297
// SPI-NEXT: "spelling": "func"
314298
// SPI-NEXT: },
315299
// SPI-NEXT: {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: cp -r %S/Inputs/EmitWhileBuilding/EmitWhileBuilding.framework %t
3+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -emit-module-path %t/EmitWhileBuilding.framework/Modules/EmitWhileBuilding.swiftmodule/%target-swiftmodule-name -import-underlying-module -F %t -module-name EmitWhileBuilding -disable-objc-attr-requires-foundation-module %s %S/Inputs/EmitWhileBuilding/Extra.swift -emit-symbol-graph -emit-symbol-graph-dir %t
4+
// RUN: %{python} -m json.tool %t/EmitWhileBuilding.symbols.json %t/EmitWhileBuilding.formatted.symbols.json
5+
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.formatted.symbols.json
6+
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.formatted.symbols.json --check-prefix HEADER
7+
8+
// REQUIRES: objc_interop
9+
10+
import Foundation
11+
12+
public enum SwiftEnum {}
13+
14+
// HEADER: "precise": "c:@testVariable"
15+
16+
// CHECK: "precise": "s:17EmitWhileBuilding9SwiftEnumO",
17+
// CHECK: "declarationFragments": [
18+
// CHECK-NEXT: {
19+
// CHECK-NEXT: "kind": "keyword",
20+
// CHECK-NEXT: "spelling": "enum"
21+
// CHECK-NEXT: },
22+
// CHECK-NEXT: {
23+
// CHECK-NEXT: "kind": "text",
24+
// CHECK-NEXT: "spelling": " "
25+
// CHECK-NEXT: },
26+
// CHECK-NEXT: {
27+
// CHECK-NEXT: "kind": "identifier",
28+
// CHECK-NEXT: "spelling": "SwiftEnum"
29+
// CHECK-NEXT: }
30+
// CHECK-NEXT: ],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
double testVariable = 1.0;

test/SymbolGraph/ClangImporter/Inputs/EmitWhileBuilding/EmitWhileBuilding.framework/Modules/EmitWhileBuilding.swiftmodule/.keep

Whitespace-only changes.

test/SymbolGraph/ClangImporter/Inputs/EmitWhileBuilding/EmitWhileBuilding.framework/ObjcProperty

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework module EmitWhileBuilding {
2+
header "EmitWhileBuilding.h"
3+
export *
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public struct SomeStruct {}

0 commit comments

Comments
 (0)