Skip to content

Commit 37fca1c

Browse files
Revert "Merge pull request #40877 from apple/revert-40810-QuietMisdreavus/sourcefile-export"
This reverts commit caf2f08, reversing changes made to 5a9abb2.
1 parent 9839378 commit 37fca1c

File tree

6 files changed

+83
-1
lines changed

6 files changed

+83
-1
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
@@ -3065,6 +3114,22 @@ void FileUnit::getTopLevelDeclsWhereAttributesMatch(
30653114
Results.erase(newEnd, Results.end());
30663115
}
30673116

3117+
void FileUnit::dumpDisplayDecls() const {
3118+
SmallVector<Decl *, 32> Decls;
3119+
getDisplayDecls(Decls);
3120+
for (auto *D : Decls) {
3121+
D->dump(llvm::errs());
3122+
}
3123+
}
3124+
3125+
void FileUnit::dumpTopLevelDecls() const {
3126+
SmallVector<Decl *, 32> Decls;
3127+
getTopLevelDecls(Decls);
3128+
for (auto *D : Decls) {
3129+
D->dump(llvm::errs());
3130+
}
3131+
}
3132+
30683133
void swift::simple_display(llvm::raw_ostream &out, const FileUnit *file) {
30693134
if (!file) {
30703135
out << "(null)";

test/SymbolGraph/ClangImporter/EmitWhileBuilding.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// RUN: %empty-directory(%t)
22
// 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 -emit-symbol-graph -emit-symbol-graph-dir %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
44
// RUN: %{python} -m json.tool %t/EmitWhileBuilding.symbols.json %t/EmitWhileBuilding.formatted.symbols.json
55
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.formatted.symbols.json
6+
// RUN: %FileCheck %s --input-file %t/EmitWhileBuilding.formatted.symbols.json --check-prefix HEADER
67

78
// REQUIRES: objc_interop
89

910
import Foundation
1011

1112
public enum SwiftEnum {}
1213

14+
// HEADER: "precise": "c:@testVariable"
15+
16+
// CHECK: "precise": "s:17EmitWhileBuilding9SwiftEnumO",
1317
// CHECK: "declarationFragments": [
1418
// CHECK-NEXT: {
1519
// CHECK-NEXT: "kind": "keyword",
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)