Skip to content

[5.6] Multiple symbol-graph regressions #40841

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 4 commits into from
Jan 13, 2022
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
4 changes: 4 additions & 0 deletions include/swift/AST/FileUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "swift/AST/Module.h"
#include "swift/AST/RawComment.h"
#include "swift/Basic/BasicSourceInfo.h"
#include "swift/Basic/Debug.h"

#include "llvm/ADT/PointerIntPair.h"

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

SWIFT_DEBUG_DUMPER(dumpDisplayDecls());
SWIFT_DEBUG_DUMPER(dumpTopLevelDecls());

/// Traverse the decls within this file.
///
/// \returns true if traversal was aborted, false if it completed
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "swift/AST/Type.h"
#include "swift/Basic/BasicSourceInfo.h"
#include "swift/Basic/Compiler.h"
#include "swift/Basic/Debug.h"
#include "swift/Basic/OptionSet.h"
#include "swift/Basic/STLExtras.h"
#include "swift/Basic/SourceLoc.h"
Expand Down Expand Up @@ -856,6 +857,9 @@ class ModuleDecl
/// transferred from module files to the dSYMs, remove this.
bool isExternallyConsumed() const;

SWIFT_DEBUG_DUMPER(dumpDisplayDecls());
SWIFT_DEBUG_DUMPER(dumpTopLevelDecls());

SourceRange getSourceRange() const { return SourceRange(); }

static bool classof(const DeclContext *DC) {
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/SourceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ class SourceFile final : public FileUnit {

~SourceFile();

bool hasImports() const {
return Imports.hasValue();
}

/// Retrieve an immutable view of the source file's imports.
ArrayRef<AttributedImport<ImportedModule>> getImports() const {
return *Imports;
Expand Down
65 changes: 65 additions & 0 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,22 @@ void SourceFile::lookupObjCMethods(
results.append(known->second.begin(), known->second.end());
}

static void collectParsedExportedImports(const ModuleDecl *M, SmallPtrSetImpl<ModuleDecl *> &Imports) {
for (const FileUnit *file : M->getFiles()) {
if (const SourceFile *source = dyn_cast<SourceFile>(file)) {
if (source->hasImports()) {
for (auto import : source->getImports()) {
if (import.options.contains(ImportFlags::Exported)) {
if (!Imports.contains(import.module.importedModule)) {
Imports.insert(import.module.importedModule);
}
}
}
}
}
}
}

void ModuleDecl::getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const {
FORWARD(getLocalTypeDecls, (Results));
}
Expand All @@ -788,6 +804,24 @@ void ModuleDecl::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const {
FORWARD(getTopLevelDecls, (Results));
}

void ModuleDecl::dumpDisplayDecls() const {
SmallVector<Decl *, 32> Decls;
getDisplayDecls(Decls);
for (auto *D : Decls) {
D->dump(llvm::errs());
llvm::errs() << "\n";
}
}

void ModuleDecl::dumpTopLevelDecls() const {
SmallVector<Decl *, 32> Decls;
getTopLevelDecls(Decls);
for (auto *D : Decls) {
D->dump(llvm::errs());
llvm::errs() << "\n";
}
}

void ModuleDecl::getExportedPrespecializations(
SmallVectorImpl<Decl *> &Results) const {
FORWARD(getExportedPrespecializations, (Results));
Expand Down Expand Up @@ -908,8 +942,23 @@ SourceFile::getExternalRawLocsForDecl(const Decl *D) const {
}

void ModuleDecl::getDisplayDecls(SmallVectorImpl<Decl*> &Results) const {
if (isParsedModule(this)) {
SmallPtrSet<ModuleDecl *, 4> Modules;
collectParsedExportedImports(this, Modules);
for (const ModuleDecl *import : Modules) {
import->getDisplayDecls(Results);
}
}
// FIXME: Should this do extra access control filtering?
FORWARD(getDisplayDecls, (Results));

#ifndef NDEBUG
llvm::DenseSet<Decl *> visited;
for (auto *D : Results) {
auto inserted = visited.insert(D).second;
assert(inserted && "there should be no duplicate decls");
}
#endif
}

ProtocolConformanceRef
Expand Down Expand Up @@ -3060,6 +3109,22 @@ void FileUnit::getTopLevelDeclsWhereAttributesMatch(
Results.erase(newEnd, Results.end());
}

void FileUnit::dumpDisplayDecls() const {
SmallVector<Decl *, 32> Decls;
getDisplayDecls(Decls);
for (auto *D : Decls) {
D->dump(llvm::errs());
}
}

void FileUnit::dumpTopLevelDecls() const {
SmallVector<Decl *, 32> Decls;
getTopLevelDecls(Decls);
for (auto *D : Decls) {
D->dump(llvm::errs());
}
}

void swift::simple_display(llvm::raw_ostream &out, const FileUnit *file) {
if (!file) {
out << "(null)";
Expand Down
4 changes: 4 additions & 0 deletions lib/SymbolGraphGen/SymbolGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ PrintOptions SymbolGraph::getDeclarationFragmentsPrintOptions() const {
ExcludeAttrs.insert(std::make_pair("DAK_Postfix", DAK_Postfix));
ExcludeAttrs.insert(std::make_pair("DAK_Infix", DAK_Infix));

// In "emit modules separately" jobs, access modifiers show up as attributes,
// but we don't want them to be printed in declarations
ExcludeAttrs.insert(std::make_pair("DAK_AccessControl", DAK_AccessControl));

for (const auto &Entry : ExcludeAttrs) {
Opts.ExcludeAttrList.push_back(Entry.getValue());
}
Expand Down
9 changes: 0 additions & 9 deletions test/SourceKit/CursorInfo/cursor_symbol_graph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,6 @@ enum MyEnum {
// CHECKY: "symbols": [
// CHECKY: {
// CHECKY: "accessLevel": "private",
// CHECKY: "declarationFragments": [
// CHECKY: {
// CHECKY: "kind": "keyword",
// CHECKY: "spelling": "private"
// CHECKY: },
// CHECKY: {
// CHECKY: "kind": "text",
// CHECKY: "spelling": " "
// CHECKY: },
// CHECKY: {
// CHECKY: "kind": "keyword",
// CHECKY: "spelling": "var"
Expand Down
16 changes: 0 additions & 16 deletions test/SourceKit/CursorInfo/cursor_symbol_graph_referenced.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,6 @@ extension Parent {
// PRIVATE: "declarationFragments": [
// PRIVATE-NEXT: {
// PRIVATE-NEXT: "kind": "keyword",
// PRIVATE-NEXT: "spelling": "private"
// PRIVATE-NEXT: },
// PRIVATE-NEXT: {
// PRIVATE-NEXT: "kind": "text",
// PRIVATE-NEXT: "spelling": " "
// PRIVATE-NEXT: },
// PRIVATE-NEXT: {
// PRIVATE-NEXT: "kind": "keyword",
// PRIVATE-NEXT: "spelling": "func"
// PRIVATE-NEXT: },
// PRIVATE-NEXT: {
Expand Down Expand Up @@ -302,14 +294,6 @@ extension Parent {
// SPI: "declarationFragments": [
// SPI-NEXT: {
// SPI-NEXT: "kind": "keyword",
// SPI-NEXT: "spelling": "internal"
// SPI-NEXT: },
// SPI-NEXT: {
// SPI-NEXT: "kind": "text",
// SPI-NEXT: "spelling": " "
// SPI-NEXT: },
// SPI-NEXT: {
// SPI-NEXT: "kind": "keyword",
// SPI-NEXT: "spelling": "func"
// SPI-NEXT: },
// SPI-NEXT: {
Expand Down
30 changes: 30 additions & 0 deletions test/SymbolGraph/ClangImporter/EmitWhileBuilding.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: %empty-directory(%t)
// RUN: cp -r %S/Inputs/EmitWhileBuilding/EmitWhileBuilding.framework %t
// 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
// RUN: %{python} -m json.tool %t/EmitWhileBuilding.symbols.json %t/EmitWhileBuilding.formatted.symbols.json
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.formatted.symbols.json
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.formatted.symbols.json --check-prefix HEADER

// REQUIRES: objc_interop

import Foundation

public enum SwiftEnum {}

// HEADER: "precise": "c:@testVariable"

// CHECK: "precise": "s:17EmitWhileBuilding9SwiftEnumO",
// CHECK: "declarationFragments": [
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "keyword",
// CHECK-NEXT: "spelling": "enum"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "text",
// CHECK-NEXT: "spelling": " "
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "kind": "identifier",
// CHECK-NEXT: "spelling": "SwiftEnum"
// CHECK-NEXT: }
// CHECK-NEXT: ],
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
double testVariable = 1.0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework module EmitWhileBuilding {
header "EmitWhileBuilding.h"
export *
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public struct SomeStruct {}