Skip to content

Commit 9405f1e

Browse files
committed
[AST] Break dependency cycle between swiftAST and swiftClangImporter
NormalProtocolConformance::isRetroactive() introduces dependency on swiftClangImporter by calling ClangModuleUnit::getAdapterModule(). Do some refactoring to break the cycle.
1 parent 75ab0a5 commit 9405f1e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

include/swift/AST/Module.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,9 @@ class LoadedFile : public FileUnit {
13151315
return nullptr;
13161316
}
13171317

1318+
/// Returns the Swift module that overlays a Clang module.
1319+
virtual ModuleDecl *getAdapterModule() const { return nullptr; }
1320+
13181321
virtual bool isSystemModule() const { return false; }
13191322

13201323
/// Retrieve the set of generic signatures stored within this module.

include/swift/ClangImporter/ClangModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ClangModuleUnit final : public LoadedFile {
5454
bool isTopLevel() const;
5555

5656
/// Returns the Swift module that overlays this Clang module.
57-
ModuleDecl *getAdapterModule() const;
57+
ModuleDecl *getAdapterModule() const override;
5858

5959
/// Retrieve the "exported" name of the module, which is usually the module
6060
/// name, but might be the name of the public module through which this

lib/AST/ProtocolConformance.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "swift/AST/Types.h"
2525
#include "swift/AST/TypeWalker.h"
2626
#include "swift/Basic/Statistic.h"
27-
#include "swift/ClangImporter/ClangModule.h"
2827
#include "llvm/ADT/MapVector.h"
2928
#include "llvm/ADT/Statistic.h"
3029
#include "llvm/ADT/TinyPtrVector.h"
@@ -437,10 +436,10 @@ bool NormalProtocolConformance::isRetroactive() const {
437436

438437
// Consider the overlay module to be the "home" of a nominal type
439438
// defined in a Clang module.
440-
if (auto nominalClangModule =
441-
dyn_cast<ClangModuleUnit>(nominal->getModuleScopeContext())) {
439+
if (auto nominalLoadedModule =
440+
dyn_cast<LoadedFile>(nominal->getModuleScopeContext())) {
442441
if (auto clangLoader = nominal->getASTContext().getClangModuleLoader()) {
443-
if (auto overlayModule = nominalClangModule->getAdapterModule())
442+
if (auto overlayModule = nominalLoadedModule->getAdapterModule())
444443
nominalModule = overlayModule;
445444
}
446445
}
@@ -454,7 +453,9 @@ bool NormalProtocolConformance::isRetroactive() const {
454453
}
455454

456455
bool NormalProtocolConformance::isSynthesizedNonUnique() const {
457-
return isa<ClangModuleUnit>(getDeclContext()->getModuleScopeContext());
456+
if (auto *file = dyn_cast<FileUnit>(getDeclContext()->getModuleScopeContext()))
457+
return file->getKind() == FileUnitKind::ClangModule;
458+
return false;
458459
}
459460

460461
bool NormalProtocolConformance::isResilient() const {

0 commit comments

Comments
 (0)