Skip to content
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
23 changes: 15 additions & 8 deletions swift/extractor/mangler/SwiftMangler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "swift/extractor/mangler/SwiftMangler.h"
#include "swift/extractor/infra/SwiftDispatcher.h"
#include "swift/extractor/trap/generated/decl/TrapClasses.h"
#include "swift/logging/SwiftLogging.h"

#include <swift/AST/Module.h>
Expand Down Expand Up @@ -170,15 +169,12 @@ void SwiftMangler::indexExtensionsAndFilePrivateValues(llvm::ArrayRef<swift::Dec
}
}

void SwiftMangler::indexClangExtensionsAndFilePrivateValues(
uint32_t SwiftMangler::indexClangSubmoduleExtensionsAndFilePrivateValues(
const clang::Module* clangModule,
swift::ClangModuleLoader* moduleLoader) {
if (!moduleLoader) {
return;
}

auto index = 0u;
swift::ClangModuleLoader* moduleLoader,
uint32_t index) {
for (const auto& submodule : clangModule->submodules()) {
index = indexClangSubmoduleExtensionsAndFilePrivateValues(submodule, moduleLoader, index);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it:

  • previously we were exploring submodules, but not recursively (that's added here).
  • index is used to identify extensions or file private values internally, it is not a Clang number.
  • the submodule structure is guaranteed to be acyclic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • previously we were exploring submodules, but not recursively (that's added here).

Correct.

  • index is used to identify extensions or file private values internally, it is not a Clang number.

Correct. We just count extensions in Swift code separately from extensions that come from C++ code (clang).

  • the submodule structure is guaranteed to be acyclic?

If not that would mean that C++20 modules can import each other cyclically, which is illegal.

if (auto* swiftSubmodule = moduleLoader->getWrapperForModule(submodule)) {
llvm::SmallVector<swift::Decl*> children;
swiftSubmodule->getTopLevelDecls(children);
Expand All @@ -191,6 +187,17 @@ void SwiftMangler::indexClangExtensionsAndFilePrivateValues(
}
}
}
return index;
}

void SwiftMangler::indexClangExtensionsAndFilePrivateValues(
const clang::Module* clangModule,
swift::ClangModuleLoader* moduleLoader) {
if (!moduleLoader) {
return;
}

indexClangSubmoduleExtensionsAndFilePrivateValues(clangModule, moduleLoader, 0u);
}

SwiftMangledName SwiftMangler::visitGenericTypeParamDecl(const swift::GenericTypeParamDecl* decl) {
Expand Down
3 changes: 3 additions & 0 deletions swift/extractor/mangler/SwiftMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ class SwiftMangler : private swift::TypeVisitor<SwiftMangler, SwiftMangledName>,

bool isExtensionOrFilePrivateValue(const swift::Decl* decl);
void indexExtensionsAndFilePrivateValues(llvm::ArrayRef<swift::Decl*> siblings);
uint32_t indexClangSubmoduleExtensionsAndFilePrivateValues(const clang::Module* clangModule,
swift::ClangModuleLoader* moduleLoader,
uint32_t index);
void indexClangExtensionsAndFilePrivateValues(const clang::Module* clangModule,
swift::ClangModuleLoader* moduleLoader);
ExtensionOrFilePrivateValueIndex getExtensionOrFilePrivateValueIndex(const swift::Decl* decl,
Expand Down